@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,50 +1,44 @@
1
- import { bucketCall } from "../storage/calls.mjs";
2
- import { decodeRow, storeCall } from "../store/errors.mjs";
3
- import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
4
- import { ListedRow } from "./rows.mjs";
1
+ import { bucketDo } from "../storage/calls.mjs";
2
+ import { decodeRow } from "../store/errors.mjs";
3
+ import { ListedRow, lfsCollections } from "./rows.mjs";
5
4
  import * as Effect from "effect/Effect";
6
- /** LFS's purge over `bucket`, for `purgeJob`'s `parts`. */
7
- const lfsPurge = (bucket) => /* @__PURE__ */ Effect.fnUntraced(function* (store, repo) {
8
- const scope = repoScope(repo);
9
- const snapshot = yield* storeCall(() => store.read(scope, [
5
+ /** LFS's claim's purge over its `rows` and `bucket`, which charges each call. */
6
+ const lfsPurge = (rows, bucket) => /* @__PURE__ */ Effect.fnUntraced(function* ({ repo }) {
7
+ const snapshot = yield* rows.read(repo, [
10
8
  {
11
- collection: collections.lfsUploads,
9
+ collection: lfsCollections.uploads,
12
10
  limit: 1
13
11
  },
14
12
  {
15
- collection: collections.lfsStaging,
13
+ collection: lfsCollections.staging,
16
14
  limit: 1
17
15
  },
18
16
  {
19
- collection: collections.lfsEnding,
17
+ collection: lfsCollections.ending,
20
18
  limit: 1
21
19
  },
22
20
  {
23
- collection: collections.lfsObjects,
21
+ collection: lfsCollections.objects,
24
22
  limit: 500
25
23
  },
26
24
  {
27
- collection: collections.lfsLocks,
25
+ collection: lfsCollections.locks,
28
26
  limit: 500
29
27
  }
30
- ]));
28
+ ]);
31
29
  const [uploads = [], staging = [], ending = [], listed = [], locks = []] = snapshot.results;
32
30
  if (uploads.length + staging.length + ending.length > 0) return "waits";
33
- const rows = listed.length > 0 ? listed : locks;
34
- if (rows.length === 0) return "done";
31
+ const found = listed.length > 0 ? listed : locks;
32
+ if (found.length === 0) return "done";
35
33
  const keys = yield* Effect.forEach(listed, (row) => Effect.map(decodeRow(ListedRow, row, `LFS object ${row.id}`), (object) => object.key));
36
- yield* Effect.forEach(keys, (key) => bucketCall((signal) => bucket.delete(key, { signal })), {
34
+ yield* Effect.forEach(keys, (key) => bucketDo(bucket.remove(key)), {
37
35
  concurrency: 8,
38
36
  discard: true
39
37
  });
40
- yield* storeCall(() => store.commit(scope, {
41
- id: newChangeId(),
42
- expect: snapshot.version,
43
- delete: rows.map((row) => ({
44
- collection: row.collection,
45
- id: row.id
46
- }))
47
- }));
38
+ yield* rows.commit(repo, snapshot.version, { delete: found.map((row) => ({
39
+ collection: row.collection,
40
+ id: row.id
41
+ })) });
48
42
  return "did";
49
43
  });
50
44
  export { lfsPurge };
package/dist/lfs/rows.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { millis } from "../contracts/promises.mjs";
2
- import { collections } from "../store/scopes.mjs";
3
2
  import * as Schema from "effect/Schema";
4
3
  // src/lfs/rows.ts
5
4
  /**
@@ -8,6 +7,19 @@ import * as Schema from "effect/Schema";
8
7
  * SHA-256 ever reach. A repo serves only the objects it lists, and lists one only after its bytes
9
8
  * were checked at its key.
10
9
  */
10
+ /** LFS's collections in a repo's scope: its claim's rows, under `lfs/`. */
11
+ const lfsCollections = {
12
+ /** Each LFS object the repo lists, by its oid. Only a deleted repo unlists. */
13
+ objects: "lfs/objects",
14
+ /** Each LFS object an upload link was given for, by its oid, until listed. */
15
+ uploads: "lfs/uploads",
16
+ /** A Worker upload's staging key, by its due `removeAt` and its ID. */
17
+ staging: "lfs/staging",
18
+ /** An LFS object upkeep is deleting, by its oid, which no verify lists. */
19
+ ending: "lfs/ending",
20
+ /** Each LFS lock, by its path's SHA-256. */
21
+ locks: "lfs/locks"
22
+ };
11
23
  /**
12
24
  * The largest object LFS takes: R2's largest put in one request, 5 GiB less 5 MiB, since a
13
25
  * multipart upload's result has no SHA-256 to check it by.
@@ -71,38 +83,38 @@ const objectKey = (repo, oid, generation) => `lfs/${repo}/${oid}.${generation}`;
71
83
  /** A Worker upload's bytes as they stream, before they're checked. */
72
84
  const stagingKey = (repo, id) => `lfs/${repo}/staging/${id}`;
73
85
  const listedKey = (oid) => ({
74
- collection: collections.lfsObjects,
86
+ collection: lfsCollections.objects,
75
87
  id: oid
76
88
  });
77
89
  const uploadKey = (oid) => ({
78
- collection: collections.lfsUploads,
90
+ collection: lfsCollections.uploads,
79
91
  id: oid
80
92
  });
81
93
  /** An ending row's key: its upload's oid and generation, so two generations' rows never meet. */
82
94
  const endingKey = (oid, generation) => ({
83
- collection: collections.lfsEnding,
95
+ collection: lfsCollections.ending,
84
96
  id: `${oid}.${generation}`
85
97
  });
86
98
  const lockKey = (id) => ({
87
- collection: collections.lfsLocks,
99
+ collection: lfsCollections.locks,
88
100
  id
89
101
  });
90
102
  /** A staging row's ID: its `removeAt`, padded so the soonest sorts first, then its own. */
91
103
  const stagingId = (removeAt, id) => `${String(removeAt).padStart(16, "0")}.${id}`;
92
104
  const lockRead = (id) => ({
93
- collection: collections.lfsLocks,
105
+ collection: lfsCollections.locks,
94
106
  id
95
107
  });
96
108
  const stagingRead = (id) => ({
97
- collection: collections.lfsStaging,
109
+ collection: lfsCollections.staging,
98
110
  id
99
111
  });
100
112
  const listedRead = (oid) => ({
101
- collection: collections.lfsObjects,
113
+ collection: lfsCollections.objects,
102
114
  id: oid
103
115
  });
104
116
  const uploadRead = (oid) => ({
105
- collection: collections.lfsUploads,
117
+ collection: lfsCollections.uploads,
106
118
  id: oid
107
119
  });
108
- export { EndingRow, ListedRow, LockRow, StagingRow, UploadRow, endingKey, largestObject, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead };
120
+ export { EndingRow, ListedRow, LockRow, StagingRow, UploadRow, endingKey, largestObject, lfsCollections, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead };
@@ -1,9 +1,14 @@
1
- import "../contracts/promises.mjs";
2
1
  import { LfsFeature } from "../contracts/lfs.mjs";
3
- import "../contracts/result.mjs";
2
+ import { GitError } from "../contracts/result.mjs";
4
3
  import "../core/parts.mjs";
5
- import "./objects.mjs";
6
- import "effect/Effect";
4
+ import { LfsCall } from "./objects.mjs";
5
+ import * as Effect from "effect/Effect";
7
6
  import "effect/Context";
7
+ /** A request under a repo's `info/lfs/`: `route` is the rest of its path, as `objects/batch`. */
8
+ export interface LfsRoute extends LfsCall {
9
+ readonly route: string;
10
+ }
11
+ /** Git LFS's API for a server's repos, its objects in `bucket`. */
12
+ export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
8
13
  /** Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. */
9
14
  export declare const lfs: () => LfsFeature;
@@ -1,23 +1,14 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
- import { CoreParts } from "../core/parts.mjs";
3
2
  import { createLock, listLocks, unlock, verifyLocks } from "./locks.mjs";
4
- import { batch, receive, send, signingOf, verify } from "./objects.mjs";
3
+ import { batch, receive, send, verify } from "./objects.mjs";
5
4
  import { lfsAnswer } from "./wire.mjs";
6
5
  import * as Effect from "effect/Effect";
7
6
  // src/lfs/service.ts
8
7
  /** Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. */
9
8
  const lfs = () => ({ kind: "lfs" });
10
9
  const methodNotAllowed = (allow) => Effect.succeed(lfsAnswer(405, { message: "Method not allowed" }, { allow }));
11
- /** LFS's routes over `needs`, the server's services, its objects in `bucket`. */
12
- const lfsService = (needs, bucket) => {
13
- const signed = signingOf(bucket);
14
- const routed = (call) => Effect.flatMap(Effect.service(CoreParts), (core) => served({
15
- core,
16
- bucket,
17
- signed
18
- }, call));
19
- return (call) => Effect.provideContext(routed(call), needs);
20
- };
10
+ /** LFS's routes over `parts`, provided `needs`, the server's services, which `openRepo` reads. */
11
+ const lfsService = (needs, parts) => (call) => Effect.provideContext(served(parts, call), needs);
21
12
  /** `call`'s answer, by its route and method. */
22
13
  const served = (parts, call) => {
23
14
  const { route } = call;
@@ -1,8 +1,6 @@
1
- import { bucketCall } from "../storage/calls.mjs";
2
- import { decodeRow, storeCall } from "../store/errors.mjs";
3
- import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
4
- import { signingOf } from "./objects.mjs";
5
- import { EndingRow, StagingRow, UploadRow, endingKey, listedRead, objectKey, uploadKey, uploadRead } from "./rows.mjs";
1
+ import { bucketDo } from "../storage/calls.mjs";
2
+ import { decodeRow } from "../store/errors.mjs";
3
+ import { EndingRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey, uploadKey, uploadRead } from "./rows.mjs";
6
4
  import * as Effect from "effect/Effect";
7
5
  // src/lfs/upkeep.ts
8
6
  /**
@@ -18,17 +16,17 @@ import * as Effect from "effect/Effect";
18
16
  */
19
17
  /** The most rows of each kind a step ends. */
20
18
  const upkeepPage = 500;
21
- /** Upkeep over `bucket`'s LFS objects, for `repackJob`'s `upkeep`. */
22
- const lfsUpkeep = (bucket) => {
23
- const signed = signingOf(bucket) !== void 0;
24
- return (store, repo, at) => upkeepStep({
25
- store,
26
- bucket,
27
- signed,
28
- repo,
29
- at
30
- });
31
- };
19
+ /**
20
+ * LFS's claim's upkeep over its `rows` and `bucket`'s objects: `bucket` charges each call, and
21
+ * `signed` says the host signs LFS's links, so its uploads have upload rows to end.
22
+ */
23
+ const lfsUpkeep = (rows, bucket, signed) => ({ repo, at }) => upkeepStep({
24
+ rows,
25
+ bucket,
26
+ signed,
27
+ repo,
28
+ at
29
+ });
32
30
  const did = { more: true };
33
31
  const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
34
32
  /**
@@ -36,14 +34,13 @@ const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
36
34
  * and answers `more`; with nothing due, it answers when the soonest row is.
37
35
  */
38
36
  const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
39
- const scope = repoScope(upkeep.repo);
40
- const snapshot = yield* storeCall(() => upkeep.store.read(scope, [{
41
- collection: collections.lfsEnding,
37
+ const snapshot = yield* upkeep.rows.read(upkeep.repo, [{
38
+ collection: lfsCollections.ending,
42
39
  limit: upkeepPage
43
40
  }, {
44
- collection: collections.lfsStaging,
41
+ collection: lfsCollections.staging,
45
42
  limit: upkeepPage
46
- }]));
43
+ }]);
47
44
  const [ending = [], staging = []] = snapshot.results;
48
45
  const endings = yield* Effect.forEach(ending, (row) => Effect.map(decodeRow(EndingRow, row, `LFS ending row ${row.id}`), (decoded) => ({
49
46
  id: row.id,
@@ -66,51 +63,42 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
66
63
  });
67
64
  /** Deletes each ending row's key, then the row, at `version`. */
68
65
  const endObjects = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version, rows) {
69
- yield* Effect.forEach(rows, (row) => bucketCall((signal) => upkeep.bucket.delete(row.key, { signal })), {
66
+ yield* Effect.forEach(rows, (row) => bucketDo(upkeep.bucket.remove(row.key)), {
70
67
  concurrency: 8,
71
68
  discard: true
72
69
  });
73
- yield* storeCall(() => upkeep.store.commit(repoScope(upkeep.repo), {
74
- id: newChangeId(),
75
- expect: version,
76
- delete: rows.map((row) => ({
77
- collection: collections.lfsEnding,
78
- id: row.id
79
- }))
80
- }));
70
+ yield* upkeep.rows.commit(upkeep.repo, version, { delete: rows.map((row) => ({
71
+ collection: lfsCollections.ending,
72
+ id: row.id
73
+ })) });
81
74
  return did;
82
75
  });
83
76
  /** Deletes each due staging key, then its row, at `version`. */
84
77
  const endStages = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version, stages) {
85
- yield* Effect.forEach(stages, (stage) => bucketCall((signal) => upkeep.bucket.delete(stage.key, { signal })), {
78
+ yield* Effect.forEach(stages, (stage) => bucketDo(upkeep.bucket.remove(stage.key)), {
86
79
  concurrency: 8,
87
80
  discard: true
88
81
  });
89
- yield* storeCall(() => upkeep.store.commit(repoScope(upkeep.repo), {
90
- id: newChangeId(),
91
- expect: version,
92
- delete: stages.map((stage) => ({
93
- collection: collections.lfsStaging,
94
- id: stage.id
95
- }))
96
- }));
82
+ yield* upkeep.rows.commit(upkeep.repo, version, { delete: stages.map((stage) => ({
83
+ collection: lfsCollections.staging,
84
+ id: stage.id
85
+ })) });
97
86
  return did;
98
87
  });
99
88
  /** Up to a page of the upload rows that are due, and when the soonest of the rest is. */
100
89
  const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
101
- const scope = repoScope(upkeep.repo);
102
90
  const oids = [];
103
91
  let next;
104
92
  let after;
105
93
  for (;;) {
106
94
  const read = {
107
- collection: collections.lfsUploads,
95
+ collection: lfsCollections.uploads,
108
96
  limit: upkeepPage
109
97
  };
110
- const rows = (yield* storeCall(() => upkeep.store.read(scope, [after === void 0 ? read : {
98
+ const rows = (yield* upkeep.rows.read(upkeep.repo, [after === void 0 ? read : {
111
99
  ...read,
112
100
  after
113
- }]))).results[0] ?? [];
101
+ }])).results[0] ?? [];
114
102
  for (const row of rows) {
115
103
  const upload = yield* uploadOf(row);
116
104
  if (upload.removeAt > upkeep.at) next = earliest(next, upload.removeAt);
@@ -130,8 +118,7 @@ const uploadOf = (row) => decodeRow(UploadRow, row, `LFS object ${row.id}'s uplo
130
118
  * staging keys, which their own rows end.
131
119
  */
132
120
  const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, oids) {
133
- const scope = repoScope(upkeep.repo);
134
- const snapshot = yield* storeCall(() => upkeep.store.read(scope, oids.flatMap((oid) => [uploadRead(oid), listedRead(oid)])));
121
+ const snapshot = yield* upkeep.rows.read(upkeep.repo, oids.flatMap((oid) => [uploadRead(oid), listedRead(oid)]));
135
122
  const dropped = [];
136
123
  const ended = [];
137
124
  for (const [index, oid] of oids.entries()) {
@@ -146,16 +133,14 @@ const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, oids) {
146
133
  });
147
134
  }
148
135
  if (dropped.length === 0) return did;
149
- const committed = yield* storeCall(() => upkeep.store.commit(scope, {
150
- id: newChangeId(),
151
- expect: snapshot.version,
136
+ const committed = yield* upkeep.rows.commit(upkeep.repo, snapshot.version, {
152
137
  put: ended.map(({ collection, id, key }) => ({
153
138
  collection,
154
139
  id,
155
140
  value: { key }
156
141
  })),
157
142
  delete: dropped.map(uploadKey)
158
- }));
143
+ });
159
144
  if (!committed.ok || ended.length === 0) return did;
160
145
  return yield* endObjects(upkeep, committed.version, ended);
161
146
  });
package/dist/node.d.mts CHANGED
@@ -1,2 +1,3 @@
1
- import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse, toNodeHandler, toNodeMiddleware } from "./http/node.mjs";
2
- export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
1
+ import { NodeAnswerer, toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
2
+ import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse } from "./http/node.mjs";
3
+ export { type NodeAnswerer, type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
package/dist/node.mjs CHANGED
@@ -1 +1 @@
1
- export { toNodeHandler, toNodeMiddleware } from "./http/node.mjs";
1
+ export { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
@@ -1,5 +1,6 @@
1
1
  import { Oid } from "../../contracts/ids.mjs";
2
2
  import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
3
+ import "./lines.mjs";
3
4
  import { PushLimits } from "./push-limits.mjs";
4
5
  import * as Schema from "effect/Schema";
5
6
  import * as Effect from "effect/Effect";
@@ -51,17 +52,10 @@ export declare const receivePackCapabilities: (agent: string, offers?: {
51
52
  }) => string[];
52
53
  /**
53
54
  * `info/refs` for `service` in v0, as `git http-backend` answers it: the service line and a
54
- * flush, then `served`'s refs with `capabilities` on the first. A ref or a capability that would
55
- * break its line is refused.
55
+ * flush, then `served`'s refs with `capabilities` on the first, never one under Git's own
56
+ * `refs/import/`. A ref or a capability that would break its line is refused.
56
57
  */
57
- export declare const encodeAdvertisement: (service: GitService, served: {
58
- readonly head?: string;
59
- readonly refs: readonly {
60
- readonly name: string;
61
- readonly oid: string;
62
- readonly peeled?: string;
63
- }[];
64
- }, capabilities: readonly string[]) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError, never>;
58
+ export declare const encodeAdvertisement: (service: GitService, served: ServedRefs, capabilities: ReadonlyArray<string>) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError>;
65
59
  /** What a client reads of a source's advertisement: the refs it keeps, and the branch `HEAD` names. */
66
60
  export type SourceRefs = {
67
61
  readonly kind: 'read';
@@ -2,7 +2,7 @@ import { Oid } from "../../contracts/ids.mjs";
2
2
  import { joinedBytes } from "../bytes/joined.mjs";
3
3
  import { isOid, quoted } from "../bytes/text.mjs";
4
4
  import { pktText, readPkt } from "../framing/pkt-line.mjs";
5
- import { byName, decoded, encodeErr, isWord, listsRef, refusedText, textLines, unwritable } from "./lines.mjs";
5
+ import { byName, decoded, encodeErr, gitsOwnRefs, isWord, listsRef, refusedText, textLines, unwritable } from "./lines.mjs";
6
6
  import { pushLimitOffers } from "./push-limits.mjs";
7
7
  import { pushUploadOffer } from "./push-uploads.mjs";
8
8
  import * as Schema from "effect/Schema";
@@ -81,22 +81,26 @@ const receivePackCapabilities = (agent, offers = {}) => [
81
81
  ...offers.uploadAbove === void 0 ? [] : [pushUploadOffer(offers.uploadAbove)],
82
82
  ...pushLimitOffers(offers.limits ?? {})
83
83
  ];
84
- /** The refs v0 lists, by Git's order: never one under a `hiddenRefs` prefix. */
85
- const listed = (served) => served.refs.filter((ref) => listsRef(ref.name, [])).toSorted((a, b) => byName(a.name, b.name));
86
84
  /**
87
- * `info/refs` for `service` in v0, as `git http-backend` answers it: the service line and a
88
- * flush, then `served`'s refs with `capabilities` on the first. A ref or a capability that would
89
- * break its line is refused.
85
+ * `info/refs` for `service` in v0, as `encodeAdvertisement` writes it, with none of the refs under
86
+ * `table`'s prefixes: a server's own, its registered prefixes among them.
90
87
  */
91
- const encodeAdvertisement = /* @__PURE__ */ Effect.fnUntraced(function* (service, served, capabilities) {
88
+ const advertisementOf = /* @__PURE__ */ Effect.fnUntraced(function* (service, served, capabilities, table) {
92
89
  const head = headOf(served);
93
- const lines = advertisementPages(service, service === "git-upload-pack" && head !== void 0 ? { headRef: head } : {}, capabilities);
90
+ const lines = advertisementPages(service, service === "git-upload-pack" && head !== void 0 ? { headRef: head } : {}, capabilities, table);
91
+ const refs = served.refs.toSorted((a, b) => byName(a.name, b.name));
94
92
  return joinedBytes([
95
93
  yield* lines.start,
96
- yield* lines.page(listed(served)),
94
+ yield* lines.page(refs),
97
95
  yield* lines.end
98
96
  ]);
99
97
  });
98
+ /**
99
+ * `info/refs` for `service` in v0, as `git http-backend` answers it: the service line and a
100
+ * flush, then `served`'s refs with `capabilities` on the first, never one under Git's own
101
+ * `refs/import/`. A ref or a capability that would break its line is refused.
102
+ */
103
+ const encodeAdvertisement = (service, served, capabilities) => advertisementOf(service, served, capabilities, gitsOwnRefs);
100
104
  /** `served`'s view of a streamed listing's head, for what reads `HEAD` from its refs. */
101
105
  const servedHead = (listed) => {
102
106
  const refs = listed.headRef === void 0 ? [] : [listed.headRef];
@@ -115,7 +119,7 @@ const onLines = (what, texts) => {
115
119
  * each page's refs, `capabilities` on the first line written, each tag's peel after it for
116
120
  * `git-upload-pack`, and a ref-less line for the capabilities when no ref came, then the flush.
117
121
  */
118
- const advertisementPages = (service, listed, capabilities) => {
122
+ const advertisementPages = (service, listed, capabilities, table) => {
119
123
  const uploading = service === "git-upload-pack";
120
124
  const caps = capabilities.join(" ");
121
125
  let first = true;
@@ -132,7 +136,7 @@ const advertisementPages = (service, listed, capabilities) => {
132
136
  return {
133
137
  start: Effect.andThen(onLines("advertisement", capabilities), () => Effect.map(Effect.all([serviceLine, textLines(lines(head), false)]), joinedBytes)),
134
138
  page: (refs) => {
135
- const shown = refs.filter((ref) => listsRef(ref.name, []));
139
+ const shown = refs.filter((ref) => listsRef(table, ref.name, []));
136
140
  return Effect.andThen(onLines("advertisement", shown.map((ref) => ref.name)), () => textLines(lines(shown), false));
137
141
  },
138
142
  end: Effect.suspend(() => textLines(first ? [`${zero} capabilities^{}\0${caps}\n`] : [], true))
@@ -254,4 +258,4 @@ const advertisedLines = (bytes) => decoded("advertisement", () => {
254
258
  const advertisedHead = (bytes) => Effect.map(advertisedLines(bytes), (lines) => lines.find((line) => line.name === "HEAD")?.id);
255
259
  /** Every ref advertised, by name, each at its own object: an annotated tag's is the tag's. */
256
260
  const advertisedRefs = (bytes) => Effect.map(advertisedLines(bytes), (lines) => new Map(lines.filter((line) => line.name.startsWith("refs/") && !line.name.endsWith("^{}")).map((line) => [line.name, line.id])));
257
- export { AdvertisedRef, ServedRefs, advertisedHead, advertisedRefs, advertisedSource, advertisementPages, encodeAdvertisement, encodeRefusedAdvertisement, headOf, pastServiceLine, receivePackCapabilities, servedHead, uploadPackCapabilities };
261
+ export { AdvertisedRef, ServedRefs, advertisedHead, advertisedRefs, advertisedSource, advertisementOf, advertisementPages, encodeAdvertisement, encodeRefusedAdvertisement, headOf, pastServiceLine, receivePackCapabilities, servedHead, uploadPackCapabilities };
@@ -1,5 +1,5 @@
1
1
  import { WireEncodeError } from "../bytes/errors.mjs";
2
- import "../../contracts/refs.mjs";
2
+ import { RefOwner } from "../../contracts/git.mjs";
3
3
  import * as Effect from "effect/Effect";
4
4
  import "effect/Result";
5
5
  /**
@@ -7,4 +7,16 @@ import "effect/Result";
7
7
  * alike. It ends without a newline, as `gitprotocol-pack`'s `error-line` does and Git writes it. A
8
8
  * message holding a newline is refused, since the line would end early.
9
9
  */
10
- export declare const encodeErr: (message: string) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError>;
10
+ export declare const encodeErr: (message: string) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError>;
11
+ /**
12
+ * A prefix whose refs are Git's own: only `owner`, the claim that registered it or an import,
13
+ * moves one, and no push or API call does. v0 never advertises them. v2's `ls-refs`, and
14
+ * `refs.list`, list one only for an asked prefix under it when `underPrefix` is `listed`, and never
15
+ * when it's `hidden`, nor does a fetch reach a commit only a `hidden` one holds.
16
+ */
17
+ export interface HiddenRefs {
18
+ readonly owner: RefOwner;
19
+ readonly underPrefix: 'listed' | 'hidden';
20
+ /** Who moves them, as a refusal says it. */
21
+ readonly mover: string;
22
+ }
@@ -79,43 +79,54 @@ function byName(a, b) {
79
79
  }
80
80
  /** Whether a line can hold `text` as one word: no NUL, newline or space to end it early. */
81
81
  const isWord = (text) => !/[\0\n ]/.test(text);
82
- /** Where a host's queue keeps its open entries, and where an import stages what it publishes. */
83
- const hiddenRefs = [{
84
- prefix: "refs/queue/",
85
- owner: "queue",
86
- underPrefix: "listed",
87
- mover: "the merge queue"
88
- }, {
82
+ /** An import's owner: where it stages what it publishes, which only sync's writes move. */
83
+ const importOwner = Object.freeze({
89
84
  prefix: "refs/import/",
90
- owner: "import",
85
+ owner: "import"
86
+ });
87
+ /**
88
+ * Git's own rows, beside each registered prefix's, which a server's registry adds at its seal: a
89
+ * client's table, and the one this module's public encoders read.
90
+ */
91
+ const gitsOwnRefs = [{
92
+ owner: importOwner,
91
93
  underPrefix: "hidden",
92
94
  mover: "an import"
93
95
  }];
94
- /** The hidden prefix `name` is under, if any. */
95
- const hiddenUnder = (name) => hiddenRefs.find((hidden) => name.startsWith(hidden.prefix));
96
96
  /**
97
- * Whether `ref` is Git's own and `source` its owner, the queue or an import: a move of it by that
98
- * owner no rule, hook, `ref.updated` or index update sees, and that owner's view sees it.
97
+ * A registered prefix's row, as the registry adds it for a claim with `refs`: listed for a prefix
98
+ * under it, and moved only by the claim, which a refusal names.
99
+ */
100
+ const registeredRow = (owner) => ({
101
+ owner,
102
+ underPrefix: "listed",
103
+ mover: `the ${owner.owner} feature`
104
+ });
105
+ /** `table`'s hidden prefix `name` is under, if any. */
106
+ const hiddenUnder = (table, name) => table.find((hidden) => name.startsWith(hidden.owner.prefix));
107
+ /**
108
+ * Whether `ref` is Git's own and `as` its owner, the very one the registry made or `importOwner`:
109
+ * a move of it no rule, hook, `ref.updated` or index update sees, and that owner's view sees it.
99
110
  */
100
- const gitsOwnMove = (source, ref) => hiddenUnder(ref)?.owner === source;
111
+ const gitsOwnMove = (table, as, ref) => as !== void 0 && hiddenUnder(table, ref)?.owner === as;
101
112
  /**
102
113
  * Whether a host's own listing for `prefix` shows `name`, as `refs.list` does: a ref under a
103
114
  * hidden prefix only for a prefix under it, of either kind, since the host's code asks for it.
104
115
  */
105
- const hostLists = (name, prefix) => {
106
- const hidden = hiddenUnder(name);
107
- return hidden === void 0 || prefix !== void 0 && prefix.startsWith(hidden.prefix);
116
+ const hostLists = (table, name, prefix) => {
117
+ const hidden = hiddenUnder(table, name);
118
+ return hidden === void 0 || prefix !== void 0 && prefix.startsWith(hidden.owner.prefix);
108
119
  };
109
120
  /** Whether a fetch reaches what `name` holds: every ref but one whose prefix is `hidden`. */
110
- const fetchReaches = (name) => hiddenUnder(name)?.underPrefix !== "hidden";
121
+ const fetchReaches = (table, name) => hiddenUnder(table, name)?.underPrefix !== "hidden";
111
122
  /**
112
123
  * Whether a client's listing for `prefixes` shows `name`: every ref not under a hidden prefix when there
113
124
  * are none, and otherwise those that start with one, a hidden one only for a prefix under it whose
114
125
  * refs are `listed`.
115
126
  */
116
- const listsRef = (name, prefixes) => {
117
- const hidden = hiddenUnder(name);
127
+ const listsRef = (table, name, prefixes) => {
128
+ const hidden = hiddenUnder(table, name);
118
129
  if (prefixes.length === 0) return hidden === void 0;
119
- return prefixes.some((prefix) => name.startsWith(prefix) && (hidden === void 0 || hidden.underPrefix === "listed" && prefix.startsWith(hidden.prefix)));
130
+ return prefixes.some((prefix) => name.startsWith(prefix) && (hidden === void 0 || hidden.underPrefix === "listed" && prefix.startsWith(hidden.owner.prefix)));
120
131
  };
121
- export { byName, decoded, encodeErr, fetchReaches, gitsOwnMove, hiddenRefs, hiddenUnder, hostLists, isWord, listsRef, readSection, refusedText, textLines, unwritable };
132
+ export { byName, decoded, encodeErr, fetchReaches, gitsOwnMove, gitsOwnRefs, hiddenUnder, hostLists, importOwner, isWord, listsRef, readSection, refusedText, registeredRow, textLines, unwritable };
@@ -1,5 +1,6 @@
1
1
  import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
2
- import "./advertisement.mjs";
2
+ import { ServedRefs } from "./advertisement.mjs";
3
+ import "./lines.mjs";
3
4
  import * as Schema from "effect/Schema";
4
5
  import * as Effect from "effect/Effect";
5
6
  /**
@@ -52,21 +53,9 @@ export declare const readLsRefs: (request: V2Request) => Effect.Effect<LsRefs, W
52
53
  * `ls-refs`'s answer, as Git's: `HEAD` first when it resolves, or `unborn HEAD` when it doesn't
53
54
  * and both `unborn` and `symrefs` were asked, then each listed ref in Git's order, each line
54
55
  * `<oid> <name>`, with `symref-target:` for `HEAD` and `peeled:` for an annotated tag as asked,
55
- * then a flush.
56
+ * then a flush. It hides only Git's own `refs/import/`: a server hides each claim's prefix too.
56
57
  */
57
- export declare const encodeLsRefs: (served: {
58
- readonly head?: string;
59
- readonly refs: readonly {
60
- readonly name: string;
61
- readonly oid: string;
62
- readonly peeled?: string;
63
- }[];
64
- }, asked: {
65
- readonly peel: boolean;
66
- readonly symrefs: boolean;
67
- readonly unborn: boolean;
68
- readonly prefixes: readonly string[];
69
- }) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError, never>;
58
+ export declare const encodeLsRefs: (served: ServedRefs, asked: LsRefs) => Effect.Effect<Uint8Array<ArrayBuffer>, WireEncodeError>;
70
59
  /**
71
60
  * What a v2 `info/refs` answer says: `v2` with its capabilities when it starts `version 2`, as a
72
61
  * server that speaks v2 answers a client that asked for it, else `v0`, an advertisement of refs.