@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
@@ -0,0 +1,27 @@
1
+ import { Git } from "../contracts/git.mjs";
2
+ import { LfsGetInput, LfsObject } from "../contracts/lfs.mjs";
3
+ import { RepoName } from "../contracts/ids.mjs";
4
+ import { GitError } from "../contracts/result.mjs";
5
+ import { LfsBase } from "./base.mjs";
6
+ import { Bucket } from "@ref0/infra";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Context from "effect/Context";
9
+ import * as Layer from "effect/Layer";
10
+ declare const Lfs_base: Context.ServiceClass<Lfs, "@ref0/git/Lfs", {
11
+ /**
12
+ * An object the repo lists, or a source up its fork chain does, for a caller who may read
13
+ * the repo: the read refusal for any other. `NOT_FOUND` for an object none lists or of
14
+ * another `size`; `DATA_LOSS` for a listed object whose bytes are gone. `signal` aborted
15
+ * cancels the bucket's stream.
16
+ */
17
+ readonly get: (repo: RepoName, input: LfsGetInput) => Effect.Effect<LfsObject, GitError>;
18
+ }>;
19
+ /** Git LFS's objects, read as a call rather than over git-lfs's own HTTP API. */
20
+ export declare class Lfs extends /* @__PURE__ */ Lfs_base {}
21
+ /**
22
+ * Git LFS, a feature over core: it claims `lfs`, keeps its objects in the host's `Bucket`, and
23
+ * serves git-lfs's API under each repo's `info/lfs/`. With `BucketLinks` its transfers go straight
24
+ * to the bucket; without, through the Worker.
25
+ */
26
+ export declare const layer: () => Layer.Layer<Lfs, GitError, Git | LfsBase | Bucket.Bucket>;
27
+ export {};
@@ -0,0 +1,64 @@
1
+ import { claim } from "../contracts/git.mjs";
2
+ import { callerFor } from "../core/access.mjs";
3
+ import { LfsBase } from "./base.mjs";
4
+ import { objectOf } from "./objects.mjs";
5
+ import { pointerCheck } from "./pointers.mjs";
6
+ import { lfsPurge } from "./purge.mjs";
7
+ import { lfsService } from "./service.mjs";
8
+ import { lfsUpkeep } from "./upkeep.mjs";
9
+ import { Bucket } from "@ref0/infra";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Context from "effect/Context";
12
+ import * as Layer from "effect/Layer";
13
+ // src/lfs/layer.ts
14
+ /** Git LFS's objects, read as a call rather than over git-lfs's own HTTP API. */
15
+ var Lfs = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/Lfs")) {};
16
+ /**
17
+ * LFS over `claim`: its routes and pointer check attached to the server, its upkeep and purge on
18
+ * the claim, its rows the claim's, under `lfs/`. A server with no bucket is a defect.
19
+ */
20
+ const lfsClaim = /* @__PURE__ */ Effect.fnUntraced(function* (claim) {
21
+ const base = yield* LfsBase;
22
+ const { needs, bucket, links } = base;
23
+ if (bucket === void 0) return yield* Effect.die(/* @__PURE__ */ new TypeError("lfs() keeps its objects in the adapter's bucket: give the adapter a bucket"));
24
+ const parts = {
25
+ rows: claim.rows,
26
+ bucket,
27
+ signed: links
28
+ };
29
+ const read = (one) => objectOf(parts, one);
30
+ const callerOf = callerFor(void 0);
31
+ yield* base.attach({
32
+ service: lfsService(needs, parts),
33
+ check: {
34
+ claim: claim.name,
35
+ band: "post",
36
+ handler: (input, updates) => pointerCheck(claim.rows, {
37
+ updates,
38
+ objects: input.objects
39
+ })
40
+ },
41
+ read
42
+ });
43
+ yield* claim.addUpkeep(lfsUpkeep(claim.rows, bucket, links !== void 0));
44
+ yield* claim.addPurge(lfsPurge(claim.rows, bucket));
45
+ return Lfs.of({ get: (repo, { oid, size, signal, internalId, ...input }) => Effect.provideContext(read({
46
+ caller: callerOf(input),
47
+ repo,
48
+ oid,
49
+ size,
50
+ signal,
51
+ internalId
52
+ }), needs) });
53
+ });
54
+ /**
55
+ * Git LFS, a feature over core: it claims `lfs`, keeps its objects in the host's `Bucket`, and
56
+ * serves git-lfs's API under each repo's `info/lfs/`. With `BucketLinks` its transfers go straight
57
+ * to the bucket; without, through the Worker.
58
+ */
59
+ const layer = () => Layer.effect(Lfs, Effect.gen(function* () {
60
+ yield* Bucket.Bucket;
61
+ const claim$1 = yield* claim({ name: "lfs" });
62
+ return yield* lfsClaim(claim$1);
63
+ }));
64
+ export { Lfs, layer, lfsClaim };
@@ -1,12 +1,10 @@
1
1
  import { fail, gitError } from "../contracts/result.mjs";
