@leed-ai/git-gateway-worker 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 +49 -2
- package/dist/audit/audit-recorder.d.ts +2 -0
- package/dist/audit/audit-recorder.js +53 -0
- package/dist/audit/audit-recorder.js.map +1 -0
- package/dist/audit/push-report.d.ts +13 -0
- package/dist/audit/push-report.js +66 -0
- package/dist/audit/push-report.js.map +1 -0
- package/dist/audit-recorder-K1Ns3tfC.d.ts +31 -0
- package/dist/auth/authenticate.d.ts +14 -0
- package/dist/auth/authenticate.js +59 -0
- package/dist/auth/authenticate.js.map +1 -0
- package/dist/auth/authorize.d.ts +12 -0
- package/dist/auth/authorize.js +57 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/auth/read-token-auth.d.ts +60 -0
- package/dist/auth/read-token-auth.js +83 -0
- package/dist/auth/read-token-auth.js.map +1 -0
- package/dist/cache/decision-cache.d.ts +2 -0
- package/dist/cache/decision-cache.js +45 -0
- package/dist/cache/decision-cache.js.map +1 -0
- package/dist/commit-workflow-schemas-BWlg7bZR.d.ts +95 -0
- package/dist/decision-cache-87U32iSj.d.ts +24 -0
- package/dist/gateway-app.d.ts +69 -0
- package/dist/gateway-app.js +80 -0
- package/dist/gateway-app.js.map +1 -0
- package/dist/gateway-context-Boh9I0mk.d.ts +54 -0
- package/dist/gateway-env-DnsBU4Pq.d.ts +40 -0
- package/dist/gateway-worker.d.ts +13 -0
- package/dist/gateway-worker.js +22 -0
- package/dist/gateway-worker.js.map +1 -0
- package/dist/git-route-Spxi09Rm.d.ts +22 -0
- package/dist/health.d.ts +6 -0
- package/dist/health.js +16 -0
- package/dist/health.js.map +1 -0
- package/dist/logger-BZ1zyKLb.d.ts +27 -0
- package/dist/logging/logger.d.ts +2 -0
- package/dist/logging/logger.js +15 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/on-push-DTREOB__.d.ts +62 -0
- package/dist/policy/branch-policy.d.ts +24 -0
- package/dist/policy/branch-policy.js +125 -0
- package/dist/policy/branch-policy.js.map +1 -0
- package/dist/policy/enforce-branch-policy.d.ts +30 -0
- package/dist/policy/enforce-branch-policy.js +214 -0
- package/dist/policy/enforce-branch-policy.js.map +1 -0
- package/dist/policy/fast-forward.d.ts +32 -0
- package/dist/policy/fast-forward.js +95 -0
- package/dist/policy/fast-forward.js.map +1 -0
- package/dist/policy/ref-pattern.d.ts +7 -0
- package/dist/policy/ref-pattern.js +25 -0
- package/dist/policy/ref-pattern.js.map +1 -0
- package/dist/policy/rule-branch-policy.d.ts +17 -0
- package/dist/policy/rule-branch-policy.js +69 -0
- package/dist/policy/rule-branch-policy.js.map +1 -0
- package/dist/proxy/defer.d.ts +8 -0
- package/dist/proxy/defer.js +15 -0
- package/dist/proxy/defer.js.map +1 -0
- package/dist/proxy/forward-read.d.ts +11 -0
- package/dist/proxy/forward-read.js +53 -0
- package/dist/proxy/forward-read.js.map +1 -0
- package/dist/proxy/gateway-deps.d.ts +39 -0
- package/dist/proxy/gateway-deps.js +0 -0
- package/dist/proxy/gateway-env.d.ts +2 -0
- package/dist/proxy/gateway-env.js +0 -0
- package/dist/proxy/git-responses.d.ts +25 -0
- package/dist/proxy/git-responses.js +83 -0
- package/dist/proxy/git-responses.js.map +1 -0
- package/dist/proxy/git-route.d.ts +2 -0
- package/dist/proxy/git-route.js +34 -0
- package/dist/proxy/git-route.js.map +1 -0
- package/dist/proxy/push-events.d.ts +28 -0
- package/dist/proxy/push-events.js +65 -0
- package/dist/proxy/push-events.js.map +1 -0
- package/dist/proxy/push-guard.d.ts +43 -0
- package/dist/proxy/push-guard.js +81 -0
- package/dist/proxy/push-guard.js.map +1 -0
- package/dist/proxy/push-options.d.ts +16 -0
- package/dist/proxy/push-options.js +33 -0
- package/dist/proxy/push-options.js.map +1 -0
- package/dist/proxy/receive-pack.d.ts +17 -0
- package/dist/proxy/receive-pack.js +244 -0
- package/dist/proxy/receive-pack.js.map +1 -0
- package/dist/proxy/request-log.d.ts +13 -0
- package/dist/proxy/request-log.js +41 -0
- package/dist/proxy/request-log.js.map +1 -0
- package/dist/proxy/resolve-route.d.ts +9 -0
- package/dist/proxy/resolve-route.js +22 -0
- package/dist/proxy/resolve-route.js.map +1 -0
- package/dist/proxy/upstream-call.d.ts +23 -0
- package/dist/proxy/upstream-call.js +63 -0
- package/dist/proxy/upstream-call.js.map +1 -0
- package/dist/proxy/upstream.d.ts +2 -0
- package/dist/proxy/upstream.js +68 -0
- package/dist/proxy/upstream.js.map +1 -0
- package/dist/push-event-f-5TsFUY.d.ts +15 -0
- package/dist/push-policy/changed-paths.d.ts +26 -0
- package/dist/push-policy/changed-paths.js +117 -0
- package/dist/push-policy/changed-paths.js.map +1 -0
- package/dist/push-policy/pushed-objects.d.ts +30 -0
- package/dist/push-policy/pushed-objects.js +76 -0
- package/dist/push-policy/pushed-objects.js.map +1 -0
- package/dist/push-policy/run-push-policy.d.ts +35 -0
- package/dist/push-policy/run-push-policy.js +77 -0
- package/dist/push-policy/run-push-policy.js.map +1 -0
- package/dist/push-policy/tree-diff.d.ts +21 -0
- package/dist/push-policy/tree-diff.js +78 -0
- package/dist/push-policy/tree-diff.js.map +1 -0
- package/dist/push-policy/uncheckable.d.ts +14 -0
- package/dist/push-policy/uncheckable.js +25 -0
- package/dist/push-policy/uncheckable.js.map +1 -0
- package/dist/rpc/branch-methods.d.ts +16 -0
- package/dist/rpc/branch-methods.js +43 -0
- package/dist/rpc/branch-methods.js.map +1 -0
- package/dist/rpc/commit-attempt.d.ts +27 -0
- package/dist/rpc/commit-attempt.js +85 -0
- package/dist/rpc/commit-attempt.js.map +1 -0
- package/dist/rpc/commit-graph.d.ts +20 -0
- package/dist/rpc/commit-graph.js +38 -0
- package/dist/rpc/commit-graph.js.map +1 -0
- package/dist/rpc/commit-method.d.ts +13 -0
- package/dist/rpc/commit-method.js +30 -0
- package/dist/rpc/commit-method.js.map +1 -0
- package/dist/rpc/commit-source.d.ts +12 -0
- package/dist/rpc/commit-source.js +9 -0
- package/dist/rpc/commit-source.js.map +1 -0
- package/dist/rpc/gateway-context.d.ts +2 -0
- package/dist/rpc/gateway-context.js +30 -0
- package/dist/rpc/gateway-context.js.map +1 -0
- package/dist/rpc/gateway-rpc.d.ts +10 -0
- package/dist/rpc/gateway-rpc.js +48 -0
- package/dist/rpc/gateway-rpc.js.map +1 -0
- package/dist/rpc/gateway-service.d.ts +24 -0
- package/dist/rpc/gateway-service.js +63 -0
- package/dist/rpc/gateway-service.js.map +1 -0
- package/dist/rpc/history-page.d.ts +35 -0
- package/dist/rpc/history-page.js +122 -0
- package/dist/rpc/history-page.js.map +1 -0
- package/dist/rpc/lifecycle-methods.d.ts +12 -0
- package/dist/rpc/lifecycle-methods.js +39 -0
- package/dist/rpc/lifecycle-methods.js.map +1 -0
- package/dist/rpc/paint-down.d.ts +17 -0
- package/dist/rpc/paint-down.js +96 -0
- package/dist/rpc/paint-down.js.map +1 -0
- package/dist/rpc/promote-attempt.d.ts +21 -0
- package/dist/rpc/promote-attempt.js +55 -0
- package/dist/rpc/promote-attempt.js.map +1 -0
- package/dist/rpc/push-ref.d.ts +21 -0
- package/dist/rpc/push-ref.js +47 -0
- package/dist/rpc/push-ref.js.map +1 -0
- package/dist/rpc/read-methods.d.ts +17 -0
- package/dist/rpc/read-methods.js +94 -0
- package/dist/rpc/read-methods.js.map +1 -0
- package/dist/rpc/read-token.d.ts +39 -0
- package/dist/rpc/read-token.js +107 -0
- package/dist/rpc/read-token.js.map +1 -0
- package/dist/rpc/repo-access.d.ts +36 -0
- package/dist/rpc/repo-access.js +75 -0
- package/dist/rpc/repo-access.js.map +1 -0
- package/dist/rpc/sync-attempt.d.ts +23 -0
- package/dist/rpc/sync-attempt.js +105 -0
- package/dist/rpc/sync-attempt.js.map +1 -0
- package/dist/sync-workflow-schemas-DCNmNE5-.d.ts +57 -0
- package/dist/upstream-DvqMCj5N.d.ts +15 -0
- package/dist/workflow-starter-BqhwX6oA.d.ts +45 -0
- package/dist/workflows/commit-workflow-schemas.d.ts +2 -0
- package/dist/workflows/commit-workflow-schemas.js +84 -0
- package/dist/workflows/commit-workflow-schemas.js.map +1 -0
- package/dist/workflows/commit-workflow.d.ts +16 -0
- package/dist/workflows/commit-workflow.js +22 -0
- package/dist/workflows/commit-workflow.js.map +1 -0
- package/dist/workflows/on-push.d.ts +2 -0
- package/dist/workflows/on-push.js +90 -0
- package/dist/workflows/on-push.js.map +1 -0
- package/dist/workflows/push-event.d.ts +2 -0
- package/dist/workflows/push-event.js +28 -0
- package/dist/workflows/push-event.js.map +1 -0
- package/dist/workflows/run-commit-workflow.d.ts +15 -0
- package/dist/workflows/run-commit-workflow.js +49 -0
- package/dist/workflows/run-commit-workflow.js.map +1 -0
- package/dist/workflows/run-sync-workflow.d.ts +14 -0
- package/dist/workflows/run-sync-workflow.js +67 -0
- package/dist/workflows/run-sync-workflow.js.map +1 -0
- package/dist/workflows/step-errors.d.ts +15 -0
- package/dist/workflows/step-errors.js +24 -0
- package/dist/workflows/step-errors.js.map +1 -0
- package/dist/workflows/step-runner.d.ts +31 -0
- package/dist/workflows/step-runner.js +6 -0
- package/dist/workflows/step-runner.js.map +1 -0
- package/dist/workflows/sync-branch-workflow.d.ts +15 -0
- package/dist/workflows/sync-branch-workflow.js +21 -0
- package/dist/workflows/sync-branch-workflow.js.map +1 -0
- package/dist/workflows/sync-workflow-schemas.d.ts +2 -0
- package/dist/workflows/sync-workflow-schemas.js +104 -0
- package/dist/workflows/sync-workflow-schemas.js.map +1 -0
- package/dist/workflows/workflow-instance-id.d.ts +12 -0
- package/dist/workflows/workflow-instance-id.js +33 -0
- package/dist/workflows/workflow-instance-id.js.map +1 -0
- package/dist/workflows/workflow-runtime.d.ts +7 -0
- package/dist/workflows/workflow-runtime.js +11 -0
- package/dist/workflows/workflow-runtime.js.map +1 -0
- package/dist/workflows/workflow-starter.d.ts +2 -0
- package/dist/workflows/workflow-starter.js +40 -0
- package/dist/workflows/workflow-starter.js.map +1 -0
- package/package.json +381 -4
- package/src/audit/audit-recorder.ts +74 -0
- package/src/audit/push-report.ts +60 -0
- package/src/auth/authenticate.ts +68 -0
- package/src/auth/authorize.ts +57 -0
- package/src/auth/read-token-auth.ts +119 -0
- package/src/cache/decision-cache.ts +57 -0
- package/src/gateway-app.ts +147 -0
- package/src/gateway-worker.ts +32 -0
- package/src/health.ts +12 -0
- package/src/logging/logger.ts +40 -0
- package/src/policy/branch-policy.ts +119 -0
- package/src/policy/enforce-branch-policy.ts +213 -0
- package/src/policy/fast-forward.ts +136 -0
- package/src/policy/ref-pattern.ts +24 -0
- package/src/policy/rule-branch-policy.ts +76 -0
- package/src/proxy/defer.ts +18 -0
- package/src/proxy/forward-read.ts +52 -0
- package/src/proxy/gateway-deps.ts +43 -0
- package/src/proxy/gateway-env.ts +43 -0
- package/src/proxy/git-responses.ts +89 -0
- package/src/proxy/git-route.ts +49 -0
- package/src/proxy/push-events.ts +91 -0
- package/src/proxy/push-guard.ts +109 -0
- package/src/proxy/push-options.ts +38 -0
- package/src/proxy/receive-pack.ts +257 -0
- package/src/proxy/request-log.ts +44 -0
- package/src/proxy/resolve-route.ts +24 -0
- package/src/proxy/upstream-call.ts +71 -0
- package/src/proxy/upstream.ts +76 -0
- package/src/push-policy/changed-paths.ts +143 -0
- package/src/push-policy/pushed-objects.ts +88 -0
- package/src/push-policy/run-push-policy.ts +99 -0
- package/src/push-policy/tree-diff.ts +107 -0
- package/src/push-policy/uncheckable.ts +27 -0
- package/src/rpc/branch-methods.ts +57 -0
- package/src/rpc/commit-attempt.ts +87 -0
- package/src/rpc/commit-graph.ts +44 -0
- package/src/rpc/commit-method.ts +36 -0
- package/src/rpc/commit-source.ts +15 -0
- package/src/rpc/gateway-context.ts +77 -0
- package/src/rpc/gateway-rpc.ts +65 -0
- package/src/rpc/gateway-service.ts +85 -0
- package/src/rpc/history-page.ts +163 -0
- package/src/rpc/lifecycle-methods.ts +50 -0
- package/src/rpc/paint-down.ts +120 -0
- package/src/rpc/promote-attempt.ts +52 -0
- package/src/rpc/push-ref.ts +54 -0
- package/src/rpc/read-methods.ts +111 -0
- package/src/rpc/read-token.ts +135 -0
- package/src/rpc/repo-access.ts +112 -0
- package/src/rpc/sync-attempt.ts +84 -0
- package/src/workflows/commit-workflow-schemas.ts +95 -0
- package/src/workflows/commit-workflow.ts +39 -0
- package/src/workflows/on-push.ts +128 -0
- package/src/workflows/push-event.ts +41 -0
- package/src/workflows/run-commit-workflow.ts +45 -0
- package/src/workflows/run-sync-workflow.ts +52 -0
- package/src/workflows/step-errors.ts +26 -0
- package/src/workflows/step-runner.ts +36 -0
- package/src/workflows/sync-branch-workflow.ts +40 -0
- package/src/workflows/sync-workflow-schemas.ts +122 -0
- package/src/workflows/workflow-instance-id.ts +26 -0
- package/src/workflows/workflow-runtime.ts +13 -0
- package/src/workflows/workflow-starter.ts +69 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { reasonLine } from "../policy/branch-policy.js";
|
|
2
|
+
import { ChangedPaths } from "./changed-paths.js";
|
|
3
|
+
import { readPushedObjects } from "./pushed-objects.js";
|
|
4
|
+
import { ReadBudget, Uncheckable } from "./uncheckable.js";
|
|
5
|
+
import { PushPolicyNeeds, PushPolicyResult } from "@leed-ai/git-gateway-contract/proxy/push-policy-result";
|
|
6
|
+
// src/push-policy/run-push-policy.ts
|
|
7
|
+
/** Asks the policy whether it needs changed paths for a push. */
|
|
8
|
+
async function pushPolicyNeeds(deps, push) {
|
|
9
|
+
return PushPolicyNeeds.parse(await deps.pushPolicy.needs(push.principal, push.repo, push.updates));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Runs the policy's check over a push with, per update, its commits (null when changed paths
|
|
13
|
+
* were not asked for) and returns the refused updates: denied ones with the policy's reason, and
|
|
14
|
+
* any the result does not name.
|
|
15
|
+
*/
|
|
16
|
+
async function judgeWithPushPolicy(deps, push, commits) {
|
|
17
|
+
const result = PushPolicyResult.parse(await deps.pushPolicy.check({
|
|
18
|
+
principal: push.principal,
|
|
19
|
+
repo: push.repo,
|
|
20
|
+
updates: push.updates.map((update, index) => ({
|
|
21
|
+
...update,
|
|
22
|
+
commits: commits[index] ?? null
|
|
23
|
+
}))
|
|
24
|
+
}));
|
|
25
|
+
const decisions = new Map(result.refs.map((decision) => [decision.ref, decision]));
|
|
26
|
+
const refusals = [];
|
|
27
|
+
for (const update of push.updates) {
|
|
28
|
+
const decision = decisions.get(update.ref);
|
|
29
|
+
if (decision === void 0) refusals.push({
|
|
30
|
+
ref: update.ref,
|
|
31
|
+
reason: "the push policy made no decision for this ref"
|
|
32
|
+
});
|
|
33
|
+
else if (decision.decision === "deny") refusals.push({
|
|
34
|
+
ref: update.ref,
|
|
35
|
+
reason: reasonLine(decision.reason)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return refusals;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Computes every update's commits and changed paths from the whole pushed pack (`pack`, checksum
|
|
42
|
+
* included) and storage, within the configured bounds, and runs the policy's check. A push that
|
|
43
|
+
* cannot be checked within them has every update refused, saying why.
|
|
44
|
+
*/
|
|
45
|
+
async function judgeChangedPaths(deps, push, pack) {
|
|
46
|
+
const { config, backend } = deps;
|
|
47
|
+
let commits;
|
|
48
|
+
try {
|
|
49
|
+
const budget = new ReadBudget(config.maxPushPolicyReads);
|
|
50
|
+
const objects = await readPushedObjects(pack, {
|
|
51
|
+
repo: push.repo,
|
|
52
|
+
backend,
|
|
53
|
+
budget,
|
|
54
|
+
maxObjectBytes: config.maxPushPolicyObjectBytes
|
|
55
|
+
});
|
|
56
|
+
const paths = new ChangedPaths({
|
|
57
|
+
repo: push.repo,
|
|
58
|
+
backend,
|
|
59
|
+
objects,
|
|
60
|
+
budget,
|
|
61
|
+
maxChangedPaths: config.maxChangedPaths
|
|
62
|
+
});
|
|
63
|
+
commits = [];
|
|
64
|
+
for (const update of push.updates) commits.push(await paths.commitsOf(update));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (!(error instanceof Uncheckable)) throw error;
|
|
67
|
+
const reason = reasonLine(`the push policy could not check this push: ${error.message}`);
|
|
68
|
+
return push.updates.map((update) => ({
|
|
69
|
+
ref: update.ref,
|
|
70
|
+
reason
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
return judgeWithPushPolicy(deps, push, commits);
|
|
74
|
+
}
|
|
75
|
+
export { judgeChangedPaths, judgeWithPushPolicy, pushPolicyNeeds };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=run-push-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-push-policy.js","names":[],"sources":["../../src/push-policy/run-push-policy.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { PushPolicy } from '@leed-ai/git-gateway-contract/proxy/gateway-hooks';\nimport type { Principal } from '@leed-ai/git-gateway-contract/proxy/principal';\nimport type { PushedCommit } from '@leed-ai/git-gateway-contract/proxy/push-policy';\nimport { PushPolicyNeeds, PushPolicyResult } from '@leed-ai/git-gateway-contract/proxy/push-policy-result';\nimport type { RefUpdate } from '@leed-ai/git-gateway-contract/schemas/ref-update';\nimport type { SmartHttpConfig } from '@leed-ai/git-gateway-contract/proxy/smart-http-config';\nimport type { StorageBackend } from '@leed-ai/git-gateway-contract/storage/storage-backend';\n\nimport { reasonLine } from '../policy/branch-policy.ts';\nimport type { RefRefusal } from '../proxy/git-responses.ts';\nimport { ChangedPaths } from './changed-paths.ts';\nimport { readPushedObjects } from './pushed-objects.ts';\nimport { ReadBudget, Uncheckable } from './uncheckable.ts';\n\n/** What running the push policy needs from the gateway. */\nexport interface PushPolicyDeps {\n readonly pushPolicy: PushPolicy;\n readonly backend: StorageBackend;\n readonly config: SmartHttpConfig;\n}\n\n/** Who pushes what, where. */\nexport interface PushPolicyPush {\n readonly principal: Principal;\n readonly repo: string;\n readonly updates: readonly RefUpdate[];\n}\n\n/** Asks the policy whether it needs changed paths for a push. */\nexport async function pushPolicyNeeds(deps: PushPolicyDeps, push: PushPolicyPush): Promise<PushPolicyNeeds> {\n return PushPolicyNeeds.parse(await deps.pushPolicy.needs(push.principal, push.repo, push.updates));\n}\n\n/**\n * Runs the policy's check over a push with, per update, its commits (null when changed paths\n * were not asked for) and returns the refused updates: denied ones with the policy's reason, and\n * any the result does not name.\n */\nexport async function judgeWithPushPolicy(\n deps: PushPolicyDeps,\n push: PushPolicyPush,\n commits: readonly (PushedCommit[] | null)[],\n): Promise<RefRefusal[]> {\n const result = PushPolicyResult.parse(\n await deps.pushPolicy.check({\n principal: push.principal,\n repo: push.repo,\n updates: push.updates.map((update, index) => ({ ...update, commits: commits[index] ?? null })),\n }),\n );\n const decisions = new Map(result.refs.map((decision) => [decision.ref, decision]));\n const refusals: RefRefusal[] = [];\n for (const update of push.updates) {\n const decision = decisions.get(update.ref);\n if (decision === undefined)\n refusals.push({ ref: update.ref, reason: 'the push policy made no decision for this ref' });\n else if (decision.decision === 'deny')\n refusals.push({ ref: update.ref, reason: reasonLine(decision.reason) });\n }\n return refusals;\n}\n\n/**\n * Computes every update's commits and changed paths from the whole pushed pack (`pack`, checksum\n * included) and storage, within the configured bounds, and runs the policy's check. A push that\n * cannot be checked within them has every update refused, saying why.\n */\nexport async function judgeChangedPaths(\n deps: PushPolicyDeps,\n push: PushPolicyPush,\n pack: Uint8Array,\n): Promise<RefRefusal[]> {\n const { config, backend } = deps;\n let commits: PushedCommit[][];\n try {\n const budget = new ReadBudget(config.maxPushPolicyReads);\n const objects = await readPushedObjects(pack, {\n repo: push.repo,\n backend,\n budget,\n maxObjectBytes: config.maxPushPolicyObjectBytes,\n });\n const paths = new ChangedPaths({\n repo: push.repo,\n backend,\n objects,\n budget,\n maxChangedPaths: config.maxChangedPaths,\n });\n commits = [];\n for (const update of push.updates) commits.push(await paths.commitsOf(update));\n } catch (error) {\n if (!(error instanceof Uncheckable)) throw error;\n const reason = reasonLine(`the push policy could not check this push: ${error.message}`);\n return push.updates.map((update) => ({ ref: update.ref, reason }));\n }\n return judgeWithPushPolicy(deps, push, commits);\n}\n"],"mappings":";;;;;;;AA8BA,eAAsB,gBAAgB,MAAsB,MAAgD;CAC1G,OAAO,gBAAgB,MAAM,MAAM,KAAK,WAAW,MAAM,KAAK,WAAW,KAAK,MAAM,KAAK,OAAO,CAAC;AACnG;;;;;;AAOA,eAAsB,oBACpB,MACA,MACA,SACuB;CACvB,MAAM,SAAS,iBAAiB,MAC9B,MAAM,KAAK,WAAW,MAAM;EAC1B,WAAW,KAAK;EAChB,MAAM,KAAK;EACX,SAAS,KAAK,QAAQ,KAAK,QAAQ,WAAW;GAAE,GAAG;GAAQ,SAAS,QAAQ,UAAU;EAAK,EAAE;CAC/F,CAAC,CACH;CACA,MAAM,YAAY,IAAI,IAAI,OAAO,KAAK,KAAK,aAAa,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC;CACjF,MAAM,WAAyB,CAAC;CAChC,KAAK,MAAM,UAAU,KAAK,SAAS;EACjC,MAAM,WAAW,UAAU,IAAI,OAAO,GAAG;EACzC,IAAI,aAAa,KAAA,GACf,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK,QAAQ;EAAgD,CAAC;OACvF,IAAI,SAAS,aAAa,QAC7B,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK,QAAQ,WAAW,SAAS,MAAM;EAAE,CAAC;CAC1E;CACA,OAAO;AACT;;;;;;AAOA,eAAsB,kBACpB,MACA,MACA,MACuB;CACvB,MAAM,EAAE,QAAQ,YAAY;CAC5B,IAAI;CACJ,IAAI;EACF,MAAM,SAAS,IAAI,WAAW,OAAO,kBAAkB;EACvD,MAAM,UAAU,MAAM,kBAAkB,MAAM;GAC5C,MAAM,KAAK;GACX;GACA;GACA,gBAAgB,OAAO;EACzB,CAAC;EACD,MAAM,QAAQ,IAAI,aAAa;GAC7B,MAAM,KAAK;GACX;GACA;GACA;GACA,iBAAiB,OAAO;EAC1B,CAAC;EACD,UAAU,CAAC;EACX,KAAK,MAAM,UAAU,KAAK,SAAS,QAAQ,KAAK,MAAM,MAAM,UAAU,MAAM,CAAC;CAC/E,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,cAAc,MAAM;EAC3C,MAAM,SAAS,WAAW,8CAA8C,MAAM,SAAS;EACvF,OAAO,KAAK,QAAQ,KAAK,YAAY;GAAE,KAAK,OAAO;GAAK;EAAO,EAAE;CACnE;CACA,OAAO,oBAAoB,MAAM,MAAM,OAAO;AAChD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ChangedPath } from "@leed-ai/git-gateway-contract/proxy/push-policy";
|
|
2
|
+
import { GitTreeEntry } from "@leed-ai/git-gateway-core/schemas/git-object";
|
|
3
|
+
/** A changed path before its size is known. */
|
|
4
|
+
export type TreeChange = Omit<ChangedPath, 'size'>;
|
|
5
|
+
/** Where tree entries come from; throws {@link Uncheckable} for a tree it cannot find. */
|
|
6
|
+
export type TreeLookup = (sha: string) => Promise<readonly GitTreeEntry[]>;
|
|
7
|
+
/** Collects changes, refusing more than `limit` of them across every diff it is used for. */
|
|
8
|
+
export declare class ChangeSink {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(limit: number);
|
|
11
|
+
/** Counts one more change; throws {@link Uncheckable} past the limit. */
|
|
12
|
+
take(change: TreeChange, into: TreeChange[]): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The files that differ between two trees (null for the empty tree), recursing only into subtrees
|
|
16
|
+
* whose ids differ, so the cost is proportional to what changed. A directory added or removed
|
|
17
|
+
* yields each file in it; an entry that turns from a file into a directory (or back) is the file
|
|
18
|
+
* deleted (or added) plus the directory's files. A mode change alone is "modified".
|
|
19
|
+
*/
|
|
20
|
+
export declare function diffTrees(lookup: TreeLookup, oldTree: string | null, newTree: string | null, sink: ChangeSink, prefix?: string): Promise<TreeChange[]>;
|
|
21
|
+
//# sourceMappingURL=tree-diff.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Uncheckable } from "./uncheckable.js";
|
|
2
|
+
// src/push-policy/tree-diff.ts
|
|
3
|
+
/** Longest path a ChangedPath may carry. */
|
|
4
|
+
const MAX_PATH = 4096;
|
|
5
|
+
const TREE_MODE = "040000";
|
|
6
|
+
/** Collects changes, refusing more than `limit` of them across every diff it is used for. */
|
|
7
|
+
var ChangeSink = class {
|
|
8
|
+
#limit;
|
|
9
|
+
#count = 0;
|
|
10
|
+
constructor(limit) {
|
|
11
|
+
this.#limit = limit;
|
|
12
|
+
}
|
|
13
|
+
/** Counts one more change; throws {@link Uncheckable} past the limit. */
|
|
14
|
+
take(change, into) {
|
|
15
|
+
this.#count += 1;
|
|
16
|
+
if (this.#count > this.#limit) throw new Uncheckable(`it changes more than ${this.#limit} paths`);
|
|
17
|
+
if (change.path.length > MAX_PATH) throw new Uncheckable(`a path is longer than ${MAX_PATH} characters`);
|
|
18
|
+
into.push(change);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const added = (path, entry) => ({
|
|
22
|
+
path,
|
|
23
|
+
change: "added",
|
|
24
|
+
oldMode: null,
|
|
25
|
+
newMode: entry.mode,
|
|
26
|
+
oldSha: null,
|
|
27
|
+
newSha: entry.sha
|
|
28
|
+
});
|
|
29
|
+
const deleted = (path, entry) => ({
|
|
30
|
+
path,
|
|
31
|
+
change: "deleted",
|
|
32
|
+
oldMode: entry.mode,
|
|
33
|
+
newMode: null,
|
|
34
|
+
oldSha: entry.sha,
|
|
35
|
+
newSha: null
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* The files that differ between two trees (null for the empty tree), recursing only into subtrees
|
|
39
|
+
* whose ids differ, so the cost is proportional to what changed. A directory added or removed
|
|
40
|
+
* yields each file in it; an entry that turns from a file into a directory (or back) is the file
|
|
41
|
+
* deleted (or added) plus the directory's files. A mode change alone is "modified".
|
|
42
|
+
*/
|
|
43
|
+
async function diffTrees(lookup, oldTree, newTree, sink, prefix = "") {
|
|
44
|
+
const changes = [];
|
|
45
|
+
if (oldTree === newTree) return changes;
|
|
46
|
+
const before = new Map((oldTree === null ? [] : await lookup(oldTree)).map((entry) => [entry.name, entry]));
|
|
47
|
+
const after = new Map((newTree === null ? [] : await lookup(newTree)).map((entry) => [entry.name, entry]));
|
|
48
|
+
const names = [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].toSorted();
|
|
49
|
+
for (const name of names) {
|
|
50
|
+
const old = before.get(name);
|
|
51
|
+
const current = after.get(name);
|
|
52
|
+
if (old?.sha === current?.sha && old?.mode === current?.mode) continue;
|
|
53
|
+
const path = `${prefix}${name}`;
|
|
54
|
+
const oldIsTree = old?.mode === TREE_MODE;
|
|
55
|
+
const newIsTree = current?.mode === TREE_MODE;
|
|
56
|
+
if (oldIsTree || newIsTree) {
|
|
57
|
+
const nested = await diffTrees(lookup, oldIsTree ? old?.sha ?? null : null, newIsTree ? current?.sha ?? null : null, sink, `${path}/`);
|
|
58
|
+
changes.push(...nested);
|
|
59
|
+
if (old !== void 0 && !oldIsTree) sink.take(deleted(path, old), changes);
|
|
60
|
+
if (current !== void 0 && !newIsTree) sink.take(added(path, current), changes);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (old !== void 0 && current !== void 0) sink.take({
|
|
64
|
+
path,
|
|
65
|
+
change: "modified",
|
|
66
|
+
oldMode: old.mode,
|
|
67
|
+
newMode: current.mode,
|
|
68
|
+
oldSha: old.sha,
|
|
69
|
+
newSha: current.sha
|
|
70
|
+
}, changes);
|
|
71
|
+
else if (old !== void 0) sink.take(deleted(path, old), changes);
|
|
72
|
+
else if (current !== void 0) sink.take(added(path, current), changes);
|
|
73
|
+
}
|
|
74
|
+
return changes;
|
|
75
|
+
}
|
|
76
|
+
export { ChangeSink, diffTrees };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=tree-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-diff.js","names":[],"sources":["../../src/push-policy/tree-diff.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { ChangedPath } from '@leed-ai/git-gateway-contract/proxy/push-policy';\nimport type { GitTreeEntry } from '@leed-ai/git-gateway-core/schemas/git-object';\n\nimport { Uncheckable } from './uncheckable.ts';\n\n/** A changed path before its size is known. */\nexport type TreeChange = Omit<ChangedPath, 'size'>;\n\n/** Where tree entries come from; throws {@link Uncheckable} for a tree it cannot find. */\nexport type TreeLookup = (sha: string) => Promise<readonly GitTreeEntry[]>;\n\n/** Longest path a ChangedPath may carry. */\nconst MAX_PATH = 4096;\nconst TREE_MODE = '040000';\n\n/** Collects changes, refusing more than `limit` of them across every diff it is used for. */\nexport class ChangeSink {\n readonly #limit: number;\n #count = 0;\n\n constructor(limit: number) {\n this.#limit = limit;\n }\n\n /** Counts one more change; throws {@link Uncheckable} past the limit. */\n take(change: TreeChange, into: TreeChange[]): void {\n this.#count += 1;\n if (this.#count > this.#limit) throw new Uncheckable(`it changes more than ${this.#limit} paths`);\n if (change.path.length > MAX_PATH) throw new Uncheckable(`a path is longer than ${MAX_PATH} characters`);\n into.push(change);\n }\n}\n\nconst added = (path: string, entry: GitTreeEntry): TreeChange => ({\n path,\n change: 'added',\n oldMode: null,\n newMode: entry.mode,\n oldSha: null,\n newSha: entry.sha,\n});\n\nconst deleted = (path: string, entry: GitTreeEntry): TreeChange => ({\n path,\n change: 'deleted',\n oldMode: entry.mode,\n newMode: null,\n oldSha: entry.sha,\n newSha: null,\n});\n\n/**\n * The files that differ between two trees (null for the empty tree), recursing only into subtrees\n * whose ids differ, so the cost is proportional to what changed. A directory added or removed\n * yields each file in it; an entry that turns from a file into a directory (or back) is the file\n * deleted (or added) plus the directory's files. A mode change alone is \"modified\".\n */\nexport async function diffTrees(\n lookup: TreeLookup,\n oldTree: string | null,\n newTree: string | null,\n sink: ChangeSink,\n prefix = '',\n): Promise<TreeChange[]> {\n const changes: TreeChange[] = [];\n if (oldTree === newTree) return changes;\n const before = new Map((oldTree === null ? [] : await lookup(oldTree)).map((entry) => [entry.name, entry]));\n const after = new Map((newTree === null ? [] : await lookup(newTree)).map((entry) => [entry.name, entry]));\n const names = [...new Set([...before.keys(), ...after.keys()])].toSorted();\n for (const name of names) {\n const old = before.get(name);\n const current = after.get(name);\n if (old?.sha === current?.sha && old?.mode === current?.mode) continue;\n const path = `${prefix}${name}`;\n const oldIsTree = old?.mode === TREE_MODE;\n const newIsTree = current?.mode === TREE_MODE;\n if (oldIsTree || newIsTree) {\n const nested = await diffTrees(\n lookup,\n oldIsTree ? (old?.sha ?? null) : null,\n newIsTree ? (current?.sha ?? null) : null,\n sink,\n `${path}/`,\n );\n changes.push(...nested);\n if (old !== undefined && !oldIsTree) sink.take(deleted(path, old), changes);\n if (current !== undefined && !newIsTree) sink.take(added(path, current), changes);\n continue;\n }\n if (old !== undefined && current !== undefined) {\n sink.take(\n {\n path,\n change: 'modified',\n oldMode: old.mode,\n newMode: current.mode,\n oldSha: old.sha,\n newSha: current.sha,\n },\n changes,\n );\n } else if (old !== undefined) sink.take(deleted(path, old), changes);\n else if (current !== undefined) sink.take(added(path, current), changes);\n }\n return changes;\n}\n"],"mappings":";;;AAaA,MAAM,WAAW;AACjB,MAAM,YAAY;;AAGlB,IAAa,aAAb,MAAwB;CACtB;CACA,SAAS;CAET,YAAY,OAAe;EACzB,KAAK,SAAS;CAChB;;CAGA,KAAK,QAAoB,MAA0B;EACjD,KAAK,UAAU;EACf,IAAI,KAAK,SAAS,KAAK,QAAQ,MAAM,IAAI,YAAY,wBAAwB,KAAK,OAAO,OAAO;EAChG,IAAI,OAAO,KAAK,SAAS,UAAU,MAAM,IAAI,YAAY,yBAAyB,SAAS,YAAY;EACvG,KAAK,KAAK,MAAM;CAClB;AACF;AAEA,MAAM,SAAS,MAAc,WAAqC;CAChE;CACA,QAAQ;CACR,SAAS;CACT,SAAS,MAAM;CACf,QAAQ;CACR,QAAQ,MAAM;AAChB;AAEA,MAAM,WAAW,MAAc,WAAqC;CAClE;CACA,QAAQ;CACR,SAAS,MAAM;CACf,SAAS;CACT,QAAQ,MAAM;CACd,QAAQ;AACV;;;;;;;AAQA,eAAsB,UACpB,QACA,SACA,SACA,MACA,SAAS,IACc;CACvB,MAAM,UAAwB,CAAC;CAC/B,IAAI,YAAY,SAAS,OAAO;CAChC,MAAM,SAAS,IAAI,KAAK,YAAY,OAAO,CAAC,IAAI,MAAM,OAAO,OAAO,EAAA,CAAG,KAAK,UAAU,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;CAC1G,MAAM,QAAQ,IAAI,KAAK,YAAY,OAAO,CAAC,IAAI,MAAM,OAAO,OAAO,EAAA,CAAG,KAAK,UAAU,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;CACzG,MAAM,QAAQ,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;CACzE,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,MAAM,OAAO,IAAI,IAAI;EAC3B,MAAM,UAAU,MAAM,IAAI,IAAI;EAC9B,IAAI,KAAK,QAAQ,SAAS,OAAO,KAAK,SAAS,SAAS,MAAM;EAC9D,MAAM,OAAO,GAAG,SAAS;EACzB,MAAM,YAAY,KAAK,SAAS;EAChC,MAAM,YAAY,SAAS,SAAS;EACpC,IAAI,aAAa,WAAW;GAC1B,MAAM,SAAS,MAAM,UACnB,QACA,YAAa,KAAK,OAAO,OAAQ,MACjC,YAAa,SAAS,OAAO,OAAQ,MACrC,MACA,GAAG,KAAK,EACV;GACA,QAAQ,KAAK,GAAG,MAAM;GACtB,IAAI,QAAQ,KAAA,KAAa,CAAC,WAAW,KAAK,KAAK,QAAQ,MAAM,GAAG,GAAG,OAAO;GAC1E,IAAI,YAAY,KAAA,KAAa,CAAC,WAAW,KAAK,KAAK,MAAM,MAAM,OAAO,GAAG,OAAO;GAChF;EACF;EACA,IAAI,QAAQ,KAAA,KAAa,YAAY,KAAA,GACnC,KAAK,KACH;GACE;GACA,QAAQ;GACR,SAAS,IAAI;GACb,SAAS,QAAQ;GACjB,QAAQ,IAAI;GACZ,QAAQ,QAAQ;EAClB,GACA,OACF;OACK,IAAI,QAAQ,KAAA,GAAW,KAAK,KAAK,QAAQ,MAAM,GAAG,GAAG,OAAO;OAC9D,IAAI,YAAY,KAAA,GAAW,KAAK,KAAK,MAAM,MAAM,OAAO,GAAG,OAAO;CACzE;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Thrown when a push cannot be checked within the configured bounds; the push is refused. */
|
|
2
|
+
export declare class Uncheckable extends Error {
|
|
3
|
+
readonly name = "Uncheckable";
|
|
4
|
+
}
|
|
5
|
+
/** Counts storage calls against a limit (SmartHttpConfig.maxPushPolicyReads). */
|
|
6
|
+
export declare class ReadBudget {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(limit: number);
|
|
9
|
+
/** How many calls have been made. */
|
|
10
|
+
get used(): number;
|
|
11
|
+
/** Records one storage call; throws {@link Uncheckable} past the limit. */
|
|
12
|
+
spend(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=uncheckable.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/push-policy/uncheckable.ts
|
|
2
|
+
/** Thrown when a push cannot be checked within the configured bounds; the push is refused. */
|
|
3
|
+
var Uncheckable = class extends Error {
|
|
4
|
+
name = "Uncheckable";
|
|
5
|
+
};
|
|
6
|
+
/** Counts storage calls against a limit (SmartHttpConfig.maxPushPolicyReads). */
|
|
7
|
+
var ReadBudget = class {
|
|
8
|
+
#limit;
|
|
9
|
+
#used = 0;
|
|
10
|
+
constructor(limit) {
|
|
11
|
+
this.#limit = limit;
|
|
12
|
+
}
|
|
13
|
+
/** How many calls have been made. */
|
|
14
|
+
get used() {
|
|
15
|
+
return this.#used;
|
|
16
|
+
}
|
|
17
|
+
/** Records one storage call; throws {@link Uncheckable} past the limit. */
|
|
18
|
+
spend() {
|
|
19
|
+
this.#used += 1;
|
|
20
|
+
if (this.#used > this.#limit) throw new Uncheckable(`it needs more than ${this.#limit} storage reads`);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export { ReadBudget, Uncheckable };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=uncheckable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncheckable.js","names":[],"sources":["../../src/push-policy/uncheckable.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** Thrown when a push cannot be checked within the configured bounds; the push is refused. */\nexport class Uncheckable extends Error {\n override readonly name = 'Uncheckable';\n}\n\n/** Counts storage calls against a limit (SmartHttpConfig.maxPushPolicyReads). */\nexport class ReadBudget {\n readonly #limit: number;\n #used = 0;\n\n constructor(limit: number) {\n this.#limit = limit;\n }\n\n /** How many calls have been made. */\n get used(): number {\n return this.#used;\n }\n\n /** Records one storage call; throws {@link Uncheckable} past the limit. */\n spend(): void {\n this.#used += 1;\n if (this.#used > this.#limit) throw new Uncheckable(`it needs more than ${this.#limit} storage reads`);\n }\n}\n"],"mappings":";;AAGA,IAAa,cAAb,cAAiC,MAAM;CACrC,OAAyB;AAC3B;;AAGA,IAAa,aAAb,MAAwB;CACtB;CACA,QAAQ;CAER,YAAY,OAAe;EACzB,KAAK,SAAS;CAChB;;CAGA,IAAI,OAAe;EACjB,OAAO,KAAK;CACd;;CAGA,QAAc;EACZ,KAAK,SAAS;EACd,IAAI,KAAK,QAAQ,KAAK,QAAQ,MAAM,IAAI,YAAY,sBAAsB,KAAK,OAAO,eAAe;CACvG;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { PromoteParams } from "./promote-attempt.js";
|
|
3
|
+
import { SyncParams } from "./sync-attempt.js";
|
|
4
|
+
import { RpcOutput } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
5
|
+
/**
|
|
6
|
+
* syncBranch(): up to `1 + config.inlineRetries` attempts, each re-reading both heads. When
|
|
7
|
+
* `into` moved under every attempt, stale_head (retryable by the caller, or by a
|
|
8
|
+
* SyncBranchWorkflow).
|
|
9
|
+
*/
|
|
10
|
+
export declare function gatewaySyncBranch(context: GatewayContext, input: SyncParams): Promise<RpcOutput<'syncBranch'>>;
|
|
11
|
+
/**
|
|
12
|
+
* promote(): up to `1 + config.inlineRetries` attempts, each re-checking both refusals against
|
|
13
|
+
* the current heads. When `into` moved under every attempt, stale_head.
|
|
14
|
+
*/
|
|
15
|
+
export declare function gatewayPromote(context: GatewayContext, input: PromoteParams): Promise<RpcOutput<'promote'>>;
|
|
16
|
+
//# sourceMappingURL=branch-methods.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { attemptPromote } from "./promote-attempt.js";
|
|
2
|
+
import { branchHead } from "./repo-access.js";
|
|
3
|
+
import { attemptSync } from "./sync-attempt.js";
|
|
4
|
+
import { gatewayError } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
5
|
+
// src/rpc/branch-methods.ts
|
|
6
|
+
/** The stale_head error for a branch that kept moving through every inline attempt. */
|
|
7
|
+
async function stillMoving(context, repo, branch, expectedHead) {
|
|
8
|
+
return gatewayError("stale_head", `Branch ${branch} kept moving; retry`, {
|
|
9
|
+
branch,
|
|
10
|
+
expectedHead,
|
|
11
|
+
actualHead: await branchHead(context, repo, branch)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* syncBranch(): up to `1 + config.inlineRetries` attempts, each re-reading both heads. When
|
|
16
|
+
* `into` moved under every attempt, stale_head (retryable by the caller, or by a
|
|
17
|
+
* SyncBranchWorkflow).
|
|
18
|
+
*/
|
|
19
|
+
async function gatewaySyncBranch(context, input) {
|
|
20
|
+
let lastHead = null;
|
|
21
|
+
for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
|
|
22
|
+
const outcome = await attemptSync(context, input);
|
|
23
|
+
if (outcome.kind === "done") return outcome.output;
|
|
24
|
+
lastHead = outcome.intoHead;
|
|
25
|
+
}
|
|
26
|
+
throw await stillMoving(context, input.repo, input.into, lastHead);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* promote(): up to `1 + config.inlineRetries` attempts, each re-checking both refusals against
|
|
30
|
+
* the current heads. When `into` moved under every attempt, stale_head.
|
|
31
|
+
*/
|
|
32
|
+
async function gatewayPromote(context, input) {
|
|
33
|
+
let lastHead = null;
|
|
34
|
+
for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
|
|
35
|
+
const outcome = await attemptPromote(context, input);
|
|
36
|
+
if (outcome.kind === "done") return outcome.output;
|
|
37
|
+
lastHead = outcome.intoHead;
|
|
38
|
+
}
|
|
39
|
+
throw await stillMoving(context, input.repo, input.into, lastHead);
|
|
40
|
+
}
|
|
41
|
+
export { gatewayPromote, gatewaySyncBranch };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=branch-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch-methods.js","names":[],"sources":["../../src/rpc/branch-methods.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { gatewayError } from '@leed-ai/git-gateway-contract/gateway-error';\n\nimport type { GatewayContext } from './gateway-context.ts';\nimport { attemptPromote, type PromoteParams } from './promote-attempt.ts';\nimport { branchHead } from './repo-access.ts';\nimport { attemptSync, type SyncParams } from './sync-attempt.ts';\n\n/** The stale_head error for a branch that kept moving through every inline attempt. */\nasync function stillMoving(\n context: GatewayContext,\n repo: string,\n branch: string,\n expectedHead: string | null,\n): Promise<Error> {\n return gatewayError('stale_head', `Branch ${branch} kept moving; retry`, {\n branch,\n expectedHead,\n actualHead: await branchHead(context, repo, branch),\n });\n}\n\n/**\n * syncBranch(): up to `1 + config.inlineRetries` attempts, each re-reading both heads. When\n * `into` moved under every attempt, stale_head (retryable by the caller, or by a\n * SyncBranchWorkflow).\n */\nexport async function gatewaySyncBranch(\n context: GatewayContext,\n input: SyncParams,\n): Promise<RpcOutput<'syncBranch'>> {\n let lastHead: string | null = null;\n for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {\n const outcome = await attemptSync(context, input);\n if (outcome.kind === 'done') return outcome.output;\n lastHead = outcome.intoHead;\n }\n throw await stillMoving(context, input.repo, input.into, lastHead);\n}\n\n/**\n * promote(): up to `1 + config.inlineRetries` attempts, each re-checking both refusals against\n * the current heads. When `into` moved under every attempt, stale_head.\n */\nexport async function gatewayPromote(\n context: GatewayContext,\n input: PromoteParams,\n): Promise<RpcOutput<'promote'>> {\n let lastHead: string | null = null;\n for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {\n const outcome = await attemptPromote(context, input);\n if (outcome.kind === 'done') return outcome.output;\n lastHead = outcome.intoHead;\n }\n throw await stillMoving(context, input.repo, input.into, lastHead);\n}\n"],"mappings":";;;;;;AAUA,eAAe,YACb,SACA,MACA,QACA,cACgB;CAChB,OAAO,aAAa,cAAc,UAAU,OAAO,sBAAsB;EACvE;EACA;EACA,YAAY,MAAM,WAAW,SAAS,MAAM,MAAM;CACpD,CAAC;AACH;;;;;;AAOA,eAAsB,kBACpB,SACA,OACkC;CAClC,IAAI,WAA0B;CAC9B,KAAK,IAAI,UAAU,GAAG,WAAW,QAAQ,OAAO,eAAe,WAAW,GAAG;EAC3E,MAAM,UAAU,MAAM,YAAY,SAAS,KAAK;EAChD,IAAI,QAAQ,SAAS,QAAQ,OAAO,QAAQ;EAC5C,WAAW,QAAQ;CACrB;CACA,MAAM,MAAM,YAAY,SAAS,MAAM,MAAM,MAAM,MAAM,QAAQ;AACnE;;;;;AAMA,eAAsB,eACpB,SACA,OAC+B;CAC/B,IAAI,WAA0B;CAC9B,KAAK,IAAI,UAAU,GAAG,WAAW,QAAQ,OAAO,eAAe,WAAW,GAAG;EAC3E,MAAM,UAAU,MAAM,eAAe,SAAS,KAAK;EACnD,IAAI,QAAQ,SAAS,QAAQ,OAAO,QAAQ;EAC5C,WAAW,QAAQ;CACrB;CACA,MAAM,MAAM,YAAY,SAAS,MAAM,MAAM,MAAM,MAAM,QAAQ;AACnE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { RpcOutput, RpcParsedInput } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
3
|
+
/** commit() input after parsing. */
|
|
4
|
+
export type CommitParams = RpcParsedInput<'commit'>;
|
|
5
|
+
/** The outcome of one commit attempt. */
|
|
6
|
+
export type CommitAttempt =
|
|
7
|
+
/** Finished: committed, replayed or no-op. Never "queued"; handing off is the caller's choice. */
|
|
8
|
+
{
|
|
9
|
+
readonly kind: 'done';
|
|
10
|
+
readonly output: Exclude<RpcOutput<'commit'>, {
|
|
11
|
+
status: 'queued';
|
|
12
|
+
}>;
|
|
13
|
+
} |
|
|
14
|
+
/** The push was refused because the branch moved; rebuild on `head` and try again. */
|
|
15
|
+
{
|
|
16
|
+
readonly kind: 'stale';
|
|
17
|
+
readonly head: string | null;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* One attempt at commit(), in the contract's order: idempotency replay (a commit carrying the key
|
|
21
|
+
* in the branch's recent history is returned as is), then the stale-head check against
|
|
22
|
+
* `expectedHead`, then the actions — built without a clone on the current head and pushed with an
|
|
23
|
+
* update naming that head. Safe to repeat any number of times, including after a crash between
|
|
24
|
+
* the push and recording its result: the next attempt finds the pushed commit by its key.
|
|
25
|
+
*/
|
|
26
|
+
export declare function attemptCommit(context: GatewayContext, input: CommitParams): Promise<CommitAttempt>;
|
|
27
|
+
//# sourceMappingURL=commit-attempt.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { pushRefUpdate } from "./push-ref.js";
|
|
2
|
+
import { branchHead, hasBranches, requireBranchHead, requireCommit, treeReader } from "./repo-access.js";
|
|
3
|
+
import { gatewayError } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
4
|
+
import { storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
|
|
5
|
+
import { buildCommit } from "@leed-ai/git-gateway-core/commit/build-commit";
|
|
6
|
+
import { findIdempotentCommit } from "@leed-ai/git-gateway-core/idempotency/find-idempotent-commit";
|
|
7
|
+
// src/rpc/commit-attempt.ts
|
|
8
|
+
/** The commit a missing branch starts from: the start branch's head, none (a root commit), or ref_not_found. */
|
|
9
|
+
async function startOf(context, input) {
|
|
10
|
+
if (input.startBranch !== void 0) return requireBranchHead(context, input.repo, input.startBranch);
|
|
11
|
+
if (!await hasBranches(context, input.repo)) return null;
|
|
12
|
+
throw gatewayError("ref_not_found", `Branch not found: ${input.branch}`, { ref: input.branch });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* One attempt at commit(), in the contract's order: idempotency replay (a commit carrying the key
|
|
16
|
+
* in the branch's recent history is returned as is), then the stale-head check against
|
|
17
|
+
* `expectedHead`, then the actions — built without a clone on the current head and pushed with an
|
|
18
|
+
* update naming that head. Safe to repeat any number of times, including after a crash between
|
|
19
|
+
* the push and recording its result: the next attempt finds the pushed commit by its key.
|
|
20
|
+
*/
|
|
21
|
+
async function attemptCommit(context, input) {
|
|
22
|
+
const { repo, branch } = input;
|
|
23
|
+
const head = await branchHead(context, repo, branch);
|
|
24
|
+
if (head !== null) {
|
|
25
|
+
const replay = await findIdempotentCommit({
|
|
26
|
+
head,
|
|
27
|
+
key: input.idempotencyKey,
|
|
28
|
+
window: context.config.idempotency,
|
|
29
|
+
now: context.now().toISOString()
|
|
30
|
+
}, { readCommit: (sha) => context.backend.readCommit(repo, sha) });
|
|
31
|
+
if (replay !== null) return {
|
|
32
|
+
kind: "done",
|
|
33
|
+
output: {
|
|
34
|
+
status: "replayed",
|
|
35
|
+
commit: replay
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (input.expectedHead !== void 0 && input.expectedHead !== head) throw gatewayError("stale_head", `Branch ${branch} moved`, {
|
|
40
|
+
branch,
|
|
41
|
+
expectedHead: input.expectedHead,
|
|
42
|
+
actualHead: head
|
|
43
|
+
});
|
|
44
|
+
const baseSha = head ?? await startOf(context, input);
|
|
45
|
+
const base = baseSha === null ? null : {
|
|
46
|
+
sha: baseSha,
|
|
47
|
+
tree: (await requireCommit(context, repo, baseSha)).tree
|
|
48
|
+
};
|
|
49
|
+
const built = await buildCommit({
|
|
50
|
+
branch,
|
|
51
|
+
base,
|
|
52
|
+
oldSha: head,
|
|
53
|
+
actions: input.actions,
|
|
54
|
+
message: input.message,
|
|
55
|
+
author: input.author,
|
|
56
|
+
...input.committer === void 0 ? {} : { committer: input.committer },
|
|
57
|
+
idempotencyKey: input.idempotencyKey,
|
|
58
|
+
date: context.now().toISOString()
|
|
59
|
+
}, treeReader(context, repo));
|
|
60
|
+
if (built.status === "noop") return {
|
|
61
|
+
kind: "done",
|
|
62
|
+
output: {
|
|
63
|
+
status: "noop",
|
|
64
|
+
head
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const pushed = await pushRefUpdate(context, repo, built.refUpdate, built.objects);
|
|
68
|
+
if (pushed.status === "ok") return {
|
|
69
|
+
kind: "done",
|
|
70
|
+
output: {
|
|
71
|
+
status: "committed",
|
|
72
|
+
commit: built.commit,
|
|
73
|
+
refUpdate: built.refUpdate
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const current = await branchHead(context, repo, branch);
|
|
77
|
+
if (current === head) throw storageUnavailable(`push to ${built.refUpdate.ref}`, pushed.reason);
|
|
78
|
+
return {
|
|
79
|
+
kind: "stale",
|
|
80
|
+
head: current
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export { attemptCommit };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=commit-attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-attempt.js","names":[],"sources":["../../src/rpc/commit-attempt.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { RpcOutput, RpcParsedInput } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { gatewayError } from '@leed-ai/git-gateway-contract/gateway-error';\nimport { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';\nimport { buildCommit } from '@leed-ai/git-gateway-core/commit/build-commit';\nimport { findIdempotentCommit } from '@leed-ai/git-gateway-core/idempotency/find-idempotent-commit';\n\nimport type { GatewayContext } from './gateway-context.ts';\nimport { pushRefUpdate } from './push-ref.ts';\nimport { branchHead, hasBranches, requireBranchHead, requireCommit, treeReader } from './repo-access.ts';\n\n/** commit() input after parsing. */\nexport type CommitParams = RpcParsedInput<'commit'>;\n\n/** The outcome of one commit attempt. */\nexport type CommitAttempt =\n /** Finished: committed, replayed or no-op. Never \"queued\"; handing off is the caller's choice. */\n | { readonly kind: 'done'; readonly output: Exclude<RpcOutput<'commit'>, { status: 'queued' }> }\n /** The push was refused because the branch moved; rebuild on `head` and try again. */\n | { readonly kind: 'stale'; readonly head: string | null };\n\n/** The commit a missing branch starts from: the start branch's head, none (a root commit), or ref_not_found. */\nasync function startOf(context: GatewayContext, input: CommitParams): Promise<string | null> {\n if (input.startBranch !== undefined) return requireBranchHead(context, input.repo, input.startBranch);\n if (!(await hasBranches(context, input.repo))) return null;\n throw gatewayError('ref_not_found', `Branch not found: ${input.branch}`, { ref: input.branch });\n}\n\n/**\n * One attempt at commit(), in the contract's order: idempotency replay (a commit carrying the key\n * in the branch's recent history is returned as is), then the stale-head check against\n * `expectedHead`, then the actions — built without a clone on the current head and pushed with an\n * update naming that head. Safe to repeat any number of times, including after a crash between\n * the push and recording its result: the next attempt finds the pushed commit by its key.\n */\nexport async function attemptCommit(context: GatewayContext, input: CommitParams): Promise<CommitAttempt> {\n const { repo, branch } = input;\n const head = await branchHead(context, repo, branch);\n if (head !== null) {\n const replay = await findIdempotentCommit(\n {\n head,\n key: input.idempotencyKey,\n window: context.config.idempotency,\n now: context.now().toISOString(),\n },\n { readCommit: (sha) => context.backend.readCommit(repo, sha) },\n );\n if (replay !== null) return { kind: 'done', output: { status: 'replayed', commit: replay } };\n }\n if (input.expectedHead !== undefined && input.expectedHead !== head) {\n throw gatewayError('stale_head', `Branch ${branch} moved`, {\n branch,\n expectedHead: input.expectedHead,\n actualHead: head,\n });\n }\n const baseSha = head ?? (await startOf(context, input));\n const base =\n baseSha === null ? null : { sha: baseSha, tree: (await requireCommit(context, repo, baseSha)).tree };\n const built = await buildCommit(\n {\n branch,\n base,\n oldSha: head,\n actions: input.actions,\n message: input.message,\n author: input.author,\n ...(input.committer === undefined ? {} : { committer: input.committer }),\n idempotencyKey: input.idempotencyKey,\n date: context.now().toISOString(),\n },\n treeReader(context, repo),\n );\n if (built.status === 'noop') return { kind: 'done', output: { status: 'noop', head } };\n const pushed = await pushRefUpdate(context, repo, built.refUpdate, built.objects);\n if (pushed.status === 'ok') {\n return {\n kind: 'done',\n output: { status: 'committed', commit: built.commit, refUpdate: built.refUpdate },\n };\n }\n const current = await branchHead(context, repo, branch);\n // A refusal while the branch still names the head we built on is not contention: the host said no.\n if (current === head) throw storageUnavailable(`push to ${built.refUpdate.ref}`, pushed.reason);\n return { kind: 'stale', head: current };\n}\n"],"mappings":";;;;;;;;AAsBA,eAAe,QAAQ,SAAyB,OAA6C;CAC3F,IAAI,MAAM,gBAAgB,KAAA,GAAW,OAAO,kBAAkB,SAAS,MAAM,MAAM,MAAM,WAAW;CACpG,IAAI,CAAE,MAAM,YAAY,SAAS,MAAM,IAAI,GAAI,OAAO;CACtD,MAAM,aAAa,iBAAiB,qBAAqB,MAAM,UAAU,EAAE,KAAK,MAAM,OAAO,CAAC;AAChG;;;;;;;;AASA,eAAsB,cAAc,SAAyB,OAA6C;CACxG,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,OAAO,MAAM,WAAW,SAAS,MAAM,MAAM;CACnD,IAAI,SAAS,MAAM;EACjB,MAAM,SAAS,MAAM,qBACnB;GACE;GACA,KAAK,MAAM;GACX,QAAQ,QAAQ,OAAO;GACvB,KAAK,QAAQ,IAAI,CAAC,CAAC,YAAY;EACjC,GACA,EAAE,aAAa,QAAQ,QAAQ,QAAQ,WAAW,MAAM,GAAG,EAAE,CAC/D;EACA,IAAI,WAAW,MAAM,OAAO;GAAE,MAAM;GAAQ,QAAQ;IAAE,QAAQ;IAAY,QAAQ;GAAO;EAAE;CAC7F;CACA,IAAI,MAAM,iBAAiB,KAAA,KAAa,MAAM,iBAAiB,MAC7D,MAAM,aAAa,cAAc,UAAU,OAAO,SAAS;EACzD;EACA,cAAc,MAAM;EACpB,YAAY;CACd,CAAC;CAEH,MAAM,UAAU,QAAS,MAAM,QAAQ,SAAS,KAAK;CACrD,MAAM,OACJ,YAAY,OAAO,OAAO;EAAE,KAAK;EAAS,OAAO,MAAM,cAAc,SAAS,MAAM,OAAO,EAAA,CAAG;CAAK;CACrG,MAAM,QAAQ,MAAM,YAClB;EACE;EACA;EACA,QAAQ;EACR,SAAS,MAAM;EACf,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,GAAI,MAAM,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,MAAM,UAAU;EACtE,gBAAgB,MAAM;EACtB,MAAM,QAAQ,IAAI,CAAC,CAAC,YAAY;CAClC,GACA,WAAW,SAAS,IAAI,CAC1B;CACA,IAAI,MAAM,WAAW,QAAQ,OAAO;EAAE,MAAM;EAAQ,QAAQ;GAAE,QAAQ;GAAQ;EAAK;CAAE;CACrF,MAAM,SAAS,MAAM,cAAc,SAAS,MAAM,MAAM,WAAW,MAAM,OAAO;CAChF,IAAI,OAAO,WAAW,MACpB,OAAO;EACL,MAAM;EACN,QAAQ;GAAE,QAAQ;GAAa,QAAQ,MAAM;GAAQ,WAAW,MAAM;EAAU;CAClF;CAEF,MAAM,UAAU,MAAM,WAAW,SAAS,MAAM,MAAM;CAEtD,IAAI,YAAY,MAAM,MAAM,mBAAmB,WAAW,MAAM,UAAU,OAAO,OAAO,MAAM;CAC9F,OAAO;EAAE,MAAM;EAAS,MAAM;CAAQ;AACxC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommitSource } from "./commit-source.js";
|
|
2
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
3
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
4
|
+
/**
|
|
5
|
+
* The commits of one repository, read through the backend on demand and kept for the duration of
|
|
6
|
+
* one call (commits are immutable, so the cache can never go stale). Ancestry questions are
|
|
7
|
+
* answered with git's paint-down walk, which reads only the history between the commits asked
|
|
8
|
+
* about and their merge base — never the whole history of a branch.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CommitGraph implements CommitSource {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(context: GatewayContext, repo: string);
|
|
13
|
+
/** The commit with this id, or null when the repository has none; each id is read once. */
|
|
14
|
+
commit(sha: string): Promise<Commit | null>;
|
|
15
|
+
/** True when `ancestor` is reachable from `descendant` (a commit contains itself). */
|
|
16
|
+
contains(descendant: string, ancestor: string): Promise<boolean>;
|
|
17
|
+
/** The reference's merge base of two commits, or null when their histories are unrelated. */
|
|
18
|
+
mergeBase(a: string, b: string): Promise<string | null>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=commit-graph.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isAncestor, mergeBaseOf } from "./paint-down.js";
|
|
2
|
+
// src/rpc/commit-graph.ts
|
|
3
|
+
/**
|
|
4
|
+
* The commits of one repository, read through the backend on demand and kept for the duration of
|
|
5
|
+
* one call (commits are immutable, so the cache can never go stale). Ancestry questions are
|
|
6
|
+
* answered with git's paint-down walk, which reads only the history between the commits asked
|
|
7
|
+
* about and their merge base — never the whole history of a branch.
|
|
8
|
+
*/
|
|
9
|
+
var CommitGraph = class {
|
|
10
|
+
#context;
|
|
11
|
+
#repo;
|
|
12
|
+
#commits = /* @__PURE__ */ new Map();
|
|
13
|
+
constructor(context, repo) {
|
|
14
|
+
this.#context = context;
|
|
15
|
+
this.#repo = repo;
|
|
16
|
+
}
|
|
17
|
+
/** The commit with this id, or null when the repository has none; each id is read once. */
|
|
18
|
+
commit(sha) {
|
|
19
|
+
let read = this.#commits.get(sha);
|
|
20
|
+
if (read === void 0) {
|
|
21
|
+
read = this.#context.backend.readCommit(this.#repo, sha);
|
|
22
|
+
this.#commits.set(sha, read);
|
|
23
|
+
read.catch(() => this.#commits.delete(sha));
|
|
24
|
+
}
|
|
25
|
+
return read;
|
|
26
|
+
}
|
|
27
|
+
/** True when `ancestor` is reachable from `descendant` (a commit contains itself). */
|
|
28
|
+
contains(descendant, ancestor) {
|
|
29
|
+
return isAncestor(this, descendant, ancestor);
|
|
30
|
+
}
|
|
31
|
+
/** The reference's merge base of two commits, or null when their histories are unrelated. */
|
|
32
|
+
mergeBase(a, b) {
|
|
33
|
+
return mergeBaseOf(this, a, b);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export { CommitGraph };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=commit-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-graph.js","names":[],"sources":["../../src/rpc/commit-graph.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\n\nimport type { CommitSource } from './commit-source.ts';\nimport type { GatewayContext } from './gateway-context.ts';\nimport { isAncestor, mergeBaseOf } from './paint-down.ts';\n\n/**\n * The commits of one repository, read through the backend on demand and kept for the duration of\n * one call (commits are immutable, so the cache can never go stale). Ancestry questions are\n * answered with git's paint-down walk, which reads only the history between the commits asked\n * about and their merge base — never the whole history of a branch.\n */\nexport class CommitGraph implements CommitSource {\n readonly #context: GatewayContext;\n readonly #repo: string;\n readonly #commits = new Map<string, Promise<Commit | null>>();\n\n constructor(context: GatewayContext, repo: string) {\n this.#context = context;\n this.#repo = repo;\n }\n\n /** The commit with this id, or null when the repository has none; each id is read once. */\n commit(sha: string): Promise<Commit | null> {\n let read = this.#commits.get(sha);\n if (read === undefined) {\n read = this.#context.backend.readCommit(this.#repo, sha);\n this.#commits.set(sha, read);\n read.catch(() => this.#commits.delete(sha));\n }\n return read;\n }\n\n /** True when `ancestor` is reachable from `descendant` (a commit contains itself). */\n contains(descendant: string, ancestor: string): Promise<boolean> {\n return isAncestor(this, descendant, ancestor);\n }\n\n /** The reference's merge base of two commits, or null when their histories are unrelated. */\n mergeBase(a: string, b: string): Promise<string | null> {\n return mergeBaseOf(this, a, b);\n }\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,cAAb,MAAiD;CAC/C;CACA;CACA,2BAAoB,IAAI,IAAoC;CAE5D,YAAY,SAAyB,MAAc;EACjD,KAAK,WAAW;EAChB,KAAK,QAAQ;CACf;;CAGA,OAAO,KAAqC;EAC1C,IAAI,OAAO,KAAK,SAAS,IAAI,GAAG;EAChC,IAAI,SAAS,KAAA,GAAW;GACtB,OAAO,KAAK,SAAS,QAAQ,WAAW,KAAK,OAAO,GAAG;GACvD,KAAK,SAAS,IAAI,KAAK,IAAI;GAC3B,KAAK,YAAY,KAAK,SAAS,OAAO,GAAG,CAAC;EAC5C;EACA,OAAO;CACT;;CAGA,SAAS,YAAoB,UAAoC;EAC/D,OAAO,WAAW,MAAM,YAAY,QAAQ;CAC9C;;CAGA,UAAU,GAAW,GAAmC;EACtD,OAAO,YAAY,MAAM,GAAG,CAAC;CAC/B;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CommitParams } from "./commit-attempt.js";
|
|
2
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
3
|
+
import { RpcOutput } from "@leed-ai/git-gateway-contract/git-gateway";
|
|
4
|
+
/**
|
|
5
|
+
* commit(): up to `1 + config.inlineRetries` attempts, each rebuilt on the head that beat the
|
|
6
|
+
* previous one. When every attempt lost a race, the same input — idempotency key included — is
|
|
7
|
+
* handed to a CommitWorkflow under an id derived from repository, branch and key (so handing the
|
|
8
|
+
* same commit off twice starts one instance) and `queued` is returned with that id. When the
|
|
9
|
+
* instance under that id has errored or been terminated, it is restarted, so a retry with the same
|
|
10
|
+
* key is never answered by an instance that will not run.
|
|
11
|
+
*/
|
|
12
|
+
export declare function gatewayCommit(context: GatewayContext, input: CommitParams): Promise<RpcOutput<'commit'>>;
|
|
13
|
+
//# sourceMappingURL=commit-method.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { commitWorkflowId } from "../workflows/workflow-instance-id.js";
|
|
2
|
+
import { startWorkflowOnce } from "../workflows/workflow-starter.js";
|
|
3
|
+
import { attemptCommit } from "./commit-attempt.js";
|
|
4
|
+
import { storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
|
|
5
|
+
// src/rpc/commit-method.ts
|
|
6
|
+
/**
|
|
7
|
+
* commit(): up to `1 + config.inlineRetries` attempts, each rebuilt on the head that beat the
|
|
8
|
+
* previous one. When every attempt lost a race, the same input — idempotency key included — is
|
|
9
|
+
* handed to a CommitWorkflow under an id derived from repository, branch and key (so handing the
|
|
10
|
+
* same commit off twice starts one instance) and `queued` is returned with that id. When the
|
|
11
|
+
* instance under that id has errored or been terminated, it is restarted, so a retry with the same
|
|
12
|
+
* key is never answered by an instance that will not run.
|
|
13
|
+
*/
|
|
14
|
+
async function gatewayCommit(context, input) {
|
|
15
|
+
for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
|
|
16
|
+
const outcome = await attemptCommit(context, input);
|
|
17
|
+
if (outcome.kind === "done") return outcome.output;
|
|
18
|
+
}
|
|
19
|
+
const workflow = context.commitWorkflow;
|
|
20
|
+
if (workflow === void 0) throw storageUnavailable(`commit to ${input.branch}`, "the branch kept moving and no CommitWorkflow is configured to finish the commit");
|
|
21
|
+
const workflowInstanceId = await commitWorkflowId(input.repo, input.branch, input.idempotencyKey);
|
|
22
|
+
await startWorkflowOnce(workflow, workflowInstanceId, input);
|
|
23
|
+
return {
|
|
24
|
+
status: "queued",
|
|
25
|
+
workflowInstanceId
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { gatewayCommit };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=commit-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-method.js","names":[],"sources":["../../src/rpc/commit-method.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';\n\nimport { commitWorkflowId } from '../workflows/workflow-instance-id.ts';\nimport { startWorkflowOnce } from '../workflows/workflow-starter.ts';\nimport { attemptCommit, type CommitParams } from './commit-attempt.ts';\nimport type { GatewayContext } from './gateway-context.ts';\n\n/**\n * commit(): up to `1 + config.inlineRetries` attempts, each rebuilt on the head that beat the\n * previous one. When every attempt lost a race, the same input — idempotency key included — is\n * handed to a CommitWorkflow under an id derived from repository, branch and key (so handing the\n * same commit off twice starts one instance) and `queued` is returned with that id. When the\n * instance under that id has errored or been terminated, it is restarted, so a retry with the same\n * key is never answered by an instance that will not run.\n */\nexport async function gatewayCommit(\n context: GatewayContext,\n input: CommitParams,\n): Promise<RpcOutput<'commit'>> {\n for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {\n const outcome = await attemptCommit(context, input);\n if (outcome.kind === 'done') return outcome.output;\n }\n const workflow = context.commitWorkflow;\n if (workflow === undefined) {\n throw storageUnavailable(\n `commit to ${input.branch}`,\n 'the branch kept moving and no CommitWorkflow is configured to finish the commit',\n );\n }\n const workflowInstanceId = await commitWorkflowId(input.repo, input.branch, input.idempotencyKey);\n await startWorkflowOnce(workflow, workflowInstanceId, input);\n return { status: 'queued', workflowInstanceId };\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,eAAsB,cACpB,SACA,OAC8B;CAC9B,KAAK,IAAI,UAAU,GAAG,WAAW,QAAQ,OAAO,eAAe,WAAW,GAAG;EAC3E,MAAM,UAAU,MAAM,cAAc,SAAS,KAAK;EAClD,IAAI,QAAQ,SAAS,QAAQ,OAAO,QAAQ;CAC9C;CACA,MAAM,WAAW,QAAQ;CACzB,IAAI,aAAa,KAAA,GACf,MAAM,mBACJ,aAAa,MAAM,UACnB,iFACF;CAEF,MAAM,qBAAqB,MAAM,iBAAiB,MAAM,MAAM,MAAM,QAAQ,MAAM,cAAc;CAChG,MAAM,kBAAkB,UAAU,oBAAoB,KAAK;CAC3D,OAAO;EAAE,QAAQ;EAAU;CAAmB;AAChD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
2
|
+
/** Reads commits one at a time by id, as `CommitGraph` does over a backend. */
|
|
3
|
+
export interface CommitSource {
|
|
4
|
+
/** The commit with this id, or null when the repository has none. */
|
|
5
|
+
commit(sha: string): Promise<Commit | null>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Orders committer dates the way the contract's reference history does: as strings. Every walk
|
|
9
|
+
* that must agree with the reference compares dates with this, never with `Date.parse`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const dateOrder: (a: Commit, b: Commit) => number;
|
|
12
|
+
//# sourceMappingURL=commit-source.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/rpc/commit-source.ts
|
|
2
|
+
/**
|
|
3
|
+
* Orders committer dates the way the contract's reference history does: as strings. Every walk
|
|
4
|
+
* that must agree with the reference compares dates with this, never with `Date.parse`.
|
|
5
|
+
*/
|
|
6
|
+
const dateOrder = (a, b) => a.committer.date === b.committer.date ? 0 : a.committer.date > b.committer.date ? 1 : -1;
|
|
7
|
+
export { dateOrder };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=commit-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-source.js","names":[],"sources":["../../src/rpc/commit-source.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\n\n/** Reads commits one at a time by id, as `CommitGraph` does over a backend. */\nexport interface CommitSource {\n /** The commit with this id, or null when the repository has none. */\n commit(sha: string): Promise<Commit | null>;\n}\n\n/**\n * Orders committer dates the way the contract's reference history does: as strings. Every walk\n * that must agree with the reference compares dates with this, never with `Date.parse`.\n */\nexport const dateOrder = (a: Commit, b: Commit): number =>\n a.committer.date === b.committer.date ? 0 : a.committer.date > b.committer.date ? 1 : -1;\n"],"mappings":";;;;;AAaA,MAAa,aAAa,GAAW,MACnC,EAAE,UAAU,SAAS,EAAE,UAAU,OAAO,IAAI,EAAE,UAAU,OAAO,EAAE,UAAU,OAAO,IAAI"}
|