git-fs-s3 0.3.5
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/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/chunk-4QPWSRYC.js +123 -0
- package/dist/chunk-4QPWSRYC.js.map +1 -0
- package/dist/chunk-T5NHPY7U.js +118 -0
- package/dist/chunk-T5NHPY7U.js.map +1 -0
- package/dist/http.cjs +692 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +197 -0
- package/dist/http.d.ts +197 -0
- package/dist/http.js +594 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +801 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +373 -0
- package/dist/index.d.ts +373 -0
- package/dist/index.js +568 -0
- package/dist/index.js.map +1 -0
- package/dist/ops.cjs +1021 -0
- package/dist/ops.cjs.map +1 -0
- package/dist/ops.d.cts +290 -0
- package/dist/ops.d.ts +290 -0
- package/dist/ops.js +889 -0
- package/dist/ops.js.map +1 -0
- package/dist/s3.cjs +123 -0
- package/dist/s3.cjs.map +1 -0
- package/dist/s3.d.cts +36 -0
- package/dist/s3.d.ts +36 -0
- package/dist/s3.js +104 -0
- package/dist/s3.js.map +1 -0
- package/dist/types-BHoHOaQt.d.cts +53 -0
- package/dist/types-BHoHOaQt.d.ts +53 -0
- package/dist/types-QgIkUR_q.d.cts +121 -0
- package/dist/types-QgIkUR_q.d.ts +121 -0
- package/package.json +104 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GitAuthenticationError,
|
|
3
|
+
GitAuthorizationError,
|
|
4
|
+
GitConflictError,
|
|
5
|
+
GitError,
|
|
6
|
+
GitInvalidRequestError,
|
|
7
|
+
GitObjectNotFoundError,
|
|
8
|
+
GitPathNotFoundError,
|
|
9
|
+
GitProtocolError,
|
|
10
|
+
GitRateLimitError,
|
|
11
|
+
GitRefNotFoundError,
|
|
12
|
+
GitRepositoryNotFoundError,
|
|
13
|
+
formatErrorResponse
|
|
14
|
+
} from "./chunk-T5NHPY7U.js";
|
|
15
|
+
import {
|
|
16
|
+
concat,
|
|
17
|
+
decodeAscii,
|
|
18
|
+
decodeUtf8,
|
|
19
|
+
deflate,
|
|
20
|
+
encodeUtf8,
|
|
21
|
+
fromHex,
|
|
22
|
+
hasNullByte,
|
|
23
|
+
isFullSha,
|
|
24
|
+
isSafeBranchName,
|
|
25
|
+
isSafeFullRefName,
|
|
26
|
+
isSafeRefName,
|
|
27
|
+
isSafeRepoPath,
|
|
28
|
+
qualifyBranchRef,
|
|
29
|
+
readBlobContent,
|
|
30
|
+
sha1,
|
|
31
|
+
toBase64,
|
|
32
|
+
toHex
|
|
33
|
+
} from "./chunk-4QPWSRYC.js";
|
|
34
|
+
|
|
35
|
+
// src/cache.ts
|
|
36
|
+
import { LRUCache } from "lru-cache";
|
|
37
|
+
var MISS = /* @__PURE__ */ Symbol("miss");
|
|
38
|
+
function listEntrySize(entry) {
|
|
39
|
+
let size = entry.prefix.length + 16;
|
|
40
|
+
for (const o of entry.result.objects) size += o.key.length + 8;
|
|
41
|
+
for (const p of entry.result.prefixes) size += p.length;
|
|
42
|
+
return size;
|
|
43
|
+
}
|
|
44
|
+
function copyListResult(result) {
|
|
45
|
+
return {
|
|
46
|
+
objects: result.objects.map((o) => ({ ...o })),
|
|
47
|
+
prefixes: [...result.prefixes]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createCachedStore(store, options = {}) {
|
|
51
|
+
const maxBytes = options.maxBytes ?? 50 * 1024 * 1024;
|
|
52
|
+
const maxEntryBytes = options.maxEntryBytes ?? Math.ceil(maxBytes / 10);
|
|
53
|
+
const ttl = options.ttlMs ?? 6e4;
|
|
54
|
+
const ttlForKey = options.ttlForKey;
|
|
55
|
+
const cacheMisses = options.cacheMisses ?? false;
|
|
56
|
+
const cacheLists = options.cacheLists ?? false;
|
|
57
|
+
const coalesce = options.coalesce ?? true;
|
|
58
|
+
const onHit = options.onHit;
|
|
59
|
+
const onMiss = options.onMiss;
|
|
60
|
+
const cache = new LRUCache({
|
|
61
|
+
maxSize: maxBytes,
|
|
62
|
+
sizeCalculation: (value) => value === MISS ? 1 : value.byteLength || 1,
|
|
63
|
+
ttl
|
|
64
|
+
});
|
|
65
|
+
const listCache = new LRUCache({
|
|
66
|
+
maxSize: Math.max(1, Math.ceil(maxBytes / 10)),
|
|
67
|
+
sizeCalculation: listEntrySize,
|
|
68
|
+
ttl
|
|
69
|
+
});
|
|
70
|
+
const pendingGets = /* @__PURE__ */ new Map();
|
|
71
|
+
const pendingHeads = /* @__PURE__ */ new Map();
|
|
72
|
+
const pendingLists = /* @__PURE__ */ new Map();
|
|
73
|
+
const admit = (key, data) => {
|
|
74
|
+
if (data.byteLength <= maxEntryBytes) {
|
|
75
|
+
cache.set(key, data.slice(), { ttl: ttlForKey?.(key) });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function clearStaleListEntries(key) {
|
|
79
|
+
for (const [listKey, entry] of listCache.entries()) {
|
|
80
|
+
if (!key.startsWith(entry.prefix)) continue;
|
|
81
|
+
if (entry.probe && !entry.empty) continue;
|
|
82
|
+
listCache.delete(listKey);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function coalesced(pending, key, fn) {
|
|
86
|
+
if (!coalesce) return fn();
|
|
87
|
+
const inflight = pending.get(key);
|
|
88
|
+
if (inflight !== void 0) return inflight;
|
|
89
|
+
const p = fn().finally(() => pending.delete(key));
|
|
90
|
+
pending.set(key, p);
|
|
91
|
+
return p;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
async get(key) {
|
|
95
|
+
const cached = cache.get(key);
|
|
96
|
+
if (cached !== void 0) {
|
|
97
|
+
onHit?.(key);
|
|
98
|
+
return cached === MISS ? null : cached.slice();
|
|
99
|
+
}
|
|
100
|
+
const data = await coalesced(pendingGets, key, async () => {
|
|
101
|
+
onMiss?.(key);
|
|
102
|
+
const fetched = await store.get(key);
|
|
103
|
+
if (fetched !== null) {
|
|
104
|
+
admit(key, fetched);
|
|
105
|
+
} else if (cacheMisses) {
|
|
106
|
+
cache.set(key, MISS, { ttl: ttlForKey?.(key) });
|
|
107
|
+
}
|
|
108
|
+
return fetched;
|
|
109
|
+
});
|
|
110
|
+
return data === null ? null : data.slice();
|
|
111
|
+
},
|
|
112
|
+
async put(key, data) {
|
|
113
|
+
await store.put(key, data);
|
|
114
|
+
admit(key, data);
|
|
115
|
+
if (data.byteLength > maxEntryBytes) cache.delete(key);
|
|
116
|
+
clearStaleListEntries(key);
|
|
117
|
+
},
|
|
118
|
+
async delete(key) {
|
|
119
|
+
await store.delete(key);
|
|
120
|
+
if (cacheMisses) {
|
|
121
|
+
cache.set(key, MISS, { ttl: ttlForKey?.(key) });
|
|
122
|
+
} else {
|
|
123
|
+
cache.delete(key);
|
|
124
|
+
}
|
|
125
|
+
clearStaleListEntries(key);
|
|
126
|
+
},
|
|
127
|
+
async head(key) {
|
|
128
|
+
const cached = cache.get(key);
|
|
129
|
+
if (cached !== void 0) {
|
|
130
|
+
onHit?.(key);
|
|
131
|
+
return cached === MISS ? null : { size: cached.byteLength };
|
|
132
|
+
}
|
|
133
|
+
return coalesced(pendingHeads, key, async () => {
|
|
134
|
+
onMiss?.(key);
|
|
135
|
+
const stat = await store.head(key);
|
|
136
|
+
if (stat === null && cacheMisses) {
|
|
137
|
+
cache.set(key, MISS, { ttl: ttlForKey?.(key) });
|
|
138
|
+
}
|
|
139
|
+
return stat;
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
async list(prefix, listOptions) {
|
|
143
|
+
if (!cacheLists) return store.list(prefix, listOptions);
|
|
144
|
+
const listKey = `${listOptions?.delimiter ?? ""}|${listOptions?.limit ?? ""}|${prefix}`;
|
|
145
|
+
const cached = listCache.get(listKey);
|
|
146
|
+
if (cached !== void 0) {
|
|
147
|
+
onHit?.(prefix);
|
|
148
|
+
return copyListResult(cached.result);
|
|
149
|
+
}
|
|
150
|
+
const result = await coalesced(pendingLists, listKey, async () => {
|
|
151
|
+
onMiss?.(prefix);
|
|
152
|
+
const fetched = await store.list(prefix, listOptions);
|
|
153
|
+
listCache.set(
|
|
154
|
+
listKey,
|
|
155
|
+
{
|
|
156
|
+
result: copyListResult(fetched),
|
|
157
|
+
prefix,
|
|
158
|
+
probe: listOptions?.limit === 1,
|
|
159
|
+
empty: fetched.objects.length === 0 && fetched.prefixes.length === 0
|
|
160
|
+
},
|
|
161
|
+
{ ttl: ttlForKey?.(prefix) }
|
|
162
|
+
);
|
|
163
|
+
return fetched;
|
|
164
|
+
});
|
|
165
|
+
return copyListResult(result);
|
|
166
|
+
},
|
|
167
|
+
invalidate(prefix) {
|
|
168
|
+
for (const key of cache.keys()) {
|
|
169
|
+
if (key.startsWith(prefix)) cache.delete(key);
|
|
170
|
+
}
|
|
171
|
+
for (const [listKey, entry] of listCache.entries()) {
|
|
172
|
+
if (entry.prefix.startsWith(prefix) || prefix.startsWith(entry.prefix)) {
|
|
173
|
+
listCache.delete(listKey);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/errors.ts
|
|
181
|
+
var FsError = class extends Error {
|
|
182
|
+
code;
|
|
183
|
+
syscall;
|
|
184
|
+
path;
|
|
185
|
+
constructor(code, syscall, path) {
|
|
186
|
+
super(`${code}: ${syscall} '${path}'`);
|
|
187
|
+
this.name = "FsError";
|
|
188
|
+
this.code = code;
|
|
189
|
+
this.syscall = syscall;
|
|
190
|
+
this.path = path;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var enoent = (syscall, path) => new FsError("ENOENT", syscall, path);
|
|
194
|
+
var enotdir = (syscall, path) => new FsError("ENOTDIR", syscall, path);
|
|
195
|
+
var enotempty = (syscall, path) => new FsError("ENOTEMPTY", syscall, path);
|
|
196
|
+
var einval = (syscall, path) => new FsError("EINVAL", syscall, path);
|
|
197
|
+
var eperm = (syscall, path) => new FsError("EPERM", syscall, path);
|
|
198
|
+
|
|
199
|
+
// src/git-fs.ts
|
|
200
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
201
|
+
|
|
202
|
+
// src/path.ts
|
|
203
|
+
function normalizePath(filepath) {
|
|
204
|
+
const segments = filepath.split("/");
|
|
205
|
+
const out = [];
|
|
206
|
+
for (const segment of segments) {
|
|
207
|
+
if (segment === "" || segment === ".") continue;
|
|
208
|
+
if (segment === "..") {
|
|
209
|
+
if (out.length === 0) throw einval("resolve", filepath);
|
|
210
|
+
out.pop();
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
out.push(segment);
|
|
214
|
+
}
|
|
215
|
+
return out.join("/");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/git-fs.ts
|
|
219
|
+
var FILE_MODE = 33188;
|
|
220
|
+
var DIR_MODE = 16384;
|
|
221
|
+
var LOOSE_OBJECT_RE = /(^|\/)objects\/[0-9a-f]{2}\/[0-9a-f]{38}$/;
|
|
222
|
+
var textEncoder = new TextEncoder();
|
|
223
|
+
var textDecoder = new TextDecoder();
|
|
224
|
+
function makeStat(type, size) {
|
|
225
|
+
const epoch = /* @__PURE__ */ new Date(0);
|
|
226
|
+
return {
|
|
227
|
+
type,
|
|
228
|
+
mode: type === "file" ? FILE_MODE : DIR_MODE,
|
|
229
|
+
size,
|
|
230
|
+
ino: 0,
|
|
231
|
+
mtimeMs: 0,
|
|
232
|
+
ctimeMs: 0,
|
|
233
|
+
uid: 0,
|
|
234
|
+
gid: 0,
|
|
235
|
+
dev: 0,
|
|
236
|
+
mtime: epoch,
|
|
237
|
+
ctime: epoch,
|
|
238
|
+
isFile: () => type === "file",
|
|
239
|
+
isDirectory: () => type === "dir",
|
|
240
|
+
isSymbolicLink: () => false
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function resolveEncoding(options) {
|
|
244
|
+
if (typeof options === "string") return options;
|
|
245
|
+
return options?.encoding;
|
|
246
|
+
}
|
|
247
|
+
function createGitFs(store, options = {}) {
|
|
248
|
+
const prefix = options.prefix ?? "";
|
|
249
|
+
const structurallyAbsent = options.isStructurallyAbsent;
|
|
250
|
+
const useLooseHints = options.looseObjectHints ?? false;
|
|
251
|
+
const onNote = options.onNote;
|
|
252
|
+
const toKey = (path) => {
|
|
253
|
+
if (prefix === "") return path;
|
|
254
|
+
return path === "" ? prefix : `${prefix}/${path}`;
|
|
255
|
+
};
|
|
256
|
+
const looseHints = new LRUCache2({
|
|
257
|
+
max: 1024,
|
|
258
|
+
ttl: options.hintTtlMs ?? 36e5
|
|
259
|
+
});
|
|
260
|
+
function looseScope(path) {
|
|
261
|
+
const match = LOOSE_OBJECT_RE.exec(path);
|
|
262
|
+
if (match === null) return null;
|
|
263
|
+
return path.slice(0, match.index);
|
|
264
|
+
}
|
|
265
|
+
function knownAbsent(path) {
|
|
266
|
+
if (structurallyAbsent?.(path)) return true;
|
|
267
|
+
if (!useLooseHints) return false;
|
|
268
|
+
const scope = looseScope(path);
|
|
269
|
+
return scope !== null && looseHints.get(scope) === "none";
|
|
270
|
+
}
|
|
271
|
+
async function isDirectory(dirKey) {
|
|
272
|
+
const { objects, prefixes } = await store.list(`${dirKey}/`, {
|
|
273
|
+
limit: 1
|
|
274
|
+
});
|
|
275
|
+
return objects.length > 0 || prefixes.length > 0;
|
|
276
|
+
}
|
|
277
|
+
async function stat(filepath, syscall) {
|
|
278
|
+
const path = normalizePath(filepath);
|
|
279
|
+
if (knownAbsent(path)) throw enoent(syscall, filepath);
|
|
280
|
+
const k = toKey(path);
|
|
281
|
+
if (k === prefix || k === "") return makeStat("dir", 0);
|
|
282
|
+
const fileStat = await store.head(k);
|
|
283
|
+
if (fileStat) return makeStat("file", fileStat.size);
|
|
284
|
+
if (useLooseHints && looseScope(path) !== null) {
|
|
285
|
+
throw enoent(syscall, filepath);
|
|
286
|
+
}
|
|
287
|
+
if (await isDirectory(k)) return makeStat("dir", 0);
|
|
288
|
+
throw enoent(syscall, filepath);
|
|
289
|
+
}
|
|
290
|
+
const promises = {
|
|
291
|
+
async readFile(filepath, opts) {
|
|
292
|
+
const path = normalizePath(filepath);
|
|
293
|
+
if (knownAbsent(path)) throw enoent("open", filepath);
|
|
294
|
+
const data = await store.get(toKey(path));
|
|
295
|
+
if (data === null) throw enoent("open", filepath);
|
|
296
|
+
return resolveEncoding(opts) === "utf8" ? textDecoder.decode(data) : data;
|
|
297
|
+
},
|
|
298
|
+
async writeFile(filepath, data, _opts) {
|
|
299
|
+
const path = normalizePath(filepath);
|
|
300
|
+
if (useLooseHints) {
|
|
301
|
+
const scope = looseScope(path);
|
|
302
|
+
if (scope !== null) looseHints.set(scope, "present");
|
|
303
|
+
}
|
|
304
|
+
const bytes = typeof data === "string" ? textEncoder.encode(data) : data;
|
|
305
|
+
await store.put(toKey(path), bytes);
|
|
306
|
+
},
|
|
307
|
+
async unlink(filepath) {
|
|
308
|
+
const k = toKey(normalizePath(filepath));
|
|
309
|
+
if (await store.head(k) === null) throw enoent("unlink", filepath);
|
|
310
|
+
await store.delete(k);
|
|
311
|
+
},
|
|
312
|
+
async readdir(dirpath) {
|
|
313
|
+
const k = toKey(normalizePath(dirpath));
|
|
314
|
+
const isRoot = k === prefix || k === "";
|
|
315
|
+
const listPrefix = isRoot && k === "" ? "" : `${k}/`;
|
|
316
|
+
const { objects, prefixes } = await store.list(listPrefix, {
|
|
317
|
+
delimiter: "/"
|
|
318
|
+
});
|
|
319
|
+
if (objects.length === 0 && prefixes.length === 0) {
|
|
320
|
+
if (!isRoot && await store.head(k) !== null) {
|
|
321
|
+
throw enotdir("scandir", dirpath);
|
|
322
|
+
}
|
|
323
|
+
if (!isRoot) throw enoent("scandir", dirpath);
|
|
324
|
+
}
|
|
325
|
+
const names = objects.map((o) => o.key.slice(listPrefix.length));
|
|
326
|
+
const dirNames = prefixes.map(
|
|
327
|
+
(p) => p.slice(listPrefix.length).replace(/\/$/, "")
|
|
328
|
+
);
|
|
329
|
+
return [...names, ...dirNames].sort();
|
|
330
|
+
},
|
|
331
|
+
async mkdir(_dirpath, _opts) {
|
|
332
|
+
},
|
|
333
|
+
async rmdir(dirpath) {
|
|
334
|
+
const k = toKey(normalizePath(dirpath));
|
|
335
|
+
const { objects, prefixes } = await store.list(`${k}/`, { limit: 1 });
|
|
336
|
+
if (objects.length > 0 || prefixes.length > 0) {
|
|
337
|
+
throw enotempty("rmdir", dirpath);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
stat: (filepath) => stat(filepath, "stat"),
|
|
341
|
+
lstat: (filepath) => stat(filepath, "lstat"),
|
|
342
|
+
async readlink(filepath) {
|
|
343
|
+
throw enoent("readlink", filepath);
|
|
344
|
+
},
|
|
345
|
+
async symlink(_target, filepath) {
|
|
346
|
+
throw eperm("symlink", filepath);
|
|
347
|
+
},
|
|
348
|
+
async chmod(_filepath, _mode) {
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
async function detectLooseObjects(gitdir) {
|
|
352
|
+
if (!useLooseHints) return;
|
|
353
|
+
const scope = normalizePath(gitdir);
|
|
354
|
+
if (looseHints.has(scope)) return;
|
|
355
|
+
try {
|
|
356
|
+
const { objects } = await store.list(`${toKey(scope)}/objects/`, {
|
|
357
|
+
limit: 1
|
|
358
|
+
});
|
|
359
|
+
const first = objects[0]?.key;
|
|
360
|
+
const hint = first !== void 0 && LOOSE_OBJECT_RE.test(first) ? "present" : "none";
|
|
361
|
+
looseHints.set(scope, hint);
|
|
362
|
+
onNote?.(`loose objects ${hint} under ${scope}`);
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function prefetchPacks(gitdir, prefetchOptions) {
|
|
367
|
+
const maxPacks = prefetchOptions?.maxPacks ?? 30;
|
|
368
|
+
const packDir = `${normalizePath(gitdir)}/objects/pack`;
|
|
369
|
+
const entries = await promises.readdir(packDir).catch(() => []);
|
|
370
|
+
if (entries.length > maxPacks * 2) {
|
|
371
|
+
await detectLooseObjects(gitdir);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
await Promise.all([
|
|
375
|
+
detectLooseObjects(gitdir),
|
|
376
|
+
...entries.map(
|
|
377
|
+
(name) => promises.readFile(`${packDir}/${name}`).catch(() => void 0)
|
|
378
|
+
)
|
|
379
|
+
]);
|
|
380
|
+
}
|
|
381
|
+
function invalidate(pathPrefix) {
|
|
382
|
+
const normalized = normalizePath(pathPrefix);
|
|
383
|
+
for (const scope of looseHints.keys()) {
|
|
384
|
+
if (scope.startsWith(normalized)) looseHints.delete(scope);
|
|
385
|
+
}
|
|
386
|
+
const maybe = store;
|
|
387
|
+
maybe.invalidate?.(toKey(normalized));
|
|
388
|
+
}
|
|
389
|
+
return { promises, detectLooseObjects, prefetchPacks, invalidate };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/retry.ts
|
|
393
|
+
var CircuitOpenError = class extends Error {
|
|
394
|
+
code = "EUNAVAILABLE";
|
|
395
|
+
constructor() {
|
|
396
|
+
super("Circuit breaker is open, object store unavailable");
|
|
397
|
+
this.name = "CircuitOpenError";
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
var RETRYABLE_NAMES = /* @__PURE__ */ new Set([
|
|
401
|
+
"TimeoutError",
|
|
402
|
+
"RequestTimeout",
|
|
403
|
+
"RequestTimeoutException",
|
|
404
|
+
"SlowDown",
|
|
405
|
+
"ThrottlingException",
|
|
406
|
+
"TooManyRequestsException"
|
|
407
|
+
]);
|
|
408
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
409
|
+
"ECONNRESET",
|
|
410
|
+
"ECONNREFUSED",
|
|
411
|
+
"EPIPE",
|
|
412
|
+
"ETIMEDOUT",
|
|
413
|
+
"ENOTFOUND",
|
|
414
|
+
"EAI_AGAIN",
|
|
415
|
+
"EPROTO"
|
|
416
|
+
]);
|
|
417
|
+
function defaultIsRetryable(error) {
|
|
418
|
+
if (typeof error !== "object" || error === null) return false;
|
|
419
|
+
const err = error;
|
|
420
|
+
if (err.name !== void 0 && RETRYABLE_NAMES.has(err.name)) return true;
|
|
421
|
+
if (err.code !== void 0 && RETRYABLE_CODES.has(err.code)) return true;
|
|
422
|
+
const status = err.$metadata?.httpStatusCode;
|
|
423
|
+
return status !== void 0 && (status >= 500 || status === 429);
|
|
424
|
+
}
|
|
425
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
426
|
+
function createRetryStore(store, options = {}) {
|
|
427
|
+
const retries = options.retries ?? 3;
|
|
428
|
+
const initialDelayMs = options.initialDelayMs ?? 100;
|
|
429
|
+
const maxDelayMs = options.maxDelayMs ?? 5e3;
|
|
430
|
+
const jitter = options.jitter ?? 0.3;
|
|
431
|
+
const isRetryable = options.isRetryable ?? defaultIsRetryable;
|
|
432
|
+
const breaker = options.breaker === false ? null : {
|
|
433
|
+
threshold: options.breaker?.threshold ?? 5,
|
|
434
|
+
resetMs: options.breaker?.resetMs ?? 3e4
|
|
435
|
+
};
|
|
436
|
+
let failures = 0;
|
|
437
|
+
let lastFailureAt = 0;
|
|
438
|
+
let state = "closed";
|
|
439
|
+
async function guarded(fn) {
|
|
440
|
+
if (breaker === null) return fn();
|
|
441
|
+
if (state === "open") {
|
|
442
|
+
if (Date.now() - lastFailureAt < breaker.resetMs) {
|
|
443
|
+
throw new CircuitOpenError();
|
|
444
|
+
}
|
|
445
|
+
state = "half-open";
|
|
446
|
+
}
|
|
447
|
+
try {
|
|
448
|
+
const result = await fn();
|
|
449
|
+
if (state === "half-open") {
|
|
450
|
+
state = "closed";
|
|
451
|
+
failures = 0;
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
failures++;
|
|
456
|
+
lastFailureAt = Date.now();
|
|
457
|
+
if (failures >= breaker.threshold) state = "open";
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async function run(op, key, fn) {
|
|
462
|
+
let lastError;
|
|
463
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
464
|
+
try {
|
|
465
|
+
return await guarded(fn);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
lastError = error;
|
|
468
|
+
if (error instanceof CircuitOpenError) throw error;
|
|
469
|
+
if (!isRetryable(error) || attempt === retries) throw error;
|
|
470
|
+
const base = Math.min(initialDelayMs * 2 ** attempt, maxDelayMs);
|
|
471
|
+
const delayMs = Math.round(base + Math.random() * base * jitter);
|
|
472
|
+
options.onRetry?.({ key, op, attempt: attempt + 1, delayMs });
|
|
473
|
+
await sleep(delayMs);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
throw lastError;
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
get: (key) => run("get", key, () => store.get(key)),
|
|
480
|
+
put: (key, data) => run("put", key, () => store.put(key, data)),
|
|
481
|
+
delete: (key) => run("delete", key, () => store.delete(key)),
|
|
482
|
+
head: (key) => run("head", key, () => store.head(key)),
|
|
483
|
+
list: (prefix, listOptions) => run("list", prefix, () => store.list(prefix, listOptions))
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/stores/memory.ts
|
|
488
|
+
var MemoryObjectStore = class {
|
|
489
|
+
objects = /* @__PURE__ */ new Map();
|
|
490
|
+
async get(key) {
|
|
491
|
+
const data = this.objects.get(key);
|
|
492
|
+
return data ? data.slice() : null;
|
|
493
|
+
}
|
|
494
|
+
async put(key, data) {
|
|
495
|
+
this.objects.set(key, data.slice());
|
|
496
|
+
}
|
|
497
|
+
async delete(key) {
|
|
498
|
+
this.objects.delete(key);
|
|
499
|
+
}
|
|
500
|
+
async head(key) {
|
|
501
|
+
const data = this.objects.get(key);
|
|
502
|
+
return data ? { size: data.byteLength } : null;
|
|
503
|
+
}
|
|
504
|
+
async list(prefix, options) {
|
|
505
|
+
const delimiter = options?.delimiter;
|
|
506
|
+
const limit = options?.limit ?? Number.POSITIVE_INFINITY;
|
|
507
|
+
const objects = [];
|
|
508
|
+
const prefixes = /* @__PURE__ */ new Set();
|
|
509
|
+
for (const [key, data] of this.objects) {
|
|
510
|
+
if (!key.startsWith(prefix)) continue;
|
|
511
|
+
const rest = key.slice(prefix.length);
|
|
512
|
+
if (delimiter !== void 0) {
|
|
513
|
+
const idx = rest.indexOf(delimiter);
|
|
514
|
+
if (idx !== -1) {
|
|
515
|
+
prefixes.add(prefix + rest.slice(0, idx + delimiter.length));
|
|
516
|
+
} else {
|
|
517
|
+
objects.push({ key, size: data.byteLength });
|
|
518
|
+
}
|
|
519
|
+
} else {
|
|
520
|
+
objects.push({ key, size: data.byteLength });
|
|
521
|
+
}
|
|
522
|
+
if (objects.length + prefixes.size >= limit) break;
|
|
523
|
+
}
|
|
524
|
+
return { objects, prefixes: [...prefixes] };
|
|
525
|
+
}
|
|
526
|
+
/** Number of stored objects (test convenience, not part of ObjectStore). */
|
|
527
|
+
get size() {
|
|
528
|
+
return this.objects.size;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
export {
|
|
532
|
+
CircuitOpenError,
|
|
533
|
+
FsError,
|
|
534
|
+
GitAuthenticationError,
|
|
535
|
+
GitAuthorizationError,
|
|
536
|
+
GitConflictError,
|
|
537
|
+
GitError,
|
|
538
|
+
GitInvalidRequestError,
|
|
539
|
+
GitObjectNotFoundError,
|
|
540
|
+
GitPathNotFoundError,
|
|
541
|
+
GitProtocolError,
|
|
542
|
+
GitRateLimitError,
|
|
543
|
+
GitRefNotFoundError,
|
|
544
|
+
GitRepositoryNotFoundError,
|
|
545
|
+
MemoryObjectStore,
|
|
546
|
+
concat,
|
|
547
|
+
createCachedStore,
|
|
548
|
+
createGitFs,
|
|
549
|
+
createRetryStore,
|
|
550
|
+
decodeAscii,
|
|
551
|
+
decodeUtf8,
|
|
552
|
+
deflate,
|
|
553
|
+
encodeUtf8,
|
|
554
|
+
formatErrorResponse,
|
|
555
|
+
fromHex,
|
|
556
|
+
hasNullByte,
|
|
557
|
+
isFullSha,
|
|
558
|
+
isSafeBranchName,
|
|
559
|
+
isSafeFullRefName,
|
|
560
|
+
isSafeRefName,
|
|
561
|
+
isSafeRepoPath,
|
|
562
|
+
qualifyBranchRef,
|
|
563
|
+
readBlobContent,
|
|
564
|
+
sha1,
|
|
565
|
+
toBase64,
|
|
566
|
+
toHex
|
|
567
|
+
};
|
|
568
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache.ts","../src/errors.ts","../src/git-fs.ts","../src/path.ts","../src/retry.ts","../src/stores/memory.ts"],"sourcesContent":["import { LRUCache } from \"lru-cache\";\nimport type {\n\tListOptions,\n\tListResult,\n\tObjectStat,\n\tObjectStore,\n} from \"./types.js\";\n\nexport interface CacheOptions {\n\t/** Maximum bytes of object data held in memory. Default 50 MiB. */\n\tmaxBytes?: number;\n\t/**\n\t * Largest single entry admitted to the cache. Defaults to a tenth of\n\t * `maxBytes` so one huge packfile cannot evict the whole working set.\n\t */\n\tmaxEntryBytes?: number;\n\t/** Entry time-to-live in milliseconds. Default 60 000. */\n\tttlMs?: number;\n\t/**\n\t * Override the TTL for a specific key (get/head) or list prefix (list),\n\t * in milliseconds. Return `undefined` to fall back to `ttlMs`. Git refs\n\t * (`refs/heads/<branch>`, `HEAD`) are mutable — the same key's value\n\t * changes on every push — unlike content-addressed object keys, which\n\t * never change for a given key and are safe to cache for the full\n\t * `ttlMs`. Without this, a long `ttlMs` tuned for objects also caches\n\t * ref reads that long, so a warm process can keep serving a\n\t * pre-push ref value for the rest of that TTL even though nothing\n\t * changed *this* process's own cache (see `invalidate`) — it just never\n\t * knew to. Give ref-like keys a short override (a few seconds) instead:\n\t * a ref read is one small object, so re-reading it far more often than\n\t * `ttlMs` is cheap, and every read downstream of a fresh ref (tree,\n\t * commit, blob — all keyed by the sha it resolves to) still gets the\n\t * full-length cache/coalescing benefit.\n\t */\n\tttlForKey?: (key: string) => number | undefined;\n\t/**\n\t * Also cache \"key does not exist\" results. Loose-object probes on packed\n\t * repositories are almost always misses, so this saves many round trips —\n\t * but only enable it when a single process is the only writer, otherwise\n\t * another instance's push can be masked for up to `ttlMs`.\n\t */\n\tcacheMisses?: boolean;\n\t/**\n\t * Also cache `list()` results (directory listings and `limit: 1`\n\t * existence probes). Writes through this store keep cached listings\n\t * consistent; after writing to the backend by any other means, call\n\t * `invalidate()` with the affected prefix. Default false.\n\t */\n\tcacheLists?: boolean;\n\t/**\n\t * Collapse concurrent `get`/`head`/`list` calls for the same key into a\n\t * single backend request. Default true.\n\t */\n\tcoalesce?: boolean;\n\t/** Called when a read is answered from cache. */\n\tonHit?: (key: string) => void;\n\t/** Called when a read has to go to the backing store. */\n\tonMiss?: (key: string) => void;\n}\n\n/** An {@link ObjectStore} wrapper that also supports explicit invalidation. */\nexport interface CachedObjectStore extends ObjectStore {\n\t/**\n\t * Drop every cached entry — contents, misses, and listings — whose key\n\t * falls under `prefix` (exact keys included). Call this after the backing\n\t * store was modified by something other than this wrapper.\n\t */\n\tinvalidate(prefix: string): void;\n}\n\nconst MISS = Symbol(\"miss\");\ntype CacheEntry = Uint8Array | typeof MISS;\n\ninterface ListEntry {\n\tresult: ListResult;\n\t/** The raw list prefix this entry describes. */\n\tprefix: string;\n\t/** True for `limit: 1` existence probes. */\n\tprobe: boolean;\n\t/** True when the listing came back with no objects or prefixes. */\n\tempty: boolean;\n}\n\nfunction listEntrySize(entry: ListEntry): number {\n\tlet size = entry.prefix.length + 16;\n\tfor (const o of entry.result.objects) size += o.key.length + 8;\n\tfor (const p of entry.result.prefixes) size += p.length;\n\treturn size;\n}\n\nfunction copyListResult(result: ListResult): ListResult {\n\treturn {\n\t\tobjects: result.objects.map((o) => ({ ...o })),\n\t\tprefixes: [...result.prefixes],\n\t};\n}\n\n/**\n * Wrap an {@link ObjectStore} with an in-process LRU read cache.\n *\n * Git object keys are content-addressed and therefore immutable, which makes\n * them ideal cache entries; mutable keys (refs, packed-refs) are bounded by\n * `ttlMs`. Writes and deletes through this wrapper invalidate their key and\n * any cached listings they affect — with one asymmetry: a non-empty `limit: 1`\n * probe (a \"directory exists\" answer) survives writes underneath it, because\n * adding a key below a prefix cannot make that prefix stop existing, while\n * empty probes and full listings are always dropped.\n */\nexport function createCachedStore(\n\tstore: ObjectStore,\n\toptions: CacheOptions = {},\n): CachedObjectStore {\n\tconst maxBytes = options.maxBytes ?? 50 * 1024 * 1024;\n\tconst maxEntryBytes = options.maxEntryBytes ?? Math.ceil(maxBytes / 10);\n\tconst ttl = options.ttlMs ?? 60_000;\n\tconst ttlForKey = options.ttlForKey;\n\tconst cacheMisses = options.cacheMisses ?? false;\n\tconst cacheLists = options.cacheLists ?? false;\n\tconst coalesce = options.coalesce ?? true;\n\tconst onHit = options.onHit;\n\tconst onMiss = options.onMiss;\n\n\tconst cache = new LRUCache<string, CacheEntry>({\n\t\tmaxSize: maxBytes,\n\t\tsizeCalculation: (value) => (value === MISS ? 1 : value.byteLength || 1),\n\t\tttl,\n\t});\n\tconst listCache = new LRUCache<string, ListEntry>({\n\t\tmaxSize: Math.max(1, Math.ceil(maxBytes / 10)),\n\t\tsizeCalculation: listEntrySize,\n\t\tttl,\n\t});\n\n\tconst pendingGets = new Map<string, Promise<Uint8Array | null>>();\n\tconst pendingHeads = new Map<string, Promise<ObjectStat | null>>();\n\tconst pendingLists = new Map<string, Promise<ListResult>>();\n\n\tconst admit = (key: string, data: Uint8Array) => {\n\t\tif (data.byteLength <= maxEntryBytes) {\n\t\t\tcache.set(key, data.slice(), { ttl: ttlForKey?.(key) });\n\t\t}\n\t};\n\n\t/** Drop list entries a write/delete at `key` may have made stale. */\n\tfunction clearStaleListEntries(key: string): void {\n\t\tfor (const [listKey, entry] of listCache.entries()) {\n\t\t\tif (!key.startsWith(entry.prefix)) continue;\n\t\t\tif (entry.probe && !entry.empty) continue;\n\t\t\tlistCache.delete(listKey);\n\t\t}\n\t}\n\n\tfunction coalesced<T>(\n\t\tpending: Map<string, Promise<T>>,\n\t\tkey: string,\n\t\tfn: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (!coalesce) return fn();\n\t\tconst inflight = pending.get(key);\n\t\tif (inflight !== undefined) return inflight;\n\t\tconst p = fn().finally(() => pending.delete(key));\n\t\tpending.set(key, p);\n\t\treturn p;\n\t}\n\n\treturn {\n\t\tasync get(key: string): Promise<Uint8Array | null> {\n\t\t\tconst cached = cache.get(key);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tonHit?.(key);\n\t\t\t\treturn cached === MISS ? null : cached.slice();\n\t\t\t}\n\t\t\tconst data = await coalesced(pendingGets, key, async () => {\n\t\t\t\tonMiss?.(key);\n\t\t\t\tconst fetched = await store.get(key);\n\t\t\t\tif (fetched !== null) {\n\t\t\t\t\tadmit(key, fetched);\n\t\t\t\t} else if (cacheMisses) {\n\t\t\t\t\tcache.set(key, MISS, { ttl: ttlForKey?.(key) });\n\t\t\t\t}\n\t\t\t\treturn fetched;\n\t\t\t});\n\t\t\treturn data === null ? null : data.slice();\n\t\t},\n\n\t\tasync put(key: string, data: Uint8Array): Promise<void> {\n\t\t\tawait store.put(key, data);\n\t\t\tadmit(key, data);\n\t\t\tif (data.byteLength > maxEntryBytes) cache.delete(key);\n\t\t\tclearStaleListEntries(key);\n\t\t},\n\n\t\tasync delete(key: string): Promise<void> {\n\t\t\tawait store.delete(key);\n\t\t\tif (cacheMisses) {\n\t\t\t\tcache.set(key, MISS, { ttl: ttlForKey?.(key) });\n\t\t\t} else {\n\t\t\t\tcache.delete(key);\n\t\t\t}\n\t\t\tclearStaleListEntries(key);\n\t\t},\n\n\t\tasync head(key: string): Promise<ObjectStat | null> {\n\t\t\tconst cached = cache.get(key);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tonHit?.(key);\n\t\t\t\treturn cached === MISS ? null : { size: cached.byteLength };\n\t\t\t}\n\t\t\treturn coalesced(pendingHeads, key, async () => {\n\t\t\t\tonMiss?.(key);\n\t\t\t\tconst stat = await store.head(key);\n\t\t\t\tif (stat === null && cacheMisses) {\n\t\t\t\t\tcache.set(key, MISS, { ttl: ttlForKey?.(key) });\n\t\t\t\t}\n\t\t\t\treturn stat;\n\t\t\t});\n\t\t},\n\n\t\tasync list(prefix: string, listOptions?: ListOptions): Promise<ListResult> {\n\t\t\tif (!cacheLists) return store.list(prefix, listOptions);\n\t\t\tconst listKey = `${listOptions?.delimiter ?? \"\"}|${listOptions?.limit ?? \"\"}|${prefix}`;\n\t\t\tconst cached = listCache.get(listKey);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tonHit?.(prefix);\n\t\t\t\treturn copyListResult(cached.result);\n\t\t\t}\n\t\t\tconst result = await coalesced(pendingLists, listKey, async () => {\n\t\t\t\tonMiss?.(prefix);\n\t\t\t\tconst fetched = await store.list(prefix, listOptions);\n\t\t\t\tlistCache.set(\n\t\t\t\t\tlistKey,\n\t\t\t\t\t{\n\t\t\t\t\t\tresult: copyListResult(fetched),\n\t\t\t\t\t\tprefix,\n\t\t\t\t\t\tprobe: listOptions?.limit === 1,\n\t\t\t\t\t\tempty:\n\t\t\t\t\t\t\tfetched.objects.length === 0 && fetched.prefixes.length === 0,\n\t\t\t\t\t},\n\t\t\t\t\t{ ttl: ttlForKey?.(prefix) },\n\t\t\t\t);\n\t\t\t\treturn fetched;\n\t\t\t});\n\t\t\treturn copyListResult(result);\n\t\t},\n\n\t\tinvalidate(prefix: string): void {\n\t\t\tfor (const key of cache.keys()) {\n\t\t\t\tif (key.startsWith(prefix)) cache.delete(key);\n\t\t\t}\n\t\t\tfor (const [listKey, entry] of listCache.entries()) {\n\t\t\t\tif (\n\t\t\t\t\tentry.prefix.startsWith(prefix) ||\n\t\t\t\t\tprefix.startsWith(entry.prefix)\n\t\t\t\t) {\n\t\t\t\t\tlistCache.delete(listKey);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n","/**\n * Node-style filesystem error carrying a `code` property, which is what\n * isomorphic-git inspects to distinguish \"file not found\" from real failures.\n */\nexport class FsError extends Error {\n\treadonly code: string;\n\treadonly syscall: string;\n\treadonly path: string;\n\n\tconstructor(code: string, syscall: string, path: string) {\n\t\tsuper(`${code}: ${syscall} '${path}'`);\n\t\tthis.name = \"FsError\";\n\t\tthis.code = code;\n\t\tthis.syscall = syscall;\n\t\tthis.path = path;\n\t}\n}\n\nexport const enoent = (syscall: string, path: string) =>\n\tnew FsError(\"ENOENT\", syscall, path);\n\nexport const enotdir = (syscall: string, path: string) =>\n\tnew FsError(\"ENOTDIR\", syscall, path);\n\nexport const eisdir = (syscall: string, path: string) =>\n\tnew FsError(\"EISDIR\", syscall, path);\n\nexport const enotempty = (syscall: string, path: string) =>\n\tnew FsError(\"ENOTEMPTY\", syscall, path);\n\nexport const einval = (syscall: string, path: string) =>\n\tnew FsError(\"EINVAL\", syscall, path);\n\nexport const eperm = (syscall: string, path: string) =>\n\tnew FsError(\"EPERM\", syscall, path);\n","import { LRUCache } from \"lru-cache\";\nimport { enoent, enotdir, enotempty, eperm } from \"./errors.js\";\nimport { normalizePath } from \"./path.js\";\nimport type {\n\tEncoding,\n\tGitFsClient,\n\tGitFsOptions,\n\tObjectStore,\n\tReadFileOptions,\n\tStat,\n\tWriteFileOptions,\n} from \"./types.js\";\n\nconst FILE_MODE = 0o100644;\nconst DIR_MODE = 0o40000;\n\n/**\n * A loose git object path: `objects/xx/<38 hex>` under any gitdir. The two\n * capture groups let the gitdir scope be recovered from a full path.\n */\nconst LOOSE_OBJECT_RE = /(^|\\/)objects\\/[0-9a-f]{2}\\/[0-9a-f]{38}$/;\n\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\nfunction makeStat(type: \"file\" | \"dir\", size: number): Stat {\n\tconst epoch = new Date(0);\n\treturn {\n\t\ttype,\n\t\tmode: type === \"file\" ? FILE_MODE : DIR_MODE,\n\t\tsize,\n\t\tino: 0,\n\t\tmtimeMs: 0,\n\t\tctimeMs: 0,\n\t\tuid: 0,\n\t\tgid: 0,\n\t\tdev: 0,\n\t\tmtime: epoch,\n\t\tctime: epoch,\n\t\tisFile: () => type === \"file\",\n\t\tisDirectory: () => type === \"dir\",\n\t\tisSymbolicLink: () => false,\n\t};\n}\n\nfunction resolveEncoding(\n\toptions?: ReadFileOptions | WriteFileOptions | Encoding,\n): Encoding | undefined {\n\tif (typeof options === \"string\") return options;\n\treturn options?.encoding;\n}\n\n/**\n * The filesystem returned by {@link createGitFs}: the isomorphic-git client\n * plus git-aware maintenance hooks.\n */\nexport interface GitFs extends GitFsClient {\n\t/**\n\t * Probe, with one bounded list, whether `gitdir` contains any loose\n\t * objects, and remember the answer. This is the only way a loose-object\n\t * hint is ever created; call it before full-history walks (commit logs,\n\t * reachability traversals) so fully packed repositories skip every\n\t * guaranteed-miss loose-object read. A later loose write flips the hint\n\t * back, so it cannot go stale mid-push.\n\t */\n\tdetectLooseObjects(gitdir: string): Promise<void>;\n\t/**\n\t * Warm the cache with every pack file under `gitdir` in parallel (plus\n\t * the loose-object hint) before a sequential history walk. Skipped when\n\t * the pack directory holds more than `maxPacks * 2` entries — warming\n\t * only helps when the cache budget actually fits the packs.\n\t */\n\tprefetchPacks(gitdir: string, options?: { maxPacks?: number }): Promise<void>;\n\t/**\n\t * Clear fs-level state (loose-object hints) under `pathPrefix`, and\n\t * forward to the store's `invalidate` when it has one. Call after the\n\t * backing store was modified by something other than this fs.\n\t */\n\tinvalidate(pathPrefix: string): void;\n}\n\n/**\n * Create a promise-based filesystem client for isomorphic-git backed by an\n * {@link ObjectStore}.\n *\n * Semantics:\n * - Directories are implicit, as in object storage: `mkdir` is a no-op and a\n * directory \"exists\" whenever at least one key lives under its prefix.\n * - Symbolic links are not supported (`readlink`/`symlink` throw). Bare\n * repositories never contain them.\n * - Designed for bare, server-side repositories (`git.init({bare: true})`,\n * plumbing commands, ref updates). Worktree checkouts belong on a real disk.\n */\nexport function createGitFs(\n\tstore: ObjectStore,\n\toptions: GitFsOptions = {},\n): GitFs {\n\tconst prefix = options.prefix ?? \"\";\n\tconst structurallyAbsent = options.isStructurallyAbsent;\n\tconst useLooseHints = options.looseObjectHints ?? false;\n\tconst onNote = options.onNote;\n\n\tconst toKey = (path: string): string => {\n\t\tif (prefix === \"\") return path;\n\t\treturn path === \"\" ? prefix : `${prefix}/${path}`;\n\t};\n\n\t/**\n\t * Per-gitdir \"does any loose object exist\" hint. Entries are only created\n\t * by {@link GitFs.detectLooseObjects}, so a pathological ref that merely\n\t * looks like a loose object (`refs/heads/objects/aa/…`) derives a scope\n\t * that was never registered and can never be wrongly short-circuited.\n\t */\n\tconst looseHints = new LRUCache<string, \"none\" | \"present\">({\n\t\tmax: 1024,\n\t\tttl: options.hintTtlMs ?? 3_600_000,\n\t});\n\n\t/** The gitdir scope of a loose-object path, or null when it isn't one. */\n\tfunction looseScope(path: string): string | null {\n\t\tconst match = LOOSE_OBJECT_RE.exec(path);\n\t\tif (match === null) return null;\n\t\treturn path.slice(0, match.index);\n\t}\n\n\tfunction knownAbsent(path: string): boolean {\n\t\tif (structurallyAbsent?.(path)) return true;\n\t\tif (!useLooseHints) return false;\n\t\tconst scope = looseScope(path);\n\t\treturn scope !== null && looseHints.get(scope) === \"none\";\n\t}\n\n\tasync function isDirectory(dirKey: string): Promise<boolean> {\n\t\tconst { objects, prefixes } = await store.list(`${dirKey}/`, {\n\t\t\tlimit: 1,\n\t\t});\n\t\treturn objects.length > 0 || prefixes.length > 0;\n\t}\n\n\tasync function stat(filepath: string, syscall: string): Promise<Stat> {\n\t\tconst path = normalizePath(filepath);\n\t\tif (knownAbsent(path)) throw enoent(syscall, filepath);\n\t\tconst k = toKey(path);\n\t\tif (k === prefix || k === \"\") return makeStat(\"dir\", 0);\n\t\tconst fileStat = await store.head(k);\n\t\tif (fileStat) return makeStat(\"file\", fileStat.size);\n\t\t// A loose-object path is always a leaf; when the object itself is\n\t\t// absent there is no point probing for a directory of the same name.\n\t\tif (useLooseHints && looseScope(path) !== null) {\n\t\t\tthrow enoent(syscall, filepath);\n\t\t}\n\t\tif (await isDirectory(k)) return makeStat(\"dir\", 0);\n\t\tthrow enoent(syscall, filepath);\n\t}\n\n\tconst promises: GitFsClient[\"promises\"] = {\n\t\tasync readFile(filepath, opts) {\n\t\t\tconst path = normalizePath(filepath);\n\t\t\tif (knownAbsent(path)) throw enoent(\"open\", filepath);\n\t\t\tconst data = await store.get(toKey(path));\n\t\t\tif (data === null) throw enoent(\"open\", filepath);\n\t\t\treturn resolveEncoding(opts) === \"utf8\" ? textDecoder.decode(data) : data;\n\t\t},\n\n\t\tasync writeFile(filepath, data, _opts) {\n\t\t\tconst path = normalizePath(filepath);\n\t\t\tif (useLooseHints) {\n\t\t\t\tconst scope = looseScope(path);\n\t\t\t\t// Flip before the write lands so a racing read can never\n\t\t\t\t// short-circuit an object that is in the middle of arriving.\n\t\t\t\tif (scope !== null) looseHints.set(scope, \"present\");\n\t\t\t}\n\t\t\tconst bytes = typeof data === \"string\" ? textEncoder.encode(data) : data;\n\t\t\tawait store.put(toKey(path), bytes);\n\t\t},\n\n\t\tasync unlink(filepath) {\n\t\t\tconst k = toKey(normalizePath(filepath));\n\t\t\tif ((await store.head(k)) === null) throw enoent(\"unlink\", filepath);\n\t\t\tawait store.delete(k);\n\t\t},\n\n\t\tasync readdir(dirpath) {\n\t\t\tconst k = toKey(normalizePath(dirpath));\n\t\t\tconst isRoot = k === prefix || k === \"\";\n\t\t\tconst listPrefix = isRoot && k === \"\" ? \"\" : `${k}/`;\n\t\t\tconst { objects, prefixes } = await store.list(listPrefix, {\n\t\t\t\tdelimiter: \"/\",\n\t\t\t});\n\t\t\tif (objects.length === 0 && prefixes.length === 0) {\n\t\t\t\tif (!isRoot && (await store.head(k)) !== null) {\n\t\t\t\t\tthrow enotdir(\"scandir\", dirpath);\n\t\t\t\t}\n\t\t\t\tif (!isRoot) throw enoent(\"scandir\", dirpath);\n\t\t\t}\n\t\t\tconst names = objects.map((o) => o.key.slice(listPrefix.length));\n\t\t\tconst dirNames = prefixes.map((p) =>\n\t\t\t\tp.slice(listPrefix.length).replace(/\\/$/, \"\"),\n\t\t\t);\n\t\t\treturn [...names, ...dirNames].sort();\n\t\t},\n\n\t\tasync mkdir(_dirpath, _opts) {\n\t\t\t// Directories are implicit in object storage.\n\t\t},\n\n\t\tasync rmdir(dirpath) {\n\t\t\tconst k = toKey(normalizePath(dirpath));\n\t\t\tconst { objects, prefixes } = await store.list(`${k}/`, { limit: 1 });\n\t\t\tif (objects.length > 0 || prefixes.length > 0) {\n\t\t\t\tthrow enotempty(\"rmdir\", dirpath);\n\t\t\t}\n\t\t\t// Empty implicit directories don't exist; nothing to remove.\n\t\t},\n\n\t\tstat: (filepath) => stat(filepath, \"stat\"),\n\t\tlstat: (filepath) => stat(filepath, \"lstat\"),\n\n\t\tasync readlink(filepath): Promise<never> {\n\t\t\tthrow enoent(\"readlink\", filepath);\n\t\t},\n\n\t\tasync symlink(_target, filepath): Promise<never> {\n\t\t\tthrow eperm(\"symlink\", filepath);\n\t\t},\n\n\t\tasync chmod(_filepath, _mode) {\n\t\t\t// POSIX modes don't exist in object storage.\n\t\t},\n\t};\n\n\tasync function detectLooseObjects(gitdir: string): Promise<void> {\n\t\tif (!useLooseHints) return;\n\t\tconst scope = normalizePath(gitdir);\n\t\t// A live hint must win over re-detection: after a loose write flips it\n\t\t// to \"present\", re-deriving from a (possibly cached, pre-write) listing\n\t\t// could wrongly reinstate \"none\" and mask real objects.\n\t\tif (looseHints.has(scope)) return;\n\t\ttry {\n\t\t\tconst { objects } = await store.list(`${toKey(scope)}/objects/`, {\n\t\t\t\tlimit: 1,\n\t\t\t});\n\t\t\t// Loose fan-out directories (two hex digits) sort before \"info/\"\n\t\t\t// and \"pack/\", so when any loose object exists it is the first key.\n\t\t\tconst first = objects[0]?.key;\n\t\t\tconst hint =\n\t\t\t\tfirst !== undefined && LOOSE_OBJECT_RE.test(first) ? \"present\" : \"none\";\n\t\t\tlooseHints.set(scope, hint);\n\t\t\tonNote?.(`loose objects ${hint} under ${scope}`);\n\t\t} catch {\n\t\t\t// Leave unknown — reads fall back to their normal round trip.\n\t\t}\n\t}\n\n\tasync function prefetchPacks(\n\t\tgitdir: string,\n\t\tprefetchOptions?: { maxPacks?: number },\n\t): Promise<void> {\n\t\tconst maxPacks = prefetchOptions?.maxPacks ?? 30;\n\t\tconst packDir = `${normalizePath(gitdir)}/objects/pack`;\n\t\tconst entries = await promises.readdir(packDir).catch(() => []);\n\t\tif (entries.length > maxPacks * 2) {\n\t\t\tawait detectLooseObjects(gitdir);\n\t\t\treturn;\n\t\t}\n\t\tawait Promise.all([\n\t\t\tdetectLooseObjects(gitdir),\n\t\t\t...entries.map((name) =>\n\t\t\t\tpromises.readFile(`${packDir}/${name}`).catch(() => undefined),\n\t\t\t),\n\t\t]);\n\t}\n\n\tfunction invalidate(pathPrefix: string): void {\n\t\tconst normalized = normalizePath(pathPrefix);\n\t\tfor (const scope of looseHints.keys()) {\n\t\t\tif (scope.startsWith(normalized)) looseHints.delete(scope);\n\t\t}\n\t\tconst maybe = store as ObjectStore & {\n\t\t\tinvalidate?: (prefix: string) => void;\n\t\t};\n\t\tmaybe.invalidate?.(toKey(normalized));\n\t}\n\n\treturn { promises, detectLooseObjects, prefetchPacks, invalidate };\n}\n","import { einval } from \"./errors.js\";\n\n/**\n * Normalize an absolute-or-relative filesystem path into a storage key\n * segment: no leading/trailing slashes, `.` segments dropped, `..` resolved.\n * A `..` that would escape the root throws EINVAL — paths handed to the fs\n * must never address keys outside the configured prefix.\n */\nexport function normalizePath(filepath: string): string {\n\tconst segments = filepath.split(\"/\");\n\tconst out: string[] = [];\n\tfor (const segment of segments) {\n\t\tif (segment === \"\" || segment === \".\") continue;\n\t\tif (segment === \"..\") {\n\t\t\tif (out.length === 0) throw einval(\"resolve\", filepath);\n\t\t\tout.pop();\n\t\t\tcontinue;\n\t\t}\n\t\tout.push(segment);\n\t}\n\treturn out.join(\"/\");\n}\n\n/** Join a configured key prefix with a normalized path. */\nexport function toKey(prefix: string, filepath: string): string {\n\tconst normalized = normalizePath(filepath);\n\tif (prefix === \"\") return normalized;\n\treturn normalized === \"\" ? prefix : `${prefix}/${normalized}`;\n}\n","import type { ObjectStore } from \"./types.js\";\n\n/** Options accepted by {@link createRetryStore}. */\nexport interface RetryOptions {\n\t/** Retries after the first attempt (total attempts = retries + 1). Default 3. */\n\tretries?: number;\n\t/** Backoff base delay in milliseconds, doubled each attempt. Default 100. */\n\tinitialDelayMs?: number;\n\t/** Upper bound for the backoff base delay. Default 5000. */\n\tmaxDelayMs?: number;\n\t/** Random jitter added to each delay, as a fraction of it. Default 0.3. */\n\tjitter?: number;\n\t/**\n\t * Decide whether an error is worth retrying. The store contract maps\n\t * \"not found\" to `null` rather than throwing, so any thrown error is a\n\t * genuine failure; the default retries network faults, throttling, and\n\t * HTTP 5xx responses.\n\t */\n\tisRetryable?: (error: unknown) => boolean;\n\t/**\n\t * Circuit breaker configuration, or `false` to disable. After `threshold`\n\t * consecutive failures the store fails fast for `resetMs`, then lets one\n\t * request probe the backend again. Defaults: 5 failures, 30 000 ms.\n\t */\n\tbreaker?: false | { threshold?: number; resetMs?: number };\n\t/** Called before each retry sleep; useful for logging/metrics. */\n\tonRetry?: (info: {\n\t\tkey: string;\n\t\top: string;\n\t\tattempt: number;\n\t\tdelayMs: number;\n\t}) => void;\n}\n\n/**\n * Thrown instead of calling the backend while the circuit breaker is open.\n * Carries `code: \"EUNAVAILABLE\"` so callers can map it to a 503.\n */\nexport class CircuitOpenError extends Error {\n\treadonly code = \"EUNAVAILABLE\";\n\n\tconstructor() {\n\t\tsuper(\"Circuit breaker is open, object store unavailable\");\n\t\tthis.name = \"CircuitOpenError\";\n\t}\n}\n\nconst RETRYABLE_NAMES = new Set([\n\t\"TimeoutError\",\n\t\"RequestTimeout\",\n\t\"RequestTimeoutException\",\n\t\"SlowDown\",\n\t\"ThrottlingException\",\n\t\"TooManyRequestsException\",\n]);\n\nconst RETRYABLE_CODES = new Set([\n\t\"ECONNRESET\",\n\t\"ECONNREFUSED\",\n\t\"EPIPE\",\n\t\"ETIMEDOUT\",\n\t\"ENOTFOUND\",\n\t\"EAI_AGAIN\",\n\t\"EPROTO\",\n]);\n\nfunction defaultIsRetryable(error: unknown): boolean {\n\tif (typeof error !== \"object\" || error === null) return false;\n\tconst err = error as {\n\t\tname?: string;\n\t\tcode?: string;\n\t\t$metadata?: { httpStatusCode?: number };\n\t};\n\tif (err.name !== undefined && RETRYABLE_NAMES.has(err.name)) return true;\n\tif (err.code !== undefined && RETRYABLE_CODES.has(err.code)) return true;\n\tconst status = err.$metadata?.httpStatusCode;\n\treturn status !== undefined && (status >= 500 || status === 429);\n}\n\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Wrap an {@link ObjectStore} with retries (exponential backoff + jitter) and\n * an optional per-instance circuit breaker.\n *\n * Place this decorator closest to the network store, underneath any cache:\n * the cache then never stores transient failures, and callers coalesced onto\n * one request share a single retried attempt.\n */\nexport function createRetryStore(\n\tstore: ObjectStore,\n\toptions: RetryOptions = {},\n): ObjectStore {\n\tconst retries = options.retries ?? 3;\n\tconst initialDelayMs = options.initialDelayMs ?? 100;\n\tconst maxDelayMs = options.maxDelayMs ?? 5000;\n\tconst jitter = options.jitter ?? 0.3;\n\tconst isRetryable = options.isRetryable ?? defaultIsRetryable;\n\tconst breaker =\n\t\toptions.breaker === false\n\t\t\t? null\n\t\t\t: {\n\t\t\t\t\tthreshold: options.breaker?.threshold ?? 5,\n\t\t\t\t\tresetMs: options.breaker?.resetMs ?? 30_000,\n\t\t\t\t};\n\n\tlet failures = 0;\n\tlet lastFailureAt = 0;\n\tlet state: \"closed\" | \"open\" | \"half-open\" = \"closed\";\n\n\tasync function guarded<T>(fn: () => Promise<T>): Promise<T> {\n\t\tif (breaker === null) return fn();\n\t\tif (state === \"open\") {\n\t\t\tif (Date.now() - lastFailureAt < breaker.resetMs) {\n\t\t\t\tthrow new CircuitOpenError();\n\t\t\t}\n\t\t\tstate = \"half-open\";\n\t\t}\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (state === \"half-open\") {\n\t\t\t\tstate = \"closed\";\n\t\t\t\tfailures = 0;\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tfailures++;\n\t\t\tlastFailureAt = Date.now();\n\t\t\tif (failures >= breaker.threshold) state = \"open\";\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function run<T>(op: string, key: string, fn: () => Promise<T>) {\n\t\tlet lastError: unknown;\n\t\tfor (let attempt = 0; attempt <= retries; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn await guarded(fn);\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error;\n\t\t\t\tif (error instanceof CircuitOpenError) throw error;\n\t\t\t\tif (!isRetryable(error) || attempt === retries) throw error;\n\t\t\t\tconst base = Math.min(initialDelayMs * 2 ** attempt, maxDelayMs);\n\t\t\t\tconst delayMs = Math.round(base + Math.random() * base * jitter);\n\t\t\t\toptions.onRetry?.({ key, op, attempt: attempt + 1, delayMs });\n\t\t\t\tawait sleep(delayMs);\n\t\t\t}\n\t\t}\n\t\tthrow lastError;\n\t}\n\n\treturn {\n\t\tget: (key) => run(\"get\", key, () => store.get(key)),\n\t\tput: (key, data) => run(\"put\", key, () => store.put(key, data)),\n\t\tdelete: (key) => run(\"delete\", key, () => store.delete(key)),\n\t\thead: (key) => run(\"head\", key, () => store.head(key)),\n\t\tlist: (prefix, listOptions) =>\n\t\t\trun(\"list\", prefix, () => store.list(prefix, listOptions)),\n\t};\n}\n","import type {\n\tListOptions,\n\tListResult,\n\tObjectStat,\n\tObjectStore,\n} from \"../types.js\";\n\n/**\n * In-memory {@link ObjectStore}. Useful for tests, examples, and ephemeral\n * repositories; also the reference implementation for the list/delimiter\n * semantics other stores must match.\n */\nexport class MemoryObjectStore implements ObjectStore {\n\tprivate readonly objects = new Map<string, Uint8Array>();\n\n\tasync get(key: string): Promise<Uint8Array | null> {\n\t\tconst data = this.objects.get(key);\n\t\treturn data ? data.slice() : null;\n\t}\n\n\tasync put(key: string, data: Uint8Array): Promise<void> {\n\t\tthis.objects.set(key, data.slice());\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.objects.delete(key);\n\t}\n\n\tasync head(key: string): Promise<ObjectStat | null> {\n\t\tconst data = this.objects.get(key);\n\t\treturn data ? { size: data.byteLength } : null;\n\t}\n\n\tasync list(prefix: string, options?: ListOptions): Promise<ListResult> {\n\t\tconst delimiter = options?.delimiter;\n\t\tconst limit = options?.limit ?? Number.POSITIVE_INFINITY;\n\t\tconst objects: ListResult[\"objects\"] = [];\n\t\tconst prefixes = new Set<string>();\n\n\t\tfor (const [key, data] of this.objects) {\n\t\t\tif (!key.startsWith(prefix)) continue;\n\t\t\tconst rest = key.slice(prefix.length);\n\t\t\tif (delimiter !== undefined) {\n\t\t\t\tconst idx = rest.indexOf(delimiter);\n\t\t\t\tif (idx !== -1) {\n\t\t\t\t\tprefixes.add(prefix + rest.slice(0, idx + delimiter.length));\n\t\t\t\t} else {\n\t\t\t\t\tobjects.push({ key, size: data.byteLength });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tobjects.push({ key, size: data.byteLength });\n\t\t\t}\n\t\t\tif (objects.length + prefixes.size >= limit) break;\n\t\t}\n\n\t\treturn { objects, prefixes: [...prefixes] };\n\t}\n\n\t/** Number of stored objects (test convenience, not part of ObjectStore). */\n\tget size(): number {\n\t\treturn this.objects.size;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAsEzB,IAAM,OAAO,uBAAO,MAAM;AAa1B,SAAS,cAAc,OAA0B;AAChD,MAAI,OAAO,MAAM,OAAO,SAAS;AACjC,aAAW,KAAK,MAAM,OAAO,QAAS,SAAQ,EAAE,IAAI,SAAS;AAC7D,aAAW,KAAK,MAAM,OAAO,SAAU,SAAQ,EAAE;AACjD,SAAO;AACR;AAEA,SAAS,eAAe,QAAgC;AACvD,SAAO;AAAA,IACN,SAAS,OAAO,QAA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