@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
@@ -1,14 +1,13 @@
1
1
  import { closedError, isServerClosed } from "./closed.mjs";
2
2
  import { resending } from "./errors.mjs";
3
- import { exitIn, noCall, readableIn, syncIn, uncounted } from "./crossing.mjs";
3
+ import { exitIn, forkIn, noCall, readableIn, syncIn, uncounted } from "./crossing.mjs";
4
4
  import { JobGate } from "@ref0/infra";
5
5
  import * as Effect from "effect/Effect";
6
6
  import * as Context from "effect/Context";
7
7
  import * as Cause from "effect/Cause";
8
8
  import * as Exit from "effect/Exit";
9
- import * as Option from "effect/Option";
10
- import * as Data from "effect/Data";
11
9
  import * as Stream from "effect/Stream";
10
+ import * as Scope$1 from "effect/Scope";
12
11
  import * as EffectDuration from "effect/Duration";
13
12
  import * as Scheduler from "effect/Scheduler";
14
13
  // src/store/promises.ts
@@ -37,6 +36,14 @@ const askClosed = (door) => Effect.suspend(() => {
37
36
  const refused = door.refusal();
38
37
  return refused !== void 0 && isServerClosed(refused) ? Effect.die(refused) : Effect.void;
39
38
  });
39
+ /**
40
+ * `door`'s refusal at the ask, any of them, as a defect: a failed build's too. A host's bucket can't
41
+ * read the server's build, as a run in it does, so a call a package holds from `bind` refuses here.
42
+ */
43
+ const askRefused = (door) => Effect.suspend(() => {
44
+ const refused = door.refusal();
45
+ return refused === void 0 ? Effect.void : Effect.die(refused);
46
+ });
40
47
  /** Dies with the closed error as `door` closes. Its listener goes with the run that waits on it. */
