@torpor/adapter-node 0.0.10 → 0.0.11

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @torpor/adapter-node
2
2
 
3
+ ## 0.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 7162232: Fix: set globalThis.adapter in all adapters
8
+ - Updated dependencies [02eac8e]
9
+ - @torpor/build@0.1.13
10
+
3
11
  ## 0.0.10
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -140,6 +140,7 @@ var adapter_default = {
140
140
  process.env.PROTOCOL ??= "http:";
141
141
  process.env.HOST ??= "localhost";
142
142
  process.env.PORT ??= "7059";
143
+ globalThis.adapter = { env: process.env };
143
144
  const url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;
144
145
  console.log(`
145
146
  Connecting to ${url}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/createNodeServer.ts","../src/constants.ts","../src/nodeMessageToRequest.ts","../src/flattenHeaders.ts","../src/responseToNodeResponse.ts","../src/createFetchHandler.ts","../src/adapter.ts"],"sourcesContent":["import node from \"./adapter\";\n\nexport { node };\n","import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(\n\thandler: (req: Request) => Response | Promise<Response>,\n): Server<typeof IncomingMessage, typeof ServerResponse> {\n\t// Create a server, polyfill it so that it can handle standard fetch methods,\n\t// and pass our app fetch method to the handler\n\treturn createServer(createFetchHandler(handler));\n}\n","export const INTERNAL_BODY: unique symbol = Symbol(\"internal_body\");\n","import { type IncomingMessage } from \"node:http\";\nimport { Http2ServerRequest } from \"node:http2\";\nimport { Readable } from \"node:stream\";\nimport flattenHeaders from \"./flattenHeaders\";\n\n// From https://stackoverflow.com/a/78849544\n// and https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n\nexport default async function nodeMessageToRequest(\n\treq: IncomingMessage | Http2ServerRequest,\n): Promise<Request> {\n\t// Build the full url\n\tlet path = req.url;\n\tif (path === undefined) {\n\t\tthrow new Error(`Empty request URL`);\n\t}\n\tif (!path.startsWith(\"/\")) {\n\t\tpath = \"/\" + path;\n\t}\n\tconst { host } = req.headers;\n\tif (host == undefined) {\n\t\tthrow new Error(`Missing \"Host\" header`);\n\t}\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst url = `${protocol}://${host}${path}`;\n\n\t// Flatten the headers\n\tconst headers = flattenHeaders(req.headers);\n\n\t// Convert body to Buffer if applicable\n\tconst body =\n\t\treq.method !== \"GET\" && req.method !== \"HEAD\"\n\t\t\t? (Readable.toWeb(req) as ReadableStream) // await readableToBuffer(req)\n\t\t\t: null;\n\n\treturn new Request(url, {\n\t\tmethod: req.method,\n\t\theaders: headers,\n\t\tbody: body,\n\t\t// @ts-ignore this is needed for using a Readable for some reason\n\t\tduplex: \"half\",\n\t});\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import { ServerResponse } from \"node:http\";\nimport { Http2ServerResponse } from \"node:http2\";\nimport { isArrayBufferView } from \"node:util/types\";\nimport { INTERNAL_BODY } from \"./constants\";\n\nexport default async function responseToNodeResponse(\n\tres: Response,\n\toutgoing: ServerResponse | Http2ServerResponse,\n): Promise<void> {\n\toutgoing.statusCode = res.status;\n\toutgoing.statusMessage = res.statusText;\n\n\tres.headers.forEach((value, key) => {\n\t\toutgoing.setHeader(key, value);\n\t});\n\n\tconst body = (res as any)[INTERNAL_BODY];\n\n\tif (body === null || body === undefined) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else if (typeof body === \"string\" || body instanceof Uint8Array) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(body);\n\t} else if (body instanceof Blob) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(await body.arrayBuffer()));\n\t} else if (body instanceof ArrayBuffer) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body));\n\t} else if (isArrayBufferView(body)) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body.buffer));\n\t} else if (body instanceof FormData) {\n\t\t// TODO\n\t\toutgoing.setHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t}\n}\n","import { type IncomingMessage, ServerResponse } from \"node:http\";\nimport { Http2ServerRequest, Http2ServerResponse } from \"node:http2\";\nimport { INTERNAL_BODY } from \"./constants\";\nimport nodeMessageToRequest from \"./nodeMessageToRequest\";\nimport responseToNodeResponse from \"./responseToNodeResponse\";\n\n// From https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n// Referenced from https://marvinh.dev/blog/modern-way-to-write-javascript-servers/\n\nconst GlobalResponse = Response;\nglobalThis.Response = class Response extends GlobalResponse {\n\t[INTERNAL_BODY]: BodyInit | null | undefined = null;\n\n\tconstructor(body?: BodyInit | null, init?: ResponseInit) {\n\t\tsuper(body, init);\n\t\tthis[INTERNAL_BODY] = body;\n\t}\n};\n\nexport function createFetchHandler(handler: (req: Request) => Response | Promise<Response>) {\n\treturn async (\n\t\tincoming: IncomingMessage | Http2ServerRequest,\n\t\toutgoing: ServerResponse | Http2ServerResponse,\n\t): Promise<void> => {\n\t\tconst req = await nodeMessageToRequest(incoming);\n\t\tconst res = await handler(req);\n\t\treturn await responseToNodeResponse(res, outgoing);\n\t};\n}\n","import { type Adapter } from \"@torpor/build\";\nimport { Server } from \"@torpor/build/server\";\nimport createNodeServer from \"./createNodeServer\";\n\nexport default {\n\tserve: (server: Server) => {\n\t\tprocess.env.PROTOCOL ??= \"http:\";\n\t\tprocess.env.HOST ??= \"localhost\";\n\t\tprocess.env.PORT ??= \"7059\";\n\n\t\t// Create the Node server and start listening\n\t\tconst url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;\n\t\tconsole.log(`\\nConnecting to ${url}`);\n\t\tconst devServer = createNodeServer(server.fetch);\n\t\tdevServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {\n\t\t\tconsole.log(`Listening on ${url}\\n`);\n\t\t});\n\t},\n} satisfies Adapter as Adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAA6B;;;ACDtB,IAAM,gBAA+B,OAAO,eAAe;;;ACElE,yBAAyB;;;ACCV,SAAR,eACN,SACc;AACd,QAAM,cAAc,IA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M,uBAAuB,KAAK,QAAQ;AAAA,EAClD;AACD;;;ALxBe,SAAR,iBACN,SACwD;AAGxD,aAAO,+BAAa,mBAAmB,OAAO,CAAC;AAChD;;;AMNA,IAAO,kBAAQ;AAAA,EACd,OAAO,CAAC,WAAmB;AAC1B,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS;AAGrB,UAAM,MAAM,GAAG,QAAQ,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI;AAC5E,YAAQ,IAAI;AAAA,gBAAmB,GAAG,EAAE;AACpC,UAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,cAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,GAAG,QAAQ,IAAI,MAAM,MAAM;AACpE,cAAQ,IAAI,gBAAgB,GAAG;AAAA,CAAI;AAAA,IACpC,CAAC;AAAA,EACF;AACD;","names":["v","Response"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/createNodeServer.ts","../src/constants.ts","../src/nodeMessageToRequest.ts","../src/flattenHeaders.ts","../src/responseToNodeResponse.ts","../src/createFetchHandler.ts","../src/adapter.ts"],"sourcesContent":["import node from \"./adapter\";\n\nexport { node };\n","import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(\n\thandler: (req: Request) => Response | Promise<Response>,\n): Server<typeof IncomingMessage, typeof ServerResponse> {\n\t// Create a server, polyfill it so that it can handle standard fetch methods,\n\t// and pass our app fetch method to the handler\n\treturn createServer(createFetchHandler(handler));\n}\n","export const INTERNAL_BODY: unique symbol = Symbol(\"internal_body\");\n","import { type IncomingMessage } from \"node:http\";\nimport { Http2ServerRequest } from \"node:http2\";\nimport { Readable } from \"node:stream\";\nimport flattenHeaders from \"./flattenHeaders\";\n\n// From https://stackoverflow.com/a/78849544\n// and https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n\nexport default async function nodeMessageToRequest(\n\treq: IncomingMessage | Http2ServerRequest,\n): Promise<Request> {\n\t// Build the full url\n\tlet path = req.url;\n\tif (path === undefined) {\n\t\tthrow new Error(`Empty request URL`);\n\t}\n\tif (!path.startsWith(\"/\")) {\n\t\tpath = \"/\" + path;\n\t}\n\tconst { host } = req.headers;\n\tif (host == undefined) {\n\t\tthrow new Error(`Missing \"Host\" header`);\n\t}\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst url = `${protocol}://${host}${path}`;\n\n\t// Flatten the headers\n\tconst headers = flattenHeaders(req.headers);\n\n\t// Convert body to Buffer if applicable\n\tconst body =\n\t\treq.method !== \"GET\" && req.method !== \"HEAD\"\n\t\t\t? (Readable.toWeb(req) as ReadableStream) // await readableToBuffer(req)\n\t\t\t: null;\n\n\treturn new Request(url, {\n\t\tmethod: req.method,\n\t\theaders: headers,\n\t\tbody: body,\n\t\t// @ts-ignore this is needed for using a Readable for some reason\n\t\tduplex: \"half\",\n\t});\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import { ServerResponse } from \"node:http\";\nimport { Http2ServerResponse } from \"node:http2\";\nimport { isArrayBufferView } from \"node:util/types\";\nimport { INTERNAL_BODY } from \"./constants\";\n\nexport default async function responseToNodeResponse(\n\tres: Response,\n\toutgoing: ServerResponse | Http2ServerResponse,\n): Promise<void> {\n\toutgoing.statusCode = res.status;\n\toutgoing.statusMessage = res.statusText;\n\n\tres.headers.forEach((value, key) => {\n\t\toutgoing.setHeader(key, value);\n\t});\n\n\tconst body = (res as any)[INTERNAL_BODY];\n\n\tif (body === null || body === undefined) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else if (typeof body === \"string\" || body instanceof Uint8Array) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(body);\n\t} else if (body instanceof Blob) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(await body.arrayBuffer()));\n\t} else if (body instanceof ArrayBuffer) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body));\n\t} else if (isArrayBufferView(body)) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body.buffer));\n\t} else if (body instanceof FormData) {\n\t\t// TODO\n\t\toutgoing.setHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t}\n}\n","import { type IncomingMessage, ServerResponse } from \"node:http\";\nimport { Http2ServerRequest, Http2ServerResponse } from \"node:http2\";\nimport { INTERNAL_BODY } from \"./constants\";\nimport nodeMessageToRequest from \"./nodeMessageToRequest\";\nimport responseToNodeResponse from \"./responseToNodeResponse\";\n\n// From https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n// Referenced from https://marvinh.dev/blog/modern-way-to-write-javascript-servers/\n\nconst GlobalResponse = Response;\nglobalThis.Response = class Response extends GlobalResponse {\n\t[INTERNAL_BODY]: BodyInit | null | undefined = null;\n\n\tconstructor(body?: BodyInit | null, init?: ResponseInit) {\n\t\tsuper(body, init);\n\t\tthis[INTERNAL_BODY] = body;\n\t}\n};\n\nexport function createFetchHandler(handler: (req: Request) => Response | Promise<Response>) {\n\treturn async (\n\t\tincoming: IncomingMessage | Http2ServerRequest,\n\t\toutgoing: ServerResponse | Http2ServerResponse,\n\t): Promise<void> => {\n\t\tconst req = await nodeMessageToRequest(incoming);\n\t\tconst res = await handler(req);\n\t\treturn await responseToNodeResponse(res, outgoing);\n\t};\n}\n","import { type Adapter } from \"@torpor/build\";\nimport { Server } from \"@torpor/build/server\";\nimport createNodeServer from \"./createNodeServer\";\n\nexport default {\n\tserve: (server: Server) => {\n\t\tprocess.env.PROTOCOL ??= \"http:\";\n\t\tprocess.env.HOST ??= \"localhost\";\n\t\tprocess.env.PORT ??= \"7059\";\n\n\t\t// Put adapter-specific functionality in the `adapter` property of\n\t\t// globalThis for now\n\t\t// @ts-ignore\n\t\tglobalThis.adapter = { env: process.env };\n\n\t\t// Create the Node server and start listening\n\t\tconst url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;\n\t\tconsole.log(`\\nConnecting to ${url}`);\n\t\tconst devServer = createNodeServer(server.fetch);\n\t\tdevServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {\n\t\t\tconsole.log(`Listening on ${url}\\n`);\n\t\t});\n\t},\n} satisfies Adapter as Adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAA6B;;;ACD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,UAAM,MAAM,MAAM,qBAAqB,QAAQ;AAC/C,UAAM,MAAM,MAAM,QAAQ,GAAG;AAC7B,WAAO,MAAM,uBAAuB,KAAK,QAAQ;AAAA,EAClD;AACD;;;ALxBe,SAAR,iBACN,SACwD;AAGxD,aAAO,+BAAa,mBAAmB,OAAO,CAAC;AAChD;;;AMNA,IAAO,kBAAQ;AAAA,EACd,OAAO,CAAC,WAAmB;AAC1B,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS;AAKrB,eAAW,UAAU,EAAE,KAAK,QAAQ,IAAI;AAGxC,UAAM,MAAM,GAAG,QAAQ,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI;AAC5E,YAAQ,IAAI;AAAA,gBAAmB,GAAG,EAAE;AACpC,UAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,cAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,GAAG,QAAQ,IAAI,MAAM,MAAM;AACpE,cAAQ,IAAI,gBAAgB,GAAG;AAAA,CAAI;AAAA,IACpC,CAAC;AAAA,EACF;AACD;","names":["v","Response"]}
package/dist/index.js CHANGED
@@ -114,6 +114,7 @@ var adapter_default = {
114
114
  process.env.PROTOCOL ??= "http:";
115
115
  process.env.HOST ??= "localhost";
116
116
  process.env.PORT ??= "7059";
117
+ globalThis.adapter = { env: process.env };
117
118
  const url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;
118
119
  console.log(`
119
120
  Connecting to ${url}`);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createNodeServer.ts","../src/constants.ts","../src/nodeMessageToRequest.ts","../src/flattenHeaders.ts","../src/responseToNodeResponse.ts","../src/createFetchHandler.ts","../src/adapter.ts"],"sourcesContent":["import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(\n\thandler: (req: Request) => Response | Promise<Response>,\n): Server<typeof IncomingMessage, typeof ServerResponse> {\n\t// Create a server, polyfill it so that it can handle standard fetch methods,\n\t// and pass our app fetch method to the handler\n\treturn createServer(createFetchHandler(handler));\n}\n","export const INTERNAL_BODY: unique symbol = Symbol(\"internal_body\");\n","import { type IncomingMessage } from \"node:http\";\nimport { Http2ServerRequest } from \"node:http2\";\nimport { Readable } from \"node:stream\";\nimport flattenHeaders from \"./flattenHeaders\";\n\n// From https://stackoverflow.com/a/78849544\n// and https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n\nexport default async function nodeMessageToRequest(\n\treq: IncomingMessage | Http2ServerRequest,\n): Promise<Request> {\n\t// Build the full url\n\tlet path = req.url;\n\tif (path === undefined) {\n\t\tthrow new Error(`Empty request URL`);\n\t}\n\tif (!path.startsWith(\"/\")) {\n\t\tpath = \"/\" + path;\n\t}\n\tconst { host } = req.headers;\n\tif (host == undefined) {\n\t\tthrow new Error(`Missing \"Host\" header`);\n\t}\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst url = `${protocol}://${host}${path}`;\n\n\t// Flatten the headers\n\tconst headers = flattenHeaders(req.headers);\n\n\t// Convert body to Buffer if applicable\n\tconst body =\n\t\treq.method !== \"GET\" && req.method !== \"HEAD\"\n\t\t\t? (Readable.toWeb(req) as ReadableStream) // await readableToBuffer(req)\n\t\t\t: null;\n\n\treturn new Request(url, {\n\t\tmethod: req.method,\n\t\theaders: headers,\n\t\tbody: body,\n\t\t// @ts-ignore this is needed for using a Readable for some reason\n\t\tduplex: \"half\",\n\t});\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import { ServerResponse } from \"node:http\";\nimport { Http2ServerResponse } from \"node:http2\";\nimport { isArrayBufferView } from \"node:util/types\";\nimport { INTERNAL_BODY } from \"./constants\";\n\nexport default async function responseToNodeResponse(\n\tres: Response,\n\toutgoing: ServerResponse | Http2ServerResponse,\n): Promise<void> {\n\toutgoing.statusCode = res.status;\n\toutgoing.statusMessage = res.statusText;\n\n\tres.headers.forEach((value, key) => {\n\t\toutgoing.setHeader(key, value);\n\t});\n\n\tconst body = (res as any)[INTERNAL_BODY];\n\n\tif (body === null || body === undefined) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else if (typeof body === \"string\" || body instanceof Uint8Array) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(body);\n\t} else if (body instanceof Blob) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(await body.arrayBuffer()));\n\t} else if (body instanceof ArrayBuffer) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body));\n\t} else if (isArrayBufferView(body)) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body.buffer));\n\t} else if (body instanceof FormData) {\n\t\t// TODO\n\t\toutgoing.setHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t}\n}\n","import { type IncomingMessage, ServerResponse } from \"node:http\";\nimport { Http2ServerRequest, Http2ServerResponse } from \"node:http2\";\nimport { INTERNAL_BODY } from \"./constants\";\nimport nodeMessageToRequest from \"./nodeMessageToRequest\";\nimport responseToNodeResponse from \"./responseToNodeResponse\";\n\n// From https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n// Referenced from https://marvinh.dev/blog/modern-way-to-write-javascript-servers/\n\nconst GlobalResponse = Response;\nglobalThis.Response = class Response extends GlobalResponse {\n\t[INTERNAL_BODY]: BodyInit | null | undefined = null;\n\n\tconstructor(body?: BodyInit | null, init?: ResponseInit) {\n\t\tsuper(body, init);\n\t\tthis[INTERNAL_BODY] = body;\n\t}\n};\n\nexport function createFetchHandler(handler: (req: Request) => Response | Promise<Response>) {\n\treturn async (\n\t\tincoming: IncomingMessage | Http2ServerRequest,\n\t\toutgoing: ServerResponse | Http2ServerResponse,\n\t): Promise<void> => {\n\t\tconst req = await nodeMessageToRequest(incoming);\n\t\tconst res = await handler(req);\n\t\treturn await responseToNodeResponse(res, outgoing);\n\t};\n}\n","import { type Adapter } from \"@torpor/build\";\nimport { Server } from \"@torpor/build/server\";\nimport createNodeServer from \"./createNodeServer\";\n\nexport default {\n\tserve: (server: Server) => {\n\t\tprocess.env.PROTOCOL ??= \"http:\";\n\t\tprocess.env.HOST ??= \"localhost\";\n\t\tprocess.env.PORT ??= \"7059\";\n\n\t\t// Create the Node server and start listening\n\t\tconst url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;\n\t\tconsole.log(`\\nConnecting to ${url}`);\n\t\tconst devServer = createNodeServer(server.fetch);\n\t\tdevServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {\n\t\t\tconsole.log(`Listening on ${url}\\n`);\n\t\t});\n\t},\n} satisfies Adapter as Adapter;\n"],"mappings":";AACA,SAAS,oBAAoB;;;ACDtB,IAAM,gBAA+B,OAAO,eAAe;;;ACElE,SAAS,gBAAgB;;;ACCV,SAAR,eACN,SACc;AACd,QAAM,cAAc,IAAI,QAAQ;AAChC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AACnD,QAAI,UAAU,UAAa,UAAU,MAAM;AAC1C;AAAA,IACD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAChC,iBAAW,KAAK,OAAO;AACtB,YAAI,MAAM,UAAa,MAAM,MAAM;AAClC,gBAAM,QAAQ,CAACA,OAAM,YAAY,OAAO,KAAKA,EAAC,CAAC;AAAA,QAChD;AAAA,MACD;AAAA,IACD,OAAO;AACN,kBAAY,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,IACnC;AAAA,EACD;AACA,SAAO;AAuBR;;;ADnCA,eAAO,qBACN,KACmB;AAEnB,MAAI,OAAO,IAAI;AACf,MAAI,SAAS,QAAW;AACvB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AACA,MAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AAC1B,WAAO,MAAM;AAAA,EACd;AACA,QAAM,EAAE,KAAK,IAAI,IAAI;AACrB,MAAI,QAAQ,QAAW;AACtB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACxC;AACA,QAAM,WAAW,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,UAAU;AAC/E,QAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,GAAG,IAAI;AAGxC,QAAM,UAAU,eAAe,IAAI,OAAO;AAG1C,QAAM,OACL,IAAI,WAAW,SAAS,IAAI,WAAW,SACnC,SAAS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;AACvB,WAAW,WAAW,MAAMC,kBAAiB,eAAe;AAAA,EAC3D,CAAC,aAAa,IAAiC;AAAA,EAE/C,YAAY,MAAwB,MAAqB;AACxD,UAAM,MAAM,IAAI;AAChB,SAAK,aAAa,IAAI;AAAA,EACvB;AACD;AAEO,SAAS,mBAAmB,SAAyD;AAC3F,SAAO,OACN,UACA,aACmB;AACnB,UAAM,MAAM,MAAM,qBAAqB,QAAQ;AAC/C,UAAM,MAAM,MAAM,QAAQ,GAAG;AAC7B,WAAO,MAAM,uBAAuB,KAAK,QAAQ;AAAA,EAClD;AACD;;;ALxBe,SAAR,iBACN,SACwD;AAGxD,SAAO,aAAa,mBAAmB,OAAO,CAAC;AAChD;;;AMNA,IAAO,kBAAQ;AAAA,EACd,OAAO,CAAC,WAAmB;AAC1B,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS;AAGrB,UAAM,MAAM,GAAG,QAAQ,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI;AAC5E,YAAQ,IAAI;AAAA,gBAAmB,GAAG,EAAE;AACpC,UAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,cAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,GAAG,QAAQ,IAAI,MAAM,MAAM;AACpE,cAAQ,IAAI,gBAAgB,GAAG;AAAA,CAAI;AAAA,IACpC,CAAC;AAAA,EACF;AACD;","names":["v","Response"]}
1
+ {"version":3,"sources":["../src/createNodeServer.ts","../src/constants.ts","../src/nodeMessageToRequest.ts","../src/flattenHeaders.ts","../src/responseToNodeResponse.ts","../src/createFetchHandler.ts","../src/adapter.ts"],"sourcesContent":["import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(\n\thandler: (req: Request) => Response | Promise<Response>,\n): Server<typeof IncomingMessage, typeof ServerResponse> {\n\t// Create a server, polyfill it so that it can handle standard fetch methods,\n\t// and pass our app fetch method to the handler\n\treturn createServer(createFetchHandler(handler));\n}\n","export const INTERNAL_BODY: unique symbol = Symbol(\"internal_body\");\n","import { type IncomingMessage } from \"node:http\";\nimport { Http2ServerRequest } from \"node:http2\";\nimport { Readable } from \"node:stream\";\nimport flattenHeaders from \"./flattenHeaders\";\n\n// From https://stackoverflow.com/a/78849544\n// and https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n\nexport default async function nodeMessageToRequest(\n\treq: IncomingMessage | Http2ServerRequest,\n): Promise<Request> {\n\t// Build the full url\n\tlet path = req.url;\n\tif (path === undefined) {\n\t\tthrow new Error(`Empty request URL`);\n\t}\n\tif (!path.startsWith(\"/\")) {\n\t\tpath = \"/\" + path;\n\t}\n\tconst { host } = req.headers;\n\tif (host == undefined) {\n\t\tthrow new Error(`Missing \"Host\" header`);\n\t}\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst url = `${protocol}://${host}${path}`;\n\n\t// Flatten the headers\n\tconst headers = flattenHeaders(req.headers);\n\n\t// Convert body to Buffer if applicable\n\tconst body =\n\t\treq.method !== \"GET\" && req.method !== \"HEAD\"\n\t\t\t? (Readable.toWeb(req) as ReadableStream) // await readableToBuffer(req)\n\t\t\t: null;\n\n\treturn new Request(url, {\n\t\tmethod: req.method,\n\t\theaders: headers,\n\t\tbody: body,\n\t\t// @ts-ignore this is needed for using a Readable for some reason\n\t\tduplex: \"half\",\n\t});\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import { ServerResponse } from \"node:http\";\nimport { Http2ServerResponse } from \"node:http2\";\nimport { isArrayBufferView } from \"node:util/types\";\nimport { INTERNAL_BODY } from \"./constants\";\n\nexport default async function responseToNodeResponse(\n\tres: Response,\n\toutgoing: ServerResponse | Http2ServerResponse,\n): Promise<void> {\n\toutgoing.statusCode = res.status;\n\toutgoing.statusMessage = res.statusText;\n\n\tres.headers.forEach((value, key) => {\n\t\toutgoing.setHeader(key, value);\n\t});\n\n\tconst body = (res as any)[INTERNAL_BODY];\n\n\tif (body === null || body === undefined) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else if (typeof body === \"string\" || body instanceof Uint8Array) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(body);\n\t} else if (body instanceof Blob) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(await body.arrayBuffer()));\n\t} else if (body instanceof ArrayBuffer) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body));\n\t} else if (isArrayBufferView(body)) {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end(new Uint8Array(body.buffer));\n\t} else if (body instanceof FormData) {\n\t\t// TODO\n\t\toutgoing.setHeader(\"Content-Type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t} else {\n\t\toutgoing.writeHead(res.status, res.statusText);\n\t\toutgoing.end();\n\t}\n}\n","import { type IncomingMessage, ServerResponse } from \"node:http\";\nimport { Http2ServerRequest, Http2ServerResponse } from \"node:http2\";\nimport { INTERNAL_BODY } from \"./constants\";\nimport nodeMessageToRequest from \"./nodeMessageToRequest\";\nimport responseToNodeResponse from \"./responseToNodeResponse\";\n\n// From https://gist.github.com/marvinhagemeister/cc236ec97235ce0305ae9d48a24a607d\n// Referenced from https://marvinh.dev/blog/modern-way-to-write-javascript-servers/\n\nconst GlobalResponse = Response;\nglobalThis.Response = class Response extends GlobalResponse {\n\t[INTERNAL_BODY]: BodyInit | null | undefined = null;\n\n\tconstructor(body?: BodyInit | null, init?: ResponseInit) {\n\t\tsuper(body, init);\n\t\tthis[INTERNAL_BODY] = body;\n\t}\n};\n\nexport function createFetchHandler(handler: (req: Request) => Response | Promise<Response>) {\n\treturn async (\n\t\tincoming: IncomingMessage | Http2ServerRequest,\n\t\toutgoing: ServerResponse | Http2ServerResponse,\n\t): Promise<void> => {\n\t\tconst req = await nodeMessageToRequest(incoming);\n\t\tconst res = await handler(req);\n\t\treturn await responseToNodeResponse(res, outgoing);\n\t};\n}\n","import { type Adapter } from \"@torpor/build\";\nimport { Server } from \"@torpor/build/server\";\nimport createNodeServer from \"./createNodeServer\";\n\nexport default {\n\tserve: (server: Server) => {\n\t\tprocess.env.PROTOCOL ??= \"http:\";\n\t\tprocess.env.HOST ??= \"localhost\";\n\t\tprocess.env.PORT ??= \"7059\";\n\n\t\t// Put adapter-specific functionality in the `adapter` property of\n\t\t// globalThis for now\n\t\t// @ts-ignore\n\t\tglobalThis.adapter = { env: process.env };\n\n\t\t// Create the Node server and start listening\n\t\tconst url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;\n\t\tconsole.log(`\\nConnecting to ${url}`);\n\t\tconst devServer = createNodeServer(server.fetch);\n\t\tdevServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {\n\t\t\tconsole.log(`Listening on ${url}\\n`);\n\t\t});\n\t},\n} satisfies Adapter as Adapter;\n"],"mappings":";AACA,SAAS,oBAAoB;;;ACDtB,IAAM,gBAA+B,OAAO,eAAe;;;ACElE,SAAS,gBAAgB;;;ACCV,SAAR,eACN,SACc;AACd,QAAM,cAAc,IAAI,QAAQ;AAChC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AACnD,QAAI,UAAU,UAAa,UAAU,MAAM;AAC1C;AAAA,IACD,WAAW,MAAM,QAAQ,KAAK,GAAG;AAChC,iBAAW,KAAK,OAAO;AACtB,YAAI,MAAM,UAAa,MAAM,MAAM;AAClC,gBAAM,QAAQ,CAACA,OAAM,YAAY,OAAO,KAAKA,EAAC,CAAC;AAAA,QAChD;AAAA,MACD;AAAA,IACD,OAAO;AACN,kBAAY,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,IACnC;AAAA,EACD;AACA,SAAO;AAuBR;;;ADnCA,eAAO,qBACN,KACmB;AAEnB,MAAI,OAAO,IAAI;AACf,MAAI,SAAS,QAAW;AACvB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AACA,MAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AAC1B,WAAO,MAAM;AAAA,EACd;AACA,QAAM,EAAE,KAAK,IAAI,IAAI;AACrB,MAAI,QAAQ,QAAW;AACtB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACxC;AACA,QAAM,WAAW,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,UAAU;AAC/E,QAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,GAAG,IAAI;AAGxC,QAAM,UAAU,eAAe,IAAI,OAAO;AAG1C,QAAM,OACL,IAAI,WAAW,SAAS,IAAI,WAAW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AAM,iBAAiB;AACvB,WAAW,WAAW,MAAMC,kBAAiB,eAAe;AAAA,EAC3D,CAAC,aAAa,IAAiC;AAAA,EAE/C,YAAY,MAAwB,MAAqB;AACxD,UAAM,MAAM,IAAI;AAChB,SAAK,aAAa,IAAI;AAAA,EACvB;AACD;AAEO,SAAS,mBAAmB,SAAyD;AAC3F,SAAO,OACN,UACA,aACmB;AACnB,UAAM,MAAM,MAAM,qBAAqB,QAAQ;AAC/C,UAAM,MAAM,MAAM,QAAQ,GAAG;AAC7B,WAAO,MAAM,uBAAuB,KAAK,QAAQ;AAAA,EAClD;AACD;;;ALxBe,SAAR,iBACN,SACwD;AAGxD,SAAO,aAAa,mBAAmB,OAAO,CAAC;AAChD;;;AMNA,IAAO,kBAAQ;AAAA,EACd,OAAO,CAAC,WAAmB;AAC1B,YAAQ,IAAI,aAAa;AACzB,YAAQ,IAAI,SAAS;AACrB,YAAQ,IAAI,SAAS;AAKrB,eAAW,UAAU,EAAE,KAAK,QAAQ,IAAI;AAGxC,UAAM,MAAM,GAAG,QAAQ,IAAI,QAAQ,KAAK,QAAQ,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI;AAC5E,YAAQ,IAAI;AAAA,gBAAmB,GAAG,EAAE;AACpC,UAAM,YAAY,iBAAiB,OAAO,KAAK;AAC/C,cAAU,OAAO,SAAS,QAAQ,IAAI,IAAI,GAAG,QAAQ,IAAI,MAAM,MAAM;AACpE,cAAQ,IAAI,gBAAgB,GAAG;AAAA,CAAI;AAAA,IACpC,CAAC;AAAA,EACF;AACD;","names":["v","Response"]}
@@ -1 +1 @@
1
- {"inputs":{"src/constants.ts":{"bytes":69,"imports":[],"format":"esm"},"src/flattenHeaders.ts":{"bytes":1017,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true}],"format":"esm"},"src/nodeMessageToRequest.ts":{"bytes":1277,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"stream","kind":"import-statement","external":true},{"path":"src/flattenHeaders.ts","kind":"import-statement","original":"./flattenHeaders"}],"format":"esm"},"src/responseToNodeResponse.ts":{"bytes":1486,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"util/types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"}],"format":"esm"},"src/createFetchHandler.ts":{"bytes":1119,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/nodeMessageToRequest.ts","kind":"import-statement","original":"./nodeMessageToRequest"},{"path":"src/responseToNodeResponse.ts","kind":"import-statement","original":"./responseToNodeResponse"}],"format":"esm"},"src/createNodeServer.ts":{"bytes":506,"imports":[{"path":"http","kind":"import-statement","external":true},{"path":"http","kind":"import-statement","external":true},{"path":"src/createFetchHandler.ts","kind":"import-statement","original":"./createFetchHandler"}],"format":"esm"},"src/adapter.ts":{"bytes":675,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"@torpor/build/server","kind":"import-statement","external":true},{"path":"src/createNodeServer.ts","kind":"import-statement","original":"./createNodeServer"}],"format":"esm"},"src/index.ts":{"bytes":48,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9758},"dist/index.cjs":{"imports":[{"path":"http","kind":"require-call","external":true},{"path":"stream","kind":"require-call","external":true},{"path":"util/types","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":130},"src/createNodeServer.ts":{"bytesInOutput":153},"src/constants.ts":{"bytesInOutput":45},"src/nodeMessageToRequest.ts":{"bytesInOutput":808},"src/flattenHeaders.ts":{"bytesInOutput":472},"src/responseToNodeResponse.ts":{"bytesInOutput":1289},"src/createFetchHandler.ts":{"bytesInOutput":443},"src/adapter.ts":{"bytesInOutput":469}},"bytes":4973}}}
1
+ {"inputs":{"src/constants.ts":{"bytes":69,"imports":[],"format":"esm"},"src/flattenHeaders.ts":{"bytes":1017,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true}],"format":"esm"},"src/nodeMessageToRequest.ts":{"bytes":1277,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"stream","kind":"import-statement","external":true},{"path":"src/flattenHeaders.ts","kind":"import-statement","original":"./flattenHeaders"}],"format":"esm"},"src/responseToNodeResponse.ts":{"bytes":1486,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"util/types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"}],"format":"esm"},"src/createFetchHandler.ts":{"bytes":1119,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/nodeMessageToRequest.ts","kind":"import-statement","original":"./nodeMessageToRequest"},{"path":"src/responseToNodeResponse.ts","kind":"import-statement","original":"./responseToNodeResponse"}],"format":"esm"},"src/createNodeServer.ts":{"bytes":506,"imports":[{"path":"http","kind":"import-statement","external":true},{"path":"http","kind":"import-statement","external":true},{"path":"src/createFetchHandler.ts","kind":"import-statement","original":"./createFetchHandler"}],"format":"esm"},"src/adapter.ts":{"bytes":830,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"@torpor/build/server","kind":"import-statement","external":true},{"path":"src/createNodeServer.ts","kind":"import-statement","original":"./createNodeServer"}],"format":"esm"},"src/index.ts":{"bytes":48,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9962},"dist/index.cjs":{"imports":[{"path":"http","kind":"require-call","external":true},{"path":"stream","kind":"require-call","external":true},{"path":"util/types","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":130},"src/createNodeServer.ts":{"bytesInOutput":153},"src/constants.ts":{"bytesInOutput":45},"src/nodeMessageToRequest.ts":{"bytesInOutput":808},"src/flattenHeaders.ts":{"bytesInOutput":472},"src/responseToNodeResponse.ts":{"bytesInOutput":1289},"src/createFetchHandler.ts":{"bytesInOutput":443},"src/adapter.ts":{"bytesInOutput":516}},"bytes":5020}}}
@@ -1 +1 @@
1
- {"inputs":{"src/constants.ts":{"bytes":69,"imports":[],"format":"esm"},"src/flattenHeaders.ts":{"bytes":1017,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true}],"format":"esm"},"src/nodeMessageToRequest.ts":{"bytes":1277,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"node:stream","kind":"import-statement","external":true},{"path":"src/flattenHeaders.ts","kind":"import-statement","original":"./flattenHeaders"}],"format":"esm"},"src/responseToNodeResponse.ts":{"bytes":1486,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"node:util/types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"}],"format":"esm"},"src/createFetchHandler.ts":{"bytes":1119,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/nodeMessageToRequest.ts","kind":"import-statement","original":"./nodeMessageToRequest"},{"path":"src/responseToNodeResponse.ts","kind":"import-statement","original":"./responseToNodeResponse"}],"format":"esm"},"src/createNodeServer.ts":{"bytes":506,"imports":[{"path":"http","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"src/createFetchHandler.ts","kind":"import-statement","original":"./createFetchHandler"}],"format":"esm"},"src/adapter.ts":{"bytes":675,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"@torpor/build/server","kind":"import-statement","external":true},{"path":"src/createNodeServer.ts","kind":"import-statement","original":"./createNodeServer"}],"format":"esm"},"src/index.ts":{"bytes":48,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":9649},"dist/index.js":{"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:stream","kind":"import-statement","external":true},{"path":"node:util/types","kind":"import-statement","external":true}],"exports":["node"],"entryPoint":"src/index.ts","inputs":{"src/createNodeServer.ts":{"bytesInOutput":133},"src/constants.ts":{"bytesInOutput":45},"src/nodeMessageToRequest.ts":{"bytesInOutput":785},"src/flattenHeaders.ts":{"bytesInOutput":472},"src/responseToNodeResponse.ts":{"bytesInOutput":1282},"src/createFetchHandler.ts":{"bytesInOutput":443},"src/adapter.ts":{"bytesInOutput":469},"src/index.ts":{"bytesInOutput":0}},"bytes":3916}}}
1
+ {"inputs":{"src/constants.ts":{"bytes":69,"imports":[],"format":"esm"},"src/flattenHeaders.ts":{"bytes":1017,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true}],"format":"esm"},"src/nodeMessageToRequest.ts":{"bytes":1277,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"node:stream","kind":"import-statement","external":true},{"path":"src/flattenHeaders.ts","kind":"import-statement","original":"./flattenHeaders"}],"format":"esm"},"src/responseToNodeResponse.ts":{"bytes":1486,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"node:util/types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"}],"format":"esm"},"src/createFetchHandler.ts":{"bytes":1119,"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:http2","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants"},{"path":"src/nodeMessageToRequest.ts","kind":"import-statement","original":"./nodeMessageToRequest"},{"path":"src/responseToNodeResponse.ts","kind":"import-statement","original":"./responseToNodeResponse"}],"format":"esm"},"src/createNodeServer.ts":{"bytes":506,"imports":[{"path":"http","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"src/createFetchHandler.ts","kind":"import-statement","original":"./createFetchHandler"}],"format":"esm"},"src/adapter.ts":{"bytes":830,"imports":[{"path":"@torpor/build","kind":"import-statement","external":true},{"path":"@torpor/build/server","kind":"import-statement","external":true},{"path":"src/createNodeServer.ts","kind":"import-statement","original":"./createNodeServer"}],"format":"esm"},"src/index.ts":{"bytes":48,"imports":[{"path":"src/adapter.ts","kind":"import-statement","original":"./adapter"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":9853},"dist/index.js":{"imports":[{"path":"node:http","kind":"import-statement","external":true},{"path":"node:stream","kind":"import-statement","external":true},{"path":"node:util/types","kind":"import-statement","external":true}],"exports":["node"],"entryPoint":"src/index.ts","inputs":{"src/createNodeServer.ts":{"bytesInOutput":133},"src/constants.ts":{"bytesInOutput":45},"src/nodeMessageToRequest.ts":{"bytesInOutput":785},"src/flattenHeaders.ts":{"bytesInOutput":472},"src/responseToNodeResponse.ts":{"bytesInOutput":1282},"src/createFetchHandler.ts":{"bytesInOutput":443},"src/adapter.ts":{"bytesInOutput":516},"src/index.ts":{"bytesInOutput":0}},"bytes":3963}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/adapter-node",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "A @torpor/build adapter for running on Node",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -19,7 +19,7 @@
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
21
  "vite": "^6.3.3",
22
- "@torpor/build": "^0.1.12"
22
+ "@torpor/build": "^0.1.13"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
package/src/adapter.ts CHANGED
@@ -8,6 +8,11 @@ export default {
8
8
  process.env.HOST ??= "localhost";
9
9
  process.env.PORT ??= "7059";
10
10
 
11
+ // Put adapter-specific functionality in the `adapter` property of
12
+ // globalThis for now
13
+ // @ts-ignore
14
+ globalThis.adapter = { env: process.env };
15
+
11
16
  // Create the Node server and start listening
12
17
  const url = `${process.env.PROTOCOL}//${process.env.HOST}:${process.env.PORT}`;
13
18
  console.log(`\nConnecting to ${url}`);