@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.
Files changed (269) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +49 -2
  3. package/dist/audit/audit-recorder.d.ts +2 -0
  4. package/dist/audit/audit-recorder.js +53 -0
  5. package/dist/audit/audit-recorder.js.map +1 -0
  6. package/dist/audit/push-report.d.ts +13 -0
  7. package/dist/audit/push-report.js +66 -0
  8. package/dist/audit/push-report.js.map +1 -0
  9. package/dist/audit-recorder-K1Ns3tfC.d.ts +31 -0
  10. package/dist/auth/authenticate.d.ts +14 -0
  11. package/dist/auth/authenticate.js +59 -0
  12. package/dist/auth/authenticate.js.map +1 -0
  13. package/dist/auth/authorize.d.ts +12 -0
  14. package/dist/auth/authorize.js +57 -0
  15. package/dist/auth/authorize.js.map +1 -0
  16. package/dist/auth/read-token-auth.d.ts +60 -0
  17. package/dist/auth/read-token-auth.js +83 -0
  18. package/dist/auth/read-token-auth.js.map +1 -0
  19. package/dist/cache/decision-cache.d.ts +2 -0
  20. package/dist/cache/decision-cache.js +45 -0
  21. package/dist/cache/decision-cache.js.map +1 -0
  22. package/dist/commit-workflow-schemas-BWlg7bZR.d.ts +95 -0
  23. package/dist/decision-cache-87U32iSj.d.ts +24 -0
  24. package/dist/gateway-app.d.ts +69 -0
  25. package/dist/gateway-app.js +80 -0
  26. package/dist/gateway-app.js.map +1 -0
  27. package/dist/gateway-context-Boh9I0mk.d.ts +54 -0
  28. package/dist/gateway-env-DnsBU4Pq.d.ts +40 -0
  29. package/dist/gateway-worker.d.ts +13 -0
  30. package/dist/gateway-worker.js +22 -0
  31. package/dist/gateway-worker.js.map +1 -0
  32. package/dist/git-route-Spxi09Rm.d.ts +22 -0
  33. package/dist/health.d.ts +6 -0
  34. package/dist/health.js +16 -0
  35. package/dist/health.js.map +1 -0
  36. package/dist/logger-BZ1zyKLb.d.ts +27 -0
  37. package/dist/logging/logger.d.ts +2 -0
  38. package/dist/logging/logger.js +15 -0
  39. package/dist/logging/logger.js.map +1 -0
  40. package/dist/on-push-DTREOB__.d.ts +62 -0
  41. package/dist/policy/branch-policy.d.ts +24 -0
  42. package/dist/policy/branch-policy.js +125 -0
  43. package/dist/policy/branch-policy.js.map +1 -0
  44. package/dist/policy/enforce-branch-policy.d.ts +30 -0
  45. package/dist/policy/enforce-branch-policy.js +214 -0
  46. package/dist/policy/enforce-branch-policy.js.map +1 -0
  47. package/dist/policy/fast-forward.d.ts +32 -0
  48. package/dist/policy/fast-forward.js +95 -0
  49. package/dist/policy/fast-forward.js.map +1 -0
  50. package/dist/policy/ref-pattern.d.ts +7 -0
  51. package/dist/policy/ref-pattern.js +25 -0
  52. package/dist/policy/ref-pattern.js.map +1 -0
  53. package/dist/policy/rule-branch-policy.d.ts +17 -0
  54. package/dist/policy/rule-branch-policy.js +69 -0
  55. package/dist/policy/rule-branch-policy.js.map +1 -0
  56. package/dist/proxy/defer.d.ts +8 -0
  57. package/dist/proxy/defer.js +15 -0
  58. package/dist/proxy/defer.js.map +1 -0
  59. package/dist/proxy/forward-read.d.ts +11 -0
  60. package/dist/proxy/forward-read.js +53 -0
  61. package/dist/proxy/forward-read.js.map +1 -0
  62. package/dist/proxy/gateway-deps.d.ts +39 -0
  63. package/dist/proxy/gateway-deps.js +0 -0
  64. package/dist/proxy/gateway-env.d.ts +2 -0
  65. package/dist/proxy/gateway-env.js +0 -0
  66. package/dist/proxy/git-responses.d.ts +25 -0
  67. package/dist/proxy/git-responses.js +83 -0
  68. package/dist/proxy/git-responses.js.map +1 -0
  69. package/dist/proxy/git-route.d.ts +2 -0
  70. package/dist/proxy/git-route.js +34 -0
  71. package/dist/proxy/git-route.js.map +1 -0
  72. package/dist/proxy/push-events.d.ts +28 -0
  73. package/dist/proxy/push-events.js +65 -0
  74. package/dist/proxy/push-events.js.map +1 -0
  75. package/dist/proxy/push-guard.d.ts +43 -0
  76. package/dist/proxy/push-guard.js +81 -0
  77. package/dist/proxy/push-guard.js.map +1 -0
  78. package/dist/proxy/push-options.d.ts +16 -0
  79. package/dist/proxy/push-options.js +33 -0
  80. package/dist/proxy/push-options.js.map +1 -0
  81. package/dist/proxy/receive-pack.d.ts +17 -0
  82. package/dist/proxy/receive-pack.js +244 -0
  83. package/dist/proxy/receive-pack.js.map +1 -0
  84. package/dist/proxy/request-log.d.ts +13 -0
  85. package/dist/proxy/request-log.js +41 -0
  86. package/dist/proxy/request-log.js.map +1 -0
  87. package/dist/proxy/resolve-route.d.ts +9 -0
  88. package/dist/proxy/resolve-route.js +22 -0
  89. package/dist/proxy/resolve-route.js.map +1 -0
  90. package/dist/proxy/upstream-call.d.ts +23 -0
  91. package/dist/proxy/upstream-call.js +63 -0
  92. package/dist/proxy/upstream-call.js.map +1 -0
  93. package/dist/proxy/upstream.d.ts +2 -0
  94. package/dist/proxy/upstream.js +68 -0
  95. package/dist/proxy/upstream.js.map +1 -0
  96. package/dist/push-event-f-5TsFUY.d.ts +15 -0
  97. package/dist/push-policy/changed-paths.d.ts +26 -0
  98. package/dist/push-policy/changed-paths.js +117 -0
  99. package/dist/push-policy/changed-paths.js.map +1 -0
  100. package/dist/push-policy/pushed-objects.d.ts +30 -0
  101. package/dist/push-policy/pushed-objects.js +76 -0
  102. package/dist/push-policy/pushed-objects.js.map +1 -0
  103. package/dist/push-policy/run-push-policy.d.ts +35 -0
  104. package/dist/push-policy/run-push-policy.js +77 -0
  105. package/dist/push-policy/run-push-policy.js.map +1 -0
  106. package/dist/push-policy/tree-diff.d.ts +21 -0
  107. package/dist/push-policy/tree-diff.js +78 -0
  108. package/dist/push-policy/tree-diff.js.map +1 -0
  109. package/dist/push-policy/uncheckable.d.ts +14 -0
  110. package/dist/push-policy/uncheckable.js +25 -0
  111. package/dist/push-policy/uncheckable.js.map +1 -0
  112. package/dist/rpc/branch-methods.d.ts +16 -0
  113. package/dist/rpc/branch-methods.js +43 -0
  114. package/dist/rpc/branch-methods.js.map +1 -0
  115. package/dist/rpc/commit-attempt.d.ts +27 -0
  116. package/dist/rpc/commit-attempt.js +85 -0
  117. package/dist/rpc/commit-attempt.js.map +1 -0
  118. package/dist/rpc/commit-graph.d.ts +20 -0
  119. package/dist/rpc/commit-graph.js +38 -0
  120. package/dist/rpc/commit-graph.js.map +1 -0
  121. package/dist/rpc/commit-method.d.ts +13 -0
  122. package/dist/rpc/commit-method.js +30 -0
  123. package/dist/rpc/commit-method.js.map +1 -0
  124. package/dist/rpc/commit-source.d.ts +12 -0
  125. package/dist/rpc/commit-source.js +9 -0
  126. package/dist/rpc/commit-source.js.map +1 -0
  127. package/dist/rpc/gateway-context.d.ts +2 -0
  128. package/dist/rpc/gateway-context.js +30 -0
  129. package/dist/rpc/gateway-context.js.map +1 -0
  130. package/dist/rpc/gateway-rpc.d.ts +10 -0
  131. package/dist/rpc/gateway-rpc.js +48 -0
  132. package/dist/rpc/gateway-rpc.js.map +1 -0
  133. package/dist/rpc/gateway-service.d.ts +24 -0
  134. package/dist/rpc/gateway-service.js +63 -0
  135. package/dist/rpc/gateway-service.js.map +1 -0
  136. package/dist/rpc/history-page.d.ts +35 -0
  137. package/dist/rpc/history-page.js +122 -0
  138. package/dist/rpc/history-page.js.map +1 -0
  139. package/dist/rpc/lifecycle-methods.d.ts +12 -0
  140. package/dist/rpc/lifecycle-methods.js +39 -0
  141. package/dist/rpc/lifecycle-methods.js.map +1 -0
  142. package/dist/rpc/paint-down.d.ts +17 -0
  143. package/dist/rpc/paint-down.js +96 -0
  144. package/dist/rpc/paint-down.js.map +1 -0
  145. package/dist/rpc/promote-attempt.d.ts +21 -0
  146. package/dist/rpc/promote-attempt.js +55 -0
  147. package/dist/rpc/promote-attempt.js.map +1 -0
  148. package/dist/rpc/push-ref.d.ts +21 -0
  149. package/dist/rpc/push-ref.js +47 -0
  150. package/dist/rpc/push-ref.js.map +1 -0
  151. package/dist/rpc/read-methods.d.ts +17 -0
  152. package/dist/rpc/read-methods.js +94 -0
  153. package/dist/rpc/read-methods.js.map +1 -0
  154. package/dist/rpc/read-token.d.ts +39 -0
  155. package/dist/rpc/read-token.js +107 -0
  156. package/dist/rpc/read-token.js.map +1 -0
  157. package/dist/rpc/repo-access.d.ts +36 -0
  158. package/dist/rpc/repo-access.js +75 -0
  159. package/dist/rpc/repo-access.js.map +1 -0
  160. package/dist/rpc/sync-attempt.d.ts +23 -0
  161. package/dist/rpc/sync-attempt.js +105 -0
  162. package/dist/rpc/sync-attempt.js.map +1 -0
  163. package/dist/sync-workflow-schemas-DCNmNE5-.d.ts +57 -0
  164. package/dist/upstream-DvqMCj5N.d.ts +15 -0
  165. package/dist/workflow-starter-BqhwX6oA.d.ts +45 -0
  166. package/dist/workflows/commit-workflow-schemas.d.ts +2 -0
  167. package/dist/workflows/commit-workflow-schemas.js +84 -0
  168. package/dist/workflows/commit-workflow-schemas.js.map +1 -0
  169. package/dist/workflows/commit-workflow.d.ts +16 -0
  170. package/dist/workflows/commit-workflow.js +22 -0
  171. package/dist/workflows/commit-workflow.js.map +1 -0
  172. package/dist/workflows/on-push.d.ts +2 -0
  173. package/dist/workflows/on-push.js +90 -0
  174. package/dist/workflows/on-push.js.map +1 -0
  175. package/dist/workflows/push-event.d.ts +2 -0
  176. package/dist/workflows/push-event.js +28 -0
  177. package/dist/workflows/push-event.js.map +1 -0
  178. package/dist/workflows/run-commit-workflow.d.ts +15 -0
  179. package/dist/workflows/run-commit-workflow.js +49 -0
  180. package/dist/workflows/run-commit-workflow.js.map +1 -0
  181. package/dist/workflows/run-sync-workflow.d.ts +14 -0
  182. package/dist/workflows/run-sync-workflow.js +67 -0
  183. package/dist/workflows/run-sync-workflow.js.map +1 -0
  184. package/dist/workflows/step-errors.d.ts +15 -0
  185. package/dist/workflows/step-errors.js +24 -0
  186. package/dist/workflows/step-errors.js.map +1 -0
  187. package/dist/workflows/step-runner.d.ts +31 -0
  188. package/dist/workflows/step-runner.js +6 -0
  189. package/dist/workflows/step-runner.js.map +1 -0
  190. package/dist/workflows/sync-branch-workflow.d.ts +15 -0
  191. package/dist/workflows/sync-branch-workflow.js +21 -0
  192. package/dist/workflows/sync-branch-workflow.js.map +1 -0
  193. package/dist/workflows/sync-workflow-schemas.d.ts +2 -0
  194. package/dist/workflows/sync-workflow-schemas.js +104 -0
  195. package/dist/workflows/sync-workflow-schemas.js.map +1 -0
  196. package/dist/workflows/workflow-instance-id.d.ts +12 -0
  197. package/dist/workflows/workflow-instance-id.js +33 -0
  198. package/dist/workflows/workflow-instance-id.js.map +1 -0
  199. package/dist/workflows/workflow-runtime.d.ts +7 -0
  200. package/dist/workflows/workflow-runtime.js +11 -0
  201. package/dist/workflows/workflow-runtime.js.map +1 -0
  202. package/dist/workflows/workflow-starter.d.ts +2 -0
  203. package/dist/workflows/workflow-starter.js +40 -0
  204. package/dist/workflows/workflow-starter.js.map +1 -0
  205. package/package.json +381 -4
  206. package/src/audit/audit-recorder.ts +74 -0
  207. package/src/audit/push-report.ts +60 -0
  208. package/src/auth/authenticate.ts +68 -0
  209. package/src/auth/authorize.ts +57 -0
  210. package/src/auth/read-token-auth.ts +119 -0
  211. package/src/cache/decision-cache.ts +57 -0
  212. package/src/gateway-app.ts +147 -0
  213. package/src/gateway-worker.ts +32 -0
  214. package/src/health.ts +12 -0
  215. package/src/logging/logger.ts +40 -0
  216. package/src/policy/branch-policy.ts +119 -0
  217. package/src/policy/enforce-branch-policy.ts +213 -0
  218. package/src/policy/fast-forward.ts +136 -0
  219. package/src/policy/ref-pattern.ts +24 -0
  220. package/src/policy/rule-branch-policy.ts +76 -0
  221. package/src/proxy/defer.ts +18 -0
  222. package/src/proxy/forward-read.ts +52 -0
  223. package/src/proxy/gateway-deps.ts +43 -0
  224. package/src/proxy/gateway-env.ts +43 -0
  225. package/src/proxy/git-responses.ts +89 -0
  226. package/src/proxy/git-route.ts +49 -0
  227. package/src/proxy/push-events.ts +91 -0
  228. package/src/proxy/push-guard.ts +109 -0
  229. package/src/proxy/push-options.ts +38 -0
  230. package/src/proxy/receive-pack.ts +257 -0
  231. package/src/proxy/request-log.ts +44 -0
  232. package/src/proxy/resolve-route.ts +24 -0
  233. package/src/proxy/upstream-call.ts +71 -0
  234. package/src/proxy/upstream.ts +76 -0
  235. package/src/push-policy/changed-paths.ts +143 -0
  236. package/src/push-policy/pushed-objects.ts +88 -0
  237. package/src/push-policy/run-push-policy.ts +99 -0
  238. package/src/push-policy/tree-diff.ts +107 -0
  239. package/src/push-policy/uncheckable.ts +27 -0
  240. package/src/rpc/branch-methods.ts +57 -0
  241. package/src/rpc/commit-attempt.ts +87 -0
  242. package/src/rpc/commit-graph.ts +44 -0
  243. package/src/rpc/commit-method.ts +36 -0
  244. package/src/rpc/commit-source.ts +15 -0
  245. package/src/rpc/gateway-context.ts +77 -0
  246. package/src/rpc/gateway-rpc.ts +65 -0
  247. package/src/rpc/gateway-service.ts +85 -0
  248. package/src/rpc/history-page.ts +163 -0
  249. package/src/rpc/lifecycle-methods.ts +50 -0
  250. package/src/rpc/paint-down.ts +120 -0
  251. package/src/rpc/promote-attempt.ts +52 -0
  252. package/src/rpc/push-ref.ts +54 -0
  253. package/src/rpc/read-methods.ts +111 -0
  254. package/src/rpc/read-token.ts +135 -0
  255. package/src/rpc/repo-access.ts +112 -0
  256. package/src/rpc/sync-attempt.ts +84 -0
  257. package/src/workflows/commit-workflow-schemas.ts +95 -0
  258. package/src/workflows/commit-workflow.ts +39 -0
  259. package/src/workflows/on-push.ts +128 -0
  260. package/src/workflows/push-event.ts +41 -0
  261. package/src/workflows/run-commit-workflow.ts +45 -0
  262. package/src/workflows/run-sync-workflow.ts +52 -0
  263. package/src/workflows/step-errors.ts +26 -0
  264. package/src/workflows/step-runner.ts +36 -0
  265. package/src/workflows/sync-branch-workflow.ts +40 -0
  266. package/src/workflows/sync-workflow-schemas.ts +122 -0
  267. package/src/workflows/workflow-instance-id.ts +26 -0
  268. package/src/workflows/workflow-runtime.ts +13 -0
  269. package/src/workflows/workflow-starter.ts +69 -0
