@ref0/git 0.26.0 → 0.29.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 (90) hide show
  1. package/dist/client/git-http.mjs +29 -12
  2. package/dist/client/push-upload.mjs +13 -12
  3. package/dist/client/remote-helper.mjs +1 -1
  4. package/dist/client/remote.mjs +1 -1
  5. package/dist/client/run-remote-helper.mjs +7 -14
  6. package/dist/client/slice-push.d.mts +13 -9
  7. package/dist/client/slice-push.mjs +16 -5
  8. package/dist/client/slice-report.mjs +6 -8
  9. package/dist/client/transport.mjs +27 -5
  10. package/dist/contracts/git.d.mts +17 -2
  11. package/dist/contracts/store.d.mts +1 -1
  12. package/dist/core/forks.mjs +1 -1
  13. package/dist/core/purge.mjs +1 -1
  14. package/dist/http/push-uploads.mjs +10 -15
  15. package/dist/lfs/copy.d.mts +4 -1
  16. package/dist/lfs/copy.mjs +7 -6
  17. package/dist/lfs/layer.mjs +1 -1
  18. package/dist/lfs/objects.mjs +127 -8
  19. package/dist/lfs/upload-most.mjs +19 -3
  20. package/dist/merges/merges.d.mts +3 -2
  21. package/dist/protocol/bytes/buffers.mjs +26 -1
  22. package/dist/protocol/bytes/crc32.mjs +39 -6
  23. package/dist/protocol/bytes/deflate.d.mts +11 -31
  24. package/dist/protocol/bytes/deflate.mjs +133 -72
  25. package/dist/protocol/bytes/inflate.d.mts +11 -6
  26. package/dist/protocol/bytes/inflate.mjs +184 -119
  27. package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
  28. package/dist/protocol/bytes/zlib-ng/LICENSE.md +19 -0
  29. package/dist/protocol/bytes/zlib-ng/README.md +132 -0
  30. package/dist/protocol/bytes/zlib-ng/bundled.d.mts +5 -0
  31. package/dist/protocol/bytes/zlib-ng/bundled.mjs +8 -0
  32. package/dist/protocol/bytes/zlib-ng/compile.d.mts +9 -0
  33. package/dist/protocol/bytes/zlib-ng/compile.mjs +19 -0
  34. package/dist/protocol/bytes/zlib-ng/embedded.mjs +4 -0
  35. package/dist/protocol/bytes/zlib-ng/instance.d.mts +1 -0
  36. package/dist/protocol/bytes/zlib-ng/instance.mjs +111 -0
  37. package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
  38. package/dist/protocol/objects/fsck-names.mjs +27 -7
  39. package/dist/protocol/objects/fsck.mjs +100 -88
  40. package/dist/protocol/objects/object-rules.d.mts +1 -0
  41. package/dist/protocol/objects/tree.d.mts +1 -0
  42. package/dist/protocol/objects/tree.mjs +55 -6
  43. package/dist/protocol/packs/reader.mjs +35 -30
  44. package/dist/protocol/wire/push-uploads.mjs +12 -1
  45. package/dist/server/registry.mjs +12 -0
  46. package/dist/server/server.mjs +7 -1
  47. package/dist/storage/budget.d.mts +2 -0
  48. package/dist/storage/budget.mjs +26 -24
  49. package/dist/storage/calls.d.mts +1 -1
  50. package/dist/storage/calls.mjs +4 -2
  51. package/dist/storage/host-bucket.mjs +15 -5
  52. package/dist/storage/index-bitmaps.d.mts +1 -0
  53. package/dist/storage/index-bitmaps.mjs +15 -14
  54. package/dist/storage/index-build.d.mts +2 -1
  55. package/dist/storage/index-build.mjs +14 -15
  56. package/dist/storage/index-files.mjs +3 -3
  57. package/dist/storage/index-graph.mjs +3 -3
  58. package/dist/storage/index-remap.mjs +6 -7
  59. package/dist/storage/links.mjs +34 -2
  60. package/dist/storage/loose.mjs +2 -1
  61. package/dist/storage/memory-budget.d.mts +1 -0
  62. package/dist/storage/memory-budget.mjs +12 -3
  63. package/dist/storage/merge-most.mjs +2 -1
  64. package/dist/storage/merge-stream.mjs +4 -3
  65. package/dist/storage/merge-write.mjs +2 -2
  66. package/dist/storage/pack-reads.mjs +1 -1
  67. package/dist/storage/pack-receive.mjs +24 -8
  68. package/dist/storage/packs-memory.mjs +2 -1
  69. package/dist/storage/packs.d.mts +3 -1
  70. package/dist/storage/packs.mjs +34 -11
  71. package/dist/storage/put-holds.d.mts +1 -0
  72. package/dist/storage/put-holds.mjs +20 -0
  73. package/dist/storage/ready.mjs +4 -2
  74. package/dist/storage/receive-bounds.d.mts +1 -1
  75. package/dist/storage/receive-bounds.mjs +4 -4
  76. package/dist/storage/receive-links.mjs +31 -15
  77. package/dist/storage/receive-steps.mjs +21 -1
  78. package/dist/storage/runs.d.mts +1 -1
  79. package/dist/storage/runs.mjs +7 -5
  80. package/dist/store/door.mjs +9 -1
  81. package/dist/store/job-try.mjs +5 -5
  82. package/dist/store/repo-record.mjs +1 -1
  83. package/dist/sync/step.mjs +3 -4
  84. package/package.json +12 -9
  85. package/dist/http/node.d.mts +0 -62
  86. package/dist/http/node.mjs +0 -212
  87. package/dist/node.d.mts +0 -3
  88. package/dist/node.mjs +0 -1
  89. package/dist/server/edge-node.d.mts +0 -19
  90. package/dist/server/edge-node.mjs +0 -20
