@ref0/git 0.2.0 → 0.3.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 (113) hide show
  1. package/dist/auth/authorize.d.mts +1 -1
  2. package/dist/auth/fences.d.mts +1 -1
  3. package/dist/auth/host-function.mjs +2 -2
  4. package/dist/auth/identify.d.mts +1 -1
  5. package/dist/auth/tokens.d.mts +1 -1
  6. package/dist/client/client.mjs +2 -3
  7. package/dist/client/local.mjs +13 -3
  8. package/dist/contracts/calls-spent.mjs +3 -2
  9. package/dist/contracts/client.d.mts +2 -2
  10. package/dist/contracts/handlers.d.mts +2 -1
  11. package/dist/contracts/objects.d.mts +2 -2
  12. package/dist/contracts/promises.d.mts +13 -38
  13. package/dist/contracts/promises.mjs +13 -0
  14. package/dist/contracts/queue.d.mts +2 -1
  15. package/dist/contracts/result.d.mts +7 -0
  16. package/dist/contracts/server.d.mts +67 -40
  17. package/dist/contracts/sync.d.mts +1 -1
  18. package/dist/contracts/topics.d.mts +7 -1
  19. package/dist/core/access.d.mts +1 -1
  20. package/dist/core/call-names.d.mts +1 -0
  21. package/dist/core/call-names.mjs +93 -0
  22. package/dist/core/events/deliver.mjs +14 -7
  23. package/dist/core/events/stream.d.mts +1 -1
  24. package/dist/core/events/stream.mjs +8 -1
  25. package/dist/core/hooks/post-receive.mjs +15 -7
  26. package/dist/core/promise.mjs +28 -10
  27. package/dist/core/push.mjs +2 -1
  28. package/dist/core/seam.d.mts +2 -0
  29. package/dist/core/seam.mjs +19 -6
  30. package/dist/extend.d.mts +2 -1
  31. package/dist/extend.mjs +3 -1
  32. package/dist/index.d.mts +2 -2
  33. package/dist/lfs/objects.mjs +1 -1
  34. package/dist/lfs/rows.mjs +1 -1
  35. package/dist/queue/advance.mjs +2 -1
  36. package/dist/queue/host.d.mts +1 -1
  37. package/dist/queue/host.mjs +1 -1
  38. package/dist/queue/schedule.mjs +1 -1
  39. package/dist/rest/blobs.d.mts +15 -15
  40. package/dist/rest/client.mjs +2 -2
  41. package/dist/rest/commits.d.mts +91 -91
  42. package/dist/rest/errors.d.mts +2 -2
  43. package/dist/rest/errors.mjs +2 -2
  44. package/dist/rest/files.d.mts +81 -81
  45. package/dist/rest/handler.d.mts +1 -0
  46. package/dist/rest/handler.mjs +39 -16
  47. package/dist/rest/handlers.mjs +6 -6
  48. package/dist/rest/repos.d.mts +38 -38
  49. package/dist/rest/tags.d.mts +41 -41
  50. package/dist/rest/tokens.d.mts +145 -145
  51. package/dist/rest/work.d.mts +43 -43
  52. package/dist/server/extension.d.mts +6 -3
  53. package/dist/server/extension.mjs +39 -31
  54. package/dist/server/lifecycle.d.mts +3 -0
  55. package/dist/server/lifecycle.mjs +89 -0
  56. package/dist/server/routes.d.mts +7 -4
  57. package/dist/server/routes.mjs +12 -19
  58. package/dist/server/server.d.mts +8 -2
  59. package/dist/server/server.mjs +280 -104
  60. package/dist/signin/context.d.mts +1 -1
  61. package/dist/signin/grants.d.mts +1 -1
  62. package/dist/storage/bits.mjs +41 -0
  63. package/dist/storage/calls.d.mts +1 -1
  64. package/dist/storage/calls.mjs +2 -2
  65. package/dist/storage/fetch.d.mts +3 -1
  66. package/dist/storage/fetch.mjs +230 -24
  67. package/dist/storage/index-bitmaps.d.mts +1 -1
  68. package/dist/storage/index-build.d.mts +1 -1
  69. package/dist/storage/index-build.mjs +27 -13
  70. package/dist/storage/index-fetch.d.mts +1 -0
  71. package/dist/storage/index-fetch.mjs +103 -182
  72. package/dist/storage/index-graph.d.mts +1 -1
  73. package/dist/storage/loose.mjs +3 -2
  74. package/dist/storage/pack-order.d.mts +1 -1
  75. package/dist/storage/pack-order.mjs +3 -1
  76. package/dist/storage/pack-ranges.d.mts +1 -1
  77. package/dist/storage/pack-reads.d.mts +1 -1
  78. package/dist/storage/pack-reads.mjs +17 -0
  79. package/dist/storage/pack-receive.d.mts +2 -2
  80. package/dist/storage/pack-receive.mjs +1 -1
  81. package/dist/storage/packs.d.mts +2 -2
  82. package/dist/storage/packs.mjs +10 -7
  83. package/dist/storage/push-uploads.mjs +2 -1
  84. package/dist/storage/ready.d.mts +2 -2
  85. package/dist/storage/receive-links.mjs +1 -1
  86. package/dist/storage/repack.d.mts +2 -2
  87. package/dist/storage/rows.d.mts +2 -1
  88. package/dist/storage/rows.mjs +1 -1
  89. package/dist/storage/send-list.d.mts +8 -0
  90. package/dist/storage/send-list.mjs +319 -0
  91. package/dist/storage/shallow.d.mts +1 -2
  92. package/dist/storage/unpack.mjs +5 -3
  93. package/dist/storage/walk.d.mts +2 -1
  94. package/dist/storage/walk.mjs +14 -8
  95. package/dist/store/catalogue.d.mts +1 -1
  96. package/dist/store/closed.d.mts +21 -0
  97. package/dist/store/closed.mjs +34 -0
  98. package/dist/store/crossing.mjs +9 -6
  99. package/dist/store/cursor-seal.mjs +4 -1
  100. package/dist/store/errors.mjs +13 -7
  101. package/dist/store/outbox.mjs +4 -2
  102. package/dist/store/promises.d.mts +5 -0
  103. package/dist/store/promises.mjs +258 -0
  104. package/dist/sync/bound.mjs +9 -4
  105. package/dist/sync/jobs.d.mts +3 -3
  106. package/dist/sync/jobs.mjs +28 -25
  107. package/dist/sync/tries.mjs +2 -2
  108. package/dist/topics/advance.mjs +2 -1
  109. package/dist/topics/calls.mjs +3 -3
  110. package/dist/topics/host.d.mts +1 -1
  111. package/dist/topics/host.mjs +1 -1
  112. package/dist/topics/topic.mjs +22 -7
  113. package/package.json +2 -2
