git-fs-s3 0.3.13 → 0.5.0

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.
Files changed (65) hide show
  1. package/README.md +23 -17
  2. package/dist/{chunk-3BDDEGAP.js → chunk-2JP4MS6H.js} +7 -3
  3. package/dist/chunk-2JP4MS6H.js.map +1 -0
  4. package/dist/{chunk-YQFNY6PG.js → chunk-FIFWOMPM.js} +1 -1
  5. package/dist/chunk-FIFWOMPM.js.map +1 -0
  6. package/dist/chunk-RMAOPWHJ.js +38 -0
  7. package/dist/chunk-RMAOPWHJ.js.map +1 -0
  8. package/dist/http.js +257 -81
  9. package/dist/http.js.map +1 -1
  10. package/dist/index.js +115 -18
  11. package/dist/index.js.map +1 -1
  12. package/dist/ops.js +2 -2
  13. package/dist/types/cache.d.ts +81 -0
  14. package/dist/types/edge-utils.d.ts +43 -0
  15. package/dist/types/errors.d.ts +16 -0
  16. package/dist/types/git-errors.d.ts +70 -0
  17. package/dist/types/git-fs.d.ts +60 -0
  18. package/dist/types/git-layout.d.ts +52 -0
  19. package/dist/types/http/index.d.ts +7 -0
  20. package/dist/types/http/info-refs.d.ts +27 -0
  21. package/dist/types/http/pack-reuse.d.ts +26 -0
  22. package/dist/types/http/pkt-line.d.ts +14 -0
  23. package/dist/types/http/reachability.d.ts +36 -0
  24. package/dist/types/http/receive-pack.d.ts +54 -0
  25. package/dist/types/http/repack.d.ts +24 -0
  26. package/dist/types/http/types.d.ts +40 -0
  27. package/dist/types/http/upload-pack.d.ts +21 -0
  28. package/dist/types/index.d.ts +11 -0
  29. package/dist/types/ops/branch.d.ts +38 -0
  30. package/dist/types/ops/commit.d.ts +45 -0
  31. package/dist/types/ops/diff.d.ts +24 -0
  32. package/dist/types/ops/file-history.d.ts +41 -0
  33. package/dist/types/ops/history.d.ts +85 -0
  34. package/dist/types/ops/index.d.ts +9 -0
  35. package/dist/types/ops/last-commit.d.ts +23 -0
  36. package/dist/types/ops/merge.d.ts +28 -0
  37. package/dist/types/ops/tree.d.ts +19 -0
  38. package/dist/{types-BHoHOaQt.d.ts → types/ops/types.d.ts} +7 -9
  39. package/dist/types/pack-files.d.ts +28 -0
  40. package/dist/types/path.d.ts +9 -0
  41. package/dist/types/refs.d.ts +54 -0
  42. package/dist/types/retry.d.ts +52 -0
  43. package/dist/types/stores/memory.d.ts +16 -0
  44. package/dist/{s3.d.ts → types/stores/s3.d.ts} +4 -7
  45. package/dist/{types-QgIkUR_q.d.cts → types/types.d.ts} +22 -23
  46. package/package.json +19 -23
  47. package/dist/chunk-3BDDEGAP.js.map +0 -1
  48. package/dist/chunk-YQFNY6PG.js.map +0 -1
  49. package/dist/http.cjs +0 -793
  50. package/dist/http.cjs.map +0 -1
  51. package/dist/http.d.cts +0 -206
  52. package/dist/http.d.ts +0 -206
  53. package/dist/index.cjs +0 -815
  54. package/dist/index.cjs.map +0 -1
  55. package/dist/index.d.cts +0 -381
  56. package/dist/index.d.ts +0 -381
  57. package/dist/ops.cjs +0 -1057
  58. package/dist/ops.cjs.map +0 -1
  59. package/dist/ops.d.cts +0 -302
  60. package/dist/ops.d.ts +0 -302
  61. package/dist/s3.cjs +0 -123
  62. package/dist/s3.cjs.map +0 -1
  63. package/dist/s3.d.cts +0 -36
  64. package/dist/types-BHoHOaQt.d.cts +0 -53
  65. package/dist/types-QgIkUR_q.d.ts +0 -121
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Git ref-name validation, mirroring isomorphic-git's own internal `isValidRef`
3
+ * character-class rules (the check `git.branch` and top-level `git.writeRef`
4
+ * run before touching disk).
5
+ *
6
+ * Several of isomorphic-git's OTHER ref-touching primitives — `git.commit`,
7
+ * `git.merge`, `git.deleteBranch`, and top-level `git.resolveRef`/
8
+ * `git.deleteRef` — do NOT run this check internally: they resolve straight
9
+ * through `fs.write`/`fs.rm(join(gitdir, ref))` with no jail to the gitdir.
10
+ * On a shared-storage server (many repos under one prefix or base directory),
11
+ * every branch/ref name that originates from request input must be validated
12
+ * against these predicates before it reaches any of those primitives —
13
+ * otherwise a `"../"`-laden name lets a caller with write access to any single
14
+ * repo read, corrupt, or delete another repo's ref/object files.
15
+ */
16
+ /** Validates a fully-qualified ref (must start with refs/heads/ or refs/tags/). */
17
+ export declare function isSafeFullRefName(ref: string): boolean;
18
+ /**
19
+ * Validates a bare branch name (no refs/ prefix). Rejects anything that looks
20
+ * like a full ref path — a name of `"refs/heads/x"` would otherwise sail
21
+ * through unprefixed at call sites that build `refs/heads/${name}` themselves
22
+ * (doubling the prefix into something that still resolves), or be used as-is
23
+ * at call sites that pass a name already containing `"refs/"` straight
24
+ * through. Also rejects 40-hex SHA-shaped values so a stored branch name can
25
+ * never be ambiguous with a commit SHA at write time; use
26
+ * {@link isSafeRefName} on read paths that accept both shapes.
27
+ */
28
+ export declare function isSafeBranchName(name: string): boolean;
29
+ /** True for a full 40-hex-char commit SHA — the shape {@link isSafeBranchName} deliberately rejects. */
30
+ export declare function isFullSha(value: string): boolean;
31
+ /**
32
+ * Validates a "ref" field that may name either a branch or a commit SHA it's
33
+ * pinned to — the shape read-path route params take (permalinks, raw links).
34
+ * Both shapes still go through the traversal check.
35
+ */
36
+ export declare function isSafeRefName(value: string): boolean;
37
+ /**
38
+ * Validates a repo-relative file path from request input: relative, no `..`
39
+ * segments, no `.git/` prefix, no null bytes. Use this anywhere a path
40
+ * segment comes straight off a URL or form field rather than re-deriving the
41
+ * checks ad hoc.
42
+ */
43
+ export declare function isSafeRepoPath(p: string): boolean;
44
+ /**
45
+ * Qualify a bare branch name to `refs/heads/<name>` before handing it to
46
+ * isomorphic-git. `resolveRef`/`expand` try several candidate paths in
47
+ * sequence for a bare name — `ref`, `refs/ref`, `refs/tags/ref`,
48
+ * `refs/heads/ref`, … — missing (and, against object storage, paying a real
49
+ * round trip for) the first three every time. For a branch-only ref model,
50
+ * skip straight to the winner. Left untouched: already-qualified refs,
51
+ * `"HEAD"` (its own first candidate, already optimal), and 40-hex oids
52
+ * (resolved locally by isomorphic-git with no I/O at all).
53
+ */
54
+ export declare function qualifyBranchRef(ref: string): string;
@@ -0,0 +1,52 @@
1
+ import type { ObjectStore } from "./types.js";
2
+ /** Options accepted by {@link createRetryStore}. */
3
+ export interface RetryOptions {
4
+ /** Retries after the first attempt (total attempts = retries + 1). Default 3. */
5
+ retries?: number;
6
+ /** Backoff base delay in milliseconds, doubled each attempt. Default 100. */
7
+ initialDelayMs?: number;
8
+ /** Upper bound for the backoff base delay. Default 5000. */
9
+ maxDelayMs?: number;
10
+ /** Random jitter added to each delay, as a fraction of it. Default 0.3. */
11
+ jitter?: number;
12
+ /**
13
+ * Decide whether an error is worth retrying. The store contract maps
14
+ * "not found" to `null` rather than throwing, so any thrown error is a
15
+ * genuine failure; the default retries network faults, throttling, and
16
+ * HTTP 5xx responses.
17
+ */
18
+ isRetryable?: (error: unknown) => boolean;
19
+ /**
20
+ * Circuit breaker configuration, or `false` to disable. After `threshold`
21
+ * consecutive failures the store fails fast for `resetMs`, then lets one
22
+ * request probe the backend again. Defaults: 5 failures, 30 000 ms.
23
+ */
24
+ breaker?: false | {
25
+ threshold?: number;
26
+ resetMs?: number;
27
+ };
28
+ /** Called before each retry sleep; useful for logging/metrics. */
29
+ onRetry?: (info: {
30
+ key: string;
31
+ op: string;
32
+ attempt: number;
33
+ delayMs: number;
34
+ }) => void;
35
+ }
36
+ /**
37
+ * Thrown instead of calling the backend while the circuit breaker is open.
38
+ * Carries `code: "EUNAVAILABLE"` so callers can map it to a 503.
39
+ */
40
+ export declare class CircuitOpenError extends Error {
41
+ readonly code = "EUNAVAILABLE";
42
+ constructor();
43
+ }
44
+ /**
45
+ * Wrap an {@link ObjectStore} with retries (exponential backoff + jitter) and
46
+ * an optional per-instance circuit breaker.
47
+ *
48
+ * Place this decorator closest to the network store, underneath any cache:
49
+ * the cache then never stores transient failures, and callers coalesced onto
50
+ * one request share a single retried attempt.
51
+ */
52
+ export declare function createRetryStore(store: ObjectStore, options?: RetryOptions): ObjectStore;
@@ -0,0 +1,16 @@
1
+ import type { ListOptions, ListResult, ObjectStat, ObjectStore } from "../types.js";
2
+ /**
3
+ * In-memory {@link ObjectStore}. Useful for tests, examples, and ephemeral
4
+ * repositories; also the reference implementation for the list/delimiter
5
+ * semantics other stores must match.
6
+ */
7
+ export declare class MemoryObjectStore implements ObjectStore {
8
+ private readonly objects;
9
+ get(key: string): Promise<Uint8Array | null>;
10
+ put(key: string, data: Uint8Array): Promise<void>;
11
+ delete(key: string): Promise<void>;
12
+ head(key: string): Promise<ObjectStat | null>;
13
+ list(prefix: string, options?: ListOptions): Promise<ListResult>;
14
+ /** Number of stored objects (test convenience, not part of ObjectStore). */
15
+ get size(): number;
16
+ }
@@ -1,7 +1,6 @@
1
- import { S3Client } from '@aws-sdk/client-s3';
2
- import { O as ObjectStore, b as ObjectStat, L as ListOptions, c as ListResult } from './types-QgIkUR_q.js';
3
-
4
- interface S3ObjectStoreOptions {
1
+ import { type S3Client } from "@aws-sdk/client-s3";
2
+ import type { ListOptions, ListResult, ObjectStat, ObjectStore } from "../types.js";
3
+ export interface S3ObjectStoreOptions {
5
4
  /** A configured S3Client. Works with AWS S3, Cloudflare R2, MinIO, Backblaze B2, … */
6
5
  client: S3Client;
7
6
  bucket: string;
@@ -19,7 +18,7 @@ interface S3ObjectStoreOptions {
19
18
  * (peer dependency). One instance per bucket/prefix; reuse a single
20
19
  * `S3Client` across stores so HTTP connections are pooled.
21
20
  */
22
- declare class S3ObjectStore implements ObjectStore {
21
+ export declare class S3ObjectStore implements ObjectStore {
23
22
  private readonly client;
24
23
  private readonly bucket;
25
24
  private readonly prefix;
@@ -32,5 +31,3 @@ declare class S3ObjectStore implements ObjectStore {
32
31
  head(key: string): Promise<ObjectStat | null>;
33
32
  list(prefix: string, options?: ListOptions): Promise<ListResult>;
34
33
  }
35
-
36
- export { S3ObjectStore, type S3ObjectStoreOptions };
@@ -5,7 +5,7 @@
5
5
  * implementations ship with the package: {@link ../stores/memory.MemoryObjectStore}
6
6
  * and {@link ../stores/s3.S3ObjectStore}.
7
7
  */
8
- interface ObjectStore {
8
+ export interface ObjectStore {
9
9
  /** Return the object's bytes, or `null` if the key does not exist. */
10
10
  get(key: string): Promise<Uint8Array | null>;
11
11
  /** Create or overwrite the object at `key`. */
@@ -24,22 +24,31 @@ interface ObjectStore {
24
24
  */
25
25
  list(prefix: string, options?: ListOptions): Promise<ListResult>;
26
26
  }
27
- interface ObjectStat {
27
+ export interface ObjectStat {
28
28
  size: number;
29
29
  }
30
- interface ListOptions {
30
+ export interface ListOptions {
31
31
  delimiter?: string;
32
32
  limit?: number;
33
33
  }
34
- interface ListResult {
34
+ export interface ListResult {
35
35
  objects: {
36
36
  key: string;
37
37
  size: number;
38
38
  }[];
39
39
  prefixes: string[];
40
40
  }
41
+ /** What a caller knows about a gitdir it registers with `registerGitdir`. */
42
+ export interface GitdirFacts {
43
+ /**
44
+ * Top-level gitdir files this backend never writes, such as
45
+ * `packed-refs` or `shallow`; reading or statting them answers ENOENT
46
+ * with zero store calls. isomorphic-git probes both on most commands.
47
+ */
48
+ absentFiles?: readonly string[];
49
+ }
41
50
  /** Options accepted by {@link ../git-fs.createGitFs}. */
42
- interface GitFsOptions {
51
+ export interface GitFsOptions {
43
52
  /**
44
53
  * Key prefix all paths are stored under, e.g. `"repos/alice/blog"`.
45
54
  * Defaults to `""` (paths map directly to keys).
@@ -48,30 +57,22 @@ interface GitFsOptions {
48
57
  /**
49
58
  * Track, per git directory, whether any loose objects exist at all.
50
59
  * Fully packed repositories then skip the doomed round trip probing a
51
- * loose-object path that is guaranteed to miss — but only after an
52
- * explicit `detectLooseObjects(gitdir)` call has registered the gitdir.
60
+ * loose-object path that is guaranteed to miss. The first loose-object
61
+ * read under a gitdir detects its hint (one listing) if no explicit
62
+ * `detectLooseObjects(gitdir)` call already has.
53
63
  * Default false.
54
64
  */
55
65
  looseObjectHints?: boolean;
56
- /**
57
- * Paths (relative to the fs, before `prefix` is applied) that are known
58
- * never to exist; `readFile`/`stat` answer ENOENT for them with zero
59
- * store calls. Useful for files git probes on every operation but this
60
- * backend never writes, such as `packed-refs` or `shallow` under a known
61
- * gitdir layout. Match precisely — a plain suffix check is wrong, since
62
- * e.g. `refs/heads/packed-refs` is a legal branch ref.
63
- */
64
- isStructurallyAbsent?: (path: string) => boolean;
65
66
  /** Time-to-live for loose-object hints in milliseconds. Default 3 600 000. */
66
67
  hintTtlMs?: number;
67
68
  /** Diagnostic sink for notable fs events (hint detection results). */
68
69
  onNote?: (message: string) => void;
69
70
  }
70
- type Encoding = "utf8";
71
- interface ReadFileOptions {
71
+ export type Encoding = "utf8";
72
+ export interface ReadFileOptions {
72
73
  encoding?: Encoding;
73
74
  }
74
- interface WriteFileOptions {
75
+ export interface WriteFileOptions {
75
76
  encoding?: Encoding;
76
77
  mode?: number;
77
78
  }
@@ -79,7 +80,7 @@ interface WriteFileOptions {
79
80
  * The stat shape isomorphic-git expects. Object storage has no inodes,
80
81
  * owners, or modification times, so numeric fields are zero.
81
82
  */
82
- interface Stat {
83
+ export interface Stat {
83
84
  type: "file" | "dir";
84
85
  mode: number;
85
86
  size: number;
@@ -100,7 +101,7 @@ interface Stat {
100
101
  * option. Declared locally so the package has no dependency on
101
102
  * isomorphic-git itself.
102
103
  */
103
- interface GitFsClient {
104
+ export interface GitFsClient {
104
105
  promises: {
105
106
  readFile(filepath: string, options?: ReadFileOptions | Encoding): Promise<Uint8Array | string>;
106
107
  writeFile(filepath: string, data: Uint8Array | string, options?: WriteFileOptions | Encoding): Promise<void>;
@@ -117,5 +118,3 @@ interface GitFsClient {
117
118
  chmod(filepath: string, mode: number): Promise<void>;
118
119
  };
119
120
  }
120
-
121
- export type { GitFsClient as G, ListOptions as L, ObjectStore as O, Stat as S, GitFsOptions as a, ObjectStat as b, ListResult as c };
package/package.json CHANGED
@@ -1,28 +1,24 @@
1
1
  {
2
2
  "name": "git-fs-s3",
3
- "version": "0.3.13",
3
+ "version": "0.5.0",
4
4
  "description": "isomorphic-git filesystem backend for S3-compatible object storage (AWS S3, Cloudflare R2, MinIO) — run git servers without a disk",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./dist/index.d.ts",
9
- "import": "./dist/index.js",
10
- "require": "./dist/index.cjs"
8
+ "types": "./dist/types/index.d.ts",
9
+ "import": "./dist/index.js"
11
10
  },
12
11
  "./s3": {
13
- "types": "./dist/s3.d.ts",
14
- "import": "./dist/s3.js",
15
- "require": "./dist/s3.cjs"
12
+ "types": "./dist/types/stores/s3.d.ts",
13
+ "import": "./dist/s3.js"
16
14
  },
17
15
  "./ops": {
18
- "types": "./dist/ops.d.ts",
19
- "import": "./dist/ops.js",
20
- "require": "./dist/ops.cjs"
16
+ "types": "./dist/types/ops/index.d.ts",
17
+ "import": "./dist/ops.js"
21
18
  },
22
19
  "./http": {
23
- "types": "./dist/http.d.ts",
24
- "import": "./dist/http.js",
25
- "require": "./dist/http.cjs"
20
+ "types": "./dist/types/http/index.d.ts",
21
+ "import": "./dist/http.js"
26
22
  }
27
23
  },
28
24
  "files": [
@@ -30,7 +26,7 @@
30
26
  ],
31
27
  "sideEffects": false,
32
28
  "scripts": {
33
- "build": "tsup",
29
+ "build": "tsup && tsc -p tsconfig.build.json",
34
30
  "test": "vitest run",
35
31
  "test:watch": "vitest",
36
32
  "coverage": "vitest run --coverage",
@@ -66,10 +62,10 @@
66
62
  "access": "public"
67
63
  },
68
64
  "engines": {
69
- "node": ">=18"
65
+ "node": ">=22"
70
66
  },
71
67
  "dependencies": {
72
- "lru-cache": "^11.2.1"
68
+ "lru-cache": "^11.5.3"
73
69
  },
74
70
  "peerDependencies": {
75
71
  "@aws-sdk/client-s3": ">=3.0.0",
@@ -88,13 +84,13 @@
88
84
  }
89
85
  },
90
86
  "devDependencies": {
91
- "@aws-sdk/client-s3": "^3.750.0",
92
- "@biomejs/biome": "^2.3.8",
93
- "@types/node": "^22.15.21",
94
- "isomorphic-git": "^1.27.0",
95
- "tsup": "^8.5.0",
96
- "typescript": "^5.8.3",
97
- "vitest": "^3.2.3",
87
+ "@aws-sdk/client-s3": "^3.1149.0",
88
+ "@biomejs/biome": "^2.5.15",
89
+ "@types/node": "^26.6.5",
90
+ "isomorphic-git": "^1.43.3",
91
+ "tsup": "^8.5.1",
92
+ "typescript": "^7.0.2",
93
+ "vitest": "^5.0.3",
98
94
  "diff": "^9.0.0"
99
95
  },
100
96
  "allowScripts": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/ops/branch.ts"],"sourcesContent":["import git from \"isomorphic-git\";\nimport { GitInvalidRequestError } from \"../git-errors.js\";\nimport { isSafeBranchName } from \"../refs.js\";\nimport type { Repo } from \"./types.js\";\n\nexport interface Branch {\n\tname: string;\n\tcommit: string;\n\tisDefault: boolean;\n}\n\n/**\n * Defense in depth for every branch-name argument below: `git.deleteBranch`\n * and raw resolveRef/writeRef reads don't validate ref names internally the\n * way `git.branch` does (see refs.ts) — guard at the point the primitives are\n * actually called, not just at an API boundary far above.\n */\nexport function assertSafeBranchName(name: string): void {\n\tif (!isSafeBranchName(name)) {\n\t\tthrow new GitInvalidRequestError(`Invalid branch name: ${name}`);\n\t}\n}\n\nconst FULL_SHA_RE = /^[0-9a-f]{40}$/i;\n\ntype RecursiveFileLister = {\n\tlistFilesRecursively(dirpath: string): Promise<string[]>;\n};\n\nfunction hasRecursiveFileLister(\n\tfs: Repo[\"fs\"],\n): fs is Repo[\"fs\"] & RecursiveFileLister {\n\treturn (\n\t\ttypeof fs === \"object\" &&\n\t\tfs !== null &&\n\t\t\"listFilesRecursively\" in fs &&\n\t\ttypeof (fs as Partial<RecursiveFileLister>).listFilesRecursively ===\n\t\t\t\"function\"\n\t);\n}\n\ntype PromisesFs = {\n\treadFile(path: string, encoding: \"utf8\"): Promise<string | Uint8Array>;\n};\n\n// Repo.fs is typed as isomorphic-git's own fs union (promise- or\n// callback-based) since that's what git.readTree's signature allows, but\n// every fs this package actually constructs (git-fs.ts) is promise-based —\n// this just keeps the callback-style branch honest instead of crashing on\n// it. Shared by every loose-ref fast path below instead of each repeating\n// the same cast + presence check.\nfunction getPromisesFs(fs: Repo[\"fs\"]): PromisesFs | null {\n\tconst promises = (fs as { promises?: PromisesFs }).promises;\n\treturn promises ?? null;\n}\n\nfunction decodeFileContent(content: string | Uint8Array): string {\n\treturn typeof content === \"string\"\n\t\t? content\n\t\t: new TextDecoder().decode(content);\n}\n\n/**\n * Lists loose branch names without isomorphic-git's recursive readdir/stat\n * traversal. Object stores already return only leaf keys in a recursive LIST,\n * so this is one request regardless of branch-name nesting. Ordinary\n * filesystems retain isomorphic-git's implementation and packed refs remain\n * supported there.\n */\nasync function listLooseBranches(repo: Repo): Promise<string[] | null> {\n\tif (!hasRecursiveFileLister(repo.fs)) return null;\n\tconst names = await repo.fs.listFilesRecursively(`${repo.gitdir}/refs/heads`);\n\treturn names.filter(isSafeBranchName);\n}\n\n/** Read packed branch refs so the object-store fast path preserves Git semantics. */\nasync function readPackedBranches(repo: Repo): Promise<Map<string, string>> {\n\tif (!hasRecursiveFileLister(repo.fs)) return new Map();\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (!promisesFs) return new Map();\n\ttry {\n\t\tconst content = await promisesFs.readFile(\n\t\t\t`${repo.gitdir}/packed-refs`,\n\t\t\t\"utf8\",\n\t\t);\n\t\tconst refs = new Map<string, string>();\n\t\tfor (const line of decodeFileContent(content).split(\"\\n\")) {\n\t\t\tconst match = /^([0-9a-f]{40}) refs\\/heads\\/(.+)$/i.exec(line);\n\t\t\tif (match?.[1] && match[2] && isSafeBranchName(match[2])) {\n\t\t\t\trefs.set(match[2], match[1]);\n\t\t\t}\n\t\t}\n\t\treturn refs;\n\t} catch {\n\t\treturn new Map();\n\t}\n}\n\n/** Read the symbolic HEAD directly when the object-store fs is available. */\nasync function getCurrentLooseBranch(repo: Repo): Promise<string | null> {\n\tif (!hasRecursiveFileLister(repo.fs)) return null;\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (!promisesFs) return null;\n\ttry {\n\t\tconst content = await promisesFs.readFile(`${repo.gitdir}/HEAD`, \"utf8\");\n\t\tconst head = decodeFileContent(content).trim();\n\t\tconst match = /^ref: refs\\/heads\\/(.+)$/.exec(head);\n\t\treturn match?.[1] && isSafeBranchName(match[1]) ? match[1] : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Resolve a fully-qualified ref's oid with one read instead of isomorphic-\n * git's own `resolveRef`, which does a stat *then* a read for a loose ref\n * (two round trips against object storage) — wasteful specifically here,\n * where the caller already knows the ref exists (it came from a directory\n * listing moments earlier). Reads the loose file directly and falls back to\n * `git.resolveRef` only when that doesn't pan out (packed-refs, or anything\n * else the plain-loose-file assumption doesn't cover), so correctness for\n * those cases is unchanged — this only removes the redundant round trip on\n * the common path.\n */\nexport async function resolveLooseRefFast(\n\trepo: Repo,\n\tref: string,\n): Promise<string> {\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (promisesFs) {\n\t\ttry {\n\t\t\tconst content = await promisesFs.readFile(\n\t\t\t\t`${repo.gitdir}/${ref}`,\n\t\t\t\t\"utf8\",\n\t\t\t);\n\t\t\tconst oid = decodeFileContent(content).trim();\n\t\t\tif (FULL_SHA_RE.test(oid)) return oid;\n\t\t} catch {\n\t\t\t// Not a loose file (packed-refs, or genuinely absent) — fall through.\n\t\t}\n\t}\n\treturn git.resolveRef({ ...repo, ref });\n}\n\n/** All branches with their tip commits; [] for an empty repository. */\nexport async function listBranches(repo: Repo): Promise<Branch[]> {\n\ttry {\n\t\tconst [looseBranches, looseCurrentBranch, packedBranches] =\n\t\t\tawait Promise.all([\n\t\t\t\tlistLooseBranches(repo),\n\t\t\t\tgetCurrentLooseBranch(repo),\n\t\t\t\treadPackedBranches(repo),\n\t\t\t]);\n\t\tconst branches =\n\t\t\tlooseBranches === null\n\t\t\t\t? await git.listBranches(repo)\n\t\t\t\t: [...new Set([...looseBranches, ...packedBranches.keys()])].sort();\n\t\tconst currentBranch =\n\t\t\tlooseBranches === null\n\t\t\t\t? await git\n\t\t\t\t\t\t.currentBranch({ ...repo, fullname: false })\n\t\t\t\t\t\t.catch(() => null)\n\t\t\t\t: looseCurrentBranch;\n\n\t\treturn Promise.all(\n\t\t\tbranches.map(async (branch) => {\n\t\t\t\tconst packedCommit = packedBranches.get(branch);\n\t\t\t\treturn {\n\t\t\t\t\tname: branch,\n\t\t\t\t\tcommit:\n\t\t\t\t\t\tpackedCommit && !looseBranches?.includes(branch)\n\t\t\t\t\t\t\t? packedCommit\n\t\t\t\t\t\t\t: await resolveLooseRefFast(repo, `refs/heads/${branch}`),\n\t\t\t\t\tisDefault: branch === currentBranch,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\t} catch (err: unknown) {\n\t\tif ((err as { code?: string }).code === \"NotFoundError\") return [];\n\t\tthrow err;\n\t}\n}\n\n/** Create `name` pointing at the tip of `startPoint` (no checkout). */\nexport async function createBranchFrom(\n\trepo: Repo,\n\tname: string,\n\tstartPoint = \"main\",\n): Promise<void> {\n\tassertSafeBranchName(name);\n\tassertSafeBranchName(startPoint);\n\tconst object = await resolveLooseRefFast(repo, `refs/heads/${startPoint}`);\n\tawait git.branch({ ...repo, ref: name, checkout: false, object });\n}\n\n/** Delete a branch ref (validated — deleteBranch has no internal ref check). */\nexport async function deleteBranchByName(\n\trepo: Repo,\n\tname: string,\n): Promise<void> {\n\tassertSafeBranchName(name);\n\tawait git.deleteBranch({ ...repo, ref: name });\n}\n\n/** Throws (NotFoundError) unless the branch resolves. */\nexport async function assertBranchExists(\n\trepo: Repo,\n\tname: string,\n): Promise<void> {\n\tassertSafeBranchName(name);\n\tawait resolveLooseRefFast(repo, `refs/heads/${name}`);\n}\n"],"mappings":";;;;;;AAAA,OAAO,SAAS;AAiBT,SAAS,qBAAqB,MAAoB;AACxD,MAAI,CAAC,iBAAiB,IAAI,GAAG;AAC5B,UAAM,IAAI,uBAAuB,wBAAwB,IAAI,EAAE;AAAA,EAChE;AACD;AAEA,IAAM,cAAc;AAMpB,SAAS,uBACR,IACyC;AACzC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AM;AAAA,UACN,QACC,gBAAgB,CAAC,eAAe,SAAS,MAAM,IAC5C,eACA,MAAM,oBAAoB,MAAM,cAAc,MAAM,EAAE;AAAA,UAC1D,WAAW,WAAW;AAAA,QACvB;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD,SAAS,KAAc;AACtB,QAAK,IAA0B,SAAS,gBAAiB,QAAO,CAAC;AACjE,UAAM;AAAA,EACP;AACD;AAGA,eAAsB,iBACrB,MACA,MACA,aAAa,QACG;AAChB,uBAAqB,IAAI;AACzB,uBAAqB,UAAU;AAC/B,QAAM,SAAS,MAAM,oBAAoB,MAAM,cAAc,UAAU,EAAE;AACzE,QAAM,IAAI,OAAO,EAAE,GAAG,MAAM,KAAK,MAAM,UAAU,OAAO,OAAO,CAAC;AACjE;AAGA,eAAsB,mBACrB,MACA,MACgB;AAChB,uBAAqB,IAAI;AACzB,QAAM,IAAI,aAAa,EAAE,GAAG,MAAM,KAAK,KAAK,CAAC;AAC9C;AAGA,eAAsB,mBACrB,MACA,MACgB;AAChB,uBAAqB,IAAI;AACzB,QAAM,oBAAoB,MAAM,cAAc,IAAI,EAAE;AACrD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/edge-utils.ts","../src/git-errors.ts","../src/refs.ts"],"sourcesContent":["/**\n * Edge-compatible utilities replacing node:crypto, node:zlib, and Buffer.\n *\n * Every function here uses only Web APIs (SubtleCrypto, CompressionStream,\n * TextEncoder/TextDecoder) — no Node built-ins. They work on Cloudflare\n * Workers, Vercel Edge, Deno Deploy, and Node >= 18.\n */\n\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\n// ---------------------------------------------------------------------------\n// Text\n// ---------------------------------------------------------------------------\n\n/**\n * Encode a UTF-8 string to bytes.\n *\n * Return type pinned to `Uint8Array<ArrayBuffer>` (not the bare `Uint8Array`,\n * whose default type argument differs across TypeScript versions) so it's\n * always assignable to Fetch API `BodyInit` regardless of a consumer's own\n * TypeScript/lib version.\n */\nexport function encodeUtf8(data: string): Uint8Array<ArrayBuffer> {\n\treturn textEncoder.encode(data);\n}\n\n/** Decode bytes as UTF-8. */\nexport function decodeUtf8(data: Uint8Array): string {\n\treturn textDecoder.decode(data);\n}\n\n/** Decode bytes as ASCII. */\nexport function decodeAscii(data: Uint8Array): string {\n\tlet s = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\ts += String.fromCharCode(data[i] as number);\n\treturn s;\n}\n\n// ---------------------------------------------------------------------------\n// Array manipulation\n// ---------------------------------------------------------------------------\n\n/** Concatenate any number of Uint8Arrays into one. */\nexport function concat(...parts: Uint8Array[]): Uint8Array<ArrayBuffer> {\n\tlet total = 0;\n\tfor (const p of parts) total += p.length;\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const p of parts) {\n\t\tout.set(p, offset);\n\t\toffset += p.length;\n\t}\n\treturn out;\n}\n\n// ---------------------------------------------------------------------------\n// Encoding\n// ---------------------------------------------------------------------------\n\n/** Uint8Array → lowercase hex string. */\nexport function toHex(data: Uint8Array): string {\n\tlet hex = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\thex += (data[i] as number).toString(16).padStart(2, \"0\");\n\treturn hex;\n}\n\n/** Uint8Array → base64 string. */\nexport function toBase64(data: Uint8Array): string {\n\tlet binary = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\tbinary += String.fromCharCode(data[i] as number);\n\treturn btoa(binary);\n}\n\n/** Hex string → Uint8Array. */\nexport function fromHex(hex: string): Uint8Array<ArrayBuffer> {\n\tconst bytes = new Uint8Array(hex.length / 2);\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tbytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n\t}\n\treturn bytes;\n}\n\n// ---------------------------------------------------------------------------\n// Crypto\n// ---------------------------------------------------------------------------\n\n/** SHA-1 hash via Web Crypto API. Returns a hex string. */\nexport async function sha1(data: Uint8Array | string): Promise<string> {\n\tconst bytes = typeof data === \"string\" ? encodeUtf8(data) : data;\n\tconst hash = await globalThis.crypto.subtle.digest(\"SHA-1\", bytes);\n\treturn toHex(new Uint8Array(hash));\n}\n\n// ---------------------------------------------------------------------------\n// Compression\n// ---------------------------------------------------------------------------\n\n/**\n * Deflate compress via the CompressionStream Web API.\n * Falls back to throwing if CompressionStream is unavailable (very old runtimes).\n */\nexport async function deflate(\n\tdata: Uint8Array,\n): Promise<Uint8Array<ArrayBuffer>> {\n\tconst stream = new Blob([data])\n\t\t.stream()\n\t\t.pipeThrough(new CompressionStream(\"deflate\"));\n\treturn new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n// ---------------------------------------------------------------------------\n// Binary detection (replaces Buffer.includes(0) pattern)\n// ---------------------------------------------------------------------------\n\n/** Check if a Uint8Array contains a null byte. */\nexport function hasNullByte(data: Uint8Array): boolean {\n\treturn data.includes(0);\n}\n\n/**\n * Read a blob as text or binary metadata — the edge-compatible replacement\n * for the `Buffer.from(blob)` pattern used throughout diff.ts and history.ts.\n */\nexport function readBlobContent(blob: Uint8Array): {\n\tisBinary: boolean;\n\ttext: string;\n\tbytes: Uint8Array;\n} {\n\tconst isBinary = hasNullByte(blob);\n\treturn {\n\t\tisBinary,\n\t\ttext: isBinary ? \"\" : decodeUtf8(blob),\n\t\tbytes: blob,\n\t};\n}\n","/**\n * Git-server error types carrying an HTTP status and a retryability flag, so\n * transport layers can map internal failures to responses without inspecting\n * messages. Extend {@link GitError} for app-specific cases (storage backends,\n * quota, …) and {@link formatErrorResponse} keeps working for them.\n */\nexport class GitError extends Error {\n\tstatusCode: number;\n\tretryable: boolean;\n\n\tconstructor(message: string, statusCode = 500, retryable = false) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t\tthis.statusCode = statusCode;\n\t\tthis.retryable = retryable;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): Record<string, unknown> {\n\t\treturn {\n\t\t\terror: this.name,\n\t\t\tmessage: this.message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tretryable: this.retryable,\n\t\t};\n\t}\n}\n\n/** A file/directory path not found within a tree (404). */\nexport class GitPathNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** A git object not found (404). */\nexport class GitObjectNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** A ref (branch/tag) not found (404). */\nexport class GitRefNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** The repository itself not found (404). */\nexport class GitRepositoryNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\nexport interface MergeConflictDetail {\n\tfile: string;\n\tbaseLines?: string[];\n\tsourceLines?: string[];\n\ttargetLines?: string[];\n}\n\n/** A merge conflict (409), carrying per-file conflict detail. */\nexport class GitConflictError extends GitError {\n\tconflicts: MergeConflictDetail[];\n\n\tconstructor(message: string, conflicts: MergeConflictDetail[] = []) {\n\t\tsuper(message, 409, false);\n\t\tthis.conflicts = conflicts;\n\t}\n\n\toverride toJSON(): Record<string, unknown> {\n\t\treturn { ...super.toJSON(), conflicts: this.conflicts };\n\t}\n}\n\n/** Authentication failed (401). */\nexport class GitAuthenticationError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 401, false);\n\t}\n}\n\n/** Authorization failed (403). */\nexport class GitAuthorizationError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 403, false);\n\t}\n}\n\n/** Too many failed attempts (429). */\nexport class GitRateLimitError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 429, false);\n\t}\n}\n\n/** Malformed request (400). */\nexport class GitInvalidRequestError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 400, false);\n\t}\n}\n\n/** Git wire-protocol violation (400). */\nexport class GitProtocolError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 400, false);\n\t}\n}\n\n/**\n * Map any error to an HTTP response shape. 401s carry the WWW-Authenticate\n * header git clients need before they will prompt for credentials. Non-GitError\n * failures are masked as opaque 500s — internal messages don't leak.\n */\nexport function formatErrorResponse(error: unknown): {\n\tstatus: number;\n\tbody: Record<string, unknown>;\n\theaders?: Record<string, string>;\n} {\n\tif (error instanceof GitError) {\n\t\treturn {\n\t\t\tstatus: error.statusCode,\n\t\t\tbody: error.toJSON(),\n\t\t\theaders:\n\t\t\t\terror.statusCode === 401\n\t\t\t\t\t? { \"WWW-Authenticate\": 'Basic realm=\"Git Repository\"' }\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\tstatus: 500,\n\t\t\tbody: {\n\t\t\t\terror: \"InternalServerError\",\n\t\t\t\tmessage: \"An internal error occurred\",\n\t\t\t\tretryable: true,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: 500,\n\t\tbody: {\n\t\t\terror: \"UnknownError\",\n\t\t\tmessage: \"An unknown error occurred\",\n\t\t\tretryable: true,\n\t\t},\n\t};\n}\n","/**\n * Git ref-name validation, mirroring isomorphic-git's own internal `isValidRef`\n * character-class rules (the check `git.branch` and top-level `git.writeRef`\n * run before touching disk).\n *\n * Several of isomorphic-git's OTHER ref-touching primitives — `git.commit`,\n * `git.merge`, `git.deleteBranch`, and top-level `git.resolveRef`/\n * `git.deleteRef` — do NOT run this check internally: they resolve straight\n * through `fs.write`/`fs.rm(join(gitdir, ref))` with no jail to the gitdir.\n * On a shared-storage server (many repos under one prefix or base directory),\n * every branch/ref name that originates from request input must be validated\n * against these predicates before it reaches any of those primitives —\n * otherwise a `\"../\"`-laden name lets a caller with write access to any single\n * repo read, corrupt, or delete another repo's ref/object files.\n */\n\nconst BAD_REF_COMPONENT =\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are exactly what git's own ref-name rules reject — this needs to match the same range.\n\t/(^|[/.])([/.]|$)|^@$|@\\{|[\\x00-\\x20\\x7f~^:?*[\\\\]|\\.lock(\\/|$)/;\n\nconst FULL_SHA_RE = /^[0-9a-f]{40}$/i;\n\n/** Validates a fully-qualified ref (must start with refs/heads/ or refs/tags/). */\nexport function isSafeFullRefName(ref: string): boolean {\n\tif (!ref.startsWith(\"refs/heads/\") && !ref.startsWith(\"refs/tags/\")) {\n\t\treturn false;\n\t}\n\treturn !BAD_REF_COMPONENT.test(ref);\n}\n\n/**\n * Validates a bare branch name (no refs/ prefix). Rejects anything that looks\n * like a full ref path — a name of `\"refs/heads/x\"` would otherwise sail\n * through unprefixed at call sites that build `refs/heads/${name}` themselves\n * (doubling the prefix into something that still resolves), or be used as-is\n * at call sites that pass a name already containing `\"refs/\"` straight\n * through. Also rejects 40-hex SHA-shaped values so a stored branch name can\n * never be ambiguous with a commit SHA at write time; use\n * {@link isSafeRefName} on read paths that accept both shapes.\n */\nexport function isSafeBranchName(name: string): boolean {\n\tif (!name || name.startsWith(\"refs/\") || name === \"HEAD\") return false;\n\tif (FULL_SHA_RE.test(name)) return false;\n\treturn !BAD_REF_COMPONENT.test(name);\n}\n\n/** True for a full 40-hex-char commit SHA — the shape {@link isSafeBranchName} deliberately rejects. */\nexport function isFullSha(value: string): boolean {\n\treturn FULL_SHA_RE.test(value);\n}\n\n/**\n * Validates a \"ref\" field that may name either a branch or a commit SHA it's\n * pinned to — the shape read-path route params take (permalinks, raw links).\n * Both shapes still go through the traversal check.\n */\nexport function isSafeRefName(value: string): boolean {\n\treturn isSafeBranchName(value) || isFullSha(value);\n}\n\n/**\n * Validates a repo-relative file path from request input: relative, no `..`\n * segments, no `.git/` prefix, no null bytes. Use this anywhere a path\n * segment comes straight off a URL or form field rather than re-deriving the\n * checks ad hoc.\n */\nexport function isSafeRepoPath(p: string): boolean {\n\tif (p.startsWith(\"/\")) return false;\n\tif (p.split(\"/\").some((segment) => segment === \"..\")) return false;\n\tif (/^\\.git(\\/|$)/i.test(p)) return false;\n\tif (p.includes(\"\\0\")) return false;\n\treturn true;\n}\n\n/**\n * Qualify a bare branch name to `refs/heads/<name>` before handing it to\n * isomorphic-git. `resolveRef`/`expand` try several candidate paths in\n * sequence for a bare name — `ref`, `refs/ref`, `refs/tags/ref`,\n * `refs/heads/ref`, … — missing (and, against object storage, paying a real\n * round trip for) the first three every time. For a branch-only ref model,\n * skip straight to the winner. Left untouched: already-qualified refs,\n * `\"HEAD\"` (its own first candidate, already optimal), and 40-hex oids\n * (resolved locally by isomorphic-git with no I/O at all).\n */\nexport function qualifyBranchRef(ref: string): string {\n\tif (ref.startsWith(\"refs/\") || ref === \"HEAD\" || FULL_SHA_RE.test(ref)) {\n\t\treturn ref;\n\t}\n\treturn `refs/heads/${ref}`;\n}\n"],"mappings":";AAQA,IAAM,cAAc,IAAI,YAAY;AACpC,IAAM,cAAc,IAAI,YAAY;AAc7B,SAAS,WAAW,MAAuC;AACjE,SAAO,YAAY,OAAO,IAAI;AAC/B;AAGO,SAAS,WAAW,MAA0B;AACpD,SAAO,YAAY,OAAO,IAAI;AAC/B;AAGO,SAAS,YAAY,MAA0B;AACrD,MAAI,IAAI;AACR,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ;AAChC,SAAK,OAAO,aAAa,KAAK,CAAC,CAAW;AAC3C,SAAO;AACR;AAOO,SAAS,UAAU,OAA8C;AACvE,MAAI,QAAQ;AACZ,aAAW,KAAK,MAAO,UAAS,EAAE;AAClC,QAAM,MAAM,IAAI,WAAW,KAAK;AAChC,MAAI,SAAS;AACb,aAAW,KAAK,OAAO;AACtB,QAAI,IAAI,GAAG,MAAM;AACjB,cAAU,EAAE;AAAA,EACb;AACA,SAAO;AACR;AAOO,SAAS,MAAM,MAA0B;AAC/C,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ;AAChC,WAAQ,KAAK,CAAC,EAAa,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AACxD,SAAO;AACR;AAGO,SAAS,SAAS,MAA0B;AAClD,MAAI,SAAS;AACb,WAAS,I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