likec4 1.48.0 → 1.50.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 (118) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5941 -4496
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1228 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +4649 -1897
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +169 -141
  10. package/dist/THIRD-PARTY-LICENSES.md +1769 -0
  11. package/dist/_chunks/LikeC4.mjs +1154 -202
  12. package/dist/_chunks/binary.mjs +72 -0
  13. package/dist/_chunks/index.d.mts +234 -140
  14. package/dist/_chunks/index2.d.mts +2043 -1828
  15. package/dist/_chunks/libs/@chevrotain/cst-dts-gen.mjs +30 -0
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +114 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.d.mts +61 -1
  27. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  28. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +1 -10
  29. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  30. package/dist/_chunks/libs/ajv.mjs +1 -777
  31. package/dist/_chunks/libs/atomically.mjs +1 -362
  32. package/dist/_chunks/libs/birpc.mjs +1 -201
  33. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  34. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  35. package/dist/_chunks/libs/conf.mjs +1 -2258
  36. package/dist/_chunks/libs/defu.mjs +1 -42
  37. package/dist/_chunks/libs/esm-env.mjs +1 -5
  38. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  39. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  40. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  41. package/dist/_chunks/libs/get-port.mjs +1 -107
  42. package/dist/_chunks/libs/is-docker.mjs +1 -26
  43. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  44. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  45. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  46. package/dist/_chunks/libs/isexe.mjs +1 -127
  47. package/dist/_chunks/libs/json5.mjs +14 -959
  48. package/dist/_chunks/libs/khroma.mjs +1 -605
  49. package/dist/_chunks/libs/ky.mjs +2 -807
  50. package/dist/_chunks/libs/langium.d.mts +2913 -2876
  51. package/dist/_chunks/libs/langium.mjs +33 -20351
  52. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  53. package/dist/_chunks/libs/p-limit.mjs +1 -120
  54. package/dist/_chunks/libs/p-queue.mjs +1 -449
  55. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  56. package/dist/_chunks/libs/package-up.mjs +1 -10
  57. package/dist/_chunks/libs/pako.mjs +1 -0
  58. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  59. package/dist/_chunks/libs/pathe.mjs +1 -0
  60. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  61. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  62. package/dist/_chunks/libs/remeda.mjs +2 -690
  63. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  64. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  65. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  66. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  67. package/dist/_chunks/libs/ufo.mjs +1 -240
  68. package/dist/_chunks/libs/which.mjs +1 -84
  69. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence.mjs +1 -0
  72. package/dist/_chunks/src.mjs +15 -0
  73. package/dist/_chunks/src2.mjs +499 -0
  74. package/dist/cli/index.mjs +77 -1952
  75. package/dist/config/index.d.mts +2 -2
  76. package/dist/config/index.mjs +1 -6
  77. package/dist/index.d.mts +150 -7
  78. package/dist/index.mjs +1 -21
  79. package/dist/model/builder.mjs +1 -3
  80. package/dist/model/index.d.mts +57 -3
  81. package/dist/model/index.mjs +1 -5
  82. package/dist/vite-plugin/index.d.mts +7 -3
  83. package/dist/vite-plugin/index.mjs +1 -22
  84. package/dist/vite-plugin/internal.d.mts +6 -7
  85. package/dist/vite-plugin/internal.mjs +1 -68
  86. package/package.json +64 -45
  87. package/react/{index.d.ts → index.d.mts} +114 -72
  88. package/react/{index.js → index.mjs} +21320 -22041
  89. package/react/package.json +2 -5
  90. package/vite-plugin-modules.d.ts +10 -5
  91. package/dist/_chunks/LikeC4.d.mts +0 -121
  92. package/dist/_chunks/config-app.prod.d.mts +0 -18
  93. package/dist/_chunks/config-app.prod.mjs +0 -188
  94. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  95. package/dist/_chunks/define-config.mjs +0 -409
  96. package/dist/_chunks/index3.d.mts +0 -60
  97. package/dist/_chunks/libs/@chevrotain/gast.mjs +0 -3969
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/libs/nanostores.d.mts +0 -63
  101. package/dist/_chunks/libs/nanostores.mjs +0 -198
  102. package/dist/_chunks/model.mjs +0 -12
  103. package/dist/_chunks/module.d.mts +0 -71
  104. package/dist/_chunks/module.mjs +0 -18657
  105. package/dist/_chunks/plugin.mjs +0 -996
  106. package/dist/_chunks/sequence-view.mjs +0 -575
  107. package/dist/_chunks/vite-build.mjs +0 -69
  108. package/dist/_chunks/vite-dev.mjs +0 -79
  109. package/dist/_chunks/vite-preview.mjs +0 -27
  110. package/dist/language/module.d.mts +0 -5
  111. package/dist/language/module.mjs +0 -20
  112. package/dist/vite/vite-build.d.mts +0 -26
  113. package/dist/vite/vite-build.mjs +0 -27
  114. package/dist/vite/vite-dev.d.mts +0 -34
  115. package/dist/vite/vite-dev.mjs +0 -29
  116. package/dist/vite/vite-preview.d.mts +0 -20
  117. package/dist/vite/vite-preview.mjs +0 -26
  118. /package/dist/_chunks/{index4.d.mts → libs/@chevrotain/types.d.mts} +0 -0