@@ -2,97 +2,7 @@ import { JsonHttpError } from "./errors.mjs";
2
2
  import { GitCallerMiddleware, GitRestServices } from "./caller.mjs";
3
3
  import * as Schema from "effect/Schema";
4
4
  import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api";
5
- declare const CommitsApiGroup_base: HttpApiGroup.HttpApiGroup<"commits", HttpApiEndpoint.HttpApiEndpoint<"list", "GET", "/repos/:repo/-/commits", Schema.toCodecStringTree<Schema.Struct<{
6
- repo: Schema.String;
7
- }>>, Schema.toCodecStringTree<Schema.Struct<{
8
- after: Schema.optionalKey<Schema.String>;
9
- limit: Schema.optionalKey<Schema.Int>;
10
- objects: Schema.optionalKey<Schema.Int>;
11
- bytes: Schema.optionalKey<Schema.Int>;
12
- entries: Schema.optionalKey<Schema.Int>;
13
- milliseconds: Schema.optionalKey<Schema.Int>;
14
- ref: Schema.String;
15
- path: Schema.optionalKey<Schema.String>;
16
- }>>, never, never, Schema.toCodecJson<Schema.Struct<{
17
- readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
18
- readonly oid: Schema.String;
19
- readonly tree: Schema.String;
20
- readonly parents: Schema.$Array<Schema.String>;
21
- readonly author: Schema.Struct<{
22
- readonly name: Schema.String;
23
- readonly email: Schema.String;
24
- readonly at: Schema.Number;
25
- readonly offset: Schema.Int;
26
- }>;
27
- readonly committer: Schema.Struct<{
28
- readonly name: Schema.String;
29
- readonly email: Schema.String;
30
- readonly at: Schema.Number;
31
- readonly offset: Schema.Int;
32
- }>;
33
- readonly subject: Schema.String;
34
- readonly message: Schema.String;
35
- readonly signature: Schema.optionalKey<Schema.String>;
36
- }>>>;
37
- readonly next: Schema.optionalKey<Schema.String>;
38
- }>>, Schema.toCodecJson<HttpApiSchema.encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
39
- "ref0-code": Schema.String;
40
- }> | HttpApiSchema.encodeToWithHeaders<Schema.Struct<{
41
- code: Schema.Literal<"UNAUTHENTICATED">;
42
- message: Schema.String;
43
- hint: Schema.optionalKey<Schema.String>;
44
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
45
- }>, Schema.Struct<{
46
- code: Schema.Literal<"UNAUTHENTICATED">;
47
- message: Schema.String;
48
- hint: Schema.optionalKey<Schema.String>;
49
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
50
- }>, {
51
- "ref0-code": Schema.String;
52
- 'www-authenticate': Schema.String;
53
- }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"get", "GET", "/repos/:repo/-/commits/:oid", Schema.toCodecStringTree<Schema.Struct<{
54
- repo: Schema.String;
55
- oid: Schema.String;
56
- }>>, Schema.toCodecStringTree<Schema.Struct<{
57
- objects: Schema.optionalKey<Schema.Int>;
58
- bytes: Schema.optionalKey<Schema.Int>;
59
- entries: Schema.optionalKey<Schema.Int>;
60
- milliseconds: Schema.optionalKey<Schema.Int>;
61
- }>>, never, never, Schema.toCodecJson<Schema.Struct<{
62
- readonly oid: Schema.String;
63
- readonly tree: Schema.String;
64
- readonly parents: Schema.$Array<Schema.String>;
65
- readonly author: Schema.Struct<{
66
- readonly name: Schema.String;
67
- readonly email: Schema.String;
68
- readonly at: Schema.Number;
69
- readonly offset: Schema.Int;
70
- }>;
71
- readonly committer: Schema.Struct<{
72
- readonly name: Schema.String;
73
- readonly email: Schema.String;
74
- readonly at: Schema.Number;
75
- readonly offset: Schema.Int;
76
- }>;
77
- readonly subject: Schema.String;
78
- readonly message: Schema.String;
79
- readonly signature: Schema.optionalKey<Schema.String>;
80
- }>>, Schema.toCodecJson<HttpApiSchema.encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
81
- "ref0-code": Schema.String;
82
- }> | HttpApiSchema.encodeToWithHeaders<Schema.Struct<{
83
- code: Schema.Literal<"UNAUTHENTICATED">;
84
- message: Schema.String;
85
- hint: Schema.optionalKey<Schema.String>;
86
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
87
- }>, Schema.Struct<{
88
- code: Schema.Literal<"UNAUTHENTICATED">;
89
- message: Schema.String;
90
- hint: Schema.optionalKey<Schema.String>;
91
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
92
- }>, {
93
- "ref0-code": Schema.String;
94
- 'www-authenticate': Schema.String;
95
- }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"create", "POST", "/repos/:repo/-/commits", Schema.toCodecStringTree<Schema.Struct<{
5
+ declare const CommitsApiGroup_base: HttpApiGroup.HttpApiGroup<"commits", HttpApiEndpoint.HttpApiEndpoint<"create", "POST", "/repos/:repo/-/commits", Schema.toCodecStringTree<Schema.Struct<{
96
6
  repo: Schema.String;
97
7
  }>>, never, Schema.toCodecJson<Schema.Struct<{
98
8
  readonly key: Schema.optionalKey<Schema.String>;
@@ -425,6 +335,96 @@ declare const CommitsApiGroup_base: HttpApiGroup.HttpApiGroup<"commits", HttpApi
425
335
  }>, {
426
336
  "ref0-code": Schema.String;
427
337
  'www-authenticate': Schema.String;
338
+ }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"list", "GET", "/repos/:repo/-/commits", Schema.toCodecStringTree<Schema.Struct<{
339
+ repo: Schema.String;
340
+ }>>, Schema.toCodecStringTree<Schema.Struct<{
341
+ after: Schema.optionalKey<Schema.String>;
342
+ limit: Schema.optionalKey<Schema.Int>;
343
+ objects: Schema.optionalKey<Schema.Int>;
344
+ bytes: Schema.optionalKey<Schema.Int>;
345
+ entries: Schema.optionalKey<Schema.Int>;
346
+ milliseconds: Schema.optionalKey<Schema.Int>;
347
+ ref: Schema.String;
348
+ path: Schema.optionalKey<Schema.String>;
349
+ }>>, never, never, Schema.toCodecJson<Schema.Struct<{
350
+ readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
351
+ readonly oid: Schema.String;
352
+ readonly tree: Schema.String;
353
+ readonly parents: Schema.$Array<Schema.String>;
354
+ readonly author: Schema.Struct<{
355
+ readonly name: Schema.String;
356
+ readonly email: Schema.String;
357
+ readonly at: Schema.Number;
358
+ readonly offset: Schema.Int;
359
+ }>;
360
+ readonly committer: Schema.Struct<{
361
+ readonly name: Schema.String;
362
+ readonly email: Schema.String;
363
+ readonly at: Schema.Number;
364
+ readonly offset: Schema.Int;
365
+ }>;
366
+ readonly subject: Schema.String;
367
+ readonly message: Schema.String;
368
+ readonly signature: Schema.optionalKey<Schema.String>;
369
+ }>>>;
370
+ readonly next: Schema.optionalKey<Schema.String>;
371
+ }>>, Schema.toCodecJson<HttpApiSchema.encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
372
+ "ref0-code": Schema.String;
373
+ }> | HttpApiSchema.encodeToWithHeaders<Schema.Struct<{
374
+ code: Schema.Literal<"UNAUTHENTICATED">;
375
+ message: Schema.String;
376
+ hint: Schema.optionalKey<Schema.String>;
377
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
378
+ }>, Schema.Struct<{
379
+ code: Schema.Literal<"UNAUTHENTICATED">;
380
+ message: Schema.String;
381
+ hint: Schema.optionalKey<Schema.String>;
382
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
383
+ }>, {
384
+ "ref0-code": Schema.String;
385
+ 'www-authenticate': Schema.String;
386
+ }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"get", "GET", "/repos/:repo/-/commits/:oid", Schema.toCodecStringTree<Schema.Struct<{
387
+ repo: Schema.String;
388
+ oid: Schema.String;
389
+ }>>, Schema.toCodecStringTree<Schema.Struct<{
390
+ objects: Schema.optionalKey<Schema.Int>;
391
+ bytes: Schema.optionalKey<Schema.Int>;
392
+ entries: Schema.optionalKey<Schema.Int>;
393
+ milliseconds: Schema.optionalKey<Schema.Int>;
394
+ }>>, never, never, Schema.toCodecJson<Schema.Struct<{
395
+ readonly oid: Schema.String;
396
+ readonly tree: Schema.String;
397
+ readonly parents: Schema.$Array<Schema.String>;
398
+ readonly author: Schema.Struct<{
399
+ readonly name: Schema.String;
400
+ readonly email: Schema.String;
401
+ readonly at: Schema.Number;
402
+ readonly offset: Schema.Int;
403
+ }>;
404
+ readonly committer: Schema.Struct<{
405
+ readonly name: Schema.String;
406
+ readonly email: Schema.String;
407
+ readonly at: Schema.Number;
408
+ readonly offset: Schema.Int;
409
+ }>;
410
+ readonly subject: Schema.String;
411
+ readonly message: Schema.String;
412
+ readonly signature: Schema.optionalKey<Schema.String>;
413
+ }>>, Schema.toCodecJson<HttpApiSchema.encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
414
+ "ref0-code": Schema.String;
415
+ }> | HttpApiSchema.encodeToWithHeaders<Schema.Struct<{
416
+ code: Schema.Literal<"UNAUTHENTICATED">;
417
+ message: Schema.String;
418
+ hint: Schema.optionalKey<Schema.String>;
419
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
420
+ }>, Schema.Struct<{
421
+ code: Schema.Literal<"UNAUTHENTICATED">;
422
+ message: Schema.String;
423
+ hint: Schema.optionalKey<Schema.String>;
424
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
425
+ }>, {
426
+ "ref0-code": Schema.String;
427
+ 'www-authenticate': Schema.String;
428
428
  }>>, GitCallerMiddleware, GitRestServices>, false>;