@@ -0,0 +1,67 @@
1
+ import { attemptSync } from "../rpc/sync-attempt.js";
2
+ import { BranchMovedError, classifyStepError } from "./step-errors.js";
3
+ import { keepError } from "./step-runner.js";
4
+ import { SyncBranchWorkflowParams, SyncStepResult } from "./sync-workflow-schemas.js";
5
+ import { invalidInput } from "@leed-ai/git-gateway-contract/gateway-error";
6
+ // src/workflows/run-sync-workflow.ts
7
+ /** Retries of the sync step: back off from 5 s, eight times. */
8
+ const SYNC_STEP_CONFIG = {
9
+ retries: {
10
+ limit: 8,
11
+ delay: "5 seconds",
12
+ backoff: "exponential"
13
+ },
14
+ timeout: "5 minutes"
15
+ };
16
+ /** The stored form of a syncBranch() result: ids and paths only. */
17
+ function summarize(output) {
18
+ if (output.status === "up_to_date") return {
19
+ status: "up_to_date",
20
+ head: output.head
21
+ };
22
+ if (output.status === "fast_forward") return {
23
+ status: "fast_forward",
24
+ head: output.refUpdate.newSha
25
+ };
26
+ if (output.status === "merged") return {
27
+ status: "merged",
28
+ head: output.commit.sha
29
+ };
30
+ const { paths, base, fromHead, intoHead } = output;
31
+ return {
32
+ status: "conflict",
33
+ paths,
34
+ base,
35
+ fromHead,
36
+ intoHead
37
+ };
38
+ }
39
+ /**
40
+ * The body of SyncBranchWorkflow: one durable step that syncs `into` with `from` (see
41
+ * syncBranch). `into` moving under the step throws so the engine retries with backoff; a missing
42
+ * branch or unrelated histories stop the instance; a conflict completes it with the conflicting
43
+ * paths. Replaying a step that merged and then crashed finds `into` already containing `from` and
44
+ * reports up_to_date, so a sync never writes two merge commits.
45
+ */
46
+ async function runSyncWorkflow(context, payload, step, fatal = keepError) {
47
+ const parsed = SyncBranchWorkflowParams.safeParse(payload);
48
+ if (!parsed.success) throw fatal(invalidInput(parsed.error));
49
+ const { repo, from, into } = parsed.data;
50
+ const stored = await step.do("sync", SYNC_STEP_CONFIG, async () => {
51
+ try {
52
+ const outcome = await attemptSync(context, {
53
+ repo,
54
+ from,
55
+ into
56
+ });
57
+ if (outcome.kind === "stale") throw new BranchMovedError(into);
58
+ return SyncStepResult.parse(summarize(outcome.output));
59
+ } catch (thrown) {
60
+ throw classifyStepError(thrown, fatal);
61
+ }
62
+ });
63
+ return SyncStepResult.parse(stored);
64
+ }
65
+ export { SYNC_STEP_CONFIG, runSyncWorkflow };
66
+
67
+ //# sourceMappingURL=run-sync-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-sync-workflow.js","names":[],"sources":["../../src/workflows/run-sync-workflow.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';\nimport { invalidInput } from '@leed-ai/git-gateway-contract/gateway-error';\n\nimport type { GatewayContext } from '../rpc/gateway-context.ts';\nimport { attemptSync } from '../rpc/sync-attempt.ts';\nimport { BranchMovedError, classifyStepError } from './step-errors.ts';\nimport { keepError, type FatalError, type StepConfig, type StepRunner } from './step-runner.ts';\nimport { SyncBranchWorkflowParams, SyncStepResult } from './sync-workflow-schemas.ts';\n\n/** Retries of the sync step: back off from 5 s, eight times. */\nexport const SYNC_STEP_CONFIG: StepConfig = {\n retries: { limit: 8, delay: '5 seconds', backoff: 'exponential' },\n timeout: '5 minutes',\n};\n\n/** The stored form of a syncBranch() result: ids and paths only. */\nfunction summarize(output: RpcOutput<'syncBranch'>): SyncStepResult {\n if (output.status === 'up_to_date') return { status: 'up_to_date', head: output.head };\n if (output.status === 'fast_forward') return { status: 'fast_forward', head: output.refUpdate.newSha };\n if (output.status === 'merged') return { status: 'merged', head: output.commit.sha };\n const { paths, base, fromHead, intoHead } = output;\n return { status: 'conflict', paths, base, fromHead, intoHead };\n}\n\n/**\n * The body of SyncBranchWorkflow: one durable step that syncs `into` with `from` (see\n * syncBranch). `into` moving under the step throws so the engine retries with backoff; a missing\n * branch or unrelated histories stop the instance; a conflict completes it with the conflicting\n * paths. Replaying a step that merged and then crashed finds `into` already containing `from` and\n * reports up_to_date, so a sync never writes two merge commits.\n */\nexport async function runSyncWorkflow(\n context: GatewayContext,\n payload: unknown,\n step: StepRunner,\n fatal: FatalError = keepError,\n): Promise<SyncStepResult> {\n const parsed = SyncBranchWorkflowParams.safeParse(payload);\n if (!parsed.success) throw fatal(invalidInput(parsed.error));\n const { repo, from, into } = parsed.data;\n const stored = await step.do('sync', SYNC_STEP_CONFIG, async (): Promise<SyncStepResult> => {\n try {\n const outcome = await attemptSync(context, { repo, from, into });\n if (outcome.kind === 'stale') throw new BranchMovedError(into);\n return SyncStepResult.parse(summarize(outcome.output));\n } catch (thrown) {\n throw classifyStepError(thrown, fatal);\n }\n });\n return SyncStepResult.parse(stored);\n}\n"],"mappings":";;;;;;;AAWA,MAAa,mBAA+B;CAC1C,SAAS;EAAE,OAAO;EAAG,OAAO;EAAa,SAAS;CAAc;CAChE,SAAS;AACX;;AAGA,SAAS,UAAU,QAAiD;CAClE,IAAI,OAAO,WAAW,cAAc,OAAO;EAAE,QAAQ;EAAc,MAAM,OAAO;CAAK;CACrF,IAAI,OAAO,WAAW,gBAAgB,OAAO;EAAE,QAAQ;EAAgB,MAAM,OAAO,UAAU;CAAO;CACrG,IAAI,OAAO,WAAW,UAAU,OAAO;EAAE,QAAQ;EAAU,MAAM,OAAO,OAAO;CAAI;CACnF,MAAM,EAAE,OAAO,MAAM,UAAU,aAAa;CAC5C,OAAO;EAAE,QAAQ;EAAY;EAAO;EAAM;EAAU;CAAS;AAC/D;;;;;;;;AASA,eAAsB,gBACpB,SACA,SACA,MACA,QAAoB,WACK;CACzB,MAAM,SAAS,yBAAyB,UAAU,OAAO;CACzD,IAAI,CAAC,OAAO,SAAS,MAAM,MAAM,aAAa,OAAO,KAAK,CAAC;CAC3D,MAAM,EAAE,MAAM,MAAM,SAAS,OAAO;CACpC,MAAM,SAAS,MAAM,KAAK,GAAG,QAAQ,kBAAkB,YAAqC;EAC1F,IAAI;GACF,MAAM,UAAU,MAAM,YAAY,SAAS;IAAE;IAAM;IAAM;GAAK,CAAC;GAC/D,IAAI,QAAQ,SAAS,SAAS,MAAM,IAAI,iBAAiB,IAAI;GAC7D,OAAO,eAAe,MAAM,UAAU,QAAQ,MAAM,CAAC;EACvD,SAAS,QAAQ;GACf,MAAM,kBAAkB,QAAQ,KAAK;EACvC;CACF,CAAC;CACD,OAAO,eAAe,MAAM,MAAM;AACpC"}
@@ -0,0 +1,15 @@
1
+ import { FatalError } from "./step-runner.js";
2
+ /** Thrown inside a step when the branch moved under it, so the engine retries the step with backoff. */
3
+ export declare class BranchMovedError extends Error {
4
+ readonly name = "BranchMovedError";
5
+ constructor(branch: string);
6
+ }
7
+ /**
8
+ * Sorts an error thrown inside a step: a GatewayError that retrying cannot fix (any code but
9
+ * storage_unavailable — a rule broken by the actions, a missing branch, a stale expected head) is
10
+ * turned into a fatal error so the instance stops at once, keeping the GatewayError's message (and
11
+ * so its body). Everything else — storage failures, a moved branch, the unexpected — is rethrown
12
+ * as is for the engine to retry.
13
+ */
14
+ export declare function classifyStepError(thrown: unknown, fatal: FatalError): unknown;
15
+ //# sourceMappingURL=step-errors.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { readGatewayError } from "@leed-ai/git-gateway-contract/gateway-error";
2
+ // src/workflows/step-errors.ts
3
+ /** Thrown inside a step when the branch moved under it, so the engine retries the step with backoff. */
4
+ var BranchMovedError = class extends Error {
5
+ name = "BranchMovedError";
6
+ constructor(branch) {
7
+ super(`Branch ${branch} moved during the step; retrying`);
8
+ }
9
+ };
10
+ /**
11
+ * Sorts an error thrown inside a step: a GatewayError that retrying cannot fix (any code but
12
+ * storage_unavailable — a rule broken by the actions, a missing branch, a stale expected head) is
13
+ * turned into a fatal error so the instance stops at once, keeping the GatewayError's message (and
14
+ * so its body). Everything else — storage failures, a moved branch, the unexpected — is rethrown
15
+ * as is for the engine to retry.
16
+ */
17
+ function classifyStepError(thrown, fatal) {
18
+ const body = readGatewayError(thrown);
19
+ if (body === null || body.code === "storage_unavailable" || !(thrown instanceof Error)) return thrown;
20
+ return fatal(thrown);
21
+ }
22
+ export { BranchMovedError, classifyStepError };
23
+
24
+ //# sourceMappingURL=step-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-errors.js","names":[],"sources":["../../src/workflows/step-errors.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { readGatewayError } from '@leed-ai/git-gateway-contract/gateway-error';\n\nimport type { FatalError } from './step-runner.ts';\n\n/** Thrown inside a step when the branch moved under it, so the engine retries the step with backoff. */\nexport class BranchMovedError extends Error {\n override readonly name = 'BranchMovedError';\n\n constructor(branch: string) {\n super(`Branch ${branch} moved during the step; retrying`);\n }\n}\n\n/**\n * Sorts an error thrown inside a step: a GatewayError that retrying cannot fix (any code but\n * storage_unavailable — a rule broken by the actions, a missing branch, a stale expected head) is\n * turned into a fatal error so the instance stops at once, keeping the GatewayError's message (and\n * so its body). Everything else — storage failures, a moved branch, the unexpected — is rethrown\n * as is for the engine to retry.\n */\nexport function classifyStepError(thrown: unknown, fatal: FatalError): unknown {\n const body = readGatewayError(thrown);\n if (body === null || body.code === 'storage_unavailable' || !(thrown instanceof Error)) return thrown;\n return fatal(thrown);\n}\n"],"mappings":";;;AAMA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,OAAyB;CAEzB,YAAY,QAAgB;EAC1B,MAAM,UAAU,OAAO,iCAAiC;CAC1D;AACF;;;;;;;;AASA,SAAgB,kBAAkB,QAAiB,OAA4B;CAC7E,MAAM,OAAO,iBAAiB,MAAM;CACpC,IAAI,SAAS,QAAQ,KAAK,SAAS,yBAAyB,EAAE,kBAAkB,QAAQ,OAAO;CAC/F,OAAO,MAAM,MAAM;AACrB"}
@@ -0,0 +1,31 @@
1
+ import { i as CommitStepResult } from "../commit-workflow-schemas-BWlg7bZR.js";
2
+ import { a as SyncStepResult } from "../sync-workflow-schemas-DCNmNE5-.js";
3
+ /** Retry and timeout settings of one Workflow step, in the shape `WorkflowStep.do` takes. */
4
+ export interface StepConfig {
5
+ readonly retries: {
6
+ readonly limit: number;
7
+ readonly delay: `${number} ${'second' | 'minute'}${'s' | ''}`;
8
+ readonly backoff: 'constant' | 'linear' | 'exponential';
9
+ };
10
+ readonly timeout: `${number} ${'second' | 'minute'}${'s' | ''}`;
11
+ }
12
+ /** What a gateway Workflow step stores: ids, statuses and paths, never content or a credential. */
13
+ export type StepResult = CommitStepResult | SyncStepResult;
14
+ /**
15
+ * The part of a Workflows `WorkflowStep` the gateway's workflows use: run a named, durable step.
16
+ * The engine stores what the callback returns and, when the instance replays after a crash or a
17
+ * retry, hands back the stored value instead of running a finished step again. A step whose
18
+ * result was never stored (the isolate died mid-step) runs again, so every step is idempotent.
19
+ * The stored value comes back as `unknown`: callers parse it with its schema.
20
+ */
21
+ export interface StepRunner {
22
+ do(name: string, config: StepConfig, callback: () => Promise<StepResult>): Promise<unknown>;
23
+ }
24
+ /**
25
+ * Turns an error a step cannot recover from into the error that stops the instance without
26
+ * retries (in a Worker, `NonRetryableError` from `cloudflare:workflows`).
27
+ */
28
+ export type FatalError = (error: Error) => Error;
29
+ /** The default {@link FatalError}: the error unchanged (for runners without a non-retryable error). */
30
+ export declare const keepError: FatalError;
31
+ //# sourceMappingURL=step-runner.d.ts.map
@@ -0,0 +1,6 @@
1
+ // src/workflows/step-runner.ts
2
+ /** The default {@link FatalError}: the error unchanged (for runners without a non-retryable error). */
3
+ const keepError = (error) => error;
4
+ export { keepError };
5
+
6
+ //# sourceMappingURL=step-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-runner.js","names":[],"sources":["../../src/workflows/step-runner.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { CommitStepResult } from './commit-workflow-schemas.ts';\nimport type { SyncStepResult } from './sync-workflow-schemas.ts';\n\n/** Retry and timeout settings of one Workflow step, in the shape `WorkflowStep.do` takes. */\nexport interface StepConfig {\n readonly retries: {\n readonly limit: number;\n readonly delay: `${number} ${'second' | 'minute'}${'s' | ''}`;\n readonly backoff: 'constant' | 'linear' | 'exponential';\n };\n readonly timeout: `${number} ${'second' | 'minute'}${'s' | ''}`;\n}\n\n/** What a gateway Workflow step stores: ids, statuses and paths, never content or a credential. */\nexport type StepResult = CommitStepResult | SyncStepResult;\n\n/**\n * The part of a Workflows `WorkflowStep` the gateway's workflows use: run a named, durable step.\n * The engine stores what the callback returns and, when the instance replays after a crash or a\n * retry, hands back the stored value instead of running a finished step again. A step whose\n * result was never stored (the isolate died mid-step) runs again, so every step is idempotent.\n * The stored value comes back as `unknown`: callers parse it with its schema.\n */\nexport interface StepRunner {\n do(name: string, config: StepConfig, callback: () => Promise<StepResult>): Promise<unknown>;\n}\n\n/**\n * Turns an error a step cannot recover from into the error that stops the instance without\n * retries (in a Worker, `NonRetryableError` from `cloudflare:workflows`).\n */\nexport type FatalError = (error: Error) => Error;\n\n/** The default {@link FatalError}: the error unchanged (for runners without a non-retryable error). */\nexport const keepError: FatalError = (error) => error;\n"],"mappings":";;AAmCA,MAAa,aAAyB,UAAU"}
@@ -0,0 +1,15 @@
1
+ import { GatewayOptionsResolver } from "../rpc/gateway-service.js";
2
+ import { a as SyncStepResult, t as SyncBranchWorkflowParams } from "../sync-workflow-schemas-DCNmNE5-.js";
3
+ import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers";
4
+ /** The SyncBranchWorkflow class {@link createSyncBranchWorkflow} returns. */
5
+ export type SyncBranchWorkflowClass<Env> = new (ctx: ExecutionContext, env: Env) => WorkflowEntrypoint<Env, SyncBranchWorkflowParams> & {
6
+ run(event: Readonly<WorkflowEvent<SyncBranchWorkflowParams>>, step: WorkflowStep): Promise<SyncStepResult>;
7
+ };
8
+ /**
9
+ * The SyncBranchWorkflow a deployment exports and binds, which onPush sync rules start (see
10
+ * `syncRuleHook`), e.g. to sync staging from main after every push to main:
11
+ *
12
+ * export const SyncBranchWorkflow = createSyncBranchWorkflow(gatewayOptions);
13
+ */
14
+ export declare function createSyncBranchWorkflow<Env>(resolve: GatewayOptionsResolver<Env>): SyncBranchWorkflowClass<Env>;
15
+ //# sourceMappingURL=sync-branch-workflow.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { gatewayContext } from "../rpc/gateway-context.js";
2
+ import { runSyncWorkflow } from "./run-sync-workflow.js";
3
+ import { nonRetryable, stepRunnerOf } from "./workflow-runtime.js";
4
+ import { WorkflowEntrypoint } from "cloudflare:workers";
5
+ // src/workflows/sync-branch-workflow.ts
6
+ /**
7
+ * The SyncBranchWorkflow a deployment exports and binds, which onPush sync rules start (see
8
+ * `syncRuleHook`), e.g. to sync staging from main after every push to main:
9
+ *
10
+ * export const SyncBranchWorkflow = createSyncBranchWorkflow(gatewayOptions);
11
+ */
12
+ function createSyncBranchWorkflow(resolve) {
13
+ return class SyncBranchWorkflow extends WorkflowEntrypoint {
14
+ run(event, step) {
15
+ return runSyncWorkflow(gatewayContext(resolve(this.env)), event.payload, stepRunnerOf(step), nonRetryable);
16
+ }
17
+ };
18
+ }
19
+ export { createSyncBranchWorkflow };
20
+
21
+ //# sourceMappingURL=sync-branch-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-branch-workflow.js","names":[],"sources":["../../src/workflows/sync-branch-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 { runSyncWorkflow } from './run-sync-workflow.ts';\nimport { nonRetryable, stepRunnerOf } from './workflow-runtime.ts';\nimport type { SyncBranchWorkflowParams, SyncStepResult } from './sync-workflow-schemas.ts';\n\n/** The SyncBranchWorkflow class {@link createSyncBranchWorkflow} returns. */\nexport type SyncBranchWorkflowClass<Env> = new (\n ctx: ExecutionContext,\n env: Env,\n) => WorkflowEntrypoint<Env, SyncBranchWorkflowParams> & {\n run(event: Readonly<WorkflowEvent<SyncBranchWorkflowParams>>, step: WorkflowStep): Promise<SyncStepResult>;\n};\n\n/**\n * The SyncBranchWorkflow a deployment exports and binds, which onPush sync rules start (see\n * `syncRuleHook`), e.g. to sync staging from main after every push to main:\n *\n * export const SyncBranchWorkflow = createSyncBranchWorkflow(gatewayOptions);\n */\nexport function createSyncBranchWorkflow<Env>(\n resolve: GatewayOptionsResolver<Env>,\n): SyncBranchWorkflowClass<Env> {\n return class SyncBranchWorkflow extends WorkflowEntrypoint<Env, SyncBranchWorkflowParams> {\n override run(\n event: Readonly<WorkflowEvent<SyncBranchWorkflowParams>>,\n step: WorkflowStep,\n ): Promise<SyncStepResult> {\n return runSyncWorkflow(\n gatewayContext(resolve(this.env)),\n event.payload,\n stepRunnerOf(step),\n nonRetryable,\n );\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAgB,yBACd,SAC8B;CAC9B,OAAO,MAAM,2BAA2B,mBAAkD;EACxF,IACE,OACA,MACyB;GACzB,OAAO,gBACL,eAAe,QAAQ,KAAK,GAAG,CAAC,GAChC,MAAM,SACN,aAAa,IAAI,GACjB,YACF;EACF;CACF;AACF"}
@@ -0,0 +1,2 @@
1
+ import { a as SyncStepResult, i as SyncStepMerged, n as SyncStepConflict, o as SyncStepUpToDate, r as SyncStepFastForward, t as SyncBranchWorkflowParams } from "../sync-workflow-schemas-DCNmNE5-.js";
2
+ export { SyncBranchWorkflowParams, SyncStepConflict, SyncStepFastForward, SyncStepMerged, SyncStepResult, SyncStepUpToDate };
@@ -0,0 +1,104 @@
1
+ import { Sha } from "@leed-ai/git-gateway-contract/schemas/sha";
2
+ import { BranchName, FilePath, RepoName } from "@leed-ai/git-gateway-contract/schemas/names";
3
+ import { EXAMPLE_SHA_A, EXAMPLE_SHA_B } from "@leed-ai/git-gateway-contract/schemas/examples";
4
+ import { z } from "zod";
5
+ // src/workflows/sync-workflow-schemas.ts
6
+ /** What a SyncBranchWorkflow instance is started with. */
7
+ const SyncBranchWorkflowParams = z.object({
8
+ repo: RepoName.describe("Repository holding both branches."),
9
+ from: BranchName.describe("Branch whose commits are brought into `into`, e.g. main."),
10
+ into: BranchName.describe("Branch brought up to date, e.g. staging; only fast-forwarded or merged into."),
11
+ fromHead: Sha.describe("Head of `from` the push left; identifies the instance, so one push starts at most one sync.")
12
+ }).strict().refine((params) => params.from !== params.into, {
13
+ message: "from and into must differ",
14
+ path: ["into"]
15
+ }).meta({
16
+ id: "SyncBranchWorkflowParams",
17
+ title: "SyncBranchWorkflow params",
18
+ description: "The params a SyncBranchWorkflow instance is started with by an onPush sync rule: sync `into` with `from` after a push moved `from` to `fromHead`. The sync merges whatever `from` holds when it runs.",
19
+ examples: [{
20
+ repo: "acme-raw-content",
21
+ from: "main",
22
+ into: "staging",
23
+ fromHead: EXAMPLE_SHA_B
24
+ }]
25
+ });
26
+ /** `into` already contained `from`. */
27
+ const SyncStepUpToDate = z.object({
28
+ status: z.literal("up_to_date").describe("`into` already contained `from` (possibly because an earlier run of the step merged it)."),
29
+ head: Sha.describe("Head of `into`, unchanged.")
30
+ }).strict().meta({
31
+ id: "SyncStepUpToDate",
32
+ title: "sync step: up to date",
33
+ description: "The SyncBranchWorkflow's sync step found nothing to do.",
34
+ examples: [{
35
+ status: "up_to_date",
36
+ head: EXAMPLE_SHA_A
37
+ }]
38
+ });
39
+ /** `into` was fast-forwarded. */
40
+ const SyncStepFastForward = z.object({
41
+ status: z.literal("fast_forward").describe("`into` had no commits of its own and was fast-forwarded."),
42
+ head: Sha.describe("New head of `into`, the head of `from`.")
43
+ }).strict().meta({
44
+ id: "SyncStepFastForward",
45
+ title: "sync step: fast-forward",
46
+ description: "The SyncBranchWorkflow's sync step fast-forwarded `into`.",
47
+ examples: [{
48
+ status: "fast_forward",
49
+ head: EXAMPLE_SHA_B
50
+ }]
51
+ });
52
+ /** A merge commit was written. */
53
+ const SyncStepMerged = z.object({
54
+ status: z.literal("merged").describe("Both branches had commits; a file-level merge commit was written."),
55
+ head: Sha.describe("New head of `into`, the merge commit.")
56
+ }).strict().meta({
57
+ id: "SyncStepMerged",
58
+ title: "sync step: merged",
59
+ description: "The SyncBranchWorkflow's sync step wrote a merge commit to `into`.",
60
+ examples: [{
61
+ status: "merged",
62
+ head: EXAMPLE_SHA_B
63
+ }]
64
+ });
65
+ /** The branches conflict. */
66
+ const SyncStepConflict = z.object({
67
+ status: z.literal("conflict").describe("Some paths changed differently on both sides; nothing was written and retrying cannot help."),
68
+ paths: z.array(FilePath.describe("A conflicting path.")).min(1).describe("Every conflicting path, sorted in byte order (paths only, never content)."),
69
+ base: Sha.describe("The merge base used."),
70
+ fromHead: Sha.describe("The head of `from` merged."),
71
+ intoHead: Sha.describe("The head of `into`, unchanged.")
72
+ }).strict().meta({
73
+ id: "SyncStepConflict",
74
+ title: "sync step: conflict",
75
+ description: "The SyncBranchWorkflow's sync step could not merge; the instance completes with this result so the conflict can be reported and resolved by hand.",
76
+ examples: [{
77
+ status: "conflict",
78
+ paths: ["content/about.md"],
79
+ base: "4b825dc642cb6eb9a060e54bf8d69288fbee4904",
80
+ fromHead: EXAMPLE_SHA_B,
81
+ intoHead: EXAMPLE_SHA_A
82
+ }]
83
+ });
84
+ /**
85
+ * What the SyncBranchWorkflow's sync step stores and the instance returns: ids and paths only,
86
+ * never file content or a credential.
87
+ */
88
+ const SyncStepResult = z.discriminatedUnion("status", [
89
+ SyncStepUpToDate,
90
+ SyncStepFastForward,
91
+ SyncStepMerged,
92
+ SyncStepConflict
93
+ ]).meta({
94
+ id: "SyncStepResult",
95
+ title: "SyncBranchWorkflow result",
96
+ description: "What the SyncBranchWorkflow's sync step stores and the instance returns, discriminated by `status`: commit ids and conflicting paths only.",
97
+ examples: [{
98
+ status: "merged",
99
+ head: EXAMPLE_SHA_B
100
+ }]
101
+ });
102
+ export { SyncBranchWorkflowParams, SyncStepConflict, SyncStepFastForward, SyncStepMerged, SyncStepResult, SyncStepUpToDate };
103
+
104
+ //# sourceMappingURL=sync-workflow-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-workflow-schemas.js","names":[],"sources":["../../src/workflows/sync-workflow-schemas.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { EXAMPLE_SHA_A, EXAMPLE_SHA_B } from '@leed-ai/git-gateway-contract/schemas/examples';\nimport { BranchName, FilePath, RepoName } from '@leed-ai/git-gateway-contract/schemas/names';\nimport { Sha } from '@leed-ai/git-gateway-contract/schemas/sha';\nimport { z } from 'zod';\n\n/** What a SyncBranchWorkflow instance is started with. */\nexport const SyncBranchWorkflowParams = z\n .object({\n repo: RepoName.describe('Repository holding both branches.'),\n from: BranchName.describe('Branch whose commits are brought into `into`, e.g. main.'),\n into: BranchName.describe('Branch brought up to date, e.g. staging; only fast-forwarded or merged into.'),\n fromHead: Sha.describe(\n 'Head of `from` the push left; identifies the instance, so one push starts at most one sync.',\n ),\n })\n .strict()\n .refine((params) => params.from !== params.into, { message: 'from and into must differ', path: ['into'] })\n .meta({\n id: 'SyncBranchWorkflowParams',\n title: 'SyncBranchWorkflow params',\n description:\n 'The params a SyncBranchWorkflow instance is started with by an onPush sync rule: sync `into` with `from` after a push moved `from` to `fromHead`. The sync merges whatever `from` holds when it runs.',\n examples: [{ repo: 'acme-raw-content', from: 'main', into: 'staging', fromHead: EXAMPLE_SHA_B }],\n });\n\n/** SyncBranchWorkflow params, inferred from {@link SyncBranchWorkflowParams}. */\nexport type SyncBranchWorkflowParams = z.infer<typeof SyncBranchWorkflowParams>;\n\n/** `into` already contained `from`. */\nexport const SyncStepUpToDate = z\n .object({\n status: z\n .literal('up_to_date')\n .describe('`into` already contained `from` (possibly because an earlier run of the step merged it).'),\n head: Sha.describe('Head of `into`, unchanged.'),\n })\n .strict()\n .meta({\n id: 'SyncStepUpToDate',\n title: 'sync step: up to date',\n description: \"The SyncBranchWorkflow's sync step found nothing to do.\",\n examples: [{ status: 'up_to_date', head: EXAMPLE_SHA_A }],\n });\n\n/** `into` was fast-forwarded. */\nexport const SyncStepFastForward = z\n .object({\n status: z.literal('fast_forward').describe('`into` had no commits of its own and was fast-forwarded.'),\n head: Sha.describe('New head of `into`, the head of `from`.'),\n })\n .strict()\n .meta({\n id: 'SyncStepFastForward',\n title: 'sync step: fast-forward',\n description: \"The SyncBranchWorkflow's sync step fast-forwarded `into`.\",\n examples: [{ status: 'fast_forward', head: EXAMPLE_SHA_B }],\n });\n\n/** A merge commit was written. */\nexport const SyncStepMerged = z\n .object({\n status: z.literal('merged').describe('Both branches had commits; a file-level merge commit was written.'),\n head: Sha.describe('New head of `into`, the merge commit.'),\n })\n .strict()\n .meta({\n id: 'SyncStepMerged',\n title: 'sync step: merged',\n description: \"The SyncBranchWorkflow's sync step wrote a merge commit to `into`.\",\n examples: [{ status: 'merged', head: EXAMPLE_SHA_B }],\n });\n\n/** The branches conflict. */\nexport const SyncStepConflict = z\n .object({\n status: z\n .literal('conflict')\n .describe(\n 'Some paths changed differently on both sides; nothing was written and retrying cannot help.',\n ),\n paths: z\n .array(FilePath.describe('A conflicting path.'))\n .min(1)\n .describe('Every conflicting path, sorted in byte order (paths only, never content).'),\n base: Sha.describe('The merge base used.'),\n fromHead: Sha.describe('The head of `from` merged.'),\n intoHead: Sha.describe('The head of `into`, unchanged.'),\n })\n .strict()\n .meta({\n id: 'SyncStepConflict',\n title: 'sync step: conflict',\n description:\n \"The SyncBranchWorkflow's sync step could not merge; the instance completes with this result so the conflict can be reported and resolved by hand.\",\n examples: [\n {\n status: 'conflict',\n paths: ['content/about.md'],\n base: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',\n fromHead: EXAMPLE_SHA_B,\n intoHead: EXAMPLE_SHA_A,\n },\n ],\n });\n\n/**\n * What the SyncBranchWorkflow's sync step stores and the instance returns: ids and paths only,\n * never file content or a credential.\n */\nexport const SyncStepResult = z\n .discriminatedUnion('status', [SyncStepUpToDate, SyncStepFastForward, SyncStepMerged, SyncStepConflict])\n .meta({\n id: 'SyncStepResult',\n title: 'SyncBranchWorkflow result',\n description:\n \"What the SyncBranchWorkflow's sync step stores and the instance returns, discriminated by `status`: commit ids and conflicting paths only.\",\n examples: [{ status: 'merged', head: EXAMPLE_SHA_B }],\n });\n\n/** A SyncBranchWorkflow result, inferred from {@link SyncStepResult}. */\nexport type SyncStepResult = z.infer<typeof SyncStepResult>;\n"],"mappings":";;;;;;AAOA,MAAa,2BAA2B,EACrC,OAAO;CACN,MAAM,SAAS,SAAS,mCAAmC;CAC3D,MAAM,WAAW,SAAS,0DAA0D;CACpF,MAAM,WAAW,SAAS,8EAA8E;CACxG,UAAU,IAAI,SACZ,6FACF;AACF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,QAAQ,WAAW,OAAO,SAAS,OAAO,MAAM;CAAE,SAAS;CAA6B,MAAM,CAAC,MAAM;AAAE,CAAC,CAAC,CACzG,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,MAAM;EAAoB,MAAM;EAAQ,MAAM;EAAW,UAAU;CAAc,CAAC;AACjG,CAAC;;AAMH,MAAa,mBAAmB,EAC7B,OAAO;CACN,QAAQ,EACL,QAAQ,YAAY,CAAC,CACrB,SAAS,0FAA0F;CACtG,MAAM,IAAI,SAAS,4BAA4B;AACjD,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAc,MAAM;CAAc,CAAC;AAC1D,CAAC;;AAGH,MAAa,sBAAsB,EAChC,OAAO;CACN,QAAQ,EAAE,QAAQ,cAAc,CAAC,CAAC,SAAS,0DAA0D;CACrG,MAAM,IAAI,SAAS,yCAAyC;AAC9D,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAgB,MAAM;CAAc,CAAC;AAC5D,CAAC;;AAGH,MAAa,iBAAiB,EAC3B,OAAO;CACN,QAAQ,EAAE,QAAQ,QAAQ,CAAC,CAAC,SAAS,mEAAmE;CACxG,MAAM,IAAI,SAAS,uCAAuC;AAC5D,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAU,MAAM;CAAc,CAAC;AACtD,CAAC;;AAGH,MAAa,mBAAmB,EAC7B,OAAO;CACN,QAAQ,EACL,QAAQ,UAAU,CAAC,CACnB,SACC,6FACF;CACF,OAAO,EACJ,MAAM,SAAS,SAAS,qBAAqB,CAAC,CAAC,CAC/C,IAAI,CAAC,CAAC,CACN,SAAS,2EAA2E;CACvF,MAAM,IAAI,SAAS,sBAAsB;CACzC,UAAU,IAAI,SAAS,4BAA4B;CACnD,UAAU,IAAI,SAAS,gCAAgC;AACzD,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,QAAQ;EACR,OAAO,CAAC,kBAAkB;EAC1B,MAAM;EACN,UAAU;EACV,UAAU;CACZ,CACF;AACF,CAAC;;;;;AAMH,MAAa,iBAAiB,EAC3B,mBAAmB,UAAU;CAAC;CAAkB;CAAqB;CAAgB;AAAgB,CAAC,CAAC,CACvG,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAU,MAAM;CAAc,CAAC;AACtD,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A Workflow instance id derived from what identifies the work, so starting the same work twice
3
+ * names the same instance: `<prefix>-<40 hex digits>`, the SHA-1 of the parts joined by NUL.
4
+ * Always at most 100 characters of `[a-z0-9-]` for prefixes of that alphabet, which is what
5
+ * Workflows accepts as an instance id.
6
+ */
7
+ export declare function workflowInstanceId(prefix: string, parts: readonly string[]): Promise<string>;
8
+ /** The id of the CommitWorkflow instance for one idempotent commit. */
9
+ export declare function commitWorkflowId(repo: string, branch: string, idempotencyKey: string): Promise<string>;
10
+ /** The id of the SyncBranchWorkflow instance that syncs `into` with `from` at one head of `from`. */
11
+ export declare function syncWorkflowId(repo: string, from: string, into: string, fromHead: string): Promise<string>;
12
+ //# sourceMappingURL=workflow-instance-id.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { bytesToHex, sha1Bytes } from "@leed-ai/git-gateway-core/bytes";
2
+ import { utf8 } from "@leed-ai/git-gateway-contract/reference/bytes";
3
+ // src/workflows/workflow-instance-id.ts
4
+ /**
5
+ * A Workflow instance id derived from what identifies the work, so starting the same work twice
6
+ * names the same instance: `<prefix>-<40 hex digits>`, the SHA-1 of the parts joined by NUL.
7
+ * Always at most 100 characters of `[a-z0-9-]` for prefixes of that alphabet, which is what
8
+ * Workflows accepts as an instance id.
9
+ */
10
+ async function workflowInstanceId(prefix, parts) {
11
+ if (!/^[a-z][a-z0-9-]{0,40}$/.test(prefix)) throw new RangeError(`workflowInstanceId: invalid prefix ${JSON.stringify(prefix)}`);
12
+ return `${prefix}-${bytesToHex(await sha1Bytes(utf8(parts.join("\0"))))}`;
13
+ }
14
+ /** The id of the CommitWorkflow instance for one idempotent commit. */
15
+ function commitWorkflowId(repo, branch, idempotencyKey) {
16
+ return workflowInstanceId("commit", [
17
+ repo,
18
+ branch,
19
+ idempotencyKey
20
+ ]);
21
+ }
22
+ /** The id of the SyncBranchWorkflow instance that syncs `into` with `from` at one head of `from`. */
23
+ function syncWorkflowId(repo, from, into, fromHead) {
24
+ return workflowInstanceId("sync", [
25
+ repo,
26
+ from,
27
+ into,
28
+ fromHead
29
+ ]);
30
+ }
31
+ export { commitWorkflowId, syncWorkflowId, workflowInstanceId };
32
+
33
+ //# sourceMappingURL=workflow-instance-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-instance-id.js","names":[],"sources":["../../src/workflows/workflow-instance-id.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { utf8 } from '@leed-ai/git-gateway-contract/reference/bytes';\nimport { bytesToHex, sha1Bytes } from '@leed-ai/git-gateway-core/bytes';\n\n/**\n * A Workflow instance id derived from what identifies the work, so starting the same work twice\n * names the same instance: `<prefix>-<40 hex digits>`, the SHA-1 of the parts joined by NUL.\n * Always at most 100 characters of `[a-z0-9-]` for prefixes of that alphabet, which is what\n * Workflows accepts as an instance id.\n */\nexport async function workflowInstanceId(prefix: string, parts: readonly string[]): Promise<string> {\n if (!/^[a-z][a-z0-9-]{0,40}$/.test(prefix)) {\n throw new RangeError(`workflowInstanceId: invalid prefix ${JSON.stringify(prefix)}`);\n }\n return `${prefix}-${bytesToHex(await sha1Bytes(utf8(parts.join('\\0'))))}`;\n}\n\n/** The id of the CommitWorkflow instance for one idempotent commit. */\nexport function commitWorkflowId(repo: string, branch: string, idempotencyKey: string): Promise<string> {\n return workflowInstanceId('commit', [repo, branch, idempotencyKey]);\n}\n\n/** The id of the SyncBranchWorkflow instance that syncs `into` with `from` at one head of `from`. */\nexport function syncWorkflowId(repo: string, from: string, into: string, fromHead: string): Promise<string> {\n return workflowInstanceId('sync', [repo, from, into, fromHead]);\n}\n"],"mappings":";;;;;;;;;AAUA,eAAsB,mBAAmB,QAAgB,OAA2C;CAClG,IAAI,CAAC,yBAAyB,KAAK,MAAM,GACvC,MAAM,IAAI,WAAW,sCAAsC,KAAK,UAAU,MAAM,GAAG;CAErF,OAAO,GAAG,OAAO,GAAG,WAAW,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC;AACxE;;AAGA,SAAgB,iBAAiB,MAAc,QAAgB,gBAAyC;CACtG,OAAO,mBAAmB,UAAU;EAAC;EAAM;EAAQ;CAAc,CAAC;AACpE;;AAGA,SAAgB,eAAe,MAAc,MAAc,MAAc,UAAmC;CAC1G,OAAO,mBAAmB,QAAQ;EAAC;EAAM;EAAM;EAAM;CAAQ,CAAC;AAChE"}
@@ -0,0 +1,7 @@
1
+ import { FatalError, StepRunner } from "./step-runner.js";
2
+ import { WorkflowStep } from "cloudflare:workers";
3
+ /** A Workflows `WorkflowStep` as the gateway's {@link StepRunner}. */
4
+ export declare function stepRunnerOf(step: WorkflowStep): StepRunner;
5
+ /** Stops a Workflow instance without retries, keeping the error's message (and any GatewayError body in it). */
6
+ export declare const nonRetryable: FatalError;
7
+ //# sourceMappingURL=workflow-runtime.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { NonRetryableError } from "cloudflare:workflows";
2
+ // src/workflows/workflow-runtime.ts
3
+ /** A Workflows `WorkflowStep` as the gateway's {@link StepRunner}. */
4
+ function stepRunnerOf(step) {
5
+ return { do: (name, config, callback) => step.do(name, config, callback) };
6
+ }
7
+ /** Stops a Workflow instance without retries, keeping the error's message (and any GatewayError body in it). */
8
+ const nonRetryable = (error) => new NonRetryableError(error.message, error.name);
9
+ export { nonRetryable, stepRunnerOf };
10
+
11
+ //# sourceMappingURL=workflow-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-runtime.js","names":[],"sources":["../../src/workflows/workflow-runtime.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { WorkflowStep } from 'cloudflare:workers';\nimport { NonRetryableError } from 'cloudflare:workflows';\n\nimport type { FatalError, StepRunner } from './step-runner.ts';\n\n/** A Workflows `WorkflowStep` as the gateway's {@link StepRunner}. */\nexport function stepRunnerOf(step: WorkflowStep): StepRunner {\n return { do: (name, config, callback) => step.do(name, config, callback) };\n}\n\n/** Stops a Workflow instance without retries, keeping the error's message (and any GatewayError body in it). */\nexport const nonRetryable: FatalError = (error) => new NonRetryableError(error.message, error.name);\n"],"mappings":";;;AAOA,SAAgB,aAAa,MAAgC;CAC3D,OAAO,EAAE,KAAK,MAAM,QAAQ,aAAa,KAAK,GAAG,MAAM,QAAQ,QAAQ,EAAE;AAC3E;;AAGA,MAAa,gBAA4B,UAAU,IAAI,kBAAkB,MAAM,SAAS,MAAM,IAAI"}
@@ -0,0 +1,2 @@
1
+ import { i as startWorkflowOnce, n as WorkflowStart, r as WorkflowStarter, t as WorkflowHandle } from "../workflow-starter-BqhwX6oA.js";
2
+ export { WorkflowHandle, WorkflowStart, WorkflowStarter, startWorkflowOnce };
@@ -0,0 +1,40 @@
1
+ import { storageUnavailable } from "@leed-ai/git-gateway-contract/storage/storage-errors";
2
+ // src/workflows/workflow-starter.ts
3
+ /** Instance states after which the instance will never run again unless restarted. */
4
+ const DEAD_STATES = /* @__PURE__ */ new Set(["errored", "terminated"]);
5
+ /**
6
+ * Starts a Workflow instance under a deterministic id, at most once while it lives: when the id
7
+ * is already taken by a queued, running, waiting, paused or complete instance (the same write was
8
+ * handed off before), that instance stands and nothing new starts. When the instance under the id
9
+ * is dead — errored after its retries ran out, or terminated — it is restarted, so retrying the
10
+ * same write is never answered by an instance that will not run. Restarting is safe because the
11
+ * workflows' steps are idempotent. Throws storage_unavailable when the instance can be neither
12
+ * created nor found, or when its status cannot be read or it cannot be restarted.
13
+ */
14
+ async function startWorkflowOnce(starter, id, params) {
15
+ try {
16
+ await starter.create({
17
+ id,
18
+ params
19
+ });
20
+ return "created";
21
+ } catch (createError) {
22
+ let handle;
23
+ try {
24
+ handle = await starter.get(id);
25
+ } catch {
26
+ throw storageUnavailable(`start workflow instance ${id}`, createError);
27
+ }
28
+ try {
29
+ const { status } = await handle.status();
30
+ if (!DEAD_STATES.has(status)) return "existing";
31
+ await handle.restart();
32
+ return "restarted";
33
+ } catch (error) {
34
+ throw storageUnavailable(`restart workflow instance ${id}`, error);
35
+ }
36
+ }
37
+ }
38
+ export { startWorkflowOnce };
39
+
40
+ //# sourceMappingURL=workflow-starter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-starter.js","names":[],"sources":["../../src/workflows/workflow-starter.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';\n\n/**\n * The part of a Workflows instance handle (`WorkflowInstance`) the gateway uses: read its status,\n * or run it again from the start with the params it was created with.\n */\nexport interface WorkflowHandle {\n readonly id: string;\n /** The instance's current status; `status` is one of the Workflows instance states. */\n status(): Promise<{ readonly status: string }>;\n /** Runs the instance again from its first step, with the params it was created with. */\n restart(): Promise<void>;\n}\n\n/**\n * The part of a Workflows binding (`env.COMMIT_WORKFLOW`) the gateway uses: start an instance\n * under a chosen id, or look one up. A real `Workflow<P>` binding satisfies it; tests pass a fake.\n */\nexport interface WorkflowStarter<P> {\n /** Starts an instance with this id and params; rejects when the id is already taken. */\n create(options: { id: string; params: P }): Promise<{ readonly id: string }>;\n /** The instance with this id; rejects when there is none. */\n get(id: string): Promise<WorkflowHandle>;\n}\n\n/**\n * What {@link startWorkflowOnce} did: started a new instance, found a live or finished one\n * already under the id, or found a dead one (errored or terminated) and restarted it.\n */\nexport type WorkflowStart = 'created' | 'existing' | 'restarted';\n\n/** Instance states after which the instance will never run again unless restarted. */\nconst DEAD_STATES: ReadonlySet<string> = new Set(['errored', 'terminated']);\n\n/**\n * Starts a Workflow instance under a deterministic id, at most once while it lives: when the id\n * is already taken by a queued, running, waiting, paused or complete instance (the same write was\n * handed off before), that instance stands and nothing new starts. When the instance under the id\n * is dead — errored after its retries ran out, or terminated — it is restarted, so retrying the\n * same write is never answered by an instance that will not run. Restarting is safe because the\n * workflows' steps are idempotent. Throws storage_unavailable when the instance can be neither\n * created nor found, or when its status cannot be read or it cannot be restarted.\n */\nexport async function startWorkflowOnce<P>(\n starter: WorkflowStarter<P>,\n id: string,\n params: P,\n): Promise<WorkflowStart> {\n try {\n await starter.create({ id, params });\n return 'created';\n } catch (createError) {\n let handle: WorkflowHandle;\n try {\n handle = await starter.get(id);\n } catch {\n throw storageUnavailable(`start workflow instance ${id}`, createError);\n }\n try {\n const { status } = await handle.status();\n if (!DEAD_STATES.has(status)) return 'existing';\n await handle.restart();\n return 'restarted';\n } catch (error) {\n throw storageUnavailable(`restart workflow instance ${id}`, error);\n }\n }\n}\n"],"mappings":";;;AAiCA,MAAM,8BAAmC,IAAI,IAAI,CAAC,WAAW,YAAY,CAAC;;;;;;;;;;AAW1E,eAAsB,kBACpB,SACA,IACA,QACwB;CACxB,IAAI;EACF,MAAM,QAAQ,OAAO;GAAE;GAAI;EAAO,CAAC;EACnC,OAAO;CACT,SAAS,aAAa;EACpB,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,QAAQ,IAAI,EAAE;EAC/B,QAAQ;GACN,MAAM,mBAAmB,2BAA2B,MAAM,WAAW;EACvE;EACA,IAAI;GACF,MAAM,EAAE,WAAW,MAAM,OAAO,OAAO;GACvC,IAAI,CAAC,YAAY,IAAI,MAAM,GAAG,OAAO;GACrC,MAAM,OAAO,QAAQ;GACrB,OAAO;EACT,SAAS,OAAO;GACd,MAAM,mBAAmB,6BAA6B,MAAM,KAAK;EACnE;CACF;AACF"}