@ref0/git 0.4.0 → 0.6.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 (167) hide show
  1. package/dist/access/private-refs.mjs +3 -4
  2. package/dist/auth/authorize.mjs +9 -4
  3. package/dist/auth/identify.d.mts +5 -3
  4. package/dist/auth/tokens.mjs +12 -11
  5. package/dist/client/local.mjs +2 -0
  6. package/dist/client/slice-push.d.mts +1 -1
  7. package/dist/contracts/access.d.mts +6 -2
  8. package/dist/contracts/authorize.d.mts +14 -10
  9. package/dist/contracts/events.d.mts +32 -5
  10. package/dist/contracts/events.mjs +14 -3
  11. package/dist/contracts/git.d.mts +68 -3
  12. package/dist/contracts/grants.d.mts +6 -1
  13. package/dist/contracts/lfs.d.mts +5 -2
  14. package/dist/contracts/objects.d.mts +7 -2
  15. package/dist/contracts/promises.d.mts +2 -14
  16. package/dist/contracts/push-uploads.d.mts +1 -1
  17. package/dist/contracts/queue.d.mts +15 -7
  18. package/dist/contracts/refs.d.mts +1 -1
  19. package/dist/contracts/result.d.mts +9 -5
  20. package/dist/contracts/result.mjs +5 -0
  21. package/dist/contracts/server.d.mts +13 -6
  22. package/dist/contracts/work.d.mts +1 -1
  23. package/dist/core/access.mjs +17 -1
  24. package/dist/core/call-names.d.mts +3 -1
  25. package/dist/core/claim-rows.d.mts +4 -0
  26. package/dist/core/claim-rows.mjs +53 -0
  27. package/dist/core/events/deliver.d.mts +12 -0
  28. package/dist/core/events/deliver.mjs +367 -145
  29. package/dist/core/events/seen.mjs +17 -3
  30. package/dist/core/forks.mjs +82 -20
  31. package/dist/core/hooks/post-receive.mjs +20 -17
  32. package/dist/core/index-job.mjs +23 -17
  33. package/dist/core/parts.d.mts +6 -0
  34. package/dist/core/purge.d.mts +8 -0
  35. package/dist/core/purge.mjs +16 -21
  36. package/dist/core/push-decide.mjs +26 -4
  37. package/dist/core/push.mjs +57 -20
  38. package/dist/core/ref-index-job.mjs +9 -14
  39. package/dist/core/ref-index.d.mts +1 -0
  40. package/dist/core/ref-index.mjs +28 -8
  41. package/dist/core/ref-view.mjs +14 -9
  42. package/dist/core/refs.mjs +13 -11
  43. package/dist/core/repack.d.mts +2 -1
  44. package/dist/core/repack.mjs +66 -118
  45. package/dist/core/repos.mjs +5 -5
  46. package/dist/core/rules/check.mjs +7 -6
  47. package/dist/core/rules/context.d.mts +1 -1
  48. package/dist/core/seam.d.mts +56 -9
  49. package/dist/core/seam.mjs +7 -1
  50. package/dist/core/still-takes.mjs +75 -0
  51. package/dist/core/view.d.mts +1 -0
  52. package/dist/core/view.mjs +8 -9
  53. package/dist/core/work.mjs +1 -1
  54. package/dist/extend.d.mts +2 -1
  55. package/dist/http/core-parts.mjs +19 -11
  56. package/dist/http/handler.mjs +2 -2
  57. package/dist/http/node.d.mts +2 -23
  58. package/dist/http/parts.d.mts +1 -0
  59. package/dist/http/push-uploads.d.mts +10 -2
  60. package/dist/http/push-uploads.mjs +31 -34
  61. package/dist/http/receive-pack.mjs +5 -3
  62. package/dist/http/upload-pack.mjs +2 -2
  63. package/dist/index.d.mts +11 -7
  64. package/dist/index.mjs +5 -3
  65. package/dist/lfs/base.d.mts +32 -0
  66. package/dist/lfs/base.mjs +8 -0
  67. package/dist/lfs/calls.mjs +21 -12
  68. package/dist/lfs/layer.d.mts +27 -0
  69. package/dist/lfs/layer.mjs +64 -0
  70. package/dist/lfs/locks.mjs +13 -27
  71. package/dist/lfs/namespace.d.mts +2 -0
  72. package/dist/lfs/objects.d.mts +23 -4
  73. package/dist/lfs/objects.mjs +65 -81
  74. package/dist/lfs/pointers.mjs +8 -6
  75. package/dist/lfs/public.d.mts +5 -0
  76. package/dist/lfs/public.mjs +8 -0
  77. package/dist/lfs/purge.mjs +19 -25
  78. package/dist/lfs/rows.mjs +22 -10
  79. package/dist/lfs/service.d.mts +9 -4
  80. package/dist/lfs/service.mjs +3 -12
  81. package/dist/lfs/upkeep.mjs +34 -49
  82. package/dist/node.d.mts +3 -2
  83. package/dist/node.mjs +1 -1
  84. package/dist/protocol/wire/advertisement.d.mts +4 -10
  85. package/dist/protocol/wire/advertisement.mjs +16 -12
  86. package/dist/protocol/wire/lines.d.mts +14 -2
  87. package/dist/protocol/wire/lines.mjs +32 -21
  88. package/dist/protocol/wire/v2.d.mts +4 -15
  89. package/dist/protocol/wire/v2.mjs +16 -14
  90. package/dist/queue/advance.mjs +78 -55
  91. package/dist/queue/calls.mjs +4 -2
  92. package/dist/queue/commit.mjs +20 -13
  93. package/dist/queue/host.d.mts +2 -2
  94. package/dist/queue/layer.d.mts +4 -2
  95. package/dist/queue/layer.mjs +8 -3
  96. package/dist/queue/limits.mjs +36 -6
  97. package/dist/queue/rows.mjs +14 -5
  98. package/dist/queue/state.mjs +19 -5
  99. package/dist/queue/steps.mjs +10 -4
  100. package/dist/queue/trim.mjs +284 -0
  101. package/dist/rest/blobs.d.mts +19 -19
  102. package/dist/rest/caller.d.mts +4 -4
  103. package/dist/rest/commits.d.mts +96 -96
  104. package/dist/rest/errors.d.mts +2 -2
  105. package/dist/rest/events.d.mts +2 -2
  106. package/dist/rest/files.d.mts +54 -54
  107. package/dist/rest/forks.d.mts +87 -87
  108. package/dist/rest/handler.mjs +13 -5
  109. package/dist/rest/layer.d.mts +14 -0
  110. package/dist/rest/layer.mjs +52 -0
  111. package/dist/rest/me.d.mts +2 -2
  112. package/dist/rest/merges.d.mts +2 -2
  113. package/dist/rest/namespace.d.mts +2 -0
  114. package/dist/rest/queue.d.mts +208 -208
  115. package/dist/rest/refs.d.mts +131 -131
  116. package/dist/rest/repos.d.mts +12 -12
  117. package/dist/rest/tags.d.mts +70 -70
  118. package/dist/rest/tokens.d.mts +23 -23
  119. package/dist/rest/topics.d.mts +111 -111
  120. package/dist/rest/trees.d.mts +57 -57
  121. package/dist/rest/wire.d.mts +2 -0
  122. package/dist/rest/wire.mjs +2 -2
  123. package/dist/rest/work.d.mts +6 -6
  124. package/dist/server/edge-node.d.mts +20 -0
  125. package/dist/server/edge-node.mjs +20 -0
  126. package/dist/server/edge.d.mts +10 -0
  127. package/dist/server/edge.mjs +23 -0
  128. package/dist/server/extension.mjs +1 -1
  129. package/dist/server/git-layer.d.mts +15 -4
  130. package/dist/server/git-layer.mjs +13 -2
  131. package/dist/server/git-namespace.d.mts +5 -4
  132. package/dist/server/git-namespace.mjs +6 -3
  133. package/dist/server/registry.d.mts +3 -0
  134. package/dist/server/registry.mjs +58 -7
  135. package/dist/server/server.d.mts +3 -0
  136. package/dist/server/server.mjs +81 -39
  137. package/dist/server/uploads.d.mts +14 -0
  138. package/dist/server/uploads.mjs +15 -0
  139. package/dist/storage/calls.d.mts +7 -8
  140. package/dist/storage/calls.mjs +14 -14
  141. package/dist/storage/clean-up.mjs +59 -29
  142. package/dist/storage/host-bucket.mjs +16 -1
  143. package/dist/storage/index-build.d.mts +1 -1
  144. package/dist/storage/layout.mjs +5 -0
  145. package/dist/storage/merge.d.mts +1 -1
  146. package/dist/storage/push-uploads.mjs +12 -16
  147. package/dist/storage/quarantine.d.mts +1 -1
  148. package/dist/storage/quarantine.mjs +51 -12
  149. package/dist/storage/receive-bounds.d.mts +1 -1
  150. package/dist/storage/repack-job.d.mts +1 -1
  151. package/dist/storage/repack-job.mjs +7 -14
  152. package/dist/storage/rows.mjs +42 -3
  153. package/dist/storage/runs.d.mts +1 -1
  154. package/dist/store/job-try.mjs +26 -0
  155. package/dist/store/list-job.mjs +22 -16
  156. package/dist/store/outbox.mjs +38 -12
  157. package/dist/store/promises.d.mts +6 -1
  158. package/dist/store/promises.mjs +74 -89
  159. package/dist/store/queue-jobs.mjs +22 -1
  160. package/dist/store/scopes.mjs +0 -10
  161. package/dist/sync/mirror.d.mts +1 -1
  162. package/dist/sync/mirror.mjs +1 -1
  163. package/dist/sync/publish.mjs +12 -7
  164. package/dist/sync/step.mjs +4 -0
  165. package/package.json +3 -3
  166. package/dist/lfs/repo.mjs +0 -42
  167. package/dist/storage/promise-calls.mjs +0 -29
