@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,78 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { ZERO_SHA } from '../schemas/sha.ts';
3
+ import { assertEqual, expectGatewayError } from './assertions.ts';
4
+ import { behaviourCase, type BehaviourCase } from './behaviour-case.ts';
5
+ import { branchFrom, requireHead, seedRepo, writeFiles } from './fixtures.ts';
6
+
7
+ const GROUP = 'promote';
8
+
9
+ /** promote fast-forwards from the source head only, and every refusal. */
10
+ export const promoteCases: readonly BehaviourCase[] = [
11
+ behaviourCase(
12
+ GROUP,
13
+ 'promotes the source head when it contains the target head',
14
+ async ({ gateway, repo }) => {
15
+ const seed = await seedRepo(gateway, repo);
16
+ const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'new.md': 'n' });
17
+ const output = await gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha });
18
+ assertEqual(
19
+ output,
20
+ { status: 'promoted', refUpdate: { ref: 'refs/heads/main', oldSha: seed.sha, newSha: staging.sha } },
21
+ 'fast-forwarded',
22
+ );
23
+ assertEqual(await requireHead(gateway, repo, 'main'), staging.sha, 'main moved');
24
+ },
25
+ ),
26
+ behaviourCase(GROUP, 'up_to_date when the target already points at sha', async ({ gateway, repo }) => {
27
+ const seed = await seedRepo(gateway, repo);
28
+ await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });
29
+ const output = await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });
30
+ assertEqual(output, { status: 'up_to_date', head: seed.sha }, 'nothing to do');
31
+ }),
32
+ behaviourCase(GROUP, 'a missing target branch is created at sha', async ({ gateway, repo }) => {
33
+ const seed = await seedRepo(gateway, repo);
34
+ const output = await gateway.promote({ repo, from: 'main', into: 'production', sha: seed.sha });
35
+ assertEqual(
36
+ output,
37
+ { status: 'promoted', refUpdate: { ref: 'refs/heads/production', oldSha: ZERO_SHA, newSha: seed.sha } },
38
+ 'created',
39
+ );
40
+ }),
41
+ behaviourCase(GROUP, 'refuses a sha that is not the source head', async ({ gateway, repo }) => {
42
+ const seed = await seedRepo(gateway, repo);
43
+ const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });
44
+ const newer = await writeFiles(gateway, repo, 'staging', { 'b.md': 'b' });
45
+ const error = await expectGatewayError(
46
+ gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha }),
47
+ 'not_head_of_source',
48
+ );
49
+ assertEqual(error.details, { from: 'staging', sha: staging.sha, head: newer.sha }, 'details');
50
+ assertEqual(await requireHead(gateway, repo, 'main'), seed.sha, 'main unchanged');
51
+ }),
52
+ behaviourCase(GROUP, 'refuses an unknown sha as not_head_of_source', async ({ gateway, repo }) => {
53
+ await seedRepo(gateway, repo);
54
+ await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });
55
+ const sha = 'ffffffffffffffffffffffffffffffffffffffff';
56
+ await expectGatewayError(
57
+ gateway.promote({ repo, from: 'staging', into: 'main', sha }),
58
+ 'not_head_of_source',
59
+ );
60
+ }),
61
+ behaviourCase(GROUP, 'refuses a non-fast-forward and never merges', async ({ gateway, repo }) => {
62
+ await seedRepo(gateway, repo);
63
+ const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'a.md': 'a' });
64
+ const hotfix = await writeFiles(gateway, repo, 'main', { 'hotfix.md': 'h' });
65
+ const error = await expectGatewayError(
66
+ gateway.promote({ repo, from: 'staging', into: 'main', sha: staging.sha }),
67
+ 'not_fast_forward',
68
+ );
69
+ assertEqual(error.details, { into: 'main', sha: staging.sha, head: hotfix.sha }, 'details');
70
+ assertEqual(await requireHead(gateway, repo, 'main'), hotfix.sha, 'main unchanged');
71
+ assertEqual(await requireHead(gateway, repo, 'staging'), staging.sha, 'staging unchanged');
72
+ }),
73
+ behaviourCase(GROUP, 'a missing source branch is ref_not_found', async ({ gateway, repo }) => {
74
+ const seed = await seedRepo(gateway, repo);
75
+ const call = gateway.promote({ repo, from: 'staging', into: 'main', sha: seed.sha });
76
+ assertEqual((await expectGatewayError(call, 'ref_not_found')).details.ref, 'staging', 'names the source');
77
+ }),
78
+ ];
@@ -0,0 +1,176 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { assertEqual, assertTrue, expectGatewayError, present } from './assertions.ts';
3
+ import { behaviourCase, type BehaviourCase } from './behaviour-case.ts';
4
+ import { branchFrom, readText, seedRepo, writeFiles } from './fixtures.ts';
5
+
6
+ const GROUP = 'reads';
7
+ const SEED = { 'a.md': 'hello\n', 'dir/b.md': 'b', 'dir/sub/c.md': 'c', 'z.md': 'hello\n' };
8
+ const UNKNOWN_SHA = 'ffffffffffffffffffffffffffffffffffffffff';
9
+
10
+ /** readFile, listTree, resolveRef, log and commitExists. */
11
+ export const readCases: readonly BehaviourCase[] = [
12
+ behaviourCase(
13
+ GROUP,
14
+ 'readFile returns content, git blob id, size, mode and commit',
15
+ async ({ gateway, repo }) => {
16
+ const seed = await seedRepo(gateway, repo, SEED);
17
+ const file = present(await gateway.readFile({ repo, ref: 'main', path: 'a.md' }), 'file exists');
18
+ assertEqual(
19
+ file,
20
+ {
21
+ path: 'a.md',
22
+ commit: seed.sha,
23
+ sha: 'ce013625030ba8dba906f756967f9e9ca394464a',
24
+ size: 6,
25
+ executable: false,
26
+ encoding: 'text',
27
+ content: 'hello\n',
28
+ },
29
+ 'file read',
30
+ );
31
+ const twin = await gateway.readFile({ repo, ref: 'main', path: 'z.md' });
32
+ assertEqual(twin?.sha, file.sha, 'equal content has an equal blob id');
33
+ },
34
+ ),
35
+ behaviourCase(GROUP, 'readFile at an old commit reads the old content', async ({ gateway, repo }) => {
36
+ const seed = await seedRepo(gateway, repo, SEED);
37
+ await writeFiles(gateway, repo, 'main', { 'a.md': 'changed' });
38
+ assertEqual(await readText(gateway, repo, seed.sha, 'a.md'), 'hello\n', 'old content by sha');
39
+ assertEqual(await readText(gateway, repo, 'main', 'a.md'), 'changed', 'new content by branch');
40
+ }),
41
+ behaviourCase(GROUP, 'readFile is null for a missing path or a directory', async ({ gateway, repo }) => {
42
+ await seedRepo(gateway, repo, SEED);
43
+ assertEqual(await gateway.readFile({ repo, ref: 'main', path: 'nope.md' }), null, 'missing path');
44
+ assertEqual(await gateway.readFile({ repo, ref: 'main', path: 'dir' }), null, 'directory');
45
+ }),
46
+ behaviourCase(GROUP, 'reads at a missing ref are ref_not_found', async ({ gateway, repo }) => {
47
+ await seedRepo(gateway, repo, SEED);
48
+ await expectGatewayError(gateway.readFile({ repo, ref: 'nope', path: 'a.md' }), 'ref_not_found');
49
+ await expectGatewayError(gateway.readFile({ repo, ref: UNKNOWN_SHA, path: 'a.md' }), 'ref_not_found');
50
+ await expectGatewayError(gateway.listTree({ repo, ref: 'nope' }), 'ref_not_found');
51
+ await expectGatewayError(gateway.log({ repo, ref: 'nope' }), 'ref_not_found');
52
+ }),
53
+ behaviourCase(
54
+ GROUP,
55
+ 'listTree lists one level, sorted, with types and modes',
56
+ async ({ gateway, repo }) => {
57
+ const seed = await seedRepo(gateway, repo, SEED);
58
+ const root = present(await gateway.listTree({ repo, ref: 'main' }), 'root listing');
59
+ assertEqual([root.commit, root.path], [seed.sha, null], 'listing header');
60
+ assertEqual(
61
+ root.entries.map((entry) => [entry.path, entry.name, entry.type, entry.mode]),
62
+ [
63
+ ['a.md', 'a.md', 'blob', '100644'],
64
+ ['dir', 'dir', 'tree', '040000'],
65
+ ['z.md', 'z.md', 'blob', '100644'],
66
+ ],
67
+ 'root entries',
68
+ );
69
+ const dir = present(await gateway.listTree({ repo, ref: 'main', path: 'dir' }), 'dir listing');
70
+ assertEqual(
71
+ dir.entries.map((entry) => entry.path),
72
+ ['dir/b.md', 'dir/sub'],
73
+ 'dir entries',
74
+ );
75
+ },
76
+ ),
77
+ behaviourCase(
78
+ GROUP,
79
+ 'listTree recursive lists everything beneath, directories included',
80
+ async ({ gateway, repo }) => {
81
+ await seedRepo(gateway, repo, SEED);
82
+ const listing = present(
83
+ await gateway.listTree({ repo, ref: 'main', path: 'dir', recursive: true }),
84
+ 'listing',
85
+ );
86
+ assertEqual(
87
+ listing.entries.map((entry) => entry.path),
88
+ ['dir/b.md', 'dir/sub', 'dir/sub/c.md'],
89
+ 'entries',
90
+ );
91
+ },
92
+ ),
93
+ behaviourCase(GROUP, 'listTree is null for a file or a missing directory', async ({ gateway, repo }) => {
94
+ await seedRepo(gateway, repo, SEED);
95
+ assertEqual(await gateway.listTree({ repo, ref: 'main', path: 'a.md' }), null, 'file');
96
+ assertEqual(await gateway.listTree({ repo, ref: 'main', path: 'nope' }), null, 'missing');
97
+ }),
98
+ behaviourCase(GROUP, 'an unchanged directory keeps its tree id', async ({ gateway, repo }) => {
99
+ const seed = await seedRepo(gateway, repo, SEED);
100
+ const next = await writeFiles(gateway, repo, 'main', { 'a.md': 'changed' });
101
+ const dirSha = async (ref: string) =>
102
+ (await gateway.listTree({ repo, ref }))?.entries.find((entry) => entry.path === 'dir')?.sha;
103
+ assertEqual(await dirSha(next.sha), await dirSha(seed.sha), 'dir tree id unchanged');
104
+ assertTrue(next.tree !== seed.tree, 'root tree id changed');
105
+ }),
106
+ behaviourCase(GROUP, 'resolveRef resolves branches and confirms commit ids', async ({ gateway, repo }) => {
107
+ const seed = await seedRepo(gateway, repo, SEED);
108
+ assertEqual(await gateway.resolveRef({ repo, ref: 'main' }), { sha: seed.sha }, 'branch');
109
+ assertEqual(await gateway.resolveRef({ repo, ref: seed.sha }), { sha: seed.sha }, 'commit id');
110
+ assertEqual(await gateway.resolveRef({ repo, ref: 'nope' }), null, 'missing branch');
111
+ assertEqual(await gateway.resolveRef({ repo, ref: UNKNOWN_SHA }), null, 'unknown commit');
112
+ }),
113
+ behaviourCase(
114
+ GROUP,
115
+ 'log lists newest first and pages with limit, offset and hasMore',
116
+ async ({ gateway, repo }) => {
117
+ const first = await seedRepo(gateway, repo, SEED);
118
+ const second = await writeFiles(gateway, repo, 'main', { 'n.md': '2' });
119
+ const third = await writeFiles(gateway, repo, 'main', { 'n.md': '3' });
120
+ const all = await gateway.log({ repo, ref: 'main' });
121
+ assertEqual(
122
+ all.commits.map((c) => c.sha),
123
+ [third.sha, second.sha, first.sha],
124
+ 'newest first',
125
+ );
126
+ assertEqual(all.hasMore, false, 'no more');
127
+ const page = await gateway.log({ repo, ref: 'main', limit: 1, offset: 1 });
128
+ assertEqual([page.commits.map((c) => c.sha), page.hasMore], [[second.sha], true], 'second page');
129
+ const atSha = await gateway.log({ repo, ref: second.sha });
130
+ assertEqual(
131
+ atSha.commits.map((c) => c.sha),
132
+ [second.sha, first.sha],
133
+ 'log from a commit id',
134
+ );
135
+ },
136
+ ),
137
+ behaviourCase(GROUP, 'log since keeps commits at or after the time', async ({ gateway, repo }) => {
138
+ const first = await seedRepo(gateway, repo, SEED);
139
+ const second = await writeFiles(gateway, repo, 'main', { 'n.md': '2' });
140
+ const since = (date: string) => gateway.log({ repo, ref: 'main', since: date });
141
+ assertEqual((await since('2000-01-01T00:00:00.000Z')).commits.length, 2, 'all after the distant past');
142
+ assertEqual((await since('2999-01-01T00:00:00.000Z')).commits, [], 'none after the far future');
143
+ const fromSecond = (await since(second.committer.date)).commits.map((c) => c.sha);
144
+ assertTrue(fromSecond.includes(second.sha), 'a commit at exactly `since` is kept');
145
+ assertTrue(first.committer.date <= second.committer.date, 'dates never go backwards');
146
+ }),
147
+ behaviourCase(
148
+ GROUP,
149
+ 'log of a merge lists both sides, children before parents',
150
+ async ({ gateway, repo }) => {
151
+ const seed = await seedRepo(gateway, repo, SEED);
152
+ const side = await branchFrom(gateway, repo, 'main', 'side', { 's.md': 's' });
153
+ const mainline = await writeFiles(gateway, repo, 'main', { 'm.md': 'm' });
154
+ await gateway.syncBranch({ repo, from: 'side', into: 'main' });
155
+ const shas = (await gateway.log({ repo, ref: 'main' })).commits.map((c) => c.sha);
156
+ assertEqual(shas.length, 4, 'merge, both sides and the seed');
157
+ assertEqual(shas.at(-1), seed.sha, 'root last');
158
+ assertTrue(shas.includes(side.sha) && shas.includes(mainline.sha), 'both sides listed');
159
+ },
160
+ ),
161
+ behaviourCase(
162
+ GROUP,
163
+ 'commitExists checks the repository and, optionally, a branch',
164
+ async ({ gateway, repo }) => {
165
+ const seed = await seedRepo(gateway, repo, SEED);
166
+ const side = await branchFrom(gateway, repo, 'main', 'side', { 's.md': 's' });
167
+ const exists = async (sha: string, branch?: string) =>
168
+ (await gateway.commitExists({ repo, sha, ...(branch === undefined ? {} : { branch }) })).exists;
169
+ assertEqual(await exists(side.sha), true, 'any commit');
170
+ assertEqual(await exists(UNKNOWN_SHA), false, 'unknown commit');
171
+ assertEqual(await exists(seed.sha, 'side'), true, 'ancestor is reachable');
172
+ assertEqual(await exists(side.sha, 'main'), false, 'not on main');
173
+ assertEqual(await exists(seed.sha, 'nope'), false, 'missing branch');
174
+ },
175
+ ),
176
+ ];
@@ -0,0 +1,156 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { assertEqual, assertTrue, expectGatewayError, expectStatus } from './assertions.ts';
3
+ import { behaviourCase, type BehaviourCase } from './behaviour-case.ts';
4
+ import { branchFrom, filePaths, readText, requireHead, seedRepo, writeFiles } from './fixtures.ts';
5
+
6
+ const GROUP = 'syncBranch';
7
+ const SEED = { 'shared.md': 'base\n', 'other.md': 'other\n', 'keep.md': 'keep\n' };
8
+
9
+ /** Diverges `main` and `staging` from a common seed with one commit each; returns both heads. */
10
+ async function diverge(
11
+ gateway: Parameters<BehaviourCase['run']>[0]['gateway'],
12
+ repo: string,
13
+ onMain: Record<string, string | null>,
14
+ onStaging: Record<string, string | null>,
15
+ ): Promise<{ base: string; main: string; staging: string }> {
16
+ const base = await seedRepo(gateway, repo, SEED);
17
+ const staging = await branchFrom(gateway, repo, 'main', 'staging', onStaging);
18
+ const main = await writeFiles(gateway, repo, 'main', onMain);
19
+ return { base: base.sha, main: main.sha, staging: staging.sha };
20
+ }
21
+
22
+ /** Every syncBranch shape: up to date, fast-forward, merge, conflict, and its refusals. */
23
+ export const syncCases: readonly BehaviourCase[] = [
24
+ behaviourCase(GROUP, 'up_to_date when into already contains from', async ({ gateway, repo }) => {
25
+ await seedRepo(gateway, repo, SEED);
26
+ const staging = await branchFrom(gateway, repo, 'main', 'staging', { 'new.md': 'n' });
27
+ const output = await gateway.syncBranch({ repo, from: 'main', into: 'staging' });
28
+ assertEqual(output, { status: 'up_to_date', head: staging.sha }, 'nothing to do');
29
+ }),
30
+ behaviourCase(GROUP, 'fast_forward when into has no commits of its own', async ({ gateway, repo }) => {
31
+ const seed = await seedRepo(gateway, repo, SEED);
32
+ await gateway.promote({ repo, from: 'main', into: 'staging', sha: seed.sha });
33
+ const ahead = await writeFiles(gateway, repo, 'main', { 'new.md': 'n' });
34
+ const output = await gateway.syncBranch({ repo, from: 'main', into: 'staging' });
35
+ assertEqual(
36
+ output,
37
+ {
38
+ status: 'fast_forward',
39
+ refUpdate: { ref: 'refs/heads/staging', oldSha: seed.sha, newSha: ahead.sha },
40
+ },
41
+ 'fast-forwarded',
42
+ );
43
+ assertEqual(await requireHead(gateway, repo, 'staging'), ahead.sha, 'staging moved');
44
+ }),
45
+ behaviourCase(GROUP, 'merged: changes on different paths are combined', async ({ gateway, repo }) => {
46
+ const heads = await diverge(
47
+ gateway,
48
+ repo,
49
+ { 'other.md': 'main\n', 'm.md': 'm' },
50
+ { 'shared.md': 'staging\n', 'keep.md': null },
51
+ );
52
+ const merged = expectStatus(await gateway.syncBranch({ repo, from: 'main', into: 'staging' }), 'merged');
53
+ assertEqual(merged.commit.parents, [heads.staging, heads.main], 'parents: into, then from');
54
+ assertEqual(
55
+ merged.refUpdate,
56
+ { ref: 'refs/heads/staging', oldSha: heads.staging, newSha: merged.commit.sha },
57
+ 'ref',
58
+ );
59
+ assertEqual(
60
+ await filePaths(gateway, repo, 'staging'),
61
+ ['m.md', 'other.md', 'shared.md'],
62
+ 'deletion kept, addition taken',
63
+ );
64
+ assertEqual(await readText(gateway, repo, 'staging', 'other.md'), 'main\n', 'from-side change taken');
65
+ assertEqual(await readText(gateway, repo, 'staging', 'shared.md'), 'staging\n', 'into-side change kept');
66
+ assertEqual(await requireHead(gateway, repo, 'main'), heads.main, 'from is never moved');
67
+ }),
68
+ behaviourCase(GROUP, 'merged: the default message names both branches', async ({ gateway, repo }) => {
69
+ await diverge(gateway, repo, { 'a.md': 'a' }, { 'b.md': 'b' });
70
+ const merged = expectStatus(await gateway.syncBranch({ repo, from: 'main', into: 'staging' }), 'merged');
71
+ assertTrue(merged.commit.message.startsWith("Merge branch 'main' into staging"), 'default message');
72
+ }),
73
+ behaviourCase(GROUP, 'merged: an explicit author and message are used', async ({ gateway, repo }) => {
74
+ await diverge(gateway, repo, { 'a.md': 'a' }, { 'b.md': 'b' });
75
+ const author = { name: 'Sync Bot', email: 'sync@example.com' };
76
+ const output = await gateway.syncBranch({
77
+ repo,
78
+ from: 'main',
79
+ into: 'staging',
80
+ author,
81
+ message: 'Sync now',
82
+ });
83
+ const { commit } = expectStatus(output, 'merged');
84
+ assertEqual([commit.author.name, commit.committer.email], ['Sync Bot', 'sync@example.com'], 'author');
85
+ assertTrue(commit.message.startsWith('Sync now'), 'message');
86
+ }),
87
+ behaviourCase(
88
+ GROUP,
89
+ 'merged: the same change on both sides is not a conflict',
90
+ async ({ gateway, repo }) => {
91
+ await diverge(gateway, repo, { 'shared.md': 'same\n', 'a.md': 'a' }, { 'shared.md': 'same\n' });
92
+ expectStatus(await gateway.syncBranch({ repo, from: 'main', into: 'staging' }), 'merged');
93
+ assertEqual(await readText(gateway, repo, 'staging', 'shared.md'), 'same\n', 'agreed content');
94
+ },
95
+ ),
96
+ behaviourCase(GROUP, 'conflict: a path changed differently on both sides', async ({ gateway, repo }) => {
97
+ const heads = await diverge(
98
+ gateway,
99
+ repo,
100
+ { 'shared.md': 'main\n', 'a.md': 'a' },
101
+ { 'shared.md': 'staging\n' },
102
+ );
103
+ const output = await gateway.syncBranch({ repo, from: 'main', into: 'staging' });
104
+ assertEqual(
105
+ output,
106
+ {
107
+ status: 'conflict',
108
+ paths: ['shared.md'],
109
+ base: heads.base,
110
+ fromHead: heads.main,
111
+ intoHead: heads.staging,
112
+ },
113
+ 'conflict reported',
114
+ );
115
+ assertEqual(await requireHead(gateway, repo, 'staging'), heads.staging, 'into unchanged');
116
+ }),
117
+ behaviourCase(GROUP, 'conflict: changed on one side, deleted on the other', async ({ gateway, repo }) => {
118
+ await diverge(gateway, repo, { 'shared.md': null }, { 'shared.md': 'edited\n' });
119
+ const output = expectStatus(
120
+ await gateway.syncBranch({ repo, from: 'main', into: 'staging' }),
121
+ 'conflict',
122
+ );
123
+ assertEqual(output.paths, ['shared.md'], 'modify/delete conflict');
124
+ }),
125
+ behaviourCase(
126
+ GROUP,
127
+ 'conflict: a file on one side, a directory on the other',
128
+ async ({ gateway, repo }) => {
129
+ await diverge(gateway, repo, { thing: 'file' }, { 'thing/inner.md': 'dir' });
130
+ const output = expectStatus(
131
+ await gateway.syncBranch({ repo, from: 'main', into: 'staging' }),
132
+ 'conflict',
133
+ );
134
+ assertTrue(output.paths.includes('thing'), 'file/directory conflict names the file');
135
+ },
136
+ ),
137
+ behaviourCase(GROUP, 'syncing again after a merge is up_to_date', async ({ gateway, repo }) => {
138
+ await diverge(gateway, repo, { 'a.md': 'a' }, { 'b.md': 'b' });
139
+ const merged = expectStatus(await gateway.syncBranch({ repo, from: 'main', into: 'staging' }), 'merged');
140
+ const again = await gateway.syncBranch({ repo, from: 'main', into: 'staging' });
141
+ assertEqual(again, { status: 'up_to_date', head: merged.commit.sha }, 'idempotent');
142
+ }),
143
+ behaviourCase(GROUP, 'a missing branch is ref_not_found', async ({ gateway, repo }) => {
144
+ await seedRepo(gateway, repo, SEED);
145
+ const error = await expectGatewayError(
146
+ gateway.syncBranch({ repo, from: 'main', into: 'nope' }),
147
+ 'ref_not_found',
148
+ );
149
+ assertEqual(error.details.ref, 'nope', 'names the branch');
150
+ await expectGatewayError(gateway.syncBranch({ repo, from: 'nope', into: 'main' }), 'ref_not_found');
151
+ }),
152
+ behaviourCase(GROUP, 'from and into must differ', async ({ gateway, repo }) => {
153
+ await seedRepo(gateway, repo, SEED);
154
+ await expectGatewayError(gateway.syncBranch({ repo, from: 'main', into: 'main' }), 'invalid_input');
155
+ }),
156
+ ];
@@ -0,0 +1,72 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { z } from 'zod';
3
+
4
+ import { GatewayErrorBody, type GatewayErrorCode } from './schemas/gateway-error-body.ts';
5
+
6
+ /** The body of the error with a given code. */
7
+ export type GatewayErrorOf<C extends GatewayErrorCode> = Extract<GatewayErrorBody, { code: C }>;
8
+
9
+ const PREFIX = 'GatewayError ';
10
+
11
+ /**
12
+ * The error every gateway call throws. `body` is a {@link GatewayErrorBody}; the message carries
13
+ * the same body as JSON after a fixed prefix, so it survives transports (such as Workers RPC)
14
+ * that keep only an error's message.
15
+ */
16
+ export class GatewayError<C extends GatewayErrorCode = GatewayErrorCode> extends Error {
17
+ override readonly name = 'GatewayError';
18
+ readonly body: GatewayErrorOf<C>;
19
+
20
+ constructor(body: GatewayErrorOf<C>) {
21
+ super(`${PREFIX}${JSON.stringify(body)}`);
22
+ this.body = body;
23
+ }
24
+
25
+ /** The error's code. */
26
+ get code(): C {
27
+ return this.body.code;
28
+ }
29
+ }
30
+
31
+ /** Builds a {@link GatewayError} from a code, message and details, validating them against the schema. */
32
+ export function gatewayError<C extends GatewayErrorCode>(
33
+ code: C,
34
+ message: string,
35
+ details: GatewayErrorOf<C>['details'],
36
+ ): GatewayError {
37
+ return new GatewayError(GatewayErrorBody.parse({ code, message, details }));
38
+ }
39
+
40
+ /**
41
+ * Recovers the body of a gateway error from anything thrown: a {@link GatewayError}, or any error
42
+ * whose message is one (e.g. after crossing a Workers RPC boundary). Null for anything else.
43
+ */
44
+ export function readGatewayError(thrown: unknown): GatewayErrorBody | null {
45
+ if (thrown instanceof GatewayError) return thrown.body;
46
+ if (!(thrown instanceof Error)) return null;
47
+ const at = thrown.message.indexOf(PREFIX);
48
+ if (at === -1) return null;
49
+ try {
50
+ const parsed = GatewayErrorBody.safeParse(JSON.parse(thrown.message.slice(at + PREFIX.length)));
51
+ return parsed.success ? parsed.data : null;
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+
57
+ /** True when `thrown` is a gateway error, and has `code` when one is given. */
58
+ export function isGatewayError(thrown: unknown, code?: GatewayErrorCode): boolean {
59
+ const body = readGatewayError(thrown);
60
+ return body !== null && (code === undefined || body.code === code);
61
+ }
62
+
63
+ /** Converts Zod validation issues into an invalid_input {@link GatewayError}. */
64
+ export function invalidInput(error: z.ZodError): GatewayError {
65
+ const issues = error.issues.map((issue) => ({
66
+ path: issue.path.map(String).join('.'),
67
+ message: issue.message.length > 0 ? issue.message : 'Invalid value',
68
+ }));
69
+ return gatewayError('invalid_input', 'Invalid input', {
70
+ issues: issues.length > 0 ? issues : [{ path: '', message: 'Invalid value' }],
71
+ });
72
+ }
@@ -0,0 +1,76 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import type { z } from 'zod';
3
+
4
+ import { CommitExistsInput, CommitExistsOutput } from './rpc/commit-exists.ts';
5
+ import { CommitInput, CommitOutput } from './rpc/commit.ts';
6
+ import { ListTreeInput, ListTreeOutput } from './rpc/list-tree.ts';
7
+ import { LogInput, LogOutput } from './rpc/log.ts';
8
+ import { MintReadTokenInput, MintReadTokenOutput } from './rpc/mint-read-token.ts';
9
+ import { PromoteInput, PromoteOutput } from './rpc/promote.ts';
10
+ import { ReadFileInput, ReadFileOutput } from './rpc/read-file.ts';
11
+ import {
12
+ CreateRepoInput,
13
+ CreateRepoOutput,
14
+ DeleteRepoInput,
15
+ DeleteRepoOutput,
16
+ } from './rpc/repo-lifecycle.ts';
17
+ import { ResolveRefInput, ResolveRefOutput } from './rpc/resolve-ref.ts';
18
+ import { SyncBranchInput, SyncBranchOutput } from './rpc/sync-branch.ts';
19
+
20
+ /**
21
+ * The input and output schema of every RPC method. An implementation parses each input with its
22
+ * schema before acting and returns a value its output schema accepts; failures are thrown as
23
+ * {@link GatewayError}s.
24
+ */
25
+ export const RPC_SCHEMAS = {
26
+ commit: { input: CommitInput, output: CommitOutput },
27
+ readFile: { input: ReadFileInput, output: ReadFileOutput },
28
+ listTree: { input: ListTreeInput, output: ListTreeOutput },
29
+ resolveRef: { input: ResolveRefInput, output: ResolveRefOutput },
30
+ log: { input: LogInput, output: LogOutput },
31
+ commitExists: { input: CommitExistsInput, output: CommitExistsOutput },
32
+ syncBranch: { input: SyncBranchInput, output: SyncBranchOutput },
33
+ promote: { input: PromoteInput, output: PromoteOutput },
34
+ createRepo: { input: CreateRepoInput, output: CreateRepoOutput },
35
+ deleteRepo: { input: DeleteRepoInput, output: DeleteRepoOutput },
36
+ mintReadToken: { input: MintReadTokenInput, output: MintReadTokenOutput },
37
+ } as const;
38
+
39
+ /** The name of an RPC method. */
40
+ export type RpcMethod = keyof typeof RPC_SCHEMAS;
41
+
42
+ /** What a caller passes to an RPC method (defaults optional). */
43
+ export type RpcInput<M extends RpcMethod> = z.input<(typeof RPC_SCHEMAS)[M]['input']>;
44
+ /** What an implementation works with after parsing the input (defaults applied). */
45
+ export type RpcParsedInput<M extends RpcMethod> = z.output<(typeof RPC_SCHEMAS)[M]['input']>;
46
+ /** What an RPC method resolves to. */
47
+ export type RpcOutput<M extends RpcMethod> = z.output<(typeof RPC_SCHEMAS)[M]['output']>;
48
+
49
+ /**
50
+ * The git-gateway RPC API, reached over a Workers service binding. Every method's signature is
51
+ * the inferred type of its schemas in {@link RPC_SCHEMAS}; errors are thrown as GatewayErrors.
52
+ */
53
+ export interface GitGateway {
54
+ /** A multi-file commit to one branch, built without a clone; idempotent by key. */
55
+ commit(input: RpcInput<'commit'>): Promise<RpcOutput<'commit'>>;
56
+ /** One file at a branch or commit, or null when no file is at the path. */
57
+ readFile(input: RpcInput<'readFile'>): Promise<RpcOutput<'readFile'>>;
58
+ /** A directory listing at a branch or commit, or null when the path is not a directory. */
59
+ listTree(input: RpcInput<'listTree'>): Promise<RpcOutput<'listTree'>>;
60
+ /** The commit a branch names, or null when it does not exist. */
61
+ resolveRef(input: RpcInput<'resolveRef'>): Promise<RpcOutput<'resolveRef'>>;
62
+ /** A page of history reachable from a branch or commit. */
63
+ log(input: RpcInput<'log'>): Promise<RpcOutput<'log'>>;
64
+ /** Whether a commit exists, optionally reachable from a branch. */
65
+ commitExists(input: RpcInput<'commitExists'>): Promise<RpcOutput<'commitExists'>>;
66
+ /** Bring one branch up to date with another without rewriting it. */
67
+ syncBranch(input: RpcInput<'syncBranch'>): Promise<RpcOutput<'syncBranch'>>;
68
+ /** Fast-forward one branch to the head of another, never merging or forcing. */
69
+ promote(input: RpcInput<'promote'>): Promise<RpcOutput<'promote'>>;
70
+ /** Create an empty repository. */
71
+ createRepo(input: RpcInput<'createRepo'>): Promise<RpcOutput<'createRepo'>>;
72
+ /** Permanently delete a repository. */
73
+ deleteRepo(input: RpcInput<'deleteRepo'>): Promise<RpcOutput<'deleteRepo'>>;
74
+ /** A short-lived credential that can read one repository through the gateway. */
75
+ mintReadToken(input: RpcInput<'mintReadToken'>): Promise<RpcOutput<'mintReadToken'>>;
76
+ }
package/src/health.ts ADDED
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from 'zod';
3
+
4
+ /** Body of `GET /health`. */
5
+ export const HealthResponse = z
6
+ .object({
7
+ status: z.literal('ok').describe('Always "ok": the gateway Worker is up and routing requests.'),
8
+ service: z
9
+ .string()
10
+ .min(1)
11
+ .max(64)
12
+ .describe(
13
+ 'Name of the deployment answering, 1–64 characters; "git-gateway" unless the deployment names itself.',
14
+ ),
15
+ })
16
+ .strict()
17
+ .meta({
18
+ id: 'HealthResponse',
19
+ title: 'Health response',
20
+ description:
21
+ 'Body of GET /health. Returned with status 200 whenever the Worker is serving; it does not probe storage backends.',
22
+ examples: [{ status: 'ok', service: 'git-gateway' }],
23
+ });
24
+
25
+ /** Body of `GET /health`, inferred from {@link HealthResponse}. */
26
+ export type HealthResponse = z.infer<typeof HealthResponse>;
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ /** The npm name this package is published under. */
4
+ export const packageName = '@leed-ai/git-gateway-contract' as const;