@@ -1,436 +1 @@
1
- import crypto from "crypto";
2
- import { createServer } from "http";
3
- import { Http2ServerRequest } from "http2";
4
- import { Readable } from "stream";
5
-
6
- //#region ../../node_modules/.pnpm/@hono+node-server@1.19.9_hono@4.11.6/node_modules/@hono/node-server/dist/index.mjs
7
- var RequestError = class extends Error {
8
- constructor(message, options) {
9
- super(message, options);
10
- this.name = "RequestError";
11
- }
12
- };
13
- var toRequestError = (e) => {
14
- if (e instanceof RequestError) return e;
15
- return new RequestError(e.message, { cause: e });
16
- };
17
- var GlobalRequest = global.Request;
18
- var Request = class extends GlobalRequest {
19
- constructor(input, options) {
20
- if (typeof input === "object" && getRequestCache in input) input = input[getRequestCache]();
21
- if (typeof options?.body?.getReader !== "undefined") options.duplex ??= "half";
22
- super(input, options);
23
- }
24
- };
25
- var newHeadersFromIncoming = (incoming) => {
26
- const headerRecord = [];
27
- const rawHeaders = incoming.rawHeaders;
28
- for (let i = 0; i < rawHeaders.length; i += 2) {
29
- const { [i]: key, [i + 1]: value } = rawHeaders;
30
- if (key.charCodeAt(0) !== 58) headerRecord.push([key, value]);
31
- }
32
- return new Headers(headerRecord);
33
- };
34
- var wrapBodyStream = Symbol("wrapBodyStream");
35
- var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
36
- const init = {
37
- method,
38
- headers,
39
- signal: abortController.signal
40
- };
41
- if (method === "TRACE") {
42
- init.method = "GET";
43
- const req = new Request(url, init);
44
- Object.defineProperty(req, "method", { get() {
45
- return "TRACE";
46
- } });
47
- return req;
48
- }
49
- if (!(method === "GET" || method === "HEAD")) if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) init.body = new ReadableStream({ start(controller) {
50
- controller.enqueue(incoming.rawBody);
51
- controller.close();
52
- } });
53
- else if (incoming[wrapBodyStream]) {
54
- let reader;
55
- init.body = new ReadableStream({ async pull(controller) {
56
- try {
57
- reader ||= Readable.toWeb(incoming).getReader();
58
- const { done, value } = await reader.read();
59
- if (done) controller.close();
60
- else controller.enqueue(value);
61
- } catch (error) {
62
- controller.error(error);
63
- }
64
- } });
65
- } else init.body = Readable.toWeb(incoming);
66
- return new Request(url, init);
67
- };
68
- var getRequestCache = Symbol("getRequestCache");
69
- var requestCache = Symbol("requestCache");
70
- var incomingKey = Symbol("incomingKey");
71
- var urlKey = Symbol("urlKey");
72
- var headersKey = Symbol("headersKey");
73
- var abortControllerKey = Symbol("abortControllerKey");
74
- var requestPrototype = {
75
- get method() {
76
- return this[incomingKey].method || "GET";
77
- },
78
- get url() {
79
- return this[urlKey];
80
- },
81
- get headers() {
82
- return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
83
- },
84
- [Symbol("getAbortController")]() {
85
- this[getRequestCache]();
86
- return this[abortControllerKey];
87
- },
88
- [getRequestCache]() {
89
- this[abortControllerKey] ||= new AbortController();
90
- return this[requestCache] ||= newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], this[abortControllerKey]);
91
- }
92
- };
93
- [
94
- "body",
95
- "bodyUsed",
96
- "cache",
97
- "credentials",
98
- "destination",
99
- "integrity",
100
- "mode",
101
- "redirect",
102
- "referrer",
103
- "referrerPolicy",
104
- "signal",
105
- "keepalive"
106
- ].forEach((k) => {
107
- Object.defineProperty(requestPrototype, k, { get() {
108
- return this[getRequestCache]()[k];
109
- } });
110
- });
111
- [
112
- "arrayBuffer",
113
- "blob",
114
- "clone",
115
- "formData",
116
- "json",
117
- "text"
118
- ].forEach((k) => {
119
- Object.defineProperty(requestPrototype, k, { value: function() {
120
- return this[getRequestCache]()[k]();
121
- } });
122
- });
123
- Object.setPrototypeOf(requestPrototype, Request.prototype);
124
- var newRequest = (incoming, defaultHostname) => {
125
- const req = Object.create(requestPrototype);
126
- req[incomingKey] = incoming;
127
- const incomingUrl = incoming.url || "";
128
- if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
129
- if (incoming instanceof Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
130
- try {
131
- req[urlKey] = new URL(incomingUrl).href;
132
- } catch (e) {
133
- throw new RequestError("Invalid absolute URL", { cause: e });
134
- }
135
- return req;
136
- }
137
- const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
138
- if (!host) throw new RequestError("Missing host header");
139
- let scheme;
140
- if (incoming instanceof Http2ServerRequest) {
141
- scheme = incoming.scheme;
142
- if (!(scheme === "http" || scheme === "https")) throw new RequestError("Unsupported scheme");
143
- } else scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
144
- const url = new URL(`${scheme}://${host}${incomingUrl}`);
145
- if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) throw new RequestError("Invalid host header");
146
- req[urlKey] = url.href;
147
- return req;
148
- };
149
- var responseCache = Symbol("responseCache");
150
- var getResponseCache = Symbol("getResponseCache");
151
- var cacheKey = Symbol("cache");
152
- var GlobalResponse = global.Response;
153
- var Response2 = class _Response {
154
- #body;
155
- #init;
156
- [getResponseCache]() {
157
- delete this[cacheKey];
158
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
159
- }
160
- constructor(body, init) {
161
- let headers;
162
- this.#body = body;
163
- if (init instanceof _Response) {
164
- const cachedGlobalResponse = init[responseCache];
165
- if (cachedGlobalResponse) {
166
- this.#init = cachedGlobalResponse;
167
- this[getResponseCache]();
168
- return;
169
- } else {
170
- this.#init = init.#init;
171
- headers = new Headers(init.#init.headers);
172
- }
173
- } else this.#init = init;
174
- if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
175
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
176
- this[cacheKey] = [
177
- init?.status || 200,
178
- body,
179
- headers
180
- ];
181
- }
182
- }
183
- get headers() {
184
- const cache = this[cacheKey];
185
- if (cache) {
186
- if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2]);
187
- return cache[2];
188
- }
189
- return this[getResponseCache]().headers;
190
- }
191
- get status() {
192
- return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
193
- }
194
- get ok() {
195
- const status = this.status;
196
- return status >= 200 && status < 300;
197
- }
198
- };
199
- [
200
- "body",
201
- "bodyUsed",
202
- "redirected",
203
- "statusText",
204
- "trailers",
205
- "type",
206
- "url"
207
- ].forEach((k) => {
208
- Object.defineProperty(Response2.prototype, k, { get() {
209
- return this[getResponseCache]()[k];
210
- } });
211
- });
212
- [
213
- "arrayBuffer",
214
- "blob",
215
- "clone",
216
- "formData",
217
- "json",
218
- "text"
219
- ].forEach((k) => {
220
- Object.defineProperty(Response2.prototype, k, { value: function() {
221
- return this[getResponseCache]()[k]();
222
- } });
223
- });
224
- Object.setPrototypeOf(Response2, GlobalResponse);
225
- Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
226
- async function readWithoutBlocking(readPromise) {
227
- return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
228
- }
229
- function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
230
- const cancel = (error) => {
231
- reader.cancel(error).catch(() => {});
232
- };
233
- writable.on("close", cancel);
234
- writable.on("error", cancel);
235
- (currentReadPromise ?? reader.read()).then(flow, handleStreamError);
236
- return reader.closed.finally(() => {
237
- writable.off("close", cancel);
238
- writable.off("error", cancel);
239
- });
240
- function handleStreamError(error) {
241
- if (error) writable.destroy(error);
242
- }
243
- function onDrain() {
244
- reader.read().then(flow, handleStreamError);
245
- }
246
- function flow({ done, value }) {
247
- try {
248
- if (done) writable.end();
249
- else if (!writable.write(value)) writable.once("drain", onDrain);
250
- else return reader.read().then(flow, handleStreamError);
251
- } catch (e) {
252
- handleStreamError(e);
253
- }
254
- }
255
- }
256
- function writeFromReadableStream(stream, writable) {
257
- if (stream.locked) throw new TypeError("ReadableStream is locked.");
258
- else if (writable.destroyed) return;
259
- return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
260
- }
261
- var buildOutgoingHttpHeaders = (headers) => {
262
- const res = {};
263
- if (!(headers instanceof Headers)) headers = new Headers(headers ?? void 0);
264
- const cookies = [];
265
- for (const [k, v] of headers) if (k === "set-cookie") cookies.push(v);
266
- else res[k] = v;
267
- if (cookies.length > 0) res["set-cookie"] = cookies;
268
- res["content-type"] ??= "text/plain; charset=UTF-8";
269
- return res;
270
- };
271
- var X_ALREADY_SENT = "x-hono-already-sent";
272
- if (typeof global.crypto === "undefined") global.crypto = crypto;
273
- var outgoingEnded = Symbol("outgoingEnded");
274
- var handleRequestError = () => new Response(null, { status: 400 });
275
- var handleFetchError = (e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 });
276
- var handleResponseError = (e, outgoing) => {
277
- const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
278
- if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
279
- else {
280
- console.error(e);
281
- if (!outgoing.headersSent) outgoing.writeHead(500, { "Content-Type": "text/plain" });
282
- outgoing.end(`Error: ${err.message}`);
283
- outgoing.destroy(err);
284
- }
285
- };
286
- var flushHeaders = (outgoing) => {
287
- if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
288
- };
289
- var responseViaCache = async (res, outgoing) => {
290
- let [status, body, header] = res[cacheKey];
291
- if (header instanceof Headers) header = buildOutgoingHttpHeaders(header);
292
- if (typeof body === "string") header["Content-Length"] = Buffer.byteLength(body);
293
- else if (body instanceof Uint8Array) header["Content-Length"] = body.byteLength;
294
- else if (body instanceof Blob) header["Content-Length"] = body.size;
295
- outgoing.writeHead(status, header);
296
- if (typeof body === "string" || body instanceof Uint8Array) outgoing.end(body);
297
- else if (body instanceof Blob) outgoing.end(new Uint8Array(await body.arrayBuffer()));
298
- else {
299
- flushHeaders(outgoing);
300
- await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
301
- }
302
- outgoing[outgoingEnded]?.();
303
- };
304
- var isPromise = (res) => typeof res.then === "function";
305
- var responseViaResponseObject = async (res, outgoing, options = {}) => {
306
- if (isPromise(res)) if (options.errorHandler) try {
307
- res = await res;
308
- } catch (err) {
309
- const errRes = await options.errorHandler(err);
310
- if (!errRes) return;
311
- res = errRes;
312
- }
313
- else res = await res.catch(handleFetchError);
314
- if (cacheKey in res) return responseViaCache(res, outgoing);
315
- const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
316
- if (res.body) {
317
- const reader = res.body.getReader();
318
- const values = [];
319
- let done = false;
320
- let currentReadPromise = void 0;
321
- if (resHeaderRecord["transfer-encoding"] !== "chunked") {
322
- let maxReadCount = 2;
323
- for (let i = 0; i < maxReadCount; i++) {
324
- currentReadPromise ||= reader.read();
325
- const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
326
- console.error(e);
327
- done = true;
328
- });
329
- if (!chunk) {
330
- if (i === 1) {
331
- await new Promise((resolve) => setTimeout(resolve));
332
- maxReadCount = 3;
333
- continue;
334
- }
335
- break;
336
- }
337
- currentReadPromise = void 0;
338
- if (chunk.value) values.push(chunk.value);
339
- if (chunk.done) {
340
- done = true;
341
- break;
342
- }
343
- }
344
- if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
345
- }
346
- outgoing.writeHead(res.status, resHeaderRecord);
347
- values.forEach((value) => {
348
- outgoing.write(value);
349
- });
350
- if (done) outgoing.end();
351
- else {
352
- if (values.length === 0) flushHeaders(outgoing);
353
- await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
354
- }
355
- } else if (resHeaderRecord[X_ALREADY_SENT]) {} else {
356
- outgoing.writeHead(res.status, resHeaderRecord);
357
- outgoing.end();
358
- }
359
- outgoing[outgoingEnded]?.();
360
- };
361
- var getRequestListener = (fetchCallback, options = {}) => {
362
- const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
363
- if (options.overrideGlobalObjects !== false && global.Request !== Request) {
364
- Object.defineProperty(global, "Request", { value: Request });
365
- Object.defineProperty(global, "Response", { value: Response2 });
366
- }
367
- return async (incoming, outgoing) => {
368
- let res, req;
369
- try {
370
- req = newRequest(incoming, options.hostname);
371
- let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
372
- if (!incomingEnded) {
373
- incoming[wrapBodyStream] = true;
374
- incoming.on("end", () => {
375
- incomingEnded = true;
376
- });
377
- if (incoming instanceof Http2ServerRequest) outgoing[outgoingEnded] = () => {
378
- if (!incomingEnded) setTimeout(() => {
379
- if (!incomingEnded) setTimeout(() => {
380
- incoming.destroy();
381
- outgoing.destroy();
382
- });
383
- });
384
- };
385
- }
386
- outgoing.on("close", () => {
387
- if (req[abortControllerKey]) {
388
- if (incoming.errored) req[abortControllerKey].abort(incoming.errored.toString());
389
- else if (!outgoing.writableFinished) req[abortControllerKey].abort("Client connection prematurely closed.");
390
- }
391
- if (!incomingEnded) setTimeout(() => {
392
- if (!incomingEnded) setTimeout(() => {
393
- incoming.destroy();
394
- });
395
- });
396
- });
397
- res = fetchCallback(req, {
398
- incoming,
399
- outgoing
400
- });
401
- if (cacheKey in res) return responseViaCache(res, outgoing);
402
- } catch (e) {
403
- if (!res) if (options.errorHandler) {
404
- res = await options.errorHandler(req ? e : toRequestError(e));
405
- if (!res) return;
406
- } else if (!req) res = handleRequestError();
407
- else res = handleFetchError(e);
408
- else return handleResponseError(e, outgoing);
409
- }
410
- try {
411
- return await responseViaResponseObject(res, outgoing, options);
412
- } catch (e) {
413
- return handleResponseError(e, outgoing);
414
- }
415
- };
416
- };
417
- var createAdaptorServer = (options) => {
418
- const fetchCallback = options.fetch;
419
- const requestListener = getRequestListener(fetchCallback, {
420
- hostname: options.hostname,
421
- overrideGlobalObjects: options.overrideGlobalObjects,
422
- autoCleanupIncoming: options.autoCleanupIncoming
423
- });
424
- return (options.createServer || createServer)(options.serverOptions || {}, requestListener);
425
- };
426
- var serve = (options, listeningListener) => {
427
- const server = createAdaptorServer(options);
428
- server.listen(options?.port ?? 3e3, options.hostname, () => {
429
- const serverInfo = server.address();
430
- listeningListener && listeningListener(serverInfo);
431
- });
432
- return server;
433
- };
434
-
435
- //#endregion
436
- export { serve as t };
1
+ import e from"crypto";import{createServer as t}from"http";import{Http2ServerRequest as n}from"http2";import{Readable as r}from"stream";var i=class extends Error{constructor(e,t){super(e,t),this.name=`RequestError`}},a=e=>e instanceof i?e:new i(e.message,{cause:e}),o=global.Request,s=class extends o{constructor(e,t){typeof e==`object`&&d in e&&(e=e[d]()),t?.body?.getReader!==void 0&&(t.duplex??=`half`),super(e,t)}},c=e=>{let t=[],n=e.rawHeaders;for(let e=0;e<n.length;e+=2){let{[e]:r,[e+1]:i}=n;r.charCodeAt(0)!==58&&t.push([r,i])}return new Headers(t)},l=Symbol(`wrapBodyStream`),u=(e,t,n,i,a)=>{let o={method:e,headers:n,signal:a.signal};if(e===`TRACE`){o.method=`GET`;let e=new s(t,o);return Object.defineProperty(e,`method`,{get(){return`TRACE`}}),e}if(!(e===`GET`||e===`HEAD`))if(`rawBody`in i&&i.rawBody instanceof Buffer)o.body=new ReadableStream({start(e){e.enqueue(i.rawBody),e.close()}});else if(i[l]){let e;o.body=new ReadableStream({async pull(t){try{e||=r.toWeb(i).getReader();let{done:n,value:a}=await e.read();n?t.close():t.enqueue(a)}catch(e){t.error(e)}}})}else o.body=r.toWeb(i);return new s(t,o)},d=Symbol(`getRequestCache`),f=Symbol(`requestCache`),p=Symbol(`incomingKey`),m=Symbol(`urlKey`),h=Symbol(`headersKey`),g=Symbol(`abortControllerKey`),_={get method(){return this[p].method||`GET`},get url(){return this[m]},get headers(){return this[h]||=c(this[p])},[Symbol(`getAbortController`)](){return this[d](),this[g]},[d](){return this[g]||=new AbortController,this[f]||=u(this.method,this[m],this.headers,this[p],this[g])}};[`body`,`bodyUsed`,`cache`,`credentials`,`destination`,`integrity`,`mode`,`redirect`,`referrer`,`referrerPolicy`,`signal`,`keepalive`].forEach(e=>{Object.defineProperty(_,e,{get(){return this[d]()[e]}})}),[`arrayBuffer`,`blob`,`clone`,`formData`,`json`,`text`].forEach(e=>{Object.defineProperty(_,e,{value:function(){return this[d]()[e]()}})}),Object.setPrototypeOf(_,s.prototype);var v=(e,t)=>{let r=Object.create(_);r[p]=e;let a=e.url||``;if(a[0]!==`/`&&(a.startsWith(`http://`)||a.startsWith(`https://`))){if(e instanceof n)throw new i(`Absolute URL for :path is not allowed in HTTP/2`);try{r[m]=new URL(a).href}catch(e){throw new i(`Invalid absolute URL`,{cause:e})}return r}let o=(e instanceof n?e.authority:e.headers.host)||t;if(!o)throw new i(`Missing host header`);let s;if(e instanceof n){if(s=e.scheme,!(s===`http`||s===`https`))throw new i(`Unsupported scheme`)}else s=e.socket&&e.socket.encrypted?`https`:`http`;let c=new URL(`${s}://${o}${a}`);if(c.hostname.length!==o.length&&c.hostname!==o.replace(/:\d+$/,``))throw new i(`Invalid host header`);return r[m]=c.href,r},y=Symbol(`responseCache`),b=Symbol(`getResponseCache`),x=Symbol(`cache`),S=global.Response,C=class e{#e;#t;[b](){return delete this[x],this[y]||=new S(this.#e,this.#t)}constructor(t,n){let r;if(this.#e=t,n instanceof e){let e=n[y];if(e){this.#t=e,this[b]();return}else this.#t=n.#t,r=new Headers(n.#t.headers)}else this.#t=n;(typeof t==`string`||t?.getReader!==void 0||t instanceof Blob||t instanceof Uint8Array)&&(r||=n?.headers||{"content-type":`text/plain; charset=UTF-8`},this[x]=[n?.status||200,t,r])}get headers(){let e=this[x];return e?(e[2]instanceof Headers||(e[2]=new Headers(e[2])),e[2]):this[b]().headers}get status(){return this[x]?.[0]??this[b]().status}get ok(){let e=this.status;return e>=200&&e<300}};[`body`,`bodyUsed`,`redirected`,`statusText`,`trailers`,`type`,`url`].forEach(e=>{Object.defineProperty(C.prototype,e,{get(){return this[b]()[e]}})}),[`arrayBuffer`,`blob`,`clone`,`formData`,`json`,`text`].forEach(e=>{Object.defineProperty(C.prototype,e,{value:function(){return this[b]()[e]()}})}),Object.setPrototypeOf(C,S),Object.setPrototypeOf(C.prototype,S.prototype);async function w(e){return Promise.race([e,Promise.resolve().then(()=>Promise.resolve(void 0))])}function T(e,t,n){let r=t=>{e.cancel(t).catch(()=>{})};return t.on(`close`,r),t.on(`error`,r),(n??e.read()).then(o,i),e.closed.finally(()=>{t.off(`close`,r),t.off(`error`,r)});function i(e){e&&t.destroy(e)}function a(){e.read().then(o,i)}function o({done:n,value:r}){try{if(n)t.end();else if(!t.write(r))t.once(`drain`,a);else return e.read().then(o,i)}catch(e){i(e)}}}function E(e,t){if(e.locked)throw TypeError(`ReadableStream is locked.`);return t.destroyed?void 0:T(e.getReader(),t)}var D=e=>{let t={};e instanceof Headers||(e=new Headers(e??void 0));let n=[];for(let[r,i]of e)r===`set-cookie`?n.push(i):t[r]=i;return n.length>0&&(t[`set-cookie`]=n),t[`content-type`]??=`text/plain; charset=UTF-8`,t},O=`x-hono-already-sent`;global.crypto===void 0&&(global.crypto=e);var k=Symbol(`outgoingEnded`),A=()=>new Response(null,{status:400}),j=e=>new Response(null,{status:e instanceof Error&&(e.name===`TimeoutError`||e.constructor.name===`TimeoutError`)?504:500}),M=(e,t)=>{let n=e instanceof Error?e:Error(`unknown error`,{cause:e});n.code===`ERR_STREAM_PREMATURE_CLOSE`?console.info(`The user aborted a request.`):(console.error(e),t.headersSent||t.writeHead(500,{"Content-Type":`text/plain`}),t.end(`Error: ${n.message}`),t.destroy(n))},N=e=>{`flushHeaders`in e&&e.writable&&e.flushHeaders()},P=async(e,t)=>{let[n,r,i]=e[x];i instanceof Headers&&(i=D(i)),typeof r==`string`?i[`Content-Length`]=Buffer.byteLength(r):r instanceof Uint8Array?i[`Content-Length`]=r.byteLength:r instanceof Blob&&(i[`Content-Length`]=r.size),t.writeHead(n,i),typeof r==`string`||r instanceof Uint8Array?t.end(r):r instanceof Blob?t.end(new Uint8Array(await r.arrayBuffer())):(N(t),await E(r,t)?.catch(e=>M(e,t))),t[k]?.()},F=e=>typeof e.then==`function`,I=async(e,t,n={})=>{if(F(e))if(n.errorHandler)try{e=await e}catch(t){let r=await n.errorHandler(t);if(!r)return;e=r}else e=await e.catch(j);if(x in e)return P(e,t);let r=D(e.headers);if(e.body){let n=e.body.getReader(),i=[],a=!1,o;if(r[`transfer-encoding`]!==`chunked`){let e=2;for(let t=0;t<e;t++){o||=n.read();let r=await w(o).catch(e=>{console.error(e),a=!0});if(!r){if(t===1){await new Promise(e=>setTimeout(e)),e=3;continue}break}if(o=void 0,r.value&&i.push(r.value),r.done){a=!0;break}}a&&!(`content-length`in r)&&(r[`content-length`]=i.reduce((e,t)=>e+t.length,0))}t.writeHead(e.status,r),i.forEach(e=>{t.write(e)}),a?t.end():(i.length===0&&N(t),await T(n,t,o))}else r[O]||(t.writeHead(e.status,r),t.end());t[k]?.()},L=(e,t={})=>{let r=t.autoCleanupIncoming??!0;return t.overrideGlobalObjects!==!1&&global.Request!==s&&(Object.defineProperty(global,`Request`,{value:s}),Object.defineProperty(global,`Response`,{value:C})),async(i,o)=>{let s,c;try{c=v(i,t.hostname);let a=!r||i.method===`GET`||i.method===`HEAD`;if(a||(i[l]=!0,i.on(`end`,()=>{a=!0}),i instanceof n&&(o[k]=()=>{a||setTimeout(()=>{a||setTimeout(()=>{i.destroy(),o.destroy()})})})),o.on(`close`,()=>{c[g]&&(i.errored?c[g].abort(i.errored.toString()):o.writableFinished||c[g].abort(`Client connection prematurely closed.`)),a||setTimeout(()=>{a||setTimeout(()=>{i.destroy()})})}),s=e(c,{incoming:i,outgoing:o}),x in s)return P(s,o)}catch(e){if(s)return M(e,o);if(t.errorHandler){if(s=await t.errorHandler(c?e:a(e)),!s)return}else s=c?j(e):A()}try{return await I(s,o,t)}catch(e){return M(e,o)}}},R=e=>{let n=e.fetch,r=L(n,{hostname:e.hostname,overrideGlobalObjects:e.overrideGlobalObjects,autoCleanupIncoming:e.autoCleanupIncoming});return(e.createServer||t)(e.serverOptions||{},r)},z=(e,t)=>{let n=R(e);return n.listen(e?.port??3e3,e.hostname,()=>{let e=n.address();t&&t(e)}),n};export{z as t};