@ref0/git 0.11.0 → 0.14.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 (262) hide show
  1. package/dist/access/private-refs.mjs +8 -7
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +14 -3
  28. package/dist/contracts/git.d.mts +41 -12
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +30 -23
  42. package/dist/contracts/result.mjs +24 -9
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +90 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.d.mts +1 -0
  54. package/dist/core/access.mjs +34 -13
  55. package/dist/core/ancestry.d.mts +9 -0
  56. package/dist/core/ancestry.mjs +6 -6
  57. package/dist/core/asked.mjs +68 -0
  58. package/dist/core/call-names.mjs +1 -0
  59. package/dist/core/call-services.mjs +2 -1
  60. package/dist/core/events/deliver.d.mts +1 -0
  61. package/dist/core/events/deliver.mjs +15 -3
  62. package/dist/core/forks.mjs +42 -16
  63. package/dist/core/imports.mjs +156 -13
  64. package/dist/core/index-job.mjs +9 -6
  65. package/dist/core/job-view.mjs +8 -9
  66. package/dist/core/mirror-rows.mjs +19 -4
  67. package/dist/core/objects/commits.mjs +16 -6
  68. package/dist/core/objects/reading.mjs +17 -9
  69. package/dist/core/parts.d.mts +8 -2
  70. package/dist/core/parts.mjs +1 -4
  71. package/dist/core/purge.mjs +76 -6
  72. package/dist/core/push-decide.mjs +1 -1
  73. package/dist/core/push-files.d.mts +12 -0
  74. package/dist/core/push-files.mjs +225 -0
  75. package/dist/core/push-repo.d.mts +8 -0
  76. package/dist/core/push-repo.mjs +56 -0
  77. package/dist/core/push.d.mts +17 -0
  78. package/dist/core/push.mjs +107 -32
  79. package/dist/core/receipts.mjs +26 -10
  80. package/dist/core/ref-view.mjs +59 -5
  81. package/dist/core/refs.mjs +18 -10
  82. package/dist/core/registered-rows.mjs +7 -5
  83. package/dist/core/repack.mjs +16 -11
  84. package/dist/core/repo-info.mjs +16 -9
  85. package/dist/core/repos.mjs +30 -14
  86. package/dist/core/saved-caller-views.d.mts +18 -0
  87. package/dist/core/saved-caller-views.mjs +17 -4
  88. package/dist/core/saved-callers-public.d.mts +3 -3
  89. package/dist/core/saved-callers-public.mjs +3 -2
  90. package/dist/core/saved-callers.d.mts +7 -0
  91. package/dist/core/seam.mjs +2 -2
  92. package/dist/core/view.d.mts +6 -0
  93. package/dist/core/view.mjs +45 -12
  94. package/dist/core/work.mjs +47 -22
  95. package/dist/effect.d.mts +3 -1
  96. package/dist/effect.mjs +3 -1
  97. package/dist/engine/reads.mjs +13 -6
  98. package/dist/engine/walk.mjs +4 -4
  99. package/dist/event-streams/event-streams.d.mts +1 -1
  100. package/dist/event-streams/event-streams.mjs +1 -1
  101. package/dist/event-streams/stream.d.mts +1 -1
  102. package/dist/event-streams/stream.mjs +1 -1
  103. package/dist/extend.d.mts +4 -3
  104. package/dist/extend.mjs +3 -2
  105. package/dist/http/answers.mjs +4 -2
  106. package/dist/http/core-parts.mjs +64 -15
  107. package/dist/http/handler.mjs +2 -2
  108. package/dist/http/node.mjs +5 -4
  109. package/dist/http/parts.d.mts +1 -0
  110. package/dist/http/push-upload-job.mjs +503 -0
  111. package/dist/http/push-uploads.d.mts +1 -0
  112. package/dist/http/push-uploads.mjs +120 -59
  113. package/dist/http/upload-pack.mjs +7 -6
  114. package/dist/index.d.mts +23 -24
  115. package/dist/index.mjs +4 -7
  116. package/dist/lfs/base.d.mts +7 -3
  117. package/dist/lfs/base.mjs +2 -1
  118. package/dist/lfs/copy.d.mts +46 -0
  119. package/dist/lfs/copy.mjs +26 -0
  120. package/dist/lfs/layer.mjs +4 -2
  121. package/dist/lfs/locks.mjs +14 -9
  122. package/dist/lfs/objects.d.mts +6 -0
  123. package/dist/lfs/objects.mjs +95 -61
  124. package/dist/lfs/rows.d.mts +13 -0
  125. package/dist/lfs/service.d.mts +1 -7
  126. package/dist/lfs/service.mjs +1 -9
  127. package/dist/lfs/upload-most.mjs +5 -5
  128. package/dist/node.d.mts +2 -2
  129. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  130. package/dist/protocol/bytes/sha256.d.mts +32 -0
  131. package/dist/protocol/bytes/sha256.mjs +105 -49
  132. package/dist/protocol/wire/advertisement.mjs +9 -4
  133. package/dist/protocol/wire/lines.d.mts +4 -2
  134. package/dist/protocol/wire/lines.mjs +11 -5
  135. package/dist/protocol/wire/push-uploads.mjs +13 -1
  136. package/dist/protocol/wire/v2.mjs +2 -2
  137. package/dist/protocol.d.mts +3 -1
  138. package/dist/protocol.mjs +3 -1
  139. package/dist/queue/advance.mjs +1 -1
  140. package/dist/queue/calls.mjs +21 -1
  141. package/dist/queue/host.d.mts +1 -7
  142. package/dist/queue/host.mjs +1 -7
  143. package/dist/queue/layer.mjs +1 -1
  144. package/dist/queue/trim.mjs +1 -1
  145. package/dist/rest/blobs.d.mts +16 -8
  146. package/dist/rest/blobs.mjs +1 -1
  147. package/dist/rest/caller.d.mts +49 -9
  148. package/dist/rest/caller.mjs +1 -1
  149. package/dist/rest/client.d.mts +10 -3
  150. package/dist/rest/client.mjs +4 -0
  151. package/dist/rest/commits.d.mts +272 -239
  152. package/dist/rest/errors.d.mts +24 -4
  153. package/dist/rest/events.d.mts +9 -6
  154. package/dist/rest/events.mjs +1 -2
  155. package/dist/rest/files.d.mts +112 -100
  156. package/dist/rest/forks.d.mts +146 -122
  157. package/dist/rest/handler.mjs +4 -57
  158. package/dist/rest/handlers.d.mts +1 -1
  159. package/dist/rest/handlers.mjs +18 -4
  160. package/dist/rest/layer.mjs +10 -2
  161. package/dist/rest/me.d.mts +8 -4
  162. package/dist/rest/merges.d.mts +8 -4
  163. package/dist/rest/paths.mjs +1 -0
  164. package/dist/rest/queue.d.mts +292 -236
  165. package/dist/rest/refs.d.mts +98 -69
  166. package/dist/rest/repos.d.mts +133 -105
  167. package/dist/rest/tags.d.mts +100 -88
  168. package/dist/rest/tokens.d.mts +192 -168
  169. package/dist/rest/topics.d.mts +154 -134
  170. package/dist/rest/trees.d.mts +32 -16
  171. package/dist/rest/work.d.mts +467 -20
  172. package/dist/rest/work.mjs +8 -0
  173. package/dist/server/edge-node.d.mts +9 -13
  174. package/dist/server/edge-node.mjs +9 -12
  175. package/dist/server/git-layer.d.mts +1 -6
  176. package/dist/server/git-layer.mjs +2 -2
  177. package/dist/server/git-namespace.d.mts +4 -4
  178. package/dist/server/joined.d.mts +15 -22
  179. package/dist/server/joined.mjs +5 -29
  180. package/dist/server/lifecycle.mjs +107 -23
  181. package/dist/server/registry.mjs +9 -1
  182. package/dist/server/server.mjs +139 -216
  183. package/dist/storage/budget.mjs +2 -2
  184. package/dist/storage/clean-up.mjs +13 -10
  185. package/dist/storage/fetch.mjs +13 -8
  186. package/dist/storage/file-limits.mjs +24 -0
  187. package/dist/storage/index-build.d.mts +1 -0
  188. package/dist/storage/index-build.mjs +106 -62
  189. package/dist/storage/index-fetch.mjs +16 -3
  190. package/dist/storage/index-reach.mjs +33 -5
  191. package/dist/storage/index-remap.mjs +8 -1
  192. package/dist/storage/index-shallow.mjs +5 -3
  193. package/dist/storage/largest-files.mjs +48 -0
  194. package/dist/storage/lfs-pointers.mjs +10 -1
  195. package/dist/storage/loose.mjs +3 -1
  196. package/dist/storage/memory-budget.mjs +154 -8
  197. package/dist/storage/merge-cut.mjs +5 -4
  198. package/dist/storage/pack-reads.mjs +246 -34
  199. package/dist/storage/pack-receive.mjs +83 -25
  200. package/dist/storage/packs.mjs +37 -21
  201. package/dist/storage/prune-keep.mjs +203 -34
  202. package/dist/storage/prune-seen.mjs +11 -6
  203. package/dist/storage/prune-walk.mjs +219 -81
  204. package/dist/storage/prune.mjs +629 -196
  205. package/dist/storage/push-uploads.mjs +36 -12
  206. package/dist/storage/quarantine.mjs +9 -7
  207. package/dist/storage/ready.mjs +47 -19
  208. package/dist/storage/receive-bounds.mjs +29 -8
  209. package/dist/storage/receive-state.mjs +8 -0
  210. package/dist/storage/receive-steps.mjs +71 -18
  211. package/dist/storage/repack.d.mts +1 -1
  212. package/dist/storage/repack.mjs +1 -8
  213. package/dist/storage/rows.mjs +12 -1
  214. package/dist/storage/shallow.d.mts +1 -0
  215. package/dist/storage/shallow.mjs +26 -4
  216. package/dist/storage/stream-whole.mjs +5 -2
  217. package/dist/storage/visible.mjs +29 -1
  218. package/dist/storage/walk.mjs +2 -1
  219. package/dist/store/catalogue.mjs +1 -0
  220. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  221. package/dist/store/cursor-seal-public.d.mts +5 -0
  222. package/dist/store/cursor-seal-public.mjs +5 -0
  223. package/dist/store/cursor-seal.d.mts +16 -2
  224. package/dist/store/cursor-seal.mjs +26 -14
  225. package/dist/store/errors.mjs +9 -1
  226. package/dist/store/records.d.mts +2 -0
  227. package/dist/store/records.mjs +9 -6
  228. package/dist/store/repo-record.d.mts +27 -0
  229. package/dist/store/repo-record.mjs +141 -4
  230. package/dist/store/scopes.mjs +10 -2
  231. package/dist/sync/bound.d.mts +2 -0
  232. package/dist/sync/bound.mjs +11 -2
  233. package/dist/sync/github.d.mts +6 -1
  234. package/dist/sync/github.mjs +63 -42
  235. package/dist/sync/http.mjs +36 -1
  236. package/dist/sync/import.mjs +4 -2
  237. package/dist/sync/layer.mjs +6 -2
  238. package/dist/sync/lfs-batch.mjs +119 -0
  239. package/dist/sync/lfs-copy.mjs +251 -0
  240. package/dist/sync/mirror.mjs +227 -147
  241. package/dist/sync/said.mjs +204 -0
  242. package/dist/sync/smart-http.mjs +4 -2
  243. package/dist/sync/step.mjs +33 -13
  244. package/dist/sync/tries.mjs +71 -24
  245. package/dist/sync.d.mts +2 -2
  246. package/dist/topics/advance.mjs +10 -3
  247. package/dist/topics/host.mjs +1 -19
  248. package/dist/topics/layer.mjs +1 -1
  249. package/package.json +3 -8
  250. package/dist/auth/bridge.mjs +0 -30
  251. package/dist/auth/helpers.d.mts +0 -17
  252. package/dist/core/purge.d.mts +0 -8
  253. package/dist/core/registered-rows.d.mts +0 -4
  254. package/dist/core/repack.d.mts +0 -11
  255. package/dist/http/handler.d.mts +0 -2
  256. package/dist/rest/handler.d.mts +0 -21
  257. package/dist/rest.d.mts +0 -2
  258. package/dist/rest.mjs +0 -1
  259. package/dist/server/registry.d.mts +0 -16
  260. package/dist/server/server.d.mts +0 -36
  261. package/dist/storage/repack-job.d.mts +0 -3
  262. package/dist/topics/host.d.mts +0 -7