@@ -1,62 +0,0 @@
1
- /**
2
- * What `toNodeHandler` reads of `node:http`'s request, which Express's extends: this package has
3
- * no Node types, so the few members used are typed here.
4
- */
5
- export interface NodeRequest extends AsyncIterable<Uint8Array> {
6
- readonly method?: string | undefined;
7
- readonly url?: string | undefined;
8
- /** Express's: the path before a router took its mount off `url`. */
9
- readonly originalUrl?: string | undefined;
10
- readonly rawHeaders: ReadonlyArray<string>;
11
- /** `host`, or over HTTP/2, `node:http2`'s `:authority`, which stands in for it. */
12
- readonly headers: {
13
- readonly host?: string | undefined;
14
- readonly ':authority'?: string | undefined;
15
- };
16
- /** A `Socket`, whose `remoteAddress` every one has; a TLS one's `encrypted` is `true`. */
17
- readonly socket: {
18
- readonly remoteAddress?: string | undefined;
19
- readonly encrypted?: boolean | undefined;
20
- };
21
- }
22
- /**
23
- * What `toNodeHandler` calls of `node:http`'s response, or `node:http2`'s compatibility one. Both
24
- * set `writableEnded` once `end` is called, and not for a client that left first; `node:http2`'s
25
- * has no `destroyed` of its own, and its stream's says whether it's gone, and its `close` that
26
- * the client left.
27
- */
28
- export interface NodeResponse {
29
- readonly headersSent: boolean;
30
- readonly writableEnded: boolean;
31
- readonly destroyed?: boolean | undefined;
32
- readonly stream?: {
33
- readonly destroyed: boolean;
34
- once(event: 'close', listener: () => void): void;
35
- } | undefined;
36
- writeHead(status: number, headers: string[]): void;
37
- write(chunk: Uint8Array): boolean;
38
- end(): void;
39
- once(event: 'drain' | 'close', listener: () => void): void;
40
- removeListener(event: 'drain' | 'close', listener: () => void): void;
41
- destroy(): void;
42
- }
43
- /** A listener for `node:http`'s `createServer`, or an Express route. */
44
- export type NodeHandler = (request: NodeRequest, response: NodeResponse) => void;
45
- /**
46
- * What a Node host serves under, its public origin, when a proxy in front of it serves one its
47
- * socket can't tell, as one that ends TLS does: every link Git gives out, a clone's, a redirect's
48
- * and LFS's, is built from it. A request's own `Host`, `X-Forwarded-Host` and `X-Forwarded-Proto`
49
- * never are: a client can send any of them.
50
- */
51
- export interface NodeServeOptions {
52
- /**
53
- * The origin the host is reached at, such as `'https://git.example.com'`: a scheme, a host and a
54
- * port, with no path, query or trailing slash. A `basePath` stays the runtime's. Unset, each
55
- * request's is the connection's, its scheme from the socket and its host from its `Host`.
56
- */
57
- readonly origin?: string | undefined;
58
- }
59
- /** Express's `next`: the request goes on to the app's own middleware and routes. */
60
- export type NodeNext = () => void;
61
- /** An Express middleware, or `next` for a request it doesn't answer. */
62
- export type NodeMiddleware = (request: NodeRequest, response: NodeResponse, next: NodeNext) => void;
@@ -1,212 +0,0 @@
1
- import { ownedReader } from "../protocol/bytes/reader.mjs";
2
- // src/http/node.ts
3
- /**
4
- * A request's body as a stream, read from Node only as the handler pulls it, with nothing read
5
- * ahead: over HTTP/2, `node:http2` closes a stream whose upload no one reads once its answer has
6
- * ended, so an upload Git refused unread doesn't hold the stream open till the client ends it.
7
- */
8
- const streamOf = (incoming) => {
9
- const chunks = incoming[Symbol.asyncIterator]();
10
- return new ReadableStream({
11
- pull: async (controller) => {
12
- const next = await chunks.next();
13
- if (next.done === true) return controller.close();
14
- controller.enqueue(next.value);
15
- },
16
- cancel: async () => {
17
- await chunks.return?.();
18
- }
19
- }, { highWaterMark: 0 });
20
- };
21
- /**
22
- * The origin of the connection Node received `incoming` on: its scheme from the socket, `https`
23
- * for TLS, and its `Host`. Over HTTP/2, `:authority` is the `Host`, and a request whose `host`
24
- * names another, which RFC 9113 calls malformed, has none. It throws for a `Host` that is empty or
25
- * holds more than a host and port, as `mo.dev#`, `mo.dev/git` or `@evil.example` do, since the
26
- * target would be read as part of the origin.
27
- */
28
- const socketOrigin = (incoming) => {
29
- const authority = incoming.headers[":authority"];
30
- const given = incoming.headers.host;
31
- if (authority !== void 0 && given !== void 0 && given.toLowerCase() !== authority.toLowerCase()) throw new TypeError(`A Host, ${given}, that isn't the :authority, ${authority}`);
32
- const host = authority ?? given ?? "localhost";
33
- if (host === "" || /[/\\?#@]/.test(host)) throw new TypeError(`No origin in the Host ${host}`);
34
- return `${incoming.socket.encrypted === true ? "https" : "http"}://${host}`;
35
- };
36
- /**
37
- * The URL Node received, as `Request` reads it, under `origin`, the connection's when the host
38
- * names none: dot segments, `%2e%2e` and `\` resolved. A path is read after the origin, so one
39
- * that starts `//`, as `//evil.example/git/…` does, stays a path, and an absolute target keeps
40
- * only its path and query: neither names the origin Git builds its links from. It throws for one
41
- * that can't be read, such as one whose `Host` `socketOrigin` refuses, when the host names none.
42
- */
43
- const urlOf = (incoming, origin = socketOrigin(incoming)) => {
44
- const target = incoming.originalUrl ?? incoming.url ?? "/";
45
- if (target.startsWith("/")) return new URL(`${origin}${target}`);
46
- const named = new URL(target);
47
- return new URL(`${origin}${named.pathname}${named.search}`);
48
- };
49
- /** A bare `http://` or `https://` host and port, as a URL's `origin` reads it. */
50
- const bareOrigin = /^https?:\/\/[^/\\?#@\s]+$/i;
51
- /**
52
- * `options.origin`, checked as the handler is made, so a host that names a wrong one fails as it
53
- * starts, not on its first request: one that isn't a bare `http(s)://host[:port]` throws.
54
- * `undefined` when it's unset.
55
- */
56
- const servedOrigin = ({ origin }) => {
57
- if (origin === void 0) return void 0;
58
- const url = URL.parse(origin);
59
- if (url === null || !bareOrigin.test(origin) || url.pathname !== "/") throw new TypeError(`A Node host's origin is a bare http(s)://host[:port], with no path, query or trailing slash, not ${origin}`);
60
- return url.origin;
61
- };
62
- /**
63
- * The request Node received, at `url`, as a `Request` on `signal`, its body streamed. HTTP/2's
64
- * pseudo-headers, such as `:method` and `:authority`, are left out: `Headers` refuses their names.
65
- */
66
- const requestOf = (incoming, signal, url = urlOf(incoming)) => {
67
- const headers = new Headers();
68
- for (let at = 0; at + 1 < incoming.rawHeaders.length; at += 2) {
69
- const name = incoming.rawHeaders[at] ?? "";
70
- if (!name.startsWith(":")) headers.append(name, incoming.rawHeaders[at + 1] ?? "");
71
- }
72
- const method = incoming.method ?? "GET";
73
- const init = {
74
- method,
75
- headers
76
- };
77
- if (signal !== void 0) init.signal = signal;
78
- if (method !== "GET" && method !== "HEAD") {
79
- init.body = streamOf(incoming);
80
- init.duplex = "half";
81
- }
82
- return new Request(url, init);
83
- };
84
- /**
85
- * What emits `close` when the client leaves: over HTTP/2, the response's stream, since `node:http2`'s
86
- * compatibility response emits none for a HEAD whose stream closes before `end`; else the response.
87
- */
88
- const closer = (response) => response.stream ?? response;
89
- /**
90
- * Whether Node's response is gone, its connection closed or reset: `node:http`'s says so itself,
91
- * and `node:http2`'s compatibility response only through its stream.
92
- */
93
- const gone = (response) => response.destroyed === true || response.stream?.destroyed === true;
94
- /**
95
- * Resolves once Node can take more of the response, or once its connection has closed, and takes
96
- * its other listener off: a long answer waits for `drain` many times, and each wait would leave a
97
- * `close` listener on the response till it closed.
98
- */
99
- const writable = (response) => new Promise((ready) => {
100
- const settle = () => {
101
- response.removeListener("drain", settle);
102
- response.removeListener("close", settle);
103
- ready();
104
- };
105
- response.once("drain", settle);
106
- response.once("close", settle);
107
- });
108
- /**
109
- * Writes `answer` to Node's response, each header as it is, its body as it streams: a write Node
110
- * can't take yet waits for `drain`, so a slow client holds the stream back, not memory. A
111
- * connection that closes first cancels the body, a read it waits on included. The answer to a
112
- * `HEAD` goes without its body, which is cancelled, as RFC 9110 says: `node:http2` ends a HEAD's
113
- * stream with its head, and would take no write after it.
114
- */
115
- const respond = async (answer, response, head = false) => {
116
- const headers = [...answer.headers].flatMap(([name, value]) => [name, value]);
117
- response.writeHead(answer.status, headers);
118
- if (head) answer.body?.cancel().catch(() => {});
119
- else if (answer.body !== null) {
120
- const { reader, close: cancel } = ownedReader(answer.body);
121
- if (gone(response)) return cancel();
122
- closer(response).once("close", () => {
123
- if (!response.writableEnded) cancel();
124
- });
125
- try {
126
- for (;;) {
127
- const next = await reader.read();
128
- if (next.done || gone(response)) break;
129
- if (!response.write(next.value)) await writable(response);
130
- }
131
- } finally {
132
- cancel();
133
- }
134
- }
135
- if (!gone(response)) response.end();
136
- };
137
- /** No answer to a client that went away: `answer`'s body is cancelled and the response destroyed. */
138
- const leave = (answer, response) => {
139
- answer.body?.cancel().catch(() => {});
140
- response.destroy();
141
- };
142
- /**
143
- * `handler`'s answer to `incoming`, at `url` or the URL Node received under `origin`, written to
144
- * `response`. A response already gone, as when the client left while the app's earlier middleware
145
- * ran, gets no call to `handler`: its `close` came before this could hear it.
146
- */
147
- const answerAt = (handler, incoming, response, url, origin) => {
148
- if (gone(response)) return;
149
- const ended = new AbortController();
150
- closer(response).once("close", () => {
151
- if (!response.writableEnded) ended.abort();
152
- });
153
- let request;
154
- try {
155
- request = requestOf(incoming, ended.signal, url ?? urlOf(incoming, origin));
156
- } catch {
157
- response.writeHead(400, ["content-type", "text/plain"]);
158
- response.end();
159
- return;
160
- }
161
- Promise.resolve().then(() => handler.fetch(request)).then((answer) => ended.signal.aborted ? leave(answer, response) : respond(answer, response, request.method === "HEAD")).catch(() => {
162
- if (ended.signal.aborted || response.headersSent || gone(response)) {
163
- response.destroy();
164
- return;
165
- }
166
- response.writeHead(500, ["content-type", "text/plain"]);
167
- response.end();
168
- });
169
- };
170
- /**
171
- * A `fetch` as a `node:http` or `node:http2` listener or an Express route, which
172
- * `@ref0/git/node`'s `toNodeHandler` hands a runtime's `Git.toFetch`; beside an app's own routes,
173
- * `toNodeMiddleware`. The body
174
- * streams to Git unread. The response streams back as Node can take it, and a client that
175
- * disconnects or resets its stream before the response ends, which a `close` of the HTTP/2
176
- * stream, or the HTTP/1 response, before `writableEnded` says, aborts the request's `signal`, which ends Git's reads and leaves it
177
- * unanswered. A request whose URL can't be read, such as one with a malformed `Host`, is answered
178
- * 400. Over HTTP/2, `node:http2` keeps a stream open while its client's end is, as for a `HEAD`
179
- * whose client never ends it: that holds only the client's own stream. With `options.origin`, every
180
- * request is read under it, its `Host` unread, and forwarded headers are never trusted: it throws
181
- * as it's made for an origin that isn't a bare `http(s)://host[:port]`.
182
- */
183
- const toNodeHandler = (handler, options = {}) => {
184
- const origin = servedOrigin(options);
185
- return (incoming, response) => answerAt(handler, incoming, response, void 0, origin);
186
- };
187
- /**
188
- * A `fetch` beside an app's own routes, as an Express middleware, which `@ref0/git/node`'s
189
- * `toNodeMiddleware` hands a runtime's `Git.toFetch`, before any body parser. A
190
- * request `pathOf` names is answered at the path it gives, as `toNodeHandler` answers it, the
191
- * query kept; every other goes on to `next`, its body unread. `pathOf` is handed the URL `fetch`
192
- * gets, with its dot segments resolved, so the path Express routed by never decides. A URL that
193
- * can't be read goes on to `next` too. It calls `next` synchronously, before it returns, or not
194
- * at all, so a framework's hook, as Fastify's `onRequest` is, can tell by then whether it answers.
195
- * `options.origin` is read as `toNodeHandler` reads it.
196
- */
197
- const toNodeMiddleware = (handler, pathOf, options = {}) => {
198
- const origin = servedOrigin(options);
199
- return (incoming, response, next) => {
200
- let url;
201
- try {
202
- url = urlOf(incoming, origin);
203
- } catch {
204
- return next();
205
- }
206
- const path = pathOf(url);
207
- if (path === void 0) return next();
208
- url.pathname = path;
209
- answerAt(handler, incoming, response, url, origin);
210
- };
211
- };
212
- export { requestOf, respond, toNodeHandler, toNodeMiddleware };
package/dist/node.d.mts DELETED
@@ -1,3 +0,0 @@
1
- import { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
2
- import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse, NodeServeOptions } from "./http/node.mjs";
3
- export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, type NodeServeOptions, toNodeHandler, toNodeMiddleware };
package/dist/node.mjs DELETED
@@ -1 +0,0 @@
1
- export { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
@@ -1,19 +0,0 @@
1
- import { Git } from "../contracts/git.mjs";
2
- import { NodeHandler, NodeMiddleware, NodeServeOptions } from "../http/node.mjs";
3
- import { Runtime } from "./edge.mjs";
4
- /**
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
- * `Git.runtime(Git.layer(options, features).pipe(Layer.provide(adapter)))`, as docs/deploy/node.md's
8
- * "Stores" builds it. Each request is answered through `Git.toFetch`, so a failed build answers
9
- * `UNAVAILABLE` here too, and `starting` while it waits to build again. Behind a proxy that ends
10
- * TLS, `options.origin` names the origin it's reached at, which every link Git gives out is built
11
- * from; forwarded headers are never trusted, as a client can send any.
12
- */
13
- export declare const toNodeHandler: (runtime: Runtime<Git, unknown>, options?: NodeServeOptions) => NodeHandler;
14
- /**
15
- * A runtime over `Git.layer` beside an app's own routes, as an Express middleware: it answers the
16
- * paths `pathOf` names through `Git.toFetch`, and calls `next` for every other. `options.origin`
17
- * is read as `toNodeHandler` reads it.
18
- */
19
- export declare const toNodeMiddleware: (runtime: Runtime<Git, unknown>, pathOf: (url: URL) => string | undefined, options?: NodeServeOptions) => NodeMiddleware;
@@ -1,20 +0,0 @@
1
- import { toNodeHandler as toNodeHandler$1, toNodeMiddleware as toNodeMiddleware$1 } from "../http/node.mjs";
2
- import { toFetch } from "./edge.mjs";
3
- // src/server/edge-node.ts
4
- /**
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
- * `Git.runtime(Git.layer(options, features).pipe(Layer.provide(adapter)))`, as docs/deploy/node.md's
8
- * "Stores" builds it. Each request is answered through `Git.toFetch`, so a failed build answers
9
- * `UNAVAILABLE` here too, and `starting` while it waits to build again. Behind a proxy that ends
10
- * TLS, `options.origin` names the origin it's reached at, which every link Git gives out is built
11
- * from; forwarded headers are never trusted, as a client can send any.
12
- */
13
- const toNodeHandler = (runtime, options) => toNodeHandler$1({ fetch: toFetch(runtime) }, options);
14
- /**
15
- * A runtime over `Git.layer` beside an app's own routes, as an Express middleware: it answers the
16
- * paths `pathOf` names through `Git.toFetch`, and calls `next` for every other. `options.origin`
17
- * is read as `toNodeHandler` reads it.
18
- */
19
- const toNodeMiddleware = (runtime, pathOf, options) => toNodeMiddleware$1({ fetch: toFetch(runtime) }, pathOf, options);
20
- export { toNodeHandler, toNodeMiddleware };