@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,7 @@
1
+ /** The trailer the gateway appends to every commit made with an idempotency key. */
2
+ export declare const IDEMPOTENCY_TRAILER = "Gateway-Idempotency-Key";
3
+ /** The message with the idempotency trailer appended as its last paragraph. */
4
+ export declare function appendIdempotencyTrailer(message: string, key: string): string;
5
+ /** The idempotency key in a message's trailer, or null when it has none. */
6
+ export declare function readIdempotencyTrailer(message: string): string | null;
7
+ //# sourceMappingURL=trailer.d.ts.map
@@ -0,0 +1,16 @@
1
+ // src/reference/trailer.ts
2
+ /** The trailer the gateway appends to every commit made with an idempotency key. */
3
+ const IDEMPOTENCY_TRAILER = "Gateway-Idempotency-Key";
4
+ const TRAILER_LINE = new RegExp(`^${IDEMPOTENCY_TRAILER}: ([A-Za-z0-9][A-Za-z0-9._:-]{0,127})$`, "m");
5
+ /** The message with the idempotency trailer appended as its last paragraph. */
6
+ function appendIdempotencyTrailer(message, key) {
7
+ return `${message.trimEnd()}\n\n${IDEMPOTENCY_TRAILER}: ${key}\n`;
8
+ }
9
+ /** The idempotency key in a message's trailer, or null when it has none. */
10
+ function readIdempotencyTrailer(message) {
11
+ const last = message.trimEnd().split("\n").at(-1) ?? "";
12
+ return TRAILER_LINE.exec(last)?.[1] ?? null;
13
+ }
14
+ export { IDEMPOTENCY_TRAILER, appendIdempotencyTrailer, readIdempotencyTrailer };
15
+
16
+ //# sourceMappingURL=trailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trailer.js","names":[],"sources":["../../src/reference/trailer.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** The trailer the gateway appends to every commit made with an idempotency key. */\nexport const IDEMPOTENCY_TRAILER = 'Gateway-Idempotency-Key';\n\nconst TRAILER_LINE = new RegExp(`^${IDEMPOTENCY_TRAILER}: ([A-Za-z0-9][A-Za-z0-9._:-]{0,127})$`, 'm');\n\n/** The message with the idempotency trailer appended as its last paragraph. */\nexport function appendIdempotencyTrailer(message: string, key: string): string {\n return `${message.trimEnd()}\\n\\n${IDEMPOTENCY_TRAILER}: ${key}\\n`;\n}\n\n/** The idempotency key in a message's trailer, or null when it has none. */\nexport function readIdempotencyTrailer(message: string): string | null {\n const lines = message.trimEnd().split('\\n');\n const last = lines.at(-1) ?? '';\n return TRAILER_LINE.exec(last)?.[1] ?? null;\n}\n"],"mappings":";;AAGA,MAAa,sBAAsB;AAEnC,MAAM,eAAe,IAAI,OAAO,IAAI,oBAAoB,yCAAyC,GAAG;;AAGpG,SAAgB,yBAAyB,SAAiB,KAAqB;CAC7E,OAAO,GAAG,QAAQ,QAAQ,EAAE,MAAM,oBAAoB,IAAI,IAAI;AAChE;;AAGA,SAAgB,uBAAuB,SAAgC;CAErE,MAAM,OADQ,QAAQ,QAAQ,CAAC,CAAC,MAAM,IACrB,CAAC,CAAC,GAAG,EAAE,KAAK;CAC7B,OAAO,aAAa,KAAK,IAAI,CAAC,GAAG,MAAM;AACzC"}
@@ -0,0 +1,2 @@
1
+ import { n as buildTreeIndex, r as entriesBeneath, t as TreeIndex } from "../tree-index-Bk721Phv.js";
2
+ export { TreeIndex, buildTreeIndex, entriesBeneath };
@@ -0,0 +1,66 @@
1
+ import { byteOrder } from "./bytes.js";
2
+ import { parentDirectories } from "./file-map.js";
3
+ import { modelSha } from "./hash.js";
4
+ // src/reference/tree-index.ts
5
+ const nameOf = (path) => path.slice(path.lastIndexOf("/") + 1);
6
+ const dirOf = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
7
+ const depth = (path) => path === "" ? 0 : path.split("/").length;
8
+ /** Builds the directory index of a snapshot, computing each tree id from its entries bottom-up. */
9
+ async function buildTreeIndex(files) {
10
+ const children = /* @__PURE__ */ new Map([["", /* @__PURE__ */ new Map()]]);
11
+ const childMap = (dir) => {
12
+ let map = children.get(dir);
13
+ if (map === void 0) {
14
+ map = /* @__PURE__ */ new Map();
15
+ children.set(dir, map);
16
+ }
17
+ return map;
18
+ };
19
+ for (const [path, file] of files) {
20
+ for (const dir of parentDirectories(path)) childMap(dir);
21
+ childMap(dirOf(path)).set(path, {
22
+ path,
23
+ name: nameOf(path),
24
+ type: "blob",
25
+ mode: file.executable ? "100755" : "100644",
26
+ sha: file.sha
27
+ });
28
+ }
29
+ const deepestFirst = [...children.keys()].toSorted((a, b) => depth(b) - depth(a) || byteOrder(a, b));
30
+ const directories = /* @__PURE__ */ new Map();
31
+ let rootSha = "";
32
+ for (const dir of deepestFirst) {
33
+ const entries = [...children.get(dir)?.values() ?? []].toSorted((a, b) => byteOrder(a.path, b.path));
34
+ directories.set(dir, entries);
35
+ const sha = await modelSha("tree", entries.map((e) => `${e.mode} ${e.name} ${e.sha}`).join("\n"));
36
+ if (dir === "") rootSha = sha;
37
+ else childMap(dirOf(dir)).set(dir, {
38
+ path: dir,
39
+ name: nameOf(dir),
40
+ type: "tree",
41
+ mode: "040000",
42
+ sha
43
+ });
44
+ }
45
+ return {
46
+ rootSha,
47
+ directories
48
+ };
49
+ }
50
+ /** Every entry beneath a directory ('' for the root), sorted by full path in byte order. */
51
+ function entriesBeneath(index, dir, recursive) {
52
+ const direct = index.directories.get(dir) ?? [];
53
+ if (!recursive) return [...direct];
54
+ const all = [];
55
+ const visit = (entries) => {
56
+ for (const entry of entries) {
57
+ all.push(entry);
58
+ if (entry.type === "tree") visit(index.directories.get(entry.path) ?? []);
59
+ }
60
+ };
61
+ visit(direct);
62
+ return all.toSorted((a, b) => byteOrder(a.path, b.path));
63
+ }
64
+ export { buildTreeIndex, entriesBeneath };
65
+
66
+ //# sourceMappingURL=tree-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-index.js","names":[],"sources":["../../src/reference/tree-index.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { TreeEntry } from '../schemas/tree-entry.ts';\nimport { byteOrder } from './bytes.ts';\nimport { parentDirectories, type FileMap } from './file-map.ts';\nimport { modelSha } from './hash.ts';\n\n/** Every directory of a snapshot with its entries, and the root tree id. */\nexport interface TreeIndex {\n readonly rootSha: string;\n /** Directory path ('' for the root) → its direct entries, sorted by path in byte order. */\n readonly directories: ReadonlyMap<string, readonly TreeEntry[]>;\n}\n\nconst nameOf = (path: string): string => path.slice(path.lastIndexOf('/') + 1);\nconst dirOf = (path: string): string => (path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '');\nconst depth = (path: string): number => (path === '' ? 0 : path.split('/').length);\n\n/** Builds the directory index of a snapshot, computing each tree id from its entries bottom-up. */\nexport async function buildTreeIndex(files: FileMap): Promise<TreeIndex> {\n const children = new Map<string, Map<string, TreeEntry>>([['', new Map()]]);\n const childMap = (dir: string): Map<string, TreeEntry> => {\n let map = children.get(dir);\n if (map === undefined) {\n map = new Map();\n children.set(dir, map);\n }\n return map;\n };\n for (const [path, file] of files) {\n for (const dir of parentDirectories(path)) childMap(dir);\n childMap(dirOf(path)).set(path, {\n path,\n name: nameOf(path),\n type: 'blob',\n mode: file.executable ? '100755' : '100644',\n sha: file.sha,\n });\n }\n const deepestFirst = [...children.keys()].toSorted((a, b) => depth(b) - depth(a) || byteOrder(a, b));\n const directories = new Map<string, readonly TreeEntry[]>();\n let rootSha = '';\n for (const dir of deepestFirst) {\n const entries = [...(children.get(dir)?.values() ?? [])].toSorted((a, b) => byteOrder(a.path, b.path));\n directories.set(dir, entries);\n const sha = await modelSha('tree', entries.map((e) => `${e.mode} ${e.name} ${e.sha}`).join('\\n'));\n if (dir === '') rootSha = sha;\n else childMap(dirOf(dir)).set(dir, { path: dir, name: nameOf(dir), type: 'tree', mode: '040000', sha });\n }\n return { rootSha, directories };\n}\n\n/** Every entry beneath a directory ('' for the root), sorted by full path in byte order. */\nexport function entriesBeneath(index: TreeIndex, dir: string, recursive: boolean): TreeEntry[] {\n const direct = index.directories.get(dir) ?? [];\n if (!recursive) return [...direct];\n const all: TreeEntry[] = [];\n const visit = (entries: readonly TreeEntry[]): void => {\n for (const entry of entries) {\n all.push(entry);\n if (entry.type === 'tree') visit(index.directories.get(entry.path) ?? []);\n }\n };\n visit(direct);\n return all.toSorted((a, b) => byteOrder(a.path, b.path));\n}\n"],"mappings":";;;;AAaA,MAAM,UAAU,SAAyB,KAAK,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;AAC7E,MAAM,SAAS,SAA0B,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,KAAK,YAAY,GAAG,CAAC,IAAI;AACrG,MAAM,SAAS,SAA0B,SAAS,KAAK,IAAI,KAAK,MAAM,GAAG,CAAC,CAAC;;AAG3E,eAAsB,eAAe,OAAoC;CACvE,MAAM,2BAAW,IAAI,IAAoC,CAAC,CAAC,oBAAI,IAAI,IAAI,CAAC,CAAC,CAAC;CAC1E,MAAM,YAAY,QAAwC;EACxD,IAAI,MAAM,SAAS,IAAI,GAAG;EAC1B,IAAI,QAAQ,KAAA,GAAW;GACrB,sBAAM,IAAI,IAAI;GACd,SAAS,IAAI,KAAK,GAAG;EACvB;EACA,OAAO;CACT;CACA,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO;EAChC,KAAK,MAAM,OAAO,kBAAkB,IAAI,GAAG,SAAS,GAAG;EACvD,SAAS,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM;GAC9B;GACA,MAAM,OAAO,IAAI;GACjB,MAAM;GACN,MAAM,KAAK,aAAa,WAAW;GACnC,KAAK,KAAK;EACZ,CAAC;CACH;CACA,MAAM,eAAe,CAAC,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC;CACnG,MAAM,8BAAc,IAAI,IAAkC;CAC1D,IAAI,UAAU;CACd,KAAK,MAAM,OAAO,cAAc;EAC9B,MAAM,UAAU,CAAC,GAAI,SAAS,IAAI,GAAG,CAAC,EAAE,OAAO,KAAK,CAAC,CAAE,CAAC,CAAC,UAAU,GAAG,MAAM,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC;EACrG,YAAY,IAAI,KAAK,OAAO;EAC5B,MAAM,MAAM,MAAM,SAAS,QAAQ,QAAQ,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;EAChG,IAAI,QAAQ,IAAI,UAAU;OACrB,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK;GAAE,MAAM;GAAK,MAAM,OAAO,GAAG;GAAG,MAAM;GAAQ,MAAM;GAAU;EAAI,CAAC;CACxG;CACA,OAAO;EAAE;EAAS;CAAY;AAChC;;AAGA,SAAgB,eAAe,OAAkB,KAAa,WAAiC;CAC7F,MAAM,SAAS,MAAM,YAAY,IAAI,GAAG,KAAK,CAAC;CAC9C,IAAI,CAAC,WAAW,OAAO,CAAC,GAAG,MAAM;CACjC,MAAM,MAAmB,CAAC;CAC1B,MAAM,SAAS,YAAwC;EACrD,KAAK,MAAM,SAAS,SAAS;GAC3B,IAAI,KAAK,KAAK;GACd,IAAI,MAAM,SAAS,QAAQ,MAAM,MAAM,YAAY,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;EAC1E;CACF;CACA,MAAM,MAAM;CACZ,OAAO,IAAI,UAAU,GAAG,MAAM,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC;AACzD"}
@@ -0,0 +1,15 @@
1
+ import { Identity } from "../schemas/identity.js";
2
+ import { t as FileMap } from "../file-map-CxUveLWz.js";
3
+ import { RepoState, StoredCommit } from "./repo-state.js";
4
+ /** What a new commit records. */
5
+ export interface NewCommit {
6
+ readonly parents: readonly string[];
7
+ readonly files: FileMap;
8
+ readonly author: Identity;
9
+ readonly committer: Identity;
10
+ readonly message: string;
11
+ readonly date: string;
12
+ }
13
+ /** Builds a commit from a snapshot, stores it in the repository and returns it. Moves no branch. */
14
+ export declare function writeCommit(repo: RepoState, next: NewCommit): Promise<StoredCommit>;
15
+ //# sourceMappingURL=write-commit.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { modelSha } from "./hash.js";
2
+ import { readIdempotencyTrailer } from "./trailer.js";
3
+ import { buildTreeIndex } from "./tree-index.js";
4
+ // src/reference/write-commit.ts
5
+ /** Builds a commit from a snapshot, stores it in the repository and returns it. Moves no branch. */
6
+ async function writeCommit(repo, next) {
7
+ const tree = await buildTreeIndex(next.files);
8
+ const author = {
9
+ name: next.author.name,
10
+ email: next.author.email,
11
+ date: next.date
12
+ };
13
+ const committer = {
14
+ name: next.committer.name,
15
+ email: next.committer.email,
16
+ date: next.date
17
+ };
18
+ const canonical = JSON.stringify({
19
+ tree: tree.rootSha,
20
+ parents: next.parents,
21
+ author,
22
+ committer,
23
+ message: next.message
24
+ });
25
+ const commit = {
26
+ sha: await modelSha("commit", canonical),
27
+ tree: tree.rootSha,
28
+ parents: [...next.parents],
29
+ author,
30
+ committer,
31
+ message: next.message,
32
+ idempotencyKey: readIdempotencyTrailer(next.message)
33
+ };
34
+ const stored = {
35
+ commit,
36
+ files: next.files,
37
+ tree
38
+ };
39
+ repo.commits.set(commit.sha, stored);
40
+ return stored;
41
+ }
42
+ export { writeCommit };
43
+
44
+ //# sourceMappingURL=write-commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-commit.js","names":[],"sources":["../../src/reference/write-commit.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '../schemas/commit.ts';\nimport type { Identity } from '../schemas/identity.ts';\nimport type { FileMap } from './file-map.ts';\nimport { modelSha } from './hash.ts';\nimport type { RepoState, StoredCommit } from './repo-state.ts';\nimport { readIdempotencyTrailer } from './trailer.ts';\nimport { buildTreeIndex } from './tree-index.ts';\n\n/** What a new commit records. */\nexport interface NewCommit {\n readonly parents: readonly string[];\n readonly files: FileMap;\n readonly author: Identity;\n readonly committer: Identity;\n readonly message: string;\n readonly date: string;\n}\n\n/** Builds a commit from a snapshot, stores it in the repository and returns it. Moves no branch. */\nexport async function writeCommit(repo: RepoState, next: NewCommit): Promise<StoredCommit> {\n const tree = await buildTreeIndex(next.files);\n const author = { name: next.author.name, email: next.author.email, date: next.date };\n const committer = { name: next.committer.name, email: next.committer.email, date: next.date };\n const canonical = JSON.stringify({\n tree: tree.rootSha,\n parents: next.parents,\n author,\n committer,\n message: next.message,\n });\n const commit: Commit = {\n sha: await modelSha('commit', canonical),\n tree: tree.rootSha,\n parents: [...next.parents],\n author,\n committer,\n message: next.message,\n idempotencyKey: readIdempotencyTrailer(next.message),\n };\n const stored = { commit, files: next.files, tree };\n repo.commits.set(commit.sha, stored);\n return stored;\n}\n"],"mappings":";;;;;AAoBA,eAAsB,YAAY,MAAiB,MAAwC;CACzF,MAAM,OAAO,MAAM,eAAe,KAAK,KAAK;CAC5C,MAAM,SAAS;EAAE,MAAM,KAAK,OAAO;EAAM,OAAO,KAAK,OAAO;EAAO,MAAM,KAAK;CAAK;CACnF,MAAM,YAAY;EAAE,MAAM,KAAK,UAAU;EAAM,OAAO,KAAK,UAAU;EAAO,MAAM,KAAK;CAAK;CAC5F,MAAM,YAAY,KAAK,UAAU;EAC/B,MAAM,KAAK;EACX,SAAS,KAAK;EACd;EACA;EACA,SAAS,KAAK;CAChB,CAAC;CACD,MAAM,SAAiB;EACrB,KAAK,MAAM,SAAS,UAAU,SAAS;EACvC,MAAM,KAAK;EACX,SAAS,CAAC,GAAG,KAAK,OAAO;EACzB;EACA;EACA,SAAS,KAAK;EACd,gBAAgB,uBAAuB,KAAK,OAAO;CACrD;CACA,MAAM,SAAS;EAAE;EAAQ,OAAO,KAAK;EAAO;CAAK;CACjD,KAAK,QAAQ,IAAI,OAAO,KAAK,MAAM;CACnC,OAAO;AACT"}
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ /** Input of `commitExists`. */
3
+ export declare const CommitExistsInput: z.ZodObject<{
4
+ repo: z.ZodString;
5
+ sha: z.ZodString;
6
+ branch: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strict>;
8
+ /** Input of `commitExists`, inferred from {@link CommitExistsInput}. */
9
+ export type CommitExistsInput = z.input<typeof CommitExistsInput>;
10
+ /** Output of `commitExists`. */
11
+ export declare const CommitExistsOutput: z.ZodObject<{
12
+ exists: z.ZodBoolean;
13
+ }, z.core.$strict>;
14
+ /** Output of `commitExists`, inferred from {@link CommitExistsOutput}. */
15
+ export type CommitExistsOutput = z.infer<typeof CommitExistsOutput>;
16
+ //# sourceMappingURL=commit-exists.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { EXAMPLE_SHA_B } from "../schemas/examples.js";
2
+ import { BranchName, RepoName } from "../schemas/names.js";
3
+ import { Sha } from "../schemas/sha.js";
4
+ import { z } from "zod";
5
+ // src/rpc/commit-exists.ts
6
+ /** Input of `commitExists`. */
7
+ const CommitExistsInput = z.object({
8
+ repo: RepoName.describe("Repository to look in."),
9
+ sha: Sha.describe("Commit id to look for."),
10
+ branch: BranchName.optional().describe("When given, the commit must also be reachable from this branch's head (the head itself or an ancestor). Absent: any commit in the repository counts.")
11
+ }).strict().meta({
12
+ id: "CommitExistsInput",
13
+ title: "commitExists input",
14
+ description: "Input of commitExists(): is this commit in the repository, optionally on a branch?",
15
+ examples: [{
16
+ repo: "acme-raw-content",
17
+ sha: EXAMPLE_SHA_B,
18
+ branch: "main"
19
+ }]
20
+ });
21
+ /** Output of `commitExists`. */
22
+ const CommitExistsOutput = z.object({ exists: z.boolean().describe("true when the commit exists (and is reachable from `branch` when one was named); false otherwise, including when the branch does not exist.") }).strict().meta({
23
+ id: "CommitExistsOutput",
24
+ title: "commitExists output",
25
+ description: "Output of commitExists().",
26
+ examples: [{ exists: true }]
27
+ });
28
+ export { CommitExistsInput, CommitExistsOutput };
29
+
30
+ //# sourceMappingURL=commit-exists.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-exists.js","names":[],"sources":["../../src/rpc/commit-exists.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { EXAMPLE_SHA_B } from '../schemas/examples.ts';\nimport { BranchName, RepoName } from '../schemas/names.ts';\nimport { Sha } from '../schemas/sha.ts';\n\n/** Input of `commitExists`. */\nexport const CommitExistsInput = z\n .object({\n repo: RepoName.describe('Repository to look in.'),\n sha: Sha.describe('Commit id to look for.'),\n branch: BranchName.optional().describe(\n \"When given, the commit must also be reachable from this branch's head (the head itself or an ancestor). Absent: any commit in the repository counts.\",\n ),\n })\n .strict()\n .meta({\n id: 'CommitExistsInput',\n title: 'commitExists input',\n description: 'Input of commitExists(): is this commit in the repository, optionally on a branch?',\n examples: [{ repo: 'acme-raw-content', sha: EXAMPLE_SHA_B, branch: 'main' }],\n });\n\n/** Input of `commitExists`, inferred from {@link CommitExistsInput}. */\nexport type CommitExistsInput = z.input<typeof CommitExistsInput>;\n\n/** Output of `commitExists`. */\nexport const CommitExistsOutput = z\n .object({\n exists: z\n .boolean()\n .describe(\n 'true when the commit exists (and is reachable from `branch` when one was named); false otherwise, including when the branch does not exist.',\n ),\n })\n .strict()\n .meta({\n id: 'CommitExistsOutput',\n title: 'commitExists output',\n description: 'Output of commitExists().',\n examples: [{ exists: true }],\n });\n\n/** Output of `commitExists`, inferred from {@link CommitExistsOutput}. */\nexport type CommitExistsOutput = z.infer<typeof CommitExistsOutput>;\n"],"mappings":";;;;;;AAQA,MAAa,oBAAoB,EAC9B,OAAO;CACN,MAAM,SAAS,SAAS,wBAAwB;CAChD,KAAK,IAAI,SAAS,wBAAwB;CAC1C,QAAQ,WAAW,SAAS,CAAC,CAAC,SAC5B,sJACF;AACF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,MAAM;EAAoB,KAAK;EAAe,QAAQ;CAAO,CAAC;AAC7E,CAAC;;AAMH,MAAa,qBAAqB,EAC/B,OAAO,EACN,QAAQ,EACL,QAAQ,CAAC,CACT,SACC,6IACF,EACJ,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC,EAAE,QAAQ,KAAK,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,172 @@
1
+ import { z } from "zod";
2
+ /** Input of `commit`. */
3
+ export declare const CommitInput: z.ZodObject<{
4
+ repo: z.ZodString;
5
+ branch: z.ZodString;
6
+ startBranch: z.ZodOptional<z.ZodString>;
7
+ expectedHead: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ message: z.ZodString;
9
+ author: z.ZodObject<{
10
+ name: z.ZodString;
11
+ email: z.ZodEmail;
12
+ }, z.core.$strict>;
13
+ committer: z.ZodOptional<z.ZodObject<{
14
+ name: z.ZodString;
15
+ email: z.ZodEmail;
16
+ }, z.core.$strict>>;
17
+ actions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
18
+ action: z.ZodLiteral<"create">;
19
+ path: z.ZodString;
20
+ content: z.ZodString;
21
+ encoding: z.ZodDefault<z.ZodEnum<{
22
+ base64: "base64";
23
+ text: "text";
24
+ }>>;
25
+ }, z.core.$strict>, z.ZodObject<{
26
+ action: z.ZodLiteral<"update">;
27
+ path: z.ZodString;
28
+ content: z.ZodString;
29
+ encoding: z.ZodDefault<z.ZodEnum<{
30
+ base64: "base64";
31
+ text: "text";
32
+ }>>;
33
+ }, z.core.$strict>, z.ZodObject<{
34
+ action: z.ZodLiteral<"upsert">;
35
+ path: z.ZodString;
36
+ content: z.ZodString;
37
+ encoding: z.ZodDefault<z.ZodEnum<{
38
+ base64: "base64";
39
+ text: "text";
40
+ }>>;
41
+ }, z.core.$strict>, z.ZodObject<{
42
+ action: z.ZodLiteral<"delete">;
43
+ path: z.ZodString;
44
+ }, z.core.$strict>, z.ZodObject<{
45
+ action: z.ZodLiteral<"move">;
46
+ path: z.ZodString;
47
+ previousPath: z.ZodString;
48
+ content: z.ZodOptional<z.ZodString>;
49
+ encoding: z.ZodDefault<z.ZodEnum<{
50
+ base64: "base64";
51
+ text: "text";
52
+ }>>;
53
+ }, z.core.$strict>, z.ZodObject<{
54
+ action: z.ZodLiteral<"chmod">;
55
+ path: z.ZodString;
56
+ executeFilemode: z.ZodBoolean;
57
+ }, z.core.$strict>], "action">>;
58
+ idempotencyKey: z.ZodString;
59
+ }, z.core.$strict>;
60
+ /** Input of `commit` as accepted (defaults optional). */
61
+ export type CommitInput = z.input<typeof CommitInput>;
62
+ /** A new commit was written. */
63
+ export declare const CommitCommitted: z.ZodObject<{
64
+ status: z.ZodLiteral<"committed">;
65
+ commit: z.ZodObject<{
66
+ sha: z.ZodString;
67
+ tree: z.ZodString;
68
+ parents: z.ZodArray<z.ZodString>;
69
+ author: z.ZodObject<{
70
+ name: z.ZodString;
71
+ email: z.ZodEmail;
72
+ date: z.ZodISODateTime;
73
+ }, z.core.$strict>;
74
+ committer: z.ZodObject<{
75
+ name: z.ZodString;
76
+ email: z.ZodEmail;
77
+ date: z.ZodISODateTime;
78
+ }, z.core.$strict>;
79
+ message: z.ZodString;
80
+ idempotencyKey: z.ZodNullable<z.ZodString>;
81
+ }, z.core.$strict>;
82
+ refUpdate: z.ZodObject<{
83
+ ref: z.ZodString;
84
+ oldSha: z.ZodString;
85
+ newSha: z.ZodString;
86
+ }, z.core.$strict>;
87
+ }, z.core.$strict>;
88
+ /** The key was found in recent history; that commit is returned. */
89
+ export declare const CommitReplayed: z.ZodObject<{
90
+ status: z.ZodLiteral<"replayed">;
91
+ commit: z.ZodObject<{
92
+ sha: z.ZodString;
93
+ tree: z.ZodString;
94
+ parents: z.ZodArray<z.ZodString>;
95
+ author: z.ZodObject<{
96
+ name: z.ZodString;
97
+ email: z.ZodEmail;
98
+ date: z.ZodISODateTime;
99
+ }, z.core.$strict>;
100
+ committer: z.ZodObject<{
101
+ name: z.ZodString;
102
+ email: z.ZodEmail;
103
+ date: z.ZodISODateTime;
104
+ }, z.core.$strict>;
105
+ message: z.ZodString;
106
+ idempotencyKey: z.ZodNullable<z.ZodString>;
107
+ }, z.core.$strict>;
108
+ }, z.core.$strict>;
109
+ /** The actions changed nothing. */
110
+ export declare const CommitNoop: z.ZodObject<{
111
+ status: z.ZodLiteral<"noop">;
112
+ head: z.ZodNullable<z.ZodString>;
113
+ }, z.core.$strict>;
114
+ /** Inline retries ran out; a Workflow finishes the commit. */
115
+ export declare const CommitQueued: z.ZodObject<{
116
+ status: z.ZodLiteral<"queued">;
117
+ workflowInstanceId: z.ZodString;
118
+ }, z.core.$strict>;
119
+ /** Output of `commit`, discriminated by `status`. */
120
+ export declare const CommitOutput: z.ZodDiscriminatedUnion<[z.ZodObject<{
121
+ status: z.ZodLiteral<"committed">;
122
+ commit: z.ZodObject<{
123
+ sha: z.ZodString;
124
+ tree: z.ZodString;
125
+ parents: z.ZodArray<z.ZodString>;
126
+ author: z.ZodObject<{
127
+ name: z.ZodString;
128
+ email: z.ZodEmail;
129
+ date: z.ZodISODateTime;
130
+ }, z.core.$strict>;
131
+ committer: z.ZodObject<{
132
+ name: z.ZodString;
133
+ email: z.ZodEmail;
134
+ date: z.ZodISODateTime;
135
+ }, z.core.$strict>;
136
+ message: z.ZodString;
137
+ idempotencyKey: z.ZodNullable<z.ZodString>;
138
+ }, z.core.$strict>;
139
+ refUpdate: z.ZodObject<{
140
+ ref: z.ZodString;
141
+ oldSha: z.ZodString;
142
+ newSha: z.ZodString;
143
+ }, z.core.$strict>;
144
+ }, z.core.$strict>, z.ZodObject<{
145
+ status: z.ZodLiteral<"replayed">;
146
+ commit: z.ZodObject<{
147
+ sha: z.ZodString;
148
+ tree: z.ZodString;
149
+ parents: z.ZodArray<z.ZodString>;
150
+ author: z.ZodObject<{
151
+ name: z.ZodString;
152
+ email: z.ZodEmail;
153
+ date: z.ZodISODateTime;
154
+ }, z.core.$strict>;
155
+ committer: z.ZodObject<{
156
+ name: z.ZodString;
157
+ email: z.ZodEmail;
158
+ date: z.ZodISODateTime;
159
+ }, z.core.$strict>;
160
+ message: z.ZodString;
161
+ idempotencyKey: z.ZodNullable<z.ZodString>;
162
+ }, z.core.$strict>;
163
+ }, z.core.$strict>, z.ZodObject<{
164
+ status: z.ZodLiteral<"noop">;
165
+ head: z.ZodNullable<z.ZodString>;
166
+ }, z.core.$strict>, z.ZodObject<{
167
+ status: z.ZodLiteral<"queued">;
168
+ workflowInstanceId: z.ZodString;
169
+ }, z.core.$strict>], "status">;
170
+ /** Output of `commit`, inferred from {@link CommitOutput}. */
171
+ export type CommitOutput = z.infer<typeof CommitOutput>;
172
+ //# sourceMappingURL=commit.d.ts.map
@@ -0,0 +1,115 @@
1
+ import { Commit } from "../schemas/commit.js";
2
+ import { CommitAction } from "../schemas/commit-action.js";
3
+ import { EXAMPLE_COMMIT, EXAMPLE_IDENTITY, EXAMPLE_SHA_A, EXAMPLE_SHA_B } from "../schemas/examples.js";
4
+ import { Identity } from "../schemas/identity.js";
5
+ import { BranchName, IdempotencyKey, RepoName } from "../schemas/names.js";
6
+ import { RefUpdate } from "../schemas/ref-update.js";
7
+ import { Sha } from "../schemas/sha.js";
8
+ import { z } from "zod";
9
+ // src/rpc/commit.ts
10
+ /** Input of `commit`. */
11
+ const CommitInput = z.object({
12
+ repo: RepoName.describe("Repository to commit to."),
13
+ branch: BranchName.describe("Branch to commit to. If it does not exist it is created: from `startBranch` when given, or as a root commit when the repository has no branches at all; otherwise the call fails with ref_not_found."),
14
+ startBranch: BranchName.optional().describe("Branch to start `branch` from when `branch` does not exist yet; ignored when it does. Absent: no start branch."),
15
+ expectedHead: Sha.nullable().optional().describe("Head the caller based its change on. When given and the branch head differs, the call fails with stale_head; null expects the branch not to exist yet. Absent: commit onto whatever the head is."),
16
+ message: z.string().min(1).max(65536).refine((text) => text.trim().length > 0, { message: "message must not be blank" }).describe("Commit message, 1–65536 characters and not blank. The gateway appends the idempotency trailer."),
17
+ author: Identity.describe("Who wrote the change."),
18
+ committer: Identity.optional().describe("Who records the commit. Absent: the author."),
19
+ actions: z.array(CommitAction).min(1).max(1e3).describe("Changes to apply, in order, each to the result of the previous; 1–1000 actions."),
20
+ idempotencyKey: IdempotencyKey.describe("Makes the call safe to retry: if a commit with this key is in the branch's recent history, it is returned (status \"replayed\") and nothing is written.")
21
+ }).strict().meta({
22
+ id: "CommitInput",
23
+ title: "commit input",
24
+ description: "Input of commit(): a multi-file commit to one branch, built without a clone. Checked in this order: idempotency replay, then stale head, then the actions.",
25
+ examples: [{
26
+ repo: "acme-raw-content",
27
+ branch: "staging",
28
+ expectedHead: EXAMPLE_SHA_A,
29
+ message: "Update about page",
30
+ author: EXAMPLE_IDENTITY,
31
+ actions: [{
32
+ action: "update",
33
+ path: "content/about.md",
34
+ content: "# About us\n",
35
+ encoding: "text"
36
+ }],
37
+ idempotencyKey: "cms:publish:2f9c1e"
38
+ }]
39
+ });
40
+ /** A new commit was written. */
41
+ const CommitCommitted = z.object({
42
+ status: z.literal("committed").describe("A new commit was written and the branch moved to it."),
43
+ commit: Commit.describe("The commit written."),
44
+ refUpdate: RefUpdate.describe("How the branch moved; oldSha is all zeros when the commit created it.")
45
+ }).strict().meta({
46
+ id: "CommitCommitted",
47
+ title: "commit: committed",
48
+ description: "commit() wrote a new commit and moved the branch to it.",
49
+ examples: [{
50
+ status: "committed",
51
+ commit: EXAMPLE_COMMIT,
52
+ refUpdate: {
53
+ ref: "refs/heads/staging",
54
+ oldSha: EXAMPLE_SHA_A,
55
+ newSha: EXAMPLE_SHA_B
56
+ }
57
+ }]
58
+ });
59
+ /** The key was found in recent history; that commit is returned. */
60
+ const CommitReplayed = z.object({
61
+ status: z.literal("replayed").describe("A commit with the same idempotency key already exists; nothing was written."),
62
+ commit: Commit.describe("The earlier commit carrying the same idempotency key.")
63
+ }).strict().meta({
64
+ id: "CommitReplayed",
65
+ title: "commit: replayed",
66
+ description: "commit() found a commit with the same idempotency key in the branch's recent history and returned it without writing.",
67
+ examples: [{
68
+ status: "replayed",
69
+ commit: EXAMPLE_COMMIT
70
+ }]
71
+ });
72
+ /** The actions changed nothing. */
73
+ const CommitNoop = z.object({
74
+ status: z.literal("noop").describe("The actions left the tree unchanged; nothing was written or pushed."),
75
+ head: Sha.nullable().describe("The branch head, unchanged; null when the branch does not exist.")
76
+ }).strict().meta({
77
+ id: "CommitNoop",
78
+ title: "commit: no-op",
79
+ description: "commit() applied the actions and the resulting tree equals the head's, so nothing was written.",
80
+ examples: [{
81
+ status: "noop",
82
+ head: EXAMPLE_SHA_A
83
+ }]
84
+ });
85
+ /** Inline retries ran out; a Workflow finishes the commit. */
86
+ const CommitQueued = z.object({
87
+ status: z.literal("queued").describe("Inline retries ran out; a CommitWorkflow finishes the commit."),
88
+ workflowInstanceId: z.string().min(1).max(100).describe("Id of the CommitWorkflow instance carrying the same idempotency key.")
89
+ }).strict().meta({
90
+ id: "CommitQueued",
91
+ title: "commit: queued",
92
+ description: "commit() hit stale-head refusals more times than the inline retry budget and handed the commit to a CommitWorkflow with the same idempotency key. The in-memory reference never returns this.",
93
+ examples: [{
94
+ status: "queued",
95
+ workflowInstanceId: "commit-cms-publish-2f9c1e"
96
+ }]
97
+ });
98
+ /** Output of `commit`, discriminated by `status`. */
99
+ const CommitOutput = z.discriminatedUnion("status", [
100
+ CommitCommitted,
101
+ CommitReplayed,
102
+ CommitNoop,
103
+ CommitQueued
104
+ ]).meta({
105
+ id: "CommitOutput",
106
+ title: "commit output",
107
+ description: "Output of commit(), discriminated by `status`.",
108
+ examples: [{
109
+ status: "noop",
110
+ head: EXAMPLE_SHA_A
111
+ }]
112
+ });
113
+ export { CommitCommitted, CommitInput, CommitNoop, CommitOutput, CommitQueued, CommitReplayed };
114
+
115
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.js","names":["SHA_A","ADA","COMMIT_EXAMPLE","SHA_B"],"sources":["../../src/rpc/commit.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nimport { Commit } from '../schemas/commit.ts';\nimport { CommitAction } from '../schemas/commit-action.ts';\nimport {\n EXAMPLE_COMMIT as COMMIT_EXAMPLE,\n EXAMPLE_IDENTITY as ADA,\n EXAMPLE_SHA_A as SHA_A,\n EXAMPLE_SHA_B as SHA_B,\n} from '../schemas/examples.ts';\nimport { Identity } from '../schemas/identity.ts';\nimport { BranchName, IdempotencyKey, RepoName } from '../schemas/names.ts';\nimport { RefUpdate } from '../schemas/ref-update.ts';\nimport { Sha } from '../schemas/sha.ts';\n\n/** Input of `commit`. */\nexport const CommitInput = z\n .object({\n repo: RepoName.describe('Repository to commit to.'),\n branch: BranchName.describe(\n 'Branch to commit to. If it does not exist it is created: from `startBranch` when given, or as a root commit when the repository has no branches at all; otherwise the call fails with ref_not_found.',\n ),\n startBranch: BranchName.optional().describe(\n 'Branch to start `branch` from when `branch` does not exist yet; ignored when it does. Absent: no start branch.',\n ),\n expectedHead: Sha.nullable()\n .optional()\n .describe(\n 'Head the caller based its change on. When given and the branch head differs, the call fails with stale_head; null expects the branch not to exist yet. Absent: commit onto whatever the head is.',\n ),\n message: z\n .string()\n .min(1)\n .max(65_536)\n .refine((text) => text.trim().length > 0, { message: 'message must not be blank' })\n .describe(\n 'Commit message, 1–65536 characters and not blank. The gateway appends the idempotency trailer.',\n ),\n author: Identity.describe('Who wrote the change.'),\n committer: Identity.optional().describe('Who records the commit. Absent: the author.'),\n actions: z\n .array(CommitAction)\n .min(1)\n .max(1000)\n .describe('Changes to apply, in order, each to the result of the previous; 1–1000 actions.'),\n idempotencyKey: IdempotencyKey.describe(\n 'Makes the call safe to retry: if a commit with this key is in the branch\\'s recent history, it is returned (status \"replayed\") and nothing is written.',\n ),\n })\n .strict()\n .meta({\n id: 'CommitInput',\n title: 'commit input',\n description:\n 'Input of commit(): a multi-file commit to one branch, built without a clone. Checked in this order: idempotency replay, then stale head, then the actions.',\n examples: [\n {\n repo: 'acme-raw-content',\n branch: 'staging',\n expectedHead: SHA_A,\n message: 'Update about page',\n author: ADA,\n actions: [{ action: 'update', path: 'content/about.md', content: '# About us\\n', encoding: 'text' }],\n idempotencyKey: 'cms:publish:2f9c1e',\n },\n ],\n });\n\n/** Input of `commit` as accepted (defaults optional). */\nexport type CommitInput = z.input<typeof CommitInput>;\n\n/** A new commit was written. */\nexport const CommitCommitted = z\n .object({\n status: z.literal('committed').describe('A new commit was written and the branch moved to it.'),\n commit: Commit.describe('The commit written.'),\n refUpdate: RefUpdate.describe('How the branch moved; oldSha is all zeros when the commit created it.'),\n })\n .strict()\n .meta({\n id: 'CommitCommitted',\n title: 'commit: committed',\n description: 'commit() wrote a new commit and moved the branch to it.',\n examples: [\n {\n status: 'committed',\n commit: COMMIT_EXAMPLE,\n refUpdate: { ref: 'refs/heads/staging', oldSha: SHA_A, newSha: SHA_B },\n },\n ],\n });\n\n/** The key was found in recent history; that commit is returned. */\nexport const CommitReplayed = z\n .object({\n status: z\n .literal('replayed')\n .describe('A commit with the same idempotency key already exists; nothing was written.'),\n commit: Commit.describe('The earlier commit carrying the same idempotency key.'),\n })\n .strict()\n .meta({\n id: 'CommitReplayed',\n title: 'commit: replayed',\n description:\n \"commit() found a commit with the same idempotency key in the branch's recent history and returned it without writing.\",\n examples: [{ status: 'replayed', commit: COMMIT_EXAMPLE }],\n });\n\n/** The actions changed nothing. */\nexport const CommitNoop = z\n .object({\n status: z.literal('noop').describe('The actions left the tree unchanged; nothing was written or pushed.'),\n head: Sha.nullable().describe('The branch head, unchanged; null when the branch does not exist.'),\n })\n .strict()\n .meta({\n id: 'CommitNoop',\n title: 'commit: no-op',\n description:\n \"commit() applied the actions and the resulting tree equals the head's, so nothing was written.\",\n examples: [{ status: 'noop', head: SHA_A }],\n });\n\n/** Inline retries ran out; a Workflow finishes the commit. */\nexport const CommitQueued = z\n .object({\n status: z.literal('queued').describe('Inline retries ran out; a CommitWorkflow finishes the commit.'),\n workflowInstanceId: z\n .string()\n .min(1)\n .max(100)\n .describe('Id of the CommitWorkflow instance carrying the same idempotency key.'),\n })\n .strict()\n .meta({\n id: 'CommitQueued',\n title: 'commit: queued',\n description:\n 'commit() hit stale-head refusals more times than the inline retry budget and handed the commit to a CommitWorkflow with the same idempotency key. The in-memory reference never returns this.',\n examples: [{ status: 'queued', workflowInstanceId: 'commit-cms-publish-2f9c1e' }],\n });\n\n/** Output of `commit`, discriminated by `status`. */\nexport const CommitOutput = z\n .discriminatedUnion('status', [CommitCommitted, CommitReplayed, CommitNoop, CommitQueued])\n .meta({\n id: 'CommitOutput',\n title: 'commit output',\n description: 'Output of commit(), discriminated by `status`.',\n examples: [{ status: 'noop', head: SHA_A }],\n });\n\n/** Output of `commit`, inferred from {@link CommitOutput}. */\nexport type CommitOutput = z.infer<typeof CommitOutput>;\n"],"mappings":";;;;;;;;;;AAiBA,MAAa,cAAc,EACxB,OAAO;CACN,MAAM,SAAS,SAAS,0BAA0B;CAClD,QAAQ,WAAW,SACjB,sMACF;CACA,aAAa,WAAW,SAAS,CAAC,CAAC,SACjC,gHACF;CACA,cAAc,IAAI,SAAS,CAAC,CACzB,SAAS,CAAC,CACV,SACC,kMACF;CACF,SAAS,EACN,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,KAAM,CAAC,CACX,QAAQ,SAAS,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,SAAS,4BAA4B,CAAC,CAAC,CAClF,SACC,gGACF;CACF,QAAQ,SAAS,SAAS,uBAAuB;CACjD,WAAW,SAAS,SAAS,CAAC,CAAC,SAAS,6CAA6C;CACrF,SAAS,EACN,MAAM,YAAY,CAAC,CACnB,IAAI,CAAC,CAAC,CACN,IAAI,GAAI,CAAC,CACT,SAAS,iFAAiF;CAC7F,gBAAgB,eAAe,SAC7B,yJACF;AACF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CACR;EACE,MAAM;EACN,QAAQ;EACR,cAAcA;EACd,SAAS;EACT,QAAQC;EACR,SAAS,CAAC;GAAE,QAAQ;GAAU,MAAM;GAAoB,SAAS;GAAgB,UAAU;EAAO,CAAC;EACnG,gBAAgB;CAClB,CACF;AACF,CAAC;;AAMH,MAAa,kBAAkB,EAC5B,OAAO;CACN,QAAQ,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,sDAAsD;CAC9F,QAAQ,OAAO,SAAS,qBAAqB;CAC7C,WAAW,UAAU,SAAS,uEAAuE;AACvG,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CACR;EACE,QAAQ;EACR,QAAQC;EACR,WAAW;GAAE,KAAK;GAAsB,QAAQF;GAAO,QAAQG;EAAM;CACvE,CACF;AACF,CAAC;;AAGH,MAAa,iBAAiB,EAC3B,OAAO;CACN,QAAQ,EACL,QAAQ,UAAU,CAAC,CACnB,SAAS,6EAA6E;CACzF,QAAQ,OAAO,SAAS,uDAAuD;AACjF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAY,QAAQD;CAAe,CAAC;AAC3D,CAAC;;AAGH,MAAa,aAAa,EACvB,OAAO;CACN,QAAQ,EAAE,QAAQ,MAAM,CAAC,CAAC,SAAS,qEAAqE;CACxG,MAAM,IAAI,SAAS,CAAC,CAAC,SAAS,kEAAkE;AAClG,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAQ,MAAMF;CAAM,CAAC;AAC5C,CAAC;;AAGH,MAAa,eAAe,EACzB,OAAO;CACN,QAAQ,EAAE,QAAQ,QAAQ,CAAC,CAAC,SAAS,+DAA+D;CACpG,oBAAoB,EACjB,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,SAAS,sEAAsE;AACpF,CAAC,CAAC,CACD,OAAO,CAAC,CACR,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aACE;CACF,UAAU,CAAC;EAAE,QAAQ;EAAU,oBAAoB;CAA4B,CAAC;AAClF,CAAC;;AAGH,MAAa,eAAe,EACzB,mBAAmB,UAAU;CAAC;CAAiB;CAAgB;CAAY;AAAY,CAAC,CAAC,CACzF,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACb,UAAU,CAAC;EAAE,QAAQ;EAAQ,MAAMA;CAAM,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { z } from "zod";
2
+ /** Input of `listTree`. */
3
+ export declare const ListTreeInput: z.ZodObject<{
4
+ repo: z.ZodString;
5
+ ref: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
6
+ path: z.ZodOptional<z.ZodString>;
7
+ recursive: z.ZodDefault<z.ZodBoolean>;
8
+ }, z.core.$strict>;
9
+ /** Input of `listTree` as accepted (defaults optional). */
10
+ export type ListTreeInput = z.input<typeof ListTreeInput>;
11
+ /** A directory listing. */
12
+ export declare const TreeListing: z.ZodObject<{
13
+ commit: z.ZodString;
14
+ path: z.ZodNullable<z.ZodString>;
15
+ entries: z.ZodArray<z.ZodObject<{
16
+ path: z.ZodString;
17
+ name: z.ZodString;
18
+ type: z.ZodEnum<{
19
+ blob: "blob";
20
+ commit: "commit";
21
+ tree: "tree";
22
+ }>;
23
+ mode: z.ZodEnum<{
24
+ "040000": "040000";
25
+ 100644: "100644";
26
+ 100755: "100755";
27
+ 120000: "120000";
28
+ 160000: "160000";
29
+ }>;
30
+ sha: z.ZodString;
31
+ }, z.core.$strict>>;
32
+ }, z.core.$strict>;
33
+ /** A directory listing, inferred from {@link TreeListing}. */
34
+ export type TreeListing = z.infer<typeof TreeListing>;
35
+ /** Output of `listTree`: the listing, or null when the path is not a directory. */
36
+ export declare const ListTreeOutput: z.ZodNullable<z.ZodObject<{
37
+ commit: z.ZodString;
38
+ path: z.ZodNullable<z.ZodString>;
39
+ entries: z.ZodArray<z.ZodObject<{
40
+ path: z.ZodString;
41
+ name: z.ZodString;
42
+ type: z.ZodEnum<{
43
+ blob: "blob";
44
+ commit: "commit";
45
+ tree: "tree";
46
+ }>;
47
+ mode: z.ZodEnum<{
48
+ "040000": "040000";
49
+ 100644: "100644";
50
+ 100755: "100755";
51
+ 120000: "120000";
52
+ 160000: "160000";
53
+ }>;
54
+ sha: z.ZodString;
55
+ }, z.core.$strict>>;
56
+ }, z.core.$strict>>;
57
+ /** Output of `listTree`, inferred from {@link ListTreeOutput}. */
58
+ export type ListTreeOutput = z.infer<typeof ListTreeOutput>;
59
+ //# sourceMappingURL=list-tree.d.ts.map