@ref0/git 0.12.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 (247) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  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 +11 -1
  28. package/dist/contracts/git.d.mts +18 -7
  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 +23 -18
  42. package/dist/contracts/result.mjs +17 -4
  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 +79 -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.mjs +27 -5
  54. package/dist/core/ancestry.d.mts +9 -0
  55. package/dist/core/ancestry.mjs +6 -6
  56. package/dist/core/asked.mjs +42 -4
  57. package/dist/core/call-names.mjs +1 -0
  58. package/dist/core/call-services.mjs +2 -1
  59. package/dist/core/events/deliver.mjs +10 -2
  60. package/dist/core/forks.mjs +3 -3
  61. package/dist/core/imports.mjs +147 -9
  62. package/dist/core/index-job.mjs +9 -6
  63. package/dist/core/job-view.mjs +8 -9
  64. package/dist/core/mirror-rows.mjs +19 -4
  65. package/dist/core/objects/commits.mjs +16 -6
  66. package/dist/core/parts.d.mts +6 -1
  67. package/dist/core/parts.mjs +1 -4
  68. package/dist/core/purge.mjs +76 -6
  69. package/dist/core/push-decide.mjs +1 -1
  70. package/dist/core/push-files.d.mts +12 -0
  71. package/dist/core/push-files.mjs +225 -0
  72. package/dist/core/push-repo.d.mts +8 -0
  73. package/dist/core/push-repo.mjs +56 -0
  74. package/dist/core/push.d.mts +17 -0
  75. package/dist/core/push.mjs +98 -26
  76. package/dist/core/receipts.mjs +26 -10
  77. package/dist/core/ref-view.mjs +59 -5
  78. package/dist/core/refs.mjs +13 -8
  79. package/dist/core/repack.mjs +11 -8
  80. package/dist/core/repo-info.mjs +16 -9
  81. package/dist/core/repos.mjs +30 -14
  82. package/dist/core/seam.mjs +2 -2
  83. package/dist/core/view.d.mts +6 -0
  84. package/dist/core/view.mjs +45 -12
  85. package/dist/core/work.mjs +47 -22
  86. package/dist/effect.d.mts +3 -1
  87. package/dist/effect.mjs +3 -1
  88. package/dist/engine/reads.mjs +13 -6
  89. package/dist/engine/walk.mjs +4 -4
  90. package/dist/event-streams/event-streams.d.mts +1 -1
  91. package/dist/event-streams/event-streams.mjs +1 -1
  92. package/dist/event-streams/stream.d.mts +1 -1
  93. package/dist/event-streams/stream.mjs +1 -1
  94. package/dist/extend.d.mts +3 -3
  95. package/dist/extend.mjs +2 -2
  96. package/dist/http/answers.mjs +4 -2
  97. package/dist/http/core-parts.mjs +64 -15
  98. package/dist/http/handler.mjs +2 -2
  99. package/dist/http/node.mjs +5 -4
  100. package/dist/http/parts.d.mts +1 -0
  101. package/dist/http/push-upload-job.mjs +503 -0
  102. package/dist/http/push-uploads.d.mts +1 -0
  103. package/dist/http/push-uploads.mjs +114 -56
  104. package/dist/http/upload-pack.mjs +7 -6
  105. package/dist/index.d.mts +23 -24
  106. package/dist/index.mjs +4 -7
  107. package/dist/lfs/base.d.mts +7 -3
  108. package/dist/lfs/base.mjs +2 -1
  109. package/dist/lfs/copy.d.mts +46 -0
  110. package/dist/lfs/copy.mjs +26 -0
  111. package/dist/lfs/layer.mjs +4 -2
  112. package/dist/lfs/objects.d.mts +6 -0
  113. package/dist/lfs/objects.mjs +68 -41
  114. package/dist/lfs/rows.d.mts +13 -0
  115. package/dist/lfs/service.d.mts +1 -7
  116. package/dist/lfs/service.mjs +1 -9
  117. package/dist/lfs/upload-most.mjs +5 -5
  118. package/dist/node.d.mts +2 -2
  119. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  120. package/dist/protocol/bytes/sha256.d.mts +32 -0
  121. package/dist/protocol/bytes/sha256.mjs +105 -49
  122. package/dist/protocol/wire/advertisement.mjs +9 -4
  123. package/dist/protocol/wire/lines.d.mts +4 -2
  124. package/dist/protocol/wire/lines.mjs +11 -5
  125. package/dist/protocol/wire/push-uploads.mjs +13 -1
  126. package/dist/protocol/wire/v2.mjs +2 -2
  127. package/dist/protocol.d.mts +3 -1
  128. package/dist/protocol.mjs +3 -1
  129. package/dist/queue/advance.mjs +1 -1
  130. package/dist/queue/host.d.mts +1 -7
  131. package/dist/queue/host.mjs +1 -7
  132. package/dist/queue/layer.mjs +1 -1
  133. package/dist/queue/trim.mjs +1 -1
  134. package/dist/rest/blobs.d.mts +31 -23
  135. package/dist/rest/blobs.mjs +1 -1
  136. package/dist/rest/caller.d.mts +49 -9
  137. package/dist/rest/caller.mjs +1 -1
  138. package/dist/rest/client.d.mts +10 -3
  139. package/dist/rest/client.mjs +4 -0
  140. package/dist/rest/commits.d.mts +273 -240
  141. package/dist/rest/errors.d.mts +24 -4
  142. package/dist/rest/events.d.mts +9 -6
  143. package/dist/rest/events.mjs +1 -2
  144. package/dist/rest/files.d.mts +127 -115
  145. package/dist/rest/forks.d.mts +121 -97
  146. package/dist/rest/handler.mjs +4 -57
  147. package/dist/rest/handlers.d.mts +1 -1
  148. package/dist/rest/handlers.mjs +18 -4
  149. package/dist/rest/layer.mjs +2 -1
  150. package/dist/rest/me.d.mts +8 -4
  151. package/dist/rest/merges.d.mts +8 -4
  152. package/dist/rest/paths.mjs +1 -0
  153. package/dist/rest/queue.d.mts +282 -226
  154. package/dist/rest/refs.d.mts +205 -176
  155. package/dist/rest/repos.d.mts +108 -80
  156. package/dist/rest/tags.d.mts +24 -12
  157. package/dist/rest/tokens.d.mts +235 -211
  158. package/dist/rest/topics.d.mts +53 -33
  159. package/dist/rest/trees.d.mts +105 -89
  160. package/dist/rest/work.d.mts +467 -20
  161. package/dist/rest/work.mjs +8 -0
  162. package/dist/server/edge-node.d.mts +9 -13
  163. package/dist/server/edge-node.mjs +9 -12
  164. package/dist/server/git-layer.d.mts +1 -6
  165. package/dist/server/git-layer.mjs +2 -2
  166. package/dist/server/git-namespace.d.mts +3 -3
  167. package/dist/server/joined.d.mts +15 -22
  168. package/dist/server/joined.mjs +5 -29
  169. package/dist/server/lifecycle.mjs +107 -23
  170. package/dist/server/registry.mjs +9 -1
  171. package/dist/server/server.mjs +133 -212
  172. package/dist/storage/budget.mjs +2 -2
  173. package/dist/storage/clean-up.mjs +13 -10
  174. package/dist/storage/fetch.mjs +13 -8
  175. package/dist/storage/file-limits.mjs +24 -0
  176. package/dist/storage/index-build.d.mts +1 -0
  177. package/dist/storage/index-build.mjs +106 -62
  178. package/dist/storage/index-fetch.mjs +16 -3
  179. package/dist/storage/index-reach.mjs +33 -5
  180. package/dist/storage/index-remap.mjs +8 -1
  181. package/dist/storage/index-shallow.mjs +5 -3
  182. package/dist/storage/largest-files.mjs +48 -0
  183. package/dist/storage/lfs-pointers.mjs +10 -1
  184. package/dist/storage/loose.mjs +3 -1
  185. package/dist/storage/memory-budget.mjs +28 -4
  186. package/dist/storage/pack-reads.mjs +8 -8
  187. package/dist/storage/pack-receive.mjs +83 -25
  188. package/dist/storage/packs.mjs +37 -21
  189. package/dist/storage/prune-keep.mjs +203 -34
  190. package/dist/storage/prune-walk.mjs +54 -16
  191. package/dist/storage/prune.mjs +629 -196
  192. package/dist/storage/push-uploads.mjs +36 -12
  193. package/dist/storage/quarantine.mjs +9 -9
  194. package/dist/storage/ready.mjs +47 -19
  195. package/dist/storage/receive-bounds.mjs +29 -8
  196. package/dist/storage/receive-state.mjs +8 -0
  197. package/dist/storage/receive-steps.mjs +71 -18
  198. package/dist/storage/repack.d.mts +1 -1
  199. package/dist/storage/repack.mjs +1 -8
  200. package/dist/storage/rows.mjs +12 -1
  201. package/dist/storage/shallow.d.mts +1 -0
  202. package/dist/storage/shallow.mjs +26 -4
  203. package/dist/storage/stream-whole.mjs +5 -2
  204. package/dist/storage/visible.mjs +29 -1
  205. package/dist/storage/walk.mjs +2 -1
  206. package/dist/store/catalogue.mjs +1 -0
  207. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  208. package/dist/store/cursor-seal-public.d.mts +5 -0
  209. package/dist/store/cursor-seal-public.mjs +5 -0
  210. package/dist/store/cursor-seal.d.mts +16 -2
  211. package/dist/store/cursor-seal.mjs +26 -14
  212. package/dist/store/errors.mjs +9 -1
  213. package/dist/store/records.d.mts +2 -0
  214. package/dist/store/records.mjs +9 -6
  215. package/dist/store/repo-record.d.mts +9 -7
  216. package/dist/store/repo-record.mjs +102 -19
  217. package/dist/store/scopes.mjs +10 -2
  218. package/dist/sync/bound.d.mts +2 -0
  219. package/dist/sync/bound.mjs +11 -2
  220. package/dist/sync/github.d.mts +6 -1
  221. package/dist/sync/github.mjs +55 -43
  222. package/dist/sync/http.mjs +36 -1
  223. package/dist/sync/import.mjs +1 -0
  224. package/dist/sync/layer.mjs +6 -2
  225. package/dist/sync/lfs-batch.mjs +119 -0
  226. package/dist/sync/lfs-copy.mjs +251 -0
  227. package/dist/sync/mirror.mjs +210 -137
  228. package/dist/sync/smart-http.mjs +4 -2
  229. package/dist/sync/step.mjs +25 -5
  230. package/dist/sync/tries.mjs +45 -14
  231. package/dist/sync.d.mts +2 -2
  232. package/dist/topics/host.mjs +1 -19
  233. package/dist/topics/layer.mjs +1 -1
  234. package/package.json +3 -8
  235. package/dist/auth/bridge.mjs +0 -30
  236. package/dist/auth/helpers.d.mts +0 -17
  237. package/dist/core/purge.d.mts +0 -8
  238. package/dist/core/registered-rows.d.mts +0 -5
  239. package/dist/core/repack.d.mts +0 -11
  240. package/dist/http/handler.d.mts +0 -2
  241. package/dist/rest/handler.d.mts +0 -21
  242. package/dist/rest.d.mts +0 -2
  243. package/dist/rest.mjs +0 -1
  244. package/dist/server/registry.d.mts +0 -16
  245. package/dist/server/server.d.mts +0 -36
  246. package/dist/storage/repack-job.d.mts +0 -3
  247. package/dist/topics/host.d.mts +0 -7