429
429
  /**
430
430
  * `commits`: `<r>/commits` lists a history and `<r>/commits/<oid>` reads a commit; `merge-base`,
@@ -2,10 +2,10 @@ import { GitError, GitErrorCode } from "../contracts/result.mjs";
2
2
  import "../client/transport.mjs";
3
3
  import * as Schema from "effect/Schema";
4
4
  import { HttpApiSchema } from "effect/http-api";
5
- /** What a refused call answers over HTTP: its `GitError`, less `cause`, which HTTP strips. */
5
+ /** What a refused call answers over HTTP: its `GitError`, less `cause` and `hostHint`, which HTTP strips. */
6
6
  export type JsonHttpError = { [Code in GitErrorCode]: Omit<Extract<GitError, {
7
7
  code: Code;
8
- }>, 'cause'>; }[GitErrorCode];
8
+ }>, 'cause' | 'hostHint'>; }[GitErrorCode];
9
9
  /**
10
10
  * Every call's errors, as each REST endpoint declares them: a rate limit before 413, and each code
11
11
  * in `ref0-code` beside its body.
@@ -124,7 +124,7 @@ const GitErrors = [
124
124
  ];
125
125
  /** The JSON a refused call answers, with its status: what the handler sends outside a route. */
126
126
  const jsonError = (error, init) => {
127
- const { cause: _cause, ...body } = error;
127
+ const { cause: _cause, hostHint: _hostHint, ...body } = error;
128
128
  const status = error.code === "RESOURCE_EXHAUSTED" && error.context?.reason === "rate-limited" ? 429 : httpStatus[error.code];
129
129
  const headers = new Headers(init?.headers);
130
130
  headers.set(refusalCodeHeader, error.code);
@@ -135,7 +135,7 @@ const jsonError = (error, init) => {
135
135
  headers
136
136
  });