@@ -2,7 +2,7 @@ import { millis } from "../contracts/promises.mjs";
2
2
  import { gitError } from "../contracts/result.mjs";
3
3
  import { decodeRow, storeCall } from "../store/errors.mjs";
4
4
  import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
5
- import { bucketCall } from "./calls.mjs";
5
+ import { bucketCall, bucketDo } from "./calls.mjs";
6
6
  import { limits } from "@ref0/infra";
7
7
  import * as Schema from "effect/Schema";
8
8
  import * as Effect from "effect/Effect";
@@ -100,16 +100,13 @@ const partBytes = (bytes, part, size) => Math.min(size, bytes - (part - 1) * siz
100
100
  * `limits.valueBytes`, so a page of 8 stays within half of one answer's `limits.answerBytes`.
101
101
  */
102
102
  const upkeepPage = /* @__PURE__ */ Math.floor(limits.answerBytes / limits.valueBytes / 2);
103
- /** The bucket, when it signs parts and joins them: only then does a server take push uploads. */
104
- const signedUploadOf = (bucket) => joinsParts(bucket) ? bucket : void 0;
105
- /** A bucket made to sign parts, as `r2()` given S3 credentials makes one, has all five. */
106
- const joinsParts = (bucket) => "beginUpload" in bucket && "uploadUrl" in bucket && "listParts" in bucket && "completeUpload" in bucket && "abortUpload" in bucket;
107
103
  /**
108
- * Ends the push uploads due at `at` in `repo`: each one's parts aborted, its key deleted, then its
109
- * row, at the version the rows were read. A crash between leaves the row, and the next step ends
110
- * it again: aborting an ended upload, and deleting a key that's gone, do nothing.
104
+ * Ends the push uploads due at `at` in `repo`: each one's parts aborted, where the host has
105
+ * `uploads`, its key deleted from `bucket`, which charges each call, then its row, at the version
106
+ * the rows were read. A crash between leaves the row, and the next step ends it again: aborting an
107
+ * ended upload, and deleting a key that's gone, do nothing.
111
108
  */
112
- const pushUploadUpkeep = (bucket) => Effect.fnUntraced(function* (store, repo, at) {
109
+ const pushUploadUpkeep = (bucket, uploads) => Effect.fnUntraced(function* (store, repo, at) {
113
110
  const scope = repoScope(repo);
114
111
  const due = [];
115
112
  let next;
@@ -141,7 +138,7 @@ const pushUploadUpkeep = (bucket) => Effect.fnUntraced(function* (store, repo, a
141
138
  more: false,
142
139
  due: next
143
140
  };
144
- yield* Effect.forEach(due, ({ row }) => endUpload(bucket, row), {
141
+ yield* Effect.forEach(due, ({ row }) => endUpload(bucket, uploads, row), {
145
142
  concurrency: 8,
146
143
  discard: true
147
144
  });
@@ -152,10 +149,9 @@ const pushUploadUpkeep = (bucket) => Effect.fnUntraced(function* (store, repo, a
152
149
  }));
153
150
  return { more: true };
154
151
  });
155
- /** An upload's parts aborted, where the bucket joins them, then its key deleted. */
156
- const endUpload = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, row) {
157
- const signed = signedUploadOf(bucket);
158
- if (signed !== void 0) yield* bucketCall((signal) => signed.abortUpload(row.key, row.uploadId, { signal }));
159
- yield* bucketCall((signal) => bucket.delete(row.key, { signal }));
152
+ /** An upload's parts aborted, where the host has `uploads`, then its key deleted. */
153
+ const endUpload = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, uploads, row) {
154
+ if (uploads !== void 0) yield* bucketCall(uploads.abortUpload(row.key, row.uploadId));
155
+ yield* bucketDo(bucket.remove(row.key));
160
156
  });
161
- export { PushUploadRow, completeMost, endUpload, partBytes, partLinkLife, partSizeOf, partsOf, pushPackTooLarge, pushUploadGrace, pushUploadKey, pushUploadLife, pushUploadMost, pushUploadPart, pushUploadRead, pushUploadRowKey, pushUploadUpkeep, signedUploadOf };
157
+ export { PushUploadRow, completeMost, endUpload, partBytes, partLinkLife, partSizeOf, partsOf, pushPackTooLarge, pushUploadGrace, pushUploadKey, pushUploadLife, pushUploadMost, pushUploadPart, pushUploadRead, pushUploadRowKey, pushUploadUpkeep };
@@ -6,5 +6,5 @@ import "../contracts/services.mjs";
6
6
  import "../contracts/store.mjs";
7
7
  import "./layout.mjs";
8
8
  import "./pack-reads.mjs";
9
- import { Key, Moment, Row } from "@ref0/infra";
9
+ import { JobInput, Key, Moment, Row } from "@ref0/infra";
10
10
  import "effect/Effect";
@@ -27,6 +27,10 @@ const sharePacks = (bucket, packs, into) => Effect.forEach(packs, (pack) => isPa
27
27
  * again; then its marker, named by the repo's internal ID. The pack's bytes go only after both.
28
28
  * The add leaves a failed `git.repack` row failed, so clean-up past an outage longer than that
29
29
  * row's tries, `repackRetry`'s week, waits for a host's retry (#1662).
30
+ *
31
+ * The row is read again after the marker's put: clean-up may have taken it between the two, and
32
+ * listed the pack's markers before this one was there (#1582). Then the marker goes again, and
33
+ * the write fails before any byte, so nothing is left that clean-up doesn't see.
30
34
  */
31
35
  const openQuarantine = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
32
36
  const { store, bucket, repo, at, prune } = input;
@@ -43,6 +47,14 @@ const openQuarantine = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
43
47
  }
44
48
  });
45
49
  yield* putMarker(bucket, pack, repo);
50
+ if ((yield* quarantineState({
51
+ store,
52
+ repo,
53
+ pack
54
+ })) !== "open") {
55
+ yield* bucketDo(bucket.remove(markerKey(pack, repo)));
56
+ return yield* fail("UNAVAILABLE", "Clean-up ended the push's pack before its marker was put", { hint: "Push again" });
57
+ }
46
58
  return {
47
59
  pack,
48
60
  quarantine: quarantineKey(pack),
@@ -69,18 +81,11 @@ const stillOpen = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
69
81
  return yield* fail("UNAVAILABLE", "The push's pack outlived its quarantine, so it may be gone", { hint: "Push again" });
70
82
  });
