@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,105 @@
|
|
|
1
|
+
import { CommitGraph } from "./commit-graph.js";
|
|
2
|
+
import { pushRefUpdate } from "./push-ref.js";
|
|
3
|
+
import { branchHead, branchRef, requireBranchHead, requireCommit, treeReader } from "./repo-access.js";
|
|
4
|
+
import { gatewayError } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
5
|
+
import { storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
|
|
6
|
+
import { mergeTrees } from "@leed-ai/git-gateway-core/merge/merge-trees";
|
|
7
|
+
import { createCommit } from "@leed-ai/git-gateway-core/objects/commit-object";
|
|
8
|
+
// src/rpc/sync-attempt.ts
|
|
9
|
+
/** A commit message as git stores it: ending in exactly one newline. */
|
|
10
|
+
const asStoredMessage = (message) => {
|
|
11
|
+
let end = message.length;
|
|
12
|
+
while (end > 0 && message.charCodeAt(end - 1) === 10) end -= 1;
|
|
13
|
+
return `${message.slice(0, end)}\n`;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* One attempt at syncBranch(): `into` already contains `from` → up_to_date; `into` has nothing of
|
|
17
|
+
* its own → fast-forward; otherwise a file-level three-way merge against the merge base (the
|
|
18
|
+
* reference's own merge-base rule, found by a paint-down walk that reads only the history since it), written as a merge commit whose
|
|
19
|
+
* parents are `into` then `from`, or a conflict listing every path, with nothing written. Every
|
|
20
|
+
* push names the head of `into` it was built on, so nothing is overwritten or forced.
|
|
21
|
+
*/
|
|
22
|
+
async function attemptSync(context, input) {
|
|
23
|
+
const { repo, from, into } = input;
|
|
24
|
+
const fromHead = await requireBranchHead(context, repo, from);
|
|
25
|
+
const intoHead = await requireBranchHead(context, repo, into);
|
|
26
|
+
const base = await new CommitGraph(context, repo).mergeBase(intoHead, fromHead);
|
|
27
|
+
if (base === fromHead) return {
|
|
28
|
+
kind: "done",
|
|
29
|
+
output: {
|
|
30
|
+
status: "up_to_date",
|
|
31
|
+
head: intoHead
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const refUpdate = (newSha) => ({
|
|
35
|
+
ref: branchRef(into),
|
|
36
|
+
oldSha: intoHead,
|
|
37
|
+
newSha
|
|
38
|
+
});
|
|
39
|
+
/** Pushes `into` to `newSha`; false when `into` moved first (a refusal for any other reason throws). */
|
|
40
|
+
const push = async (newSha, objects) => {
|
|
41
|
+
const pushed = await pushRefUpdate(context, repo, refUpdate(newSha), objects);
|
|
42
|
+
if (pushed.status === "ok") return true;
|
|
43
|
+
if (await branchHead(context, repo, into) === intoHead) throw storageUnavailable(`push to ${branchRef(into)}`, pushed.reason);
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
if (base === intoHead) {
|
|
47
|
+
if (!await push(fromHead, [])) return {
|
|
48
|
+
kind: "stale",
|
|
49
|
+
intoHead
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
kind: "done",
|
|
53
|
+
output: {
|
|
54
|
+
status: "fast_forward",
|
|
55
|
+
refUpdate: refUpdate(fromHead)
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (base === null) throw gatewayError("unrelated_histories", `${from} and ${into} share no history`, {
|
|
60
|
+
from,
|
|
61
|
+
into
|
|
62
|
+
});
|
|
63
|
+
const treeOf = async (sha) => (await requireCommit(context, repo, sha)).tree;
|
|
64
|
+
const merged = await mergeTrees({
|
|
65
|
+
base: await treeOf(base),
|
|
66
|
+
ours: await treeOf(intoHead),
|
|
67
|
+
theirs: await treeOf(fromHead)
|
|
68
|
+
}, treeReader(context, repo));
|
|
69
|
+
if (merged.status === "conflict") return {
|
|
70
|
+
kind: "done",
|
|
71
|
+
output: {
|
|
72
|
+
status: "conflict",
|
|
73
|
+
paths: merged.paths,
|
|
74
|
+
base,
|
|
75
|
+
fromHead,
|
|
76
|
+
intoHead
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const signature = {
|
|
80
|
+
...input.author ?? context.config.serviceIdentity,
|
|
81
|
+
date: context.now().toISOString()
|
|
82
|
+
};
|
|
83
|
+
const { object, commit } = await createCommit({
|
|
84
|
+
tree: merged.tree,
|
|
85
|
+
parents: [intoHead, fromHead],
|
|
86
|
+
author: signature,
|
|
87
|
+
committer: signature,
|
|
88
|
+
message: asStoredMessage(input.message ?? `Merge branch '${from}' into ${into}`)
|
|
89
|
+
});
|
|
90
|
+
if (!await push(commit.sha, [...merged.objects, object])) return {
|
|
91
|
+
kind: "stale",
|
|
92
|
+
intoHead
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
kind: "done",
|
|
96
|
+
output: {
|
|
97
|
+
status: "merged",
|
|
98
|
+
commit,
|
|
99
|
+
refUpdate: refUpdate(commit.sha)
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export { attemptSync };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=sync-attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-attempt.js","names":[],"sources":["../../src/rpc/sync-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 { mergeTrees } from '@leed-ai/git-gateway-core/merge/merge-trees';\nimport { createCommit } from '@leed-ai/git-gateway-core/objects/commit-object';\nimport type { GitObject } from '@leed-ai/git-gateway-core/schemas/git-object';\n\nimport { CommitGraph } from './commit-graph.ts';\nimport type { GatewayContext } from './gateway-context.ts';\nimport { pushRefUpdate } from './push-ref.ts';\nimport { branchHead, branchRef, requireBranchHead, requireCommit, treeReader } from './repo-access.ts';\n\n/** syncBranch() input after parsing. */\nexport type SyncParams = RpcParsedInput<'syncBranch'>;\n\n/** The outcome of one sync attempt. */\nexport type SyncAttempt =\n | { readonly kind: 'done'; readonly output: RpcOutput<'syncBranch'> }\n /** The push was refused because `into` moved; `intoHead` is the head that was built on. */\n | { readonly kind: 'stale'; readonly intoHead: string };\n\n/** A commit message as git stores it: ending in exactly one newline. */\nconst asStoredMessage = (message: string): string => {\n // A scan from the end, not /\\n+$/: that regex retries from every newline run (polynomial time).\n let end = message.length;\n while (end > 0 && message.charCodeAt(end - 1) === 10) end -= 1;\n return `${message.slice(0, end)}\\n`;\n};\n\n/**\n * One attempt at syncBranch(): `into` already contains `from` → up_to_date; `into` has nothing of\n * its own → fast-forward; otherwise a file-level three-way merge against the merge base (the\n * reference's own merge-base rule, found by a paint-down walk that reads only the history since it), written as a merge commit whose\n * parents are `into` then `from`, or a conflict listing every path, with nothing written. Every\n * push names the head of `into` it was built on, so nothing is overwritten or forced.\n */\nexport async function attemptSync(context: GatewayContext, input: SyncParams): Promise<SyncAttempt> {\n const { repo, from, into } = input;\n const fromHead = await requireBranchHead(context, repo, from);\n const intoHead = await requireBranchHead(context, repo, into);\n // One paint-down walk answers all three questions: `from` is contained in `into` exactly when\n // it is their merge base, `into` in `from` exactly when `into` is.\n const base = await new CommitGraph(context, repo).mergeBase(intoHead, fromHead);\n if (base === fromHead) {\n return { kind: 'done', output: { status: 'up_to_date', head: intoHead } };\n }\n const refUpdate = (newSha: string) => ({ ref: branchRef(into), oldSha: intoHead, newSha });\n /** Pushes `into` to `newSha`; false when `into` moved first (a refusal for any other reason throws). */\n const push = async (newSha: string, objects: readonly GitObject[]): Promise<boolean> => {\n const pushed = await pushRefUpdate(context, repo, refUpdate(newSha), objects);\n if (pushed.status === 'ok') return true;\n if ((await branchHead(context, repo, into)) === intoHead) {\n throw storageUnavailable(`push to ${branchRef(into)}`, pushed.reason);\n }\n return false;\n };\n if (base === intoHead) {\n if (!(await push(fromHead, []))) return { kind: 'stale', intoHead };\n return { kind: 'done', output: { status: 'fast_forward', refUpdate: refUpdate(fromHead) } };\n }\n if (base === null) {\n throw gatewayError('unrelated_histories', `${from} and ${into} share no history`, { from, into });\n }\n const treeOf = async (sha: string): Promise<string> => (await requireCommit(context, repo, sha)).tree;\n const merged = await mergeTrees(\n { base: await treeOf(base), ours: await treeOf(intoHead), theirs: await treeOf(fromHead) },\n treeReader(context, repo),\n );\n if (merged.status === 'conflict') {\n return { kind: 'done', output: { status: 'conflict', paths: merged.paths, base, fromHead, intoHead } };\n }\n const identity = input.author ?? context.config.serviceIdentity;\n const signature = { ...identity, date: context.now().toISOString() };\n const { object, commit } = await createCommit({\n tree: merged.tree,\n parents: [intoHead, fromHead],\n author: signature,\n committer: signature,\n message: asStoredMessage(input.message ?? `Merge branch '${from}' into ${into}`),\n });\n if (!(await push(commit.sha, [...merged.objects, object]))) return { kind: 'stale', intoHead };\n return { kind: 'done', output: { status: 'merged', commit, refUpdate: refUpdate(commit.sha) } };\n}\n"],"mappings":";;;;;;;;;AAuBA,MAAM,mBAAmB,YAA4B;CAEnD,IAAI,MAAM,QAAQ;CAClB,OAAO,MAAM,KAAK,QAAQ,WAAW,MAAM,CAAC,MAAM,IAAI,OAAO;CAC7D,OAAO,GAAG,QAAQ,MAAM,GAAG,GAAG,EAAE;AAClC;;;;;;;;AASA,eAAsB,YAAY,SAAyB,OAAyC;CAClG,MAAM,EAAE,MAAM,MAAM,SAAS;CAC7B,MAAM,WAAW,MAAM,kBAAkB,SAAS,MAAM,IAAI;CAC5D,MAAM,WAAW,MAAM,kBAAkB,SAAS,MAAM,IAAI;CAG5D,MAAM,OAAO,MAAM,IAAI,YAAY,SAAS,IAAI,CAAC,CAAC,UAAU,UAAU,QAAQ;CAC9E,IAAI,SAAS,UACX,OAAO;EAAE,MAAM;EAAQ,QAAQ;GAAE,QAAQ;GAAc,MAAM;EAAS;CAAE;CAE1E,MAAM,aAAa,YAAoB;EAAE,KAAK,UAAU,IAAI;EAAG,QAAQ;EAAU;CAAO;;CAExF,MAAM,OAAO,OAAO,QAAgB,YAAoD;EACtF,MAAM,SAAS,MAAM,cAAc,SAAS,MAAM,UAAU,MAAM,GAAG,OAAO;EAC5E,IAAI,OAAO,WAAW,MAAM,OAAO;EACnC,IAAK,MAAM,WAAW,SAAS,MAAM,IAAI,MAAO,UAC9C,MAAM,mBAAmB,WAAW,UAAU,IAAI,KAAK,OAAO,MAAM;EAEtE,OAAO;CACT;CACA,IAAI,SAAS,UAAU;EACrB,IAAI,CAAE,MAAM,KAAK,UAAU,CAAC,CAAC,GAAI,OAAO;GAAE,MAAM;GAAS;EAAS;EAClE,OAAO;GAAE,MAAM;GAAQ,QAAQ;IAAE,QAAQ;IAAgB,WAAW,UAAU,QAAQ;GAAE;EAAE;CAC5F;CACA,IAAI,SAAS,MACX,MAAM,aAAa,uBAAuB,GAAG,KAAK,OAAO,KAAK,oBAAoB;EAAE;EAAM;CAAK,CAAC;CAElG,MAAM,SAAS,OAAO,SAAkC,MAAM,cAAc,SAAS,MAAM,GAAG,EAAA,CAAG;CACjG,MAAM,SAAS,MAAM,WACnB;EAAE,MAAM,MAAM,OAAO,IAAI;EAAG,MAAM,MAAM,OAAO,QAAQ;EAAG,QAAQ,MAAM,OAAO,QAAQ;CAAE,GACzF,WAAW,SAAS,IAAI,CAC1B;CACA,IAAI,OAAO,WAAW,YACpB,OAAO;EAAE,MAAM;EAAQ,QAAQ;GAAE,QAAQ;GAAY,OAAO,OAAO;GAAO;GAAM;GAAU;EAAS;CAAE;CAGvG,MAAM,YAAY;EAAE,GADH,MAAM,UAAU,QAAQ,OAAO;EACf,MAAM,QAAQ,IAAI,CAAC,CAAC,YAAY;CAAE;CACnE,MAAM,EAAE,QAAQ,WAAW,MAAM,aAAa;EAC5C,MAAM,OAAO;EACb,SAAS,CAAC,UAAU,QAAQ;EAC5B,QAAQ;EACR,WAAW;EACX,SAAS,gBAAgB,MAAM,WAAW,iBAAiB,KAAK,SAAS,MAAM;CACjF,CAAC;CACD,IAAI,CAAE,MAAM,KAAK,OAAO,KAAK,CAAC,GAAG,OAAO,SAAS,MAAM,CAAC,GAAI,OAAO;EAAE,MAAM;EAAS;CAAS;CAC7F,OAAO;EAAE,MAAM;EAAQ,QAAQ;GAAE,QAAQ;GAAU;GAAQ,WAAW,UAAU,OAAO,GAAG;EAAE;CAAE;AAChG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** What a SyncBranchWorkflow instance is started with. */
|
|
3
|
+
declare const SyncBranchWorkflowParams: z.ZodObject<{
|
|
4
|
+
repo: z.ZodString;
|
|
5
|
+
from: z.ZodString;
|
|
6
|
+
into: z.ZodString;
|
|
7
|
+
fromHead: z.ZodString;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
/** SyncBranchWorkflow params, inferred from {@link SyncBranchWorkflowParams}. */
|
|
10
|
+
type SyncBranchWorkflowParams = z.infer<typeof SyncBranchWorkflowParams>;
|
|
11
|
+
/** `into` already contained `from`. */
|
|
12
|
+
declare const SyncStepUpToDate: z.ZodObject<{
|
|
13
|
+
status: z.ZodLiteral<"up_to_date">;
|
|
14
|
+
head: z.ZodString;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
/** `into` was fast-forwarded. */
|
|
17
|
+
declare const SyncStepFastForward: z.ZodObject<{
|
|
18
|
+
status: z.ZodLiteral<"fast_forward">;
|
|
19
|
+
head: z.ZodString;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
/** A merge commit was written. */
|
|
22
|
+
declare const SyncStepMerged: z.ZodObject<{
|
|
23
|
+
status: z.ZodLiteral<"merged">;
|
|
24
|
+
head: z.ZodString;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
/** The branches conflict. */
|
|
27
|
+
declare const SyncStepConflict: z.ZodObject<{
|
|
28
|
+
status: z.ZodLiteral<"conflict">;
|
|
29
|
+
paths: z.ZodArray<z.ZodString>;
|
|
30
|
+
base: z.ZodString;
|
|
31
|
+
fromHead: z.ZodString;
|
|
32
|
+
intoHead: z.ZodString;
|
|
33
|
+
}, z.core.$strict>;
|
|
34
|
+
/**
|
|
35
|
+
* What the SyncBranchWorkflow's sync step stores and the instance returns: ids and paths only,
|
|
36
|
+
* never file content or a credential.
|
|
37
|
+
*/
|
|
38
|
+
declare const SyncStepResult: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
39
|
+
status: z.ZodLiteral<"up_to_date">;
|
|
40
|
+
head: z.ZodString;
|
|
41
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
+
status: z.ZodLiteral<"fast_forward">;
|
|
43
|
+
head: z.ZodString;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
status: z.ZodLiteral<"merged">;
|
|
46
|
+
head: z.ZodString;
|
|
47
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
48
|
+
status: z.ZodLiteral<"conflict">;
|
|
49
|
+
paths: z.ZodArray<z.ZodString>;
|
|
50
|
+
base: z.ZodString;
|
|
51
|
+
fromHead: z.ZodString;
|
|
52
|
+
intoHead: z.ZodString;
|
|
53
|
+
}, z.core.$strict>], "status">;
|
|
54
|
+
/** A SyncBranchWorkflow result, inferred from {@link SyncStepResult}. */
|
|
55
|
+
type SyncStepResult = z.infer<typeof SyncStepResult>;
|
|
56
|
+
export { SyncStepResult as a, SyncStepMerged as i, SyncStepConflict as n, SyncStepUpToDate as o, SyncStepFastForward as r, SyncBranchWorkflowParams as t };
|
|
57
|
+
//# sourceMappingURL=sync-workflow-schemas-DCNmNE5-.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as GitRequest } from "./git-route-Spxi09Rm.js";
|
|
2
|
+
import { GitRemote } from "@leed-ai/git-gateway-contract/storage/git-remote";
|
|
3
|
+
/** Sends one HTTP request: `fetch`, or a stand-in such as an in-memory backend's handler. */
|
|
4
|
+
type UpstreamFetch = (request: Request) => Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* The request to send to the storage host for a client request: the host's URL for the same
|
|
7
|
+
* endpoint, the credential headers minted for this request, and only the client headers the git
|
|
8
|
+
* protocol needs (Content-Type, Accept, Git-Protocol, User-Agent, and Content-Encoding for a
|
|
9
|
+
* fetch). The client's Authorization, cookies and anything else never leave the gateway.
|
|
10
|
+
*/
|
|
11
|
+
declare function upstreamRequest(request: Request, git: GitRequest, remote: GitRemote, body: ReadableStream<Uint8Array> | null): Request;
|
|
12
|
+
/** The response headers to give the client for a storage host response. */
|
|
13
|
+
declare function clientHeaders(upstream: Response, requestId: string): Headers;
|
|
14
|
+
export { clientHeaders as n, upstreamRequest as r, UpstreamFetch as t };
|
|
15
|
+
//# sourceMappingURL=upstream-DvqMCj5N.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of a Workflows instance handle (`WorkflowInstance`) the gateway uses: read its status,
|
|
3
|
+
* or run it again from the start with the params it was created with.
|
|
4
|
+
*/
|
|
5
|
+
interface WorkflowHandle {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** The instance's current status; `status` is one of the Workflows instance states. */
|
|
8
|
+
status(): Promise<{
|
|
9
|
+
readonly status: string;
|
|
10
|
+
}>;
|
|
11
|
+
/** Runs the instance again from its first step, with the params it was created with. */
|
|
12
|
+
restart(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The part of a Workflows binding (`env.COMMIT_WORKFLOW`) the gateway uses: start an instance
|
|
16
|
+
* under a chosen id, or look one up. A real `Workflow<P>` binding satisfies it; tests pass a fake.
|
|
17
|
+
*/
|
|
18
|
+
interface WorkflowStarter<P> {
|
|
19
|
+
/** Starts an instance with this id and params; rejects when the id is already taken. */
|
|
20
|
+
create(options: {
|
|
21
|
+
id: string;
|
|
22
|
+
params: P;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
readonly id: string;
|
|
25
|
+
}>;
|
|
26
|
+
/** The instance with this id; rejects when there is none. */
|
|
27
|
+
get(id: string): Promise<WorkflowHandle>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What {@link startWorkflowOnce} did: started a new instance, found a live or finished one
|
|
31
|
+
* already under the id, or found a dead one (errored or terminated) and restarted it.
|
|
32
|
+
*/
|
|
33
|
+
type WorkflowStart = 'created' | 'existing' | 'restarted';
|
|
34
|
+
/**
|
|
35
|
+
* Starts a Workflow instance under a deterministic id, at most once while it lives: when the id
|
|
36
|
+
* is already taken by a queued, running, waiting, paused or complete instance (the same write was
|
|
37
|
+
* handed off before), that instance stands and nothing new starts. When the instance under the id
|
|
38
|
+
* is dead — errored after its retries ran out, or terminated — it is restarted, so retrying the
|
|
39
|
+
* same write is never answered by an instance that will not run. Restarting is safe because the
|
|
40
|
+
* workflows' steps are idempotent. Throws storage_unavailable when the instance can be neither
|
|
41
|
+
* created nor found, or when its status cannot be read or it cannot be restarted.
|
|
42
|
+
*/
|
|
43
|
+
declare function startWorkflowOnce<P>(starter: WorkflowStarter<P>, id: string, params: P): Promise<WorkflowStart>;
|
|
44
|
+
export { startWorkflowOnce as i, WorkflowStart as n, WorkflowStarter as r, WorkflowHandle as t };
|
|
45
|
+
//# sourceMappingURL=workflow-starter-BqhwX6oA.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as CommitWorkflowParams, i as CommitStepResult, n as CommitStepNoop, r as CommitStepReplayed, t as CommitStepCommitted } from "../commit-workflow-schemas-BWlg7bZR.js";
|
|
2
|
+
export { CommitStepCommitted, CommitStepNoop, CommitStepReplayed, CommitStepResult, CommitWorkflowParams };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Sha } from "@leed-ai/git-gateway-contract/schemas/sha";
|
|
2
|
+
import { EXAMPLE_IDENTITY, EXAMPLE_SHA_A, EXAMPLE_SHA_B } from "@leed-ai/git-gateway-contract/schemas/examples";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { CommitInput } from "@leed-ai/git-gateway-contract/rpc/commit";
|
|
5
|
+
// src/workflows/commit-workflow-schemas.ts
|
|
6
|
+
/** What a CommitWorkflow instance is started with: the commit() input, unchanged. */
|
|
7
|
+
const CommitWorkflowParams = CommitInput.meta({
|
|
8
|
+
id: "CommitWorkflowParams",
|
|
9
|
+
title: "CommitWorkflow params",
|
|
10
|
+
description: "The params a CommitWorkflow instance is started with: exactly the commit() input whose inline retries ran out, idempotency key included, so the workflow writes the same commit at most once. Params may carry file content; step results never do.",
|
|
11
|
+
examples: [{
|
|
12
|
+
repo: "acme-raw-content",
|
|
13
|
+
branch: "staging",
|
|
14
|
+
message: "Update about page",
|
|
15
|
+
author: EXAMPLE_IDENTITY,
|
|
16
|
+
actions: [{
|
|
17
|
+
action: "update",
|
|
18
|
+
path: "content/about.md",
|
|
19
|
+
content: "# About us\n",
|
|
20
|
+
encoding: "text"
|
|
21
|
+
}],
|
|
22
|
+
idempotencyKey: "cms:publish:2f9c1e"
|
|
23
|
+
}]
|
|
24
|
+
});
|
|
25
|
+
/** The workflow wrote the commit. */
|
|
26
|
+
const CommitStepCommitted = z.object({
|
|
27
|
+
status: z.literal("committed").describe("The workflow wrote a new commit and moved the branch to it."),
|
|
28
|
+
sha: Sha.describe("Id of the commit written.")
|
|
29
|
+
}).strict().meta({
|
|
30
|
+
id: "CommitStepCommitted",
|
|
31
|
+
title: "commit step: committed",
|
|
32
|
+
description: "The CommitWorkflow's commit step wrote the commit. Carries the commit id only.",
|
|
33
|
+
examples: [{
|
|
34
|
+
status: "committed",
|
|
35
|
+
sha: EXAMPLE_SHA_B
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
/** A commit with the same idempotency key was already on the branch. */
|
|
39
|
+
const CommitStepReplayed = z.object({
|
|
40
|
+
status: z.literal("replayed").describe("A commit carrying the same idempotency key was already in the branch history (an earlier attempt, or a step that ran before a crash); nothing was written."),
|
|
41
|
+
sha: Sha.describe("Id of the earlier commit carrying the key.")
|
|
42
|
+
}).strict().meta({
|
|
43
|
+
id: "CommitStepReplayed",
|
|
44
|
+
title: "commit step: replayed",
|
|
45
|
+
description: "The CommitWorkflow's commit step found the commit already written, so a replayed step never commits twice.",
|
|
46
|
+
examples: [{
|
|
47
|
+
status: "replayed",
|
|
48
|
+
sha: EXAMPLE_SHA_B
|
|
49
|
+
}]
|
|
50
|
+
});
|
|
51
|
+
/** The actions changed nothing. */
|
|
52
|
+
const CommitStepNoop = z.object({
|
|
53
|
+
status: z.literal("noop").describe("The actions left the tree unchanged; nothing was written."),
|
|
54
|
+
head: Sha.nullable().describe("The branch head, unchanged; null when the branch does not exist.")
|
|
55
|
+
}).strict().meta({
|
|
56
|
+
id: "CommitStepNoop",
|
|
57
|
+
title: "commit step: no-op",
|
|
58
|
+
description: "The CommitWorkflow's commit step applied the actions to the head and nothing changed.",
|
|
59
|
+
examples: [{
|
|
60
|
+
status: "noop",
|
|
61
|
+
head: EXAMPLE_SHA_A
|
|
62
|
+
}]
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* What the CommitWorkflow's commit step stores and the instance returns. Ids and a status only:
|
|
66
|
+
* never file content, a message or a credential, because step results are persisted by the
|
|
67
|
+
* Workflows engine and shown in its dashboard.
|
|
68
|
+
*/
|
|
69
|
+
const CommitStepResult = z.discriminatedUnion("status", [
|
|
70
|
+
CommitStepCommitted,
|
|
71
|
+
CommitStepReplayed,
|
|
72
|
+
CommitStepNoop
|
|
73
|
+
]).meta({
|
|
74
|
+
id: "CommitStepResult",
|
|
75
|
+
title: "CommitWorkflow result",
|
|
76
|
+
description: "What the CommitWorkflow's commit step stores and the instance returns, discriminated by `status`: commit ids only, never file content or a credential.",
|
|
77
|
+
examples: [{
|
|
78
|
+
status: "committed",
|
|
79
|
+
sha: EXAMPLE_SHA_B
|
|
80
|
+
}]
|
|
81
|
+
});
|
|
82
|
+
export { CommitStepCommitted, CommitStepNoop, CommitStepReplayed, CommitStepResult, CommitWorkflowParams };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=commit-workflow-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-workflow-schemas.js","names":[],"sources":["../../src/workflows/commit-workflow-schemas.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { CommitInput } from '@leed-ai/git-gateway-contract/rpc/commit';\nimport {\n EXAMPLE_IDENTITY,\n EXAMPLE_SHA_A,\n EXAMPLE_SHA_B,\n} from '@leed-ai/git-gateway-contract/schemas/examples';\nimport { Sha } from '@leed-ai/git-gateway-contract/schemas/sha';\nimport { z } from 'zod';\n\n/** What a CommitWorkflow instance is started with: the commit() input, unchanged. */\nexport const CommitWorkflowParams = CommitInput.meta({\n id: 'CommitWorkflowParams',\n title: 'CommitWorkflow params',\n description:\n 'The params a CommitWorkflow instance is started with: exactly the commit() input whose inline retries ran out, idempotency key included, so the workflow writes the same commit at most once. Params may carry file content; step results never do.',\n examples: [\n {\n repo: 'acme-raw-content',\n branch: 'staging',\n message: 'Update about page',\n author: EXAMPLE_IDENTITY,\n actions: [{ action: 'update', path: 'content/about.md', content: '# About us\\n', encoding: 'text' }],\n idempotencyKey: 'cms:publish:2f9c1e',\n },\n ],\n});\n\n/** CommitWorkflow params after parsing (defaults applied). */\nexport type CommitWorkflowParams = z.output<typeof CommitWorkflowParams>;\n\n/** The workflow wrote the commit. */\nexport const CommitStepCommitted = z\n .object({\n status: z.literal('committed').describe('The workflow wrote a new commit and moved the branch to it.'),\n sha: Sha.describe('Id of the commit written.'),\n })\n .strict()\n .meta({\n id: 'CommitStepCommitted',\n title: 'commit step: committed',\n description: \"The CommitWorkflow's commit step wrote the commit. Carries the commit id only.\",\n examples: [{ status: 'committed', sha: EXAMPLE_SHA_B }],\n });\n\n/** A commit with the same idempotency key was already on the branch. */\nexport const CommitStepReplayed = z\n .object({\n status: z\n .literal('replayed')\n .describe(\n 'A commit carrying the same idempotency key was already in the branch history (an earlier attempt, or a step that ran before a crash); nothing was written.',\n ),\n sha: Sha.describe('Id of the earlier commit carrying the key.'),\n })\n .strict()\n .meta({\n id: 'CommitStepReplayed',\n title: 'commit step: replayed',\n description:\n \"The CommitWorkflow's commit step found the commit already written, so a replayed step never commits twice.\",\n examples: [{ status: 'replayed', sha: EXAMPLE_SHA_B }],\n });\n\n/** The actions changed nothing. */\nexport const CommitStepNoop = z\n .object({\n status: z.literal('noop').describe('The actions left the tree unchanged; nothing was written.'),\n head: Sha.nullable().describe('The branch head, unchanged; null when the branch does not exist.'),\n })\n .strict()\n .meta({\n id: 'CommitStepNoop',\n title: 'commit step: no-op',\n description: \"The CommitWorkflow's commit step applied the actions to the head and nothing changed.\",\n examples: [{ status: 'noop', head: EXAMPLE_SHA_A }],\n });\n\n/**\n * What the CommitWorkflow's commit step stores and the instance returns. Ids and a status only:\n * never file content, a message or a credential, because step results are persisted by the\n * Workflows engine and shown in its dashboard.\n */\nexport const CommitStepResult = z\n .discriminatedUnion('status', [CommitStepCommitted, CommitStepReplayed, CommitStepNoop])\n .meta({\n id: 'CommitStepResult',\n title: 'CommitWorkflow result',\n description:\n \"What the CommitWorkflow's commit step stores and the instance returns, discriminated by `status`: commit ids only, never file content or a credential.\",\n examples: [{ status: 'committed', sha: EXAMPLE_SHA_B }],\n });\n\n/** A CommitWorkflow result, inferred from {@link CommitStepResult}. */\nexport type CommitStepResult = z.infer<typeof CommitStepResult>;\n"],"mappings":";;;;;;AAWA,MAAa,uBAAuB,YAAY,KAAK;CACnD,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,MAAM;EACN,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,SAAS,CAAC;GAAE,QAAQ;GAAU,MAAM;GAAoB,SAAS;GAAgB,UAAU;EAAO,CAAC;EACnG,gBAAgB;CAClB,CACF;AACF,CAAC;;AAMD,MAAa,sBAAsB,EAChC,OAAO;CACN,QAAQ,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,6DAA6D;CACrG,KAAK,IAAI,SAAS,2BAA2B;AAC/C,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAa,KAAK;CAAc,CAAC;AACxD,CAAC;;AAGH,MAAa,qBAAqB,EAC/B,OAAO;CACN,QAAQ,EACL,QAAQ,UAAU,CAAC,CACnB,SACC,4JACF;CACF,KAAK,IAAI,SAAS,4CAA4C;AAChE,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAY,KAAK;CAAc,CAAC;AACvD,CAAC;;AAGH,MAAa,iBAAiB,EAC3B,OAAO;CACN,QAAQ,EAAE,QAAQ,MAAM,CAAC,CAAC,SAAS,2DAA2D;CAC9F,MAAM,IAAI,SAAS,CAAC,CAAC,SAAS,kEAAkE;AAClG,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAQ,MAAM;CAAc,CAAC;AACpD,CAAC;;;;;;AAOH,MAAa,mBAAmB,EAC7B,mBAAmB,UAAU;CAAC;CAAqB;CAAoB;AAAc,CAAC,CAAC,CACvF,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAa,KAAK;CAAc,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GatewayOptionsResolver } from "../rpc/gateway-service.js";
|
|
2
|
+
import { a as CommitWorkflowParams, i as CommitStepResult } from "../commit-workflow-schemas-BWlg7bZR.js";
|
|
3
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers";
|
|
4
|
+
/** The CommitWorkflow class {@link createCommitWorkflow} returns. */
|
|
5
|
+
export type CommitWorkflowClass<Env> = new (ctx: ExecutionContext, env: Env) => WorkflowEntrypoint<Env, CommitWorkflowParams> & {
|
|
6
|
+
run(event: Readonly<WorkflowEvent<CommitWorkflowParams>>, step: WorkflowStep): Promise<CommitStepResult>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The CommitWorkflow a deployment exports and binds (as the `commitWorkflow` of its options), to
|
|
10
|
+
* finish commits whose inline retries ran out. Built from the same options resolver as the RPC
|
|
11
|
+
* entrypoint, so both write through the same backend and configuration:
|
|
12
|
+
*
|
|
13
|
+
* export const CommitWorkflow = createCommitWorkflow(gatewayOptions);
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCommitWorkflow<Env>(resolve: GatewayOptionsResolver<Env>): CommitWorkflowClass<Env>;
|
|
16
|
+
//# sourceMappingURL=commit-workflow.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { gatewayContext } from "../rpc/gateway-context.js";
|
|
2
|
+
import { runCommitWorkflow } from "./run-commit-workflow.js";
|
|
3
|
+
import { nonRetryable, stepRunnerOf } from "./workflow-runtime.js";
|
|
4
|
+
import { WorkflowEntrypoint } from "cloudflare:workers";
|
|
5
|
+
// src/workflows/commit-workflow.ts
|
|
6
|
+
/**
|
|
7
|
+
* The CommitWorkflow a deployment exports and binds (as the `commitWorkflow` of its options), to
|
|
8
|
+
* finish commits whose inline retries ran out. Built from the same options resolver as the RPC
|
|
9
|
+
* entrypoint, so both write through the same backend and configuration:
|
|
10
|
+
*
|
|
11
|
+
* export const CommitWorkflow = createCommitWorkflow(gatewayOptions);
|
|
12
|
+
*/
|
|
13
|
+
function createCommitWorkflow(resolve) {
|
|
14
|
+
return class CommitWorkflow extends WorkflowEntrypoint {
|
|
15
|
+
run(event, step) {
|
|
16
|
+
return runCommitWorkflow(gatewayContext(resolve(this.env)), event.payload, stepRunnerOf(step), nonRetryable);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export { createCommitWorkflow };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=commit-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-workflow.js","names":[],"sources":["../../src/workflows/commit-workflow.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from 'cloudflare:workers';\n\nimport { gatewayContext } from '../rpc/gateway-context.ts';\nimport type { GatewayOptionsResolver } from '../rpc/gateway-service.ts';\nimport type { CommitStepResult, CommitWorkflowParams } from './commit-workflow-schemas.ts';\nimport { runCommitWorkflow } from './run-commit-workflow.ts';\nimport { nonRetryable, stepRunnerOf } from './workflow-runtime.ts';\n\n/** The CommitWorkflow class {@link createCommitWorkflow} returns. */\nexport type CommitWorkflowClass<Env> = new (\n ctx: ExecutionContext,\n env: Env,\n) => WorkflowEntrypoint<Env, CommitWorkflowParams> & {\n run(event: Readonly<WorkflowEvent<CommitWorkflowParams>>, step: WorkflowStep): Promise<CommitStepResult>;\n};\n\n/**\n * The CommitWorkflow a deployment exports and binds (as the `commitWorkflow` of its options), to\n * finish commits whose inline retries ran out. Built from the same options resolver as the RPC\n * entrypoint, so both write through the same backend and configuration:\n *\n * export const CommitWorkflow = createCommitWorkflow(gatewayOptions);\n */\nexport function createCommitWorkflow<Env>(resolve: GatewayOptionsResolver<Env>): CommitWorkflowClass<Env> {\n return class CommitWorkflow extends WorkflowEntrypoint<Env, CommitWorkflowParams> {\n override run(\n event: Readonly<WorkflowEvent<CommitWorkflowParams>>,\n step: WorkflowStep,\n ): Promise<CommitStepResult> {\n return runCommitWorkflow(\n gatewayContext(resolve(this.env)),\n event.payload,\n stepRunnerOf(step),\n nonRetryable,\n );\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAgB,qBAA0B,SAAgE;CACxG,OAAO,MAAM,uBAAuB,mBAA8C;EAChF,IACE,OACA,MAC2B;GAC3B,OAAO,kBACL,eAAe,QAAQ,KAAK,GAAG,CAAC,GAChC,MAAM,SACN,aAAa,IAAI,GACjB,YACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as composeOnPush, c as syncRuleHook, i as PushEventMessage, n as OnPushOptions, o as consumePushEvents, r as PushBatchOutcome, s as dispatchPushEvent, t as OnPushHook } from "../on-push-DTREOB__.js";
|
|
2
|
+
export { OnPushHook, OnPushOptions, PushBatchOutcome, PushEventMessage, composeOnPush, consumePushEvents, dispatchPushEvent, syncRuleHook };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PushEvent } from "./push-event.js";
|
|
2
|
+
import { syncWorkflowId } from "./workflow-instance-id.js";
|
|
3
|
+
import { startWorkflowOnce } from "./workflow-starter.js";
|
|
4
|
+
import { ZERO_SHA } from "@leed-ai/git-gateway-contract/schemas/sha";
|
|
5
|
+
import { invalidInput } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
6
|
+
// src/workflows/on-push.ts
|
|
7
|
+
/**
|
|
8
|
+
* The onPush hook for the configured sync rules: for every rule whose `from` branch the push
|
|
9
|
+
* moved (not deleted), start a SyncBranchWorkflow syncing `into` from it. The instance id is
|
|
10
|
+
* derived from repository, both branches and the new head, so a redelivered event starts nothing
|
|
11
|
+
* new.
|
|
12
|
+
*/
|
|
13
|
+
function syncRuleHook(syncRules, syncWorkflow) {
|
|
14
|
+
return async (event) => {
|
|
15
|
+
for (const rule of syncRules) {
|
|
16
|
+
const update = event.updates.findLast((candidate) => candidate.ref === `refs/heads/${rule.from}` && candidate.newSha !== ZERO_SHA);
|
|
17
|
+
if (update === void 0) continue;
|
|
18
|
+
const params = {
|
|
19
|
+
repo: event.repo,
|
|
20
|
+
from: rule.from,
|
|
21
|
+
into: rule.into,
|
|
22
|
+
fromHead: update.newSha
|
|
23
|
+
};
|
|
24
|
+
const id = await syncWorkflowId(event.repo, rule.from, rule.into, update.newSha);
|
|
25
|
+
await startWorkflowOnce(syncWorkflow, id, params);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Delivers one push event to every hook. The event is parsed with {@link PushEvent} first
|
|
31
|
+
* (invalid_input when it does not match). Every hook runs even when another fails; if any failed,
|
|
32
|
+
* an AggregateError of their errors is thrown afterwards. Hooks must therefore be idempotent, as
|
|
33
|
+
* {@link syncRuleHook} is.
|
|
34
|
+
*/
|
|
35
|
+
async function dispatchPushEvent(event, hooks) {
|
|
36
|
+
const parsed = PushEvent.safeParse(event);
|
|
37
|
+
if (!parsed.success) throw invalidInput(parsed.error);
|
|
38
|
+
const failures = (await Promise.allSettled(hooks.map((hook) => hook(parsed.data)))).flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
39
|
+
if (failures.length > 0) throw new AggregateError(failures, `${failures.length} onPush hook(s) failed`);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The one onPush hook a gateway runs after every accepted push: {@link syncRuleHook} for the
|
|
43
|
+
* configured sync rules and the deployment's own hook, each run even when the other fails (see
|
|
44
|
+
* {@link dispatchPushEvent}); a lone hook is returned as it is. Undefined when there is nothing
|
|
45
|
+
* to run. Throws a TypeError when sync rules are configured without a SyncBranchWorkflow binding,
|
|
46
|
+
* which would leave them dead.
|
|
47
|
+
*/
|
|
48
|
+
function composeOnPush(options) {
|
|
49
|
+
const hooks = [];
|
|
50
|
+
if (options.syncRules.length > 0) {
|
|
51
|
+
if (options.syncWorkflow === void 0) throw new TypeError("GatewayConfig.syncRules are set but no SyncBranchWorkflow binding (syncWorkflow) was given to start them");
|
|
52
|
+
hooks.push(syncRuleHook(options.syncRules, options.syncWorkflow));
|
|
53
|
+
}
|
|
54
|
+
if (options.onPush !== void 0) hooks.push(options.onPush);
|
|
55
|
+
if (hooks.length <= 1) return hooks[0];
|
|
56
|
+
return async (event) => dispatchPushEvent(event, hooks);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A Queues consumer for push events: each message is dispatched to the hooks, then acknowledged,
|
|
60
|
+
* or retried when a hook failed. Messages that do not parse as a {@link PushEvent} are
|
|
61
|
+
* acknowledged and counted as dropped.
|
|
62
|
+
*/
|
|
63
|
+
async function consumePushEvents(batch, hooks) {
|
|
64
|
+
let delivered = 0;
|
|
65
|
+
let dropped = 0;
|
|
66
|
+
let retried = 0;
|
|
67
|
+
for (const message of batch.messages) {
|
|
68
|
+
if (!PushEvent.safeParse(message.body).success) {
|
|
69
|
+
message.ack();
|
|
70
|
+
dropped += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await dispatchPushEvent(message.body, hooks);
|
|
75
|
+
message.ack();
|
|
76
|
+
delivered += 1;
|
|
77
|
+
} catch {
|
|
78
|
+
message.retry();
|
|
79
|
+
retried += 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
delivered,
|
|
84
|
+
dropped,
|
|
85
|
+
retried
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export { composeOnPush, consumePushEvents, dispatchPushEvent, syncRuleHook };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=on-push.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-push.js","names":[],"sources":["../../src/workflows/on-push.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { invalidInput } from '@leed-ai/git-gateway-contract/gateway-error';\nimport type { SyncRule } from '@leed-ai/git-gateway-contract/schemas/gateway-config';\nimport { ZERO_SHA } from '@leed-ai/git-gateway-contract/schemas/sha';\n\nimport { PushEvent } from './push-event.ts';\nimport type { SyncBranchWorkflowParams } from './sync-workflow-schemas.ts';\nimport { syncWorkflowId } from './workflow-instance-id.ts';\nimport { startWorkflowOnce, type WorkflowStarter } from './workflow-starter.ts';\n\n/** Something a deployment runs after every accepted push. Rejecting asks for the event again. */\nexport type OnPushHook = (event: PushEvent) => Promise<void>;\n\n/**\n * The onPush hook for the configured sync rules: for every rule whose `from` branch the push\n * moved (not deleted), start a SyncBranchWorkflow syncing `into` from it. The instance id is\n * derived from repository, both branches and the new head, so a redelivered event starts nothing\n * new.\n */\nexport function syncRuleHook(\n syncRules: readonly SyncRule[],\n syncWorkflow: WorkflowStarter<SyncBranchWorkflowParams>,\n): OnPushHook {\n return async (event) => {\n for (const rule of syncRules) {\n const update = event.updates.findLast(\n (candidate) => candidate.ref === `refs/heads/${rule.from}` && candidate.newSha !== ZERO_SHA,\n );\n if (update === undefined) continue;\n const params = { repo: event.repo, from: rule.from, into: rule.into, fromHead: update.newSha };\n const id = await syncWorkflowId(event.repo, rule.from, rule.into, update.newSha);\n await startWorkflowOnce(syncWorkflow, id, params);\n }\n };\n}\n\n/**\n * Delivers one push event to every hook. The event is parsed with {@link PushEvent} first\n * (invalid_input when it does not match). Every hook runs even when another fails; if any failed,\n * an AggregateError of their errors is thrown afterwards. Hooks must therefore be idempotent, as\n * {@link syncRuleHook} is.\n */\nexport async function dispatchPushEvent(event: unknown, hooks: readonly OnPushHook[]): Promise<void> {\n const parsed = PushEvent.safeParse(event);\n if (!parsed.success) throw invalidInput(parsed.error);\n const results = await Promise.allSettled(hooks.map((hook) => hook(parsed.data)));\n const failures = results.flatMap((result) => (result.status === 'rejected' ? [result.reason] : []));\n if (failures.length > 0) throw new AggregateError(failures, `${failures.length} onPush hook(s) failed`);\n}\n\n/** What {@link composeOnPush} builds the deployment's onPush hook from. */\nexport interface OnPushOptions {\n /** The configured sync rules (GatewayConfig.syncRules). */\n readonly syncRules: readonly SyncRule[];\n /** The SyncBranchWorkflow binding the sync rules start instances of; required when there are rules. */\n readonly syncWorkflow?: WorkflowStarter<SyncBranchWorkflowParams> | undefined;\n /** The deployment's own hook, run beside the sync rules. */\n readonly onPush?: OnPushHook | undefined;\n}\n\n/**\n * The one onPush hook a gateway runs after every accepted push: {@link syncRuleHook} for the\n * configured sync rules and the deployment's own hook, each run even when the other fails (see\n * {@link dispatchPushEvent}); a lone hook is returned as it is. Undefined when there is nothing\n * to run. Throws a TypeError when sync rules are configured without a SyncBranchWorkflow binding,\n * which would leave them dead.\n */\nexport function composeOnPush(options: OnPushOptions): OnPushHook | undefined {\n const hooks: OnPushHook[] = [];\n if (options.syncRules.length > 0) {\n if (options.syncWorkflow === undefined) {\n throw new TypeError(\n 'GatewayConfig.syncRules are set but no SyncBranchWorkflow binding (syncWorkflow) was given to start them',\n );\n }\n hooks.push(syncRuleHook(options.syncRules, options.syncWorkflow));\n }\n if (options.onPush !== undefined) hooks.push(options.onPush);\n if (hooks.length <= 1) return hooks[0];\n return async (event) => dispatchPushEvent(event, hooks);\n}\n\n/** The part of a Queues message the consumer uses. */\nexport interface PushEventMessage {\n readonly body: unknown;\n ack(): void;\n retry(): void;\n}\n\n/** What {@link consumePushEvents} did with a batch. */\nexport interface PushBatchOutcome {\n /** Events every hook handled. */\n readonly delivered: number;\n /** Messages that are not push events; acknowledged, since redelivery cannot fix them. */\n readonly dropped: number;\n /** Events some hook failed on; handed back to the queue for redelivery. */\n readonly retried: number;\n}\n\n/**\n * A Queues consumer for push events: each message is dispatched to the hooks, then acknowledged,\n * or retried when a hook failed. Messages that do not parse as a {@link PushEvent} are\n * acknowledged and counted as dropped.\n */\nexport async function consumePushEvents(\n batch: { readonly messages: readonly PushEventMessage[] },\n hooks: readonly OnPushHook[],\n): Promise<PushBatchOutcome> {\n let delivered = 0;\n let dropped = 0;\n let retried = 0;\n for (const message of batch.messages) {\n if (!PushEvent.safeParse(message.body).success) {\n message.ack();\n dropped += 1;\n continue;\n }\n try {\n await dispatchPushEvent(message.body, hooks);\n message.ack();\n delivered += 1;\n } catch {\n message.retry();\n retried += 1;\n }\n }\n return { delivered, dropped, retried };\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,aACd,WACA,cACY;CACZ,OAAO,OAAO,UAAU;EACtB,KAAK,MAAM,QAAQ,WAAW;GAC5B,MAAM,SAAS,MAAM,QAAQ,UAC1B,cAAc,UAAU,QAAQ,cAAc,KAAK,UAAU,UAAU,WAAW,QACrF;GACA,IAAI,WAAW,KAAA,GAAW;GAC1B,MAAM,SAAS;IAAE,MAAM,MAAM;IAAM,MAAM,KAAK;IAAM,MAAM,KAAK;IAAM,UAAU,OAAO;GAAO;GAC7F,MAAM,KAAK,MAAM,eAAe,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,OAAO,MAAM;GAC/E,MAAM,kBAAkB,cAAc,IAAI,MAAM;EAClD;CACF;AACF;;;;;;;AAQA,eAAsB,kBAAkB,OAAgB,OAA6C;CACnG,MAAM,SAAS,UAAU,UAAU,KAAK;CACxC,IAAI,CAAC,OAAO,SAAS,MAAM,aAAa,OAAO,KAAK;CAEpD,MAAM,YAAW,MADK,QAAQ,WAAW,MAAM,KAAK,SAAS,KAAK,OAAO,IAAI,CAAC,CAAC,EAAA,CACtD,SAAS,WAAY,OAAO,WAAW,aAAa,CAAC,OAAO,MAAM,IAAI,CAAC,CAAE;CAClG,IAAI,SAAS,SAAS,GAAG,MAAM,IAAI,eAAe,UAAU,GAAG,SAAS,OAAO,uBAAuB;AACxG;;;;;;;;AAmBA,SAAgB,cAAc,SAAgD;CAC5E,MAAM,QAAsB,CAAC;CAC7B,IAAI,QAAQ,UAAU,SAAS,GAAG;EAChC,IAAI,QAAQ,iBAAiB,KAAA,GAC3B,MAAM,IAAI,UACR,0GACF;EAEF,MAAM,KAAK,aAAa,QAAQ,WAAW,QAAQ,YAAY,CAAC;CAClE;CACA,IAAI,QAAQ,WAAW,KAAA,GAAW,MAAM,KAAK,QAAQ,MAAM;CAC3D,IAAI,MAAM,UAAU,GAAG,OAAO,MAAM;CACpC,OAAO,OAAO,UAAU,kBAAkB,OAAO,KAAK;AACxD;;;;;;AAwBA,eAAsB,kBACpB,OACA,OAC2B;CAC3B,IAAI,YAAY;CAChB,IAAI,UAAU;CACd,IAAI,UAAU;CACd,KAAK,MAAM,WAAW,MAAM,UAAU;EACpC,IAAI,CAAC,UAAU,UAAU,QAAQ,IAAI,CAAC,CAAC,SAAS;GAC9C,QAAQ,IAAI;GACZ,WAAW;GACX;EACF;EACA,IAAI;GACF,MAAM,kBAAkB,QAAQ,MAAM,KAAK;GAC3C,QAAQ,IAAI;GACZ,aAAa;EACf,QAAQ;GACN,QAAQ,MAAM;GACd,WAAW;EACb;CACF;CACA,OAAO;EAAE;EAAW;EAAS;CAAQ;AACvC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RefUpdate } from "@leed-ai/git-gateway-contract/schemas/ref-update";
|
|
2
|
+
import { RepoName } from "@leed-ai/git-gateway-contract/schemas/names";
|
|
3
|
+
import { EXAMPLE_SHA_A, EXAMPLE_SHA_B, EXAMPLE_TIMESTAMP } from "@leed-ai/git-gateway-contract/schemas/examples";
|
|
4
|
+
import { Timestamp } from "@leed-ai/git-gateway-contract/schemas/identity";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/workflows/push-event.ts
|
|
7
|
+
/** A push the gateway accepted, as onPush hooks receive it. */
|
|
8
|
+
const PushEvent = z.object({
|
|
9
|
+
repo: RepoName.describe("Repository that was pushed to."),
|
|
10
|
+
updates: z.array(RefUpdate).min(1).max(1e3).describe("Every ref the push moved, in the order the push named them; 1–1000. A created ref has an all-zero oldSha, a deleted ref an all-zero newSha."),
|
|
11
|
+
pushedAt: Timestamp.describe("When the storage host accepted the push.")
|
|
12
|
+
}).strict().meta({
|
|
13
|
+
id: "PushEvent",
|
|
14
|
+
title: "Push event",
|
|
15
|
+
description: "A push the gateway accepted (through the smart-HTTP proxy or an RPC write), delivered to onPush hooks directly or through a Queue. Carries ref ids only: no content, no credential, no principal secret.",
|
|
16
|
+
examples: [{
|
|
17
|
+
repo: "acme-raw-content",
|
|
18
|
+
updates: [{
|
|
19
|
+
ref: "refs/heads/main",
|
|
20
|
+
oldSha: EXAMPLE_SHA_A,
|
|
21
|
+
newSha: EXAMPLE_SHA_B
|
|
22
|
+
}],
|
|
23
|
+
pushedAt: EXAMPLE_TIMESTAMP
|
|
24
|
+
}]
|
|
25
|
+
});
|
|
26
|
+
export { PushEvent };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=push-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-event.js","names":[],"sources":["../../src/workflows/push-event.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport {\n EXAMPLE_SHA_A,\n EXAMPLE_SHA_B,\n EXAMPLE_TIMESTAMP,\n} from '@leed-ai/git-gateway-contract/schemas/examples';\nimport { Timestamp } from '@leed-ai/git-gateway-contract/schemas/identity';\nimport { RepoName } from '@leed-ai/git-gateway-contract/schemas/names';\nimport { RefUpdate } from '@leed-ai/git-gateway-contract/schemas/ref-update';\nimport { z } from 'zod';\n\n/** A push the gateway accepted, as onPush hooks receive it. */\nexport const PushEvent = z\n .object({\n repo: RepoName.describe('Repository that was pushed to.'),\n updates: z\n .array(RefUpdate)\n .min(1)\n .max(1000)\n .describe(\n 'Every ref the push moved, in the order the push named them; 1–1000. A created ref has an all-zero oldSha, a deleted ref an all-zero newSha.',\n ),\n pushedAt: Timestamp.describe('When the storage host accepted the push.'),\n })\n .strict()\n .meta({\n id: 'PushEvent',\n title: 'Push event',\n description:\n 'A push the gateway accepted (through the smart-HTTP proxy or an RPC write), delivered to onPush hooks directly or through a Queue. Carries ref ids only: no content, no credential, no principal secret.',\n examples: [\n {\n repo: 'acme-raw-content',\n updates: [{ ref: 'refs/heads/main', oldSha: EXAMPLE_SHA_A, newSha: EXAMPLE_SHA_B }],\n pushedAt: EXAMPLE_TIMESTAMP,\n },\n ],\n });\n\n/** A push event, inferred from {@link PushEvent}. */\nexport type PushEvent = z.infer<typeof PushEvent>;\n"],"mappings":";;;;;;;AAYA,MAAa,YAAY,EACtB,OAAO;CACN,MAAM,SAAS,SAAS,gCAAgC;CACxD,SAAS,EACN,MAAM,SAAS,CAAC,CAChB,IAAI,CAAC,CAAC,CACN,IAAI,GAAI,CAAC,CACT,SACC,6IACF;CACF,UAAU,UAAU,SAAS,0CAA0C;AACzE,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,MAAM;EACN,SAAS,CAAC;GAAE,KAAK;GAAmB,QAAQ;GAAe,QAAQ;EAAc,CAAC;EAClF,UAAU;CACZ,CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { i as CommitStepResult } from "../commit-workflow-schemas-BWlg7bZR.js";
|
|
3
|
+
import { FatalError, StepConfig, StepRunner } from "./step-runner.js";
|
|
4
|
+
/** Retries of the commit step: contention clears in seconds, so back off from 2 s, ten times. */
|
|
5
|
+
export declare const COMMIT_STEP_CONFIG: StepConfig;
|
|
6
|
+
/**
|
|
7
|
+
* The body of CommitWorkflow: one durable step that makes one commit attempt with the
|
|
8
|
+
* idempotency key the RPC call carried. A lost race throws so the engine retries the step with
|
|
9
|
+
* backoff; a broken rule stops the instance. Because every attempt first looks for a commit
|
|
10
|
+
* carrying the key, a step that pushed and then crashed before its result was stored finds its
|
|
11
|
+
* own commit on replay and reports it as replayed: exactly one commit, however often the step
|
|
12
|
+
* runs. The stored result holds ids only (see {@link CommitStepResult}).
|
|
13
|
+
*/
|
|
14
|
+
export declare function runCommitWorkflow(context: GatewayContext, payload: unknown, step: StepRunner, fatal?: FatalError): Promise<CommitStepResult>;
|
|
15
|
+
//# sourceMappingURL=run-commit-workflow.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { attemptCommit } from "../rpc/commit-attempt.js";
|
|
2
|
+
import { CommitStepResult, CommitWorkflowParams } from "./commit-workflow-schemas.js";
|
|
3
|
+
import { BranchMovedError, classifyStepError } from "./step-errors.js";
|
|
4
|
+
import { keepError } from "./step-runner.js";
|
|
5
|
+
import { invalidInput } from "@leed-ai/git-gateway-contract/gateway-error";
|
|
6
|
+
// src/workflows/run-commit-workflow.ts
|
|
7
|
+
/** Retries of the commit step: contention clears in seconds, so back off from 2 s, ten times. */
|
|
8
|
+
const COMMIT_STEP_CONFIG = {
|
|
9
|
+
retries: {
|
|
10
|
+
limit: 10,
|
|
11
|
+
delay: "2 seconds",
|
|
12
|
+
backoff: "exponential"
|
|
13
|
+
},
|
|
14
|
+
timeout: "2 minutes"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The body of CommitWorkflow: one durable step that makes one commit attempt with the
|
|
18
|
+
* idempotency key the RPC call carried. A lost race throws so the engine retries the step with
|
|
19
|
+
* backoff; a broken rule stops the instance. Because every attempt first looks for a commit
|
|
20
|
+
* carrying the key, a step that pushed and then crashed before its result was stored finds its
|
|
21
|
+
* own commit on replay and reports it as replayed: exactly one commit, however often the step
|
|
22
|
+
* runs. The stored result holds ids only (see {@link CommitStepResult}).
|
|
23
|
+
*/
|
|
24
|
+
async function runCommitWorkflow(context, payload, step, fatal = keepError) {
|
|
25
|
+
const parsed = CommitWorkflowParams.safeParse(payload);
|
|
26
|
+
if (!parsed.success) throw fatal(invalidInput(parsed.error));
|
|
27
|
+
const params = parsed.data;
|
|
28
|
+
const stored = await step.do("commit", COMMIT_STEP_CONFIG, async () => {
|
|
29
|
+
try {
|
|
30
|
+
const outcome = await attemptCommit(context, params);
|
|
31
|
+
if (outcome.kind === "stale") throw new BranchMovedError(params.branch);
|
|
32
|
+
const { output } = outcome;
|
|
33
|
+
if (output.status === "noop") return CommitStepResult.parse({
|
|
34
|
+
status: "noop",
|
|
35
|
+
head: output.head
|
|
36
|
+
});
|
|
37
|
+
return CommitStepResult.parse({
|
|
38
|
+
status: output.status,
|
|
39
|
+
sha: output.commit.sha
|
|
40
|
+
});
|
|
41
|
+
} catch (thrown) {
|
|
42
|
+
throw classifyStepError(thrown, fatal);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return CommitStepResult.parse(stored);
|
|
46
|
+
}
|
|
47
|
+
export { COMMIT_STEP_CONFIG, runCommitWorkflow };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=run-commit-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-commit-workflow.js","names":[],"sources":["../../src/workflows/run-commit-workflow.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { invalidInput } from '@leed-ai/git-gateway-contract/gateway-error';\n\nimport { attemptCommit } from '../rpc/commit-attempt.ts';\nimport type { GatewayContext } from '../rpc/gateway-context.ts';\nimport { CommitStepResult, CommitWorkflowParams } from './commit-workflow-schemas.ts';\nimport { BranchMovedError, classifyStepError } from './step-errors.ts';\nimport { keepError, type FatalError, type StepConfig, type StepRunner } from './step-runner.ts';\n\n/** Retries of the commit step: contention clears in seconds, so back off from 2 s, ten times. */\nexport const COMMIT_STEP_CONFIG: StepConfig = {\n retries: { limit: 10, delay: '2 seconds', backoff: 'exponential' },\n timeout: '2 minutes',\n};\n\n/**\n * The body of CommitWorkflow: one durable step that makes one commit attempt with the\n * idempotency key the RPC call carried. A lost race throws so the engine retries the step with\n * backoff; a broken rule stops the instance. Because every attempt first looks for a commit\n * carrying the key, a step that pushed and then crashed before its result was stored finds its\n * own commit on replay and reports it as replayed: exactly one commit, however often the step\n * runs. The stored result holds ids only (see {@link CommitStepResult}).\n */\nexport async function runCommitWorkflow(\n context: GatewayContext,\n payload: unknown,\n step: StepRunner,\n fatal: FatalError = keepError,\n): Promise<CommitStepResult> {\n const parsed = CommitWorkflowParams.safeParse(payload);\n if (!parsed.success) throw fatal(invalidInput(parsed.error));\n const params = parsed.data;\n const stored = await step.do('commit', COMMIT_STEP_CONFIG, async (): Promise<CommitStepResult> => {\n try {\n const outcome = await attemptCommit(context, params);\n if (outcome.kind === 'stale') throw new BranchMovedError(params.branch);\n const { output } = outcome;\n if (output.status === 'noop') return CommitStepResult.parse({ status: 'noop', head: output.head });\n return CommitStepResult.parse({ status: output.status, sha: output.commit.sha });\n } catch (thrown) {\n throw classifyStepError(thrown, fatal);\n }\n });\n return CommitStepResult.parse(stored);\n}\n"],"mappings":";;;;;;;AAUA,MAAa,qBAAiC;CAC5C,SAAS;EAAE,OAAO;EAAI,OAAO;EAAa,SAAS;CAAc;CACjE,SAAS;AACX;;;;;;;;;AAUA,eAAsB,kBACpB,SACA,SACA,MACA,QAAoB,WACO;CAC3B,MAAM,SAAS,qBAAqB,UAAU,OAAO;CACrD,IAAI,CAAC,OAAO,SAAS,MAAM,MAAM,aAAa,OAAO,KAAK,CAAC;CAC3D,MAAM,SAAS,OAAO;CACtB,MAAM,SAAS,MAAM,KAAK,GAAG,UAAU,oBAAoB,YAAuC;EAChG,IAAI;GACF,MAAM,UAAU,MAAM,cAAc,SAAS,MAAM;GACnD,IAAI,QAAQ,SAAS,SAAS,MAAM,IAAI,iBAAiB,OAAO,MAAM;GACtE,MAAM,EAAE,WAAW;GACnB,IAAI,OAAO,WAAW,QAAQ,OAAO,iBAAiB,MAAM;IAAE,QAAQ;IAAQ,MAAM,OAAO;GAAK,CAAC;GACjG,OAAO,iBAAiB,MAAM;IAAE,QAAQ,OAAO;IAAQ,KAAK,OAAO,OAAO;GAAI,CAAC;EACjF,SAAS,QAAQ;GACf,MAAM,kBAAkB,QAAQ,KAAK;EACvC;CACF,CAAC;CACD,OAAO,iBAAiB,MAAM,MAAM;AACtC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as GatewayContext } from "../gateway-context-Boh9I0mk.js";
|
|
2
|
+
import { FatalError, StepConfig, StepRunner } from "./step-runner.js";
|
|
3
|
+
import { a as SyncStepResult } from "../sync-workflow-schemas-DCNmNE5-.js";
|
|
4
|
+
/** Retries of the sync step: back off from 5 s, eight times. */
|
|
5
|
+
export declare const SYNC_STEP_CONFIG: StepConfig;
|
|
6
|
+
/**
|
|
7
|
+
* The body of SyncBranchWorkflow: one durable step that syncs `into` with `from` (see
|
|
8
|
+
* syncBranch). `into` moving under the step throws so the engine retries with backoff; a missing
|
|
9
|
+
* branch or unrelated histories stop the instance; a conflict completes it with the conflicting
|
|
10
|
+
* paths. Replaying a step that merged and then crashed finds `into` already containing `from` and
|
|
11
|
+
* reports up_to_date, so a sync never writes two merge commits.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runSyncWorkflow(context: GatewayContext, payload: unknown, step: StepRunner, fatal?: FatalError): Promise<SyncStepResult>;
|
|
14
|
+
//# sourceMappingURL=run-sync-workflow.d.ts.map
|