@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.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.
- package/LICENSE +201 -0
- package/README.md +50 -2
- package/dist/behaviour/assertions.d.ts +23 -0
- package/dist/behaviour/assertions.js +56 -0
- package/dist/behaviour/assertions.js.map +1 -0
- package/dist/behaviour/behaviour-case.d.ts +19 -0
- package/dist/behaviour/behaviour-case.js +12 -0
- package/dist/behaviour/behaviour-case.js.map +1 -0
- package/dist/behaviour/behaviour-suite.d.ts +30 -0
- package/dist/behaviour/behaviour-suite.js +50 -0
- package/dist/behaviour/behaviour-suite.js.map +1 -0
- package/dist/behaviour/commit-action-cases.d.ts +4 -0
- package/dist/behaviour/commit-action-cases.js +342 -0
- package/dist/behaviour/commit-action-cases.js.map +1 -0
- package/dist/behaviour/commit-write-cases.d.ts +4 -0
- package/dist/behaviour/commit-write-cases.js +234 -0
- package/dist/behaviour/commit-write-cases.js.map +1 -0
- package/dist/behaviour/fixtures.d.ts +29 -0
- package/dist/behaviour/fixtures.js +83 -0
- package/dist/behaviour/fixtures.js.map +1 -0
- package/dist/behaviour/lifecycle-cases.d.ts +4 -0
- package/dist/behaviour/lifecycle-cases.js +158 -0
- package/dist/behaviour/lifecycle-cases.js.map +1 -0
- package/dist/behaviour/promote-cases.d.ts +4 -0
- package/dist/behaviour/promote-cases.js +122 -0
- package/dist/behaviour/promote-cases.js.map +1 -0
- package/dist/behaviour/read-cases.d.ts +4 -0
- package/dist/behaviour/read-cases.js +248 -0
- package/dist/behaviour/read-cases.js.map +1 -0
- package/dist/behaviour/sync-cases.d.ts +4 -0
- package/dist/behaviour/sync-cases.js +205 -0
- package/dist/behaviour/sync-cases.js.map +1 -0
- package/dist/clock-B3MlpmVY.d.ts +10 -0
- package/dist/commit-BEZmeAOl.d.ts +23 -0
- package/dist/file-map-CxUveLWz.d.ts +18 -0
- package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
- package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
- package/dist/gateway-error.d.ts +30 -0
- package/dist/gateway-error.js +63 -0
- package/dist/gateway-error.js.map +1 -0
- package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
- package/dist/git-gateway.d.ts +2 -0
- package/dist/git-gateway.js +65 -0
- package/dist/git-gateway.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.js +18 -0
- package/dist/health.js.map +1 -0
- package/dist/history-CqvHaUE-.d.ts +20 -0
- package/dist/package-name.d.ts +3 -0
- package/dist/package-name.js +6 -0
- package/dist/package-name.js.map +1 -0
- package/dist/proxy/audit-event.d.ts +61 -0
- package/dist/proxy/audit-event.js +97 -0
- package/dist/proxy/audit-event.js.map +1 -0
- package/dist/proxy/branch-rule.d.ts +72 -0
- package/dist/proxy/branch-rule.js +106 -0
- package/dist/proxy/branch-rule.js.map +1 -0
- package/dist/proxy/gateway-hooks.d.ts +58 -0
- package/dist/proxy/gateway-hooks.js +0 -0
- package/dist/proxy/git-operation.d.ts +17 -0
- package/dist/proxy/git-operation.js +32 -0
- package/dist/proxy/git-operation.js.map +1 -0
- package/dist/proxy/policy-result.d.ts +51 -0
- package/dist/proxy/policy-result.js +90 -0
- package/dist/proxy/policy-result.js.map +1 -0
- package/dist/proxy/principal.d.ts +18 -0
- package/dist/proxy/principal.js +32 -0
- package/dist/proxy/principal.js.map +1 -0
- package/dist/proxy/push-policy-result.d.ts +34 -0
- package/dist/proxy/push-policy-result.js +48 -0
- package/dist/proxy/push-policy-result.js.map +1 -0
- package/dist/proxy/push-policy.d.ts +146 -0
- package/dist/proxy/push-policy.js +112 -0
- package/dist/proxy/push-policy.js.map +1 -0
- package/dist/proxy/request-credential.d.ts +22 -0
- package/dist/proxy/request-credential.js +46 -0
- package/dist/proxy/request-credential.js.map +1 -0
- package/dist/proxy/smart-http-config.d.ts +22 -0
- package/dist/proxy/smart-http-config.js +40 -0
- package/dist/proxy/smart-http-config.js.map +1 -0
- package/dist/reference/apply-actions.d.ts +9 -0
- package/dist/reference/apply-actions.js +84 -0
- package/dist/reference/apply-actions.js.map +1 -0
- package/dist/reference/branch-methods.d.ts +7 -0
- package/dist/reference/branch-methods.js +105 -0
- package/dist/reference/branch-methods.js.map +1 -0
- package/dist/reference/bytes.d.ts +22 -0
- package/dist/reference/bytes.js +62 -0
- package/dist/reference/bytes.js.map +1 -0
- package/dist/reference/clock.d.ts +2 -0
- package/dist/reference/clock.js +18 -0
- package/dist/reference/clock.js.map +1 -0
- package/dist/reference/commit-method.d.ts +5 -0
- package/dist/reference/commit-method.js +83 -0
- package/dist/reference/commit-method.js.map +1 -0
- package/dist/reference/file-map.d.ts +2 -0
- package/dist/reference/file-map.js +24 -0
- package/dist/reference/file-map.js.map +1 -0
- package/dist/reference/hash.d.ts +10 -0
- package/dist/reference/hash.js +25 -0
- package/dist/reference/hash.js.map +1 -0
- package/dist/reference/history.d.ts +2 -0
- package/dist/reference/history.js +65 -0
- package/dist/reference/history.js.map +1 -0
- package/dist/reference/lifecycle-methods.d.ts +9 -0
- package/dist/reference/lifecycle-methods.js +48 -0
- package/dist/reference/lifecycle-methods.js.map +1 -0
- package/dist/reference/read-methods.d.ts +13 -0
- package/dist/reference/read-methods.js +68 -0
- package/dist/reference/read-methods.js.map +1 -0
- package/dist/reference/reference-gateway.d.ts +18 -0
- package/dist/reference/reference-gateway.js +35 -0
- package/dist/reference/reference-gateway.js.map +1 -0
- package/dist/reference/repo-state.d.ts +43 -0
- package/dist/reference/repo-state.js +45 -0
- package/dist/reference/repo-state.js.map +1 -0
- package/dist/reference/run-method.d.ts +13 -0
- package/dist/reference/run-method.js +15 -0
- package/dist/reference/run-method.js.map +1 -0
- package/dist/reference/three-way-merge.d.ts +16 -0
- package/dist/reference/three-way-merge.js +45 -0
- package/dist/reference/three-way-merge.js.map +1 -0
- package/dist/reference/trailer.d.ts +7 -0
- package/dist/reference/trailer.js +16 -0
- package/dist/reference/trailer.js.map +1 -0
- package/dist/reference/tree-index.d.ts +2 -0
- package/dist/reference/tree-index.js +66 -0
- package/dist/reference/tree-index.js.map +1 -0
- package/dist/reference/write-commit.d.ts +15 -0
- package/dist/reference/write-commit.js +44 -0
- package/dist/reference/write-commit.js.map +1 -0
- package/dist/rpc/commit-exists.d.ts +16 -0
- package/dist/rpc/commit-exists.js +30 -0
- package/dist/rpc/commit-exists.js.map +1 -0
- package/dist/rpc/commit.d.ts +172 -0
- package/dist/rpc/commit.js +115 -0
- package/dist/rpc/commit.js.map +1 -0
- package/dist/rpc/list-tree.d.ts +59 -0
- package/dist/rpc/list-tree.js +54 -0
- package/dist/rpc/list-tree.js.map +1 -0
- package/dist/rpc/log.d.ts +35 -0
- package/dist/rpc/log.js +41 -0
- package/dist/rpc/log.js.map +1 -0
- package/dist/rpc/mint-read-token.d.ts +17 -0
- package/dist/rpc/mint-read-token.js +36 -0
- package/dist/rpc/mint-read-token.js.map +1 -0
- package/dist/rpc/promote.d.ts +39 -0
- package/dist/rpc/promote.js +69 -0
- package/dist/rpc/promote.js.map +1 -0
- package/dist/rpc/read-file.d.ts +44 -0
- package/dist/rpc/read-file.js +56 -0
- package/dist/rpc/read-file.js.map +1 -0
- package/dist/rpc/repo-lifecycle.d.ts +39 -0
- package/dist/rpc/repo-lifecycle.js +64 -0
- package/dist/rpc/repo-lifecycle.js.map +1 -0
- package/dist/rpc/resolve-ref.d.ts +15 -0
- package/dist/rpc/resolve-ref.js +28 -0
- package/dist/rpc/resolve-ref.js.map +1 -0
- package/dist/rpc/sync-branch.d.ts +107 -0
- package/dist/rpc/sync-branch.js +114 -0
- package/dist/rpc/sync-branch.js.map +1 -0
- package/dist/schemas/commit-action.d.ts +100 -0
- package/dist/schemas/commit-action.js +138 -0
- package/dist/schemas/commit-action.js.map +1 -0
- package/dist/schemas/commit.d.ts +2 -0
- package/dist/schemas/commit.js +24 -0
- package/dist/schemas/commit.js.map +1 -0
- package/dist/schemas/content-encoding.d.ts +24 -0
- package/dist/schemas/content-encoding.js +41 -0
- package/dist/schemas/content-encoding.js.map +1 -0
- package/dist/schemas/examples.d.ts +38 -0
- package/dist/schemas/examples.js +32 -0
- package/dist/schemas/examples.js.map +1 -0
- package/dist/schemas/gateway-config.d.ts +2 -0
- package/dist/schemas/gateway-config.js +72 -0
- package/dist/schemas/gateway-config.js.map +1 -0
- package/dist/schemas/gateway-error-body.d.ts +2 -0
- package/dist/schemas/gateway-error-body.js +188 -0
- package/dist/schemas/gateway-error-body.js.map +1 -0
- package/dist/schemas/identity.d.ts +21 -0
- package/dist/schemas/identity.js +40 -0
- package/dist/schemas/identity.js.map +1 -0
- package/dist/schemas/names.d.ts +26 -0
- package/dist/schemas/names.js +58 -0
- package/dist/schemas/names.js.map +1 -0
- package/dist/schemas/ref-update.d.ts +10 -0
- package/dist/schemas/ref-update.js +25 -0
- package/dist/schemas/ref-update.js.map +1 -0
- package/dist/schemas/sha.d.ts +8 -0
- package/dist/schemas/sha.js +14 -0
- package/dist/schemas/sha.js.map +1 -0
- package/dist/schemas/tree-entry.d.ts +2 -0
- package/dist/schemas/tree-entry.js +62 -0
- package/dist/schemas/tree-entry.js.map +1 -0
- package/dist/storage/git-remote.d.ts +17 -0
- package/dist/storage/git-remote.js +31 -0
- package/dist/storage/git-remote.js.map +1 -0
- package/dist/storage/storage-backend.d.ts +61 -0
- package/dist/storage/storage-backend.js +0 -0
- package/dist/storage/storage-errors.d.ts +12 -0
- package/dist/storage/storage-errors.js +22 -0
- package/dist/storage/storage-errors.js.map +1 -0
- package/dist/storage/storage-input.d.ts +7 -0
- package/dist/storage/storage-input.js +14 -0
- package/dist/storage/storage-input.js.map +1 -0
- package/dist/storage/storage-read.d.ts +13 -0
- package/dist/storage/storage-read.js +30 -0
- package/dist/storage/storage-read.js.map +1 -0
- package/dist/storage/storage-repo-info.d.ts +16 -0
- package/dist/storage/storage-repo-info.js +30 -0
- package/dist/storage/storage-repo-info.js.map +1 -0
- package/dist/storage/storage-tree-entry.d.ts +21 -0
- package/dist/storage/storage-tree-entry.js +17 -0
- package/dist/storage/storage-tree-entry.js.map +1 -0
- package/dist/tree-entry-BM_1gou1.d.ts +41 -0
- package/dist/tree-index-Bk721Phv.d.ts +14 -0
- package/package.json +401 -4
- package/src/behaviour/assertions.ts +75 -0
- package/src/behaviour/behaviour-case.ts +28 -0
- package/src/behaviour/behaviour-suite.ts +76 -0
- package/src/behaviour/commit-action-cases.ts +253 -0
- package/src/behaviour/commit-write-cases.ts +205 -0
- package/src/behaviour/fixtures.ts +103 -0
- package/src/behaviour/lifecycle-cases.ts +104 -0
- package/src/behaviour/promote-cases.ts +78 -0
- package/src/behaviour/read-cases.ts +176 -0
- package/src/behaviour/sync-cases.ts +156 -0
- package/src/gateway-error.ts +72 -0
- package/src/git-gateway.ts +76 -0
- package/src/health.ts +26 -0
- package/src/package-name.ts +4 -0
- package/src/proxy/audit-event.ts +135 -0
- package/src/proxy/branch-rule.ts +190 -0
- package/src/proxy/gateway-hooks.ts +67 -0
- package/src/proxy/git-operation.ts +36 -0
- package/src/proxy/policy-result.ts +127 -0
- package/src/proxy/principal.ts +81 -0
- package/src/proxy/push-policy-result.ts +86 -0
- package/src/proxy/push-policy.ts +158 -0
- package/src/proxy/request-credential.ts +47 -0
- package/src/proxy/smart-http-config.ts +158 -0
- package/src/reference/apply-actions.ts +96 -0
- package/src/reference/branch-methods.ts +105 -0
- package/src/reference/bytes.ts +66 -0
- package/src/reference/clock.ts +19 -0
- package/src/reference/commit-method.ts +97 -0
- package/src/reference/file-map.ts +35 -0
- package/src/reference/hash.ts +25 -0
- package/src/reference/history.ts +78 -0
- package/src/reference/lifecycle-methods.ts +52 -0
- package/src/reference/read-methods.ts +87 -0
- package/src/reference/reference-gateway.ts +50 -0
- package/src/reference/repo-state.ts +83 -0
- package/src/reference/run-method.ts +25 -0
- package/src/reference/three-way-merge.ts +42 -0
- package/src/reference/trailer.ts +18 -0
- package/src/reference/tree-index.ts +65 -0
- package/src/reference/write-commit.ts +44 -0
- package/src/rpc/commit-exists.ts +46 -0
- package/src/rpc/commit.ts +156 -0
- package/src/rpc/list-tree.ts +78 -0
- package/src/rpc/log.ts +51 -0
- package/src/rpc/mint-read-token.ts +59 -0
- package/src/rpc/promote.ts +72 -0
- package/src/rpc/read-file.ts +75 -0
- package/src/rpc/repo-lifecycle.ts +103 -0
- package/src/rpc/resolve-ref.ts +41 -0
- package/src/rpc/sync-branch.ts +149 -0
- package/src/schemas/commit-action.ts +157 -0
- package/src/schemas/commit.ts +43 -0
- package/src/schemas/content-encoding.ts +58 -0
- package/src/schemas/examples.ts +24 -0
- package/src/schemas/gateway-config.ts +116 -0
- package/src/schemas/gateway-error-body.ts +230 -0
- package/src/schemas/identity.ts +57 -0
- package/src/schemas/names.ts +126 -0
- package/src/schemas/ref-update.ts +38 -0
- package/src/schemas/sha.ts +20 -0
- package/src/schemas/tree-entry.ts +72 -0
- package/src/storage/git-remote.ts +58 -0
- package/src/storage/storage-backend.ts +65 -0
- package/src/storage/storage-errors.ts +24 -0
- package/src/storage/storage-input.ts +14 -0
- package/src/storage/storage-read.ts +45 -0
- package/src/storage/storage-repo-info.ts +46 -0
- package/src/storage/storage-tree-entry.ts +20 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The credential a request carries. */
|
|
2
|
+
export interface RequestCredential {
|
|
3
|
+
/** How it was sent. */
|
|
4
|
+
readonly scheme: 'basic' | 'bearer';
|
|
5
|
+
/** The HTTP Basic user name (git's credential "username"); null for a Bearer token. */
|
|
6
|
+
readonly username: string | null;
|
|
7
|
+
/** The bearer credential: the Bearer token, or the HTTP Basic password. Secret. */
|
|
8
|
+
readonly secret: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The credential in a request's Authorization header. git sends credentials as HTTP Basic, and
|
|
12
|
+
* the password is treated as a bearer credential (an OAuth access token, a JWT, an API key), so a
|
|
13
|
+
* credential helper can supply one; a Bearer header is accepted too. Null when there is none, or
|
|
14
|
+
* the header is malformed or carries an empty secret.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readCredential(request: Request): RequestCredential | null;
|
|
17
|
+
/**
|
|
18
|
+
* A SHA-256 fingerprint of a credential (lowercase hex), so caches can key on it without holding
|
|
19
|
+
* the credential.
|
|
20
|
+
*/
|
|
21
|
+
export declare function credentialFingerprint(credential: RequestCredential): Promise<string>;
|
|
22
|
+
//# sourceMappingURL=request-credential.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/proxy/request-credential.ts
|
|
2
|
+
/**
|
|
3
|
+
* The credential in a request's Authorization header. git sends credentials as HTTP Basic, and
|
|
4
|
+
* the password is treated as a bearer credential (an OAuth access token, a JWT, an API key), so a
|
|
5
|
+
* credential helper can supply one; a Bearer header is accepted too. Null when there is none, or
|
|
6
|
+
* the header is malformed or carries an empty secret.
|
|
7
|
+
*/
|
|
8
|
+
function readCredential(request) {
|
|
9
|
+
const header = request.headers.get("Authorization")?.trim();
|
|
10
|
+
if (header === void 0) return null;
|
|
11
|
+
const space = header.indexOf(" ");
|
|
12
|
+
if (space === -1) return null;
|
|
13
|
+
const scheme = header.slice(0, space).toLowerCase();
|
|
14
|
+
const value = header.slice(space + 1).trim();
|
|
15
|
+
if (scheme === "bearer") return value === "" ? null : {
|
|
16
|
+
scheme,
|
|
17
|
+
username: null,
|
|
18
|
+
secret: value
|
|
19
|
+
};
|
|
20
|
+
if (scheme !== "basic") return null;
|
|
21
|
+
let decoded;
|
|
22
|
+
try {
|
|
23
|
+
decoded = new TextDecoder().decode(Uint8Array.from(atob(value), (char) => char.codePointAt(0) ?? 0));
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const colon = decoded.indexOf(":");
|
|
28
|
+
if (colon === -1) return null;
|
|
29
|
+
const secret = decoded.slice(colon + 1);
|
|
30
|
+
return secret === "" ? null : {
|
|
31
|
+
scheme,
|
|
32
|
+
username: decoded.slice(0, colon),
|
|
33
|
+
secret
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A SHA-256 fingerprint of a credential (lowercase hex), so caches can key on it without holding
|
|
38
|
+
* the credential.
|
|
39
|
+
*/
|
|
40
|
+
async function credentialFingerprint(credential) {
|
|
41
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(credential.secret));
|
|
42
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
43
|
+
}
|
|
44
|
+
export { credentialFingerprint, readCredential };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=request-credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-credential.js","names":[],"sources":["../../src/proxy/request-credential.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** The credential a request carries. */\nexport interface RequestCredential {\n /** How it was sent. */\n readonly scheme: 'basic' | 'bearer';\n /** The HTTP Basic user name (git's credential \"username\"); null for a Bearer token. */\n readonly username: string | null;\n /** The bearer credential: the Bearer token, or the HTTP Basic password. Secret. */\n readonly secret: string;\n}\n\n/**\n * The credential in a request's Authorization header. git sends credentials as HTTP Basic, and\n * the password is treated as a bearer credential (an OAuth access token, a JWT, an API key), so a\n * credential helper can supply one; a Bearer header is accepted too. Null when there is none, or\n * the header is malformed or carries an empty secret.\n */\nexport function readCredential(request: Request): RequestCredential | null {\n const header = request.headers.get('Authorization')?.trim();\n if (header === undefined) return null;\n const space = header.indexOf(' ');\n if (space === -1) return null;\n const scheme = header.slice(0, space).toLowerCase();\n const value = header.slice(space + 1).trim();\n if (scheme === 'bearer') return value === '' ? null : { scheme, username: null, secret: value };\n if (scheme !== 'basic') return null;\n let decoded: string;\n try {\n decoded = new TextDecoder().decode(Uint8Array.from(atob(value), (char) => char.codePointAt(0) ?? 0));\n } catch {\n return null;\n }\n const colon = decoded.indexOf(':');\n if (colon === -1) return null;\n const secret = decoded.slice(colon + 1);\n return secret === '' ? null : { scheme, username: decoded.slice(0, colon), secret };\n}\n\n/**\n * A SHA-256 fingerprint of a credential (lowercase hex), so caches can key on it without holding\n * the credential.\n */\nexport async function credentialFingerprint(credential: RequestCredential): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(credential.secret));\n return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,eAAe,SAA4C;CACzE,MAAM,SAAS,QAAQ,QAAQ,IAAI,eAAe,CAAC,EAAE,KAAK;CAC1D,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,QAAQ,OAAO,QAAQ,GAAG;CAChC,IAAI,UAAU,IAAI,OAAO;CACzB,MAAM,SAAS,OAAO,MAAM,GAAG,KAAK,CAAC,CAAC,YAAY;CAClD,MAAM,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC,CAAC,KAAK;CAC3C,IAAI,WAAW,UAAU,OAAO,UAAU,KAAK,OAAO;EAAE;EAAQ,UAAU;EAAM,QAAQ;CAAM;CAC9F,IAAI,WAAW,SAAS,OAAO;CAC/B,IAAI;CACJ,IAAI;EACF,UAAU,IAAI,YAAY,CAAC,CAAC,OAAO,WAAW,KAAK,KAAK,KAAK,IAAI,SAAS,KAAK,YAAY,CAAC,KAAK,CAAC,CAAC;CACrG,QAAQ;EACN,OAAO;CACT;CACA,MAAM,QAAQ,QAAQ,QAAQ,GAAG;CACjC,IAAI,UAAU,IAAI,OAAO;CACzB,MAAM,SAAS,QAAQ,MAAM,QAAQ,CAAC;CACtC,OAAO,WAAW,KAAK,OAAO;EAAE;EAAQ,UAAU,QAAQ,MAAM,GAAG,KAAK;EAAG;CAAO;AACpF;;;;;AAMA,eAAsB,sBAAsB,YAAgD;CAC1F,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,IAAI,YAAY,CAAC,CAAC,OAAO,WAAW,MAAM,CAAC;CAChG,OAAO,CAAC,GAAG,IAAI,WAAW,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AAC9F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Settings of the smart-HTTP proxy beyond those every gateway shares (GatewayConfig). */
|
|
3
|
+
export declare const SmartHttpConfig: z.ZodObject<{
|
|
4
|
+
realm: z.ZodDefault<z.ZodString>;
|
|
5
|
+
maxPushHeadBytes: z.ZodDefault<z.ZodInt>;
|
|
6
|
+
maxAncestryReads: z.ZodDefault<z.ZodInt>;
|
|
7
|
+
maxScannedCommitBytes: z.ZodDefault<z.ZodInt>;
|
|
8
|
+
maxVerdictWaitMs: z.ZodDefault<z.ZodInt>;
|
|
9
|
+
maxPushPolicyPackBytes: z.ZodDefault<z.ZodInt>;
|
|
10
|
+
maxPushPolicyObjectBytes: z.ZodDefault<z.ZodInt>;
|
|
11
|
+
maxPushPolicyReads: z.ZodDefault<z.ZodInt>;
|
|
12
|
+
maxChangedPaths: z.ZodDefault<z.ZodInt>;
|
|
13
|
+
decisionCacheEntries: z.ZodDefault<z.ZodInt>;
|
|
14
|
+
maxAuditReportBytes: z.ZodDefault<z.ZodInt>;
|
|
15
|
+
allowedPushOptions: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
16
|
+
deniedStatus: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"err">, z.ZodLiteral<403>]>>;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
/** A smart-HTTP configuration as written (defaults optional). */
|
|
19
|
+
export type SmartHttpConfigInput = z.input<typeof SmartHttpConfig>;
|
|
20
|
+
/** A complete smart-HTTP configuration, inferred from {@link SmartHttpConfig}. */
|
|
21
|
+
export type SmartHttpConfig = z.output<typeof SmartHttpConfig>;
|
|
22
|
+
//# sourceMappingURL=smart-http-config.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// src/proxy/smart-http-config.ts
|
|
3
|
+
/** Settings of the smart-HTTP proxy beyond those every gateway shares (GatewayConfig). */
|
|
4
|
+
const SmartHttpConfig = z.object({
|
|
5
|
+
realm: z.string().min(1).max(100).regex(/^[^"\\\n\0]+$/).default("git-gateway").describe("Realm named in the WWW-Authenticate: Basic challenge of a 401, which git credential helpers show and key on; 1–100 characters without quotes, backslash, newline or NUL. Default \"git-gateway\"."),
|
|
6
|
+
maxPushHeadBytes: z.int().min(4096).max(67108864).default(8388608).describe("Most bytes of a push read before the pack (update commands, capabilities, push options); a larger head is refused. 4 KiB–64 MiB, default 8 MiB (8388608)."),
|
|
7
|
+
maxAncestryReads: z.int().min(1).max(1e5).default(2e3).describe("Most commits read from the storage backend to prove that a fast-forward-only update is a fast-forward; past it the update is refused as unverifiable. 1–100000, default 2000."),
|
|
8
|
+
maxScannedCommitBytes: z.int().min(1048576).max(268435456).default(33554432).describe("Most bytes of commit objects kept while scanning a pushed pack for ancestry; a push needing more is refused as unverifiable. 1 MiB–256 MiB, default 32 MiB (33554432)."),
|
|
9
|
+
maxVerdictWaitMs: z.int().min(0).max(6e5).default(6e4).describe("Most milliseconds a push waits, once the storage host's request has failed, for the gateway to finish proving the push from its pack, so that a refusal (which makes the host's request fail by design) is reported in-protocol as \"ng <ref> <reason>\" rather than as a 502. Past it, or when no verdict comes, the push is answered 502 and nothing is written. 0–600000, default 60000 (one minute)."),
|
|
10
|
+
maxPushPolicyPackBytes: z.int().min(1048576).max(268435456).default(33554432).describe("Most bytes of a pushed pack held in memory so the push policy can be given changed paths (only when PushPolicy.needs() asks for them); a larger push is refused as uncheckable before it completes. 1 MiB–256 MiB, default 32 MiB (33554432)."),
|
|
11
|
+
maxPushPolicyObjectBytes: z.int().min(1048576).max(536870912).default(67108864).describe("Most bytes of objects decompressed and rebuilt from the pushed pack (every entry's data plus every delta's result, thin-pack bases read from storage included) to compute changed paths; past it the push is refused as uncheckable. 1 MiB–512 MiB, default 64 MiB (67108864)."),
|
|
12
|
+
maxPushPolicyReads: z.int().min(1).max(1e5).default(2e3).describe("Most storage backend calls made to compute changed paths for the push policy — parent commits, trees and blobs not in the pushed pack (thin-pack delta bases, unchanged subtrees of a moved directory, sizes of blobs storage already has); past it the push is refused as uncheckable. 1–100000, default 2000."),
|
|
13
|
+
maxChangedPaths: z.int().min(1).max(1e5).default(1e4).describe("Most changed paths, summed over every commit of a push, given to the push policy; a push changing more is refused as uncheckable. 1–100000, default 10000."),
|
|
14
|
+
decisionCacheEntries: z.int().min(0).max(1e6).default(1e4).describe("Most authentication and authorization decisions held in the per-isolate cache, oldest evicted first; 0 disables the cache. Default 10000. How long entries live is GatewayConfig.authCacheSeconds."),
|
|
15
|
+
maxAuditReportBytes: z.int().min(0).max(16777216).default(1048576).describe("Most bytes of a storage host push response kept to read its per-ref report for the audit event and the push event; past it the refs are audited as \"unknown\" and no push event is sent. 0 skips reading reports for audit; when an onPush hook is set the report is still read, up to the 1 MiB default. Default 1 MiB (1048576)."),
|
|
16
|
+
allowedPushOptions: z.array(z.string().min(1).max(100).regex(/^[^\s\0=]+$/).describe("A push option name, the part of a \"git push -o <name>[=<value>]\" option before the first \"=\"; 1–100 characters without whitespace, NUL or \"=\". Matched exactly and case-sensitively.")).max(100).default([]).describe("Push option names the proxy forwards to the storage host; a push carrying any other option is refused before it reaches storage. The host runs push options as the gateway's own credential (GitLab's merge_request.* and ci.variable, for example), so each one bypasses branch policy unless refused here. At most 100; default none, so every push option is refused."),
|
|
17
|
+
deniedStatus: z.union([z.literal("err").describe("Answer in-protocol: HTTP 200 with an \"ERR\" packet, which git prints as \"remote error: <reason>\"."), z.literal(403).describe("Answer HTTP 403 with the reason as a plain-text body, which git prints as \"The requested URL returned error: 403\".")]).default("err").describe("How an authorization refusal (the Authorizer denying read or write of a repository) is answered: \"err\" (default) or 403. Branch-policy refusals of individual refs are always in-protocol (\"ng\" or \"ERR\"), so a push to a protected branch keeps its readable reason either way.")
|
|
18
|
+
}).strict().meta({
|
|
19
|
+
id: "SmartHttpConfig",
|
|
20
|
+
title: "Smart-HTTP proxy configuration",
|
|
21
|
+
description: "Limits and names used by the smart-HTTP proxy. Every field has a default, so {} is a complete configuration.",
|
|
22
|
+
examples: [{
|
|
23
|
+
realm: "git-gateway",
|
|
24
|
+
maxPushHeadBytes: 8388608,
|
|
25
|
+
maxAncestryReads: 2e3,
|
|
26
|
+
maxScannedCommitBytes: 33554432,
|
|
27
|
+
maxVerdictWaitMs: 6e4,
|
|
28
|
+
maxPushPolicyPackBytes: 33554432,
|
|
29
|
+
maxPushPolicyObjectBytes: 67108864,
|
|
30
|
+
maxPushPolicyReads: 2e3,
|
|
31
|
+
maxChangedPaths: 1e4,
|
|
32
|
+
decisionCacheEntries: 1e4,
|
|
33
|
+
maxAuditReportBytes: 1048576,
|
|
34
|
+
allowedPushOptions: ["ci.skip"],
|
|
35
|
+
deniedStatus: "err"
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
export { SmartHttpConfig };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=smart-http-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-http-config.js","names":[],"sources":["../../src/proxy/smart-http-config.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n/** Settings of the smart-HTTP proxy beyond those every gateway shares (GatewayConfig). */\nexport const SmartHttpConfig = z\n .object({\n realm: z\n .string()\n .min(1)\n .max(100)\n .regex(/^[^\"\\\\\\n\\0]+$/)\n .default('git-gateway')\n .describe(\n 'Realm named in the WWW-Authenticate: Basic challenge of a 401, which git credential helpers show and key on; 1–100 characters without quotes, backslash, newline or NUL. Default \"git-gateway\".',\n ),\n maxPushHeadBytes: z\n .int()\n .min(4096)\n .max(64 * 1024 * 1024)\n .default(8 * 1024 * 1024)\n .describe(\n 'Most bytes of a push read before the pack (update commands, capabilities, push options); a larger head is refused. 4 KiB–64 MiB, default 8 MiB (8388608).',\n ),\n maxAncestryReads: z\n .int()\n .min(1)\n .max(100_000)\n .default(2000)\n .describe(\n 'Most commits read from the storage backend to prove that a fast-forward-only update is a fast-forward; past it the update is refused as unverifiable. 1–100000, default 2000.',\n ),\n maxScannedCommitBytes: z\n .int()\n .min(1024 * 1024)\n .max(256 * 1024 * 1024)\n .default(32 * 1024 * 1024)\n .describe(\n 'Most bytes of commit objects kept while scanning a pushed pack for ancestry; a push needing more is refused as unverifiable. 1 MiB–256 MiB, default 32 MiB (33554432).',\n ),\n maxVerdictWaitMs: z\n .int()\n .min(0)\n .max(600_000)\n .default(60_000)\n .describe(\n 'Most milliseconds a push waits, once the storage host\\'s request has failed, for the gateway to finish proving the push from its pack, so that a refusal (which makes the host\\'s request fail by design) is reported in-protocol as \"ng <ref> <reason>\" rather than as a 502. Past it, or when no verdict comes, the push is answered 502 and nothing is written. 0–600000, default 60000 (one minute).',\n ),\n maxPushPolicyPackBytes: z\n .int()\n .min(1024 * 1024)\n .max(256 * 1024 * 1024)\n .default(32 * 1024 * 1024)\n .describe(\n 'Most bytes of a pushed pack held in memory so the push policy can be given changed paths (only when PushPolicy.needs() asks for them); a larger push is refused as uncheckable before it completes. 1 MiB–256 MiB, default 32 MiB (33554432).',\n ),\n maxPushPolicyObjectBytes: z\n .int()\n .min(1024 * 1024)\n .max(512 * 1024 * 1024)\n .default(64 * 1024 * 1024)\n .describe(\n \"Most bytes of objects decompressed and rebuilt from the pushed pack (every entry's data plus every delta's result, thin-pack bases read from storage included) to compute changed paths; past it the push is refused as uncheckable. 1 MiB–512 MiB, default 64 MiB (67108864).\",\n ),\n maxPushPolicyReads: z\n .int()\n .min(1)\n .max(100_000)\n .default(2000)\n .describe(\n 'Most storage backend calls made to compute changed paths for the push policy — parent commits, trees and blobs not in the pushed pack (thin-pack delta bases, unchanged subtrees of a moved directory, sizes of blobs storage already has); past it the push is refused as uncheckable. 1–100000, default 2000.',\n ),\n maxChangedPaths: z\n .int()\n .min(1)\n .max(100_000)\n .default(10_000)\n .describe(\n 'Most changed paths, summed over every commit of a push, given to the push policy; a push changing more is refused as uncheckable. 1–100000, default 10000.',\n ),\n decisionCacheEntries: z\n .int()\n .min(0)\n .max(1_000_000)\n .default(10_000)\n .describe(\n 'Most authentication and authorization decisions held in the per-isolate cache, oldest evicted first; 0 disables the cache. Default 10000. How long entries live is GatewayConfig.authCacheSeconds.',\n ),\n maxAuditReportBytes: z\n .int()\n .min(0)\n .max(16 * 1024 * 1024)\n .default(1024 * 1024)\n .describe(\n 'Most bytes of a storage host push response kept to read its per-ref report for the audit event and the push event; past it the refs are audited as \"unknown\" and no push event is sent. 0 skips reading reports for audit; when an onPush hook is set the report is still read, up to the 1 MiB default. Default 1 MiB (1048576).',\n ),\n allowedPushOptions: z\n .array(\n z\n .string()\n .min(1)\n .max(100)\n .regex(/^[^\\s\\0=]+$/)\n .describe(\n 'A push option name, the part of a \"git push -o <name>[=<value>]\" option before the first \"=\"; 1–100 characters without whitespace, NUL or \"=\". Matched exactly and case-sensitively.',\n ),\n )\n .max(100)\n .default([])\n .describe(\n \"Push option names the proxy forwards to the storage host; a push carrying any other option is refused before it reaches storage. The host runs push options as the gateway's own credential (GitLab's merge_request.* and ci.variable, for example), so each one bypasses branch policy unless refused here. At most 100; default none, so every push option is refused.\",\n ),\n deniedStatus: z\n .union([\n z\n .literal('err')\n .describe(\n 'Answer in-protocol: HTTP 200 with an \"ERR\" packet, which git prints as \"remote error: <reason>\".',\n ),\n z\n .literal(403)\n .describe(\n 'Answer HTTP 403 with the reason as a plain-text body, which git prints as \"The requested URL returned error: 403\".',\n ),\n ])\n .default('err')\n .describe(\n 'How an authorization refusal (the Authorizer denying read or write of a repository) is answered: \"err\" (default) or 403. Branch-policy refusals of individual refs are always in-protocol (\"ng\" or \"ERR\"), so a push to a protected branch keeps its readable reason either way.',\n ),\n })\n .strict()\n .meta({\n id: 'SmartHttpConfig',\n title: 'Smart-HTTP proxy configuration',\n description:\n 'Limits and names used by the smart-HTTP proxy. Every field has a default, so {} is a complete configuration.',\n examples: [\n {\n realm: 'git-gateway',\n maxPushHeadBytes: 8_388_608,\n maxAncestryReads: 2000,\n maxScannedCommitBytes: 33_554_432,\n maxVerdictWaitMs: 60_000,\n maxPushPolicyPackBytes: 33_554_432,\n maxPushPolicyObjectBytes: 67_108_864,\n maxPushPolicyReads: 2000,\n maxChangedPaths: 10_000,\n decisionCacheEntries: 10_000,\n maxAuditReportBytes: 1_048_576,\n allowedPushOptions: ['ci.skip'],\n deniedStatus: 'err',\n },\n ],\n });\n\n/** A smart-HTTP configuration as written (defaults optional). */\nexport type SmartHttpConfigInput = z.input<typeof SmartHttpConfig>;\n/** A complete smart-HTTP configuration, inferred from {@link SmartHttpConfig}. */\nexport type SmartHttpConfig = z.output<typeof SmartHttpConfig>;\n"],"mappings":";;;AAIA,MAAa,kBAAkB,EAC5B,OAAO;CACN,OAAO,EACJ,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,eAAe,CAAC,CACtB,QAAQ,aAAa,CAAC,CACtB,SACC,mMACF;CACF,kBAAkB,EACf,IAAI,CAAC,CACL,IAAI,IAAI,CAAC,CACT,IAAI,QAAgB,CAAC,CACrB,QAAQ,OAAe,CAAC,CACxB,SACC,2JACF;CACF,kBAAkB,EACf,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,IAAI,GAAO,CAAC,CACZ,QAAQ,GAAI,CAAC,CACb,SACC,+KACF;CACF,uBAAuB,EACpB,IAAI,CAAC,CACL,IAAI,OAAW,CAAC,CAChB,IAAI,SAAiB,CAAC,CACtB,QAAQ,QAAgB,CAAC,CACzB,SACC,wKACF;CACF,kBAAkB,EACf,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,IAAI,GAAO,CAAC,CACZ,QAAQ,GAAM,CAAC,CACf,SACC,0YACF;CACF,wBAAwB,EACrB,IAAI,CAAC,CACL,IAAI,OAAW,CAAC,CAChB,IAAI,SAAiB,CAAC,CACtB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ACjB,sBAAsB;EACtB,qBAAqB;EACrB,oBAAoB,CAAC,SAAS;EAC9B,cAAc;CAChB,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommitAction } from "../schemas/commit-action.js";
|
|
2
|
+
import { t as FileMap } from "../file-map-CxUveLWz.js";
|
|
3
|
+
/**
|
|
4
|
+
* Applies commit actions in order, each to the result of the one before, with the GitLab
|
|
5
|
+
* Commits API rules (plus upsert). Returns the new snapshot; throws a GatewayError on the first
|
|
6
|
+
* action that breaks a rule, leaving `files` untouched.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyActions(files: FileMap, actions: readonly CommitAction[]): Promise<FileMap>;
|
|
9
|
+
//# sourceMappingURL=apply-actions.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { gatewayError } from "../gateway-error.js";
|
|
2
|
+
import { decodeContent } from "./bytes.js";
|
|
3
|
+
import { fileParent, isDirectory } from "./file-map.js";
|
|
4
|
+
import { blobSha } from "./hash.js";
|
|
5
|
+
// src/reference/apply-actions.ts
|
|
6
|
+
async function storedFile(content, encoding, executable) {
|
|
7
|
+
const bytes = decodeContent(content, encoding);
|
|
8
|
+
return {
|
|
9
|
+
bytes,
|
|
10
|
+
executable,
|
|
11
|
+
sha: await blobSha(bytes)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** Throws path_exists or path_conflict unless `path` is free to receive a new file. */
|
|
15
|
+
function requireFree(files, path) {
|
|
16
|
+
if (files.has(path) || isDirectory(files, path)) throw gatewayError("path_exists", `Path already exists: ${path}`, { path });
|
|
17
|
+
requireNoFileParent(files, path);
|
|
18
|
+
}
|
|
19
|
+
/** Throws path_conflict when a parent of `path` is a file. */
|
|
20
|
+
function requireNoFileParent(files, path) {
|
|
21
|
+
const conflictingPath = fileParent(files, path);
|
|
22
|
+
if (conflictingPath !== void 0) throw gatewayError("path_conflict", `A parent of ${path} is a file: ${conflictingPath}`, {
|
|
23
|
+
path,
|
|
24
|
+
conflictingPath
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** The existing file at `path`, or path_not_found. */
|
|
28
|
+
function requireFile(files, path) {
|
|
29
|
+
const file = files.get(path);
|
|
30
|
+
if (file === void 0) throw gatewayError("path_not_found", `File not found: ${path}`, { path });
|
|
31
|
+
return file;
|
|
32
|
+
}
|
|
33
|
+
async function applyOne(files, action) {
|
|
34
|
+
switch (action.action) {
|
|
35
|
+
case "create":
|
|
36
|
+
requireFree(files, action.path);
|
|
37
|
+
files.set(action.path, await storedFile(action.content, action.encoding, false));
|
|
38
|
+
return;
|
|
39
|
+
case "update": {
|
|
40
|
+
const existing = requireFile(files, action.path);
|
|
41
|
+
files.set(action.path, await storedFile(action.content, action.encoding, existing.executable));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
case "upsert": {
|
|
45
|
+
const existing = files.get(action.path);
|
|
46
|
+
if (existing === void 0) requireFree(files, action.path);
|
|
47
|
+
files.set(action.path, await storedFile(action.content, action.encoding, existing?.executable ?? false));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
case "delete":
|
|
51
|
+
requireFile(files, action.path);
|
|
52
|
+
files.delete(action.path);
|
|
53
|
+
return;
|
|
54
|
+
case "move": {
|
|
55
|
+
const existing = requireFile(files, action.previousPath);
|
|
56
|
+
files.delete(action.previousPath);
|
|
57
|
+
requireFree(files, action.path);
|
|
58
|
+
const moved = action.content === void 0 ? existing : await storedFile(action.content, action.encoding, existing.executable);
|
|
59
|
+
files.set(action.path, moved);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
case "chmod": {
|
|
63
|
+
const existing = requireFile(files, action.path);
|
|
64
|
+
files.set(action.path, {
|
|
65
|
+
...existing,
|
|
66
|
+
executable: action.executeFilemode
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Applies commit actions in order, each to the result of the one before, with the GitLab
|
|
74
|
+
* Commits API rules (plus upsert). Returns the new snapshot; throws a GatewayError on the first
|
|
75
|
+
* action that breaks a rule, leaving `files` untouched.
|
|
76
|
+
*/
|
|
77
|
+
async function applyActions(files, actions) {
|
|
78
|
+
const next = new Map(files);
|
|
79
|
+
for (const action of actions) await applyOne(next, action);
|
|
80
|
+
return next;
|
|
81
|
+
}
|
|
82
|
+
export { applyActions };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=apply-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-actions.js","names":[],"sources":["../../src/reference/apply-actions.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { gatewayError } from '../gateway-error.ts';\nimport type { CommitAction } from '../schemas/commit-action.ts';\nimport { decodeContent } from './bytes.ts';\nimport { fileParent, isDirectory, type FileMap, type StoredFile } from './file-map.ts';\nimport { blobSha } from './hash.ts';\n\nasync function storedFile(\n content: string,\n encoding: 'text' | 'base64',\n executable: boolean,\n): Promise<StoredFile> {\n const bytes = decodeContent(content, encoding);\n return { bytes, executable, sha: await blobSha(bytes) };\n}\n\n/** Throws path_exists or path_conflict unless `path` is free to receive a new file. */\nfunction requireFree(files: FileMap, path: string): void {\n if (files.has(path) || isDirectory(files, path)) {\n throw gatewayError('path_exists', `Path already exists: ${path}`, { path });\n }\n requireNoFileParent(files, path);\n}\n\n/** Throws path_conflict when a parent of `path` is a file. */\nfunction requireNoFileParent(files: FileMap, path: string): void {\n const conflictingPath = fileParent(files, path);\n if (conflictingPath !== undefined) {\n throw gatewayError('path_conflict', `A parent of ${path} is a file: ${conflictingPath}`, {\n path,\n conflictingPath,\n });\n }\n}\n\n/** The existing file at `path`, or path_not_found. */\nfunction requireFile(files: FileMap, path: string): StoredFile {\n const file = files.get(path);\n if (file === undefined) throw gatewayError('path_not_found', `File not found: ${path}`, { path });\n return file;\n}\n\nasync function applyOne(files: Map<string, StoredFile>, action: CommitAction): Promise<void> {\n switch (action.action) {\n case 'create':\n requireFree(files, action.path);\n files.set(action.path, await storedFile(action.content, action.encoding, false));\n return;\n case 'update': {\n const existing = requireFile(files, action.path);\n files.set(action.path, await storedFile(action.content, action.encoding, existing.executable));\n return;\n }\n case 'upsert': {\n const existing = files.get(action.path);\n if (existing === undefined) requireFree(files, action.path);\n files.set(\n action.path,\n await storedFile(action.content, action.encoding, existing?.executable ?? false),\n );\n return;\n }\n case 'delete':\n requireFile(files, action.path);\n files.delete(action.path);\n return;\n case 'move': {\n const existing = requireFile(files, action.previousPath);\n // The source leaves first, so a file may move beneath its own old path (a → a/b).\n files.delete(action.previousPath);\n requireFree(files, action.path);\n const moved =\n action.content === undefined\n ? existing\n : await storedFile(action.content, action.encoding, existing.executable);\n files.set(action.path, moved);\n return;\n }\n case 'chmod': {\n const existing = requireFile(files, action.path);\n files.set(action.path, { ...existing, executable: action.executeFilemode });\n return;\n }\n }\n}\n\n/**\n * Applies commit actions in order, each to the result of the one before, with the GitLab\n * Commits API rules (plus upsert). Returns the new snapshot; throws a GatewayError on the first\n * action that breaks a rule, leaving `files` untouched.\n */\nexport async function applyActions(files: FileMap, actions: readonly CommitAction[]): Promise<FileMap> {\n const next = new Map(files);\n for (const action of actions) await applyOne(next, action);\n return next;\n}\n"],"mappings":";;;;;AAOA,eAAe,WACb,SACA,UACA,YACqB;CACrB,MAAM,QAAQ,cAAc,SAAS,QAAQ;CAC7C,OAAO;EAAE;EAAO;EAAY,KAAK,MAAM,QAAQ,KAAK;CAAE;AACxD;;AAGA,SAAS,YAAY,OAAgB,MAAoB;CACvD,IAAI,MAAM,IAAI,IAAI,KAAK,YAAY,OAAO,IAAI,GAC5C,MAAM,aAAa,eAAe,wBAAwB,QAAQ,EAAE,KAAK,CAAC;CAE5E,oBAAoB,OAAO,IAAI;AACjC;;AAGA,SAAS,oBAAoB,OAAgB,MAAoB;CAC/D,MAAM,kBAAkB,WAAW,OAAO,IAAI;CAC9C,IAAI,oBAAoB,KAAA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,MAAM;IAAE,GAAG;IAAU,YAAY,OAAO;GAAgB,CAAC;GAC1E;EACF;CACF;AACF;;;;;;AAOA,eAAsB,aAAa,OAAgB,SAAoD;CACrG,MAAM,OAAO,IAAI,IAAI,KAAK;CAC1B,KAAK,MAAM,UAAU,SAAS,MAAM,SAAS,MAAM,MAAM;CACzD,OAAO;AACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { a as RpcOutput, r as RpcInput } from "../git-gateway-VA9Tc5tn.js";
|
|
2
|
+
import { ReferenceContext } from "./repo-state.js";
|
|
3
|
+
/** The reference `syncBranch`: up to date, fast-forward, file-level merge, or conflict with paths. */
|
|
4
|
+
export declare function referenceSyncBranch(context: ReferenceContext, input: RpcInput<'syncBranch'>): Promise<RpcOutput<'syncBranch'>>;
|
|
5
|
+
/** The reference `promote`: fast-forward only, from the source head only. */
|
|
6
|
+
export declare function referencePromote(context: ReferenceContext, input: RpcInput<'promote'>): Promise<RpcOutput<'promote'>>;
|
|
7
|
+
//# sourceMappingURL=branch-methods.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { RPC_SCHEMAS } from "../git-gateway.js";
|
|
2
|
+
import { gatewayError } from "../gateway-error.js";
|
|
3
|
+
import "../schemas/sha.js";
|
|
4
|
+
import { contains, mergeBase } from "./history.js";
|
|
5
|
+
import { lookupIn, requireBranchHead, requireRepo, withRepoLock } from "./repo-state.js";
|
|
6
|
+
import { runMethod } from "./run-method.js";
|
|
7
|
+
import { threeWayMerge } from "./three-way-merge.js";
|
|
8
|
+
import { writeCommit } from "./write-commit.js";
|
|
9
|
+
// src/reference/branch-methods.ts
|
|
10
|
+
const branchRef = (branch) => `refs/heads/${branch}`;
|
|
11
|
+
async function syncLocked(context, repo, input) {
|
|
12
|
+
const fromHead = requireBranchHead(repo, input.from);
|
|
13
|
+
const intoHead = requireBranchHead(repo, input.into);
|
|
14
|
+
const lookup = lookupIn(repo);
|
|
15
|
+
if (contains(lookup, intoHead, fromHead)) return {
|
|
16
|
+
status: "up_to_date",
|
|
17
|
+
head: intoHead
|
|
18
|
+
};
|
|
19
|
+
const refUpdate = (newSha) => ({
|
|
20
|
+
ref: branchRef(input.into),
|
|
21
|
+
oldSha: intoHead,
|
|
22
|
+
newSha
|
|
23
|
+
});
|
|
24
|
+
if (contains(lookup, fromHead, intoHead)) {
|
|
25
|
+
repo.branches.set(input.into, fromHead);
|
|
26
|
+
return {
|
|
27
|
+
status: "fast_forward",
|
|
28
|
+
refUpdate: refUpdate(fromHead)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const base = mergeBase(lookup, intoHead, fromHead);
|
|
32
|
+
if (base === null) throw gatewayError("unrelated_histories", `${input.from} and ${input.into} share no history`, {
|
|
33
|
+
from: input.from,
|
|
34
|
+
into: input.into
|
|
35
|
+
});
|
|
36
|
+
const files = (sha) => repo.commits.get(sha)?.files ?? /* @__PURE__ */ new Map();
|
|
37
|
+
const merged = threeWayMerge(files(base), files(intoHead), files(fromHead));
|
|
38
|
+
if (merged.kind === "conflict") return {
|
|
39
|
+
status: "conflict",
|
|
40
|
+
paths: [...merged.paths],
|
|
41
|
+
base,
|
|
42
|
+
fromHead,
|
|
43
|
+
intoHead
|
|
44
|
+
};
|
|
45
|
+
const identity = input.author ?? context.config.serviceIdentity;
|
|
46
|
+
const stored = await writeCommit(repo, {
|
|
47
|
+
parents: [intoHead, fromHead],
|
|
48
|
+
files: merged.files,
|
|
49
|
+
author: identity,
|
|
50
|
+
committer: identity,
|
|
51
|
+
message: input.message ?? `Merge branch '${input.from}' into ${input.into}`,
|
|
52
|
+
date: context.now().toISOString()
|
|
53
|
+
});
|
|
54
|
+
repo.branches.set(input.into, stored.commit.sha);
|
|
55
|
+
return {
|
|
56
|
+
status: "merged",
|
|
57
|
+
commit: stored.commit,
|
|
58
|
+
refUpdate: refUpdate(stored.commit.sha)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The reference `syncBranch`: up to date, fast-forward, file-level merge, or conflict with paths. */
|
|
62
|
+
function referenceSyncBranch(context, input) {
|
|
63
|
+
return runMethod(RPC_SCHEMAS.syncBranch, input, async (parsed) => {
|
|
64
|
+
const repo = requireRepo(context, parsed.repo);
|
|
65
|
+
return withRepoLock(repo, () => syncLocked(context, repo, parsed));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function promoteLocked(repo, input) {
|
|
69
|
+
const { from, into, sha } = input;
|
|
70
|
+
const fromHead = requireBranchHead(repo, from);
|
|
71
|
+
if (fromHead !== sha) throw gatewayError("not_head_of_source", `${sha} is not the head of ${from}`, {
|
|
72
|
+
from,
|
|
73
|
+
sha,
|
|
74
|
+
head: fromHead
|
|
75
|
+
});
|
|
76
|
+
const intoHead = repo.branches.get(into);
|
|
77
|
+
if (intoHead === sha) return {
|
|
78
|
+
status: "up_to_date",
|
|
79
|
+
head: sha
|
|
80
|
+
};
|
|
81
|
+
if (intoHead !== void 0 && !contains(lookupIn(repo), sha, intoHead)) throw gatewayError("not_fast_forward", `${sha} does not contain the head of ${into}`, {
|
|
82
|
+
into,
|
|
83
|
+
sha,
|
|
84
|
+
head: intoHead
|
|
85
|
+
});
|
|
86
|
+
repo.branches.set(into, sha);
|
|
87
|
+
return {
|
|
88
|
+
status: "promoted",
|
|
89
|
+
refUpdate: {
|
|
90
|
+
ref: branchRef(into),
|
|
91
|
+
oldSha: intoHead ?? "0000000000000000000000000000000000000000",
|
|
92
|
+
newSha: sha
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** The reference `promote`: fast-forward only, from the source head only. */
|
|
97
|
+
function referencePromote(context, input) {
|
|
98
|
+
return runMethod(RPC_SCHEMAS.promote, input, async (parsed) => {
|
|
99
|
+
const repo = requireRepo(context, parsed.repo);
|
|
100
|
+
return withRepoLock(repo, async () => promoteLocked(repo, parsed));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export { referencePromote, referenceSyncBranch };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=branch-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch-methods.js","names":[],"sources":["../../src/reference/branch-methods.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { RPC_SCHEMAS, type RpcInput, type RpcOutput, type RpcParsedInput } from '../git-gateway.ts';\nimport { gatewayError } from '../gateway-error.ts';\nimport { ZERO_SHA } from '../schemas/sha.ts';\nimport { contains, mergeBase } from './history.ts';\nimport {\n lookupIn,\n requireBranchHead,\n requireRepo,\n withRepoLock,\n type ReferenceContext,\n type RepoState,\n} from './repo-state.ts';\nimport { runMethod } from './run-method.ts';\nimport { threeWayMerge } from './three-way-merge.ts';\nimport { writeCommit } from './write-commit.ts';\n\nconst branchRef = (branch: string): string => `refs/heads/${branch}`;\n\nasync function syncLocked(\n context: ReferenceContext,\n repo: RepoState,\n input: RpcParsedInput<'syncBranch'>,\n): Promise<RpcOutput<'syncBranch'>> {\n const fromHead = requireBranchHead(repo, input.from);\n const intoHead = requireBranchHead(repo, input.into);\n const lookup = lookupIn(repo);\n if (contains(lookup, intoHead, fromHead)) return { status: 'up_to_date', head: intoHead };\n const refUpdate = (newSha: string) => ({ ref: branchRef(input.into), oldSha: intoHead, newSha });\n if (contains(lookup, fromHead, intoHead)) {\n repo.branches.set(input.into, fromHead);\n return { status: 'fast_forward', refUpdate: refUpdate(fromHead) };\n }\n const base = mergeBase(lookup, intoHead, fromHead);\n if (base === null) {\n throw gatewayError('unrelated_histories', `${input.from} and ${input.into} share no history`, {\n from: input.from,\n into: input.into,\n });\n }\n const files = (sha: string) => repo.commits.get(sha)?.files ?? new Map();\n const merged = threeWayMerge(files(base), files(intoHead), files(fromHead));\n if (merged.kind === 'conflict') {\n return { status: 'conflict', paths: [...merged.paths], base, fromHead, intoHead };\n }\n const identity = input.author ?? context.config.serviceIdentity;\n const stored = await writeCommit(repo, {\n parents: [intoHead, fromHead],\n files: merged.files,\n author: identity,\n committer: identity,\n message: input.message ?? `Merge branch '${input.from}' into ${input.into}`,\n date: context.now().toISOString(),\n });\n repo.branches.set(input.into, stored.commit.sha);\n return { status: 'merged', commit: stored.commit, refUpdate: refUpdate(stored.commit.sha) };\n}\n\n/** The reference `syncBranch`: up to date, fast-forward, file-level merge, or conflict with paths. */\nexport function referenceSyncBranch(\n context: ReferenceContext,\n input: RpcInput<'syncBranch'>,\n): Promise<RpcOutput<'syncBranch'>> {\n return runMethod(RPC_SCHEMAS.syncBranch, input, async (parsed) => {\n const repo = requireRepo(context, parsed.repo);\n return withRepoLock(repo, () => syncLocked(context, repo, parsed));\n });\n}\n\nfunction promoteLocked(repo: RepoState, input: RpcParsedInput<'promote'>): RpcOutput<'promote'> {\n const { from, into, sha } = input;\n const fromHead = requireBranchHead(repo, from);\n if (fromHead !== sha) {\n throw gatewayError('not_head_of_source', `${sha} is not the head of ${from}`, {\n from,\n sha,\n head: fromHead,\n });\n }\n const intoHead = repo.branches.get(into);\n if (intoHead === sha) return { status: 'up_to_date', head: sha };\n if (intoHead !== undefined && !contains(lookupIn(repo), sha, intoHead)) {\n throw gatewayError('not_fast_forward', `${sha} does not contain the head of ${into}`, {\n into,\n sha,\n head: intoHead,\n });\n }\n repo.branches.set(into, sha);\n return {\n status: 'promoted',\n refUpdate: { ref: branchRef(into), oldSha: intoHead ?? ZERO_SHA, newSha: sha },\n };\n}\n\n/** The reference `promote`: fast-forward only, from the source head only. */\nexport function referencePromote(\n context: ReferenceContext,\n input: RpcInput<'promote'>,\n): Promise<RpcOutput<'promote'>> {\n return runMethod(RPC_SCHEMAS.promote, input, async (parsed) => {\n const repo = requireRepo(context, parsed.repo);\n return withRepoLock(repo, async () => promoteLocked(repo, parsed));\n });\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAM,aAAa,WAA2B,cAAc;AAE5D,eAAe,WACb,SACA,MACA,OACkC;CAClC,MAAM,WAAW,kBAAkB,MAAM,MAAM,IAAI;CACnD,MAAM,WAAW,kBAAkB,MAA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,SAAgB,oBACd,SACA,OACkC;CAClC,OAAO,UAAU,YAAY,YAAY,OAAO,OAAO,WAAW;EAChE,MAAM,OAAO,YAAY,SAAS,OAAO,IAAI;EAC7C,OAAO,aAAa,YAAY,WAAW,SAAS,MAAM,MAAM,CAAC;CACnE,CAAC;AACH;AAEA,SAAS,cAAc,MAAiB,OAAwD;CAC9F,MAAM,EAAE,MAAM,MAAM,QAAQ;CAC5B,MAAM,WAAW,kBAAkB,MAAM,IAAI;CAC7C,IAAI,aAAa,KACf,MAAM,aAAa,sBAAsB,GAAG,IAAI,sBAAsB,QAAQ;EAC5E;EACA;EACA,MAAM;CACR,CAAC;CAEH,MAAM,WAAW,KAAK,SAAS,IAAI,IAAI;CACvC,IAAI,aAAa,KAAK,OAAO;EAAE,QAAQ;EAAc,MAAM;CAAI;CAC/D,IAAI,aAAa,KAAA,KAAa,CAAC,SAAS,SAAS,IAAI,GAAG,KAAK,QAAQ,GACnE,MAAM,aAAa,oBAAoB,GAAG,IAAI,gCAAgC,QAAQ;EACpF;EACA;EACA,MAAM;CACR,CAAC;CAEH,KAAK,SAAS,IAAI,MAAM,GAAG;CAC3B,OAAO;EACL,QAAQ;EACR,WAAW;GAAE,KAAK,UAAU,IAAI;GAAG,QAAQ,YAAA;GAAsB,QAAQ;EAAI;CAC/E;AACF;;AAGA,SAAgB,iBACd,SACA,OAC+B;CAC/B,OAAO,UAAU,YAAY,SAAS,OAAO,OAAO,WAAW;EAC7D,MAAM,OAAO,YAAY,SAAS,OAAO,IAAI;EAC7C,OAAO,aAAa,MAAM,YAAY,cAAc,MAAM,MAAM,CAAC;CACnE,CAAC;AACH"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContentEncoding } from "../schemas/content-encoding.js";
|
|
2
|
+
/** UTF-8 bytes of a string. */
|
|
3
|
+
export declare function utf8(text: string): Uint8Array;
|
|
4
|
+
/** Standard padded base64 of some bytes. */
|
|
5
|
+
export declare function toBase64(bytes: Uint8Array): string;
|
|
6
|
+
/** The bytes a standard padded base64 string encodes; the caller has validated the string. */
|
|
7
|
+
export declare function fromBase64(text: string): Uint8Array;
|
|
8
|
+
/** The bytes of content carried in the given encoding. */
|
|
9
|
+
export declare function decodeContent(content: string, encoding: ContentEncoding): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Content for a read: text when asked for and the bytes are valid UTF-8 that round-trips
|
|
12
|
+
* exactly, base64 otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function encodeContent(bytes: Uint8Array, preferred: ContentEncoding): {
|
|
15
|
+
encoding: ContentEncoding;
|
|
16
|
+
content: string;
|
|
17
|
+
};
|
|
18
|
+
/** True when two byte arrays hold the same bytes. */
|
|
19
|
+
export declare function sameBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
20
|
+
/** Compares two strings by their UTF-8 bytes, the order git sorts paths in. */
|
|
21
|
+
export declare function byteOrder(a: string, b: string): number;
|
|
22
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/reference/bytes.ts
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const strictDecoder = new TextDecoder("utf-8", {
|
|
4
|
+
fatal: true,
|
|
5
|
+
ignoreBOM: true
|
|
6
|
+
});
|
|
7
|
+
/** UTF-8 bytes of a string. */
|
|
8
|
+
function utf8(text) {
|
|
9
|
+
return encoder.encode(text);
|
|
10
|
+
}
|
|
11
|
+
/** Standard padded base64 of some bytes. */
|
|
12
|
+
function toBase64(bytes) {
|
|
13
|
+
let binary = "";
|
|
14
|
+
for (const byte of bytes) binary += String.fromCodePoint(byte);
|
|
15
|
+
return btoa(binary);
|
|
16
|
+
}
|
|
17
|
+
/** The bytes a standard padded base64 string encodes; the caller has validated the string. */
|
|
18
|
+
function fromBase64(text) {
|
|
19
|
+
const binary = atob(text);
|
|
20
|
+
const bytes = new Uint8Array(binary.length);
|
|
21
|
+
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.codePointAt(index) ?? 0;
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
/** The bytes of content carried in the given encoding. */
|
|
25
|
+
function decodeContent(content, encoding) {
|
|
26
|
+
return encoding === "base64" ? fromBase64(content) : utf8(content);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Content for a read: text when asked for and the bytes are valid UTF-8 that round-trips
|
|
30
|
+
* exactly, base64 otherwise.
|
|
31
|
+
*/
|
|
32
|
+
function encodeContent(bytes, preferred) {
|
|
33
|
+
if (preferred === "text") try {
|
|
34
|
+
return {
|
|
35
|
+
encoding: "text",
|
|
36
|
+
content: strictDecoder.decode(bytes)
|
|
37
|
+
};
|
|
38
|
+
} catch {}
|
|
39
|
+
return {
|
|
40
|
+
encoding: "base64",
|
|
41
|
+
content: toBase64(bytes)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** True when two byte arrays hold the same bytes. */
|
|
45
|
+
function sameBytes(a, b) {
|
|
46
|
+
if (a.length !== b.length) return false;
|
|
47
|
+
return a.every((byte, index) => byte === b[index]);
|
|
48
|
+
}
|
|
49
|
+
/** Compares two strings by their UTF-8 bytes, the order git sorts paths in. */
|
|
50
|
+
function byteOrder(a, b) {
|
|
51
|
+
const left = utf8(a);
|
|
52
|
+
const right = utf8(b);
|
|
53
|
+
const length = Math.min(left.length, right.length);
|
|
54
|
+
for (let index = 0; index < length; index += 1) {
|
|
55
|
+
const diff = (left[index] ?? 0) - (right[index] ?? 0);
|
|
56
|
+
if (diff !== 0) return diff;
|
|
57
|
+
}
|
|
58
|
+
return left.length - right.length;
|
|
59
|
+
}
|
|
60
|
+
export { byteOrder, decodeContent, encodeContent, fromBase64, sameBytes, toBase64, utf8 };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","names":[],"sources":["../../src/reference/bytes.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { ContentEncoding } from '../schemas/content-encoding.ts';\n\nconst encoder = new TextEncoder();\nconst strictDecoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });\n\n/** UTF-8 bytes of a string. */\nexport function utf8(text: string): Uint8Array {\n return encoder.encode(text);\n}\n\n/** Standard padded base64 of some bytes. */\nexport function toBase64(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCodePoint(byte);\n return btoa(binary);\n}\n\n/** The bytes a standard padded base64 string encodes; the caller has validated the string. */\nexport function fromBase64(text: string): Uint8Array {\n const binary = atob(text);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.codePointAt(index) ?? 0;\n return bytes;\n}\n\n/** The bytes of content carried in the given encoding. */\nexport function decodeContent(content: string, encoding: ContentEncoding): Uint8Array {\n return encoding === 'base64' ? fromBase64(content) : utf8(content);\n}\n\n/**\n * Content for a read: text when asked for and the bytes are valid UTF-8 that round-trips\n * exactly, base64 otherwise.\n */\nexport function encodeContent(\n bytes: Uint8Array,\n preferred: ContentEncoding,\n): { encoding: ContentEncoding; content: string } {\n if (preferred === 'text') {\n try {\n return { encoding: 'text', content: strictDecoder.decode(bytes) };\n } catch {\n // Not valid UTF-8: fall through to base64.\n }\n }\n return { encoding: 'base64', content: toBase64(bytes) };\n}\n\n/** True when two byte arrays hold the same bytes. */\nexport function sameBytes(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n return a.every((byte, index) => byte === b[index]);\n}\n\n/** Compares two strings by their UTF-8 bytes, the order git sorts paths in. */\nexport function byteOrder(a: string, b: string): number {\n const left = utf8(a);\n const right = utf8(b);\n const length = Math.min(left.length, right.length);\n for (let index = 0; index < length; index += 1) {\n const diff = (left[index] ?? 0) - (right[index] ?? 0);\n if (diff !== 0) return diff;\n }\n return left.length - right.length;\n}\n"],"mappings":";AAGA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,gBAAgB,IAAI,YA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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/reference/clock.ts
|
|
2
|
+
/**
|
|
3
|
+
* A deterministic clock for tests: the first call returns `start`, each later call `stepMs`
|
|
4
|
+
* milliseconds after the one before. With it, the reference implementation's ids are the same on
|
|
5
|
+
* every run.
|
|
6
|
+
*/
|
|
7
|
+
function steppingClock(start = "2026-01-01T00:00:00.000Z", stepMs = 1e3) {
|
|
8
|
+
let next = Date.parse(start);
|
|
9
|
+
if (Number.isNaN(next)) throw new RangeError(`steppingClock: invalid start time ${start}`);
|
|
10
|
+
return () => {
|
|
11
|
+
const now = new Date(next);
|
|
12
|
+
next += stepMs;
|
|
13
|
+
return now;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { steppingClock };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","names":[],"sources":["../../src/reference/clock.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** A source of the current time. */\nexport type Clock = () => Date;\n\n/**\n * A deterministic clock for tests: the first call returns `start`, each later call `stepMs`\n * milliseconds after the one before. With it, the reference implementation's ids are the same on\n * every run.\n */\nexport function steppingClock(start = '2026-01-01T00:00:00.000Z', stepMs = 1000): Clock {\n let next = Date.parse(start);\n if (Number.isNaN(next)) throw new RangeError(`steppingClock: invalid start time ${start}`);\n return () => {\n const now = new Date(next);\n next += stepMs;\n return now;\n };\n}\n"],"mappings":";;;;;;AAUA,SAAgB,cAAc,QAAQ,4BAA4B,SAAS,KAAa;CACtF,IAAI,OAAO,KAAK,MAAM,KAAK;CAC3B,IAAI,OAAO,MAAM,IAAI,GAAG,MAAM,IAAI,WAAW,qCAAqC,OAAO;CACzF,aAAa;EACX,MAAM,MAAM,IAAI,KAAK,IAAI;EACzB,QAAQ;EACR,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { a as RpcOutput, r as RpcInput } from "../git-gateway-VA9Tc5tn.js";
|
|
2
|
+
import { ReferenceContext } from "./repo-state.js";
|
|
3
|
+
/** The reference `commit`: GitLab Commits API rules, idempotency replay, stale-head refusal, no-op detection. */
|
|
4
|
+
export declare function referenceCommit(context: ReferenceContext, input: RpcInput<'commit'>): Promise<RpcOutput<'commit'>>;
|
|
5
|
+
//# sourceMappingURL=commit-method.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RPC_SCHEMAS } from "../git-gateway.js";
|
|
2
|
+
import { gatewayError } from "../gateway-error.js";
|
|
3
|
+
import "../schemas/sha.js";
|
|
4
|
+
import { applyActions } from "./apply-actions.js";
|
|
5
|
+
import { buildTreeIndex } from "./tree-index.js";
|
|
6
|
+
import { walkHistory } from "./history.js";
|
|
7
|
+
import { lookupIn, requireRepo, withRepoLock } from "./repo-state.js";
|
|
8
|
+
import { runMethod } from "./run-method.js";
|
|
9
|
+
import { appendIdempotencyTrailer } from "./trailer.js";
|
|
10
|
+
import { writeCommit } from "./write-commit.js";
|
|
11
|
+
// src/reference/commit-method.ts
|
|
12
|
+
/** The commit carrying `key` within the configured lookback window of the branch, if any. */
|
|
13
|
+
function findReplay(context, repo, head, key) {
|
|
14
|
+
const { maxCommits, maxAgeSeconds } = context.config.idempotency;
|
|
15
|
+
const oldest = (/* @__PURE__ */ new Date(context.now().getTime() - maxAgeSeconds * 1e3)).toISOString();
|
|
16
|
+
const window = walkHistory(lookupIn(repo), head).slice(0, maxCommits);
|
|
17
|
+
for (const commit of window) {
|
|
18
|
+
if (commit.committer.date < oldest) return void 0;
|
|
19
|
+
if (commit.idempotencyKey === key) return commit;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The commit the new one builds on: the branch head, the start branch head, or none for a root commit. */
|
|
23
|
+
function baseOf(repo, input, head) {
|
|
24
|
+
if (head !== null) return head;
|
|
25
|
+
if (input.startBranch !== void 0) {
|
|
26
|
+
const start = repo.branches.get(input.startBranch);
|
|
27
|
+
if (start === void 0) throw gatewayError("ref_not_found", `Branch not found: ${input.startBranch}`, { ref: input.startBranch });
|
|
28
|
+
return start;
|
|
29
|
+
}
|
|
30
|
+
if (repo.branches.size === 0) return null;
|
|
31
|
+
throw gatewayError("ref_not_found", `Branch not found: ${input.branch}`, { ref: input.branch });
|
|
32
|
+
}
|
|
33
|
+
async function commitLocked(context, repo, input) {
|
|
34
|
+
const head = repo.branches.get(input.branch) ?? null;
|
|
35
|
+
if (head !== null) {
|
|
36
|
+
const replay = findReplay(context, repo, head, input.idempotencyKey);
|
|
37
|
+
if (replay !== void 0) return {
|
|
38
|
+
status: "replayed",
|
|
39
|
+
commit: replay
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (input.expectedHead !== void 0 && input.expectedHead !== head) throw gatewayError("stale_head", `Branch ${input.branch} moved`, {
|
|
43
|
+
branch: input.branch,
|
|
44
|
+
expectedHead: input.expectedHead,
|
|
45
|
+
actualHead: head
|
|
46
|
+
});
|
|
47
|
+
const base = baseOf(repo, input, head);
|
|
48
|
+
const baseCommit = base === null ? void 0 : repo.commits.get(base);
|
|
49
|
+
const files = await applyActions(baseCommit?.files ?? /* @__PURE__ */ new Map(), input.actions);
|
|
50
|
+
const baseTree = baseCommit?.tree.rootSha ?? (await buildTreeIndex(/* @__PURE__ */ new Map())).rootSha;
|
|
51
|
+
if ((await buildTreeIndex(files)).rootSha === baseTree) return {
|
|
52
|
+
status: "noop",
|
|
53
|
+
head
|
|
54
|
+
};
|
|
55
|
+
const stored = await writeCommit(repo, {
|
|
56
|
+
parents: base === null ? [] : [base],
|
|
57
|
+
files,
|
|
58
|
+
author: input.author,
|
|
59
|
+
committer: input.committer ?? input.author,
|
|
60
|
+
message: appendIdempotencyTrailer(input.message, input.idempotencyKey),
|
|
61
|
+
date: context.now().toISOString()
|
|
62
|
+
});
|
|
63
|
+
repo.branches.set(input.branch, stored.commit.sha);
|
|
64
|
+
return {
|
|
65
|
+
status: "committed",
|
|
66
|
+
commit: stored.commit,
|
|
67
|
+
refUpdate: {
|
|
68
|
+
ref: `refs/heads/${input.branch}`,
|
|
69
|
+
oldSha: head ?? "0000000000000000000000000000000000000000",
|
|
70
|
+
newSha: stored.commit.sha
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The reference `commit`: GitLab Commits API rules, idempotency replay, stale-head refusal, no-op detection. */
|
|
75
|
+
function referenceCommit(context, input) {
|
|
76
|
+
return runMethod(RPC_SCHEMAS.commit, input, async (parsed) => {
|
|
77
|
+
const repo = requireRepo(context, parsed.repo);
|
|
78
|
+
return withRepoLock(repo, () => commitLocked(context, repo, parsed));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export { referenceCommit };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=commit-method.js.map
|