@dotdo/gitx
v0.1.4
Published
Pure Git implementation in TypeScript - object parsing, pack files, delta compression, refs. With AsyncFn pattern support.
Downloads
10
Readme
@dotdo/gitx
Pure Git implementation in TypeScript. Parse objects, read/write pack files, handle delta compression, manage refs. Zero dependencies - runs anywhere JavaScript runs.
This is the core package that provides platform-agnostic Git functionality. For Cloudflare Workers/Durable Objects integration, see gitx.do.
Installation
npm install @dotdo/gitxFeatures
- Git Objects - Parse and create blobs, trees, commits, and tags
- Pack Files - Read and write git pack format with delta compression
- Refs Management - Handle branches, tags, HEAD, and symbolic refs
- Protocol Support - Smart HTTP protocol for fetch/push
Usage
import {
parseObject,
createCommit,
createTree,
hashObject
} from '@dotdo/gitx'
// Parse a git object
const obj = parseObject(buffer)
// { type: 'commit', size: 245, data: {...} }
// Create a tree
const tree = createTree([
{ mode: '100644', name: 'README.md', hash: 'abc123...' },
{ mode: '040000', name: 'src', hash: 'def456...' }
])
// Create a commit
const commit = createCommit({
tree: treeHash,
parents: [parentHash],
author: { name: 'Dev', email: '[email protected]', timestamp: Date.now() },
message: 'Initial commit'
})
// Hash an object
const hash = await hashObject('blob', content)Subpath Exports
import { Blob, Tree, Commit, Tag, parseObject } from '@dotdo/gitx/objects'
import { PackReader, PackWriter, applyDelta } from '@dotdo/gitx/pack'
import { RefStorage, parseRef, resolveRef } from '@dotdo/gitx/refs'
import { smartHttp, pktLine } from '@dotdo/gitx/protocol'API
Objects (@dotdo/gitx/objects)
parseObject(buffer: Uint8Array): GitObjectcreateBlob(content: string | Uint8Array): Uint8ArraycreateTree(entries: TreeEntry[]): Uint8ArraycreateCommit(data: CommitData): Uint8ArraycreateTag(data: TagData): Uint8ArrayhashObject(type: string, data: Uint8Array): Promise<string>
Pack (@dotdo/gitx/pack)
PackReader- Read objects from pack filesPackWriter- Write pack files with delta compressionapplyDelta(base: Uint8Array, delta: Uint8Array): Uint8ArraycreateDelta(source: Uint8Array, target: Uint8Array): Uint8Array
Refs (@dotdo/gitx/refs)
parseRef(content: string): RefresolveRef(name: string, storage): Promise<string>RefStorage- Interface for ref persistence
Protocol (@dotdo/gitx/protocol)
pktLine.encode(data: string): Uint8ArraypktLine.decode(buffer: Uint8Array): string[]smartHttp.advertiseRefs(refs: Ref[]): Uint8Array
Related
- gitx.do - Managed service with R2 storage
- fsx.do - Filesystem for Workers
- bashx.do - Shell execution for Workers
License
MIT
