@scolladon/tsgit 1.3.0 → 2.0.1
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.
- package/README.md +3 -2
- package/dist/cjs/adapters/browser/index.cjs +1 -1
- package/dist/cjs/adapters/memory/index.cjs +1 -1
- package/dist/cjs/adapters/memory/index.cjs.map +1 -1
- package/dist/cjs/adapters/node/index.cjs +1 -1
- package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs +2 -0
- package/dist/cjs/chunks/adapter-detect-CD_LcgaH.cjs.map +1 -0
- package/dist/cjs/chunks/{browser-http-transport-D4NH-8oJ.cjs → browser-http-transport-CiMRqtDS.cjs} +2 -2
- package/dist/cjs/chunks/browser-http-transport-CiMRqtDS.cjs.map +1 -0
- package/dist/cjs/chunks/error-CfjFO3x_.cjs +2 -0
- package/dist/cjs/chunks/error-CfjFO3x_.cjs.map +1 -0
- package/dist/cjs/chunks/index-BWCq_5BJ.cjs +2 -0
- package/dist/cjs/chunks/index-BWCq_5BJ.cjs.map +1 -0
- package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs +2 -0
- package/dist/cjs/chunks/memory-http-transport-BVL6VgB-.cjs.map +1 -0
- package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs +2 -0
- package/dist/cjs/chunks/node-http-transport-BvfVcf02.cjs.map +1 -0
- package/dist/cjs/chunks/{progress-Bj2w-90A.cjs → progress-CxU62NC1.cjs} +2 -2
- package/dist/cjs/chunks/{progress-Bj2w-90A.cjs.map → progress-CxU62NC1.cjs.map} +1 -1
- package/dist/cjs/chunks/repository-BEg2zNtx.cjs +2 -0
- package/dist/cjs/chunks/repository-BEg2zNtx.cjs.map +1 -0
- package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs +2 -0
- package/dist/cjs/chunks/walk-submodules-D2Sp7JEB.cjs.map +1 -0
- package/dist/cjs/commands/index.cjs +1 -1
- package/dist/cjs/index.browser.cjs +1 -1
- package/dist/cjs/index.browser.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.default.cjs +1 -1
- package/dist/cjs/index.default.cjs.map +1 -1
- package/dist/cjs/index.node.cjs +1 -1
- package/dist/cjs/index.node.cjs.map +1 -1
- package/dist/cjs/primitives/index.cjs +1 -1
- package/dist/cjs/primitives/index.cjs.map +1 -1
- package/dist/esm/adapters/browser/index.js +1 -1
- package/dist/esm/adapters/memory/index.js +1 -1
- package/dist/esm/adapters/memory/index.js.map +1 -1
- package/dist/esm/adapters/node/index.js +1 -1
- package/dist/esm/adapters/node/index.js.map +1 -1
- package/dist/esm/chunks/adapter-detect-DkZhhUhd.js +2 -0
- package/dist/esm/chunks/adapter-detect-DkZhhUhd.js.map +1 -0
- package/dist/esm/chunks/{browser-http-transport-DL8bkNdg.js → browser-http-transport-4rJkHcQu.js} +2 -2
- package/dist/esm/chunks/browser-http-transport-4rJkHcQu.js.map +1 -0
- package/dist/esm/chunks/error-Dc-SRSJK.js +2 -0
- package/dist/esm/chunks/error-Dc-SRSJK.js.map +1 -0
- package/dist/esm/chunks/index-jH0UMhh-.js +2 -0
- package/dist/esm/chunks/index-jH0UMhh-.js.map +1 -0
- package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js +2 -0
- package/dist/esm/chunks/memory-http-transport-CA1WxWBp.js.map +1 -0
- package/dist/esm/chunks/node-http-transport-DPa2lK3T.js +2 -0
- package/dist/esm/chunks/node-http-transport-DPa2lK3T.js.map +1 -0
- package/dist/esm/chunks/progress-BZobfl7p.js +2 -0
- package/dist/esm/chunks/{progress-NePjO3Kd.js.map → progress-BZobfl7p.js.map} +1 -1
- package/dist/esm/chunks/repository-DF6ePd1x.js +2 -0
- package/dist/esm/chunks/repository-DF6ePd1x.js.map +1 -0
- package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js +2 -0
- package/dist/esm/chunks/walk-submodules-Dq9oGwP8.js.map +1 -0
- package/dist/esm/commands/index.js +1 -1
- package/dist/esm/index.browser.js +1 -1
- package/dist/esm/index.browser.js.map +1 -1
- package/dist/esm/index.default.js +1 -1
- package/dist/esm/index.default.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.node.js +1 -1
- package/dist/esm/index.node.js.map +1 -1
- package/dist/esm/primitives/index.js +1 -1
- package/dist/esm/primitives/index.js.map +1 -1
- package/dist/types/adapters/browser/index.d.cts +5 -2
- package/dist/types/adapters/browser/index.d.ts +5 -2
- package/dist/types/adapters/memory/index.d.cts +17 -2
- package/dist/types/adapters/memory/index.d.ts +17 -2
- package/dist/types/adapters/node/index.d.cts +5 -2
- package/dist/types/adapters/node/index.d.ts +5 -2
- package/dist/types/chunks/{context-BORy7yXb.d.ts → context-CCL0_F8R.d.ts} +65 -39
- package/dist/types/chunks/{context-CMrHCVwK.d.cts → context-YDw6qicq.d.cts} +65 -39
- package/dist/types/chunks/{http-transport-DirKfK2S.d.cts → http-transport--_NdQOiw.d.cts} +1 -1
- package/dist/types/chunks/{http-transport-DirKfK2S.d.ts → http-transport--_NdQOiw.d.ts} +1 -1
- package/dist/types/chunks/index-entry-DtEbVpOG.d.cts +47 -0
- package/dist/types/chunks/index-entry-UD4dvtKh.d.ts +47 -0
- package/dist/types/chunks/progress-7KKiXXfX.d.ts +405 -0
- package/dist/types/chunks/progress-By8yFaUE.d.cts +405 -0
- package/dist/types/chunks/{reflog-entry-C2Hsdobk.d.ts → reflog-entry-BbNnXCTC.d.cts} +17 -3
- package/dist/types/chunks/{reflog-entry-DNvSz7S5.d.cts → reflog-entry-CSzjnZd4.d.ts} +17 -3
- package/dist/types/chunks/{repository-DCR_3RVt.d.cts → repository-BeifCqp0.d.cts} +48 -8
- package/dist/types/chunks/{repository-DFxFeYi3.d.ts → repository-FoS_Laoy.d.ts} +48 -8
- package/dist/types/chunks/{write-tree-CuhpWKFo.d.cts → write-tree-C3oNxOlX.d.cts} +78 -46
- package/dist/types/chunks/{write-tree-Dn1LtIh7.d.ts → write-tree-DRI-LzSr.d.ts} +78 -46
- package/dist/types/commands/index.d.cts +826 -95
- package/dist/types/commands/index.d.ts +826 -95
- package/dist/types/index.browser.d.cts +7 -6
- package/dist/types/index.browser.d.ts +7 -6
- package/dist/types/index.d.cts +278 -53
- package/dist/types/index.d.ts +278 -53
- package/dist/types/index.default.d.cts +7 -6
- package/dist/types/index.default.d.ts +7 -6
- package/dist/types/index.node.d.cts +7 -6
- package/dist/types/index.node.d.ts +7 -6
- package/dist/types/primitives/index.d.cts +260 -12
- package/dist/types/primitives/index.d.ts +260 -12
- package/dist/types/transport/index.d.cts +1 -1
- package/dist/types/transport/index.d.ts +1 -1
- package/package.json +25 -18
- package/dist/cjs/chunks/browser-http-transport-D4NH-8oJ.cjs.map +0 -1
- package/dist/cjs/chunks/error-CDLOBdNU.cjs +0 -2
- package/dist/cjs/chunks/error-CDLOBdNU.cjs.map +0 -1
- package/dist/cjs/chunks/index-BVArBKuk.cjs +0 -2
- package/dist/cjs/chunks/index-BVArBKuk.cjs.map +0 -1
- package/dist/cjs/chunks/index-DE9HSiWf.cjs +0 -2
- package/dist/cjs/chunks/index-DE9HSiWf.cjs.map +0 -1
- package/dist/cjs/chunks/logger-CVG0zcPH.cjs +0 -2
- package/dist/cjs/chunks/logger-CVG0zcPH.cjs.map +0 -1
- package/dist/cjs/chunks/memory-http-transport-DXwDGKtR.cjs +0 -2
- package/dist/cjs/chunks/memory-http-transport-DXwDGKtR.cjs.map +0 -1
- package/dist/cjs/chunks/node-http-transport-vrbnNEDb.cjs +0 -2
- package/dist/cjs/chunks/node-http-transport-vrbnNEDb.cjs.map +0 -1
- package/dist/cjs/chunks/repository-BJwTSiGf.cjs +0 -2
- package/dist/cjs/chunks/repository-BJwTSiGf.cjs.map +0 -1
- package/dist/esm/chunks/browser-http-transport-DL8bkNdg.js.map +0 -1
- package/dist/esm/chunks/error-MOmSzp9Z.js +0 -2
- package/dist/esm/chunks/error-MOmSzp9Z.js.map +0 -1
- package/dist/esm/chunks/index-BjmofbKE.js +0 -2
- package/dist/esm/chunks/index-BjmofbKE.js.map +0 -1
- package/dist/esm/chunks/index-Jh5R-UmU.js +0 -2
- package/dist/esm/chunks/index-Jh5R-UmU.js.map +0 -1
- package/dist/esm/chunks/logger-DP2cCpvL.js +0 -2
- package/dist/esm/chunks/logger-DP2cCpvL.js.map +0 -1
- package/dist/esm/chunks/memory-http-transport-COJU6VOL.js +0 -2
- package/dist/esm/chunks/memory-http-transport-COJU6VOL.js.map +0 -1
- package/dist/esm/chunks/node-http-transport-DYCFIJbc.js +0 -2
- package/dist/esm/chunks/node-http-transport-DYCFIJbc.js.map +0 -1
- package/dist/esm/chunks/progress-NePjO3Kd.js +0 -2
- package/dist/esm/chunks/repository-Cs-dbHqO.js +0 -2
- package/dist/esm/chunks/repository-Cs-dbHqO.js.map +0 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { c as FilePath, O as ObjectId, b as Context, F as FileSystem, H as HashService, C as Compressor, P as ProgressReporter } from './context-CCL0_F8R.js';
|
|
2
|
+
import { F as FileMode, a as Tree } from './reflog-entry-CSzjnZd4.js';
|
|
3
|
+
import { G as GitIndex } from './index-entry-UD4dvtKh.js';
|
|
4
|
+
import { H as HttpTransport } from './http-transport--_NdQOiw.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Platform-abstracted stat shape for working-tree entries. Aligns with
|
|
8
|
+
* `src/ports/file-system.ts:FileStat` — `mtimeNs` and `ino` are optional so
|
|
9
|
+
* the browser adapter (which exposes neither) can satisfy the shape.
|
|
10
|
+
*
|
|
11
|
+
* `mode` is included so race detection covers chmod-only changes
|
|
12
|
+
* (executable-bit flips, permission tweaks). Racy-stat detection prefers
|
|
13
|
+
* `mtimeNs` when present, falls back to `mtimeMs`, and falls back further
|
|
14
|
+
* to SHA-trailer comparison for the index file specifically.
|
|
15
|
+
*/
|
|
16
|
+
interface WorkdirStat {
|
|
17
|
+
readonly mode: FileMode;
|
|
18
|
+
readonly size: number;
|
|
19
|
+
readonly mtimeMs: number;
|
|
20
|
+
readonly mtimeNs?: bigint;
|
|
21
|
+
readonly ino?: bigint;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pure data shape for a working-tree row. `kind` discriminates the four
|
|
25
|
+
* entry shapes the walker emits; the surfaced `mode` field mirrors
|
|
26
|
+
* `stat.mode` for ergonomic access.
|
|
27
|
+
*/
|
|
28
|
+
interface WorkdirEntryRow {
|
|
29
|
+
readonly source: 'workdir';
|
|
30
|
+
readonly path: FilePath;
|
|
31
|
+
readonly mode: FileMode;
|
|
32
|
+
readonly kind: 'file' | 'symlink' | 'directory' | 'submodule';
|
|
33
|
+
readonly stat: WorkdirStat;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A compiled glob — `test` reports whether a path matches the pattern. */
|
|
37
|
+
interface GlobMatcher {
|
|
38
|
+
test(path: string): boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PathspecEntry {
|
|
42
|
+
/** Original raw pattern (including any leading `!`), for diagnostics. */
|
|
43
|
+
readonly pattern: string;
|
|
44
|
+
/** Pattern with the leading `!` (if any) stripped — the part that compiled to `compiled`. */
|
|
45
|
+
readonly body: string;
|
|
46
|
+
/** True when the original pattern started with `!`. */
|
|
47
|
+
readonly negated: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* True when the body (post-`!`) contains no glob metacharacters.
|
|
50
|
+
* Literal entries match the exact path AND any descendant — Git's
|
|
51
|
+
* `git add src` semantics where `src` covers everything under it.
|
|
52
|
+
*/
|
|
53
|
+
readonly isLiteral: boolean;
|
|
54
|
+
/** Compiled glob matcher. Always tested against the candidate path verbatim. */
|
|
55
|
+
readonly compiled: GlobMatcher;
|
|
56
|
+
}
|
|
57
|
+
type Pathspec = ReadonlyArray<PathspecEntry>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Three index-entry boolean flags lifted out of git's wire format. Each is
|
|
61
|
+
* a real index attribute; they collectively cover the bits status / add /
|
|
62
|
+
* checkout consult.
|
|
63
|
+
*
|
|
64
|
+
* - `assumeUnchanged` (git-update-index `--assume-unchanged`): the user has
|
|
65
|
+
* promised the file does not change; tools may skip stat checks.
|
|
66
|
+
* - `skipWorktree` (sparse-checkout): the file is tracked but should not be
|
|
67
|
+
* materialized in the working tree.
|
|
68
|
+
* - `intentToAdd` (`git add --intent-to-add`): the entry exists with mode +
|
|
69
|
+
* path but its content has not yet been staged; oid is the empty blob.
|
|
70
|
+
*/
|
|
71
|
+
interface IndexFlags {
|
|
72
|
+
readonly assumeUnchanged: boolean;
|
|
73
|
+
readonly skipWorktree: boolean;
|
|
74
|
+
readonly intentToAdd: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Stat snapshot persisted alongside each index entry by git's stat-cache.
|
|
78
|
+
* May be stale (the file may have been modified since the index was
|
|
79
|
+
* written); validity is determined by comparing against a fresh `lstat`
|
|
80
|
+
* per git's racy-stat rules. Fields mirror the optional-precision shape
|
|
81
|
+
* already used by `src/ports/file-system.ts:FileStat`.
|
|
82
|
+
*/
|
|
83
|
+
interface IndexCachedStat {
|
|
84
|
+
readonly mtimeMs: number;
|
|
85
|
+
readonly mtimeNs?: bigint;
|
|
86
|
+
readonly size: number;
|
|
87
|
+
readonly ino?: bigint;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Pure data shape for an index-source row. Stage > 0 means the entry is
|
|
91
|
+
* part of an unmerged path (1 = base, 2 = ours, 3 = theirs); stage 0 is
|
|
92
|
+
* the resolved / normal entry.
|
|
93
|
+
*/
|
|
94
|
+
interface IndexEntryRow {
|
|
95
|
+
readonly source: 'index';
|
|
96
|
+
readonly path: FilePath;
|
|
97
|
+
readonly oid: ObjectId;
|
|
98
|
+
readonly mode: FileMode;
|
|
99
|
+
readonly stage: 0 | 1 | 2 | 3;
|
|
100
|
+
readonly flags: IndexFlags;
|
|
101
|
+
readonly cachedStat?: IndexCachedStat;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Discriminator for snapshot sources. Each `Snapshot` handle carries a
|
|
106
|
+
* `kind` field so consumers can dispatch on the underlying source at
|
|
107
|
+
* runtime (matching the static discriminator on the entry's `source` field).
|
|
108
|
+
*
|
|
109
|
+
* Compound state heads (`mergeHead`, `cherryPickHead`, etc.) resolve to a
|
|
110
|
+
* tree but advertise their own kind so callers can distinguish a
|
|
111
|
+
* fresh-cloned `head` from a `mergeHead` at the snapshot-handle level.
|
|
112
|
+
*/
|
|
113
|
+
type SnapshotKind = 'tree' | 'commit' | 'index' | 'workdir' | 'mergeHead' | 'cherryPickHead' | 'revertHead' | 'fetchHead' | 'stash';
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Pure data shape for a tree-source row. Carried inside `TreeEntry`
|
|
117
|
+
* (application tier) which adds I/O methods. Domain layering rule:
|
|
118
|
+
* this file has zero outward imports beyond `domain/objects/`.
|
|
119
|
+
*/
|
|
120
|
+
interface TreeEntryRow {
|
|
121
|
+
readonly source: 'tree';
|
|
122
|
+
readonly path: FilePath;
|
|
123
|
+
readonly oid: ObjectId;
|
|
124
|
+
readonly mode: FileMode;
|
|
125
|
+
readonly kind: 'file' | 'symlink' | 'submodule';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Options shared by every resolver port. The `bypassCache` flag asks a
|
|
130
|
+
* caching adapter to skip its cache for this call; raw adapters ignore it.
|
|
131
|
+
*/
|
|
132
|
+
interface ResolveOptions {
|
|
133
|
+
readonly bypassCache?: boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Predicate used by `WorkdirEnumerator` to prune working-tree traversal.
|
|
137
|
+
* Mirrors the existing `WalkIgnorePredicate` shape (14.3) so the same
|
|
138
|
+
* `repo.ignoreMatcher()` builder can be used at both the legacy walker
|
|
139
|
+
* surface and the new snapshot surface.
|
|
140
|
+
*
|
|
141
|
+
* Invoked on every directory BEFORE descent (returning `true` prunes the
|
|
142
|
+
* entire subtree, skipping its `lstat` cost) and on every leaf BEFORE
|
|
143
|
+
* yielding (returning `true` drops the leaf). Composes with `paths`
|
|
144
|
+
* (pathspec inclusion filter) via logical AND.
|
|
145
|
+
*/
|
|
146
|
+
type WalkIgnorePredicate = (path: FilePath, isDirectory: boolean) => boolean | Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* Options for `WorkdirEnumerator.enumerate`. The snapshot layer translates
|
|
149
|
+
* `WorkdirSnapshotOptions` (which carries higher-level concerns like
|
|
150
|
+
* `consistency`) down to this shape; the enumerator port itself stays
|
|
151
|
+
* focused on what to enumerate.
|
|
152
|
+
*/
|
|
153
|
+
interface WorkdirEnumOptions {
|
|
154
|
+
readonly paths?: Pathspec;
|
|
155
|
+
readonly excludes?: WalkIgnorePredicate;
|
|
156
|
+
readonly maxDepth?: number;
|
|
157
|
+
readonly maxEntries?: number;
|
|
158
|
+
readonly signal?: AbortSignal;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolves `.git/index` to its parsed `GitIndex` structure. Caching
|
|
162
|
+
* adapters (see `src/adapters/snapshot-resolvers/caching-index-resolver.ts`)
|
|
163
|
+
* implement freshness via the `WriteEventStream` + `GenerationView` ports;
|
|
164
|
+
* raw adapters parse on every call.
|
|
165
|
+
*
|
|
166
|
+
* Callers MUST treat the returned value as deeply frozen — implementations
|
|
167
|
+
* are free to share the same `GitIndex` reference across calls.
|
|
168
|
+
*/
|
|
169
|
+
interface IndexResolver {
|
|
170
|
+
resolve(ctx: Context, opts?: ResolveOptions): Promise<GitIndex>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolves a tree object by its oid. Caching adapters use a content-addressed
|
|
174
|
+
* LRU (oids are immutable, no invalidation needed). Throws on type
|
|
175
|
+
* mismatch — the oid must address a tree.
|
|
176
|
+
*/
|
|
177
|
+
interface TreeResolver {
|
|
178
|
+
resolve(ctx: Context, treeId: ObjectId, opts?: ResolveOptions): Promise<Tree>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Streams working-tree entries in canonical git path order. Honors
|
|
182
|
+
* `ctx.signal` and the optional `opts.signal`; aborts surface as
|
|
183
|
+
* `operationAborted()` from the iterator.
|
|
184
|
+
*/
|
|
185
|
+
interface WorkdirEnumerator {
|
|
186
|
+
enumerate(ctx: Context, opts: WorkdirEnumOptions): AsyncIterable<WorkdirEntryRow>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Application-tier wrapper around `IndexEntryRow`. Inherits the sync data
|
|
191
|
+
* fields (path/oid/mode/stage/flags/cachedStat) and adds `read()`, which
|
|
192
|
+
* pulls the blob bytes by oid via the existing object resolver chain.
|
|
193
|
+
*
|
|
194
|
+
* Index entries' `cachedStat` reflects the index's stat-cache; it MAY
|
|
195
|
+
* disagree with the live filesystem. Consumers that need fresh stat
|
|
196
|
+
* data should consult a `WorkdirSnapshot` instead.
|
|
197
|
+
*/
|
|
198
|
+
interface IndexEntry extends IndexEntryRow {
|
|
199
|
+
read(): Promise<Uint8Array>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Application-tier wrapper around `TreeEntryRow`. Inherits the sync data
|
|
204
|
+
* fields (path/oid/mode/kind) and adds the I/O method `read()`, which
|
|
205
|
+
* pulls the blob bytes for this entry's oid via the existing object
|
|
206
|
+
* resolver chain.
|
|
207
|
+
*
|
|
208
|
+
* Each entry binds to the `Context` it was created with. Holding an entry
|
|
209
|
+
* past its context's lifetime is undefined — the resolver may reject the
|
|
210
|
+
* read with an aborted-operation error if the context's signal fires.
|
|
211
|
+
*/
|
|
212
|
+
interface TreeEntry extends TreeEntryRow {
|
|
213
|
+
read(): Promise<Uint8Array>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Application-tier wrapper around `WorkdirEntryRow`. Inherits the sync
|
|
218
|
+
* data fields (path/mode/kind/stat) and adds four named I/O methods:
|
|
219
|
+
*
|
|
220
|
+
* - `hash()` — reads the file, computes its blob-hash (`blob <size>\0` +
|
|
221
|
+
* bytes hashed by `ctx.hash`). For a symlink, hashes the
|
|
222
|
+
* link target bytes (git's convention).
|
|
223
|
+
* - `read()` — raw file bytes (no hash). For a symlink, returns the
|
|
224
|
+
* target as UTF-8 bytes.
|
|
225
|
+
* - `readLink()` — symlink target string. Throws `UNSUPPORTED_OPERATION`
|
|
226
|
+
* when `kind !== 'symlink'`.
|
|
227
|
+
* - `verify()` — re-`lstat`s the entry; throws `WORKDIR_RACE` if any
|
|
228
|
+
* of `(mode, size, mtimeMs)` differs from the row's
|
|
229
|
+
* original stat. The opt-in race-detection hook for
|
|
230
|
+
* `add -p` / `checkout --detect-races` style callers.
|
|
231
|
+
*
|
|
232
|
+
* Each entry binds to the `Context` it was created with; the absolute
|
|
233
|
+
* workdir path is computed once at creation and shared by every method.
|
|
234
|
+
*/
|
|
235
|
+
interface WorkdirEntry extends WorkdirEntryRow {
|
|
236
|
+
hash(): Promise<ObjectId>;
|
|
237
|
+
read(): Promise<Uint8Array>;
|
|
238
|
+
readLink(): Promise<string>;
|
|
239
|
+
verify(): Promise<void>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Lazy, atomic-iteration view of a row source (tree / index / workdir / …).
|
|
244
|
+
* Snapshots are descriptions, not data — no I/O happens until the consumer
|
|
245
|
+
* starts iterating. See design §8 and ADR-149.
|
|
246
|
+
*
|
|
247
|
+
* Iteration-stability invariant: once a snapshot's `entries()` resolves its
|
|
248
|
+
* underlying source on the first iteration, every subsequent iteration on
|
|
249
|
+
* the same handle replays from that captured source. Concurrent writes
|
|
250
|
+
* routed through `WriteEventEmitter.emit(scope)` invalidate the underlying
|
|
251
|
+
* resolver cache for *new* snapshots but never disturb in-flight iterations.
|
|
252
|
+
*/
|
|
253
|
+
interface Snapshot<E extends SnapshotEntry> {
|
|
254
|
+
readonly kind: SnapshotKind;
|
|
255
|
+
entries(opts?: SnapshotOptions): AsyncIterable<E>;
|
|
256
|
+
}
|
|
257
|
+
type SnapshotEntry = TreeEntry | IndexEntry | WorkdirEntry;
|
|
258
|
+
type TreeSnapshot = Snapshot<TreeEntry>;
|
|
259
|
+
type IndexSnapshot = Snapshot<IndexEntry>;
|
|
260
|
+
type WorkdirSnapshot = Snapshot<WorkdirEntry>;
|
|
261
|
+
interface SnapshotOptions {
|
|
262
|
+
readonly paths?: Pathspec;
|
|
263
|
+
readonly recurse?: boolean;
|
|
264
|
+
readonly maxDepth?: number;
|
|
265
|
+
readonly maxEntries?: number;
|
|
266
|
+
readonly bypassCache?: boolean;
|
|
267
|
+
readonly signal?: AbortSignal;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A point-in-time view of a stash entry. The trio (index, workdir,
|
|
272
|
+
* untracked) is exposed as plain properties — discoverable at hand-out
|
|
273
|
+
* time, not behind a method (ADR-156 + design §9.1).
|
|
274
|
+
*
|
|
275
|
+
* `untracked` is `null` when the stash was created without
|
|
276
|
+
* `--include-untracked`. Consumers branch on the property's value, not
|
|
277
|
+
* on whether a method exists.
|
|
278
|
+
*/
|
|
279
|
+
interface StashSnapshot {
|
|
280
|
+
readonly kind: 'stash';
|
|
281
|
+
readonly index: TreeSnapshot;
|
|
282
|
+
readonly workdir: TreeSnapshot;
|
|
283
|
+
readonly untracked: TreeSnapshot | null;
|
|
284
|
+
}
|
|
285
|
+
declare const createStashSnapshot: (parts: {
|
|
286
|
+
readonly index: TreeSnapshot;
|
|
287
|
+
readonly workdir: TreeSnapshot;
|
|
288
|
+
readonly untracked: TreeSnapshot | null;
|
|
289
|
+
}) => StashSnapshot;
|
|
290
|
+
|
|
291
|
+
interface WorkdirSnapshotOptions extends SnapshotOptions {
|
|
292
|
+
readonly excludes?: WalkIgnorePredicate;
|
|
293
|
+
readonly consistency?: 'eager' | 'verified';
|
|
294
|
+
}
|
|
295
|
+
interface WorkdirSnapshotDeps {
|
|
296
|
+
readonly ctx: Context;
|
|
297
|
+
readonly enumerator: WorkdirEnumerator;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Lazily streams working-tree entries via `WorkdirEnumerator`. Excludes
|
|
301
|
+
* and consistency are captured at factory time (per design §8.2 boundary
|
|
302
|
+
* table); the iteration-level option bundle accepts only the base
|
|
303
|
+
* `SnapshotOptions` overrides.
|
|
304
|
+
*
|
|
305
|
+
* - `'eager'` (default) — stream rows straight from the enumerator;
|
|
306
|
+
* race detection is opt-in via `entry.verify()` per row.
|
|
307
|
+
* - `'verified'` — drain the enumerator into an array first, then
|
|
308
|
+
* yield in stored order. Provides an atomic point-in-time view of
|
|
309
|
+
* which paths existed at enumerate-time; per-row content is still
|
|
310
|
+
* subject to mutation between yield and consumption.
|
|
311
|
+
*
|
|
312
|
+
* `bypassCache` and `recurse` are no-ops here — the working tree has
|
|
313
|
+
* no resolver cache, and enumeration is inherently recursive.
|
|
314
|
+
*/
|
|
315
|
+
declare const createWorkdirSnapshot: (deps: WorkdirSnapshotDeps, fixed?: WorkdirSnapshotOptions) => Snapshot<WorkdirEntry>;
|
|
316
|
+
|
|
317
|
+
interface SnapshotFactoryDeps {
|
|
318
|
+
readonly ctx: Context;
|
|
319
|
+
readonly indexResolver: IndexResolver;
|
|
320
|
+
readonly treeResolver: TreeResolver;
|
|
321
|
+
readonly workdirEnumerator: WorkdirEnumerator;
|
|
322
|
+
}
|
|
323
|
+
interface SnapshotFactory {
|
|
324
|
+
head(opts?: SnapshotOptions): TreeSnapshot;
|
|
325
|
+
commit(oid: ObjectId, opts?: SnapshotOptions): TreeSnapshot;
|
|
326
|
+
tree(oid: ObjectId, opts?: SnapshotOptions): TreeSnapshot;
|
|
327
|
+
index(opts?: SnapshotOptions): IndexSnapshot;
|
|
328
|
+
workdir(opts?: WorkdirSnapshotOptions): WorkdirSnapshot;
|
|
329
|
+
mergeHead(opts?: SnapshotOptions): Promise<TreeSnapshot | null>;
|
|
330
|
+
cherryPickHead(opts?: SnapshotOptions): Promise<TreeSnapshot | null>;
|
|
331
|
+
revertHead(opts?: SnapshotOptions): Promise<TreeSnapshot | null>;
|
|
332
|
+
fetchHead(opts?: SnapshotOptions): Promise<TreeSnapshot | null>;
|
|
333
|
+
stashEntry(stashIndex: number, opts?: SnapshotOptions): Promise<StashSnapshot | null>;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Pulls the resolvers, enumerator, and `Context` together behind a
|
|
337
|
+
* single facade. Every factory method either is purely synchronous
|
|
338
|
+
* (`head`, `commit`, `tree`, `index`, `workdir`) or returns a promise
|
|
339
|
+
* solely because it has to check ref-file existence first. None of
|
|
340
|
+
* them parse the underlying source until the returned snapshot is
|
|
341
|
+
* iterated (design §9 construction discipline).
|
|
342
|
+
*/
|
|
343
|
+
declare const createSnapshotFactory: (deps: SnapshotFactoryDeps) => SnapshotFactory;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* The four adapter ports the facade plumbs into the Context. Each runtime
|
|
347
|
+
* shim (`index.node.ts`, `index.browser.ts`, `index.default.ts` — wired in
|
|
348
|
+
* Step 5) provides a `detectAdapter(): AdapterSet` that returns the runtime-
|
|
349
|
+
* appropriate set.
|
|
350
|
+
*/
|
|
351
|
+
interface AdapterSet {
|
|
352
|
+
readonly fs: FileSystem;
|
|
353
|
+
readonly hash: HashService;
|
|
354
|
+
readonly compressor: Compressor;
|
|
355
|
+
readonly transport: HttpTransport;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Prototype-pollution-safe runtime check. Returns true only when `process` is
|
|
359
|
+
* an object that owns BOTH `versions` and `versions.node` as own properties —
|
|
360
|
+
* an attacker who pollutes `Object.prototype.versions` cannot make this
|
|
361
|
+
* return true.
|
|
362
|
+
*
|
|
363
|
+
* Used as a manual fallback only; the primary detection mechanism is
|
|
364
|
+
* `package.json` conditional exports (resolved at bundle time, immune to
|
|
365
|
+
* runtime pollution).
|
|
366
|
+
*/
|
|
367
|
+
declare const isNode: () => boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Returns true when both `window` and `navigator` exist AS OWN globals on
|
|
370
|
+
* `globalThis` AND have non-undefined values. Two-stage check:
|
|
371
|
+
* - `hasOwn` rejects properties inherited from a polluted `Object.prototype`.
|
|
372
|
+
* - `typeof` rejects own properties that have been assigned `undefined`
|
|
373
|
+
* (e.g., test harnesses that stub the global to undefined).
|
|
374
|
+
*/
|
|
375
|
+
declare const isBrowser: () => boolean;
|
|
376
|
+
/**
|
|
377
|
+
* Three-way runtime classification used by manual call sites. Node takes
|
|
378
|
+
* precedence over browser when both look present (e.g., test environments
|
|
379
|
+
* with jsdom + a real Node process).
|
|
380
|
+
*/
|
|
381
|
+
declare const detectRuntime: () => "node" | "browser" | "memory";
|
|
382
|
+
|
|
383
|
+
/** No-op reporter — default when the caller does not provide one. */
|
|
384
|
+
declare const noopProgress: ProgressReporter;
|
|
385
|
+
/**
|
|
386
|
+
* Built-in reporter that emits one line per call to a user-supplied `sink`.
|
|
387
|
+
*
|
|
388
|
+
* Format:
|
|
389
|
+
* start(op) → "<safeOp>: start"
|
|
390
|
+
* start(op, total) → "<safeOp>: start/<total>"
|
|
391
|
+
* update(op, c) → "<safeOp>: <c>"
|
|
392
|
+
* update(op, c, t) → "<safeOp>: <c>/<t>"
|
|
393
|
+
* update(op, c, t, txt) → "<safeOp>: <c>/<t> <safeText>"
|
|
394
|
+
* end(op) → "<safeOp>: done"
|
|
395
|
+
*
|
|
396
|
+
* `op` is sanitized identically to `text` (defense-in-depth: a programming bug
|
|
397
|
+
* that wires a sideband-derived string into `op` cannot inject control characters).
|
|
398
|
+
*
|
|
399
|
+
* A throwing `sink` cannot crash the reporter — every call is wrapped in
|
|
400
|
+
* try/catch.
|
|
401
|
+
*/
|
|
402
|
+
declare const consoleProgress: (sink: (line: string) => void) => ProgressReporter;
|
|
403
|
+
|
|
404
|
+
export { isNode as a, consoleProgress as c, detectRuntime as d, isBrowser as i, noopProgress as n, createSnapshotFactory as u, createStashSnapshot as v, createWorkdirSnapshot as w };
|
|
405
|
+
export type { AdapterSet as A, IndexResolver as I, ResolveOptions as R, SnapshotFactory as S, TreeResolver as T, WalkIgnorePredicate as W, Snapshot as b, IndexEntry as e, SnapshotEntry as f, TreeEntry as g, IndexSnapshot as h, SnapshotFactoryDeps as j, SnapshotOptions as k, StashSnapshot as l, TreeSnapshot as m, WorkdirEntry as o, WorkdirEnumOptions as p, WorkdirEnumerator as q, WorkdirSnapshot as r, WorkdirSnapshotDeps as s, WorkdirSnapshotOptions as t };
|