@@ -122,9 +122,9 @@ const wholeView = (all) => ({
122
122
  publishes: () => true
123
123
  });
124
124
  /**
125
- * Private branches (experimental), for `createGitServer`'s `access`: each ref a pattern matches is
126
- * seen only by a caller whose `refs.private` answer reads that pattern, and every other ref by
127
- * everyone who may read the repo, but Git's own: a merge queue's candidates and an import's
125
+ * Private branches (experimental), as `PrivateRefs.layer` configures them: each ref a pattern
126
+ * matches is seen only by a caller whose `refs.private` answer reads that pattern, and every other
127
+ * ref by everyone who may read the repo, but Git's own: a merge queue's candidates and an import's
128
128
  * staging refs are seen only by a caller who reads every pattern, since they hold what their
129
129
  * entries hold. Until each candidate's ref view is checked against what it holds (2c), a CI
130
130
  * credential that doesn't read every pattern can't fetch a candidate. A bare pattern names a
@@ -28,8 +28,8 @@ export declare const make: (identify: AuthService['identify']) => AuthService;
28
28
  export declare const layer: <E = never, R = never>(auth: AuthService | Effect.Effect<AuthService, E, R>) => Layer.Layer<Auth, E, Exclude<R, Scope.Scope>>;
29
29
  /**
30
30
  * One secret for one actor, such as an admin token: sent as a Bearer token, or as Basic's
31
- * password, as Git sends one from its credential helper. Compared by hash, as `@ref0/git/auth`'s
32
- * `bearer` does.
31
+ * password, as Git sends one from its credential helper. Compared by hash, so the time taken
32
+ * doesn't say where a guess differs.
33
33
  */