71
83
  /**
72
- * After a receive or a merge failed, its kept indexes let go, then its marker, files and
73
- * `quarantine` row deleted before its refusal is answered, marker first, as clean-up orders them,
74
- * so a refused write keeps nothing. A row clean-up abandoned meanwhile is clean-up's to delete. A
75
- * delete that fails, or other commits that keep moving the repo, leave the row for clean-up to end
76
- * at its `removeAt`. Its own failure is dropped: the write's is the one its caller sees.
84
+ * Commits `body` over a pack's `quarantine` row while it's still `open`, each try at its own
85
+ * read's version, `dropTries` tries at most as other commits move the repo.
77
86
  */
78
- const dropRefused = (input) => bestEffort(Effect.gen(function* () {
79
- const { store, bucket, repo, pack } = input;
80
- input.indexes.forget(pack);
87
+ const whileOpen = /* @__PURE__ */ Effect.fnUntraced(function* ({ store, repo, pack }, body) {
81
88
  const scope = repoScope(repo);
82
- const keys = [markerKey(pack, repo), ...packFileKeys(pack)];
83
- yield* Effect.forEach(keys, (key) => bucketDo(bucket.remove(key)), { discard: true });
84
89
  for (let tried = 0; tried < 3; tried++) {
85
90
  const snapshot = yield* store.read({
86
91
  scope,
@@ -90,12 +95,46 @@ const dropRefused = (input) => bestEffort(Effect.gen(function* () {
90
95
  const change = {
91
96
  id: newChangeId(),
92
97
  expect: snapshot.version,
93
- delete: [quarantineKey(pack)]
98
+ ...body
94
99
  };
95
100
  if ((yield* store.commit({
96
101
  scope,
97
102
  change
98
103
  })).ok) return;
99
104
  }
105
+ });
106
+ /**
107
+ * After a receive or a merge failed, its kept indexes let go, then its marker, files and
108
+ * `quarantine` row deleted before its refusal is answered, marker first, as clean-up orders them,
109
+ * so a refused write keeps nothing. A row clean-up abandoned meanwhile is clean-up's to delete. A
110
+ * delete that fails, or other commits that keep moving the repo, leave the row for clean-up to end
111
+ * at its `removeAt`. Its own failure is dropped: the write's is the one its caller sees.
112
+ */
113
+ const dropRefused = (input) => bestEffort(Effect.gen(function* () {
114
+ const { store, bucket, repo, pack } = input;
115
+ input.indexes.forget(pack);
116
+ const keys = [markerKey(pack, repo), ...packFileKeys(pack)];
117
+ yield* Effect.forEach(keys, (key) => bucketDo(bucket.remove(key)), { discard: true });
118
+ yield* whileOpen({
119
+ store,
120
+ repo,
121
+ pack
122
+ }, { delete: [quarantineKey(pack)] });
123
+ }));
124
+ /**
125
+ * A push that ends with no commit that listed its pack commits its own `quarantine` row
126
+ * abandoned, due at `at`, with `git.repack` due then too, so the next clean-up deletes its marker,
127
+ * bytes and row, not one at its `removeAt`. Each try commits at its own read's version, over a row
128
+ * still `open`: a listing that landed, one whose answer was lost too, has taken the row, and one
129
+ * still on its way is refused by the version this moves. It deletes nothing itself, as a pack's
130
+ * bytes may be listed. Other commits that keep moving the repo, past `dropTries`, or a failure,
131
+ * leave the row for clean-up at its `removeAt`; its own failure is dropped.
132
+ */
133
+ const abandonOwn = ({ at, repackJobRow: repackAt, ...input }) => bestEffort(whileOpen(input, {
134
+ put: [quarantineRow(input.pack, {
135
+ removeAt: at,
136
+ state: "abandoned"
137
+ })],
138
+ jobs: [repackAt(at)]
100
139
  }));
101
- export { deletePackFiles, dropRefused, openQuarantine, putMarker, quarantineOf, quarantineState, sharePacks, stillOpen };
140
+ export { abandonOwn, deletePackFiles, dropRefused, openQuarantine, putMarker, quarantineOf, quarantineState, sharePacks, stillOpen };
@@ -1 +1 @@
1
- import { DeleteBatch, Multipart } from "@ref0/infra";
1
+ import "@ref0/infra";
@@ -1,3 +1,3 @@
1
1
  import "../contracts/result.mjs";
2
- import { JobInput, Key, Moment } from "@ref0/infra";
2
+ import { Job, JobInput, Key, Moment } from "@ref0/infra";
3
3
  import "effect/Schema";
@@ -1,5 +1,5 @@
1
1
  import { collections } from "../store/scopes.mjs";
2
- import { defineJob } from "@ref0/infra";
2
+ import { Job } from "@ref0/infra";
3
3
  import * as Schema from "effect/Schema";
4
4
  // src/storage/repack-job.ts
5
5
  /**
@@ -15,27 +15,20 @@ const repackJobKey = "repack";
15
15
  * leaves merges and pushes going (#1247).
16
16
  */
17
17
  const pruneJobKey = "prune";
18
- const repackJobSchema = /* @__PURE__ */ Schema.toStandardSchemaV1(RepackData);
19
18
  /**
20
19
  * Makes `git.repack`'s rows, beside the rows that need it: a `quarantine` row's `add` and a
21
- * `leaving` row's commit. The core's definition, with the same name and schema, runs them over
22
- * the server's opened objects; this one is never registered.
20
+ * `leaving` row's commit. The core's job, with the same name and payload, runs them over the
21
+ * server's opened objects.
23
22
  */
24
- const repackRows = /* @__PURE__ */ defineJob({
25
- name: repackJobName,
26
- schema: repackJobSchema,
27
- handler: () => {
28
- throw new TypeError(`'${repackJobName}' runs under the core's definition`);
29
- }
30
- });
23
+ const RepackRows = /* @__PURE__ */ Job.make(repackJobName, { payload: RepackData });
31
24
  /** `git.repack` due at `at`; a repo's row keeps the earliest time it is saved for. */
32
- const repackJobRow = (at) => repackRows.job({
25
+ const repackJobRow = (at) => RepackRows.encodedJob({
33
26
  key: repackJobKey,
34
27
  data: {},
35
28
  at
36
29
  });
37
30
  /** `git.repack`'s `prune` row, due at `at`, as `repackJobRow`'s is. */
38
- const pruneJobRow = (at) => repackRows.job({
31
+ const pruneJobRow = (at) => RepackRows.encodedJob({
39
32
  key: pruneJobKey,
40
33
  data: {},
41
34
  at
@@ -62,4 +55,4 @@ const maintenanceRunKey = {
62
55
  collection: collections.repo,
63
56
  id: "maintaining"
64
57
  };
65
- export { MaintenanceRun, RepackData, maintenanceRunKey, parksPass, pruneJobKey, pruneJobRow, repackJobKey, repackJobName, repackJobRow, repackJobSchema };
58
+ export { MaintenanceRun, RepackData, RepackRows, maintenanceRunKey, parksPass, pruneJobKey, pruneJobRow, repackJobKey, repackJobName, repackJobRow };
@@ -7,8 +7,8 @@ import * as Effect from "effect/Effect";
7
7
  // src/storage/rows.ts
8
8
  /**
9
9
  * A pack being written, added before its first byte. `open` while its writer may still list it;
10
- * `abandoned` once its `removeAt` has passed and clean-up committed it so, which refuses a late
11
- * writer's listing commit.
10
+ * `abandoned` once its `removeAt` has passed and clean-up committed it so, or its writer ended with
11
+ * no commit that listed it, which refuses a late writer's listing commit.
12
12
  */
13
13
  const QuarantineRow = /* @__PURE__ */ Schema.Struct({
14
14
  removeAt: Schema.Int,
@@ -66,6 +66,30 @@ const leavingRow = (pack, removeAt, { deleted = false } = {}) => {
66
66
  value
67
67
  };
68
68
  };
69
+ /**
70
+ * A `cover` row's key: its pack's ID, then its try's. A try's own, so no row a take reached
71
+ * before, as a lost try's `leaving` row is, holds the marker it covers.
72
+ */
73
+ const coverKey = (pack, tried) => ({
74
+ collection: objectCollections.cover,
75
+ id: `${pack}.${tried}`
76
+ });
77
+ /** A `cover` row for `pack`'s marker, which a fork's try found unheld, due at `removeAt`. */
78
+ const coverRow = (pack, tried, removeAt) => ({
79
+ ...coverKey(pack.id, tried),
80
+ value: {
81
+ removeAt,
82
+ objects: pack.objects,
83
+ bytes: pack.bytes
84
+ }
85
+ });
86
+ /** The pack a `leaving` or a `cover` row's key names, or `undefined` for neither. */
87
+ const leftPack = (key) => {
88
+ const id = key.collection === objectCollections.leaving ? key.id : key.collection === objectCollections.cover ? key.id.split(".")[0] : void 0;
89
+ return id !== void 0 && isPackId(id) ? id : void 0;
90
+ };
91
+ /** Whether `key` is a `leaving` or a `cover` row's: both hold a marker clean-up lets go. */
92
+ const isLeftKey = (key) => leftPack(key) !== void 0;
69
93
  const isLeaving = /* @__PURE__ */ Schema.is(LeavingRow);
70
94
  /**
71
95
  * `put` with each leaving row due `late` later. A fetch may hold the list from before a commit
@@ -101,4 +125,19 @@ const decodeHeld = (schema, row) => {
101
125
  value
102
126
  }));
103
127
  };
104
- export { LeavingRow, QuarantineRow, StagedRow, decodeHeld, defaultPrune, leavingKey, leavingLate, leavingRow, pruneFloor, pruneWait, quarantineKey, quarantineRow, removeAt, stagedKey };
128
+ /** A stored `leaving` or `cover` row as `LeavingRow`; one whose key names no pack is `DATA_LOSS`. */
129
+ const decodeLeft = (row) => {
130
+ const what = `The ${row.collection} row '${row.id}'`;
131
+ const pack = leftPack(row);
132
+ if (pack === void 0) return fail("DATA_LOSS", `${what} doesn't name a pack`);
133
+ const key = {
134
+ collection: row.collection,
135
+ id: row.id
136
+ };
137
+ return Effect.map(decodeRow(LeavingRow, row, what), (value) => ({
138
+ pack,
139
+ key,
140
+ value
141
+ }));
142
+ };
143
+ export { LeavingRow, QuarantineRow, StagedRow, coverKey, coverRow, decodeHeld, decodeLeft, defaultPrune, isLeftKey, leavingKey, leavingLate, leavingRow, leftPack, pruneFloor, pruneWait, quarantineKey, quarantineRow, removeAt, stagedKey };
@@ -3,6 +3,6 @@ import "../contracts/result.mjs";
3
3
  import "../protocol/packs/step.mjs";
4
4
  import "./layout.mjs";
5
5
  import "./receive-bounds.mjs";
6
- import { Multipart } from "@ref0/infra";
6
+ import "@ref0/infra";
7
7
  import "effect/Schema";
8
8
  import "effect/Effect";
@@ -0,0 +1,26 @@
1
+ import { noCall, syncIn } from "./crossing.mjs";
2
+ import { jobRepo } from "./scopes.mjs";
3
+ import { CurrentJob } from "@ref0/infra";
4
+ import * as Effect from "effect/Effect";
5
+ // src/store/job-try.ts
6
+ /**
7
+ * A `Job.make` definition's `JobDefinition`, made with no service but `CurrentJob`: Git's jobs
8
+ * close over the parts they run with, and the server registers what this answers.
9
+ */
10
+ const madeJob = (made) => syncIn(made, noCall);
11
+ /** The repo whose scope the try runs in: in any other scope, it's a defect, as `jobRepo` says. */
12
+ const currentRepo = Effect.map(CurrentJob.current, jobRepo);
13
+ /**
14
+ * The host's `call` in a try, which runs to its end past the try's interrupt, such as its timeout:
15
+ * the try ends only once the call does, so the queue settles it then, and while its lease holds no
16
+ * retry runs beside it. A call that outlives the lease can run beside the next try's: the store
17
+ * refuses the expired try's writes, but the host's own writes have no fence. A rejection is a
18
+ * defect, the try's error.
19
+ */
20
+ const settledCall = (call) => Effect.callback((resume) => {
21
+ const settled = call().then((value) => resume(Effect.succeed(value)), (cause) => resume(Effect.die(cause)));
22
+ return Effect.promise(() => settled);
23
+ });
24
+ /** `step` over the try's store, fenced by its claim and gated by the server's door, and its repo. */
25
+ const repoTry = (step) => Effect.flatMap(Effect.all([CurrentJob.store, currentRepo]), ([store, repo]) => step(store, repo));
26
+ export { currentRepo, madeJob, repoTry, settledCall };
@@ -1,35 +1,41 @@
1
1
  import { reconcile } from "./catalogue.mjs";
2
- import { runJobTry, untilAborted } from "./crossing.mjs";
3
- import { jobRepo } from "./scopes.mjs";
4
- import { defineJob } from "@ref0/infra";
2
+ import { madeJob, repoTry } from "./job-try.mjs";
3
+ import { Job, defineJob } from "@ref0/infra";
5
4
  import * as Schema from "effect/Schema";
5
+ import * as Effect from "effect/Effect";
6
6
  // src/store/list-job.ts
7
7
  const ListData = /* @__PURE__ */ Schema.Struct({});
8
8
  const listJobName = "git.list";
9
9
  /** The `git.list` job's one key in each repo's scope. */
10
10
  const listJobKey = "list";
11
11
  /**
12
- * `git.list`'s try: projects a repo's record into `git/repos`, where its own write didn't get that
13
- * far, writing an entry only when its revision is newer. Every repo write saves it in the same
14
- * commit. It stops where its try's signal aborts, as at the try's timeout.
12
+ * `git.list`: projects a repo's record into `git/repos`, where its own write didn't get that far,
13
+ * writing an entry only when its revision is newer. Every repo write saves it in the same commit.
14
+ * Its try stops at its timeout, which interrupts it.
15
15
  */
16
- const listHandler = async (job, context) => {
17
- await runJobTry(untilAborted(reconcile(context.store, jobRepo(job)), context.signal));
18
- };
19
- const listJob = /* @__PURE__ */ defineJob({
20
- name: listJobName,
21
- schema: Schema.toStandardSchemaV1(ListData),
16
+ const listJob = /* @__PURE__ */ madeJob(/* @__PURE__ */ (/* @__PURE__ */ Job.make(listJobName, {
17
+ payload: ListData,
22
18
  retry: {
23
19
  limit: 10,
24
20
  delay: "1 second",
25
21
  backoff: "exponential",
26
22
  maxDelay: "5 minutes"
27
- },
28
- handler: listHandler
23
+ }
24
+ })).definition(() => Effect.asVoid(repoTry(reconcile))));
25
+ /**
26
+ * `git.list`'s rows, by `defineJob`, as `ListJob.encodedJob` makes them: a write saves one beside
27
+ * its record without `Job.make`'s runtime, which only the server that runs `listJob` needs.
28
+ */
29
+ const listRows = /* @__PURE__ */ defineJob({
30
+ name: listJobName,
31
+ schema: Schema.toStandardSchemaV1(ListData),
32
+ handler: () => {
33
+ throw new TypeError(`'${listJobName}' runs under listJob`);
34
+ }
29
35
  });
30
36
  /** The job a repo's write saves beside its record. */
31
- const listJobRow = () => listJob.job({
37
+ const listJobRow = () => listRows.job({
32
38
  key: listJobKey,
33
39
  data: {}
34
40
  });
35
- export { listHandler, listJob, listJobKey, listJobName, listJobRow };
41
+ export { listJob, listJobKey, listJobName, listJobRow };
@@ -91,12 +91,17 @@ const keptEvent = (event, firsts) => {
91
91
  }
92
92
  };
93
93
  };
94
- /** A scope's outbox rows: its events by padded `seq`, its head, and its delivery cursor. */
94
+ /** A scope's outbox rows: its events by padded `seq`, its head, and its delivery cursors. */
95
95
  const outboxCollections = {
96
96
  events: "events",
97
97
  outbox: "outbox",
98
- /** Add-only: each cursor is a new row, by its inverted `seq`, so the newest reads first. */
98
+ /**
99
+ * The low-water mark, add-only: each is a new row, by its inverted `seq`, so the newest reads
100
+ * first. It's the slowest active delivery's cursor, as the writes' budgets count it.
101
+ */
99
102
  delivered: "delivered",
103
+ /** Each delivery's cursor, add-only, by `deliveryCursorId`: under its name, newest first. */
104
+ cursors: "cursors",
100
105
  /** By a waiting scope's internal ID: each scope its delivery wakes once it passes the `seq`. */
101
106
  followers: "followers"
102
107
  };
@@ -104,15 +109,33 @@ const headKey = {
104
109
  collection: outboxCollections.outbox,
105
110
  id: "head"
106
111
  };
107
- /** The row naming the event a failed `git.deliver`'s last try sent, which a discard skips. */
108
- const failedKey = {
112
+ /** What a delivery's `failed` row's ID starts with, under the outbox. */
113
+ const failedPrefix = "failed/";
114
+ /**
115
+ * The row naming the event a failed delivery's last try sent, which a discard skips: one per
116
+ * delivery, by its name.
117
+ */
118
+ const failedKeyOf = (delivery) => ({
109
119
  collection: outboxCollections.outbox,
110
- id: "failed"
111
- };
120
+ id: `${failedPrefix}${delivery}`
121
+ });
112
122
  /** The largest `seq` a cursor row's ID inverts. */
113
123
  const lastSeq = 10 ** 15;
114
124
  const eventId = (seq) => versionId(seq);
115
125
  const cursorId = (seq) => versionId(lastSeq - seq);
126
+ /**
127
+ * A delivery's name with each `%` and `/` escaped, `%` first: one text per name, holding no `/`,
128
+ * so its prefix with a `/` after it starts no other name's.
129
+ */
130
+ const cursorName = (delivery) => delivery.replaceAll("%", "%25").replaceAll("/", "%2F");
131
+ /** A delivery's cursor row's ID: its `cursorName`, then the inverted `seq`, so its newest reads first. */
132
+ const deliveryCursorId = (delivery, seq) => `${cursorName(delivery)}/${cursorId(seq)}`;
133
+ /** The read of a delivery's cursor: its newest row, or none before it first moves. */
134
+ const cursorRead = (delivery) => ({
135
+ collection: outboxCollections.cursors,
136
+ prefix: `${cursorName(delivery)}/`,
137
+ limit: 1
138
+ });
116
139
  const Seq = /* @__PURE__ */ Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
117
140
  /**
118
141
  * A scope that held a name's sequence before this one, the last `seq` it wrote under it, and the
@@ -151,13 +174,16 @@ const OutboxHead = /* @__PURE__ */ Schema.Struct({
151
174
  })),
152
175
  after: Schema.optionalKey(Schema.Array(Follows))
153
176
  });
154
- /** The delivery cursor: every event up to `seq` is delivered or skipped, `bytes` their sizes. */
177
+ /**
178
+ * A delivery cursor: every event up to `seq` is delivered or skipped, `bytes` their sizes. The
179
+ * low-water mark has the same shape: every active delivery has passed it.
180
+ */
155
181
  const Delivered = /* @__PURE__ */ Schema.Struct({
156
182
  seq: Seq,
157
183
  bytes: Seq
158
184
  });
159
185
  /**
160
- * A failed `git.deliver`'s last try, by the `claim` its job lists with, and the first event of the
186
+ * A failed delivery job's last try, by the `claim` its job lists with, and the first event of the
161
187
  * batch it sent: none when it failed before it sent one, or its process can't tell, as when the
162
188
  * try's claim lapsed and the one after it had no try left.
163
189
  */
@@ -209,12 +235,12 @@ const eventLimits = {
209
235
  const mib = (bytes) => `${Math.round(bytes / 1024 ** 2)} MiB`;
210
236
  const exhausted = (scope, undelivered) => fail("RESOURCE_EXHAUSTED", `${mib(undelivered)} of events in '${scope}' wait for delivery`, {
211
237
  hint: `Past ${mib(eventLimits.undelivered)} undelivered, writes that add events are refused until they're delivered: try again later`,
212
- hostHint: `The host's events delivery, 'git.deliver' in '${scope}', is failing or behind: fix it, then retry or discard that job`,
238
+ hostHint: `A delivery of the host's events, its job 'git.deliver.<name>' in '${scope}', is failing or behind: fix it, then retry or discard that job`,
213
239
  context: { reason: "events-undelivered" }
214
240
  });
215
241
  const waitsFull = (scope) => fail("RESOURCE_EXHAUSTED", `'${scope}' already waits on 20 repos that had its names`, {
216
242
  hint: "Each wait ends once the repo that had the name delivers its events: try again then",
217
- hostHint: `'git.deliver' in '${scope}' looks for them every 10 seconds`,
243
+ hostHint: `Each delivery's job, 'git.deliver.<name>' in '${scope}', looks for them every 10 seconds`,
218
244
  context: { reason: "events-waiting" }
219
245
  });
220
246
  /**
@@ -318,7 +344,7 @@ const appendEvents = (log, outbox, events, options) => {
318
344
  return Effect.succeed({
319
345
  put,
320
346
  delete: dropped,
321
- jobs: [log.deliverJob()],
347
+ jobs: [...log.deliverJobs()],
322
348
  head: next
323
349
  });
324
350
  };
@@ -372,4 +398,4 @@ const repoEnvelope = (caller, repo) => ({
372
398
  ...callerEnvelope(caller),
373
399
  repo
374
400
  });
375
- export { Delivered, FailedTry, Follower, HiddenMoves, HiddenTotal, OutboxHead, StoredEvent, StoredPush, appendEvents, callerEnvelope, cursorId, decodeEvents, decodeOutbox, dropUnconfirmed, emptyHead, emptyOutbox, eventBytes, eventId, eventLimits, failedKey, firstSeq, headKey, nothingDelivered, outboxCollections, outboxReads, repoEnvelope, shownEvent };
401
+ export { Delivered, FailedTry, Follower, HiddenMoves, HiddenTotal, OutboxHead, StoredEvent, StoredPush, appendEvents, callerEnvelope, cursorId, cursorRead, decodeEvents, decodeOutbox, deliveryCursorId, dropUnconfirmed, emptyHead, emptyOutbox, eventBytes, eventId, eventLimits, failedKeyOf, failedPrefix, firstSeq, headKey, nothingDelivered, outboxCollections, outboxReads, repoEnvelope, shownEvent };
@@ -1,6 +1,11 @@
1
+ import "../contracts/objects.mjs";
1
2
  import "../contracts/promises.mjs";
2
3
  import "@ref0/infra";
3
4
  import "effect/Effect";
4
5
  import "effect/Context";
5
6
  import "effect/Clock";
6
- import "effect/Option";
7
+ /** What the bridge reads of its server's state: its refusal now, if any, and its closing. */
8
+ export interface BridgeDoor {
9
+ readonly refusal: () => Error | undefined;
10
+ readonly closing: AbortSignal;
11
+ }