2
2
  import { Sha256 } from "../protocol/bytes/sha256.mjs";
3
3
  import { utf8 } from "../protocol/bytes/text.mjs";
4
- import { contended, openRepo } from "../core/access.mjs";
5
- import { decodeRow, storeCall } from "../store/errors.mjs";
4
+ import { contended, openFor, openRepo } from "../core/access.mjs";
5
+ import { decodeRow } from "../store/errors.mjs";
6
6
  import { randomText } from "../store/random.mjs";
7
- import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
8
- import { fenceFor, fencedRead, openFor } from "./repo.mjs";
9
- import { LockRow, lockKey, lockRead } from "./rows.mjs";
7
+ import { LockRow, lfsCollections, lockKey, lockRead } from "./rows.mjs";
10
8
  import { LockCreate, LockQuery, LockVerify, Unlock, bodyOf, lfsAnswer } from "./wire.mjs";
11
9
  import * as Schema from "effect/Schema";
12
10
  import * as Effect from "effect/Effect";
@@ -47,12 +45,10 @@ const ownerOf = (caller) => caller.actor.anonymous === true ? fail("UNAUTHENTICA
47
45
  const createLock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
48
46
  const { path } = yield* bodyOf(call.request, LockCreate);
49
47
  const owner = yield* ownerOf(call.caller);
50
- const { core } = parts;
51
48
  const repo = yield* openFor(call.caller, call.repo, true);
52
- const fence = fenceFor(core, call.caller, repo);
53
49
  const id = pathRowId(path);
54
50
  for (let tries = 0; tries < 5; tries += 1) {
55
- const read = yield* fencedRead(core, repo, fence, [lockRead(id)]);
51
+ const read = yield* parts.rows.readFenced(call.caller, repo, [lockRead(id)]);
56
52
  const held = read.results[0]?.[0];
57
53
  if (held !== void 0) return lfsAnswer(409, {
58
54
  lock: yield* lockOf(held),
@@ -64,14 +60,10 @@ const createLock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
64
60
  lockedAt: yield* Clock$1.currentTimeMillis,
65
61
  held: randomText(12)
66
62
  };
67
- if ((yield* storeCall(() => core.store.commit(repoScope(repo.internalId), {
68
- id: newChangeId(),
69
- expect: read.version,
70
- put: [{
71
- ...lockKey(id),
72
- value
73
- }]
74
- }))).ok) return lfsAnswer(201, { lock: yield* lockOf({
63
+ if ((yield* parts.rows.commit(repo.internalId, read.version, { put: [{
64
+ ...lockKey(id),
65
+ value
66
+ }] })).ok) return lfsAnswer(201, { lock: yield* lockOf({
75
67
  ...lockKey(id),
76
68
  value
77
69
  }) });
@@ -81,11 +73,11 @@ const createLock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
81
73
  /** One page of the repo's locks, after `cursor`, with the next page's cursor when there's one. */
82
74
  const pageOfLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, cursor, limit) {
83
75
  const read = {
84
- collection: collections.lfsLocks,
76
+ collection: lfsCollections.locks,
85
77
  limit: limit + 1
86
78
  };
87
79
  if (cursor !== void 0) read.after = cursor;
88
- const rows = (yield* storeCall(() => parts.core.store.read(repoScope(repo.internalId), [read]))).results[0] ?? [];
80
+ const rows = (yield* parts.rows.read(repo.internalId, [read])).results[0] ?? [];
89
81
  const locks = yield* Effect.forEach(rows.slice(0, limit), lockOf);
90
82
  const last = rows[limit - 1];
91
83
  return {
@@ -102,7 +94,7 @@ const listLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
102
94
  const id = query.get("id");
103
95
  const wanted = id !== null ? lockIdParts(id) : path === null ? void 0 : { row: pathRowId(path) };
104
96
  if (wanted !== void 0) {
105
- const row = (yield* storeCall(() => parts.core.store.read(repoScope(repo.internalId), [lockRead(wanted.row)]))).results[0]?.[0];
97
+ const row = (yield* parts.rows.read(repo.internalId, [lockRead(wanted.row)])).results[0]?.[0];
106
98
  const lock = row === void 0 ? void 0 : yield* lockOf(row);
107
99
  const named = lock !== void 0 && (id === null || lock.id === id);
108
100
  return lfsAnswer(200, { locks: named ? [lock] : [] });
@@ -138,12 +130,10 @@ const verifyLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
138
130
  const unlock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, id) {
139
131
  const { force = false } = yield* bodyOf(call.request, Unlock);
140
132
  const owner = yield* ownerOf(call.caller);
141
- const { core } = parts;
142
133
  const repo = yield* openFor(call.caller, call.repo, true);
143
- const fence = fenceFor(core, call.caller, repo);
144
134
  const { row: rowId } = lockIdParts(id);
145
135
  for (let tries = 0; tries < 5; tries += 1) {
146
- const read = yield* fencedRead(core, repo, fence, [lockRead(rowId)]);
136
+ const read = yield* parts.rows.readFenced(call.caller, repo, [lockRead(rowId)]);
147
137
  const row = read.results[0]?.[0];
148
138
  const lock = row === void 0 ? void 0 : yield* lockOf(row);
149
139
  if (lock?.id !== id) return yield* fail("NOT_FOUND", "No such lock");
@@ -154,11 +144,7 @@ const unlock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, id) {
154
144
  repo: call.repo
155
145
  })).internalId !== repo.internalId) return yield* fail("UNAVAILABLE", "The repo moved while this call ran", { hint: "Try again" });
156
146
  }
157
- if ((yield* storeCall(() => core.store.commit(repoScope(repo.internalId), {
158
- id: newChangeId(),
159
- expect: read.version,
160
- delete: [lockKey(rowId)]
161
- }))).ok) return lfsAnswer(200, { lock });
147
+ if ((yield* parts.rows.commit(repo.internalId, read.version, { delete: [lockKey(rowId)] })).ok) return lfsAnswer(200, { lock });
162
148
  }
163
149
  return yield* contended();
164
150
  });
@@ -0,0 +1,2 @@
1
+ import { public_d_exports } from "./public.mjs";
2
+ export { public_d_exports as Lfs };
@@ -1,7 +1,26 @@
1
1
  import "../contracts/result.mjs";
2
2
  import "../contracts/authorize.mjs";
3
- import "../contracts/promises.mjs";
4
- import "../contracts/actors.mjs";
5
- import "../contracts/ids.mjs";
6
3
  import "../core/parts.mjs";
7
- import "effect/Effect";
4
+ import "../contracts/objects.mjs";
5
+ import { Caller } from "../contracts/actors.mjs";
6
+ import "../contracts/git.mjs";
7
+ import { InternalRepoId, RepoName } from "../contracts/ids.mjs";
8
+ import "effect/Effect";
9
+ /** One request to a repo's `info/lfs/`, from a caller `identify` answered. */
10
+ export interface LfsCall {
11
+ readonly caller: Caller;
12
+ readonly repo: RepoName;
13
+ readonly request: Request;
14
+ /** The repo's URL as the client named it, which a Worker's links point under. */
15
+ readonly repoUrl: string;
16
+ }
17
+ /** What `objectOf` reads: an object of `repo`'s, for `caller`, of `size` when it's given. */
18
+ export interface ObjectRead {
19
+ readonly caller: Caller;
20
+ readonly repo: RepoName;
21
+ readonly oid: string;
22
+ readonly size?: number | undefined;
23
+ readonly signal?: AbortSignal | undefined;
24
+ /** The repo the caller resolved `repo` to, as `RepoInput` says. */
25
+ readonly internalId?: InternalRepoId | undefined;
26
+ }
@@ -1,54 +1,48 @@
1
1
  import { Sha256 } from "../protocol/bytes/sha256.mjs";
2
- import { contended } from "../core/access.mjs";
3
- import { CoreParts } from "../core/parts.mjs";
4
- import { readRecord } from "../store/repo-record.mjs";
5
- import { decodeRow, storeCall } from "../store/errors.mjs";
2
+ import { contended, openFor } from "../core/access.mjs";
3
+ import { decodeRow } from "../store/errors.mjs";
6
4
  import { randomText } from "../store/random.mjs";
7
- import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
8
- import { fenceFor, fencedRead, openFor } from "./repo.mjs";
9
- import { bucketCall } from "../storage/calls.mjs";
10
- import { promisePut, promiseStream } from "../storage/promise-calls.mjs";
5
+ import { bucketCall, bucketDo, bucketFailed, bucketStream } from "../storage/calls.mjs";
11
6
  import { isLfsOid } from "../protocol/objects/lfs-pointer.mjs";
12
- import { ListedRow, UploadRow, largestObject, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
7
+ import { ListedRow, UploadRow, largestObject, lfsCollections, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
13
8
  import { BatchRequest, VerifyRequest, batchMost, bodyOf, lfsAnswer } from "./wire.mjs";
14
9
  import { fail, gitError } from "../contracts/result.mjs";
10
+ import { Unavailable } from "@ref0/infra";
15
11
  import * as Effect from "effect/Effect";
16
12
  import * as Clock$1 from "effect/Clock";
13
+ import * as Option from "effect/Option";
14
+ import * as Stream from "effect/Stream";
17
15
  import * as DateTime from "effect/DateTime";
18
16
  // src/lfs/objects.ts
19
- /** A bucket's own LFS signing: links to read, and uploads it checks against their SHA-256. */
20
- const signingOf = (bucket) => isSigned(bucket) ? bucket : void 0;
21
- /** A bucket made with signing, as `r2()` given S3 credentials makes one, has all three. */
22
- const isSigned = (bucket) => "url" in bucket && "putUrl" in bucket && "head" in bucket;
23
17
  /**
24
18
  * Each object's rows, read with the repo's record and the fence's rows at one version, the fence
25
19
  * checked; `also`'s rows after them. A repo deleted since it opened is `NOT_FOUND`.
26
20
  */
27
- const objectRows = /* @__PURE__ */ Effect.fnUntraced(function* (core, repo, fence, oids, also = []) {
21
+ const objectRows = /* @__PURE__ */ Effect.fnUntraced(function* (rows, caller, repo, oids, also = []) {
28
22
  const own = oids.flatMap((oid) => [listedRead(oid), uploadRead(oid)]);
29
- const { version, results } = yield* fencedRead(core, repo, fence, [...own, ...also]);
30
- const rows = /* @__PURE__ */ new Map();
23
+ const { version, results } = yield* rows.readFenced(caller, repo, [...own, ...also]);
24
+ const found = /* @__PURE__ */ new Map();
31
25
  for (const [at, oid] of oids.entries()) {
32
26
  const [listedRows = [], uploadRows = []] = results.slice(at * 2, at * 2 + 2);
33
- const found = {};
34
- if (listedRows[0] !== void 0) found.listed = yield* decodeListed(listedRows[0], oid);
35
- if (uploadRows[0] !== void 0) found.upload = yield* decodeUpload(uploadRows[0], oid);
36
- rows.set(oid, found);
27
+ const one = {};
28
+ if (listedRows[0] !== void 0) one.listed = yield* decodeListed(listedRows[0], oid);
29
+ if (uploadRows[0] !== void 0) one.upload = yield* decodeUpload(uploadRows[0], oid);
30
+ found.set(oid, one);
37
31
  }
38
32
  return {
39
33
  version,
40
- rows,
34
+ rows: found,
41
35
  also: results.slice(own.length)
42
36
  };
43
37
  });
44
38
  const decodeListed = (row, oid) => decodeRow(ListedRow, row, `LFS object ${oid}`);
45
39
  const decodeUpload = (row, oid) => decodeRow(UploadRow, row, `LFS object ${oid}'s upload`);
46
40
  /** The repo's listed rows of `oids`, read in chunks. */
47
- const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, oids) {
41
+ const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids) {
48
42
  const listed = /* @__PURE__ */ new Map();
49
43
  for (let at = 0; at < oids.length; at += 100) {
50
44
  const chunk = oids.slice(at, at + 100);
51
- const snapshot = yield* storeCall(() => store.read(repoScope(repo), chunk.map(listedRead)));
45
+ const snapshot = yield* rows.read(repo, chunk.map(listedRead));
52
46
  for (const [index, oid] of chunk.entries()) {
53
47
  const row = snapshot.results[index]?.[0];
54
48
  if (row !== void 0) listed.set(oid, yield* decodeListed(row, oid));
@@ -62,15 +56,15 @@ const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, oids)
62
56
  * wins, so a fork's own upload shadows its source's. A deleted source's rows are read too: its LFS
63
57
  * rows and bytes stay while a fork's row names it, since `git.purge` waits on one.
64
58
  */
65
- const chainListed = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, oids) {
66
- const listed = yield* listedOf(store, repo, oids);
59
+ const chainListed = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids) {
60
+ const listed = yield* listedOf(rows, repo, oids);
67
61
  let from = repo;
68
62
  for (let read = 0; read < 16; read += 1) {
69
63
  const missing = oids.filter((oid) => !listed.has(oid));
70
64
  if (missing.length === 0) break;
71
- const source = (yield* readRecord(store, from)).record?.fork?.upstreamInternalId;
65
+ const source = yield* rows.source(from);
72
66
  if (source === void 0) break;
73
- for (const [oid, row] of yield* listedOf(store, source, missing)) listed.set(oid, row);
67
+ for (const [oid, row] of yield* listedOf(rows, source, missing)) listed.set(oid, row);
74
68
  from = source;
75
69
  }
76
70
  return listed;
@@ -115,7 +109,7 @@ const batch = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
115
109
  const validSize = (size) => Number.isSafeInteger(size) && size >= 0 && size <= largestObject;
116
110
  const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo, objects) {
117
111
  const oids = objects.map(({ oid }) => oid);
118
- const listed = yield* chainListed(parts.core.store, repo.internalId, oids);
112
+ const listed = yield* chainListed(parts.rows, repo.internalId, oids);
119
113
  const expiresAt = (yield* Clock$1.currentTimeMillis) + linkLife;
120
114
  const answers = /* @__PURE__ */ new Map();
121
115
  for (const { oid, size } of objects) {
@@ -127,10 +121,7 @@ const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo
127
121
  const key = row.key;
128
122
  const signed = parts.signed;
129
123
  const download = signed === void 0 ? ownAction(call, `objects/${oid}`, expiresAt) : {
130
- href: yield* bucketCall((signal) => signed.url(key, {
131
- expiresAt,
132
- signal
133
- })),
124
+ href: yield* bucketCall(signed.url(key, { expiresAt })),
134
125
  expires_at: isoOf(expiresAt)
135
126
  };
136
127
  answers.set(oid, {
@@ -149,12 +140,10 @@ const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo
149
140
  * so its links all write one key; a new row gets a new one.
150
141
  */
151
142
  const uploads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo, objects) {
152
- const { core } = parts;
153
- const fence = fenceFor(core, call.caller, repo);
154
143
  const oids = objects.map(({ oid }) => oid);
155
144
  for (let tries = 0; tries < 5; tries += 1) {
156
145
  const at = yield* Clock$1.currentTimeMillis;
157
- const read = yield* objectRows(core, repo, fence, oids);
146
+ const read = yield* objectRows(parts.rows, call.caller, repo, oids);
158
147
  const expiresAt = at + linkLife;
159
148
  const removeAt = expiresAt + uploadGrace;
160
149
  const put = objects.filter(({ oid }) => read.rows.get(oid)?.listed === void 0).map(({ oid, size }) => {
@@ -171,12 +160,10 @@ const uploads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo,
171
160
  };
172
161
  });
173
162
  if (put.length > 0) {
174
- if (!(yield* storeCall(() => core.store.commit(repoScope(repo.internalId), {
175
- id: newChangeId(),
176
- expect: read.version,
163
+ if (!(yield* parts.rows.commit(repo.internalId, read.version, {
177
164
  put,
178
- jobs: [core.repackJobRow(removeAt)]
179
- }))).ok) continue;
165
+ wake: removeAt
166
+ })).ok) continue;
180
167
  }
181
168
  const answers = /* @__PURE__ */ new Map();
182
169
  const generations = new Map(put.map((row) => [row.id, row.value.generation]));
@@ -203,10 +190,9 @@ const uploadActions = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call,
203
190
  const signed = parts.signed;
204
191
  if (signed === void 0) return { upload: ownAction(call, `objects/${oid}`, expiresAt) };
205
192
  return {
206
- upload: yield* bucketCall((signal) => signed.putUrl(key, {
193
+ upload: yield* bucketCall(signed.putUrl(key, {
207
194
  sha256: oid,
208
- expiresAt,
209
- signal
195
+ expiresAt
210
196
  })),
211
197
  verify: ownAction(call, "objects/verify", expiresAt)
212
198
  };
@@ -220,20 +206,17 @@ const uploadActions = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call,
220
206
  const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
221
207
  const { oid, size } = yield* bodyOf(call.request, VerifyRequest);
222
208
  if (!isLfsOid(oid)) return yield* fail("INVALID_ARGUMENT", "An oid is a SHA-256, as 64 lowercase hex digits");
223
- const { core, signed } = parts;
209
+ const { rows: claimed, signed } = parts;
224
210
  const repo = yield* openFor(call.caller, call.repo, true);
225
- const fence = fenceFor(core, call.caller, repo);
226
211
  for (let tries = 0; tries < 5; tries += 1) {
227
- const read = yield* objectRows(core, repo, fence, [oid]);
212
+ const read = yield* objectRows(claimed, call.caller, repo, [oid]);
228
213
  const rows = read.rows.get(oid);
229
214
  if (rows?.listed !== void 0) return lfsAnswer(200, { message: "Verified" });
230
215
  const key = rows?.upload === void 0 ? void 0 : objectKey(repo.internalId, oid, rows.upload.generation);
231
- const stored = signed === void 0 || key === void 0 ? void 0 : yield* bucketCall((signal) => signed.head(key, { signal }));
216
+ const stored = signed === void 0 || key === void 0 ? void 0 : yield* bucketCall(Effect.map(signed.head(key), Option.getOrUndefined));
232
217
  if (stored?.sha256 !== oid) return yield* fail("FAILED_PRECONDITION", "The bucket holds no bytes for this object", { hint: "Upload it again" });
233
218
  if (stored.size !== size) return yield* fail("INVALID_ARGUMENT", `This object is ${stored.size} bytes, not ${size}`);
234
- if ((yield* storeCall(() => core.store.commit(repoScope(repo.internalId), {
235
- id: newChangeId(),
236
- expect: read.version,
219
+ if ((yield* claimed.commit(repo.internalId, read.version, {
237
220
  put: [{
238
221
  ...listedKey(oid),
239
222
  value: {
@@ -242,7 +225,7 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
242
225
  }
243
226
  }],
244
227
  delete: [uploadKey(oid)]
245
- }))).ok) return lfsAnswer(200, { message: "Verified" });
228
+ })).ok) return lfsAnswer(200, { message: "Verified" });
246
229
  }
247
230
  return yield* contended();
248
231
  });
@@ -253,35 +236,38 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
253
236
  */
254
237
  const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
255
238
  if (!isLfsOid(oid)) return yield* fail("INVALID_ARGUMENT", "An oid is a SHA-256, as 64 lowercase hex digits");
256
- const { core, bucket } = parts;
239
+ const { rows: claimed, bucket } = parts;
257
240
  const repo = yield* openFor(call.caller, call.repo, true);
258
- const fence = fenceFor(core, call.caller, repo);
259
241
  const started = yield* Clock$1.currentTimeMillis;
260
- const rows = (yield* objectRows(core, repo, fence, [oid])).rows.get(oid);
242
+ const rows = (yield* objectRows(claimed, call.caller, repo, [oid])).rows.get(oid);
261
243
  if (rows?.listed !== void 0) return yield* answered(call.request);
262
244
  const upload = rows?.upload;
263
245
  if (upload === void 0 || upload.expiresAt < started) return yield* fail("FAILED_PRECONDITION", "No upload link for this object is live", { hint: "Ask the batch API again" });
264
246
  const id = randomText(16);
265
247
  const key = stagingKey(repo.internalId, id);
266
248
  const staged = stagingId(started + uploadGrace, id);
267
- yield* storeCall(() => core.store.add(repoScope(repo.internalId), {
249
+ yield* claimed.add(repo.internalId, {
268
250
  put: [{
269
- collection: collections.lfsStaging,
251
+ collection: lfsCollections.staging,
270
252
  id: staged,
271
253
  value: {
272
254
  key,
273
255
  removeAt: started + uploadGrace
274
256
  }
275
257
  }],
276
- jobs: [core.repackJobRow(started + uploadGrace)]
277
- }));
258
+ wake: started + uploadGrace
259
+ });
278
260
  const hashed = hashing(call.request.body, upload.size);
279
- yield* promisePut(bucket, upload.size, (retrying) => bucket.put(key, hashed.stream, {
280
- size: upload.size,
281
- retrying
282
- })).pipe(Effect.mapError((error) => hashed.past() ? pastSize(upload.size) : error));
261
+ const body = Stream.fromReadableStream({
262
+ evaluate: () => hashed.stream,
263
+ onError: (cause) => new Unavailable({
264
+ message: bucketFailed,
265
+ cause
266
+ })
267
+ });
268
+ yield* Effect.uninterruptible(bucketDo(bucket.put(key, body, { size: upload.size }))).pipe(Effect.mapError((error) => hashed.past() ? pastSize(upload.size) : error));
283
269
  if (hashed.sha256() !== oid) return yield* fail("INVALID_ARGUMENT", "The bytes' SHA-256 isn't the oid");
284
- return yield* listStaged(parts, repo, fence, {
270
+ return yield* listStaged(claimed, call.caller, repo, {
285
271
  oid,
286
272
  size: upload.size,
287
273
  key,
@@ -290,7 +276,10 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
290
276
  });
291
277
  });
292
278
  const pastSize = (size) => gitError("INVALID_ARGUMENT", `The bytes run past the ${size} the batch named`);
293
- /** An answer to a request whose body isn't needed: the body is let go first. */
279
+ /**
280
+ * An answer to a request whose body isn't needed: the body is let go first, and a cancel that
281
+ * rejects is no reason to fail an upload that's done.
282
+ */
294
283
  const answered = (request) => Effect.promise(async () => {
295
284
  await request.body?.cancel();
296
285
  return lfsAnswer(200, { message: "Already uploaded" });
@@ -312,15 +301,12 @@ const hashing = (body, most) => {
312
301
  };
313
302
  };
314
303
  /** Lists a Worker upload's bytes at their staging key, in the commit that drops its staging row. */
315
- const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, fence, staged) {
316
- const { core } = parts;
304
+ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (claimed, caller, repo, staged) {
317
305
  for (let tries = 0; tries < 5; tries += 1) {
318
- const read = yield* objectRows(core, repo, fence, [staged.oid], [stagingRead(staged.staged)]);
306
+ const read = yield* objectRows(claimed, caller, repo, [staged.oid], [stagingRead(staged.staged)]);
319
307
  if (read.rows.get(staged.oid)?.listed !== void 0) return lfsAnswer(200, { message: "Already uploaded" });
320
308
  if ((read.also[0] ?? []).length === 0 || (yield* Clock$1.currentTimeMillis) > staged.deadline) return yield* fail("DEADLINE_EXCEEDED", "The upload ran too long", { hint: "Upload it again" });
321
- if ((yield* storeCall(() => core.store.commit(repoScope(repo.internalId), {
322
- id: newChangeId(),
323
- expect: read.version,
309
+ if ((yield* claimed.commit(repo.internalId, read.version, {
324
310
  put: [{
325
311
  ...listedKey(staged.oid),
326
312
  value: {
@@ -329,26 +315,24 @@ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, fen
329
315
  }
330
316
  }],
331
317
  delete: [uploadKey(staged.oid), {
332
- collection: collections.lfsStaging,
318
+ collection: lfsCollections.staging,
333
319
  id: staged.staged
334
320
  }]
335
- }))).ok) return lfsAnswer(200, { message: "Uploaded" });
321
+ })).ok) return lfsAnswer(200, { message: "Uploaded" });
336
322
  }
337
323
  return yield* contended();
338
324
  });
339
325
  /**
340
- * A listed object's bytes, the repo's own or a source's, once the caller may read the repo: with no
341
- * bucket, none is listed. `signal` aborted cancels the bucket's stream, opening or open.
326
+ * A listed object's bytes, the repo's own or a source's, once the caller may read the repo.
327
+ * `signal` aborted cancels the bucket's stream, opening or open.
342
328
  */
343
- const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, read) {
344
- const core = yield* CoreParts;
329
+ const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
345
330
  const { oid, size, signal } = read;
346
331
  if (!isLfsOid(oid)) return yield* fail("NOT_FOUND", "Object does not exist");
347
332
  const repo = yield* openFor(read.caller, read.repo, false, read.internalId);
348
- if (bucket === void 0) return yield* fail("NOT_FOUND", "Object does not exist");
349
- const listed = (yield* chainListed(core.store, repo.internalId, [oid])).get(oid);
333
+ const listed = (yield* chainListed(parts.rows, repo.internalId, [oid])).get(oid);
350
334
  if (listed === void 0 || size !== void 0 && size !== listed.size) return yield* fail("NOT_FOUND", "Object does not exist");
351
- const stream = yield* promiseStream(bucket, listed.key, signal);
335
+ const stream = yield* bucketStream(parts.bucket, listed.key);
352
336
  if (stream === void 0) return yield* fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`);
353
337
  const bytes = signal === void 0 ? stream : stream.pipeThrough(new TransformStream(), { signal });
354
338
  return {
@@ -359,7 +343,7 @@ const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, read) {
359
343
  });
360
344
  /** `GET objects/<oid>`, a Worker download: a listed object's bytes, the repo's own or a source's. */
361
345
  const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
362
- const object = yield* objectOf(parts.bucket, {
346
+ const object = yield* objectOf(parts, {
363
347
  caller: call.caller,
364
348
  repo: call.repo,
365
349
  oid
@@ -372,4 +356,4 @@ const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
372
356
  }
373
357
  });
374
358
  });
375
- export { batch, listedOf, objectOf, receive, send, signingOf, verify };
359
+ export { batch, listedOf, objectOf, receive, send, verify };
@@ -25,9 +25,11 @@ import * as Effect from "effect/Effect";
25
25
  const pushCheckMilliseconds = 6e4;
26
26
  /** A file's modes: a symlink or a submodule is never a pointer. */
27
27
  const fileModes = /* @__PURE__ */ new Set(["100644", "100755"]);
28
- /** The check, over the repo's listed rows in `store`. */
29
- const pointerCheck = (store) => (input) => checkPointers(store, input);
30
- const checkPointers = /* @__PURE__ */ Effect.fnUntraced(function* (store, input) {
28
+ /**
29
+ * The check, over the repo's listed rows in LFS's claim's `rows`: each ref it refuses, with why.
30
+ * It answers only for the refs it's asked of, and may be asked twice.
31
+ */
32
+ const pointerCheck = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input) {
31
33
  const refused = /* @__PURE__ */ new Map();
32
34
  const tips = /* @__PURE__ */ new Map();
33
35
  for (const update of input.updates) {
@@ -38,7 +40,7 @@ const checkPointers = /* @__PURE__ */ Effect.fnUntraced(function* (store, input)
38
40
  }
39
41
  const { lfsPointers } = input.objects;
40
42
  if (lfsPointers.count === 0 || tips.size === 0) return refused;
41
- const unlisted = yield* unlistedOf(store, input.objects.repo, lfsPointers);
43
+ const unlisted = yield* unlistedOf(rows, input.objects.repo, lfsPointers);
42
44
  if (unlisted === void 0) return refused;
43
45
  const deadline = yield* deadlineOf(pushCheckMilliseconds, "walk-limit");
44
46
  const walk = Effect.forEach(tips, ([ref, tip]) => Effect.map(missingAt(input, unlisted, tip, deadline), (missing) => [ref, missing]));
@@ -51,13 +53,13 @@ const checkPointers = /* @__PURE__ */ Effect.fnUntraced(function* (store, input)
51
53
  * every one is listed. It reads a chunk of entries at a time, so it keeps no more than one read's
52
54
  * rows beside the bits.
53
55
  */
54
- const unlistedOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, pointers) {
56
+ const unlistedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, pointers) {
55
57
  const unlisted = new Uint8Array(Math.ceil(pointers.count / 8));
56
58
  let any = false;
57
59
  for (let from = 0; from < pointers.count; from += 100) {
58
60
  const to = Math.min(from + 100, pointers.count);
59
61
  const oids = Array.from({ length: to - from }, (_, at) => lfsOidAt(pointers, from + at));
60
- const listed = yield* listedOf(store, repo, [...new Set(oids)]);
62
+ const listed = yield* listedOf(rows, repo, [...new Set(oids)]);
61
63
  for (const [at, oid] of oids.entries()) {
62
64
  if (listed.has(oid)) continue;
63
65
  unlisted[from + at >>> 3] = (unlisted[from + at >>> 3] ?? 0) | 1 << (from + at & 7);
@@ -0,0 +1,5 @@
1
+ import { Lfs, layer } from "./layer.mjs";
2
+ declare namespace public_d_exports {
3
+ export { Lfs, layer };
4
+ }
5
+ export { Lfs, layer, public_d_exports };
@@ -0,0 +1,8 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { Lfs, layer } from "./layer.mjs";
3
+ // src/lfs/public.ts
4
+ var public_exports = /* @__PURE__ */ __exportAll({
5
+ Lfs: () => Lfs,
6
+ layer: () => layer
7
+ });
8
+ export { Lfs, layer, public_exports };