41
48
  const closesOf = (door) => Effect.callback((resume) => {
42
49
  const onAbort = () => resume(Effect.die(closedError()));
@@ -45,26 +52,83 @@ const closesOf = (door) => Effect.callback((resume) => {
45
52
  return Effect.sync(() => door.closing.removeEventListener("abort", onAbort));
46
53
  });
47
54
  /**
55
+ * `stream`, released as `door` closes, even while its reader holds it unread. A pull in flight dies
56
+ * with the closed error, as `closesOf` says. With none in flight, the close ends the stream's own
57
+ * scope at once, so the bucket's body goes with it, and its next pull dies with the closed error: a
58
+ * web stream's reader outside Effect, as a response's body has, holds it so. Its listener goes
59
+ * with the stream.
60
+ */
61
+ const releasedOnClose = (stream, door) => Stream.unwrap(Effect.gen(function* () {
62
+ const own = Scope$1.makeUnsafe();
63
+ const state = { pulling: false };
64
+ const onClose = () => {
65
+ if (state.pulling) return;
66
+ forkIn(Scope$1.close(own, Exit.die(closedError())), noCall);
67
+ };
68
+ door.closing.addEventListener("abort", onClose, { once: true });
69
+ const stop = Effect.sync(() => door.closing.removeEventListener("abort", onClose));
70
+ yield* Effect.addFinalizer((exit) => Effect.andThen(stop, Scope$1.close(own, exit)));
71
+ const pull = yield* Scope$1.provide(Stream.toPull(stream), own);
72
+ const pulled = Effect.suspend(() => {
73
+ state.pulling = true;
74
+ return Effect.raceFirst(closesOf(door), pull);
75
+ }).pipe(Effect.ensuring(Effect.sync(() => state.pulling = false)));
76
+ return Stream.fromPull(Effect.succeed(pulled));
77
+ }));
78
+ /**
48
79
  * `bucket`, built on `context`, as Git's objects call it from their own fibers: each call reads the
49
80
  * caller's context over the built one's services, so the bucket finds its host's and the call still
50
81
  * counts into the caller's request, and goes through `door`, so a call or a read still going as the
51
- * server closes dies with the closed error. A put's body runs in the same context, so what it reads
82
+ * server closes dies with the closed error. Each asks the door's whole refusal first, as
83
+ * `askRefused` says. A put's body runs in the same context, so what it reads
52
84
  * counts as the caller's. `context` keeps no `Scheduler`, as `ownScheduler` says.
53
85
  */
54
86
  const doorBucket = (bucket, context, door) => {
55
- const host = ownScheduler(context);
56
- const through = throughBridge(door);
57
- const over = (caller) => Context.merge(caller, host);
58
- const call = (effect) => through(Effect.updateContext(effect, over));
87
+ const { over, call } = doorOf(context, door);
59
88
  return {
60
89
  ...bucket,
61
90
  put: (key, body, options) => call(bucket.put(key, body, options)),
62
- read: (key, range) => Stream.unwrap(Effect.as(askClosed(door), bucket.read(key, range).pipe(Stream.updateContext(over), Stream.interruptWhen(closesOf(door))))),
91
+ read: (key, range) => Stream.unwrap(Effect.as(askRefused(door), releasedOnClose(bucket.read(key, range).pipe(Stream.updateContext(over)), door))),
63
92
  remove: (key) => call(bucket.remove(key)),
64
93
  removeMany: (keys, options) => call(bucket.removeMany(keys, options)),
65
94
  list: (prefix, page) => call(bucket.list(prefix, page))
66
95
  };
67
96
  };
97
+ /** `links`, built on `context`, each call through `door` on the caller's context, as `doorBucket`'s. */
98
+ const doorLinks = (links, context, door) => {
99
+ const { call } = doorOf(context, door);
100
+ return {
101
+ url: (key, options) => call(links.url(key, options)),
102
+ putUrl: (key, options) => call(links.putUrl(key, options)),
103
+ head: (key) => call(links.head(key))
104
+ };
105
+ };
106
+ /** `uploads`, built on `context`, each call through `door` on the caller's context, as `doorBucket`'s. */
107
+ const doorUploads = (uploads, context, door) => {
108
+ const { call } = doorOf(context, door);
109
+ return {
110
+ maxParts: uploads.maxParts,
111
+ beginUpload: (key) => call(uploads.beginUpload(key)),
112
+ uploadUrl: (key, options) => call(uploads.uploadUrl(key, options)),
113
+ listParts: (key, upload) => call(uploads.listParts(key, upload)),
114
+ completeUpload: (key, input) => call(uploads.completeUpload(key, input)),
115
+ abortUpload: (key, upload) => call(uploads.abortUpload(key, upload))
116
+ };
117
+ };
118
+ /**
119
+ * How a door's service runs a call: on the caller's context over `context`'s services, through
120
+ * `door`, as `doorBucket` says.
121
+ */
122
+ const doorOf = (context, door) => {
123
+ const host = ownScheduler(context);
124
+ const through = throughBridge(door);
125
+ const over = (caller) => Context.merge(caller, host);
126
+ const call = (effect) => Effect.andThen(askRefused(door), through(Effect.updateContext(effect, over)));
127
+ return {
128
+ over,
129
+ call
130
+ };
131
+ };
68
132
  /**
69
133
  * `readable`, which errors with `closing`'s reason once it aborts, and cancels `readable` then. It
70
134
  * stops the stream from in front of it, not inside it. `readableIn` runs the stream at once, so a
@@ -213,85 +277,6 @@ const promisesQueue = (queue, context, door) => {
213
277
  discard: (scope, job) => run(queue.discard(scope, job))
214
278
  };
215
279
  };
216
- /** A put's body that failed as it was read, carrying its own failure. */
217
- var BodyFailure = class extends Data.TaggedError("BodyFailure") {};
218
- const bodyOf = (body) => Stream.fromReadableStream({
219
- evaluate: () => body,
220
- onError: (cause) => new BodyFailure({ cause })
221
- });
222
- /**
223
- * The bucket over `Bucket`, with `BucketLinks`' and `BucketUploads`' methods when the runtime has
224
- * them, run on `context`: git tells a signing bucket by its methods.
225
- */
226
- const promisesBucket = (bucket, links, uploads, context, door) => {
227
- const { run, readable } = runnerOf(context, door);
228
- const face = {
229
- multipart: bucket.multipart,
230
- put: (key, body, options) => run(Effect.catchTag(bucket.put(key, bodyOf(body), options), "BodyFailure", (failure) => Effect.die(failure.cause)), options?.signal),
231
- /**
232
- * The read's stream, pulled once to tell a missing key from a found one, then handed on with
233
- * that chunk first. The stream's scope owns the body from the call's answer, so a cancel, an
234
- * abort or the door's closing closes it.
235
- */
236
- read: async (key, range, options) => {
237
- options?.signal?.throwIfAborted();
238
- const reader = readable(Stream.catchTag(bucket.read(key, range), "NotFound", () => Stream.succeed(void 0))).getReader();
239
- const cancel = () => void reader.cancel(options?.signal?.reason).catch(() => void 0);
240
- options?.signal?.addEventListener("abort", cancel, { once: true });
241
- try {
242
- const first = await reader.read();
243
- options?.signal?.throwIfAborted();
244
- const head = first.done ? void 0 : first.value;
245
- if (!first.done && head === void 0) {
246
- await reader.cancel().catch(() => void 0);
247
- return;
248
- }
249
- return new ReadableStream({
250
- start: (controller) => head === void 0 ? controller.close() : controller.enqueue(head),
251
- pull: async (controller) => {
252
- const next = await reader.read();
253
- if (next.done) controller.close();
254
- else if (next.value !== void 0) controller.enqueue(next.value);
255
- },
256
- cancel: (reason) => reader.cancel(reason)
257
- }, { highWaterMark: 0 });
258
- } catch (error) {
259
- cancel();
260
- throw error;
261
- } finally {
262
- options?.signal?.removeEventListener("abort", cancel);
263
- }
264
- },
265
- delete: (key, options) => run(bucket.remove(key), options?.signal),
266
- deleteBatch: bucket.deleteBatch,
267
- deleteMany: (keys, options) => run(bucket.removeMany(keys, options), options?.signal),
268
- list: (prefix, page, options) => run(bucket.list(prefix, page), options?.signal)
269
- };
270
- const signed = Option.match(links, {
271
- onNone: () => ({}),
272
- onSome: (links) => ({
273
- url: (key, options) => run(links.url(key, options), options.signal),
274
- putUrl: (key, options) => run(links.putUrl(key, options), options.signal),
275
- head: (key, options) => run(Effect.map(links.head(key), Option.getOrUndefined), options?.signal)
276
- })
277
- });
278
- const parted = Option.match(uploads, {
279
- onNone: () => ({}),
280
- onSome: (uploads) => ({
281
- maxParts: uploads.maxParts,
282
- beginUpload: (key, options) => run(uploads.beginUpload(key), options?.signal),
283
- uploadUrl: (key, options) => run(uploads.uploadUrl(key, options), options.signal),
284
- listParts: (key, upload, options) => run(uploads.listParts(key, upload), options?.signal),
285
- completeUpload: (key, input, options) => run(uploads.completeUpload(key, input), options?.signal),
286
- abortUpload: (key, upload, options) => run(uploads.abortUpload(key, upload), options?.signal)
287
- })
288
- });
289
- return {
290
- ...face,
291
- ...signed,
292
- ...parted
293
- };
294
- };
295
280
  /** The longest one timer waits: a later `until` sleeps in turns. */
296
281
  const longestTimer = 2 ** 31 - 1;
297
282
  /**
@@ -314,4 +299,4 @@ const promisesClock = (clock, context, door) => {
314
299
  };
315
300
  return face;
316
301
  };
317
- export { doorBucket, openDoor, promisesBucket, promisesClock, promisesQueue, promisesStore, throughBridge };
302
+ export { doorBucket, doorLinks, doorUploads, openDoor, promisesClock, promisesQueue, promisesStore, throughBridge };
@@ -8,8 +8,19 @@ import * as Schema from "effect/Schema";
8
8
  const advanceName = "queue.advance";
9
9
  const buildName = "queue.build";
10
10
  const timeoutName = "queue.report-timeout";
11
+ const trimName = "queue.trim";
11
12
  const AdvanceData = /* @__PURE__ */ Schema.Struct({ target: Schema.String });
12
13
  const CandidateData = /* @__PURE__ */ Schema.Struct({ candidate: Schema.String });
14
+ /** Where a pass of `queue.trim` is: the collection it reads, and `after` the ID it read up to. */
15
+ const TrimData = /* @__PURE__ */ Schema.Struct({
16
+ phase: Schema.Literals([
17
+ "targets",
18
+ "entries",
19
+ "candidates",
20
+ "holds"
21
+ ]),
22
+ after: Schema.optionalKey(Schema.String)
23
+ });
13
24
  /**
14
25
  * Makes a queue job's rows, beside the rows that need it. The server's definitions, with the same
15
26
  * names and schemas, run them; these are never registered.
@@ -24,6 +35,7 @@ const rowsOf = (name, schema) => defineJob({
24
35
  const advanceRows = /* @__PURE__ */ rowsOf(advanceName, AdvanceData);
25
36
  const buildRows = /* @__PURE__ */ rowsOf(buildName, CandidateData);
26
37
  const timeoutRows = /* @__PURE__ */ rowsOf(timeoutName, CandidateData);
38
+ const trimRows = /* @__PURE__ */ rowsOf(trimName, TrimData);
27
39
  /** `queue.advance` for `target`, due now: one row a target, which a later save leaves due. */
28
40
  const advanceRow = (target) => advanceRows.job({
29
41
  key: target,
@@ -40,4 +52,13 @@ const timeoutRow = (candidate, at) => timeoutRows.job({
40
52
  data: { candidate },
41
53
  at
42
54
  });
43
- export { AdvanceData, CandidateData, advanceName, advanceRow, buildName, buildRow, timeoutName, timeoutRow };
55
+ /**
56
+ * `queue.trim` for the repo, due `at`, a target's first write saves: one row a repo, which a save
57
+ * while it's due sooner, or mid-pass, leaves as it is.
58
+ */
59
+ const trimRow = (at) => trimRows.job({
60
+ key: "trim",
61
+ data: { phase: "targets" },
62
+ at
63
+ });
64
+ export { AdvanceData, CandidateData, TrimData, advanceName, advanceRow, buildName, buildRow, timeoutName, timeoutRow, trimName, trimRow };
@@ -79,16 +79,6 @@ const collections = {
79
79
  tokenKeys: "token-keys",
80
80
  /** A token's ID after its padded `expiresAt`, so cleanup reads the oldest first. */
81
81
  tokenExpiry: "token-expiry",
82
- /** In a repo's scope: each LFS object the repo lists, by its oid. Only a deleted repo unlists. */
83
- lfsObjects: "lfs-objects",
84
- /** In a repo's scope: each LFS object an upload link was given for, by its oid, until listed. */
85
- lfsUploads: "lfs-uploads",
86
- /** In a repo's scope: a Worker upload's staging key, by its due `removeAt` and its ID. */
87
- lfsStaging: "lfs-staging",
88
- /** In a repo's scope: an LFS object upkeep is deleting, by its oid, which no verify lists. */
89
- lfsEnding: "lfs-ending",
90
- /** In a repo's scope: each LFS lock, by its path's SHA-256. */
91
- lfsLocks: "lfs-locks",
92
82
  /**
93
83
  * In a repo's scope: each large push's pack uploading to the bucket, by its handle, until it's
94
84
  * pushed or upkeep ends it.
@@ -3,7 +3,7 @@ import "../contracts/authorize.mjs";
3
3
  import { MirrorState, SyncMirrorInput, SyncMirrorsInput, SyncRemoveMirrorInput } from "../contracts/sync.mjs";
4
4
  import "./bound.mjs";
5
5
  import "../core/parts.mjs";
6
- import "@ref0/infra";
6
+ import { Job } from "@ref0/infra";
7
7
  import "effect/Effect";
8
8
  /** Deletes the repo's mirror of `ref`; `RemoveMirror` says how. */
9
9
  export declare const removeMirror: (input: SyncRemoveMirrorInput) => Promise<Result<void>>;
@@ -69,7 +69,7 @@ const mirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
69
69
  const { internalId, name, record } = yield* openRepo(caller, operation, [], input.internalId);
70
70
  const ref = headOf(input.ref ?? record.defaultBranch);
71
71
  if (!isRefName(ref)) return yield* fail("INVALID_ARGUMENT", `'${ref}' isn't a ref Git takes`);
72
- if (hiddenUnder(ref) !== void 0) return yield* fail("INVALID_ARGUMENT", `'${ref}' is Git's own, and no mirror pushes it`);
72
+ if (hiddenUnder((yield* CoreParts).hiddenRefs(), ref) !== void 0) return yield* fail("INVALID_ARGUMENT", `'${ref}' is Git's own, and no mirror pushes it`);
73
73
  const refView = yield* refViewIn(caller, repoAccess({
74
74
  name,
75
75
  record,
@@ -1,20 +1,24 @@
1
1
  import { fail, gitError } from "../contracts/result.mjs";
2
2
  import { openRepo } from "../core/access.mjs";
3
3
  import { isRefName } from "../core/names.mjs";
4
+ import { CoreParts } from "../core/parts.mjs";
4
5
  import { push } from "../core/push.mjs";
5
6
  import { isOid } from "../protocol/bytes/text.mjs";
6
- import { gitsOwnMove, hiddenUnder } from "../protocol/wire/lines.mjs";
7
+ import { hiddenUnder, importOwner } from "../protocol/wire/lines.mjs";
7
8
  import { wholeRefs } from "../store/ref-rows.mjs";
8
9
  import { collections } from "../store/scopes.mjs";
9
10
  import { asSync, boundOf, syncCall } from "./bound.mjs";
10
11
  import { syncWhole } from "./tries.mjs";
11
12
  import * as Effect from "effect/Effect";
12
13
  // src/sync/publish.ts
13
- /** Whether `ref` is an import's staging ref, which only `source: 'import'` writes. */
14
- const isStaging = (ref) => gitsOwnMove("import", ref);
14
+ /** Whether `ref` is an import's staging ref, which only a push `as` `importOwner` writes. */
15
+ const isStaging = (ref) => ref.startsWith(importOwner.prefix);
15
16
  const refsRead = { collection: collections.refs };
16
- /** The first reason `moves` can't be sent, as `INVALID_ARGUMENT`. */
17
- const refusedMoves = (moves) => {
17
+ /**
18
+ * The first reason `moves` can't be sent, as `INVALID_ARGUMENT`: a `to` under one of `table`'s
19
+ * prefixes among them.
20
+ */
21
+ const refusedMoves = (table, moves) => {
18
22
  const froms = /* @__PURE__ */ new Set();
19
23
  const tos = /* @__PURE__ */ new Set();
20
24
  for (const move of moves) {
@@ -27,7 +31,7 @@ const refusedMoves = (moves) => {
27
31
  const { to, at } = move;
28
32
  if (!isRefName(to)) return `'${to}' isn't a full ref name`;
29
33
  if (at !== null && !isOid(at)) return `'${at}' isn't an object ID`;
30
- if (hiddenUnder(to) !== void 0) return `'${to}' is Git's own: no import publishes to it`;
34
+ if (hiddenUnder(table, to) !== void 0) return `'${to}' is Git's own: no import publishes to it`;
31
35
  if (tos.has(to)) return `Two moves write '${to}'`;
32
36
  tos.add(to);
33
37
  }
@@ -60,7 +64,7 @@ const firstMoved = (moves, refs) => {
60
64
  */
61
65
  const publishWith = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
62
66
  yield* boundOf(input.git);
63
- const refused = refusedMoves(input.moves);
67
+ const refused = refusedMoves((yield* CoreParts).hiddenRefs(), input.moves);
64
68
  if (refused !== void 0) return yield* fail("INVALID_ARGUMENT", refused);
65
69
  const caller = { actor: input.actor };
66
70
  const operation = {
@@ -101,6 +105,7 @@ const publishWith = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
101
105
  caller,
102
106
  repo: input.repo,
103
107
  source: "import",
108
+ as: importOwner,
104
109
  edits,
105
110
  atomic: true
106
111
  };
@@ -18,6 +18,7 @@ import { ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndD
18
18
  import { ForGood, SyncTryError, forGood, fromRemote, httpOf, openedFor, remoteOf, runTry, syncObjects, thrownOf } from "./tries.mjs";
19
19
  import { runIn, uncounted } from "../store/crossing.mjs";
20
20
  import { CoreParts, ObjectsParts, overStore } from "../core/parts.mjs";
21
+ import { importOwner } from "../protocol/wire/lines.mjs";
21
22
  import * as Effect from "effect/Effect";
22
23
  import * as Result from "effect/Result";
23
24
  // src/sync/step.ts
@@ -410,6 +411,7 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
410
411
  repo: opened.name,
411
412
  internalId: attempt.internalId,
412
413
  source: "import",
414
+ as: importOwner,
413
415
  edits: [],
414
416
  atomic: false,
415
417
  pack: pushedPack,
@@ -533,6 +535,7 @@ const resumedIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, rec
533
535
  repo: opened.name,
534
536
  internalId: attempt.internalId,
535
537
  source: "import",
538
+ as: importOwner,
536
539
  edits: [],
537
540
  atomic: false,
538
541
  pack: { received: answer.received },
@@ -612,6 +615,7 @@ const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
612
615
  repo: opened.name,
613
616
  internalId: attempt.internalId,
614
617
  source: "import",
618
+ as: importOwner,
615
619
  edits,
616
620
  atomic: true,
617
621
  also: () => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/git",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "description": "Git hosting as a library: a server, a client and their merges",
6
6
  "license": "Apache-2.0",
@@ -67,12 +67,12 @@
67
67
  }
68
68
  },
69
69
  "dependencies": {
70
- "@ref0/infra": "0.4.0",
70
+ "@ref0/infra": "0.6.0",
71
71
  "pako": "2.1.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@effect/vitest": "4.1.4",
75
- "@ref0/xdiff-wasm": "0.4.0",
75
+ "@ref0/xdiff-wasm": "0.6.0",
76
76
  "effect": "4.1.4",
77
77
  "vite-plus": "1.7.0",
78
78
  "vitest": "5.1.0"
package/dist/lfs/repo.mjs DELETED
@@ -1,42 +0,0 @@
1
- import { fail } from "../contracts/result.mjs";
2
- import { openRepo } from "../core/access.mjs";
3
- import { readRecord } from "../store/repo-record.mjs";
4
- import * as Effect from "effect/Effect";
5
- // src/lfs/repo.ts
6
- /**
7
- * The repo, once `authorize` lets the caller fetch it, or push to it. A push's refusal, whatever
8
- * its code, is told only to a caller that may read the repo, as receive's is. With `internalId`,
9
- * a name that holds another repo is as one with none, as `openRepo` says (Q705).
10
- */
11
- const openFor = (caller, repo, writing, internalId) => writing ? openRepo(caller, {
12
- kind: "push",
13
- repo,
14
- updates: []
15
- }, [], internalId).pipe(Effect.catch((refused) => Effect.andThen(openRepo(caller, {
16
- kind: "read",
17
- repo
18
- }, [], internalId), Effect.fail(refused)))) : openRepo(caller, {
19
- kind: "fetch",
20
- repo
21
- }, [], internalId);
22
- /** The fence a write to `repo` reads again before it commits. */
23
- const fenceFor = (core, caller, repo) => core.fences(caller, {
24
- internalId: repo.internalId,
25
- name: repo.name
26
- });
27
- /**
28
- * `reads`, read with the repo's record and the fence's rows at one version, the fence checked: a
29
- * write commits at `version`, so a revoke or a delete since moves it. A deleted repo is
30
- * `NOT_FOUND`.
31
- */
32
- const fencedRead = /* @__PURE__ */ Effect.fnUntraced(function* (core, repo, fence, reads) {
33
- const { record, snapshot } = yield* readRecord(core.store, repo.internalId, [...reads, ...fence.reads]);
34
- if (record === void 0 || record.deleted === true) return yield* fail("NOT_FOUND", `No repo '${repo.name}'`);
35
- const results = snapshot.results.slice(1);
36
- yield* fence.check(results.slice(reads.length));
37
- return {
38
- version: snapshot.version,
39
- results: results.slice(0, reads.length)
40
- };
41
- });
42
- export { fenceFor, fencedRead, openFor };
@@ -1,29 +0,0 @@
1
- import { chargeCalls } from "../store/call-count.mjs";
2
- import { bucketCall, bucketTry, counting, putCharge, putParts, retryCharge } from "./calls.mjs";
3
- import * as Effect from "effect/Effect";
4
- // src/storage/promise-calls.ts
5
- /**
6
- * The promise bucket's stream of `key`, or of `range` of it, its open interruptible: a stream that
7
- * comes back after the call was interrupted, by its signal or its deadline, is cancelled, as no one
8
- * will read it.
9
- */
10
- const promiseStream = (bucket, key, signal, range) => {
11
- let opening;
12
- const late = Effect.sync(() => {
13
- opening?.then((bytes) => bytes?.cancel(signal?.reason)).catch(() => void 0);
14
- });
15
- return bucketCall((fiber) => opening = bucket.read(key, range, { signal: fiber })).pipe(Effect.onInterrupt(() => late));
16
- };
17
- /**
18
- * A put of the promise bucket's, one body of `size` bytes it's told the size of, charged by
19
- * `putCharge` all at once, and each call it sends again through the `retrying` `run` passes on.
20
- * An interruption waits it out, as `bucketPut`'s does.
21
- */
22
- const promisePut = (bucket, size, run) => Effect.uninterruptible(Effect.gen(function* () {
23
- yield* counting(bucket.multipart);
24
- const { start, partSize } = putCharge(bucket.multipart, size);
25
- yield* chargeCalls("bucket", start + putParts(partSize, size) - 1);
26
- const retrying = yield* retryCharge();
27
- return yield* bucketTry(() => run(retrying));
28
- }));
29
- export { promisePut, promiseStream };