@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,57 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';
3
+ import { gatewayError } from '@leed-ai/git-gateway-contract/gateway-error';
4
+
5
+ import type { GatewayContext } from './gateway-context.ts';
6
+ import { attemptPromote, type PromoteParams } from './promote-attempt.ts';
7
+ import { branchHead } from './repo-access.ts';
8
+ import { attemptSync, type SyncParams } from './sync-attempt.ts';
9
+
10
+ /** The stale_head error for a branch that kept moving through every inline attempt. */
11
+ async function stillMoving(
12
+ context: GatewayContext,
13
+ repo: string,
14
+ branch: string,
15
+ expectedHead: string | null,
16
+ ): Promise<Error> {
17
+ return gatewayError('stale_head', `Branch ${branch} kept moving; retry`, {
18
+ branch,
19
+ expectedHead,
20
+ actualHead: await branchHead(context, repo, branch),
21
+ });
22
+ }
23
+
24
+ /**
25
+ * syncBranch(): up to `1 + config.inlineRetries` attempts, each re-reading both heads. When
26
+ * `into` moved under every attempt, stale_head (retryable by the caller, or by a
27
+ * SyncBranchWorkflow).
28
+ */
29
+ export async function gatewaySyncBranch(
30
+ context: GatewayContext,
31
+ input: SyncParams,
32
+ ): Promise<RpcOutput<'syncBranch'>> {
33
+ let lastHead: string | null = null;
34
+ for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
35
+ const outcome = await attemptSync(context, input);
36
+ if (outcome.kind === 'done') return outcome.output;
37
+ lastHead = outcome.intoHead;
38
+ }
39
+ throw await stillMoving(context, input.repo, input.into, lastHead);
40
+ }
41
+
42
+ /**
43
+ * promote(): up to `1 + config.inlineRetries` attempts, each re-checking both refusals against
44
+ * the current heads. When `into` moved under every attempt, stale_head.
45
+ */
46
+ export async function gatewayPromote(
47
+ context: GatewayContext,
48
+ input: PromoteParams,
49
+ ): Promise<RpcOutput<'promote'>> {
50
+ let lastHead: string | null = null;
51
+ for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
52
+ const outcome = await attemptPromote(context, input);
53
+ if (outcome.kind === 'done') return outcome.output;
54
+ lastHead = outcome.intoHead;
55
+ }
56
+ throw await stillMoving(context, input.repo, input.into, lastHead);
57
+ }
@@ -0,0 +1,87 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { RpcOutput, RpcParsedInput } from '@leed-ai/git-gateway-contract/git-gateway';
3
+ import { gatewayError } from '@leed-ai/git-gateway-contract/gateway-error';
4
+ import { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';
5
+ import { buildCommit } from '@leed-ai/git-gateway-core/commit/build-commit';
6
+ import { findIdempotentCommit } from '@leed-ai/git-gateway-core/idempotency/find-idempotent-commit';
7
+
8
+ import type { GatewayContext } from './gateway-context.ts';
9
+ import { pushRefUpdate } from './push-ref.ts';
10
+ import { branchHead, hasBranches, requireBranchHead, requireCommit, treeReader } from './repo-access.ts';
11
+
12
+ /** commit() input after parsing. */
13
+ export type CommitParams = RpcParsedInput<'commit'>;
14
+
15
+ /** The outcome of one commit attempt. */
16
+ export type CommitAttempt =
17
+ /** Finished: committed, replayed or no-op. Never "queued"; handing off is the caller's choice. */
18
+ | { readonly kind: 'done'; readonly output: Exclude<RpcOutput<'commit'>, { status: 'queued' }> }
19
+ /** The push was refused because the branch moved; rebuild on `head` and try again. */
20
+ | { readonly kind: 'stale'; readonly head: string | null };
21
+
22
+ /** The commit a missing branch starts from: the start branch's head, none (a root commit), or ref_not_found. */
23
+ async function startOf(context: GatewayContext, input: CommitParams): Promise<string | null> {
24
+ if (input.startBranch !== undefined) return requireBranchHead(context, input.repo, input.startBranch);
25
+ if (!(await hasBranches(context, input.repo))) return null;
26
+ throw gatewayError('ref_not_found', `Branch not found: ${input.branch}`, { ref: input.branch });
27
+ }
28
+
29
+ /**
30
+ * One attempt at commit(), in the contract's order: idempotency replay (a commit carrying the key
31
+ * in the branch's recent history is returned as is), then the stale-head check against
32
+ * `expectedHead`, then the actions — built without a clone on the current head and pushed with an
33
+ * update naming that head. Safe to repeat any number of times, including after a crash between
34
+ * the push and recording its result: the next attempt finds the pushed commit by its key.
35
+ */
36
+ export async function attemptCommit(context: GatewayContext, input: CommitParams): Promise<CommitAttempt> {
37
+ const { repo, branch } = input;
38
+ const head = await branchHead(context, repo, branch);
39
+ if (head !== null) {
40
+ const replay = await findIdempotentCommit(
41
+ {
42
+ head,
43
+ key: input.idempotencyKey,
44
+ window: context.config.idempotency,
45
+ now: context.now().toISOString(),
46
+ },
47
+ { readCommit: (sha) => context.backend.readCommit(repo, sha) },
48
+ );
49
+ if (replay !== null) return { kind: 'done', output: { status: 'replayed', commit: replay } };
50
+ }
51
+ if (input.expectedHead !== undefined && input.expectedHead !== head) {
52
+ throw gatewayError('stale_head', `Branch ${branch} moved`, {
53
+ branch,
54
+ expectedHead: input.expectedHead,
55
+ actualHead: head,
56
+ });
57
+ }
58
+ const baseSha = head ?? (await startOf(context, input));
59
+ const base =
60
+ baseSha === null ? null : { sha: baseSha, tree: (await requireCommit(context, repo, baseSha)).tree };
61
+ const built = await buildCommit(
62
+ {
63
+ branch,
64
+ base,
65
+ oldSha: head,
66
+ actions: input.actions,
67
+ message: input.message,
68
+ author: input.author,
69
+ ...(input.committer === undefined ? {} : { committer: input.committer }),
70
+ idempotencyKey: input.idempotencyKey,
71
+ date: context.now().toISOString(),
72
+ },
73
+ treeReader(context, repo),
74
+ );
75
+ if (built.status === 'noop') return { kind: 'done', output: { status: 'noop', head } };
76
+ const pushed = await pushRefUpdate(context, repo, built.refUpdate, built.objects);
77
+ if (pushed.status === 'ok') {
78
+ return {
79
+ kind: 'done',
80
+ output: { status: 'committed', commit: built.commit, refUpdate: built.refUpdate },
81
+ };
82
+ }
83
+ const current = await branchHead(context, repo, branch);
84
+ // A refusal while the branch still names the head we built on is not contention: the host said no.
85
+ if (current === head) throw storageUnavailable(`push to ${built.refUpdate.ref}`, pushed.reason);
86
+ return { kind: 'stale', head: current };
87
+ }
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';
3
+
4
+ import type { CommitSource } from './commit-source.ts';
5
+ import type { GatewayContext } from './gateway-context.ts';
6
+ import { isAncestor, mergeBaseOf } from './paint-down.ts';
7
+
8
+ /**
9
+ * The commits of one repository, read through the backend on demand and kept for the duration of
10
+ * one call (commits are immutable, so the cache can never go stale). Ancestry questions are
11
+ * answered with git's paint-down walk, which reads only the history between the commits asked
12
+ * about and their merge base — never the whole history of a branch.
13
+ */
14
+ export class CommitGraph implements CommitSource {
15
+ readonly #context: GatewayContext;
16
+ readonly #repo: string;
17
+ readonly #commits = new Map<string, Promise<Commit | null>>();
18
+
19
+ constructor(context: GatewayContext, repo: string) {
20
+ this.#context = context;
21
+ this.#repo = repo;
22
+ }
23
+
24
+ /** The commit with this id, or null when the repository has none; each id is read once. */
25
+ commit(sha: string): Promise<Commit | null> {
26
+ let read = this.#commits.get(sha);
27
+ if (read === undefined) {
28
+ read = this.#context.backend.readCommit(this.#repo, sha);
29
+ this.#commits.set(sha, read);
30
+ read.catch(() => this.#commits.delete(sha));
31
+ }
32
+ return read;
33
+ }
34
+
35
+ /** True when `ancestor` is reachable from `descendant` (a commit contains itself). */
36
+ contains(descendant: string, ancestor: string): Promise<boolean> {
37
+ return isAncestor(this, descendant, ancestor);
38
+ }
39
+
40
+ /** The reference's merge base of two commits, or null when their histories are unrelated. */
41
+ mergeBase(a: string, b: string): Promise<string | null> {
42
+ return mergeBaseOf(this, a, b);
43
+ }
44
+ }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';
3
+ import { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';
4
+
5
+ import { commitWorkflowId } from '../workflows/workflow-instance-id.ts';
6
+ import { startWorkflowOnce } from '../workflows/workflow-starter.ts';
7
+ import { attemptCommit, type CommitParams } from './commit-attempt.ts';
8
+ import type { GatewayContext } from './gateway-context.ts';
9
+
10
+ /**
11
+ * commit(): up to `1 + config.inlineRetries` attempts, each rebuilt on the head that beat the
12
+ * previous one. When every attempt lost a race, the same input — idempotency key included — is
13
+ * handed to a CommitWorkflow under an id derived from repository, branch and key (so handing the
14
+ * same commit off twice starts one instance) and `queued` is returned with that id. When the
15
+ * instance under that id has errored or been terminated, it is restarted, so a retry with the same
16
+ * key is never answered by an instance that will not run.
17
+ */
18
+ export async function gatewayCommit(
19
+ context: GatewayContext,
20
+ input: CommitParams,
21
+ ): Promise<RpcOutput<'commit'>> {
22
+ for (let attempt = 0; attempt <= context.config.inlineRetries; attempt += 1) {
23
+ const outcome = await attemptCommit(context, input);
24
+ if (outcome.kind === 'done') return outcome.output;
25
+ }
26
+ const workflow = context.commitWorkflow;
27
+ if (workflow === undefined) {
28
+ throw storageUnavailable(
29
+ `commit to ${input.branch}`,
30
+ 'the branch kept moving and no CommitWorkflow is configured to finish the commit',
31
+ );
32
+ }
33
+ const workflowInstanceId = await commitWorkflowId(input.repo, input.branch, input.idempotencyKey);
34
+ await startWorkflowOnce(workflow, workflowInstanceId, input);
35
+ return { status: 'queued', workflowInstanceId };
36
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';
3
+
4
+ /** Reads commits one at a time by id, as `CommitGraph` does over a backend. */
5
+ export interface CommitSource {
6
+ /** The commit with this id, or null when the repository has none. */
7
+ commit(sha: string): Promise<Commit | null>;
8
+ }
9
+
10
+ /**
11
+ * Orders committer dates the way the contract's reference history does: as strings. Every walk
12
+ * that must agree with the reference compares dates with this, never with `Date.parse`.
13
+ */
14
+ export const dateOrder = (a: Commit, b: Commit): number =>
15
+ a.committer.date === b.committer.date ? 0 : a.committer.date > b.committer.date ? 1 : -1;
@@ -0,0 +1,77 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { GatewayConfig, type GatewayConfigInput } from '@leed-ai/git-gateway-contract/schemas/gateway-config';
3
+ import type { StorageBackend } from '@leed-ai/git-gateway-contract/storage/storage-backend';
4
+ import type { FetchLike } from '@leed-ai/git-gateway-core/smart-http/git-http-client';
5
+
6
+ import type { CommitWorkflowParams } from '../workflows/commit-workflow-schemas.ts';
7
+ import { composeOnPush, type OnPushHook } from '../workflows/on-push.ts';
8
+ import type { SyncBranchWorkflowParams } from '../workflows/sync-workflow-schemas.ts';
9
+ import type { WorkflowStarter } from '../workflows/workflow-starter.ts';
10
+ import { ReadTokenSecret } from './read-token.ts';
11
+
12
+ /** How a deployment composes the RPC service and its Workflows. */
13
+ export interface GatewayOptions {
14
+ /** Where the repositories live. */
15
+ readonly backend: StorageBackend;
16
+ /** Gateway configuration; every field has a default. */
17
+ readonly config?: GatewayConfigInput;
18
+ /** HMAC key read tokens are signed with (see {@link ReadTokenSecret}). */
19
+ readonly readTokenSecret: string;
20
+ /** How pushes reach the backend's git remote; default the global `fetch`. */
21
+ readonly fetch?: FetchLike;
22
+ /** The clock for commit dates, token expiry and the idempotency window; default the system clock. */
23
+ readonly now?: () => Date;
24
+ /** The CommitWorkflow binding commits are handed to when inline retries run out. */
25
+ readonly commitWorkflow?: WorkflowStarter<CommitWorkflowParams>;
26
+ /**
27
+ * The SyncBranchWorkflow binding `config.syncRules` start instances of after every ref update
28
+ * the RPC API pushes; required when there are sync rules.
29
+ */
30
+ readonly syncWorkflow?: WorkflowStarter<SyncBranchWorkflowParams>;
31
+ /**
32
+ * Called after every ref update the RPC API or its Workflows push (commits, syncs, promotions),
33
+ * beside the sync rules, e.g. to send the event to a Queue. The write has
34
+ * already happened, so a failure is reported to {@link onPushError} and does not fail the call.
35
+ */
36
+ readonly onPush?: OnPushHook;
37
+ /** Receives onPush failures, e.g. to log or count them; default: they are dropped. */
38
+ readonly onPushError?: (error: unknown) => void;
39
+ }
40
+
41
+ /** {@link GatewayOptions} validated, with defaults applied; what every method works with. */
42
+ export interface GatewayContext {
43
+ readonly backend: StorageBackend;
44
+ readonly config: GatewayConfig;
45
+ readonly readTokenSecret: string;
46
+ readonly fetch: FetchLike | undefined;
47
+ readonly now: () => Date;
48
+ readonly commitWorkflow: WorkflowStarter<CommitWorkflowParams> | undefined;
49
+ /** The sync rules and the deployment's own hook, composed (see composeOnPush). */
50
+ readonly onPush: OnPushHook | undefined;
51
+ readonly onPushError: (error: unknown) => void;
52
+ }
53
+
54
+ /** The default onPush failure handler: the failure is dropped (the write itself succeeded). */
55
+ const ignorePushHookError = (): void => undefined;
56
+
57
+ /**
58
+ * Validates options (the configuration and the secret, with Zod) and applies the defaults. Throws
59
+ * a TypeError when sync rules are configured without a `syncWorkflow`.
60
+ */
61
+ export function gatewayContext(options: GatewayOptions): GatewayContext {
62
+ const config = GatewayConfig.parse(options.config ?? {});
63
+ return {
64
+ backend: options.backend,
65
+ config,
66
+ readTokenSecret: ReadTokenSecret.parse(options.readTokenSecret),
67
+ fetch: options.fetch,
68
+ now: options.now ?? (() => new Date()),
69
+ commitWorkflow: options.commitWorkflow,
70
+ onPush: composeOnPush({
71
+ syncRules: config.syncRules,
72
+ syncWorkflow: options.syncWorkflow,
73
+ onPush: options.onPush,
74
+ }),
75
+ onPushError: options.onPushError ?? ignorePushHookError,
76
+ };
77
+ }
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { RPC_SCHEMAS, type GitGateway } from '@leed-ai/git-gateway-contract/git-gateway';
3
+ import { runMethod } from '@leed-ai/git-gateway-contract/reference/run-method';
4
+ import { storageUnavailable } from '@leed-ai/git-gateway-contract/storage/storage-errors';
5
+ import { isCoreError } from '@leed-ai/git-gateway-core/core-error';
6
+
7
+ import { gatewayPromote, gatewaySyncBranch } from './branch-methods.ts';
8
+ import { gatewayCommit } from './commit-method.ts';
9
+ import { gatewayContext, type GatewayOptions } from './gateway-context.ts';
10
+ import { gatewayCreateRepo, gatewayDeleteRepo, gatewayMintReadToken } from './lifecycle-methods.ts';
11
+ import {
12
+ gatewayCommitExists,
13
+ gatewayListTree,
14
+ gatewayLog,
15
+ gatewayReadFile,
16
+ gatewayResolveRef,
17
+ } from './read-methods.ts';
18
+
19
+ /**
20
+ * Runs a method's work so that a core error (an object the backend handed back that is missing or
21
+ * malformed) is reported as storage_unavailable: storage cannot be trusted for this call.
22
+ */
23
+ async function guarded<T>(name: string, work: () => Promise<T>): Promise<T> {
24
+ try {
25
+ return await work();
26
+ } catch (thrown) {
27
+ if (isCoreError(thrown)) throw storageUnavailable(name, thrown);
28
+ throw thrown;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * The gateway's {@link GitGateway} over a storage backend: the methods the RPC entrypoint serves,
34
+ * usable directly wherever a gateway is needed in-process (tests, a deployment's own Worker).
35
+ * Every input is parsed with its contract schema before anything is read (invalid_input) and
36
+ * every output with its schema before it is returned; errors are GatewayErrors.
37
+ */
38
+ export function createGatewayRpc(options: GatewayOptions): GitGateway {
39
+ const context = gatewayContext(options);
40
+ const s = RPC_SCHEMAS;
41
+ return {
42
+ commit: (input) => runMethod(s.commit, input, (p) => guarded('commit', () => gatewayCommit(context, p))),
43
+ readFile: (input) =>
44
+ runMethod(s.readFile, input, (p) => guarded('readFile', () => gatewayReadFile(context, p))),
45
+ listTree: (input) =>
46
+ runMethod(s.listTree, input, (p) => guarded('listTree', () => gatewayListTree(context, p))),
47
+ resolveRef: (input) =>
48
+ runMethod(s.resolveRef, input, (p) => guarded('resolveRef', () => gatewayResolveRef(context, p))),
49
+ log: (input) => runMethod(s.log, input, (p) => guarded('log', () => gatewayLog(context, p))),
50
+ commitExists: (input) =>
51
+ runMethod(s.commitExists, input, (p) => guarded('commitExists', () => gatewayCommitExists(context, p))),
52
+ syncBranch: (input) =>
53
+ runMethod(s.syncBranch, input, (p) => guarded('syncBranch', () => gatewaySyncBranch(context, p))),
54
+ promote: (input) =>
55
+ runMethod(s.promote, input, (p) => guarded('promote', () => gatewayPromote(context, p))),
56
+ createRepo: (input) =>
57
+ runMethod(s.createRepo, input, (p) => guarded('createRepo', () => gatewayCreateRepo(context, p))),
58
+ deleteRepo: (input) =>
59
+ runMethod(s.deleteRepo, input, (p) => guarded('deleteRepo', () => gatewayDeleteRepo(context, p))),
60
+ mintReadToken: (input) =>
61
+ runMethod(s.mintReadToken, input, (p) =>
62
+ guarded('mintReadToken', () => gatewayMintReadToken(context, p)),
63
+ ),
64
+ };
65
+ }
@@ -0,0 +1,85 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { WorkerEntrypoint } from 'cloudflare:workers';
3
+ import type { GitGateway, RpcInput, RpcOutput } from '@leed-ai/git-gateway-contract/git-gateway';
4
+
5
+ import type { GatewayOptions } from './gateway-context.ts';
6
+ import { createGatewayRpc } from './gateway-rpc.ts';
7
+
8
+ /** Builds a deployment's {@link GatewayOptions} from its Worker environment (bindings and secrets). */
9
+ export type GatewayOptionsResolver<Env> = (env: Env) => GatewayOptions;
10
+
11
+ /** The RPC entrypoint class {@link createGatewayService} returns. */
12
+ export type GatewayServiceClass<Env> = new (
13
+ ctx: ExecutionContext,
14
+ env: Env,
15
+ ) => WorkerEntrypoint<Env> & GitGateway;
16
+
17
+ /**
18
+ * The git-gateway RPC API as a `WorkerEntrypoint`, for other Workers to call over a service
19
+ * binding. A deployment exports the returned class under a name of its choosing and binds it:
20
+ *
21
+ * export const GatewayService = createGatewayService((env: Env) => ({
22
+ * backend: new ArtifactsBackend(env.ARTIFACTS),
23
+ * readTokenSecret: env.READ_TOKEN_SECRET,
24
+ * commitWorkflow: env.COMMIT_WORKFLOW,
25
+ * }));
26
+ *
27
+ * Every method validates its input and output with the contract schemas. Errors are
28
+ * GatewayErrors, whose message carries the error body so callers recover it with
29
+ * `readGatewayError` on the far side of the binding. The options (and the secret in them) live in
30
+ * a closure, never on the class, so no RPC call can reach them.
31
+ */
32
+ export function createGatewayService<Env>(resolve: GatewayOptionsResolver<Env>): GatewayServiceClass<Env> {
33
+ return class GatewayService extends WorkerEntrypoint<Env> implements GitGateway {
34
+ #gateway: GitGateway | undefined;
35
+
36
+ #rpc(): GitGateway {
37
+ this.#gateway ??= createGatewayRpc(resolve(this.env));
38
+ return this.#gateway;
39
+ }
40
+
41
+ async commit(input: RpcInput<'commit'>): Promise<RpcOutput<'commit'>> {
42
+ return await this.#rpc().commit(input);
43
+ }
44
+
45
+ async readFile(input: RpcInput<'readFile'>): Promise<RpcOutput<'readFile'>> {
46
+ return await this.#rpc().readFile(input);
47
+ }
48
+
49
+ async listTree(input: RpcInput<'listTree'>): Promise<RpcOutput<'listTree'>> {
50
+ return await this.#rpc().listTree(input);
51
+ }
52
+
53
+ async resolveRef(input: RpcInput<'resolveRef'>): Promise<RpcOutput<'resolveRef'>> {
54
+ return await this.#rpc().resolveRef(input);
55
+ }
56
+
57
+ async log(input: RpcInput<'log'>): Promise<RpcOutput<'log'>> {
58
+ return await this.#rpc().log(input);
59
+ }
60
+
61
+ async commitExists(input: RpcInput<'commitExists'>): Promise<RpcOutput<'commitExists'>> {
62
+ return await this.#rpc().commitExists(input);
63
+ }
64
+
65
+ async syncBranch(input: RpcInput<'syncBranch'>): Promise<RpcOutput<'syncBranch'>> {
66
+ return await this.#rpc().syncBranch(input);
67
+ }
68
+
69
+ async promote(input: RpcInput<'promote'>): Promise<RpcOutput<'promote'>> {
70
+ return await this.#rpc().promote(input);
71
+ }
72
+
73
+ async createRepo(input: RpcInput<'createRepo'>): Promise<RpcOutput<'createRepo'>> {
74
+ return await this.#rpc().createRepo(input);
75
+ }
76
+
77
+ async deleteRepo(input: RpcInput<'deleteRepo'>): Promise<RpcOutput<'deleteRepo'>> {
78
+ return await this.#rpc().deleteRepo(input);
79
+ }
80
+
81
+ async mintReadToken(input: RpcInput<'mintReadToken'>): Promise<RpcOutput<'mintReadToken'>> {
82
+ return await this.#rpc().mintReadToken(input);
83
+ }
84
+ };
85
+ }
@@ -0,0 +1,163 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { walkHistory } from '@leed-ai/git-gateway-contract/reference/history';
3
+ import type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';
4
+
5
+ import { type CommitSource, dateOrder } from './commit-source.ts';
6
+
7
+ /** Which page of history to list. */
8
+ export interface HistoryPageRequest {
9
+ readonly limit: number;
10
+ readonly offset: number;
11
+ /** ISO timestamp; commits committed before it are left out. */
12
+ readonly since?: string | undefined;
13
+ }
14
+
15
+ /** One page of history and whether more follows it. */
16
+ export interface HistoryPage {
17
+ readonly commits: Commit[];
18
+ readonly hasMore: boolean;
19
+ }
20
+
21
+ /** Thrown inside the walk when a parent is dated after its child; the walk then reads everything. */
22
+ class DateSkew extends Error {}
23
+
24
+ /** Timestamps compared as strings can disagree with time by less than one second (fractions). */
25
+ const STRING_ORDER_SLACK_MS = 1000;
26
+
27
+ /** The reference's pick among ready commits: the newest committer date, with its tie rule. */
28
+ function referencePick(ready: readonly Commit[]): number {
29
+ let pick = ready.length - 1;
30
+ ready.forEach((candidate, index) => {
31
+ const best = ready[pick];
32
+ if (best !== undefined && candidate.committer.date > best.committer.date) pick = index;
33
+ });
34
+ return pick;
35
+ }
36
+
37
+ /** Applies `since`, then cuts the page. */
38
+ function cut(history: readonly Commit[], { limit, offset, since }: HistoryPageRequest): HistoryPage {
39
+ const lowest = since === undefined ? Number.NEGATIVE_INFINITY : Date.parse(since);
40
+ const kept = history.filter((commit) => Date.parse(commit.committer.date) >= lowest);
41
+ return { commits: kept.slice(offset, offset + limit), hasMore: kept.length > offset + limit };
42
+ }
43
+
44
+ /** The whole reachable history in the reference's order, read in full (the fallback). */
45
+ async function fullHistory(source: CommitSource, start: Commit): Promise<Commit[]> {
46
+ const commits = new Map<string, Commit>([[start.sha, start]]);
47
+ let frontier = [start];
48
+ while (frontier.length > 0) {
49
+ const wanted = [...new Set(frontier.flatMap((commit) => commit.parents))].filter(
50
+ (sha) => !commits.has(sha),
51
+ );
52
+ const read = await Promise.all(wanted.map((sha) => source.commit(sha)));
53
+ frontier = read.filter((commit) => commit !== null);
54
+ for (const commit of frontier) commits.set(commit.sha, commit);
55
+ }
56
+ return walkHistory((sha) => commits.get(sha), start.sha);
57
+ }
58
+
59
+ /**
60
+ * The walk behind log(): emits the history reachable from `start` in exactly the reference's
61
+ * order (`walkHistory`: newest committer date first, never a parent before its child, the
62
+ * reference's tie rule), but reads only as far as the page needs.
63
+ *
64
+ * Commits are expanded (their parents read) newest committer date first. A ready commit — one
65
+ * whose known children have all been emitted — is certain once every other unexpanded commit is
66
+ * dated strictly before it: while committer dates never decrease from parent to child, an unseen
67
+ * child of it would be dated at or after it, and could only be reached through such a commit. The
68
+ * reference's pick is emitted only when it cannot be changed by a ready commit that is not
69
+ * certain; otherwise the newest unexpanded commit is expanded first. The walk stops once
70
+ * `offset + limit + 1` commits from `since` on have been emitted, or once everything left is older
71
+ * than `since`.
72
+ *
73
+ * Every edge read is checked: on a parent dated after its child (clock skew) the walk gives up and
74
+ * orders the whole reachable history instead, as the reference does. Skew lying entirely beyond
75
+ * the commits the page needed is never read, and so cannot be detected; within it, the page can
76
+ * differ from the reference's.
77
+ */
78
+ export async function historyPage(
79
+ source: CommitSource,
80
+ start: Commit,
81
+ request: HistoryPageRequest,
82
+ ): Promise<HistoryPage> {
83
+ try {
84
+ return await boundedPage(source, start, request);
85
+ } catch (error) {
86
+ if (!(error instanceof DateSkew)) throw error;
87
+ return cut(await fullHistory(source, start), request);
88
+ }
89
+ }
90
+
91
+ async function boundedPage(
92
+ source: CommitSource,
93
+ start: Commit,
94
+ request: HistoryPageRequest,
95
+ ): Promise<HistoryPage> {
96
+ const wanted = request.offset + request.limit + 1;
97
+ const sinceMs = request.since === undefined ? Number.NEGATIVE_INFINITY : Date.parse(request.since);
98
+ const commits = new Map<string, Commit>([[start.sha, start]]);
99
+ const unexpanded = new Map<string, Commit>([[start.sha, start]]);
100
+ const pendingChildren = new Map<string, number>();
101
+ const ready: Commit[] = [start];
102
+ const emitted: Commit[] = [];
103
+ let kept = 0;
104
+
105
+ const expand = async (commit: Commit): Promise<void> => {
106
+ unexpanded.delete(commit.sha);
107
+ const parents = await Promise.all(
108
+ commit.parents.map(async (sha) => commits.get(sha) ?? source.commit(sha)),
109
+ );
110
+ commit.parents.forEach((sha, index) => {
111
+ pendingChildren.set(sha, (pendingChildren.get(sha) ?? 0) + 1);
112
+ const at = ready.findIndex((candidate) => candidate.sha === sha);
113
+ if (at !== -1) ready.splice(at, 1);
114
+ const parent = parents[index];
115
+ if (parent === null || parent === undefined) return;
116
+ if (dateOrder(parent, commit) > 0) throw new DateSkew();
117
+ if (!commits.has(sha)) {
118
+ commits.set(sha, parent);
119
+ unexpanded.set(sha, parent);
120
+ }
121
+ });
122
+ };
123
+ const certain = (commit: Commit): boolean =>
124
+ [...unexpanded.values()].every((other) => other.sha === commit.sha || dateOrder(other, commit) < 0);
125
+ const nothingLeftSince = (): boolean =>
126
+ ready.every((commit) => Date.parse(commit.committer.date) < sinceMs) &&
127
+ [...unexpanded.values()].every(
128
+ (commit) => Date.parse(commit.committer.date) < sinceMs - STRING_ORDER_SLACK_MS,
129
+ );
130
+
131
+ while (ready.length > 0 && kept < wanted && !nothingLeftSince()) {
132
+ const pick = ready[referencePick(ready)];
133
+ if (pick === undefined) break;
134
+ if (unexpanded.has(pick.sha)) {
135
+ await expand(pick);
136
+ continue;
137
+ }
138
+ const newest = ready.filter((commit) => dateOrder(commit, pick) === 0);
139
+ const last = ready.at(-1);
140
+ const safe =
141
+ newest.every(certain) &&
142
+ (newest.length === 1 || last === undefined || dateOrder(last, pick) === 0 || certain(last));
143
+ if (!safe) {
144
+ let next: Commit | undefined;
145
+ for (const commit of unexpanded.values())
146
+ if (next === undefined || dateOrder(commit, next) > 0) next = commit;
147
+ if (next !== undefined) {
148
+ await expand(next);
149
+ continue;
150
+ }
151
+ }
152
+ ready.splice(ready.indexOf(pick), 1);
153
+ emitted.push(pick);
154
+ if (Date.parse(pick.committer.date) >= sinceMs) kept += 1;
155
+ for (const sha of pick.parents) {
156
+ const left = (pendingChildren.get(sha) ?? 1) - 1;
157
+ pendingChildren.set(sha, left);
158
+ const parent = commits.get(sha);
159
+ if (left === 0 && parent !== undefined) ready.push(parent);
160
+ }
161
+ }
162
+ return cut(emitted, request);
163
+ }