34
34
  export declare const bearer: (options: {
35
35
  readonly token: Redacted.Redacted<string>;
@@ -16,17 +16,14 @@ const make = (identify) => ({ identify });
16
16
  const layer = (auth) => Effect.isEffect(auth) ? Layer.effect(Auth, auth) : Layer.succeed(Auth, auth);
17
17
  /**
18
18
  * One secret for one actor, such as an admin token: sent as a Bearer token, or as Basic's
19
- * password, as Git sends one from its credential helper. Compared by hash, as `@ref0/git/auth`'s
20
- * `bearer` does.
19
+ * password, as Git sends one from its credential helper. Compared by hash, so the time taken
20
+ * doesn't say where a guess differs.
21
21
  */
22
22
  const bearer = (options) => {
23
23
  const known = bearer$1({
24
24
  token: Redacted.value(options.token),
25
25
  actor: options.actor
26
26
  });
27
- return make((input) => Effect.map(Effect.promise((signal) => Promise.resolve(known({
28
- ...input,
29
- signal
30
- }))), Option.fromNullishOr));
27
+ return make((input) => Effect.map(Effect.promise(() => known(input)), Option.fromNullishOr));
31
28
  };
32
29
  export { Auth, bearer, layer, make };
@@ -4,7 +4,6 @@ import { accept, gitError, reject } from "../contracts/result.mjs";
4
4
  import { ghWriteScope } from "../contracts/signin.mjs";
5
5
  import { utf8 } from "../protocol/bytes/text.mjs";
6
6
  import { internalIdOf } from "../store/catalogue.mjs";
7
- import { actingOf } from "./acting.mjs";
8
7
  import { isTokenOf } from "./token-text.mjs";
9
8
  import { hostCall, logRefusal, rejectedError } from "./host-function.mjs";
10
9
  import * as Effect from "effect/Effect";
@@ -171,21 +170,6 @@ const readersError = (input) => {
171
170
  if (readable.kind === "reject") return refusalError(actor, read, readable);
172
171
  return missing ? gitError("NOT_FOUND", `No repo '${operationRepo(read) ?? ""}'`) : refused;
173
172
  };
174
- /** What the host's Promise `authorize` is asked, but its signal: the bridge's input. */
175
- const inputOf = ({ caller, operation, repo }) => {
176
- const input = { operation };
177
- if (caller.subject !== void 0) input.subject = caller.subject;
178
- if (caller.token !== void 0) input.token = caller.token;
179
- if (repo !== void 0) input.repo = {
180
- name: repo.name,
181
- public: repo.public,
182
- internalId: repo.internalId
183
- };
184
- return {
185
- ...actingOf(caller),
186
- ...input
187
- };
188
- };
189
173
  /**
190
174
  * A server's `authorize`: the credential's ceiling first, then the host's `Policy`. A refusal reaches the caller as `refusalError` makes it: a host's own code exactly as
191
175
  * returned. A refusal of anything but a read or a create, whatever its code, is told only to a
@@ -277,4 +261,4 @@ const audienceOf = (options) => Effect.fnUntraced(function* ({ caller, repo, cre
277
261
  const answer = yield* options.policy.authorize(check);
278
262
  return yield* hostCall("authorize", aboutOf(caller, operation), () => audienceIn(answer, patterns));
279
263
  });
280
- export { aboutOf, accessOf, audienceOf, authorizer, bypassKinds, hostAuthorize, inputOf, longActorId, operationRepo, readKinds };
264
+ export { aboutOf, accessOf, audienceOf, authorizer, bypassKinds, hostAuthorize, longActorId, operationRepo, readKinds };
@@ -4,8 +4,8 @@ import { sameHash, sha256Hex } from "./token-text.mjs";
4
4
  /** Whether `given` is `secret`, compared by hash so the time taken doesn't say where they differ. */
5
5
  const sameSecret = async (given, secret) => sameHash(await sha256Hex(given), await secret);
6
6
  /**
7
- * An `auth` that knows one secret, as `actor`: sent as a Bearer token, or as Basic's password,
8
- * as Git sends one from its credential helper. The admin's secret is an ordinary actor this way.
7
+ * A check that knows one secret, as `actor`: sent as a Bearer token, or as Basic's password, as
8
+ * Git sends one from its credential helper. `Auth.bearer` asks it, and a test's `auth` is it.
9
9
  */
10
10
  const bearer = (options) => {
11
11
  const secret = sha256Hex(options.token);
@@ -14,12 +14,4 @@ const bearer = (options) => {
14
14
  return await sameSecret(credentialSecret(credentials), secret) ? options.actor : void 0;
15
15
  };
16
16
  };
17
- /** An `auth` that knows one Basic username and password, as `actor`. */
18
- const basic = (options) => {
19
- const password = sha256Hex(options.password);
20
- return async ({ credentials }) => {
21
- if (credentials?.kind !== "basic" || credentials.username !== options.username) return;
22
- return await sameSecret(credentials.password, password) ? options.actor : void 0;
23
- };
24
- };
25
- export { basic, bearer };
17
+ export { bearer };
@@ -0,0 +1,11 @@
1
+ import { aboutOf } from "./authorize.mjs";
2
+ import { runIn, uncounted } from "../store/crossing.mjs";
3
+ import { hostCall } from "./host-function.mjs";
4
+ // src/auth/host-services.ts
5
+ /** A host's own `Policy` and `Auth` make no call through Git's doors. */
6
+ const hostDecider = /* @__PURE__ */ uncounted("the host's own Policy and Auth");
7
+ /** The host's `Policy`, each answer a host function the host's log names as `'authorize'`'s. */
8
+ const hostPolicy = (policy) => ({ authorize: (input) => hostCall("authorize", aboutOf(input.caller, input.operation), (signal) => runIn(policy.authorize(input), hostDecider, signal)) });
9
+ /** The host's `Auth`, each answer a host function the host's log names as `'auth'`'s. */
10
+ const hostAuth = (auth) => auth === void 0 ? void 0 : { identify: (input) => hostCall("auth", {}, (signal) => runIn(auth.identify(input), hostDecider, signal)) };
11
+ export { hostAuth, hostPolicy };
@@ -1,6 +1,7 @@
1
1
  import { RefAudience } from "../contracts/access.mjs";
2
2
  import { AuthorizeRequest } from "../contracts/authorize.mjs";
3
- import { Accepted, DecisionAnswer, GitError, RejectInput } from "../contracts/result.mjs";
3
+ import { FetchAdjustment } from "../contracts/rules.mjs";
4
+ import { Accepted, DecisionAnswer, GitError, RejectInput, Rejected } from "../contracts/result.mjs";
4
5
  import * as Effect from "effect/Effect";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Layer from "effect/Layer";
@@ -11,7 +12,17 @@ declare namespace policy_d_exports {
11
12
  /**
12
13
  * What a policy is asked: who, its `caller`, with the actor, the subject it acts for, the token or
13
14
  * grant that identified it, and `at: 'queued'` for a merge queue's publish; what, its `operation`;
14
- * and where, the `repo` it names. Decide on `repo.internalId`: core confirms it after.
15
+ * and where, the `repo` it names. Decide on `repo.internalId`: core confirms it after. A name can
16
+ * move between repos while you decide, so a policy that decides by `repo.name` alone answers about
17
+ * the other repo (the coordinator, Q871, 25 Nov).
18
+ *
19
+ * A merge queue's publish asks again for each entry, as the caller that added it, with no actor
20
+ * `meta`: decide it from the actor's ID, and never grant on `meta`'s absence. A `token.create`
21
+ * names whom the token is for, its `subject`, and any `actor` acting for them: refuse one a caller
22
+ * mints for anyone they may not act as (the coordinator, 21 Nov). A `refs.private`, asked only of
23
+ * a server with private refs, is accepted with the caller's `RefAudience`. One asked with no
24
+ * `repo` is an import's, before the repo exists: decide it from the caller, the name and the
25
+ * patterns, and an importer who reads fewer than every pattern is refused the import.
15
26
  */
16
27
  export type Input = AuthorizeRequest;
17
28
  /** `accept`, `reject`, or for `refs.private`, `accept` with the caller's ref audience. */
@@ -39,10 +50,17 @@ export declare class Policy extends /* @__PURE__ */ Policy_base {}
39
50
  export declare const make: (authorize: PolicyService['authorize']) => PolicyService;
40
51
  /** The Layer: a policy, or an Effect that builds one from the host's own services. */
41
52
  export declare const layer: <E = never, R = never>(policy: PolicyService | Effect.Effect<PolicyService, E, R>) => Layer.Layer<Policy, E, Exclude<R, Scope.Scope>>;
42
- /** An `accept`, or for `refs.private`, the caller's audience. Was `accept()`. */
43
- export declare const accept: (value?: RefAudience) => Effect.Effect<Answer>;
44
- /** A refusal: `code` is `NOT_ALLOWED` when it's left out. Was `reject()`. */
45
- export declare const reject: (refusal: RejectInput) => Effect.Effect<Answer>;
53
+ /**
54
+ * An `accept`, or for `refs.private`, the caller's audience. Was `accept()`. Without a value it's
55
+ * any decision's accept, so a rule's check or the drop-in's `authorize` answers with it too. A
56
+ * fetch rule's accept may set a depth, `Policy.accept({ depth: 10 })`, the most history it sends.
57
+ */
58
+ export declare function accept(): Effect.Effect<Accepted<never>>;
59
+ export declare function accept(value: RefAudience): Effect.Effect<Accepted<RefAudience>>;
60
+ export declare function accept(value: FetchAdjustment): Effect.Effect<Accepted<FetchAdjustment>>;
61
+ export declare function accept(value?: RefAudience): Effect.Effect<Answer>;
62
+ /** A refusal: `code` is `NOT_ALLOWED` when it's left out. Was `reject()`. Any decision answers one. */
63
+ export declare const reject: (refusal: RejectInput) => Effect.Effect<Rejected>;
46
64
  /**
47
65
  * Git's own rules, which a host names when it has none of its own: a signed-in caller may do
48
66
  * anything its credential's ceiling lets it but mint a token for anyone else, and an anonymous one
@@ -54,7 +72,9 @@ export declare const reject: (refusal: RejectInput) => Effect.Effect<Answer>;
54
72
  * refuses, so accepting it would lift every `Rules.protect` and `Rules.lock` for whoever may push.
55
73
  * It allows every other operation kind, one Git adds later too, to any signed-in caller, so a host
56
74
  * that wants a new kind closed until it decides writes its own policy. It names no one an admin:
57
- * it refuses a caller on an `admin` token, and the minting of one.
75
+ * it refuses a caller on an `admin` token, and the minting of one. So it refuses `work.listById`,
76
+ * an admin's read of any repo's work by its internal ID, to everyone, `NOT_ALLOWED`: only a host's
77
+ * own policy grants it, as `ref0-git init`'s does for its admin.
58
78
  */
59
79
  export declare const signedIn: PolicyService;
60
80
  export { policy_d_exports };
@@ -23,9 +23,10 @@ var Policy = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/Policy"
23
23
  const make = (authorize) => ({ authorize });
24
24
  /** The Layer: a policy, or an Effect that builds one from the host's own services. */
25
25
  const layer = (policy) => Effect.isEffect(policy) ? Layer.effect(Policy, policy) : Layer.succeed(Policy, policy);
26
- /** An `accept`, or for `refs.private`, the caller's audience. Was `accept()`. */
27
- const accept = (value) => Effect.succeed(value === void 0 ? accept$1() : accept$1(value));
28
- /** A refusal: `code` is `NOT_ALLOWED` when it's left out. Was `reject()`. */
26
+ function accept(value) {
27
+ return Effect.succeed(value === void 0 ? accept$1() : accept$1(value));
28
+ }
29
+ /** A refusal: `code` is `NOT_ALLOWED` when it's left out. Was `reject()`. Any decision answers one. */
29
30
  const reject = (refusal) => Effect.succeed(reject$1(refusal));
30
31
  /**
31
32
  * Whether `self`, the caller's `subject ?? actor`, mints `token` for themselves: they're its
@@ -44,10 +45,13 @@ const mintsForSelf = (self, token) => token.subject.id === self.id && token.acto
44
45
  * refuses, so accepting it would lift every `Rules.protect` and `Rules.lock` for whoever may push.
45
46
  * It allows every other operation kind, one Git adds later too, to any signed-in caller, so a host
46
47
  * that wants a new kind closed until it decides writes its own policy. It names no one an admin:
47
- * it refuses a caller on an `admin` token, and the minting of one.
48
+ * it refuses a caller on an `admin` token, and the minting of one. So it refuses `work.listById`,
49
+ * an admin's read of any repo's work by its internal ID, to everyone, `NOT_ALLOWED`: only a host's
50
+ * own policy grants it, as `ref0-git init`'s does for its admin.
48
51
  */
49
52
  const signedIn = make(({ caller, operation, repo }) => {
50
53
  if (bypassKinds.has(operation.kind)) return reject({ message: "No rule is lifted for anyone" });
54
+ if (operation.kind === "work.listById") return reject({ message: "Only a host's own policy grants a read of work by internal ID" });
51
55
  if (caller.token?.scope === "admin" || operation.kind === "token.create" && operation.scope === "admin") return reject({ message: "No one holds an admin token here" });
52
56
  const { actor } = caller;
53
57
  if (actor.anonymous !== true) {
@@ -23,8 +23,7 @@ declare const TokensBase_base: Context.ServiceClass<TokensBase, "@ref0/git/auth/
23
23
  readonly held: Effect.Effect<HeldTokens | undefined>;
24
24
  }>;
25
25
  /**
26
- * Core's tokens, which no host provides: `Tokens.layer()` turns them on once Git has opened, and the
27
- * `tokens()` bridge as it opens. Until then `identify` sends a `gt_` credential on to the grants,
26
+ * Core's tokens, which no host provides: `Tokens.layer()` turns them on once Git has opened. Until then `identify` sends a `gt_` credential on to the grants,
28
27
  * and the server has no `tokens` group.
29
28
  */
30
29
  export declare class TokensBase extends /* @__PURE__ */ TokensBase_base {}
@@ -6,10 +6,9 @@ import * as Context from "effect/Context";
6
6
  import * as Layer from "effect/Layer";
7
7
  // src/auth/tokens-layer.ts
8
8
  /** A token call on a server with none of Git's own tokens on: REST's answer, and a joined face's. */
9
- const noTokens = /* @__PURE__ */ gitError("NOT_FOUND", "This server doesn't have tokens turned on", { hostHint: "Provide Tokens.layer(), or pass tokens() to createGitServer" });
9
+ const noTokens = /* @__PURE__ */ gitError("NOT_FOUND", "This server doesn't have tokens turned on", { hostHint: "Provide Tokens.layer()" });
10
10
  /**
11
- * Core's tokens, which no host provides: `Tokens.layer()` turns them on once Git has opened, and the
12
- * `tokens()` bridge as it opens. Until then `identify` sends a `gt_` credential on to the grants,
11
+ * Core's tokens, which no host provides: `Tokens.layer()` turns them on once Git has opened. Until then `identify` sends a `gt_` credential on to the grants,
13
12
  * and the server has no `tokens` group.
14
13
  */
15
14
  var TokensBase = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/auth/TokensBase")) {};
@@ -1,6 +1,6 @@
1
- import { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
1
+ import { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TrustedWriteInput, VerifiedToken, create, get, grantScopes, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
2
2
  import { layer } from "./tokens-layer.mjs";
3
3
  declare namespace tokens_public_d_exports {
4
- export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates };
4
+ export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates };
5
5
  }
6
- export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_d_exports };
6
+ export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_d_exports };
@@ -5,17 +5,10 @@ import { InternalRepoId } from "../contracts/ids.mjs";
5
5
  import "../contracts/operations.mjs";
6
6
  import "../contracts/result.mjs";
7
7
  import { EffectCalls } from "../contracts/services.mjs";
8
- import { TokenCalls, TokensFeature } from "../contracts/tokens.mjs";
8
+ import { TokenCalls } from "../contracts/tokens.mjs";
9
9
  import "../store/outbox.mjs";
10
10
  import "effect/Effect";
11
11
  import { JobDefinition, Moment, Read, Row } from "@ref0/infra";
12
- /**
13
- * Turns on Git's own tokens. A token's scope is its ceiling, which the host's `Policy` narrows and
14
- * never opens: an `admin` token, over the whole host alone, reaches every operation, but only as
15
- * far as the policy accepts it. `Policy.signedIn` refuses it, so a host that mints one writes its
16
- * own policy, naming who may hold it.
17
- */
18
- export declare const tokens: () => TokensFeature;
19
12
  /** Git's token calls, where a create or a list may name the repo `authorize` checked, as `held`. */
20
13
  export interface HeldTokenCalls extends EffectCalls<TokenCalls> {
21
14
  readonly create: (...args: [...Parameters<EffectCalls<TokenCalls>['create']>, held?: InternalRepoId]) => ReturnType<EffectCalls<TokenCalls>['create']>;
@@ -14,13 +14,6 @@ import * as Schema from "effect/Schema";
14
14
  import { CurrentJob, Job } from "@ref0/infra";
15
15
  import * as Random from "effect/Random";
16
16
  // src/auth/tokens.ts
17
- /**
18
- * Turns on Git's own tokens. A token's scope is its ceiling, which the host's `Policy` narrows and
19
- * never opens: an `admin` token, over the whole host alone, reaches every operation, but only as
20
- * far as the policy accepts it. `Policy.signedIn` refuses it, so a host that mints one writes its
21
- * own policy, naming who may hold it.
22
- */
23
- const tokens = () => ({ kind: "tokens" });
24
17
  const day = 864e5;
25
18
  /** The longest a token may live. */
26
19
  const maxTokenLife = 365 * day;
@@ -389,4 +382,4 @@ const tokenCleanupJob = (now) => gitJob(TokenCleanupJob, () => Effect.flatMap(Ef
389
382
  CurrentJob.store,
390
383
  CurrentJob.current
391
384
  ]), ([at, store, job]) => cleanupScope(store, job.scope, at)));
392
- export { isPrefixTarget, keptAfterExpiry, maxTokenLife, readTarget, tokenCalls, tokenCleanupJob, tokenCleanupName, tokenExpiry, tokenParties, tokens };
385
+ export { isPrefixTarget, keptAfterExpiry, maxTokenLife, readTarget, tokenCalls, tokenCleanupJob, tokenCleanupName, tokenExpiry, tokenParties };
package/dist/auth.d.mts CHANGED
@@ -1,8 +1,5 @@
1
1
  import { accessHeader } from "./auth/access-jwt.mjs";
2
- import { BasicOptions, BearerOptions, basic, bearer } from "./auth/helpers.mjs";
3
- import { tokens } from "./auth/tokens.mjs";
4
2
  import { ghClientId } from "./signin/context.mjs";
5
3
  import { ghWriteScope } from "./contracts/signin.mjs";
6
4
  import { AccessTokenAnswer, DeviceCodeAnswer, deviceGrant, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "./signin/wire.mjs";
7
- import { TokensFeature } from "./contracts/tokens.mjs";
8
- export { type AccessTokenAnswer, type BasicOptions, type BearerOptions, type DeviceCodeAnswer, type TokensFeature, accessHeader, basic, bearer, deviceGrant, ghClientId, ghWriteScope, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths, tokens };
5
+ export { type AccessTokenAnswer, type DeviceCodeAnswer, accessHeader, deviceGrant, ghClientId, ghWriteScope, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths };
package/dist/auth.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  import { accessHeader } from "./auth/access-jwt.mjs";
2
- import { basic, bearer } from "./auth/helpers.mjs";
3
- import { tokens } from "./auth/tokens.mjs";
4
2
  import { ghClientId } from "./signin/context.mjs";
5
3
  import { ghWriteScope } from "./contracts/signin.mjs";
6
4
  import { deviceGrant, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "./signin/wire.mjs";
7
- export { accessHeader, basic, bearer, deviceGrant, ghClientId, ghWriteScope, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths, tokens };
5
+ export { accessHeader, deviceGrant, ghClientId, ghWriteScope, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths };
@@ -2,6 +2,7 @@ import { tryUnlessSpent } from "../contracts/calls-spent.mjs";
2
2
  import { PushUploadRequest } from "../contracts/push-uploads.mjs";
3
3
  import { fail, gitError, isGitErrorCode, refusalCodeHeader } from "../contracts/result.mjs";
4
4
  import { boundedBytes } from "../protocol/bytes/reader.mjs";
5
+ import { retryAfterOf } from "../protocol/wire/push-uploads.mjs";
5
6
  import { jsonIssue } from "../protocol/wire/json.mjs";
6
7
  import { emptyReads, emptyReadsMost } from "./answer.mjs";
7
8
  import { bodyText, dropped, remoteFetch } from "./transport.mjs";
@@ -80,6 +81,15 @@ const heldBody = (body, most, what) => boundedBytes(body, most, (reader) => tryU
80
81
  most: emptyReadsMost,
81
82
  error: emptyReads(what)
82
83
  }).pipe(Effect.flatMap((held) => held === void 0 ? Effect.fail(tooLong(what, most)) : Effect.succeed(held)));
84
+ /** A 202's `Retry-After` in seconds; one that isn't a count of them, as a date, waits the least. */
85
+ const waitOf = (response) => {
86
+ const header = response.headers.get("retry-after")?.trim() ?? "";
87
+ const seconds = /^[0-9]+$/.test(header) ? Number(header) : 1;
88
+ return {
89
+ kind: "wait",
90
+ seconds: retryAfterOf(seconds)
91
+ };
92
+ };
83
93
  /** A bucket's refusal, as `retry` sees it: its status alone, its body never read. */
84
94
  const statusOnly = (response) => Effect.succeed({ status: response.status });
85
95
  /**
@@ -162,10 +172,11 @@ const gitHttp = (options) => {
162
172
  }
163
173
  });
164
174
  /** A POST to `path` under the repo, at the base when it's sent, once an advertisement moved it. */
165
- const send = (path, init) => Effect.suspend(() => Effect.flatMap(answer(new Request(`${base}/${path}`, {
175
+ const sent = (path, init) => Effect.suspend(() => answer(new Request(`${base}/${path}`, {
166
176
  method: "POST",
167
177
  ...init
168
- })), answered));
178
+ })));
179
+ const send = (path, init) => Effect.flatMap(sent(path, init), answered);
169
180
  /** A POST to `path` of a body `open` streams, a request made afresh for each send. */
170
181
  const sendStreamed = (path, init, open) => Effect.suspend(() => {
171
182
  const at = `${base}/${path}`;
@@ -192,10 +203,13 @@ const gitHttp = (options) => {
192
203
  body
193
204
  }) : sendStreamed(service, init, body);
194
205
  },
195
- postJson: (path, body) => Effect.flatMap(requestJson(body), (json) => send(path, {
206
+ postJson: (path, body) => Effect.flatMap(requestJson(body), (json) => Effect.flatMap(sent(path, {
196
207
  headers: { "content-type": "application/json" },
197
208
  body: json
198
- })),
209
+ }), (response) => response.status === 202 ? Effect.as(dropped(response), waitOf(response)) : Effect.map(answered(response), (read) => ({
210
+ kind: "answered",
211
+ body: read
212
+ })))),
199
213
  putSigned: putSigned(options)
200
214
  };
201
215
  };
@@ -3,16 +3,18 @@ import { tryUnlessSpent } from "../contracts/calls-spent.mjs";
3
3
  import { fail, gitError, isGitError } from "../contracts/result.mjs";
4
4
  import { scopedReader } from "../protocol/bytes/reader.mjs";
5
5
  import { decodeJson } from "../protocol/wire/json.mjs";
6
- import { pushUploadAbove } from "../protocol/wire/push-uploads.mjs";
6
+ import { completeMost, pushUploadAbove } from "../protocol/wire/push-uploads.mjs";
7
7
  import { readableIn } from "../store/crossing.mjs";
8
8
  import { emptyReadsMost } from "./answer.mjs";
9
9
  import { heldBody } from "./git-http.mjs";
10
+ import * as Clock$1 from "effect/Clock";
10
11
  import * as Effect from "effect/Effect";
11
12
  import * as Option from "effect/Option";
12
13
  import * as Cause from "effect/Cause";
13
14
  import * as Result from "effect/Result";
14
15
  import * as Context from "effect/Context";
15
16
  import * as Stream from "effect/Stream";
17
+ import * as Duration from "effect/Duration";
16
18
  // src/client/push-upload.ts
17
19
  /** The most of a begin's or a part's JSON answer read. */
18
20
  const answerMost = 65536;
@@ -187,17 +189,19 @@ const takesUpload = (capabilities, bytes) => {
187
189
  const above = pushUploadAbove(capabilities);
188
190
  return above !== void 0 && bytes > above;
189
191
  };
190
- /** `body`'s JSON, decoded as `schema`; `what` names the answer in its error. */
191
- const jsonOf = /* @__PURE__ */ Effect.fnUntraced(function* (body, schema, what) {
192
- const text = new TextDecoder().decode(yield* heldBody(body, answerMost, what));
192
+ /** `answer`'s JSON, decoded as `schema`; `what` names the answer in its error. */
193
+ const jsonOf = /* @__PURE__ */ Effect.fnUntraced(function* (answer, schema, what) {
194
+ if (answer.kind === "wait") return yield* fail("UNAVAILABLE", `The remote answered its ${what} with a 202, not the JSON`);
195
+ const text = new TextDecoder().decode(yield* heldBody(answer.body, answerMost, what));
193
196
  return yield* Result.match(decodeJson(schema)(text), {
194
197
  onFailure: (why) => fail("UNAVAILABLE", `The remote's ${what} isn't the JSON it sends: ${why}`),
195
198
  onSuccess: (value) => Effect.succeed(value)
196
199
  });
197
200
  });
198
201
  /**
199
- * `pack` uploaded for `begin`'s push: begin, each part's link and PUT in order, then complete.
200
- * Complete's answer, unread: `git-receive-pack`'s report on side-band-64k.
202
+ * `pack` uploaded for `begin`'s push: begin, each part's link and PUT in order, then complete,
203
+ * sent again each time it answers 202, after the wait its `Retry-After` asks, for `completeMost`
204
+ * at most. Complete's last answer, unread: `git-receive-pack`'s report on side-band-64k.
201
205
  */
202
206
  const uploadPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, begin, pack) {
203
207
  const started = yield* jsonOf(yield* http.postJson("push-uploads", begin), PushUploadStarted, "push upload");
@@ -215,6 +219,28 @@ const uploadPush = /* @__PURE__ */ Effect.fnUntraced(function* (http, begin, pac
215
219
  etag
216
220
  });
217
221
  }
218
- return yield* http.postJson(`${upload}/complete`, { parts });
222
+ return yield* completed(http, `${upload}/complete`, { parts });
223
+ });
224
+ /**
225
+ * Complete sent until it answers with the report, waiting as each 202 asks, for at most
226
+ * `completeMost` from the first: its requests and its waits both count, a request still unanswered
227
+ * then is let go, and a wait is cut to what's left.
228
+ */
229
+ const completed = /* @__PURE__ */ Effect.fnUntraced(function* (http, path, finish) {
230
+ const deadline = (yield* Clock$1.currentTimeMillis) + completeMost;
231
+ const stillReceiving = fail("UNAVAILABLE", "The remote still receives the push upload", { hint: "Push again" });
232
+ const left = Effect.map(Clock$1.currentTimeMillis, (now) => deadline - now);
233
+ for (;;) {
234
+ const sending = yield* left;
235
+ if (sending <= 0) return yield* stillReceiving;
236
+ const answer = yield* Effect.timeoutOrElse(http.postJson(path, finish), {
237
+ duration: Duration.millis(sending),
238
+ orElse: () => stillReceiving
239
+ });
240
+ if (answer.kind === "answered") return answer.body;
241
+ const waiting = yield* left;
242
+ if (waiting <= 0) return yield* stillReceiving;
243
+ yield* Effect.sleep(Duration.millis(Math.min(answer.seconds * 1e3, waiting)));
244
+ }
219
245
  });
220
246
  export { brokenBy, fetchedBody, heldOrCounted, packBody, packHeldMost, packInMemory, packInOrder, takesUpload, uploadPush };