@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +50 -2
  3. package/dist/behaviour/assertions.d.ts +23 -0
  4. package/dist/behaviour/assertions.js +56 -0
  5. package/dist/behaviour/assertions.js.map +1 -0
  6. package/dist/behaviour/behaviour-case.d.ts +19 -0
  7. package/dist/behaviour/behaviour-case.js +12 -0
  8. package/dist/behaviour/behaviour-case.js.map +1 -0
  9. package/dist/behaviour/behaviour-suite.d.ts +30 -0
  10. package/dist/behaviour/behaviour-suite.js +50 -0
  11. package/dist/behaviour/behaviour-suite.js.map +1 -0
  12. package/dist/behaviour/commit-action-cases.d.ts +4 -0
  13. package/dist/behaviour/commit-action-cases.js +342 -0
  14. package/dist/behaviour/commit-action-cases.js.map +1 -0
  15. package/dist/behaviour/commit-write-cases.d.ts +4 -0
  16. package/dist/behaviour/commit-write-cases.js +234 -0
  17. package/dist/behaviour/commit-write-cases.js.map +1 -0
  18. package/dist/behaviour/fixtures.d.ts +29 -0
  19. package/dist/behaviour/fixtures.js +83 -0
  20. package/dist/behaviour/fixtures.js.map +1 -0
  21. package/dist/behaviour/lifecycle-cases.d.ts +4 -0
  22. package/dist/behaviour/lifecycle-cases.js +158 -0
  23. package/dist/behaviour/lifecycle-cases.js.map +1 -0
  24. package/dist/behaviour/promote-cases.d.ts +4 -0
  25. package/dist/behaviour/promote-cases.js +122 -0
  26. package/dist/behaviour/promote-cases.js.map +1 -0
  27. package/dist/behaviour/read-cases.d.ts +4 -0
  28. package/dist/behaviour/read-cases.js +248 -0
  29. package/dist/behaviour/read-cases.js.map +1 -0
  30. package/dist/behaviour/sync-cases.d.ts +4 -0
  31. package/dist/behaviour/sync-cases.js +205 -0
  32. package/dist/behaviour/sync-cases.js.map +1 -0
  33. package/dist/clock-B3MlpmVY.d.ts +10 -0
  34. package/dist/commit-BEZmeAOl.d.ts +23 -0
  35. package/dist/file-map-CxUveLWz.d.ts +18 -0
  36. package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
  37. package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
  38. package/dist/gateway-error.d.ts +30 -0
  39. package/dist/gateway-error.js +63 -0
  40. package/dist/gateway-error.js.map +1 -0
  41. package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
  42. package/dist/git-gateway.d.ts +2 -0
  43. package/dist/git-gateway.js +65 -0
  44. package/dist/git-gateway.js.map +1 -0
  45. package/dist/health.d.ts +9 -0
  46. package/dist/health.js +18 -0
  47. package/dist/health.js.map +1 -0
  48. package/dist/history-CqvHaUE-.d.ts +20 -0
  49. package/dist/package-name.d.ts +3 -0
  50. package/dist/package-name.js +6 -0
  51. package/dist/package-name.js.map +1 -0
  52. package/dist/proxy/audit-event.d.ts +61 -0
  53. package/dist/proxy/audit-event.js +97 -0
  54. package/dist/proxy/audit-event.js.map +1 -0
  55. package/dist/proxy/branch-rule.d.ts +72 -0
  56. package/dist/proxy/branch-rule.js +106 -0
  57. package/dist/proxy/branch-rule.js.map +1 -0
  58. package/dist/proxy/gateway-hooks.d.ts +58 -0
  59. package/dist/proxy/gateway-hooks.js +0 -0
  60. package/dist/proxy/git-operation.d.ts +17 -0
  61. package/dist/proxy/git-operation.js +32 -0
  62. package/dist/proxy/git-operation.js.map +1 -0
  63. package/dist/proxy/policy-result.d.ts +51 -0
  64. package/dist/proxy/policy-result.js +90 -0
  65. package/dist/proxy/policy-result.js.map +1 -0
  66. package/dist/proxy/principal.d.ts +18 -0
  67. package/dist/proxy/principal.js +32 -0
  68. package/dist/proxy/principal.js.map +1 -0
  69. package/dist/proxy/push-policy-result.d.ts +34 -0
  70. package/dist/proxy/push-policy-result.js +48 -0
  71. package/dist/proxy/push-policy-result.js.map +1 -0
  72. package/dist/proxy/push-policy.d.ts +146 -0
  73. package/dist/proxy/push-policy.js +112 -0
  74. package/dist/proxy/push-policy.js.map +1 -0
  75. package/dist/proxy/request-credential.d.ts +22 -0
  76. package/dist/proxy/request-credential.js +46 -0
  77. package/dist/proxy/request-credential.js.map +1 -0
  78. package/dist/proxy/smart-http-config.d.ts +22 -0
  79. package/dist/proxy/smart-http-config.js +40 -0
  80. package/dist/proxy/smart-http-config.js.map +1 -0
  81. package/dist/reference/apply-actions.d.ts +9 -0
  82. package/dist/reference/apply-actions.js +84 -0
  83. package/dist/reference/apply-actions.js.map +1 -0
  84. package/dist/reference/branch-methods.d.ts +7 -0
  85. package/dist/reference/branch-methods.js +105 -0
  86. package/dist/reference/branch-methods.js.map +1 -0
  87. package/dist/reference/bytes.d.ts +22 -0
  88. package/dist/reference/bytes.js +62 -0
  89. package/dist/reference/bytes.js.map +1 -0
  90. package/dist/reference/clock.d.ts +2 -0
  91. package/dist/reference/clock.js +18 -0
  92. package/dist/reference/clock.js.map +1 -0
  93. package/dist/reference/commit-method.d.ts +5 -0
  94. package/dist/reference/commit-method.js +83 -0
  95. package/dist/reference/commit-method.js.map +1 -0
  96. package/dist/reference/file-map.d.ts +2 -0
  97. package/dist/reference/file-map.js +24 -0
  98. package/dist/reference/file-map.js.map +1 -0
  99. package/dist/reference/hash.d.ts +10 -0
  100. package/dist/reference/hash.js +25 -0
  101. package/dist/reference/hash.js.map +1 -0
  102. package/dist/reference/history.d.ts +2 -0
  103. package/dist/reference/history.js +65 -0
  104. package/dist/reference/history.js.map +1 -0
  105. package/dist/reference/lifecycle-methods.d.ts +9 -0
  106. package/dist/reference/lifecycle-methods.js +48 -0
  107. package/dist/reference/lifecycle-methods.js.map +1 -0
  108. package/dist/reference/read-methods.d.ts +13 -0
  109. package/dist/reference/read-methods.js +68 -0
  110. package/dist/reference/read-methods.js.map +1 -0
  111. package/dist/reference/reference-gateway.d.ts +18 -0
  112. package/dist/reference/reference-gateway.js +35 -0
  113. package/dist/reference/reference-gateway.js.map +1 -0
  114. package/dist/reference/repo-state.d.ts +43 -0
  115. package/dist/reference/repo-state.js +45 -0
  116. package/dist/reference/repo-state.js.map +1 -0
  117. package/dist/reference/run-method.d.ts +13 -0
  118. package/dist/reference/run-method.js +15 -0
  119. package/dist/reference/run-method.js.map +1 -0
  120. package/dist/reference/three-way-merge.d.ts +16 -0
  121. package/dist/reference/three-way-merge.js +45 -0
  122. package/dist/reference/three-way-merge.js.map +1 -0
  123. package/dist/reference/trailer.d.ts +7 -0
  124. package/dist/reference/trailer.js +16 -0
  125. package/dist/reference/trailer.js.map +1 -0
  126. package/dist/reference/tree-index.d.ts +2 -0
  127. package/dist/reference/tree-index.js +66 -0
  128. package/dist/reference/tree-index.js.map +1 -0
  129. package/dist/reference/write-commit.d.ts +15 -0
  130. package/dist/reference/write-commit.js +44 -0
  131. package/dist/reference/write-commit.js.map +1 -0
  132. package/dist/rpc/commit-exists.d.ts +16 -0
  133. package/dist/rpc/commit-exists.js +30 -0
  134. package/dist/rpc/commit-exists.js.map +1 -0
  135. package/dist/rpc/commit.d.ts +172 -0
  136. package/dist/rpc/commit.js +115 -0
  137. package/dist/rpc/commit.js.map +1 -0
  138. package/dist/rpc/list-tree.d.ts +59 -0
  139. package/dist/rpc/list-tree.js +54 -0
  140. package/dist/rpc/list-tree.js.map +1 -0
  141. package/dist/rpc/log.d.ts +35 -0
  142. package/dist/rpc/log.js +41 -0
  143. package/dist/rpc/log.js.map +1 -0
  144. package/dist/rpc/mint-read-token.d.ts +17 -0
  145. package/dist/rpc/mint-read-token.js +36 -0
  146. package/dist/rpc/mint-read-token.js.map +1 -0
  147. package/dist/rpc/promote.d.ts +39 -0
  148. package/dist/rpc/promote.js +69 -0
  149. package/dist/rpc/promote.js.map +1 -0
  150. package/dist/rpc/read-file.d.ts +44 -0
  151. package/dist/rpc/read-file.js +56 -0
  152. package/dist/rpc/read-file.js.map +1 -0
  153. package/dist/rpc/repo-lifecycle.d.ts +39 -0
  154. package/dist/rpc/repo-lifecycle.js +64 -0
  155. package/dist/rpc/repo-lifecycle.js.map +1 -0
  156. package/dist/rpc/resolve-ref.d.ts +15 -0
  157. package/dist/rpc/resolve-ref.js +28 -0
  158. package/dist/rpc/resolve-ref.js.map +1 -0
  159. package/dist/rpc/sync-branch.d.ts +107 -0
  160. package/dist/rpc/sync-branch.js +114 -0
  161. package/dist/rpc/sync-branch.js.map +1 -0
  162. package/dist/schemas/commit-action.d.ts +100 -0
  163. package/dist/schemas/commit-action.js +138 -0
  164. package/dist/schemas/commit-action.js.map +1 -0
  165. package/dist/schemas/commit.d.ts +2 -0
  166. package/dist/schemas/commit.js +24 -0
  167. package/dist/schemas/commit.js.map +1 -0
  168. package/dist/schemas/content-encoding.d.ts +24 -0
  169. package/dist/schemas/content-encoding.js +41 -0
  170. package/dist/schemas/content-encoding.js.map +1 -0
  171. package/dist/schemas/examples.d.ts +38 -0
  172. package/dist/schemas/examples.js +32 -0
  173. package/dist/schemas/examples.js.map +1 -0
  174. package/dist/schemas/gateway-config.d.ts +2 -0
  175. package/dist/schemas/gateway-config.js +72 -0
  176. package/dist/schemas/gateway-config.js.map +1 -0
  177. package/dist/schemas/gateway-error-body.d.ts +2 -0
  178. package/dist/schemas/gateway-error-body.js +188 -0
  179. package/dist/schemas/gateway-error-body.js.map +1 -0
  180. package/dist/schemas/identity.d.ts +21 -0
  181. package/dist/schemas/identity.js +40 -0
  182. package/dist/schemas/identity.js.map +1 -0
  183. package/dist/schemas/names.d.ts +26 -0
  184. package/dist/schemas/names.js +58 -0
  185. package/dist/schemas/names.js.map +1 -0
  186. package/dist/schemas/ref-update.d.ts +10 -0
  187. package/dist/schemas/ref-update.js +25 -0
  188. package/dist/schemas/ref-update.js.map +1 -0
  189. package/dist/schemas/sha.d.ts +8 -0
  190. package/dist/schemas/sha.js +14 -0
  191. package/dist/schemas/sha.js.map +1 -0
  192. package/dist/schemas/tree-entry.d.ts +2 -0
  193. package/dist/schemas/tree-entry.js +62 -0
  194. package/dist/schemas/tree-entry.js.map +1 -0
  195. package/dist/storage/git-remote.d.ts +17 -0
  196. package/dist/storage/git-remote.js +31 -0
  197. package/dist/storage/git-remote.js.map +1 -0
  198. package/dist/storage/storage-backend.d.ts +61 -0
  199. package/dist/storage/storage-backend.js +0 -0
  200. package/dist/storage/storage-errors.d.ts +12 -0
  201. package/dist/storage/storage-errors.js +22 -0
  202. package/dist/storage/storage-errors.js.map +1 -0
  203. package/dist/storage/storage-input.d.ts +7 -0
  204. package/dist/storage/storage-input.js +14 -0
  205. package/dist/storage/storage-input.js.map +1 -0
  206. package/dist/storage/storage-read.d.ts +13 -0
  207. package/dist/storage/storage-read.js +30 -0
  208. package/dist/storage/storage-read.js.map +1 -0
  209. package/dist/storage/storage-repo-info.d.ts +16 -0
  210. package/dist/storage/storage-repo-info.js +30 -0
  211. package/dist/storage/storage-repo-info.js.map +1 -0
  212. package/dist/storage/storage-tree-entry.d.ts +21 -0
  213. package/dist/storage/storage-tree-entry.js +17 -0
  214. package/dist/storage/storage-tree-entry.js.map +1 -0
  215. package/dist/tree-entry-BM_1gou1.d.ts +41 -0
  216. package/dist/tree-index-Bk721Phv.d.ts +14 -0
  217. package/package.json +401 -4
  218. package/src/behaviour/assertions.ts +75 -0
  219. package/src/behaviour/behaviour-case.ts +28 -0
  220. package/src/behaviour/behaviour-suite.ts +76 -0
  221. package/src/behaviour/commit-action-cases.ts +253 -0
  222. package/src/behaviour/commit-write-cases.ts +205 -0
  223. package/src/behaviour/fixtures.ts +103 -0
  224. package/src/behaviour/lifecycle-cases.ts +104 -0
  225. package/src/behaviour/promote-cases.ts +78 -0
  226. package/src/behaviour/read-cases.ts +176 -0
  227. package/src/behaviour/sync-cases.ts +156 -0
  228. package/src/gateway-error.ts +72 -0
  229. package/src/git-gateway.ts +76 -0
  230. package/src/health.ts +26 -0
  231. package/src/package-name.ts +4 -0
  232. package/src/proxy/audit-event.ts +135 -0
  233. package/src/proxy/branch-rule.ts +190 -0
  234. package/src/proxy/gateway-hooks.ts +67 -0
  235. package/src/proxy/git-operation.ts +36 -0
  236. package/src/proxy/policy-result.ts +127 -0
  237. package/src/proxy/principal.ts +81 -0
  238. package/src/proxy/push-policy-result.ts +86 -0
  239. package/src/proxy/push-policy.ts +158 -0
  240. package/src/proxy/request-credential.ts +47 -0
  241. package/src/proxy/smart-http-config.ts +158 -0
  242. package/src/reference/apply-actions.ts +96 -0
  243. package/src/reference/branch-methods.ts +105 -0
  244. package/src/reference/bytes.ts +66 -0
  245. package/src/reference/clock.ts +19 -0
  246. package/src/reference/commit-method.ts +97 -0
  247. package/src/reference/file-map.ts +35 -0
  248. package/src/reference/hash.ts +25 -0
  249. package/src/reference/history.ts +78 -0
  250. package/src/reference/lifecycle-methods.ts +52 -0
  251. package/src/reference/read-methods.ts +87 -0
  252. package/src/reference/reference-gateway.ts +50 -0
  253. package/src/reference/repo-state.ts +83 -0
  254. package/src/reference/run-method.ts +25 -0
  255. package/src/reference/three-way-merge.ts +42 -0
  256. package/src/reference/trailer.ts +18 -0
  257. package/src/reference/tree-index.ts +65 -0
  258. package/src/reference/write-commit.ts +44 -0
  259. package/src/rpc/commit-exists.ts +46 -0
  260. package/src/rpc/commit.ts +156 -0
  261. package/src/rpc/list-tree.ts +78 -0
  262. package/src/rpc/log.ts +51 -0
  263. package/src/rpc/mint-read-token.ts +59 -0
  264. package/src/rpc/promote.ts +72 -0
  265. package/src/rpc/read-file.ts +75 -0
  266. package/src/rpc/repo-lifecycle.ts +103 -0
  267. package/src/rpc/resolve-ref.ts +41 -0
  268. package/src/rpc/sync-branch.ts +149 -0
  269. package/src/schemas/commit-action.ts +157 -0
  270. package/src/schemas/commit.ts +43 -0
  271. package/src/schemas/content-encoding.ts +58 -0
  272. package/src/schemas/examples.ts +24 -0
  273. package/src/schemas/gateway-config.ts +116 -0
  274. package/src/schemas/gateway-error-body.ts +230 -0
  275. package/src/schemas/identity.ts +57 -0
  276. package/src/schemas/names.ts +126 -0
  277. package/src/schemas/ref-update.ts +38 -0
  278. package/src/schemas/sha.ts +20 -0
  279. package/src/schemas/tree-entry.ts +72 -0
  280. package/src/storage/git-remote.ts +58 -0
  281. package/src/storage/storage-backend.ts +65 -0
  282. package/src/storage/storage-errors.ts +24 -0
  283. package/src/storage/storage-input.ts +14 -0
  284. package/src/storage/storage-read.ts +45 -0
  285. package/src/storage/storage-repo-info.ts +46 -0
  286. package/src/storage/storage-tree-entry.ts +20 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-method.js","names":[],"sources":["../../src/reference/commit-method.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { RPC_SCHEMAS, type RpcInput, type RpcOutput, type RpcParsedInput } from '../git-gateway.ts';\nimport { gatewayError } from '../gateway-error.ts';\nimport type { Commit } from '../schemas/commit.ts';\nimport { ZERO_SHA } from '../schemas/sha.ts';\nimport { applyActions } from './apply-actions.ts';\nimport { buildTreeIndex } from './tree-index.ts';\nimport { walkHistory } from './history.ts';\nimport { lookupIn, requireRepo, withRepoLock, type ReferenceContext, type RepoState } from './repo-state.ts';\nimport { runMethod } from './run-method.ts';\nimport { appendIdempotencyTrailer } from './trailer.ts';\nimport { writeCommit } from './write-commit.ts';\n\ntype Input = RpcParsedInput<'commit'>;\n\n/** The commit carrying `key` within the configured lookback window of the branch, if any. */\nfunction findReplay(\n context: ReferenceContext,\n repo: RepoState,\n head: string,\n key: string,\n): Commit | undefined {\n const { maxCommits, maxAgeSeconds } = context.config.idempotency;\n const oldest = new Date(context.now().getTime() - maxAgeSeconds * 1000).toISOString();\n const window = walkHistory(lookupIn(repo), head).slice(0, maxCommits);\n for (const commit of window) {\n if (commit.committer.date < oldest) return undefined;\n if (commit.idempotencyKey === key) return commit;\n }\n return undefined;\n}\n\n/** The commit the new one builds on: the branch head, the start branch head, or none for a root commit. */\nfunction baseOf(repo: RepoState, input: Input, head: string | null): string | null {\n if (head !== null) return head;\n if (input.startBranch !== undefined) {\n const start = repo.branches.get(input.startBranch);\n if (start === undefined) {\n throw gatewayError('ref_not_found', `Branch not found: ${input.startBranch}`, {\n ref: input.startBranch,\n });\n }\n return start;\n }\n if (repo.branches.size === 0) return null;\n throw gatewayError('ref_not_found', `Branch not found: ${input.branch}`, { ref: input.branch });\n}\n\nasync function commitLocked(\n context: ReferenceContext,\n repo: RepoState,\n input: Input,\n): Promise<RpcOutput<'commit'>> {\n const head = repo.branches.get(input.branch) ?? null;\n if (head !== null) {\n const replay = findReplay(context, repo, head, input.idempotencyKey);\n if (replay !== undefined) return { status: 'replayed', commit: replay };\n }\n if (input.expectedHead !== undefined && input.expectedHead !== head) {\n throw gatewayError('stale_head', `Branch ${input.branch} moved`, {\n branch: input.branch,\n expectedHead: input.expectedHead,\n actualHead: head,\n });\n }\n const base = baseOf(repo, input, head);\n const baseCommit = base === null ? undefined : repo.commits.get(base);\n const files = await applyActions(baseCommit?.files ?? new Map(), input.actions);\n const baseTree = baseCommit?.tree.rootSha ?? (await buildTreeIndex(new Map())).rootSha;\n const nextTree = (await buildTreeIndex(files)).rootSha;\n if (nextTree === baseTree) return { status: 'noop', head };\n const stored = await writeCommit(repo, {\n parents: base === null ? [] : [base],\n files,\n author: input.author,\n committer: input.committer ?? input.author,\n message: appendIdempotencyTrailer(input.message, input.idempotencyKey),\n date: context.now().toISOString(),\n });\n repo.branches.set(input.branch, stored.commit.sha);\n return {\n status: 'committed',\n commit: stored.commit,\n refUpdate: { ref: `refs/heads/${input.branch}`, oldSha: head ?? ZERO_SHA, newSha: stored.commit.sha },\n };\n}\n\n/** The reference `commit`: GitLab Commits API rules, idempotency replay, stale-head refusal, no-op detection. */\nexport function referenceCommit(\n context: ReferenceContext,\n input: RpcInput<'commit'>,\n): Promise<RpcOutput<'commit'>> {\n return runMethod(RPC_SCHEMAS.commit, input, async (parsed) => {\n const repo = requireRepo(context, parsed.repo);\n return withRepoLock(repo, () => commitLocked(context, repo, parsed));\n });\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,WACP,SACA,MACA,MACA,KACoB;CACpB,MAAM,EAAE,YAAY,kBAAkB,QAAQ,OAAO;CACrD,MAAM,0BAAS,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,IAAI,gBAAgB,GAAI,EAAA,CAAE,YAAY;CACpF,MAAM,SAAS,YAAY,SAAS,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,UAAU;CACpE,KAAK,MAAM,UAAU,QAAQ;EAC3B,IAAI,OAAO,UAAU,OAAO,QAAQ,OAAO,KAAA;EAC3C,IAAI,OAAO,mBAAmB,KAAK,OAAO;CAC5C;AAEF;;AAGA,SAAS,OAAO,MAAiB,OAAc,MAAoC;CACjF,IAAI,SAAS,MAAM,OAAO;CAC1B,IAAI,MAAM,gBAAgB,KAAA,GAAW;EACnC,MAAM,QAAQ,KAAK,SAAS,IAAI,MAAM,WAAW;EACjD,IAAI,UAAU,KAAA,GACZ,MAAM,aAAa,iBAAiB,qBAAqB,MAAM,eAAe,EAC5E,KAAK,MAAM,YACb,CAAC;EAEH,OAAO;CACT;CACA,IAAI,KAAK,SAAS,SAAS,GAAG,OAAO;CACrC,MAAM,aAAa,iBAAiB,qBAAqB,MAAM,UAAU,EAAE,KAAK,MAAM,OAAO,CAAC;AAChG;AAEA,eAAe,aACb,SACA,MACA,OAC8B;CAC9B,MAAM,OAAO,KAAK,SAAS,IAAI,MAAM,MAAM,KAAK;CAChD,IAAI,SAAS,MAAM;EACjB,MAAM,SAAS,WAAW,SAAS,MAAM,MAAM,MAAM,cAAc;EACnE,IAAI,WAAW,KAAA,GAAW,OAAO;GAAE,QAAQ;GAAY,QAAQ;EAAO;CACxE;CACA,IAAI,MAAM,iBAAiB,KAAA,KAAa,MAAM,iBAAiB,MAC7D,MAAM,aAAa,cAAc,UAAU,MAAM,OAAO,SAAS;EAC/D,QAAQ,MAAM;EACd,cAAc,MAAM;EACpB,YAAY;CACd,CAAC;CAEH,MAAM,OAAO,OAAO,MAAM,OAAO,IAAI;CACrC,MAAM,aAAa,SAAS,OAAO,KAAA,IAAY,KAAK,QAAQ,IAAI,IAAI;CACpE,MAAM,QAAQ,MAAM,aAAa,YAAY,yBAAS,IAAI,IAAI,GAAG,MAAM,OAAO;CAC9E,MAAM,WAAW,YAAY,KAAK,YAAY,MAAM,+BAAe,IAAI,IAAI,CAAC,EAAA,CAAG;CAE/E,KADkB,MAAM,eAAe,KAAK,EAAA,CAAG,YAC9B,UAAU,OAAO;EAAE,QAAQ;EAAQ;CAAK;CACzD,MAAM,SAAS,MAAM,YAAY,MAAM;EACrC,SAAS,SAAS,OAAO,CAAC,IAAI,CAAC,IAAI;EACnC;EACA,QAAQ,MAAM;EACd,WAAW,MAAM,aAAa,MAAM;EACpC,SAAS,yBAAyB,MAAM,SAAS,MAAM,cAAc;EACrE,MAAM,QAAQ,IAAI,CAAC,CAAC,YAAY;CAClC,CAAC;CACD,KAAK,SAAS,IAAI,MAAM,QAAQ,OAAO,OAAO,GAAG;CACjD,OAAO;EACL,QAAQ;EACR,QAAQ,OAAO;EACf,WAAW;GAAE,KAAK,cAAc,MAAM;GAAU,QAAQ,QAAA;GAAkB,QAAQ,OAAO,OAAO;EAAI;CACtG;AACF;;AAGA,SAAgB,gBACd,SACA,OAC8B;CAC9B,OAAO,UAAU,YAAY,QAAQ,OAAO,OAAO,WAAW;EAC5D,MAAM,OAAO,YAAY,SAAS,OAAO,IAAI;EAC7C,OAAO,aAAa,YAAY,aAAa,SAAS,MAAM,MAAM,CAAC;CACrE,CAAC;AACH"}
@@ -0,0 +1,2 @@
1
+ import { a as parentDirectories, i as isDirectory, n as StoredFile, o as sameFile, r as fileParent, t as FileMap } from "../file-map-CxUveLWz.js";
2
+ export { FileMap, StoredFile, fileParent, isDirectory, parentDirectories, sameFile };
@@ -0,0 +1,24 @@
1
+ // src/reference/file-map.ts
2
+ /** Every proper parent directory of a path, shallowest first: `a/b/c` → `a`, `a/b`. */
3
+ function parentDirectories(path) {
4
+ const segments = path.split("/");
5
+ return segments.slice(0, -1).map((_, index) => segments.slice(0, index + 1).join("/"));
6
+ }
7
+ /** True when some file lies beneath `path`, i.e. it is a directory of the snapshot. */
8
+ function isDirectory(files, path) {
9
+ const prefix = `${path}/`;
10
+ for (const key of files.keys()) if (key.startsWith(prefix)) return true;
11
+ return false;
12
+ }
13
+ /** The shallowest parent of `path` that is a file, or undefined when none is. */
14
+ function fileParent(files, path) {
15
+ return parentDirectories(path).find((parent) => files.has(parent));
16
+ }
17
+ /** True when two stored files have the same content and mode. */
18
+ function sameFile(a, b) {
19
+ if (a === void 0 || b === void 0) return a === b;
20
+ return a.sha === b.sha && a.executable === b.executable;
21
+ }
22
+ export { fileParent, isDirectory, parentDirectories, sameFile };
23
+
24
+ //# sourceMappingURL=file-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-map.js","names":[],"sources":["../../src/reference/file-map.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** One file of the in-memory model: its bytes, executable bit and blob id. */\nexport interface StoredFile {\n readonly bytes: Uint8Array;\n readonly executable: boolean;\n readonly sha: string;\n}\n\n/** A snapshot of a repository: every file by full path. Directories are implied by paths. */\nexport type FileMap = ReadonlyMap<string, StoredFile>;\n\n/** Every proper parent directory of a path, shallowest first: `a/b/c` → `a`, `a/b`. */\nexport function parentDirectories(path: string): string[] {\n const segments = path.split('/');\n return segments.slice(0, -1).map((_, index) => segments.slice(0, index + 1).join('/'));\n}\n\n/** True when some file lies beneath `path`, i.e. it is a directory of the snapshot. */\nexport function isDirectory(files: FileMap, path: string): boolean {\n const prefix = `${path}/`;\n for (const key of files.keys()) if (key.startsWith(prefix)) return true;\n return false;\n}\n\n/** The shallowest parent of `path` that is a file, or undefined when none is. */\nexport function fileParent(files: FileMap, path: string): string | undefined {\n return parentDirectories(path).find((parent) => files.has(parent));\n}\n\n/** True when two stored files have the same content and mode. */\nexport function sameFile(a: StoredFile | undefined, b: StoredFile | undefined): boolean {\n if (a === undefined || b === undefined) return a === b;\n return a.sha === b.sha && a.executable === b.executable;\n}\n"],"mappings":";;AAaA,SAAgB,kBAAkB,MAAwB;CACxD,MAAM,WAAW,KAAK,MAAM,GAAG;CAC/B,OAAO,SAAS,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,UAAU,SAAS,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;AACvF;;AAGA,SAAgB,YAAY,OAAgB,MAAuB;CACjE,MAAM,SAAS,GAAG,KAAK;CACvB,KAAK,MAAM,OAAO,MAAM,KAAK,GAAG,IAAI,IAAI,WAAW,MAAM,GAAG,OAAO;CACnE,OAAO;AACT;;AAGA,SAAgB,WAAW,OAAgB,MAAkC;CAC3E,OAAO,kBAAkB,IAAI,CAAC,CAAC,MAAM,WAAW,MAAM,IAAI,MAAM,CAAC;AACnE;;AAGA,SAAgB,SAAS,GAA2B,GAAoC;CACtF,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAAW,OAAO,MAAM;CACrD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE;AAC/C"}
@@ -0,0 +1,10 @@
1
+ /** Lowercase hex SHA-1 of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */
2
+ export declare function sha1Hex(bytes: Uint8Array): Promise<string>;
3
+ /** The git blob id of some bytes: SHA-1 of "blob <size>\0" followed by the bytes. */
4
+ export declare function blobSha(bytes: Uint8Array): Promise<string>;
5
+ /**
6
+ * A deterministic id for a tree or commit of the in-memory model: SHA-1 of the kind and a
7
+ * canonical text form. Equal content gives equal ids; it is not git's object encoding.
8
+ */
9
+ export declare function modelSha(kind: 'tree' | 'commit', canonical: string): Promise<string>;
10
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { utf8 } from "./bytes.js";
2
+ // src/reference/hash.ts
3
+ /** Lowercase hex SHA-1 of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */
4
+ async function sha1Hex(bytes) {
5
+ const digest = await crypto.subtle.digest("SHA-1", bytes);
6
+ return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
7
+ }
8
+ /** The git blob id of some bytes: SHA-1 of "blob <size>\0" followed by the bytes. */
9
+ async function blobSha(bytes) {
10
+ const header = utf8(`blob ${bytes.length}\0`);
11
+ const object = new Uint8Array(header.length + bytes.length);
12
+ object.set(header);
13
+ object.set(bytes, header.length);
14
+ return sha1Hex(object);
15
+ }
16
+ /**
17
+ * A deterministic id for a tree or commit of the in-memory model: SHA-1 of the kind and a
18
+ * canonical text form. Equal content gives equal ids; it is not git's object encoding.
19
+ */
20
+ async function modelSha(kind, canonical) {
21
+ return sha1Hex(utf8(`${kind}\0${canonical}`));
22
+ }
23
+ export { blobSha, modelSha, sha1Hex };
24
+
25
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","names":[],"sources":["../../src/reference/hash.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { utf8 } from './bytes.ts';\n\n/** Lowercase hex SHA-1 of some bytes, through Web Crypto (Bun, Node, Workers and browsers). */\nexport async function sha1Hex(bytes: Uint8Array): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-1', bytes);\n return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n\n/** The git blob id of some bytes: SHA-1 of \"blob <size>\\0\" followed by the bytes. */\nexport async function blobSha(bytes: Uint8Array): Promise<string> {\n const header = utf8(`blob ${bytes.length}\\0`);\n const object = new Uint8Array(header.length + bytes.length);\n object.set(header);\n object.set(bytes, header.length);\n return sha1Hex(object);\n}\n\n/**\n * A deterministic id for a tree or commit of the in-memory model: SHA-1 of the kind and a\n * canonical text form. Equal content gives equal ids; it is not git's object encoding.\n */\nexport async function modelSha(kind: 'tree' | 'commit', canonical: string): Promise<string> {\n return sha1Hex(utf8(`${kind}\\0${canonical}`));\n}\n"],"mappings":";;;AAIA,eAAsB,QAAQ,OAAoC;CAChE,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO,SAAS,KAAK;CACxD,OAAO,CAAC,GAAG,IAAI,WAAW,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AAC9F;;AAGA,eAAsB,QAAQ,OAAoC;CAChE,MAAM,SAAS,KAAK,QAAQ,MAAM,OAAO,GAAG;CAC5C,MAAM,SAAS,IAAI,WAAW,OAAO,SAAS,MAAM,MAAM;CAC1D,OAAO,IAAI,MAAM;CACjB,OAAO,IAAI,OAAO,OAAO,MAAM;CAC/B,OAAO,QAAQ,MAAM;AACvB;;;;;AAMA,eAAsB,SAAS,MAAyB,WAAoC;CAC1F,OAAO,QAAQ,KAAK,GAAG,KAAK,IAAI,WAAW,CAAC;AAC9C"}
@@ -0,0 +1,2 @@
1
+ import { a as walkHistory, i as mergeBase, n as ancestors, r as contains, t as CommitLookup } from "../history-CqvHaUE-.js";
2
+ export { CommitLookup, ancestors, contains, mergeBase, walkHistory };
@@ -0,0 +1,65 @@
1
+ // src/reference/history.ts
2
+ /** Every commit reachable from `start`, itself included. */
3
+ function ancestors(lookup, start) {
4
+ const seen = /* @__PURE__ */ new Set();
5
+ const stack = [start];
6
+ for (let sha = stack.pop(); sha !== void 0; sha = stack.pop()) {
7
+ if (seen.has(sha)) continue;
8
+ const commit = lookup(sha);
9
+ if (commit === void 0) continue;
10
+ seen.add(sha);
11
+ stack.push(...commit.parents);
12
+ }
13
+ return seen;
14
+ }
15
+ /** True when `ancestor` is reachable from `descendant` (a commit contains itself). */
16
+ function contains(lookup, descendant, ancestor) {
17
+ return ancestors(lookup, descendant).has(ancestor);
18
+ }
19
+ /**
20
+ * History reachable from `start`, newest committer date first, never listing a commit before
21
+ * one of its children; ties go to the commit discovered last (as git log does).
22
+ */
23
+ function walkHistory(lookup, start) {
24
+ const reachable = ancestors(lookup, start);
25
+ const pendingChildren = /* @__PURE__ */ new Map();
26
+ for (const sha of reachable) for (const parent of lookup(sha)?.parents ?? []) pendingChildren.set(parent, (pendingChildren.get(parent) ?? 0) + 1);
27
+ const ordered = [];
28
+ const ready = [];
29
+ const first = lookup(start);
30
+ if (first !== void 0) ready.push(first);
31
+ while (ready.length > 0) {
32
+ let pick = ready.length - 1;
33
+ ready.forEach((candidate, index) => {
34
+ const best = ready[pick];
35
+ if (best !== void 0 && candidate.committer.date > best.committer.date) pick = index;
36
+ });
37
+ const [commit] = ready.splice(pick, 1);
38
+ if (commit === void 0) break;
39
+ ordered.push(commit);
40
+ for (const parent of commit.parents) {
41
+ const left = (pendingChildren.get(parent) ?? 1) - 1;
42
+ pendingChildren.set(parent, left);
43
+ const parentCommit = lookup(parent);
44
+ if (left === 0 && parentCommit !== void 0) ready.push(parentCommit);
45
+ }
46
+ }
47
+ return ordered;
48
+ }
49
+ /**
50
+ * The best common ancestor of two commits: a common ancestor no other common ancestor descends
51
+ * from. When several qualify (criss-cross history) the newest by committer date wins, then the
52
+ * lowest id. Null when the histories are unrelated.
53
+ */
54
+ function mergeBase(lookup, a, b) {
55
+ const fromB = ancestors(lookup, b);
56
+ const common = [...ancestors(lookup, a)].filter((sha) => fromB.has(sha));
57
+ return common.filter((candidate) => !common.some((other) => other !== candidate && contains(lookup, other, candidate))).toSorted((x, y) => {
58
+ const dx = lookup(x)?.committer.date ?? "";
59
+ const dy = lookup(y)?.committer.date ?? "";
60
+ return dx === dy ? x < y ? -1 : 1 : dx > dy ? -1 : 1;
61
+ })[0] ?? null;
62
+ }
63
+ export { ancestors, contains, mergeBase, walkHistory };
64
+
65
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","names":[],"sources":["../../src/reference/history.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '../schemas/commit.ts';\n\n/** Looks up a stored commit by id. */\nexport type CommitLookup = (sha: string) => Commit | undefined;\n\n/** Every commit reachable from `start`, itself included. */\nexport function ancestors(lookup: CommitLookup, start: string): Set<string> {\n const seen = new Set<string>();\n const stack = [start];\n for (let sha = stack.pop(); sha !== undefined; sha = stack.pop()) {\n if (seen.has(sha)) continue;\n const commit = lookup(sha);\n if (commit === undefined) continue;\n seen.add(sha);\n stack.push(...commit.parents);\n }\n return seen;\n}\n\n/** True when `ancestor` is reachable from `descendant` (a commit contains itself). */\nexport function contains(lookup: CommitLookup, descendant: string, ancestor: string): boolean {\n return ancestors(lookup, descendant).has(ancestor);\n}\n\n/**\n * History reachable from `start`, newest committer date first, never listing a commit before\n * one of its children; ties go to the commit discovered last (as git log does).\n */\nexport function walkHistory(lookup: CommitLookup, start: string): Commit[] {\n const reachable = ancestors(lookup, start);\n const pendingChildren = new Map<string, number>();\n for (const sha of reachable) {\n for (const parent of lookup(sha)?.parents ?? []) {\n pendingChildren.set(parent, (pendingChildren.get(parent) ?? 0) + 1);\n }\n }\n const ordered: Commit[] = [];\n const ready: Commit[] = [];\n const first = lookup(start);\n if (first !== undefined) ready.push(first);\n while (ready.length > 0) {\n let pick = ready.length - 1;\n ready.forEach((candidate, index) => {\n const best = ready[pick];\n if (best !== undefined && candidate.committer.date > best.committer.date) pick = index;\n });\n const [commit] = ready.splice(pick, 1);\n if (commit === undefined) break;\n ordered.push(commit);\n for (const parent of commit.parents) {\n const left = (pendingChildren.get(parent) ?? 1) - 1;\n pendingChildren.set(parent, left);\n const parentCommit = lookup(parent);\n if (left === 0 && parentCommit !== undefined) ready.push(parentCommit);\n }\n }\n return ordered;\n}\n\n/**\n * The best common ancestor of two commits: a common ancestor no other common ancestor descends\n * from. When several qualify (criss-cross history) the newest by committer date wins, then the\n * lowest id. Null when the histories are unrelated.\n */\nexport function mergeBase(lookup: CommitLookup, a: string, b: string): string | null {\n const fromB = ancestors(lookup, b);\n const common = [...ancestors(lookup, a)].filter((sha) => fromB.has(sha));\n const best = common.filter(\n (candidate) => !common.some((other) => other !== candidate && contains(lookup, other, candidate)),\n );\n const ranked = best.toSorted((x, y) => {\n const dx = lookup(x)?.committer.date ?? '';\n const dy = lookup(y)?.committer.date ?? '';\n return dx === dy ? (x < y ? -1 : 1) : dx > dy ? -1 : 1;\n });\n return ranked[0] ?? null;\n}\n"],"mappings":";;AAOA,SAAgB,UAAU,QAAsB,OAA4B;CAC1E,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,QAAQ,CAAC,KAAK;CACpB,KAAK,IAAI,MAAM,MAAM,IAAI,GAAG,QAAQ,KAAA,GAAW,MAAM,MAAM,IAAI,GAAG;EAChE,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,MAAM,SAAS,OAAO,GAAG;EACzB,IAAI,WAAW,KAAA,GAAW;EAC1B,KAAK,IAAI,GAAG;EACZ,MAAM,KAAK,GAAG,OAAO,OAAO;CAC9B;CACA,OAAO;AACT;;AAGA,SAAgB,SAAS,QAAsB,YAAoB,UAA2B;CAC5F,OAAO,UAAU,QAAQ,UAAU,CAAC,CAAC,IAAI,QAAQ;AACnD;;;;;AAMA,SAAgB,YAAY,QAAsB,OAAyB;CACzE,MAAM,YAAY,UAAU,QAAQ,KAAK;CACzC,MAAM,kCAAkB,IAAI,IAAoB;CAChD,KAAK,MAAM,OAAO,WAChB,KAAK,MAAM,UAAU,OAAO,GAAG,CAAC,EAAE,WAAW,CAAC,GAC5C,gBAAgB,IAAI,SAAS,gBAAgB,IAAI,MAAM,KAAK,KAAK,CAAC;CAGtE,MAAM,UAAoB,CAAC;CAC3B,MAAM,QAAkB,CAAC;CACzB,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,UAAU,KAAA,GAAW,MAAM,KAAK,KAAK;CACzC,OAAO,MAAM,SAAS,GAAG;EACvB,IAAI,OAAO,MAAM,SAAS;EAC1B,MAAM,SAAS,WAAW,UAAU;GAClC,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,KAAa,UAAU,UAAU,OAAO,KAAK,UAAU,MAAM,OAAO;EACnF,CAAC;EACD,MAAM,CAAC,UAAU,MAAM,OAAO,MAAM,CAAC;EACrC,IAAI,WAAW,KAAA,GAAW;EAC1B,QAAQ,KAAK,MAAM;EACnB,KAAK,MAAM,UAAU,OAAO,SAAS;GACnC,MAAM,QAAQ,gBAAgB,IAAI,MAAM,KAAK,KAAK;GAClD,gBAAgB,IAAI,QAAQ,IAAI;GAChC,MAAM,eAAe,OAAO,MAAM;GAClC,IAAI,SAAS,KAAK,iBAAiB,KAAA,GAAW,MAAM,KAAK,YAAY;EACvE;CACF;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,UAAU,QAAsB,GAAW,GAA0B;CACnF,MAAM,QAAQ,UAAU,QAAQ,CAAC;CACjC,MAAM,SAAS,CAAC,GAAG,UAAU,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,QAAQ,MAAM,IAAI,GAAG,CAAC;CASvE,OARa,OAAO,QACjB,cAAc,CAAC,OAAO,MAAM,UAAU,UAAU,aAAa,SAAS,QAAQ,OAAO,SAAS,CAAC,CAEhF,CAAC,CAAC,UAAU,GAAG,MAAM;EACrC,MAAM,KAAK,OAAO,CAAC,CAAC,EAAE,UAAU,QAAQ;EACxC,MAAM,KAAK,OAAO,CAAC,CAAC,EAAE,UAAU,QAAQ;EACxC,OAAO,OAAO,KAAM,IAAI,IAAI,KAAK,IAAK,KAAK,KAAK,KAAK;CACvD,CACY,CAAC,CAAC,MAAM;AACtB"}
@@ -0,0 +1,9 @@
1
+ import { a as RpcOutput, r as RpcInput } from "../git-gateway-VA9Tc5tn.js";
2
+ import { ReferenceContext } from "./repo-state.js";
3
+ /** The reference `createRepo`. */
4
+ export declare function referenceCreateRepo(context: ReferenceContext, input: RpcInput<'createRepo'>): Promise<RpcOutput<'createRepo'>>;
5
+ /** The reference `deleteRepo`. */
6
+ export declare function referenceDeleteRepo(context: ReferenceContext, input: RpcInput<'deleteRepo'>): Promise<RpcOutput<'deleteRepo'>>;
7
+ /** The reference `mintReadToken`: an opaque, deterministic token (it authorizes nothing in memory). */
8
+ export declare function referenceMintReadToken(context: ReferenceContext, input: RpcInput<'mintReadToken'>): Promise<RpcOutput<'mintReadToken'>>;
9
+ //# sourceMappingURL=lifecycle-methods.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { RPC_SCHEMAS } from "../git-gateway.js";
2
+ import { gatewayError } from "../gateway-error.js";
3
+ import { utf8 } from "./bytes.js";
4
+ import { sha1Hex } from "./hash.js";
5
+ import { remoteUrlOf, requireRepo } from "./repo-state.js";
6
+ import { runMethod } from "./run-method.js";
7
+ // src/reference/lifecycle-methods.ts
8
+ /** The reference `createRepo`. */
9
+ function referenceCreateRepo(context, input) {
10
+ return runMethod(RPC_SCHEMAS.createRepo, input, async ({ repo, defaultBranch }) => {
11
+ if (context.repos.has(repo)) throw gatewayError("repo_exists", `Repository already exists: ${repo}`, { repo });
12
+ const createdAt = context.now().toISOString();
13
+ context.repos.set(repo, {
14
+ name: repo,
15
+ defaultBranch,
16
+ createdAt,
17
+ branches: /* @__PURE__ */ new Map(),
18
+ commits: /* @__PURE__ */ new Map(),
19
+ lock: Promise.resolve()
20
+ });
21
+ return {
22
+ name: repo,
23
+ defaultBranch,
24
+ createdAt,
25
+ remoteUrl: remoteUrlOf(context.config, repo)
26
+ };
27
+ });
28
+ }
29
+ /** The reference `deleteRepo`. */
30
+ function referenceDeleteRepo(context, input) {
31
+ return runMethod(RPC_SCHEMAS.deleteRepo, input, async ({ repo }) => ({ deleted: context.repos.delete(repo) }));
32
+ }
33
+ /** The reference `mintReadToken`: an opaque, deterministic token (it authorizes nothing in memory). */
34
+ function referenceMintReadToken(context, input) {
35
+ return runMethod(RPC_SCHEMAS.mintReadToken, input, async ({ repo, ttlSeconds }) => {
36
+ requireRepo(context, repo);
37
+ const now = context.now();
38
+ const expiresAt = new Date(now.getTime() + ttlSeconds * 1e3).toISOString();
39
+ return {
40
+ token: `ggr_${await sha1Hex(utf8(`${repo}\0${now.toISOString()}\0${expiresAt}`))}`,
41
+ expiresAt,
42
+ remoteUrl: remoteUrlOf(context.config, repo)
43
+ };
44
+ });
45
+ }
46
+ export { referenceCreateRepo, referenceDeleteRepo, referenceMintReadToken };
47
+
48
+ //# sourceMappingURL=lifecycle-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-methods.js","names":[],"sources":["../../src/reference/lifecycle-methods.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { RPC_SCHEMAS, type RpcInput, type RpcOutput } from '../git-gateway.ts';\nimport { gatewayError } from '../gateway-error.ts';\nimport { utf8 } from './bytes.ts';\nimport { sha1Hex } from './hash.ts';\nimport { remoteUrlOf, requireRepo, type ReferenceContext } from './repo-state.ts';\nimport { runMethod } from './run-method.ts';\n\n/** The reference `createRepo`. */\nexport function referenceCreateRepo(\n context: ReferenceContext,\n input: RpcInput<'createRepo'>,\n): Promise<RpcOutput<'createRepo'>> {\n return runMethod(RPC_SCHEMAS.createRepo, input, async ({ repo, defaultBranch }) => {\n if (context.repos.has(repo))\n throw gatewayError('repo_exists', `Repository already exists: ${repo}`, { repo });\n const createdAt = context.now().toISOString();\n context.repos.set(repo, {\n name: repo,\n defaultBranch,\n createdAt,\n branches: new Map(),\n commits: new Map(),\n lock: Promise.resolve(),\n });\n return { name: repo, defaultBranch, createdAt, remoteUrl: remoteUrlOf(context.config, repo) };\n });\n}\n\n/** The reference `deleteRepo`. */\nexport function referenceDeleteRepo(\n context: ReferenceContext,\n input: RpcInput<'deleteRepo'>,\n): Promise<RpcOutput<'deleteRepo'>> {\n return runMethod(RPC_SCHEMAS.deleteRepo, input, async ({ repo }) => ({\n deleted: context.repos.delete(repo),\n }));\n}\n\n/** The reference `mintReadToken`: an opaque, deterministic token (it authorizes nothing in memory). */\nexport function referenceMintReadToken(\n context: ReferenceContext,\n input: RpcInput<'mintReadToken'>,\n): Promise<RpcOutput<'mintReadToken'>> {\n return runMethod(RPC_SCHEMAS.mintReadToken, input, async ({ repo, ttlSeconds }) => {\n requireRepo(context, repo);\n const now = context.now();\n const expiresAt = new Date(now.getTime() + ttlSeconds * 1000).toISOString();\n const token = `ggr_${await sha1Hex(utf8(`${repo}\\0${now.toISOString()}\\0${expiresAt}`))}`;\n return { token, expiresAt, remoteUrl: remoteUrlOf(context.config, repo) };\n });\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,oBACd,SACA,OACkC;CAClC,OAAO,UAAU,YAAY,YAAY,OAAO,OAAO,EAAE,MAAM,oBAAoB;EACjF,IAAI,QAAQ,MAAM,IAAI,IAAI,GACxB,MAAM,aAAa,eAAe,8BAA8B,QAAQ,EAAE,KAAK,CAAC;EAClF,MAAM,YAAY,QAAQ,IAAI,CAAC,CAAC,YAAY;EAC5C,QAAQ,MAAM,IAAI,MAAM;GACtB,MAAM;GACN;GACA;GACA,0BAAU,IAAI,IAAI;GAClB,yBAAS,IAAI,IAAI;GACjB,MAAM,QAAQ,QAAQ;EACxB,CAAC;EACD,OAAO;GAAE,MAAM;GAAM;GAAe;GAAW,WAAW,YAAY,QAAQ,QAAQ,IAAI;EAAE;CAC9F,CAAC;AACH;;AAGA,SAAgB,oBACd,SACA,OACkC;CAClC,OAAO,UAAU,YAAY,YAAY,OAAO,OAAO,EAAE,YAAY,EACnE,SAAS,QAAQ,MAAM,OAAO,IAAI,EACpC,EAAE;AACJ;;AAGA,SAAgB,uBACd,SACA,OACqC;CACrC,OAAO,UAAU,YAAY,eAAe,OAAO,OAAO,EAAE,MAAM,iBAAiB;EACjF,YAAY,SAAS,IAAI;EACzB,MAAM,MAAM,QAAQ,IAAI;EACxB,MAAM,YAAY,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,GAAI,CAAC,CAAC,YAAY;EAE1E,OAAO;GAAE,OAAA,OADY,MAAM,QAAQ,KAAK,GAAG,KAAK,IAAI,IAAI,YAAY,EAAE,IAAI,WAAW,CAAC;GACtE;GAAW,WAAW,YAAY,QAAQ,QAAQ,IAAI;EAAE;CAC1E,CAAC;AACH"}
@@ -0,0 +1,13 @@
1
+ import { a as RpcOutput, r as RpcInput } from "../git-gateway-VA9Tc5tn.js";
2
+ import { ReferenceContext } from "./repo-state.js";
3
+ /** The reference `readFile`. */
4
+ export declare function referenceReadFile(context: ReferenceContext, input: RpcInput<'readFile'>): Promise<RpcOutput<'readFile'>>;
5
+ /** The reference `listTree`. */
6
+ export declare function referenceListTree(context: ReferenceContext, input: RpcInput<'listTree'>): Promise<RpcOutput<'listTree'>>;
7
+ /** The reference `resolveRef`. */
8
+ export declare function referenceResolveRef(context: ReferenceContext, input: RpcInput<'resolveRef'>): Promise<RpcOutput<'resolveRef'>>;
9
+ /** The reference `log`. */
10
+ export declare function referenceLog(context: ReferenceContext, input: RpcInput<'log'>): Promise<RpcOutput<'log'>>;
11
+ /** The reference `commitExists`. */
12
+ export declare function referenceCommitExists(context: ReferenceContext, input: RpcInput<'commitExists'>): Promise<RpcOutput<'commitExists'>>;
13
+ //# sourceMappingURL=read-methods.d.ts.map
@@ -0,0 +1,68 @@
1
+ import { RPC_SCHEMAS } from "../git-gateway.js";
2
+ import { encodeContent } from "./bytes.js";
3
+ import { contains, walkHistory } from "./history.js";
4
+ import { lookupIn, requireRepo, requireRevision, resolveRevision } from "./repo-state.js";
5
+ import { runMethod } from "./run-method.js";
6
+ import { entriesBeneath } from "./tree-index.js";
7
+ // src/reference/read-methods.ts
8
+ /** The reference `readFile`. */
9
+ function referenceReadFile(context, input) {
10
+ return runMethod(RPC_SCHEMAS.readFile, input, async ({ repo, ref, path, encoding }) => {
11
+ const stored = requireRevision(requireRepo(context, repo), ref);
12
+ const file = stored.files.get(path);
13
+ if (file === void 0) return null;
14
+ return {
15
+ path,
16
+ commit: stored.commit.sha,
17
+ sha: file.sha,
18
+ size: file.bytes.length,
19
+ executable: file.executable,
20
+ ...encodeContent(file.bytes, encoding)
21
+ };
22
+ });
23
+ }
24
+ /** The reference `listTree`. */
25
+ function referenceListTree(context, input) {
26
+ return runMethod(RPC_SCHEMAS.listTree, input, async ({ repo, ref, path, recursive }) => {
27
+ const stored = requireRevision(requireRepo(context, repo), ref);
28
+ const dir = path ?? "";
29
+ if (!stored.tree.directories.has(dir)) return null;
30
+ return {
31
+ commit: stored.commit.sha,
32
+ path: path ?? null,
33
+ entries: entriesBeneath(stored.tree, dir, recursive)
34
+ };
35
+ });
36
+ }
37
+ /** The reference `resolveRef`. */
38
+ function referenceResolveRef(context, input) {
39
+ return runMethod(RPC_SCHEMAS.resolveRef, input, async ({ repo, ref }) => {
40
+ const stored = resolveRevision(requireRepo(context, repo), ref);
41
+ return stored === void 0 ? null : { sha: stored.commit.sha };
42
+ });
43
+ }
44
+ /** The reference `log`. */
45
+ function referenceLog(context, input) {
46
+ return runMethod(RPC_SCHEMAS.log, input, async ({ repo, ref, limit, offset, since }) => {
47
+ const state = requireRepo(context, repo);
48
+ const start = requireRevision(state, ref);
49
+ const history = walkHistory(lookupIn(state), start.commit.sha).filter((commit) => since === void 0 || Date.parse(commit.committer.date) >= Date.parse(since));
50
+ return {
51
+ commits: history.slice(offset, offset + limit),
52
+ hasMore: history.length > offset + limit
53
+ };
54
+ });
55
+ }
56
+ /** The reference `commitExists`. */
57
+ function referenceCommitExists(context, input) {
58
+ return runMethod(RPC_SCHEMAS.commitExists, input, async ({ repo, sha, branch }) => {
59
+ const state = requireRepo(context, repo);
60
+ if (!state.commits.has(sha)) return { exists: false };
61
+ if (branch === void 0) return { exists: true };
62
+ const head = state.branches.get(branch);
63
+ return { exists: head !== void 0 && contains(lookupIn(state), head, sha) };
64
+ });
65
+ }
66
+ export { referenceCommitExists, referenceListTree, referenceLog, referenceReadFile, referenceResolveRef };
67
+
68
+ //# sourceMappingURL=read-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-methods.js","names":[],"sources":["../../src/reference/read-methods.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { RPC_SCHEMAS, type RpcInput, type RpcOutput } from '../git-gateway.ts';\nimport { encodeContent } from './bytes.ts';\nimport { contains, walkHistory } from './history.ts';\nimport {\n lookupIn,\n requireRepo,\n requireRevision,\n resolveRevision,\n type ReferenceContext,\n} from './repo-state.ts';\nimport { runMethod } from './run-method.ts';\nimport { entriesBeneath } from './tree-index.ts';\n\n/** The reference `readFile`. */\nexport function referenceReadFile(\n context: ReferenceContext,\n input: RpcInput<'readFile'>,\n): Promise<RpcOutput<'readFile'>> {\n return runMethod(RPC_SCHEMAS.readFile, input, async ({ repo, ref, path, encoding }) => {\n const stored = requireRevision(requireRepo(context, repo), ref);\n const file = stored.files.get(path);\n if (file === undefined) return null;\n return {\n path,\n commit: stored.commit.sha,\n sha: file.sha,\n size: file.bytes.length,\n executable: file.executable,\n ...encodeContent(file.bytes, encoding),\n };\n });\n}\n\n/** The reference `listTree`. */\nexport function referenceListTree(\n context: ReferenceContext,\n input: RpcInput<'listTree'>,\n): Promise<RpcOutput<'listTree'>> {\n return runMethod(RPC_SCHEMAS.listTree, input, async ({ repo, ref, path, recursive }) => {\n const stored = requireRevision(requireRepo(context, repo), ref);\n const dir = path ?? '';\n if (!stored.tree.directories.has(dir)) return null;\n return {\n commit: stored.commit.sha,\n path: path ?? null,\n entries: entriesBeneath(stored.tree, dir, recursive),\n };\n });\n}\n\n/** The reference `resolveRef`. */\nexport function referenceResolveRef(\n context: ReferenceContext,\n input: RpcInput<'resolveRef'>,\n): Promise<RpcOutput<'resolveRef'>> {\n return runMethod(RPC_SCHEMAS.resolveRef, input, async ({ repo, ref }) => {\n const stored = resolveRevision(requireRepo(context, repo), ref);\n return stored === undefined ? null : { sha: stored.commit.sha };\n });\n}\n\n/** The reference `log`. */\nexport function referenceLog(context: ReferenceContext, input: RpcInput<'log'>): Promise<RpcOutput<'log'>> {\n return runMethod(RPC_SCHEMAS.log, input, async ({ repo, ref, limit, offset, since }) => {\n const state = requireRepo(context, repo);\n const start = requireRevision(state, ref);\n const history = walkHistory(lookupIn(state), start.commit.sha).filter(\n (commit) => since === undefined || Date.parse(commit.committer.date) >= Date.parse(since),\n );\n return { commits: history.slice(offset, offset + limit), hasMore: history.length > offset + limit };\n });\n}\n\n/** The reference `commitExists`. */\nexport function referenceCommitExists(\n context: ReferenceContext,\n input: RpcInput<'commitExists'>,\n): Promise<RpcOutput<'commitExists'>> {\n return runMethod(RPC_SCHEMAS.commitExists, input, async ({ repo, sha, branch }) => {\n const state = requireRepo(context, repo);\n if (!state.commits.has(sha)) return { exists: false };\n if (branch === undefined) return { exists: true };\n const head = state.branches.get(branch);\n return { exists: head !== undefined && contains(lookupIn(state), head, sha) };\n });\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,kBACd,SACA,OACgC;CAChC,OAAO,UAAU,YAAY,UAAU,OAAO,OAAO,EAAE,MAAM,KAAK,MAAM,eAAe;EACrF,MAAM,SAAS,gBAAgB,YAAY,SAAS,IAAI,GAAG,GAAG;EAC9D,MAAM,OAAO,OAAO,MAAM,IAAI,IAAI;EAClC,IAAI,SAAS,KAAA,GAAW,OAAO;EAC/B,OAAO;GACL;GACA,QAAQ,OAAO,OAAO;GACtB,KAAK,KAAK;GACV,MAAM,KAAK,MAAM;GACjB,YAAY,KAAK;GACjB,GAAG,cAAc,KAAK,OAAO,QAAQ;EACvC;CACF,CAAC;AACH;;AAGA,SAAgB,kBACd,SACA,OACgC;CAChC,OAAO,UAAU,YAAY,UAAU,OAAO,OAAO,EAAE,MAAM,KAAK,MAAM,gBAAgB;EACtF,MAAM,SAAS,gBAAgB,YAAY,SAAS,IAAI,GAAG,GAAG;EAC9D,MAAM,MAAM,QAAQ;EACpB,IAAI,CAAC,OAAO,KAAK,YAAY,IAAI,GAAG,GAAG,OAAO;EAC9C,OAAO;GACL,QAAQ,OAAO,OAAO;GACtB,MAAM,QAAQ;GACd,SAAS,eAAe,OAAO,MAAM,KAAK,SAAS;EACrD;CACF,CAAC;AACH;;AAGA,SAAgB,oBACd,SACA,OACkC;CAClC,OAAO,UAAU,YAAY,YAAY,OAAO,OAAO,EAAE,MAAM,UAAU;EACvE,MAAM,SAAS,gBAAgB,YAAY,SAAS,IAAI,GAAG,GAAG;EAC9D,OAAO,WAAW,KAAA,IAAY,OAAO,EAAE,KAAK,OAAO,OAAO,IAAI;CAChE,CAAC;AACH;;AAGA,SAAgB,aAAa,SAA2B,OAAmD;CACzG,OAAO,UAAU,YAAY,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,QAAQ,YAAY;EACtF,MAAM,QAAQ,YAAY,SAAS,IAAI;EACvC,MAAM,QAAQ,gBAAgB,OAAO,GAAG;EACxC,MAAM,UAAU,YAAY,SAAS,KAAK,GAAG,MAAM,OAAO,GAAG,CAAC,CAAC,QAC5D,WAAW,UAAU,KAAA,KAAa,KAAK,MAAM,OAAO,UAAU,IAAI,KAAK,KAAK,MAAM,KAAK,CAC1F;EACA,OAAO;GAAE,SAAS,QAAQ,MAAM,QAAQ,SAAS,KAAK;GAAG,SAAS,QAAQ,SAAS,SAAS;EAAM;CACpG,CAAC;AACH;;AAGA,SAAgB,sBACd,SACA,OACoC;CACpC,OAAO,UAAU,YAAY,cAAc,OAAO,OAAO,EAAE,MAAM,KAAK,aAAa;EACjF,MAAM,QAAQ,YAAY,SAAS,IAAI;EACvC,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,GAAG,OAAO,EAAE,QAAQ,MAAM;EACpD,IAAI,WAAW,KAAA,GAAW,OAAO,EAAE,QAAQ,KAAK;EAChD,MAAM,OAAO,MAAM,SAAS,IAAI,MAAM;EACtC,OAAO,EAAE,QAAQ,SAAS,KAAA,KAAa,SAAS,SAAS,KAAK,GAAG,MAAM,GAAG,EAAE;CAC9E,CAAC;AACH"}
@@ -0,0 +1,18 @@
1
+ import { t as GitGateway } from "../git-gateway-VA9Tc5tn.js";
2
+ import { n as GatewayConfigInput } from "../gateway-config-oVsdTEeK.js";
3
+ import { t as Clock } from "../clock-B3MlpmVY.js";
4
+ /** Options for {@link createReferenceGateway}. */
5
+ export interface ReferenceGatewayOptions {
6
+ /** Gateway configuration; every field has a default. */
7
+ readonly config?: GatewayConfigInput;
8
+ /** Source of commit dates, token expiry and the idempotency window; defaults to the system clock. */
9
+ readonly now?: Clock;
10
+ }
11
+ /**
12
+ * The in-memory reference implementation of {@link GitGateway}: every rule of the contract on
13
+ * plain objects, no git objects and no I/O. Use it to develop and test consumers before (and
14
+ * alongside) the real gateway, and as the oracle the real gateway is tested against. Blob ids are
15
+ * git's; tree and commit ids are deterministic for a given clock (see `steppingClock`).
16
+ */
17
+ export declare function createReferenceGateway(options?: ReferenceGatewayOptions): GitGateway;
18
+ //# sourceMappingURL=reference-gateway.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { GatewayConfig } from "../schemas/gateway-config.js";
2
+ import { referencePromote, referenceSyncBranch } from "./branch-methods.js";
3
+ import { referenceCommit } from "./commit-method.js";
4
+ import { referenceCreateRepo, referenceDeleteRepo, referenceMintReadToken } from "./lifecycle-methods.js";
5
+ import { referenceCommitExists, referenceListTree, referenceLog, referenceReadFile, referenceResolveRef } from "./read-methods.js";
6
+ // src/reference/reference-gateway.ts
7
+ /**
8
+ * The in-memory reference implementation of {@link GitGateway}: every rule of the contract on
9
+ * plain objects, no git objects and no I/O. Use it to develop and test consumers before (and
10
+ * alongside) the real gateway, and as the oracle the real gateway is tested against. Blob ids are
11
+ * git's; tree and commit ids are deterministic for a given clock (see `steppingClock`).
12
+ */
13
+ function createReferenceGateway(options = {}) {
14
+ const context = {
15
+ config: GatewayConfig.parse(options.config ?? {}),
16
+ now: options.now ?? (() => /* @__PURE__ */ new Date()),
17
+ repos: /* @__PURE__ */ new Map()
18
+ };
19
+ return {
20
+ commit: (input) => referenceCommit(context, input),
21
+ readFile: (input) => referenceReadFile(context, input),
22
+ listTree: (input) => referenceListTree(context, input),
23
+ resolveRef: (input) => referenceResolveRef(context, input),
24
+ log: (input) => referenceLog(context, input),
25
+ commitExists: (input) => referenceCommitExists(context, input),
26
+ syncBranch: (input) => referenceSyncBranch(context, input),
27
+ promote: (input) => referencePromote(context, input),
28
+ createRepo: (input) => referenceCreateRepo(context, input),
29
+ deleteRepo: (input) => referenceDeleteRepo(context, input),
30
+ mintReadToken: (input) => referenceMintReadToken(context, input)
31
+ };
32
+ }
33
+ export { createReferenceGateway };
34
+
35
+ //# sourceMappingURL=reference-gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-gateway.js","names":[],"sources":["../../src/reference/reference-gateway.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitGateway } from '../git-gateway.ts';\nimport { GatewayConfig, type GatewayConfigInput } from '../schemas/gateway-config.ts';\nimport { referenceSyncBranch, referencePromote } from './branch-methods.ts';\nimport type { Clock } from './clock.ts';\nimport { referenceCommit } from './commit-method.ts';\nimport { referenceCreateRepo, referenceDeleteRepo, referenceMintReadToken } from './lifecycle-methods.ts';\nimport {\n referenceCommitExists,\n referenceListTree,\n referenceLog,\n referenceReadFile,\n referenceResolveRef,\n} from './read-methods.ts';\nimport type { ReferenceContext } from './repo-state.ts';\n\n/** Options for {@link createReferenceGateway}. */\nexport interface ReferenceGatewayOptions {\n /** Gateway configuration; every field has a default. */\n readonly config?: GatewayConfigInput;\n /** Source of commit dates, token expiry and the idempotency window; defaults to the system clock. */\n readonly now?: Clock;\n}\n\n/**\n * The in-memory reference implementation of {@link GitGateway}: every rule of the contract on\n * plain objects, no git objects and no I/O. Use it to develop and test consumers before (and\n * alongside) the real gateway, and as the oracle the real gateway is tested against. Blob ids are\n * git's; tree and commit ids are deterministic for a given clock (see `steppingClock`).\n */\nexport function createReferenceGateway(options: ReferenceGatewayOptions = {}): GitGateway {\n const context: ReferenceContext = {\n config: GatewayConfig.parse(options.config ?? {}),\n now: options.now ?? (() => new Date()),\n repos: new Map(),\n };\n return {\n commit: (input) => referenceCommit(context, input),\n readFile: (input) => referenceReadFile(context, input),\n listTree: (input) => referenceListTree(context, input),\n resolveRef: (input) => referenceResolveRef(context, input),\n log: (input) => referenceLog(context, input),\n commitExists: (input) => referenceCommitExists(context, input),\n syncBranch: (input) => referenceSyncBranch(context, input),\n promote: (input) => referencePromote(context, input),\n createRepo: (input) => referenceCreateRepo(context, input),\n deleteRepo: (input) => referenceDeleteRepo(context, input),\n mintReadToken: (input) => referenceMintReadToken(context, input),\n };\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAgB,uBAAuB,UAAmC,CAAC,GAAe;CACxF,MAAM,UAA4B;EAChC,QAAQ,cAAc,MAAM,QAAQ,UAAU,CAAC,CAAC;EAChD,KAAK,QAAQ,8BAAc,IAAI,KAAK;EACpC,uBAAO,IAAI,IAAI;CACjB;CACA,OAAO;EACL,SAAS,UAAU,gBAAgB,SAAS,KAAK;EACjD,WAAW,UAAU,kBAAkB,SAAS,KAAK;EACrD,WAAW,UAAU,kBAAkB,SAAS,KAAK;EACrD,aAAa,UAAU,oBAAoB,SAAS,KAAK;EACzD,MAAM,UAAU,aAAa,SAAS,KAAK;EAC3C,eAAe,UAAU,sBAAsB,SAAS,KAAK;EAC7D,aAAa,UAAU,oBAAoB,SAAS,KAAK;EACzD,UAAU,UAAU,iBAAiB,SAAS,KAAK;EACnD,aAAa,UAAU,oBAAoB,SAAS,KAAK;EACzD,aAAa,UAAU,oBAAoB,SAAS,KAAK;EACzD,gBAAgB,UAAU,uBAAuB,SAAS,KAAK;CACjE;AACF"}
@@ -0,0 +1,43 @@
1
+ import { t as Commit } from "../commit-BEZmeAOl.js";
2
+ import { t as GatewayConfig } from "../gateway-config-oVsdTEeK.js";
3
+ import { t as Clock } from "../clock-B3MlpmVY.js";
4
+ import { t as FileMap } from "../file-map-CxUveLWz.js";
5
+ import { t as CommitLookup } from "../history-CqvHaUE-.js";
6
+ import { t as TreeIndex } from "../tree-index-Bk721Phv.js";
7
+ /** A commit of the in-memory model with the snapshot it records. */
8
+ export interface StoredCommit {
9
+ readonly commit: Commit;
10
+ readonly files: FileMap;
11
+ readonly tree: TreeIndex;
12
+ }
13
+ /** One in-memory repository. */
14
+ export interface RepoState {
15
+ readonly name: string;
16
+ readonly defaultBranch: string;
17
+ readonly createdAt: string;
18
+ readonly branches: Map<string, string>;
19
+ readonly commits: Map<string, StoredCommit>;
20
+ /** Tail of the queue that serializes writes to this repository. */
21
+ lock: Promise<unknown>;
22
+ }
23
+ /** Everything the reference implementation's methods share. */
24
+ export interface ReferenceContext {
25
+ readonly config: GatewayConfig;
26
+ readonly now: Clock;
27
+ readonly repos: Map<string, RepoState>;
28
+ }
29
+ /** The repository, or repo_not_found. */
30
+ export declare function requireRepo(context: ReferenceContext, name: string): RepoState;
31
+ /** A commit lookup over one repository. */
32
+ export declare function lookupIn(repo: RepoState): CommitLookup;
33
+ /** The commit a revision names (a commit id, or a branch's head), or undefined. */
34
+ export declare function resolveRevision(repo: RepoState, revision: string): StoredCommit | undefined;
35
+ /** The commit a revision names, or ref_not_found. */
36
+ export declare function requireRevision(repo: RepoState, revision: string): StoredCommit;
37
+ /** The head of a branch, or ref_not_found. */
38
+ export declare function requireBranchHead(repo: RepoState, branch: string): string;
39
+ /** Runs `work` after every earlier write to the repository has settled, so writes never interleave. */
40
+ export declare function withRepoLock<T>(repo: RepoState, work: () => Promise<T>): Promise<T>;
41
+ /** The clone URL of a repository under the configured public base URL. */
42
+ export declare function remoteUrlOf(config: GatewayConfig, repo: string): string;
43
+ //# sourceMappingURL=repo-state.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { gatewayError } from "../gateway-error.js";
2
+ import { Sha } from "../schemas/sha.js";
3
+ // src/reference/repo-state.ts
4
+ /** The repository, or repo_not_found. */
5
+ function requireRepo(context, name) {
6
+ const repo = context.repos.get(name);
7
+ if (repo === void 0) throw gatewayError("repo_not_found", `Repository not found: ${name}`, { repo: name });
8
+ return repo;
9
+ }
10
+ /** A commit lookup over one repository. */
11
+ function lookupIn(repo) {
12
+ return (sha) => repo.commits.get(sha)?.commit;
13
+ }
14
+ /** The commit a revision names (a commit id, or a branch's head), or undefined. */
15
+ function resolveRevision(repo, revision) {
16
+ const sha = Sha.safeParse(revision).success ? revision : repo.branches.get(revision);
17
+ return sha === void 0 ? void 0 : repo.commits.get(sha);
18
+ }
19
+ /** The commit a revision names, or ref_not_found. */
20
+ function requireRevision(repo, revision) {
21
+ const stored = resolveRevision(repo, revision);
22
+ if (stored === void 0) throw gatewayError("ref_not_found", `Ref not found: ${revision}`, { ref: revision });
23
+ return stored;
24
+ }
25
+ /** The head of a branch, or ref_not_found. */
26
+ function requireBranchHead(repo, branch) {
27
+ const head = repo.branches.get(branch);
28
+ if (head === void 0) throw gatewayError("ref_not_found", `Branch not found: ${branch}`, { ref: branch });
29
+ return head;
30
+ }
31
+ /** Runs `work` after every earlier write to the repository has settled, so writes never interleave. */
32
+ function withRepoLock(repo, work) {
33
+ const run = repo.lock.then(work, work);
34
+ repo.lock = run.catch(() => void 0);
35
+ return run;
36
+ }
37
+ /** The clone URL of a repository under the configured public base URL. */
38
+ function remoteUrlOf(config, repo) {
39
+ let end = config.publicBaseUrl.length;
40
+ while (end > 0 && config.publicBaseUrl.charCodeAt(end - 1) === 47) end -= 1;
41
+ return `${config.publicBaseUrl.slice(0, end)}/${repo}.git`;
42
+ }
43
+ export { lookupIn, remoteUrlOf, requireBranchHead, requireRepo, requireRevision, resolveRevision, withRepoLock };
44
+
45
+ //# sourceMappingURL=repo-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-state.js","names":[],"sources":["../../src/reference/repo-state.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { gatewayError } from '../gateway-error.ts';\nimport type { Commit } from '../schemas/commit.ts';\nimport type { GatewayConfig } from '../schemas/gateway-config.ts';\nimport { Sha } from '../schemas/sha.ts';\nimport type { Clock } from './clock.ts';\nimport type { FileMap } from './file-map.ts';\nimport type { CommitLookup } from './history.ts';\nimport type { TreeIndex } from './tree-index.ts';\n\n/** A commit of the in-memory model with the snapshot it records. */\nexport interface StoredCommit {\n readonly commit: Commit;\n readonly files: FileMap;\n readonly tree: TreeIndex;\n}\n\n/** One in-memory repository. */\nexport interface RepoState {\n readonly name: string;\n readonly defaultBranch: string;\n readonly createdAt: string;\n readonly branches: Map<string, string>;\n readonly commits: Map<string, StoredCommit>;\n /** Tail of the queue that serializes writes to this repository. */\n lock: Promise<unknown>;\n}\n\n/** Everything the reference implementation's methods share. */\nexport interface ReferenceContext {\n readonly config: GatewayConfig;\n readonly now: Clock;\n readonly repos: Map<string, RepoState>;\n}\n\n/** The repository, or repo_not_found. */\nexport function requireRepo(context: ReferenceContext, name: string): RepoState {\n const repo = context.repos.get(name);\n if (repo === undefined)\n throw gatewayError('repo_not_found', `Repository not found: ${name}`, { repo: name });\n return repo;\n}\n\n/** A commit lookup over one repository. */\nexport function lookupIn(repo: RepoState): CommitLookup {\n return (sha) => repo.commits.get(sha)?.commit;\n}\n\n/** The commit a revision names (a commit id, or a branch's head), or undefined. */\nexport function resolveRevision(repo: RepoState, revision: string): StoredCommit | undefined {\n const sha = Sha.safeParse(revision).success ? revision : repo.branches.get(revision);\n return sha === undefined ? undefined : repo.commits.get(sha);\n}\n\n/** The commit a revision names, or ref_not_found. */\nexport function requireRevision(repo: RepoState, revision: string): StoredCommit {\n const stored = resolveRevision(repo, revision);\n if (stored === undefined)\n throw gatewayError('ref_not_found', `Ref not found: ${revision}`, { ref: revision });\n return stored;\n}\n\n/** The head of a branch, or ref_not_found. */\nexport function requireBranchHead(repo: RepoState, branch: string): string {\n const head = repo.branches.get(branch);\n if (head === undefined) throw gatewayError('ref_not_found', `Branch not found: ${branch}`, { ref: branch });\n return head;\n}\n\n/** Runs `work` after every earlier write to the repository has settled, so writes never interleave. */\nexport function withRepoLock<T>(repo: RepoState, work: () => Promise<T>): Promise<T> {\n const run = repo.lock.then(work, work);\n repo.lock = run.catch(() => undefined);\n return run;\n}\n\n/** The clone URL of a repository under the configured public base URL. */\nexport function remoteUrlOf(config: GatewayConfig, repo: string): string {\n // A scan from the end, not /\\/+$/, which retries from every slash run (polynomial time).\n let end = config.publicBaseUrl.length;\n while (end > 0 && config.publicBaseUrl.charCodeAt(end - 1) === 47) end -= 1;\n return `${config.publicBaseUrl.slice(0, end)}/${repo}.git`;\n}\n"],"mappings":";;;;AAoCA,SAAgB,YAAY,SAA2B,MAAyB;CAC9E,MAAM,OAAO,QAAQ,MAAM,IAAI,IAAI;CACnC,IAAI,SAAS,KAAA,GACX,MAAM,aAAa,kBAAkB,yBAAyB,QAAQ,EAAE,MAAM,KAAK,CAAC;CACtF,OAAO;AACT;;AAGA,SAAgB,SAAS,MAA+B;CACtD,QAAQ,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,EAAE;AACzC;;AAGA,SAAgB,gBAAgB,MAAiB,UAA4C;CAC3F,MAAM,MAAM,IAAI,UAAU,QAAQ,CAAC,CAAC,UAAU,WAAW,KAAK,SAAS,IAAI,QAAQ;CACnF,OAAO,QAAQ,KAAA,IAAY,KAAA,IAAY,KAAK,QAAQ,IAAI,GAAG;AAC7D;;AAGA,SAAgB,gBAAgB,MAAiB,UAAgC;CAC/E,MAAM,SAAS,gBAAgB,MAAM,QAAQ;CAC7C,IAAI,WAAW,KAAA,GACb,MAAM,aAAa,iBAAiB,kBAAkB,YAAY,EAAE,KAAK,SAAS,CAAC;CACrF,OAAO;AACT;;AAGA,SAAgB,kBAAkB,MAAiB,QAAwB;CACzE,MAAM,OAAO,KAAK,SAAS,IAAI,MAAM;CACrC,IAAI,SAAS,KAAA,GAAW,MAAM,aAAa,iBAAiB,qBAAqB,UAAU,EAAE,KAAK,OAAO,CAAC;CAC1G,OAAO;AACT;;AAGA,SAAgB,aAAgB,MAAiB,MAAoC;CACnF,MAAM,MAAM,KAAK,KAAK,KAAK,MAAM,IAAI;CACrC,KAAK,OAAO,IAAI,YAAY,KAAA,CAAS;CACrC,OAAO;AACT;;AAGA,SAAgB,YAAY,QAAuB,MAAsB;CAEvE,IAAI,MAAM,OAAO,cAAc;CAC/B,OAAO,MAAM,KAAK,OAAO,cAAc,WAAW,MAAM,CAAC,MAAM,IAAI,OAAO;CAC1E,OAAO,GAAG,OAAO,cAAc,MAAM,GAAG,GAAG,EAAE,GAAG,KAAK;AACvD"}
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ /** The input and output schema of one RPC method. */
3
+ export interface MethodSchemas<I extends z.ZodType, O extends z.ZodType> {
4
+ readonly input: I;
5
+ readonly output: O;
6
+ }
7
+ /**
8
+ * Runs one RPC method the way every implementation must: parse the input (invalid_input on
9
+ * failure), do the work, and parse the result with the output schema, so the reference can never
10
+ * return something its own contract rejects.
11
+ */
12
+ export declare function runMethod<I extends z.ZodType, O extends z.ZodType>(schemas: MethodSchemas<I, O>, input: unknown, work: (parsed: z.output<I>) => Promise<z.input<O>>): Promise<z.output<O>>;
13
+ //# sourceMappingURL=run-method.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { invalidInput } from "../gateway-error.js";
2
+ // src/reference/run-method.ts
3
+ /**
4
+ * Runs one RPC method the way every implementation must: parse the input (invalid_input on
5
+ * failure), do the work, and parse the result with the output schema, so the reference can never
6
+ * return something its own contract rejects.
7
+ */
8
+ async function runMethod(schemas, input, work) {
9
+ const parsed = schemas.input.safeParse(input);
10
+ if (!parsed.success) throw invalidInput(parsed.error);
11
+ return schemas.output.parse(await work(parsed.data));
12
+ }
13
+ export { runMethod };
14
+
15
+ //# sourceMappingURL=run-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-method.js","names":[],"sources":["../../src/reference/run-method.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { z } from 'zod';\n\nimport { invalidInput } from '../gateway-error.ts';\n\n/** The input and output schema of one RPC method. */\nexport interface MethodSchemas<I extends z.ZodType, O extends z.ZodType> {\n readonly input: I;\n readonly output: O;\n}\n\n/**\n * Runs one RPC method the way every implementation must: parse the input (invalid_input on\n * failure), do the work, and parse the result with the output schema, so the reference can never\n * return something its own contract rejects.\n */\nexport async function runMethod<I extends z.ZodType, O extends z.ZodType>(\n schemas: MethodSchemas<I, O>,\n input: unknown,\n work: (parsed: z.output<I>) => Promise<z.input<O>>,\n): Promise<z.output<O>> {\n const parsed = schemas.input.safeParse(input);\n if (!parsed.success) throw invalidInput(parsed.error);\n return schemas.output.parse(await work(parsed.data));\n}\n"],"mappings":";;;;;;;AAgBA,eAAsB,UACpB,SACA,OACA,MACsB;CACtB,MAAM,SAAS,QAAQ,MAAM,UAAU,KAAK;CAC5C,IAAI,CAAC,OAAO,SAAS,MAAM,aAAa,OAAO,KAAK;CACpD,OAAO,QAAQ,OAAO,MAAM,MAAM,KAAK,OAAO,IAAI,CAAC;AACrD"}
@@ -0,0 +1,16 @@
1
+ import { t as FileMap } from "../file-map-CxUveLWz.js";
2
+ /** The result of a file-level three-way merge. */
3
+ export type MergeResult = {
4
+ readonly kind: 'merged';
5
+ readonly files: FileMap;
6
+ } | {
7
+ readonly kind: 'conflict';
8
+ readonly paths: readonly string[];
9
+ };
10
+ /**
11
+ * Merges two snapshots file by file against their merge base. A path changed on only one side
12
+ * takes that side; a path changed identically on both takes either; a path changed differently on
13
+ * both sides is a conflict, as is a file on one side where the merged result has a directory.
14
+ */
15
+ export declare function threeWayMerge(base: FileMap, ours: FileMap, theirs: FileMap): MergeResult;
16
+ //# sourceMappingURL=three-way-merge.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { byteOrder } from "./bytes.js";
2
+ import { parentDirectories, sameFile } from "./file-map.js";
3
+ // src/reference/three-way-merge.ts
4
+ /**
5
+ * Merges two snapshots file by file against their merge base. A path changed on only one side
6
+ * takes that side; a path changed identically on both takes either; a path changed differently on
7
+ * both sides is a conflict, as is a file on one side where the merged result has a directory.
8
+ */
9
+ function threeWayMerge(base, ours, theirs) {
10
+ const merged = /* @__PURE__ */ new Map();
11
+ const conflicts = /* @__PURE__ */ new Set();
12
+ const paths = /* @__PURE__ */ new Set([
13
+ ...base.keys(),
14
+ ...ours.keys(),
15
+ ...theirs.keys()
16
+ ]);
17
+ for (const path of paths) {
18
+ const b = base.get(path);
19
+ const o = ours.get(path);
20
+ const t = theirs.get(path);
21
+ let pick;
22
+ if (sameFile(o, t) || sameFile(t, b)) pick = o;
23
+ else if (sameFile(o, b)) pick = t;
24
+ else {
25
+ conflicts.add(path);
26
+ continue;
27
+ }
28
+ if (pick !== void 0) merged.set(path, pick);
29
+ }
30
+ for (const path of merged.keys()) for (const parent of parentDirectories(path)) if (merged.has(parent) || conflicts.has(parent)) {
31
+ conflicts.add(parent);
32
+ conflicts.add(path);
33
+ }
34
+ if (conflicts.size > 0) return {
35
+ kind: "conflict",
36
+ paths: [...conflicts].toSorted(byteOrder)
37
+ };
38
+ return {
39
+ kind: "merged",
40
+ files: merged
41
+ };
42
+ }
43
+ export { threeWayMerge };
44
+
45
+ //# sourceMappingURL=three-way-merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"three-way-merge.js","names":[],"sources":["../../src/reference/three-way-merge.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { byteOrder } from './bytes.ts';\nimport { parentDirectories, sameFile, type FileMap, type StoredFile } from './file-map.ts';\n\n/** The result of a file-level three-way merge. */\nexport type MergeResult =\n | { readonly kind: 'merged'; readonly files: FileMap }\n | { readonly kind: 'conflict'; readonly paths: readonly string[] };\n\n/**\n * Merges two snapshots file by file against their merge base. A path changed on only one side\n * takes that side; a path changed identically on both takes either; a path changed differently on\n * both sides is a conflict, as is a file on one side where the merged result has a directory.\n */\nexport function threeWayMerge(base: FileMap, ours: FileMap, theirs: FileMap): MergeResult {\n const merged = new Map<string, StoredFile>();\n const conflicts = new Set<string>();\n const paths = new Set([...base.keys(), ...ours.keys(), ...theirs.keys()]);\n for (const path of paths) {\n const b = base.get(path);\n const o = ours.get(path);\n const t = theirs.get(path);\n let pick: StoredFile | undefined;\n if (sameFile(o, t) || sameFile(t, b)) pick = o;\n else if (sameFile(o, b)) pick = t;\n else {\n conflicts.add(path);\n continue;\n }\n if (pick !== undefined) merged.set(path, pick);\n }\n for (const path of merged.keys()) {\n for (const parent of parentDirectories(path)) {\n if (merged.has(parent) || conflicts.has(parent)) {\n conflicts.add(parent);\n conflicts.add(path);\n }\n }\n }\n if (conflicts.size > 0) return { kind: 'conflict', paths: [...conflicts].toSorted(byteOrder) };\n return { kind: 'merged', files: merged };\n}\n"],"mappings":";;;;;;;;AAcA,SAAgB,cAAc,MAAe,MAAe,QAA8B;CACxF,MAAM,yBAAS,IAAI,IAAwB;CAC3C,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,wBAAQ,IAAI,IAAI;EAAC,GAAG,KAAK,KAAK;EAAG,GAAG,KAAK,KAAK;EAAG,GAAG,OAAO,KAAK;CAAC,CAAC;CACxE,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,IAAI,KAAK,IAAI,IAAI;EACvB,MAAM,IAAI,KAAK,IAAI,IAAI;EACvB,MAAM,IAAI,OAAO,IAAI,IAAI;EACzB,IAAI;EACJ,IAAI,SAAS,GAAG,CAAC,KAAK,SAAS,GAAG,CAAC,GAAG,OAAO;OACxC,IAAI,SAAS,GAAG,CAAC,GAAG,OAAO;OAC3B;GACH,UAAU,IAAI,IAAI;GAClB;EACF;EACA,IAAI,SAAS,KAAA,GAAW,OAAO,IAAI,MAAM,IAAI;CAC/C;CACA,KAAK,MAAM,QAAQ,OAAO,KAAK,GAC7B,KAAK,MAAM,UAAU,kBAAkB,IAAI,GACzC,IAAI,OAAO,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,GAAG;EAC/C,UAAU,IAAI,MAAM;EACpB,UAAU,IAAI,IAAI;CACpB;CAGJ,IAAI,UAAU,OAAO,GAAG,OAAO;EAAE,MAAM;EAAY,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,SAAS,SAAS;CAAE;CAC7F,OAAO;EAAE,MAAM;EAAU,OAAO;CAAO;AACzC"}