just-git 1.3.6 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ import { h as Identity, j as ObjectType, g as GitRepo } from './hooks-C7c_BLqp.js';
2
+
3
+ /**
4
+ * Simplified identity for the public API. When `date` is omitted,
5
+ * defaults to the current time. Accepts either this form or the
6
+ * internal `Identity` (with `timestamp`/`timezone`) for full control.
7
+ */
8
+ interface CommitAuthor {
9
+ name: string;
10
+ email: string;
11
+ /** Defaults to `new Date()` (current time). */
12
+ date?: Date;
13
+ }
14
+ /** Accepts either the simplified {@link CommitAuthor} or the internal `Identity` with raw timestamp/timezone. */
15
+ type CommitIdentity = CommitAuthor | Identity;
16
+ /** Options for {@link createCommit}. */
17
+ interface CreateCommitOptions {
18
+ /** Hash of the tree object for this commit. */
19
+ tree: string;
20
+ /** Parent commit hashes (empty for root commits). */
21
+ parents: string[];
22
+ /** Author identity. Accepts `{ name, email, date? }` or full `Identity`. */
23
+ author: CommitIdentity;
24
+ /** Committer identity. Defaults to `author` when omitted. */
25
+ committer?: CommitIdentity;
26
+ message: string;
27
+ /**
28
+ * When set, advances `refs/heads/<branch>` to the new commit.
29
+ * If HEAD does not exist yet, it is created as a symbolic ref
30
+ * pointing to the branch — matching `git init` + `git commit`.
31
+ */
32
+ branch?: string;
33
+ }
34
+ /**
35
+ * Create a commit object directly in the object store.
36
+ * Returns the new commit's hash.
37
+ *
38
+ * When `branch` is provided, also advances the branch ref and
39
+ * (if HEAD is absent) initializes HEAD as a symbolic ref to it.
40
+ * Without `branch`, no refs are updated.
41
+ */
42
+ declare function createCommit(repo: GitRepo, options: CreateCommitOptions): Promise<string>;
43
+ /** Options for {@link createAnnotatedTag}. */
44
+ interface CreateAnnotatedTagOptions {
45
+ /** Hash of the target object (usually a commit). */
46
+ target: string;
47
+ /** Tag name (written into the tag object and used for the ref). */
48
+ name: string;
49
+ /** Tagger identity. Accepts `{ name, email, date? }` or full `Identity`. */
50
+ tagger: CommitIdentity;
51
+ message: string;
52
+ /** Type of the target object. Defaults to `"commit"`. */
53
+ targetType?: ObjectType;
54
+ }
55
+ /**
56
+ * Create an annotated tag object and its ref.
57
+ * Returns the tag object's hash.
58
+ *
59
+ * ```ts
60
+ * await createAnnotatedTag(repo, {
61
+ * target: commitHash,
62
+ * name: "v1.0.0",
63
+ * tagger: { name: "Alice", email: "alice@example.com" },
64
+ * message: "Release 1.0.0",
65
+ * });
66
+ * ```
67
+ */
68
+ declare function createAnnotatedTag(repo: GitRepo, options: CreateAnnotatedTagOptions): Promise<string>;
69
+ /** Options for {@link buildCommit}. */
70
+ interface BuildCommitOptions {
71
+ /**
72
+ * Files to add, update, or delete.
73
+ * - `string` values are written as UTF-8 blobs.
74
+ * - `Uint8Array` values are written as raw blobs.
75
+ * - `null` deletes the file from the tree.
76
+ */
77
+ files: Record<string, string | Uint8Array | null>;
78
+ message: string;
79
+ /** Author identity. Accepts `{ name, email, date? }` or full `Identity`. Timestamp defaults to now. */
80
+ author: CommitIdentity;
81
+ /** Committer identity. Defaults to `author` when omitted. */
82
+ committer?: CommitIdentity;
83
+ /**
84
+ * Branch to read the parent commit from. The new commit builds on
85
+ * top of this branch's tree. When omitted, creates a root commit
86
+ * with only the specified files.
87
+ */
88
+ branch?: string;
89
+ }
90
+ /** Result of {@link buildCommit}. */
91
+ interface CommitResult {
92
+ /** The new commit's hash. */
93
+ hash: string;
94
+ /** The parent commit hash, or `null` for root commits. Useful as `oldHash` for CAS-protected ref updates. */
95
+ parentHash: string | null;
96
+ }
97
+ /**
98
+ * Create a commit from files without advancing any refs.
99
+ *
100
+ * Handles blob creation, tree construction, and parent resolution.
101
+ * When `branch` is provided and the branch exists, the specified
102
+ * files are applied on top of the existing tree (unmentioned files
103
+ * are preserved). When the branch doesn't exist or is omitted, a
104
+ * root commit is created with only the specified files.
105
+ *
106
+ * Returns both the commit hash and the parent hash. The parent hash
107
+ * is useful as `oldHash` for CAS-protected ref updates via
108
+ * `server.updateRefs()` or `server.commit()`.
109
+ *
110
+ * ```ts
111
+ * const { hash, parentHash } = await buildCommit(repo, {
112
+ * files: { "README.md": "# Hello\n" },
113
+ * message: "initial commit",
114
+ * author: { name: "Alice", email: "alice@example.com" },
115
+ * branch: "main",
116
+ * });
117
+ * ```
118
+ */
119
+ declare function buildCommit(repo: GitRepo, options: BuildCommitOptions): Promise<CommitResult>;
120
+ /** Options for {@link commit}. */
121
+ interface CommitOptions {
122
+ /**
123
+ * Files to add, update, or delete.
124
+ * - `string` values are written as UTF-8 blobs.
125
+ * - `Uint8Array` values are written as raw blobs.
126
+ * - `null` deletes the file from the tree.
127
+ */
128
+ files: Record<string, string | Uint8Array | null>;
129
+ message: string;
130
+ /** Author identity. Accepts `{ name, email, date? }` or full `Identity`. Timestamp defaults to now. */
131
+ author: CommitIdentity;
132
+ /** Committer identity. Defaults to `author` when omitted. */
133
+ committer?: CommitIdentity;
134
+ /** Branch to commit to. Parent is auto-resolved from the current branch tip. */
135
+ branch: string;
136
+ }
137
+ /**
138
+ * Commit files to a branch in one call.
139
+ *
140
+ * Handles blob creation, tree construction, parent resolution, and
141
+ * ref advancement. When the branch already exists, the specified
142
+ * files are applied on top of the existing tree (unmentioned files
143
+ * are preserved). When the branch doesn't exist, a root commit is
144
+ * created with only the specified files.
145
+ *
146
+ * For server-backed repos where hook enforcement and CAS protection
147
+ * are needed, use `server.commit()` instead — it uses
148
+ * {@link buildCommit} + `server.updateRefs()` internally.
149
+ *
150
+ * ```ts
151
+ * await commit(repo, {
152
+ * files: { "README.md": "# Hello\n", "src/index.ts": "export {};\n" },
153
+ * message: "initial commit",
154
+ * author: { name: "Alice", email: "alice@example.com" },
155
+ * branch: "main",
156
+ * });
157
+ * ```
158
+ */
159
+ declare function commit(repo: GitRepo, options: CommitOptions): Promise<string>;
160
+ /** An entry to include in a tree built by {@link writeTree}. */
161
+ interface TreeEntryInput {
162
+ /** Filename (not a path — nesting is achieved by including tree entries). */
163
+ name: string;
164
+ /** Hash of the blob or tree object. */
165
+ hash: string;
166
+ /** File mode (e.g. "100644"). Auto-detected from the object store when omitted. */
167
+ mode?: string;
168
+ }
169
+ /**
170
+ * Build a tree object from a flat list of entries and write it to the
171
+ * object store. When `mode` is omitted, the object store is consulted:
172
+ * tree objects get "040000", everything else gets "100644".
173
+ */
174
+ declare function writeTree(repo: GitRepo, entries: TreeEntryInput[]): Promise<string>;
175
+ /**
176
+ * Write a UTF-8 string as a blob to the object store.
177
+ * Returns the blob's hash.
178
+ */
179
+ declare function writeBlob(repo: GitRepo, content: string): Promise<string>;
180
+ /** A file to add or update in a tree via {@link updateTree}. */
181
+ interface TreeUpdate {
182
+ /** Full repo-relative path (e.g. `"src/lib/foo.ts"`). */
183
+ path: string;
184
+ /** Blob hash. When `null`, the file is removed. */
185
+ hash: string | null;
186
+ /** File mode (default `"100644"`). Ignored when `hash` is `null`. */
187
+ mode?: string;
188
+ }
189
+ /**
190
+ * Apply path-based additions, updates, and deletions to an existing
191
+ * tree, handling nested subtree construction automatically.
192
+ * Returns the new root tree hash.
193
+ *
194
+ * ```ts
195
+ * const blob = await writeBlob(repo, "hello world\n");
196
+ * const newTree = await updateTree(repo, commit.tree, [
197
+ * { path: "src/new-file.ts", hash: blob },
198
+ * { path: "old-file.txt", hash: null },
199
+ * ]);
200
+ * ```
201
+ */
202
+ declare function updateTree(repo: GitRepo, treeHash: string, updates: TreeUpdate[]): Promise<string>;
203
+
204
+ export { type BuildCommitOptions as B, type CommitAuthor as C, type TreeEntryInput as T, type CommitIdentity as a, type CommitOptions as b, type CommitResult as c, type CreateAnnotatedTagOptions as d, type CreateCommitOptions as e, type TreeUpdate as f, buildCommit as g, commit as h, createAnnotatedTag as i, createCommit as j, writeTree as k, updateTree as u, writeBlob as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-git",
3
- "version": "1.3.6",
3
+ "version": "1.3.9",
4
4
  "description": "Pure TypeScript git implementation: virtual filesystem client and embeddable server.",
5
5
  "keywords": [
6
6
  "agent",