137
137
  };
138
- /** A refused answer's body, as a client reads it: any `GitError` REST sends, less `cause`. */
138
+ /** A refused answer's body, as a client reads it: any `GitError` REST sends, less `cause` and `hostHint`. */
139
139
  const GitErrorBody = Schema.Union([
140
140
  InvalidArgument,
141
141
  UnauthenticatedBody,
@@ -2,7 +2,87 @@ import { JsonHttpError } from "./errors.mjs";
2
2
  import { GitCallerMiddleware, GitRestServices } from "./caller.mjs";
3
3
  import * as Schema from "effect/Schema";
4
4
  import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
5
- declare const FilesApiGroup_base: HttpApiGroup.HttpApiGroup<"files", HttpApiEndpoint.HttpApiEndpoint<"diff", "POST", "/repos/:repo/-/files/diff", Schema.toCodecStringTree<Schema.Struct<{
5
+ declare const FilesApiGroup_base: HttpApiGroup.HttpApiGroup<"files", HttpApiEndpoint.HttpApiEndpoint<"list", "GET", "/repos/:repo/-/files", Schema.toCodecStringTree<Schema.Struct<{
6
+ repo: Schema.String;
7
+ }>>, Schema.toCodecStringTree<Schema.Struct<{
8
+ after: Schema.optionalKey<Schema.String>;
9
+ limit: Schema.optionalKey<Schema.Int>;
10
+ objects: Schema.optionalKey<Schema.Int>;
11
+ bytes: Schema.optionalKey<Schema.Int>;
12
+ entries: Schema.optionalKey<Schema.Int>;
13
+ milliseconds: Schema.optionalKey<Schema.Int>;
14
+ ref: Schema.String;
15
+ path: Schema.optionalKey<Schema.String>;
16
+ recursive: Schema.optionalKey<Schema.Boolean>;
17
+ }>>, never, never, Schema.toCodecJson<Schema.Struct<{
18
+ readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
19
+ readonly name: Schema.String;
20
+ readonly path: Schema.String;
21
+ readonly mode: Schema.String;
22
+ readonly type: Schema.Literals<readonly ["blob", "tree", "commit"]>;
23
+ readonly oid: Schema.String;
24
+ readonly size: Schema.optionalKey<Schema.Int>;
25
+ readonly pathBytes: Schema.optionalKey<Schema.Uint8ArrayFromBase64>;
26
+ }>>>;
27
+ readonly next: Schema.optionalKey<Schema.String>;
28
+ }>>, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
29
+ "ref0-code": Schema.String;
30
+ }> | import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Struct<{
31
+ code: Schema.Literal<"UNAUTHENTICATED">;
32
+ message: Schema.String;
33
+ hint: Schema.optionalKey<Schema.String>;
34
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
35
+ }>, Schema.Struct<{
36
+ code: Schema.Literal<"UNAUTHENTICATED">;
37
+ message: Schema.String;
38
+ hint: Schema.optionalKey<Schema.String>;
39
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
40
+ }>, {
41
+ "ref0-code": Schema.String;
42
+ 'www-authenticate': Schema.String;
43
+ }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"read", "POST", "/repos/:repo/-/files/read", Schema.toCodecStringTree<Schema.Struct<{
44
+ repo: Schema.String;
45
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
46
+ readonly limits: Schema.optionalKey<Schema.Struct<{
47
+ objects: Schema.optionalKey<Schema.Int>;
48
+ bytes: Schema.optionalKey<Schema.Int>;
49
+ entries: Schema.optionalKey<Schema.Int>;
50
+ milliseconds: Schema.optionalKey<Schema.Int>;
51
+ }>>;
52
+ readonly ref: Schema.String;
53
+ readonly paths: Schema.$Array<Schema.String>;
54
+ readonly page: Schema.optionalKey<Schema.Struct<{
55
+ after: Schema.optionalKey<Schema.String>;
56
+ limit: Schema.optionalKey<Schema.Int>;
57
+ }>>;
58
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
59
+ readonly files: Schema.Struct<{
60
+ readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
61
+ readonly path: Schema.String;
62
+ readonly oid: Schema.String;
63
+ readonly mode: Schema.String;
64
+ readonly size: Schema.Int;
65
+ readonly content: Schema.optionalKey<Schema.Uint8ArrayFromBase64>;
66
+ }>>>;
67
+ readonly next: Schema.optionalKey<Schema.String>;
68
+ }>;
69
+ readonly missing: Schema.$Array<Schema.String>;
70
+ }>>, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
71
+ "ref0-code": Schema.String;
72
+ }> | import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Struct<{
73
+ code: Schema.Literal<"UNAUTHENTICATED">;
74
+ message: Schema.String;
75
+ hint: Schema.optionalKey<Schema.String>;
76
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
77
+ }>, Schema.Struct<{
78
+ code: Schema.Literal<"UNAUTHENTICATED">;
79
+ message: Schema.String;
80
+ hint: Schema.optionalKey<Schema.String>;
81
+ context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
82
+ }>, {
83
+ "ref0-code": Schema.String;
84
+ 'www-authenticate': Schema.String;
85
+ }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"diff", "POST", "/repos/:repo/-/files/diff", Schema.toCodecStringTree<Schema.Struct<{
6
86
  repo: Schema.String;
7
87
  }>>, never, Schema.toCodecJson<Schema.Struct<{
8
88
  readonly limits: Schema.optionalKey<Schema.Struct<{
@@ -90,86 +170,6 @@ declare const FilesApiGroup_base: HttpApiGroup.HttpApiGroup<"files", HttpApiEndp
90
170
  }>, {
91
171
  "ref0-code": Schema.String;
92
172
  'www-authenticate': Schema.String;
93
- }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"list", "GET", "/repos/:repo/-/files", Schema.toCodecStringTree<Schema.Struct<{
94
- repo: Schema.String;
95
- }>>, Schema.toCodecStringTree<Schema.Struct<{
96
- after: Schema.optionalKey<Schema.String>;
97
- limit: Schema.optionalKey<Schema.Int>;
98
- objects: Schema.optionalKey<Schema.Int>;
99
- bytes: Schema.optionalKey<Schema.Int>;
100
- entries: Schema.optionalKey<Schema.Int>;
101
- milliseconds: Schema.optionalKey<Schema.Int>;
102
- ref: Schema.String;
103
- path: Schema.optionalKey<Schema.String>;
104
- recursive: Schema.optionalKey<Schema.Boolean>;
105
- }>>, never, never, Schema.toCodecJson<Schema.Struct<{
106
- readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
107
- readonly name: Schema.String;
108
- readonly path: Schema.String;
109
- readonly mode: Schema.String;
110
- readonly type: Schema.Literals<readonly ["blob", "tree", "commit"]>;
111
- readonly oid: Schema.String;
112
- readonly size: Schema.optionalKey<Schema.Int>;
113
- readonly pathBytes: Schema.optionalKey<Schema.Uint8ArrayFromBase64>;
114
- }>>>;
115
- readonly next: Schema.optionalKey<Schema.String>;
116
- }>>, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
117
- "ref0-code": Schema.String;
118
- }> | import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Struct<{
119
- code: Schema.Literal<"UNAUTHENTICATED">;
120
- message: Schema.String;
121
- hint: Schema.optionalKey<Schema.String>;
122
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
123
- }>, Schema.Struct<{
124
- code: Schema.Literal<"UNAUTHENTICATED">;
125
- message: Schema.String;
126
- hint: Schema.optionalKey<Schema.String>;
127
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
128
- }>, {
129
- "ref0-code": Schema.String;
130
- 'www-authenticate': Schema.String;
131
- }>>, GitCallerMiddleware, GitRestServices> | HttpApiEndpoint.HttpApiEndpoint<"read", "POST", "/repos/:repo/-/files/read", Schema.toCodecStringTree<Schema.Struct<{
132
- repo: Schema.String;
133
- }>>, never, Schema.toCodecJson<Schema.Struct<{
134
- readonly limits: Schema.optionalKey<Schema.Struct<{
135
- objects: Schema.optionalKey<Schema.Int>;
136
- bytes: Schema.optionalKey<Schema.Int>;
137
- entries: Schema.optionalKey<Schema.Int>;
138
- milliseconds: Schema.optionalKey<Schema.Int>;
139
- }>>;
140
- readonly ref: Schema.String;
141
- readonly paths: Schema.$Array<Schema.String>;
142
- readonly page: Schema.optionalKey<Schema.Struct<{
143
- after: Schema.optionalKey<Schema.String>;
144
- limit: Schema.optionalKey<Schema.Int>;
145
- }>>;
146
- }>>, never, Schema.toCodecJson<Schema.Struct<{
147
- readonly files: Schema.Struct<{
148
- readonly items: Schema.mutable<Schema.$Array<Schema.Struct<{
149
- readonly path: Schema.String;
150
- readonly oid: Schema.String;
151
- readonly mode: Schema.String;
152
- readonly size: Schema.Int;
153
- readonly content: Schema.optionalKey<Schema.Uint8ArrayFromBase64>;
154
- }>>>;
155
- readonly next: Schema.optionalKey<Schema.String>;
156
- }>;
157
- readonly missing: Schema.$Array<Schema.String>;
158
- }>>, Schema.toCodecJson<import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Codec<JsonHttpError, unknown, never, never>, Schema.Codec<JsonHttpError, unknown, never, never>, {
159
- "ref0-code": Schema.String;
160
- }> | import("effect/http-api/HttpApiSchema").encodeToWithHeaders<Schema.Struct<{
161
- code: Schema.Literal<"UNAUTHENTICATED">;
162
- message: Schema.String;
163
- hint: Schema.optionalKey<Schema.String>;
164
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
165
- }>, Schema.Struct<{
166
- code: Schema.Literal<"UNAUTHENTICATED">;
167
- message: Schema.String;
168
- hint: Schema.optionalKey<Schema.String>;
169
- context: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{}>, readonly [Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean, Schema.$Array<Schema.String>, Schema.Undefined]>>]>>;
170
- }>, {
171
- "ref0-code": Schema.String;
172
- 'www-authenticate': Schema.String;
173
173
  }>>, GitCallerMiddleware, GitRestServices>, false>;