@@ -16,6 +16,14 @@ var WorkApiGroup = class extends HttpApiGroup.make("work").add(HttpApiEndpoint.g
16
16
  },
17
17
  success: Listing(WorkItem),
18
18
  error: GitErrors
19
+ }), HttpApiEndpoint.get("listById", "/work/:internalId", {
20
+ params: { internalId: Schema.String.annotate({ description: "A repo's internal ID, `r_<id>`, as its scope and its packs' markers name it" }) },
21
+ query: {
22
+ state: Schema.optionalKey(JobState),
23
+ ...PageQuery
24
+ },
25
+ success: Listing(WorkItem),
26
+ error: GitErrors
19
27
  }), HttpApiEndpoint.post("retry", "/repos/:repo/-/work/retry", {
20
28
  params: RepoParam,
21
29
  payload: WorkWrite,
@@ -1,20 +1,16 @@
1
1
  import { Git } from "../contracts/git.mjs";
2
- import { GitServer } from "../contracts/server.mjs";
3
2
  import { NodeHandler, NodeMiddleware } from "../http/node.mjs";
4
3
  import * as ManagedRuntime from "effect/ManagedRuntime";
5
4
  /**
6
- * What a Node host answers with: its runtime over `Git.layer`, or a `{ fetch }`, such as a server
7
- * `createGitServer` made, until 2c-3b removes that form.
5
+ * A runtime over `Git.layer` as a `node:http` or `node:http2` listener or an Express route:
6
+ * `createServer(toNodeHandler(runtime))`. The runtime is the host's, made once a process with
7
+ * `ManagedRuntime.make(Git.layer(options, features).pipe(Layer.provide(adapter)))`, as
8
+ * docs/deploy/node.md's "Stores" builds it. Each request is answered through `Git.toFetch`, so a
9
+ * failed build answers `UNAVAILABLE` here too.
8
10
  */
9
- export type NodeAnswerer = Pick<GitServer, 'fetch'> | ManagedRuntime.ManagedRuntime<Git, unknown>;
11
+ export declare const toNodeHandler: (runtime: ManagedRuntime.ManagedRuntime<Git, unknown>) => NodeHandler;
10
12
  /**
11
- * A runtime over `Git.layer`, a Git server, or any `fetch`, as a `node:http` or `node:http2`
12
- * listener or an Express route: `createServer(toNodeHandler(runtime))`, as `http/node.ts`'s
13
- * `toNodeHandler` answers a `fetch`.
13
+ * A runtime over `Git.layer` beside an app's own routes, as an Express middleware: it answers the
14
+ * paths `pathOf` names through `Git.toFetch`, and calls `next` for every other.
14
15
  */
15
- export declare const toNodeHandler: (answerer: NodeAnswerer) => NodeHandler;
16
- /**
17
- * A runtime over `Git.layer`, a Git server, or any `fetch`, beside an app's own routes, as an
18
- * Express middleware, as `http/node.ts`'s `toNodeMiddleware` answers a `fetch`.
19
- */
20
- export declare const toNodeMiddleware: (answerer: NodeAnswerer, pathOf: (url: URL) => string | undefined) => NodeMiddleware;
16
+ export declare const toNodeMiddleware: (runtime: ManagedRuntime.ManagedRuntime<Git, unknown>, pathOf: (url: URL) => string | undefined) => NodeMiddleware;
@@ -1,20 +1,17 @@
1
1
  import { toNodeHandler as toNodeHandler$1, toNodeMiddleware as toNodeMiddleware$1 } from "../http/node.mjs";
2
2
  import { toFetch } from "./edge.mjs";
3
- import * as ManagedRuntime from "effect/ManagedRuntime";
4
3
  // src/server/edge-node.ts
5
- /** Whether `answerer` is a runtime, as `NodeAnswerer` holds only runtimes over `Git`. */
6
- const isRuntime = (answerer) => ManagedRuntime.isManagedRuntime(answerer);
7
- /** A runtime answered through `Git.toFetch`, so a failed build answers `UNAVAILABLE` here too. */
8
- const fetchOf = (answerer) => isRuntime(answerer) ? { fetch: toFetch(answerer) } : answerer;
9
4
  /**
10
- * A runtime over `Git.layer`, a Git server, or any `fetch`, as a `node:http` or `node:http2`
11
- * listener or an Express route: `createServer(toNodeHandler(runtime))`, as `http/node.ts`'s
12
- * `toNodeHandler` answers a `fetch`.
5
+ * A runtime over `Git.layer` as a `node:http` or `node:http2` listener or an Express route:
6
+ * `createServer(toNodeHandler(runtime))`. The runtime is the host's, made once a process with
7
+ * `ManagedRuntime.make(Git.layer(options, features).pipe(Layer.provide(adapter)))`, as
8
+ * docs/deploy/node.md's "Stores" builds it. Each request is answered through `Git.toFetch`, so a
9
+ * failed build answers `UNAVAILABLE` here too.
13
10
  */
14
- const toNodeHandler = (answerer) => toNodeHandler$1(fetchOf(answerer));
11
+ const toNodeHandler = (runtime) => toNodeHandler$1({ fetch: toFetch(runtime) });
15
12
  /**
16
- * A runtime over `Git.layer`, a Git server, or any `fetch`, beside an app's own routes, as an
17
- * Express middleware, as `http/node.ts`'s `toNodeMiddleware` answers a `fetch`.
13
+ * A runtime over `Git.layer` beside an app's own routes, as an Express middleware: it answers the
14
+ * paths `pathOf` names through `Git.toFetch`, and calls `next` for every other.
18
15
  */
19
- const toNodeMiddleware = (answerer, pathOf) => toNodeMiddleware$1(fetchOf(answerer), pathOf);
16
+ const toNodeMiddleware = (runtime, pathOf) => toNodeMiddleware$1({ fetch: toFetch(runtime) }, pathOf);
20
17
  export { toNodeHandler, toNodeMiddleware };
@@ -8,7 +8,7 @@ import { PushUploadOptions } from "../contracts/push-uploads.mjs";
8
8
  import { Refs } from "../contracts/refs.mjs";
9
9
  import { RepoRecords } from "../contracts/repo-records.mjs";
10
10
  import { GitError } from "../contracts/result.mjs";
11
- import { CallServices, GitNeeds, GitServerOptions } from "../contracts/server.mjs";
11
+ import { CallServices, GitNeeds, GitOptions } from "../contracts/server.mjs";
12
12
  import { Objects, Storage } from "../core/objects/objects.mjs";
13
13
  import { ServerSeam } from "../core/seam.mjs";
14
14
  import { LfsBase } from "../lfs/base.mjs";
@@ -21,11 +21,6 @@ import { JoinedCalls } from "./joined.mjs";
21
21
  import { UploadsBase } from "./uploads.mjs";
22
22
  import { BucketUploads } from "@ref0/infra";
23
23
  import * as Layer from "effect/Layer";
24
- /**
25
- * `Git.layer`'s options: settings only (Q834, Q1006), with a platform's `maxDuration` (Q1190). Push
26
- * uploads are `Git.layerUploads`'.
27
- */
28
- export interface GitOptions extends Pick<GitServerOptions, 'fetchLimits' | 'basePath' | 'maxDuration'> {}
29
24
  /**
30
25
  * Core's services, which every feature may require and `Git.layer` provides: `Git`, the repos'
31
26
  * records, `authorize`, refs, objects, events, the calls and the bases features build on.
@@ -1,7 +1,7 @@
1
1
  import { PrivateRefs } from "../contracts/access.mjs";
2
2
  import { fail } from "../contracts/result.mjs";
3
3
  import { Auth } from "../auth/auth.mjs";
4
- import { hostAuth, hostPolicy } from "../auth/bridge.mjs";
4
+ import { hostAuth, hostPolicy } from "../auth/host-services.mjs";
5
5
  import { Policy } from "../auth/policy.mjs";
6
6
  import { Git, register } from "../contracts/git.mjs";
7
7
  import { checkFetchOver } from "./check-fetch.mjs";
@@ -82,7 +82,7 @@ const core = (options) => Layer.effectContext(Effect.gen(function* () {
82
82
  objects,
83
83
  adapter,
84
84
  rules
85
- }, deciders, "later")), (made) => Effect.promise(() => made.server.close()));
85
+ }, deciders)), (made) => Effect.promise(() => made.server.close()));
86
86
  const built = yield* opened.built;
87
87
  const seam = seamOf(opened.server);
88
88
  if (seam === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("A Git server with no seam"));
@@ -1,7 +1,7 @@
1
- import { Git, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, checkFetch, handle, host, identify, isHost, register, route } from "../contracts/git.mjs";
2
- import { CoreServices, GitOptions, GitServices, addDelivery, layer, layerUploads } from "./git-layer.mjs";
1
+ import { AskedRepo, Git, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, checkFetch, handle, host, identify, isHost, register, route } from "../contracts/git.mjs";
2
+ import { CoreServices, GitServices, addDelivery, layer, layerUploads } from "./git-layer.mjs";
3
3
  import { toFetch } from "./edge.mjs";
4
4
  declare namespace git_namespace_d_exports {
5
- export { CoreServices, Git, GitOptions, GitServices, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, addDelivery, checkFetch, handle, host, identify, isHost, layer, layerUploads, register, route, toFetch };
5
+ export { AskedRepo, CoreServices, Git, GitServices, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, addDelivery, checkFetch, handle, host, identify, isHost, layer, layerUploads, register, route, toFetch };
6
6
  }
7
- export { CoreServices, Git, GitOptions, GitServices, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, addDelivery, checkFetch, git_namespace_d_exports, handle, host, identify, isHost, layer, layerUploads, register, route, toFetch };
7
+ export { AskedRepo, CoreServices, Git, GitServices, Hook, Purge, PurgeStep, PushCheck, PushCheckAnswer, PushCheckInput, RefOwner, RefRefusal, RegisterInput, RegisteredRows, RegisteredSnapshot, RegisteredWrites, Registration, Route, RouteMethod, RouteRequest, Upkeep, UpkeepStep, addDelivery, checkFetch, git_namespace_d_exports, handle, host, identify, isHost, layer, layerUploads, register, route, toFetch };
@@ -7,15 +7,12 @@ import { RepoRecord } from "../contracts/repos.mjs";
7
7
  import { GitError, Result } from "../contracts/result.mjs";
8
8
  import { GitServer, ServerCalls } from "../contracts/server.mjs";
9
9
  import { EffectCalls } from "../contracts/services.mjs";
10
- import { ImportState } from "../contracts/sync.mjs";
10
+ import { ImportStatus } from "../contracts/sync.mjs";
11
11
  import "../core/seam.mjs";
12
12
  import { CallAllowance } from "../store/call-count.mjs";
13
13
  import "./lifecycle.mjs";
14
14
  import * as Effect from "effect/Effect";
15
- import "effect/Exit";
16
15
  import * as Context from "effect/Context";
17
- import * as Layer from "effect/Layer";
18
- import "effect/Scope";
19
16
  /** The store, the bucket and the clock as promises, as the drop-in's records run over them. */
20
17
  export interface JoinedAdapter {
21
18
  readonly store: Store;
@@ -23,9 +20,8 @@ export interface JoinedAdapter {
23
20
  readonly clock: Clock;
24
21
  }
25
22
  /**
26
- * What a package joined to a `createGitServer` server reads beside Git's services: the calls
27
- * `RepoRecords`, `Authorize` and `Refs` don't make, each through the server's door. `Git.layer`
28
- * provides it to the drop-in; the bridge, `joinLayer`, goes with `createGitServer` in 2c-3b.
23
+ * What a joined package reads beside Git's services: the calls `RepoRecords`, `Authorize` and
24
+ * `Refs` don't make, each through the server's door. `Git.layer` provides it to the drop-in.
29
25
  */
30
26
  export interface Joined {
31
27
  /** The server itself, for what goes through its own `fetch`. */
@@ -33,6 +29,12 @@ export interface Joined {
33
29
  readonly basePath: string;
34
30
  /** The server's one queue's `keys`, or `undefined` with no queue. */
35
31
  readonly queueKeys: QueueKeys | undefined;
32
+ /**
33
+ * Adds `check` to `Git.layer`'s seal, which runs it once every feature has built, after the push
34
+ * rules' sources and before any job registers: a check that dies fails the build with its defect.
35
+ * One added after the seal is a defect. The drop-in's check of the queue's keys is one (#2313).
36
+ */
37
+ readonly addSealCheck: (check: Effect.Effect<void>) => Effect.Effect<void>;
36
38
  readonly adapter: JoinedAdapter;
37
39
  /**
38
40
  * The server's `fetchLimits`: core's purge drops a deleted repo's scopes, its joined package's
@@ -68,22 +70,13 @@ export interface Joined {
68
70
  readonly internalId: (repo: RepoName) => Effect.Effect<InternalRepoId, GitError>;
69
71
  /** The record of the repo `internalId` holds, as a host reads it: `undefined` once it's gone. */
70
72
  readonly record: (internalId: InternalRepoId) => Effect.Effect<RepoRecord | undefined, GitError>;
71
- readonly importState: (internalId: InternalRepoId) => Effect.Effect<ImportState | undefined, GitError>;
73
+ /**
74
+ * The repo's `sync.import`, as `ImportStatus` says: its state, and the Git LFS objects it copied
75
+ * and missed, on a server with `Lfs.layer`. `undefined` for a repo no import made.
76
+ */
77
+ readonly importState: (internalId: InternalRepoId) => Effect.Effect<ImportStatus | undefined, GitError>;
72
78
  }
73
79
  declare const JoinedCalls_base: Context.ServiceClass<JoinedCalls, "@ref0/git/JoinedCalls", Joined>;
74
- /** A joined Layer's `Joined`, which `joinLayer` and `Git.layer` provide (Q1030 bridge, 2c-3b). */
80
+ /** A joined package's `Joined`, which `Git.layer` provides. */
75
81
  export declare class JoinedCalls extends /* @__PURE__ */ JoinedCalls_base {}
76
- /** A joined Layer: the server's `basePath`, known at once, and the context its build gives. */
77
- export interface Joining<ROut> {
78
- readonly basePath: string;
79
- /** The built context, through the server's door, once its build is done: its failure else. */
80
- readonly context: Effect.Effect<Context.Context<ROut>, GitError>;
81
- }
82
- /**
83
- * Builds `layer` in `git`'s build, over Git's services and `JoinedCalls`, after the server's own
84
- * features and before its seal, so what it registers is sealed with Git's: a bridge, which 2c-3b
85
- * removes with `createGitServer`. Refused after the tick
86
- * that made the server.
87
- */
88
- export declare const joinLayer: <ROut, RIn>(git: GitServer, layer: Layer.Layer<ROut, GitError, RIn>) => Joining<ROut>;
89
82
  export {};
@@ -1,4 +1,3 @@
1
- import { gitError } from "../contracts/result.mjs";
2
1
  import { importStateOf } from "../core/imports.mjs";
3
2
  import { aroundCalls, guardedCall } from "../core/promise.mjs";
4
3
  import { lazyParts, seamOf } from "../core/seam.mjs";
@@ -9,10 +8,8 @@ import { thrownError } from "../store/errors.mjs";
9
8
  import * as Effect from "effect/Effect";
10
9
  import * as Option from "effect/Option";
11
10
  import * as Context from "effect/Context";
12
- import * as Layer from "effect/Layer";
13
- import * as Deferred from "effect/Deferred";
14
11
  // src/server/joined.ts
15
- /** A joined Layer's `Joined`, which `joinLayer` and `Git.layer` provide (Q1030 bridge, 2c-3b). */
12
+ /** A joined package's `Joined`, which `Git.layer` provides. */
16
13
  var JoinedCalls = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/JoinedCalls")) {};
17
14
  const attachedByServer = /* @__PURE__ */ new WeakMap();
18
15
  /** Called once, by `openServer`, for the server it returns. */
@@ -21,7 +18,7 @@ const attachJoins = (git, attached) => {
21
18
  };
22
19
  const attachedOf = (git, call) => {
23
20
  const attached = attachedByServer.get(git);
24
- if (attached === void 0) throw new TypeError(`${call} takes a server createGitServer made`);
21
+ if (attached === void 0) throw new TypeError(`${call} takes a server openServer made`);
25
22
  return attached;
26
23
  };
27
24
  /** `effect`, counted into `budget` unless a budget is in scope, which nests in it. */
@@ -30,7 +27,7 @@ const within = (budget) => (effect) => Effect.flatMap(Effect.serviceOption(CallB
30
27
  const joinedOf = (git, built) => {
31
28
  const attached = attachedOf(git, "joinedOf");
32
29
  const seam = seamOf(git);
33
- if (seam === void 0) throw new TypeError("joinedOf takes a server createGitServer made");
30
+ if (seam === void 0) throw new TypeError("joinedOf takes a server openServer made");
34
31
  const { through } = attached;
35
32
  const { store } = built.adapter;
36
33
  const guarded = guardedCall(through);
@@ -49,6 +46,7 @@ const joinedOf = (git, built) => {
49
46
  get queueKeys() {
50
47
  return attached.queueKeys;
51
48
  },
49
+ addSealCheck: attached.addSealCheck,
52
50
  adapter: built.adapter,
53
51
  fetchLimits: attached.fetchLimits,
54
52
  request: () => syncIn(requestBudget(built.parts.requestMost), noCall),
@@ -67,26 +65,4 @@ const joinedOf = (git, built) => {
67
65
  importState: (internalId) => effectRun(importStateOf(store, internalId))
68
66
  };
69
67
  };
70
- /** The refusal of a join after the tick that made the server, when its build has started. */
71
- const lateJoin = (call) => `${call} joins a server in the tick createGitServer made it in: call it where the server is made, before any await`;
72
- /**
73
- * Builds `layer` in `git`'s build, over Git's services and `JoinedCalls`, after the server's own
74
- * features and before its seal, so what it registers is sealed with Git's: a bridge, which 2c-3b
75
- * removes with `createGitServer`. Refused after the tick
76
- * that made the server.
77
- */
78
- const joinLayer = (git, layer) => {
79
- const attached = attachedOf(git, "joinLayer");
80
- if (attached.admit("join") === "late") {
81
- const hostHint = lateJoin("joinLayer");
82
- const refusal = gitError("FAILED_PRECONDITION", "joinLayer joins a server before its build starts", { hostHint });
83
- throw new Error(hostHint, { cause: refusal });
84
- }
85
- const done = Deferred.makeUnsafe();
86
- attached.joins.push({ build: (over) => Effect.exit(Layer.build(layer).pipe(Effect.provideContext(over))).pipe(Effect.tap((exit) => Deferred.done(done, exit))) });
87
- return {
88
- basePath: attached.basePath,
89
- context: attached.through(Effect.andThen(attached.built, Deferred.await(done)))
90
- };
91
- };
92
- export { JoinedCalls, attachJoins, joinLayer, joinedOf };
68
+ export { JoinedCalls, attachJoins, joinedOf };
@@ -1,75 +1,159 @@
1
1
  import { closedError } from "../store/closed.mjs";
2
2
  import { thrownError } from "../store/errors.mjs";
3
3
  import { throughBridge } from "../store/promises.mjs";
4
- import { gitError } from "../contracts/result.mjs";
4
+ import { gitError, isGitError } from "../contracts/result.mjs";
5
5
  import * as Cause from "effect/Cause";
6
+ import { InvalidArgument, Setup } from "@ref0/infra";
6
7
  // src/server/lifecycle.ts
7
- /** Every entry in every state, decided here alone. */
8
+ /**
9
+ * Every entry in every state, decided here alone. A call during `waiting` is `unavailable` until
10
+ * its `at`, and `wait` from then, which starts the next build: `admit` reads the clock for it.
11
+ */
8
12
  const admissions = {
9
- join: {
10
- joining: "join",
11
- building: "late",
12
- built: "late",
13
- failed: "late",
14
- closed: "late"
15
- },
16
13
  call: {
17
- joining: "wait",
14
+ unbuilt: "wait",
18
15
  building: "wait",
19
16
  built: "run",
17
+ waiting: "unavailable",
20
18
  failed: "unavailable",
21
19
  closed: "closed"
22
20
  },
23
21
  bridge: {
24
- joining: "run",
22
+ unbuilt: "run",
25
23
  building: "run",
26
24
  built: "run",
25
+ waiting: "unavailable",
27
26
  failed: "unavailable",
28
27
  closed: "closed"
29
28
  }
30
29
  };
31
- /** The moves each state allows: `closed` allows none. */
30
+ /**
31
+ * The moves each state allows: `closed` allows none, and `failed` only `closed`. `waiting` moves to
32
+ * `building` at most once, so of two calls at its `at` one starts the build and the other waits on it.
33
+ */
32
34
  const moves = {
33
- joining: ["building", "closed"],
35
+ unbuilt: ["building", "closed"],
34
36
  building: [
35
37
  "built",
38
+ "waiting",
36
39
  "failed",
37
40
  "closed"
38
41
  ],
39
42
  built: ["closed"],
43
+ waiting: ["building", "closed"],
40
44
  failed: ["closed"],
41
45
  closed: []
42
46
  };
43
- /** What a call or request answers once the build failed: the failure, for the host's logs. */
47
+ /**
48
+ * The server's bounds on rebuilding after a failed build, in ms: the n-th failure waits
49
+ * `min(first * 2^(n-1), longest)` before a call may start the next build. Nothing caps the count:
50
+ * a build that keeps failing on weather is tried at most once a `longest`, and only when a call
51
+ * comes, so a server idle through an outage builds once when its first call returns.
52
+ */
53
+ const buildRetries = {
54
+ first: 1e3,
55
+ longest: 3e4
56
+ };
57
+ /** How long the `failures`-th failed build waits before the next, as `buildRetries` says. */
58
+ const retryDelay = (failures) => Math.min(buildRetries.first * 2 ** Math.max(failures - 1, 0), buildRetries.longest);
59
+ /** `error`'s own `GitError`, or the one it carries as its `cause`, as a late join's and a feature's do. */
60
+ const gitErrorIn = (error) => {
61
+ if (isGitError(error)) return error;
62
+ return isGitError(error.cause) ? error.cause : void 0;
63
+ };
64
+ /** Whether `error`, a build's failure, is the host's setup or Git's word on it, which no rebuild changes. */
65
+ const deterministic = (error) => {
66
+ if (error instanceof Setup || error instanceof InvalidArgument) return true;
67
+ const git = gitErrorIn(error);
68
+ return git !== void 0 && (git.code === "INVALID_ARGUMENT" || git.code === "FAILED_PRECONDITION");
69
+ };
70
+ /**
71
+ * Whether a build that failed with `cause` may succeed if built again: it failed, and on nothing
72
+ * the next build would meet again. It doesn't for infra's `Setup` (a binding that isn't there) or
73
+ * `InvalidArgument`, for a `GitError` coded `INVALID_ARGUMENT` or `FAILED_PRECONDITION` (a refused
74
+ * rule, a clash, a late join), read one `cause` down as well, or for any defect: Git's wiring
75
+ * refuses a setup with one, and one is a bug. Any other failure retries, an untagged one among
76
+ * them. A host Layer that rejects through `Effect.promise` on a network blip dies, so it stays
77
+ * failed: wrap the call in `Effect.tryPromise`, or map it to infra's `Unavailable`, as infra's
78
+ * adapters do.
79
+ */
80
+ const retries = (cause) => {
81
+ const failures = cause.reasons.filter(Cause.isFailReason);
82
+ return failures.length > 0 && !cause.reasons.some(Cause.isDieReason) && !failures.some((reason) => deterministic(reason.error));
83
+ };
84
+ /**
85
+ * Where a build that failed with `cause` goes, its `failures`-th failure counting this one, at
86
+ * `now`: `waiting` until `retryDelay` has passed when `retries` says so, and `failed` otherwise.
87
+ *
88
+ * Only the adapter's phase can fail on weather: the host's Layers, `rules`, and the xdiff load.
89
+ * Git's wiring, which writes what outlives one build into the server's registry, runs after them in
90
+ * one synchronous step, so a failure there is a defect, which `retries` refuses. A feature builds in
91
+ * `Git.layer`, outside the server's own build, so its failure never comes here.
92
+ */
93
+ const afterFailure = (cause, failures, now) => retries(cause) ? {
94
+ kind: "waiting",
95
+ cause,
96
+ failures,
97
+ at: now + retryDelay(failures)
98
+ } : {
99
+ kind: "failed",
100
+ cause
101
+ };
102
+ /** What a call or request answers once the build failed for good: the failure, for the host's logs. */
44
103
  const unavailable = (cause) => gitError("UNAVAILABLE", "The Git server failed to start", {
45
104
  cause: Cause.squash(cause),
46
105
  hint: "Fix the host's adapter, then restart"
47
106
  });
48
- /** A server's life, `joining` until its build starts. */
49
- const serverLife = () => {
50
- let state = { kind: "joining" };
107
+ /** What a call answers while the server waits to build again: the failure, and when to come back. */
108
+ const starting = (cause, retryAfter) => gitError("UNAVAILABLE", "The Git server failed to start, and is starting again", {
109
+ cause: Cause.squash(cause),
110
+ hint: `Try again in ${retryAfter} s`,
111
+ context: {
112
+ reason: "starting",
113
+ retryAfter
114
+ }
115
+ });
116
+ /**
117
+ * The `UNAVAILABLE` a call answers in the state now, or `undefined` while the server is neither
118
+ * `failed` nor `waiting`: `waiting`'s names the whole seconds until its `at`, at least 1.
119
+ */
120
+ const refusedNow = (life) => {
121
+ const now = life.now();
122
+ if (now.kind === "failed") return unavailable(now.cause);
123
+ return now.kind === "waiting" ? starting(now.cause, Math.max(Math.ceil((now.at - life.clock()) / 1e3), 1)) : void 0;
124
+ };
125
+ /**
126
+ * A server's life, `unbuilt` until its build starts, with `waiting`'s `at` on `clock`. The host's
127
+ * own clock is a service of the Layer whose build failed, so the server's isn't it.
128
+ */
129
+ const serverLife = (clock = Date.now) => {
130
+ let state = { kind: "unbuilt" };
51
131
  const closing = new AbortController();
52
132
  return {
53
133
  now: () => state,
54
- admit: (entry) => admissions[entry][state.kind],
134
+ admit: (entry) => {
135
+ const admitted = admissions[entry][state.kind];
136
+ return entry === "call" && state.kind === "waiting" && clock() >= state.at ? "wait" : admitted;
137
+ },
55
138
  move: (to) => {
56
139
  if (!moves[state.kind].includes(to.kind)) return false;
57
140
  state = to;
58
141
  if (to.kind === "closed") closing.abort(closedError());
59
142
  return true;
60
143
  },
144
+ clock,
61
145
  closing: closing.signal
62
146
  };
63
147
  };
64
148
  /**
65
- * The bridge's refusal in the state now, or `undefined` while it runs: once the build failed, Git's
66
- * `UNAVAILABLE` naming its failure, as the server's calls answer.
149
+ * The bridge's refusal in the state now, or `undefined` while it runs: once the build failed, or
150
+ * while the server waits to build again, Git's `UNAVAILABLE` naming its failure, as its calls answer.
67
151
  */
68
152
  const bridgeRefusal = (life) => {
69
153
  const admitted = life.admit("bridge");
70
154
  if (admitted === "closed") return closedError();
71
- const now = life.now();
72
- return admitted === "unavailable" && now.kind === "failed" ? thrownError(unavailable(now.cause)) : void 0;
155
+ const refused = admitted === "unavailable" ? refusedNow(life) : void 0;
156
+ return refused === void 0 ? void 0 : thrownError(refused);
73
157
  };
74
158
  /**
75
159
  * `effect` through the door, for a run outside the server's runtime, which `close()` doesn't stop:
@@ -79,4 +163,4 @@ const throughDoor = (life) => throughBridge({
79
163
  refusal: () => life.admit("call") === "closed" ? closedError() : void 0,
80
164
  closing: life.closing
81
165
  });
82
- export { bridgeRefusal, serverLife, throughDoor, unavailable };
166
+ export { afterFailure, bridgeRefusal, buildRetries, refusedNow, retries, retryDelay, serverLife, throughDoor, unavailable };
@@ -57,6 +57,7 @@ const openRegistry = (basePath = "") => {
57
57
  const pending = [];
58
58
  const rules = [];
59
59
  const checks = [];
60
+ const sealChecks = [];
60
61
  const upkeeps = [];
61
62
  const purges = [];
62
63
  const hookGroups = [];
@@ -153,6 +154,7 @@ const openRegistry = (basePath = "") => {
153
154
  if (invalid !== void 0) return Effect.fail(clash(`Invalid registered scope '${invalid}'`));
154
155
  const overlap = scopes.find((scope, index) => [...ownedScopes, ...scopes.slice(0, index)].some((owned) => ownsScope(owned, scope) || ownsScope(scope, owned)));
155
156
  if (overlap !== void 0) return Effect.fail(clash(`Scope '${overlap}' overlaps a registered scope`));
157
+ if (input.refsReadBy !== void 0 && refs === void 0) return Effect.fail(clash(`Registration '${name}' names who reads its refs, with no refs`));
156
158
  const publishes = input.publishes ?? [];
157
159
  const unpublished = publishesClash(name, publishes, refs);
158
160
  if (unpublished !== void 0) return Effect.fail(unpublished);
@@ -165,7 +167,7 @@ const openRegistry = (basePath = "") => {
165
167
  of: input.repoScopes
166
168
  });
167
169
  const owner = refs === void 0 ? void 0 : ownerOf(name, refs);
168
- if (owner !== void 0) registered.push(registeredRow(owner));
170
+ if (owner !== void 0) registered.push(registeredRow(owner, input.refsReadBy === "owner"));
169
171
  for (const prefix of publishes) published.push(Object.freeze({
170
172
  prefix,
171
173
  by: name
@@ -255,6 +257,12 @@ const openRegistry = (basePath = "") => {
255
257
  jobOf: (job) => jobs.get(job),
256
258
  hiddenRefs: () => hidden,
257
259
  publishedRefs: () => shown,
260
+ addSealCheck: (check) => Effect.suspend(() => {
261
+ if (sealed) return Effect.die(sealedDefect());
262
+ sealChecks.push(check);
263
+ return Effect.void;
264
+ }),
265
+ sealChecks: () => sealChecks,
258
266
  seal: () => Effect.suspend(() => {
259
267
  sealed = true;
260
268
  hidden = [...gitsOwnRefs, ...registered];