174
174
  /**
175
175
  * `files`: `<r>/files` lists a folder at a revision, `<r>/files/read` reads files by path, as
@@ -1,4 +1,5 @@
1
1
  import { GitServer } from "../contracts/server.mjs";
2
+ import "../store/promises.mjs";
2
3
  import "./caller.mjs";
3
4
  import "effect/Effect";
4
5
  import "effect/Context";
@@ -1,4 +1,5 @@
1
- import { partsOf } from "../core/seam.mjs";
1
+ import { lazyParts, seamOf } from "../core/seam.mjs";
2
+ import { isServerClosed } from "../store/closed.mjs";
2
3
  import { GitRestApi } from "./api.mjs";
3
4
  import { GitRestServices, IncomingRequest } from "./caller.mjs";
4
5
  import { jsonError } from "./errors.mjs";
@@ -16,14 +17,26 @@ import { HttpApiBuilder } from "effect/http-api";
16
17
  import * as HttpRouter from "effect/http/HttpRouter";
17
18
  import * as HttpServer from "effect/http/HttpServer";
18
19
  // src/rest/handler.ts
19
- /** A lookup's failure, as REST answers one: its `GitError`, or `INTERNAL` for a defect. */
20
- const failed = (cause) => Option.match(Cause.findErrorOption(cause), {
21
- onNone: () => jsonError({
22
- code: "INTERNAL",
23
- message: "The server failed"
24
- }),
25
- onSome: jsonError
26
- });
20
+ /**
21
+ * A lookup's failure, as REST answers one: its `GitError`, or `INTERNAL` for a defect. A closed
22
+ * server's rejection is rethrown as itself, as Git's own routes reject.
23
+ */
24
+ const failed = (cause) => {
25
+ const closed = cause.reasons.filter(Cause.isDieReason).find((reason) => isServerClosed(reason.defect));
26
+ if (closed !== void 0) throw closed.defect;
27
+ return Option.match(Cause.findErrorOption(cause), {
28
+ onNone: () => jsonError({
29
+ code: "INTERNAL",
30
+ message: "The server failed"
31
+ }),
32
+ onSome: jsonError
33
+ });
34
+ };
35
+ /** `door`'s refusal now, thrown when it's the closed one: a failed build answers as JSON. */
36
+ const askClosed = (door) => {
37
+ const refused = door.refusal();
38
+ if (refused !== void 0 && isServerClosed(refused)) throw refused;
39
+ };
27
40
  const notFound = () => jsonError({
28
41
  code: "NOT_FOUND",
29
42
  message: "Nothing is served at this URL"
@@ -55,10 +68,7 @@ const serveRest = (parts) => {
55
68
  const base = normalBase(parts.basePath);
56
69
  const app = HttpApiBuilder.layer(GitRestApi).pipe(Layer.provide(GitRestHandlers), Layer.provide([HttpServer.layerServices, Layer.succeedContext(parts.services)]));
57
70
  const web = HttpRouter.toWebHandler(app, { disableLogger: true });
58
- const owned = async (request) => {
59
- const url = new URL(request.url);
60
- const path = restPath(base, url.pathname);
61
- if (path === void 0) return void 0;
71
+ const answer = async (request, url, path) => {
62
72
  const context = Context.add(parts.services, IncomingRequest, request);
63
73
  const response = await web.handler(forRouter(request, url, path.path), context);
64
74
  const { repo, endpoint } = path;
@@ -69,6 +79,17 @@ const serveRest = (parts) => {
69
79
  if (Exit.isFailure(to)) return refused(to.cause) ? missed : failed(to.cause);
70
80
  return to.value === void 0 ? missed : redirect(url, base, endpoint, to.value);
71
81
  };
82
+ const owned = async (request) => {
83
+ const url = new URL(request.url);
84
+ const path = restPath(base, url.pathname);
85
+ if (path === void 0) return void 0;
86
+ askClosed(parts.door);
87
+ try {
88
+ return await answer(request, url, path);
89
+ } finally {
90
+ askClosed(parts.door);
91
+ }
92
+ };
72
93
  const route = async (request) => await owned(request) ?? await parts.route(request);
73
94
  return {
74
95
  fetch: async (request) => await route(request) ?? notFound(),
@@ -81,9 +102,10 @@ const serveRest = (parts) => {
81
102
  * `route`, then a JSON `404`; `route` answers the same and `undefined` outside them.
82
103
  */
83
104
  const createRestHandler = (git) => {
84
- const parts = partsOf(git);
85
- if (parts === void 0) throw new TypeError("createRestHandler takes a server createGitServer made");
86
- const { basePath, identify, authorize, callsFor, renamedTo, listen } = parts;
105
+ const seam = seamOf(git);
106
+ if (seam === void 0) throw new TypeError("createRestHandler takes a server createGitServer made");
107
+ const { basePath, identify, authorize, callsFor, renamedTo, listen } = lazyParts(seam);
108
+ const { door } = seam;
87
109
  const services = Context.make(GitRestServices, {
88
110
  basePath,
89
111
  identify,
@@ -96,6 +118,7 @@ const createRestHandler = (git) => {
96
118
  basePath,
97
119
  services,
98
120
  route: git.route,
121
+ door,
99
122
  renamedFor
100
123
  });
101
124
  return {
@@ -2,18 +2,18 @@ import { tokenParties } from "../auth/tokens.mjs";
2
2
  import { treeOrChanges } from "../core/objects/commit-writes.mjs";
3
3
  import { base64Size, jsonSize, responseTooLarge } from "../core/objects/reading.mjs";
4
4
  import { treeEditOf } from "../core/objects/tree-edits.mjs";
5
+ import { tryClosing } from "../store/closed.mjs";
5
6
  import { GitCaller } from "../contracts/services.mjs";
6
7
  import { GitRestApi } from "./api.mjs";
7
8
  import { GitCallerMiddleware, GitRestServices, IncomingRequest } from "./caller.mjs";
8
9
  import { sseResponse } from "./events.mjs";
9
- import { tryUnlessSpent } from "../contracts/calls-spent.mjs";
10
10
  import { answerSpent } from "../store/errors.mjs";
11
11
  import * as Effect from "effect/Effect";
12
12
  import * as Option from "effect/Option";
13
13
  import * as Layer from "effect/Layer";
14
+ import * as Stream from "effect/Stream";
14
15
  import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
15
16
  import * as HttpServerRequest from "effect/http/HttpServerRequest";
16
- import * as Stream from "effect/Stream";
17
17
  import { HttpApiSchemaError } from "effect/http-api/HttpApiError";
18
18
  // src/rest/handlers.ts
19
19
  /** `?after=&limit=` as a call's `page`, which is left out when the query names neither. */
@@ -48,7 +48,7 @@ const readInput = ({ after, limit, objects, bytes, milliseconds, ...filters }) =
48
48
  })
49
49
  });
50
50
  /** A file's bytes, read whole: a multi-file read answers JSON, each file's bytes as base64. */
51
- const contentOf = ({ bytes, ...file }) => tryUnlessSpent(async () => ({
51
+ const contentOf = ({ bytes, ...file }) => tryClosing(async () => ({
52
52
  ...file,
53
53
  content: new Uint8Array(await new Response(bytes).arrayBuffer())
54
54
  }), (cause) => ({
@@ -129,7 +129,7 @@ const commitInputOf = ({ tree, changes, ...fields }, by) => {
129
129
  const noTokens = {
130
130
  code: "NOT_FOUND",
131
131
  message: "This server doesn't have tokens turned on",
132
- hint: "Pass tokens() in the server's features"
132
+ hostHint: "Pass tokens() in the server's features"
133
133
  };
134
134
  const anonymous = {
135
135
  code: "UNAUTHENTICATED",
@@ -477,7 +477,7 @@ const EventsHandlers = HttpApiBuilder.group(GitRestApi, "events", (handlers) =>
477
477
  const noQueue = {
478
478
  code: "NOT_FOUND",
479
479
  message: "This server has no merge queue",
480
- hint: "Pass mergeQueue() as the server's queue",
480
+ hostHint: "Pass mergeQueue() as the server's queue",
481
481
  context: { reason: "no-queue" }
482
482
  };
483
483
  /** The server's queue calls, for the caller: `NOT_FOUND`, `no-queue`, on a server with none. */
@@ -554,7 +554,7 @@ const QueueHandlers = HttpApiBuilder.group(GitRestApi, "queue", (handlers) => ha
554
554
  const noTopics = {
555
555
  code: "NOT_FOUND",
556
556
  message: "This server has no topics",
557
- hint: "Pass topics() as the server's topics",
557
+ hostHint: "Pass topics() as the server's topics",
558
558
  context: { reason: "no-topics" }
559
559
  };
560
560
  /** The server's topic calls, for the caller: `NOT_FOUND`, `no-topics`, on a server with none. */