@torpor/build 0.1.13 → 0.1.14

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/build
2
2
 
3
+ ## 0.1.14
4
+
5
+ ### Patch Changes
6
+
7
+ - e395c9e: Feat: rudimentary test infrastructure
8
+ - Updated dependencies [5676a0b]
9
+ - @torpor/unplugin@0.1.6
10
+
3
11
  ## 0.1.13
4
12
 
5
13
  ### Patch Changes
package/dist/bin/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #! /usr/bin/env node
2
2
  import {
3
3
  run
4
- } from "../chunk-GWXPZFMX.js";
5
- import "../chunk-PTCWU3AW.js";
6
- import "../chunk-27LTVTCS.js";
4
+ } from "../chunk-XLNPB3GH.js";
5
+ import "../chunk-D6LHMH2C.js";
6
+ import "../chunk-FMRCLIWE.js";
7
+ import "../chunk-2QQN3D3K.js";
8
+ import "../chunk-EVBUHZGK.js";
7
9
  import "../chunk-SJVHHGVW.js";
8
10
 
9
11
  // src/bin/index.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run from \"../site/run\";\n\n(async () => {\n\tconst workingDir = process.cwd();\n\tif (process.argv.includes(\"--dev\")) {\n\t\tawait run(workingDir, \"dev\");\n\t} else if (process.argv.includes(\"--build\")) {\n\t\tawait run(workingDir, \"build\");\n\t} else if (process.argv.includes(\"--preview\")) {\n\t\tawait run(workingDir, \"preview\");\n\t}\n})();\n"],"mappings":";;;;;;;;;CAGC,YAAY;AACZ,QAAM,aAAa,QAAQ,IAAI;AAC/B,MAAI,QAAQ,KAAK,SAAS,OAAO,GAAG;AACnC,UAAM,IAAI,YAAY,KAAK;AAAA,EAC5B,WAAW,QAAQ,KAAK,SAAS,SAAS,GAAG;AAC5C,UAAM,IAAI,YAAY,OAAO;AAAA,EAC9B,WAAW,QAAQ,KAAK,SAAS,WAAW,GAAG;AAC9C,UAAM,IAAI,YAAY,SAAS;AAAA,EAChC;AACD,GAAG;","names":[]}
1
+ {"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run from \"../site/run\";\n\n(async () => {\n\tconst workingDir = process.cwd();\n\tif (process.argv.includes(\"--dev\")) {\n\t\tawait run(workingDir, \"dev\");\n\t} else if (process.argv.includes(\"--build\")) {\n\t\tawait run(workingDir, \"build\");\n\t} else if (process.argv.includes(\"--preview\")) {\n\t\tawait run(workingDir, \"preview\");\n\t}\n})();\n"],"mappings":";;;;;;;;;;;CAGC,YAAY;AACZ,QAAM,aAAa,QAAQ,IAAI;AAC/B,MAAI,QAAQ,KAAK,SAAS,OAAO,GAAG;AACnC,UAAM,IAAI,YAAY,KAAK;AAAA,EAC5B,WAAW,QAAQ,KAAK,SAAS,SAAS,GAAG;AAC5C,UAAM,IAAI,YAAY,OAAO;AAAA,EAC9B,WAAW,QAAQ,KAAK,SAAS,WAAW,GAAG;AAC9C,UAAM,IAAI,YAAY,SAAS;AAAA,EAChC;AACD,GAAG;","names":[]}
@@ -0,0 +1,50 @@
1
+ // src/response/response.ts
2
+ function response(status, body) {
3
+ let headers = void 0;
4
+ if (body) {
5
+ if (typeof body === "object") {
6
+ headers = { "content-type": "application/json" };
7
+ body = JSON.stringify(body);
8
+ } else {
9
+ headers = { "content-type": "text/plain" };
10
+ }
11
+ }
12
+ return new Response(body, {
13
+ status,
14
+ headers
15
+ });
16
+ }
17
+
18
+ // src/response/transfer.ts
19
+ function transfer(status, location) {
20
+ return new Response(null, {
21
+ status,
22
+ headers: {
23
+ location
24
+ }
25
+ });
26
+ }
27
+
28
+ // src/response/notFound.ts
29
+ function notFound(body) {
30
+ return response(404, body);
31
+ }
32
+
33
+ // src/response/ok.ts
34
+ function ok(body) {
35
+ return response(200, body);
36
+ }
37
+
38
+ // src/response/seeOther.ts
39
+ function seeOther(location) {
40
+ return transfer(303, location);
41
+ }
42
+
43
+ export {
44
+ response,
45
+ transfer,
46
+ notFound,
47
+ ok,
48
+ seeOther
49
+ };
50
+ //# sourceMappingURL=chunk-2QQN3D3K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/response/response.ts","../src/response/transfer.ts","../src/response/notFound.ts","../src/response/ok.ts","../src/response/seeOther.ts"],"sourcesContent":["/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the content-type\n * header set to \"application/json\". Otherwise, if the body is a string, the\n * content-type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string): Response {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\theaders = { \"content-type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(body);\n\t\t} else {\n\t\t\theaders = { \"content-type\": \"text/plain\" };\n\t\t}\n\t}\n\treturn new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t});\n}\n","/**\n * Creates a redirect response with the supplied status code.\n */\nexport default function transfer(\n\tstatus: 300 | 301 | 302 | 303 | 304 | 307 | 308,\n\tlocation: string,\n): Response {\n\treturn new Response(null, {\n\t\tstatus,\n\t\theaders: {\n\t\t\tlocation,\n\t\t},\n\t});\n}\n","import response from \"./response\";\n\n/**\n * 404 Not Found\n *\n * The server cannot find the requested resource. In the browser, this means the\n * URL is not recognized. In an API, this can also mean that the endpoint is\n * valid but the resource itself does not exist. Servers may also send this\n * response instead of 403 Forbidden to hide the existence of a resource from an\n * unauthorized client. This response code is probably the most well known due\n * to its frequent occurrence on the web.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404\n */\nexport default function notFound(body?: object | string): Response {\n\treturn response(404, body);\n}\n","import response from \"./response\";\n\n/**\n * 200 OK\n *\n * The request succeeded. The result meaning of \"success\" depends on the HTTP\n * method:\n * - GET: The resource has been fetched and transmitted in the message body.\n * - HEAD: The representation headers are included in the response without any\n * message body.\n * - PUT or POST: The resource describing the result of the action is\n * transmitted in the message body.\n * - TRACE: The message body contains the request message as received by the\n * server.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200\n */\nexport default function ok(body?: object | string): Response {\n\treturn response(200, body);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 303 See Other\n *\n * The server sent this response to direct the client to get the requested\n * resource at another URI with a GET request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303\n */\nexport default function seeOther(location: string): Response {\n\treturn transfer(303, location);\n}\n"],"mappings":";AAOe,SAAR,SAA0B,QAAgB,MAAkC;AAClF,MAAI,UAA8C;AAClD,MAAI,MAAM;AACT,QAAI,OAAO,SAAS,UAAU;AAC7B,gBAAU,EAAE,gBAAgB,mBAAmB;AAC/C,aAAO,KAAK,UAAU,IAAI;AAAA,IAC3B,OAAO;AACN,gBAAU,EAAE,gBAAgB,aAAa;AAAA,IAC1C;AAAA,EACD;AACA,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,EACD,CAAC;AACF;;;AClBe,SAAR,SACN,QACA,UACW;AACX,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB;AAAA,IACA,SAAS;AAAA,MACR;AAAA,IACD;AAAA,EACD,CAAC;AACF;;;ACCe,SAAR,SAA0B,MAAkC;AAClE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACCe,SAAR,GAAoB,MAAkC;AAC5D,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACTe,SAAR,SAA0B,UAA4B;AAC5D,SAAO,SAAS,KAAK,QAAQ;AAC9B;","names":[]}
@@ -0,0 +1,150 @@
1
+ import {
2
+ pathToRegex
3
+ } from "./chunk-SJVHHGVW.js";
4
+
5
+ // src/site/Router.ts
6
+ var Router = class {
7
+ routes = [];
8
+ constructor() {
9
+ }
10
+ //add(path: string, file: string) {
11
+ // // TODO: Call the specific addX method based on the file path
12
+ // this.addPage(route, file);
13
+ //}
14
+ addPages(routes) {
15
+ for (let r of routes) {
16
+ this.routes.push(
17
+ new Route(r.path, {
18
+ path: r.path,
19
+ type: r.type,
20
+ endPoint: r.endPoint
21
+ })
22
+ );
23
+ }
24
+ this.#sortRoutes();
25
+ return this;
26
+ }
27
+ // TODO: Allow calling with the endpoint itself, so that you can setup an app with no scaffold
28
+ addPage(path, type, endPoint) {
29
+ this.routes.push(
30
+ new Route(path, {
31
+ path,
32
+ type,
33
+ endPoint
34
+ })
35
+ );
36
+ this.#sortRoutes();
37
+ return this;
38
+ }
39
+ /*
40
+ loadPage(ev: ServerEvent, file: string): Response {
41
+ let page = this.pages.get(file);
42
+ if (!page) {
43
+ page = {};
44
+ this.pages.set(file, page);
45
+ }
46
+ }
47
+ */
48
+ match(path, query) {
49
+ for (let route of this.routes) {
50
+ let match = path.match(route.regex);
51
+ if (match) {
52
+ if (!route.handler.loaded) {
53
+ this.#loadHandler(route.handler, route.path);
54
+ }
55
+ return {
56
+ handler: route.handler,
57
+ params: match.groups,
58
+ query
59
+ };
60
+ }
61
+ }
62
+ console.log(`not found: '${path}'`);
63
+ }
64
+ #loadHandler(handler, path) {
65
+ handler.layouts = this.#findLayouts(path);
66
+ handler.serverEndPoint = this.#findServer(path);
67
+ handler.serverHook = this.#findServerHook(path);
68
+ }
69
+ #findLayouts(path) {
70
+ let layouts = [];
71
+ let parts = path.replace(/\/~server$/, "").split("/");
72
+ let basePath = "";
73
+ for (let i = 0; i < parts.length; i++) {
74
+ if (i > 0) {
75
+ basePath += "/" + parts[i];
76
+ }
77
+ const layoutPath = basePath + "/_layout";
78
+ const layoutRoute = this.routes.find((r) => r.path === layoutPath);
79
+ if (layoutRoute) {
80
+ layouts.push({
81
+ path: layoutPath,
82
+ endPoint: layoutRoute.handler.endPoint,
83
+ serverEndPoint: this.#findServer(layoutPath)
84
+ });
85
+ }
86
+ }
87
+ return layouts.length ? layouts : void 0;
88
+ }
89
+ #findServer(path) {
90
+ const serverPath = path.replace(/\/$/, "") + "/~server";
91
+ const serverRoute = this.routes.find((r) => r.path === serverPath);
92
+ return serverRoute && serverRoute.handler.endPoint;
93
+ }
94
+ #findServerHook(path) {
95
+ let serverHookPath = "/_hook/~server";
96
+ if (path.startsWith("/api/")) {
97
+ serverHookPath = "/api" + serverHookPath;
98
+ }
99
+ const serverHookRoute = this.routes.find((r) => r.path === serverHookPath);
100
+ return serverHookRoute && serverHookRoute.handler.endPoint;
101
+ }
102
+ // HACK: We're doing this here as well as in Site, so that you can use the
103
+ // Router externally without Site
104
+ #sortRoutes() {
105
+ this.routes = this.routes.sort((a, b) => {
106
+ for (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {
107
+ if (a.path[i] === "[" && b.path[i] !== "[") {
108
+ return 1;
109
+ } else if (b.path[i] === "[" && a.path[i] !== "[") {
110
+ return -1;
111
+ } else if (a.path[i] === b.path[i]) {
112
+ } else {
113
+ return a.path[i].localeCompare(b.path[i]);
114
+ }
115
+ }
116
+ return a.path.length - b.path.length;
117
+ });
118
+ }
119
+ };
120
+ var Route = class {
121
+ path;
122
+ regex;
123
+ handler;
124
+ constructor(path, handler) {
125
+ this.path = path;
126
+ this.regex = pathToRegex(path);
127
+ this.handler = handler;
128
+ }
129
+ };
130
+
131
+ // src/types/RouteType.ts
132
+ var PAGE_ROUTE = 0;
133
+ var PAGE_SERVER_ROUTE = 1;
134
+ var SERVER_ROUTE = 3;
135
+ var LAYOUT_ROUTE = 4;
136
+ var LAYOUT_SERVER_ROUTE = 5;
137
+ var HOOK_ROUTE = 6;
138
+ var HOOK_SERVER_ROUTE = 7;
139
+
140
+ export {
141
+ Router,
142
+ PAGE_ROUTE,
143
+ PAGE_SERVER_ROUTE,
144
+ SERVER_ROUTE,
145
+ LAYOUT_ROUTE,
146
+ LAYOUT_SERVER_ROUTE,
147
+ HOOK_ROUTE,
148
+ HOOK_SERVER_ROUTE
149
+ };
150
+ //# sourceMappingURL=chunk-65K3R3CP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/site/Router.ts","../src/types/RouteType.ts"],"sourcesContent":["import type LayoutHandler from \"../types/LayoutHandler\";\nimport type ManifestRoute from \"../types/ManifestRoute\";\nimport type RouteHandler from \"../types/RouteHandler\";\nimport pathToRegex from \"./pathToRegex\";\n\n/**\n * A router that handles file routes with layouts, hooks, etc.\n */\nexport default class Router {\n\troutes: Route[] = [];\n\n\tconstructor() {}\n\n\t//add(path: string, file: string) {\n\t//\t// TODO: Call the specific addX method based on the file path\n\t//\tthis.addPage(route, file);\n\t//}\n\n\taddPages(routes: ManifestRoute[]): this {\n\t\tfor (let r of routes) {\n\t\t\tthis.routes.push(\n\t\t\t\tnew Route(r.path, {\n\t\t\t\t\tpath: r.path,\n\t\t\t\t\ttype: r.type,\n\t\t\t\t\tendPoint: r.endPoint,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\t// TODO: Allow calling with the endpoint itself, so that you can setup an app with no scaffold\n\taddPage(path: string, type: number, endPoint: () => Promise<any>): this {\n\t\tthis.routes.push(\n\t\t\tnew Route(path, {\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t\tendPoint,\n\t\t\t}),\n\t\t);\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\t/*\n\tloadPage(ev: ServerEvent, file: string): Response {\n\t\tlet page = this.pages.get(file);\n\t\tif (!page) {\n\t\t\tpage = {};\n\t\t\tthis.pages.set(file, page);\n\t\t}\n\t}\n\t*/\n\n\tmatch(path: string, query: URLSearchParams): Match | undefined {\n\t\tfor (let route of this.routes) {\n\t\t\tlet match = path.match(route.regex);\n\t\t\tif (match) {\n\t\t\t\t// Lazy load server endpoints and layouts\n\t\t\t\tif (!route.handler.loaded) {\n\t\t\t\t\tthis.#loadHandler(route.handler, route.path);\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\thandler: route.handler,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t\tquery,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconsole.log(`not found: '${path}'`);\n\t}\n\n\t#loadHandler(handler: RouteHandler, path: string) {\n\t\thandler.layouts = this.#findLayouts(path);\n\t\thandler.serverEndPoint = this.#findServer(path);\n\t\thandler.serverHook = this.#findServerHook(path);\n\t}\n\n\t#findLayouts(path: string): LayoutHandler[] | undefined {\n\t\tlet layouts: LayoutHandler[] = [];\n\t\tlet parts = path\n\t\t\t// Strip the trailing`~/server` (so we don't look for `~/server/_layout`\n\t\t\t// which will never exist)\n\t\t\t.replace(/\\/~server$/, \"\")\n\t\t\t// The path will always start with / so splitting e.g. `/first/second`\n\t\t\t// will result in ['', 'first', 'second'] and checks for `/_layout`,\n\t\t\t// `/first/_layout` and `/second/_layout`\n\t\t\t.split(\"/\");\n\t\tlet basePath = \"\";\n\t\tfor (let i = 0; i < parts.length; i++) {\n\t\t\tif (i > 0) {\n\t\t\t\tbasePath += \"/\" + parts[i];\n\t\t\t}\n\t\t\tconst layoutPath = basePath + \"/_layout\";\n\t\t\tconst layoutRoute = this.routes.find((r) => r.path === layoutPath);\n\t\t\tif (layoutRoute) {\n\t\t\t\tlayouts.push({\n\t\t\t\t\tpath: layoutPath,\n\t\t\t\t\tendPoint: layoutRoute.handler.endPoint,\n\t\t\t\t\tserverEndPoint: this.#findServer(layoutPath),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn layouts.length ? layouts : undefined;\n\t}\n\n\t#findServer(path: string): (() => Promise<any>) | undefined {\n\t\tconst serverPath = path.replace(/\\/$/, \"\") + \"/~server\";\n\t\tconst serverRoute = this.routes.find((r) => r.path === serverPath);\n\t\treturn serverRoute && serverRoute.handler.endPoint;\n\t}\n\n\t#findServerHook(path: string): (() => Promise<any>) | undefined {\n\t\t// TODO: Should this be a collection, like layouts?\n\t\tlet serverHookPath = \"/_hook/~server\";\n\t\t// HACK: Generalise this\n\t\tif (path.startsWith(\"/api/\")) {\n\t\t\tserverHookPath = \"/api\" + serverHookPath;\n\t\t}\n\t\tconst serverHookRoute = this.routes.find((r) => r.path === serverHookPath);\n\t\treturn serverHookRoute && serverHookRoute.handler.endPoint;\n\t}\n\n\t// HACK: We're doing this here as well as in Site, so that you can use the\n\t// Router externally without Site\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\nclass Route {\n\tpath: string;\n\tregex: RegExp;\n\thandler: RouteHandler;\n\n\tconstructor(path: string, handler: RouteHandler) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.handler = handler;\n\t}\n}\n\ntype Match = {\n\thandler: RouteHandler;\n\tparams?: Record<string, string>;\n\tquery: URLSearchParams;\n};\n","export const PAGE_ROUTE = 0;\nexport const PAGE_SERVER_ROUTE = 1;\nexport const SERVER_ROUTE = 3;\nexport const LAYOUT_ROUTE = 4;\nexport const LAYOUT_SERVER_ROUTE = 5;\nexport const HOOK_ROUTE = 6;\nexport const HOOK_SERVER_ROUTE = 7;\n"],"mappings":";;;;;AAQA,IAAqB,SAArB,MAA4B;AAAA,EAC3B,SAAkB,CAAC;AAAA,EAEnB,cAAc;AAAA,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf,SAAS,QAA+B;AACvC,aAAS,KAAK,QAAQ;AACrB,WAAK,OAAO;AAAA,QACX,IAAI,MAAM,EAAE,MAAM;AAAA,UACjB,MAAM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AC;AAAA,EACF;AACD;AAEA,IAAM,QAAN,MAAY;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,MAAc,SAAuB;AAChD,SAAK,OAAO;AACZ,SAAK,QAAQ,YAAY,IAAI;AAC7B,SAAK,UAAU;AAAA,EAChB;AACD;;;AC9JO,IAAM,aAAa;AACnB,IAAM,oBAAoB;AAC1B,IAAM,eAAe;AACrB,IAAM,eAAe;AACrB,IAAM,sBAAsB;AAC5B,IAAM,aAAa;AACnB,IAAM,oBAAoB;","names":[]}
@@ -1,19 +1,7 @@
1
- // src/response/response.ts
2
- function response(status, body) {
3
- let headers = void 0;
4
- if (body) {
5
- if (typeof body === "object") {
6
- headers = { "content-type": "application/json" };
7
- body = JSON.stringify(body);
8
- } else {
9
- headers = { "content-type": "text/plain" };
10
- }
11
- }
12
- return new Response(body, {
13
- status,
14
- headers
15
- });
16
- }
1
+ import {
2
+ response,
3
+ transfer
4
+ } from "./chunk-2QQN3D3K.js";
17
5
 
18
6
  // src/response/badRequest.ts
19
7
  function badRequest(body) {
@@ -35,46 +23,21 @@ function methodNotAllowed(body) {
35
23
  return response(405, body);
36
24
  }
37
25
 
38
- // src/response/transfer.ts
39
- function transfer(status, location) {
40
- return new Response(null, {
41
- status,
42
- headers: {
43
- location
44
- }
45
- });
46
- }
47
-
48
26
  // src/response/moved.ts
49
27
  function moved(location) {
50
28
  return transfer(308, location);
51
29
  }
52
30
 
53
- // src/response/notFound.ts
54
- function notFound(body) {
55
- return response(404, body);
56
- }
57
-
58
31
  // src/response/notModified.ts
59
32
  function notModified(location) {
60
33
  return transfer(304, location);
61
34
  }
62
35
 
63
- // src/response/ok.ts
64
- function ok(body) {
65
- return response(200, body);
66
- }
67
-
68
36
  // src/response/redirect.ts
69
37
  function redirect(location) {
70
38
  return transfer(307, location);
71
39
  }
72
40
 
73
- // src/response/seeOther.ts
74
- function seeOther(location) {
75
- return transfer(303, location);
76
- }
77
-
78
41
  // src/response/serverError.ts
79
42
  function serverError(body) {
80
43
  return response(500, body);
@@ -91,20 +54,15 @@ function unprocessable(body) {
91
54
  }
92
55
 
93
56
  export {
94
- response,
95
57
  badRequest,
96
58
  created,
97
59
  forbidden,
98
60
  methodNotAllowed,
99
- transfer,
100
61
  moved,
101
- notFound,
102
62
  notModified,
103
- ok,
104
63
  redirect,
105
- seeOther,
106
64
  serverError,
107
65
  unauthorized,
108
66
  unprocessable
109
67
  };
110
- //# sourceMappingURL=chunk-PTCWU3AW.js.map
68
+ //# sourceMappingURL=chunk-D6LHMH2C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/response/badRequest.ts","../src/response/created.ts","../src/response/forbidden.ts","../src/response/methodNotAllowed.ts","../src/response/moved.ts","../src/response/notModified.ts","../src/response/redirect.ts","../src/response/serverError.ts","../src/response/unauthorized.ts","../src/response/unprocessable.ts"],"sourcesContent":["import response from \"./response\";\n\n/**\n * 400 Bad Request\n *\n * The server cannot or will not process the request due to something that is\n * perceived to be a client error (e.g., malformed request syntax, invalid\n * request message framing, or deceptive request routing).\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400\n */\nexport default function badRequest(body?: object | string): Response {\n\treturn response(400, body);\n}\n","import response from \"./response\";\n\n/**\n * 201 Created\n *\n * The request succeeded, and a new resource was created as a result. This is\n * typically the response sent after POST requests, or some PUT requests.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201\n */\nexport default function created(body?: object | string): Response {\n\treturn response(201, body);\n}\n","import response from \"./response\";\n\n/**\n * 403 Forbidden\n *\n * The client does not have access rights to the content; that is, it is\n * unauthorized, so the server is refusing to give the requested resource.\n * Unlike 401 Unauthorized, the client's identity is known to the server.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403\n */\nexport default function forbidden(body?: object | string): Response {\n\treturn response(403, body);\n}\n","import response from \"./response\";\n\n/**\n * 405 Method Not Allowed\n *\n * The request method is known by the server but is not supported by the target\n * resource. For example, an API may not allow calling DELETE to remove a\n * resource.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405\n */\nexport default function methodNotAllowed(body?: object | string): Response {\n\treturn response(405, body);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 308 Permanent Redirect\n *\n * This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header. This has the same semantics\n * as the 301 Moved Permanently HTTP response code, with the exception that the\n * user agent must not change the HTTP method used: if a POST was used in the\n * first request, a POST must be used in the second request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n */\nexport default function moved(location: string): Response {\n\treturn transfer(308, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 304 Not Modified\n *\n * This is used for caching purposes. It tells the client that the response has\n * not been modified, so the client can continue to use the same cached version\n * of the response.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304\n */\nexport default function notModified(location: string): Response {\n\treturn transfer(304, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 307 Temporary Redirect\n *\n * The server sends this response to direct the client to get the requested\n * resource at another URI with the same method that was used in the prior\n * request. This has the same semantics as the 302 Found HTTP response code,\n * with the exception that the user agent must not change the HTTP method used:\n * if a POST was used in the first request, a POST must be used in the second\n * request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307\n */\nexport default function redirect(location: string): Response {\n\treturn transfer(307, location);\n}\n","import response from \"./response\";\n\n/**\n * 500 Server Error\n *\n * The server has encountered a situation it does not know how to handle.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body);\n}\n","import response from \"./response\";\n\n/**\n * 401 Unauthorized\n *\n * Although the HTTP standard specifies \"unauthorized\", semantically this\n * response means \"unauthenticated\". That is, the client must authenticate\n * itself to get the requested response.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401\n */\nexport default function unauthorized(body?: object | string): Response {\n\treturn response(401, body);\n}\n","import response from \"./response\";\n\n/**\n * 422 Unprocessable Content\n *\n * The request was well-formed but was unable to be followed due to semantic errors.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422\n */\nexport default function unprocessable(body?: object | string): Response {\n\treturn response(422, body);\n}\n"],"mappings":";;;;;;AAWe,SAAR,WAA4B,MAAkC;AACpE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACHe,SAAR,QAAyB,MAAkC;AACjE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACDe,SAAR,UAA2B,MAAkC;AACnE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACFe,SAAR,iBAAkC,MAAkC;AAC1E,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACAe,SAAR,MAAuB,UAA4B;AACzD,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACJe,SAAR,YAA6B,UAA4B;AAC/D,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACCe,SAAR,SAA0B,UAA4B;AAC5D,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACPe,SAAR,YAA6B,MAAkC;AACrE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACAe,SAAR,aAA8B,MAAkC;AACtE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACJe,SAAR,cAA+B,MAAkC;AACvE,SAAO,SAAS,KAAK,IAAI;AAC1B;","names":[]}
@@ -0,0 +1,85 @@
1
+ // src/server/CookieHelper.ts
2
+ import { parse, serialize } from "cookie";
3
+ var CookieHelper = class {
4
+ request;
5
+ cookies = /* @__PURE__ */ new Map();
6
+ constructor(request) {
7
+ this.request = request;
8
+ }
9
+ get(name) {
10
+ if (this.cookies.has(name)) {
11
+ return this.cookies.get(name);
12
+ }
13
+ const header = this.request.headers.get("cookie");
14
+ return parse(header ?? "")[name];
15
+ }
16
+ set(name, value, options) {
17
+ options ??= {};
18
+ options.httpOnly ??= true;
19
+ options.secure ??= true;
20
+ options.sameSite ??= "lax";
21
+ this.cookies.set(name, serialize(name, value, options));
22
+ }
23
+ delete(name, options) {
24
+ options ??= {};
25
+ options.expires = /* @__PURE__ */ new Date(0);
26
+ this.cookies.set(name, serialize(name, "", options));
27
+ }
28
+ };
29
+
30
+ // src/server/HeaderHelper.ts
31
+ var HeaderHelper = class {
32
+ request;
33
+ headers = /* @__PURE__ */ new Map();
34
+ constructor(request) {
35
+ this.request = request;
36
+ }
37
+ get(name) {
38
+ if (this.headers.has(name)) {
39
+ return this.headers.get(name);
40
+ }
41
+ return this.request.headers.get(name) ?? void 0;
42
+ }
43
+ set(name, value) {
44
+ this.headers.set(name, value);
45
+ }
46
+ delete(name) {
47
+ this.headers.delete(name);
48
+ }
49
+ };
50
+
51
+ // src/server/ServerEvent.ts
52
+ var ServerEvent = class {
53
+ request;
54
+ response;
55
+ // TODO: Should we cast types??
56
+ params;
57
+ adapter;
58
+ cookies;
59
+ headers;
60
+ constructor(request, params) {
61
+ this.request = request;
62
+ this.params = params;
63
+ this.cookies = new CookieHelper(request);
64
+ this.headers = new HeaderHelper(request);
65
+ this.adapter = globalThis.adapter;
66
+ }
67
+ addHeaders() {
68
+ if (!this.response) {
69
+ throw new Error("Response not created yet");
70
+ }
71
+ for (let cookie of this.cookies.cookies.values()) {
72
+ this.response.headers.append("set-cookie", cookie);
73
+ }
74
+ for (let header of this.headers.headers.entries()) {
75
+ this.response.headers.append(header[0], header[1]);
76
+ }
77
+ }
78
+ };
79
+
80
+ export {
81
+ CookieHelper,
82
+ HeaderHelper,
83
+ ServerEvent
84
+ };
85
+ //# sourceMappingURL=chunk-EVBUHZGK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts"],"sourcesContent":["import { SerializeOptions, parse, serialize } from \"cookie\";\n\nexport default class CookieHelper {\n\trequest: Request;\n\tcookies: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.cookies.has(name)) {\n\t\t\treturn this.cookies.get(name);\n\t\t}\n\t\t// Otherwise, return the cookie value from the `Cookie` header\n\t\tconst header = this.request.headers.get(\"cookie\");\n\t\treturn parse(header ?? \"\")[name];\n\t}\n\n\tset(name: string, value: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with some default values for security\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\tthis.cookies.set(name, serialize(name, value, options));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with an immediate expiry date\n\t\toptions ??= {};\n\t\toptions.expires = new Date(0);\n\t\tthis.cookies.set(name, serialize(name, \"\", options));\n\t}\n}\n","export default class HeaderHelper {\n\trequest: Request;\n\theaders: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.headers.has(name)) {\n\t\t\treturn this.headers.get(name);\n\t\t}\n\t\t// Otherwise, return the value from the header\n\t\treturn this.request.headers.get(name) ?? undefined;\n\t}\n\n\tset(name: string, value: string): void {\n\t\tthis.headers.set(name, value);\n\t}\n\n\tdelete(name: string): void {\n\t\tthis.headers.delete(name);\n\t}\n}\n","import CookieHelper from \"./CookieHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\n\nexport default class ServerEvent {\n\trequest: Request;\n\tresponse?: Response;\n\t// TODO: Should we cast types??\n\tparams?: Record<string, string>;\n\n\tadapter: any;\n\n\tcookies: CookieHelper;\n\theaders: HeaderHelper;\n\n\tconstructor(request: Request, params?: Record<string, string>) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.cookies = new CookieHelper(request);\n\t\tthis.headers = new HeaderHelper(request);\n\n\t\t// Adapters may have added the `adapter` property to globalThis\n\t\t// @ts-ignore\n\t\tthis.adapter = globalThis.adapter;\n\t}\n\n\taddHeaders(): void {\n\t\tif (!this.response) {\n\t\t\tthrow new Error(\"Response not created yet\");\n\t\t}\n\n\t\tfor (let cookie of this.cookies.cookies.values()) {\n\t\t\tthis.response.headers.append(\"set-cookie\", cookie);\n\t\t}\n\n\t\tfor (let header of this.headers.headers.entries()) {\n\t\t\tthis.response.headers.append(header[0], header[1]);\n\t\t}\n\t}\n}\n"],"mappings":";AAAA,SAA2B,OAAO,iBAAiB;AAEnD,IAAqB,eAArB,MAAkC;AAAA,EACjC;AAAA,EACA,UAA+B,oBAAI,IAAI;AAAA,EAEvC,YAAY,SAAkB;AAC7B,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,IAAI,MAAkC;AAErC,QAAI,KAAK,QAAQ,IAAI,IAAI,GAAG;AAC3B,aAAO,KAAK,QAAQ,IAAI,IAAI;AAAA,IAC7B;AAEA,UAAM,SAAS,KAAK,QAAQ,QAAQ,IAAI,QAAQ;AAChD,WAAO,MAAM,UAAU,EAAE,EAAE,IAAI;AAAA,EAChC;AAAA,EAEA,IAAI,MAAc,OAAe,SAAkC;AAElE,gBAAY,CAAC;AACb,YAAQ,aAAa;AACrB,YAAQ,WAAW;AACnB,YAAQ,aAAa;AACrB,SAAK,QAAQ,IAAI,MAAM,UAAU,MAAM,OAAO,OAAO,CAAC;AAAA,EACvD;AAAA,EAEA,OAAO,MAAc,SAAkC;AAEtD,gBAAY,CAAC;AACb,YAAQ,UAAU,oBAAI,KAAK,CAAC;AAC5B,SAAK,QAAQ,IAAI,MAAM,UAAU,MAAM,IAAI,OAAO,CAAC;AAAA,EACpD;AACD;;;ACnCA,IAAqB,eAArB,MAAkC;AAAA,EACjC;AAAA,EACA,UAA+B,oBAAI,IAAI;AAAA,EAEvC,YAAY,SAAkB;AAC7B,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,IAAI,MAAkC;AAErC,QAAI,KAAK,QAAQ,IAAI,IAAI,GAAG;AAC3B,aAAO,KAAK,QAAQ,IAAI,IAAI;AAAA,IAC7B;AAEA,WAAO,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK;AAAA,EAC1C;AAAA,EAEA,IAAI,MAAc,OAAqB;AACtC,SAAK,QAAQ,IAAI,MAAM,KAAK;AAAA,EAC7B;AAAA,EAEA,OAAO,MAAoB;AAC1B,SAAK,QAAQ,OAAO,IAAI;AAAA,EACzB;AACD;;;ACrBA,IAAqB,cAArB,MAAiC;AAAA,EAChC;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA,YAAY,SAAkB,QAAiC;AAC9D,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,UAAU,IAAI,aAAa,OAAO;AACvC,SAAK,UAAU,IAAI,aAAa,OAAO;AAIvC,SAAK,UAAU,WAAW;AAAA,EAC3B;AAAA,EAEA,aAAmB;AAClB,QAAI,CAAC,KAAK,UAAU;AACnB,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC3C;AAEA,aAAS,UAAU,KAAK,QAAQ,QAAQ,OAAO,GAAG;AACjD,WAAK,SAAS,QAAQ,OAAO,cAAc,MAAM;AAAA,IAClD;AAEA,aAAS,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAAG;AAClD,WAAK,SAAS,QAAQ,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AAAA,IAClD;AAAA,EACD;AACD;","names":[]}
@@ -1,86 +1,10 @@
1
+ import {
2
+ ServerEvent
3
+ } from "./chunk-EVBUHZGK.js";
1
4
  import {
2
5
  pathToRegex
3
6
  } from "./chunk-SJVHHGVW.js";
4
7
 
5
- // src/server/CookieHelper.ts
6
- import { parse, serialize } from "cookie";
7
- var CookieHelper = class {
8
- request;
9
- cookies = /* @__PURE__ */ new Map();
10
- constructor(request) {
11
- this.request = request;
12
- }
13
- get(name) {
14
- if (this.cookies.has(name)) {
15
- return this.cookies.get(name);
16
- }
17
- const header = this.request.headers.get("cookie");
18
- return parse(header ?? "")[name];
19
- }
20
- set(name, value, options) {
21
- options ??= {};
22
- options.httpOnly ??= true;
23
- options.secure ??= true;
24
- options.sameSite ??= "lax";
25
- this.cookies.set(name, serialize(name, value, options));
26
- }
27
- delete(name, options) {
28
- options ??= {};
29
- options.expires = /* @__PURE__ */ new Date(0);
30
- this.cookies.set(name, serialize(name, "", options));
31
- }
32
- };
33
-
34
- // src/server/HeaderHelper.ts
35
- var HeaderHelper = class {
36
- request;
37
- headers = /* @__PURE__ */ new Map();
38
- constructor(request) {
39
- this.request = request;
40
- }
41
- get(name) {
42
- if (this.headers.has(name)) {
43
- return this.headers.get(name);
44
- }
45
- return this.request.headers.get(name) ?? void 0;
46
- }
47
- set(name, value) {
48
- this.headers.set(name, value);
49
- }
50
- delete(name) {
51
- this.headers.delete(name);
52
- }
53
- };
54
-
55
- // src/server/ServerEvent.ts
56
- var ServerEvent = class {
57
- request;
58
- response;
59
- // TODO: Should we cast types??
60
- params;
61
- adapter;
62
- cookies;
63
- headers;
64
- constructor(request, params) {
65
- this.request = request;
66
- this.params = params;
67
- this.cookies = new CookieHelper(request);
68
- this.headers = new HeaderHelper(request);
69
- this.adapter = globalThis.adapter;
70
- }
71
- addHeaders() {
72
- if (!this.response) {
73
- throw new Error("Response not created yet");
74
- }
75
- for (let cookie of this.cookies.cookies.values()) {
76
- this.response.headers.append("set-cookie", cookie);
77
- }
78
- for (let header of this.headers.headers.entries()) {
79
- this.response.headers.append(header[0], header[1]);
80
- }
81
- }
82
- };
83
-
84
8
  // src/server/Server.ts
85
9
  var noop = () => {
86
10
  };
@@ -348,10 +272,7 @@ var statusCodesWithoutBody = [
348
272
  ];
349
273
 
350
274
  export {
351
- CookieHelper,
352
- HeaderHelper,
353
- ServerEvent,
354
275
  Server,
355
276
  connectMiddleware
356
277
  };
357
- //# sourceMappingURL=chunk-27LTVTCS.js.map
278
+ //# sourceMappingURL=chunk-FMRCLIWE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/Server.ts","../src/server/connect/flattenHeaders.ts","../src/server/connect/nodeMessageToNodeResponse.ts","../src/server/connect/readableToBuffer.ts","../src/server/connect/requestToNodeMessage.ts","../src/server/connect/connectMiddleware.ts"],"sourcesContent":["import pathToRegex from \"../site/pathToRegex\";\nimport ServerEvent from \"./ServerEvent\";\nimport type MiddlewareFunction from \"./types/MiddlewareFunction\";\nimport type ServerFunction from \"./types/ServerFunction\";\n\nconst noop = () => {};\n\n/**\n * A Fetch API Request/Response server.\n */\nexport default class Server {\n\t// TODO: We don't use any of the routes, just add(\"*\") in runDev/runBuild...\n\troutes: RouteHandler[] = [];\n\t// TODO: We only use the Vite middleware here\n\tmiddleware: MiddlewareFunction[] = [];\n\n\tconstructor() {\n\t\tthis.routes = [];\n\t\tthis.middleware = [];\n\t}\n\n\t/**\n\t * The standard Fetch API method that should work in any runtime (including\n\t * Node with polyfills).\n\t * @returns\n\t */\n\tfetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n\t\tconst request = new Request(input, init);\n\t\tconst url = new URL(request.url);\n\t\tconst match = this.match(url.pathname);\n\t\tlet ev = new ServerEvent(request, match?.params);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tawait this.middleware[0](ev, buildNext(this.middleware, 0));\n\t\t\tfunction buildNext(middleware: MiddlewareFunction[], i: number): () => void | Promise<void> {\n\t\t\t\tif (ev.response) {\n\t\t\t\t\treturn noop;\n\t\t\t\t}\n\n\t\t\t\tif (i < middleware.length - 1) {\n\t\t\t\t\tlet next = middleware[i + 1];\n\t\t\t\t\treturn async () => next(ev, buildNext(middleware, i + 1));\n\t\t\t\t} else {\n\t\t\t\t\treturn match\n\t\t\t\t\t\t? async () => {\n\t\t\t\t\t\t\t\tev.response = await match.fn(ev);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: noop;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (match) {\n\t\t\tev.response = await match.fn(ev);\n\t\t} else {\n\t\t\treturn new Response(null, { status: 404 });\n\t\t}\n\n\t\t// TODO: Should I be returning 200 if there's no response? Because it's not an error??\n\t\tev.response ??= new Response(null, { status: 200 });\n\t\tev.addHeaders();\n\n\t\treturn ev.response;\n\t};\n\n\t/**\n\t * Adds a server function at a route path.\n\t * @param path The route path pattern.\n\t * @param fn The function to call when the pattern is matched.\n\t * @returns\n\t */\n\tadd(path: string, fn: ServerFunction): Server {\n\t\tthis.routes.push(new RouteHandler(path, fn));\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\tmatch(path: string): Match | undefined {\n\t\tfor (let handler of this.routes) {\n\t\t\tlet match = path.match(handler.regex);\n\t\t\tif (match) {\n\t\t\t\treturn {\n\t\t\t\t\tfn: handler.fn,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tconsole.log(`Server path not found: ${path}`);\n\t}\n\n\t// TODO:\n\t//use(path: string, ...fn: MiddlewareFunction[])\n\tuse(...fn: MiddlewareFunction[]): Server {\n\t\tthis.middleware = this.middleware.concat(fn);\n\t\treturn this;\n\t}\n\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\nclass RouteHandler {\n\tpath: string;\n\tregex: RegExp;\n\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.fn = fn;\n\t}\n}\n\n//class MiddlewareHandler {\n//\tpath: string;\n//\tregex: RegExp;\n//\tfn: MiddlewareFunction;\n//\n//\tconstructor(path: string, fn: MiddlewareFunction) {\n//\t\tthis.path = path;\n//\t\tthis.regex = pathToRegex(path);\n//\t\tthis.fn = fn;\n//\t}\n//}\n\ntype Match = {\n\tfn: ServerFunction;\n\tparams?: Record<string, string>;\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 {\n\ttype IncomingMessage,\n\ttype OutgoingHttpHeader,\n\ttype OutgoingHttpHeaders,\n\tServerResponse,\n} from \"node:http\";\nimport { PassThrough, Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/createServerResponse.ts\n\n/**\n * Creates a custom ServerResponse object that allows for intercepting and\n * streaming the response.\n *\n * @param incomingMessage The incoming HTTP request message.\n * @returns An object containing the custom ServerResponse and a function that\n * takes a callback to invoke when the response is readable, providing an object\n * with the readable stream, headers and status code.\n */\nexport default function nodeMessageToNodeResponse(\n\tincomingMessage: IncomingMessage,\n): ServerResponseResponse {\n\tconst res = new ServerResponse(incomingMessage);\n\tconst passThrough = new PassThrough();\n\tlet handled = false;\n\n\tconst onReadable = (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => {\n\t\tconst handleReadable = () => {\n\t\t\tif (handled) return;\n\t\t\thandled = true;\n\t\t\tcb({\n\t\t\t\treadable: Readable.from(passThrough),\n\t\t\t\theaders: res.getHeaders(),\n\t\t\t\tstatus: res.statusCode,\n\t\t\t});\n\t\t};\n\n\t\tpassThrough.once(\"readable\", handleReadable);\n\t\tpassThrough.once(\"end\", handleReadable);\n\t};\n\n\tpassThrough.once(\"finish\", () => {\n\t\tres.emit(\"finish\");\n\t});\n\tpassThrough.once(\"close\", () => {\n\t\tres.destroy();\n\t\tres.emit(\"close\");\n\t});\n\tpassThrough.on(\"drain\", () => {\n\t\tres.emit(\"drain\");\n\t});\n\n\tres.write = passThrough.write.bind(passThrough);\n\tres.end = passThrough.end.bind(passThrough) as any;\n\n\tres.writeHead = function writeHead(\n\t\tstatusCode: number,\n\t\tstatusMessage?: string | OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t\theaders?: OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t): ServerResponse {\n\t\tres.statusCode = statusCode;\n\t\tif (typeof statusMessage === \"object\") {\n\t\t\theaders = statusMessage;\n\t\t\tstatusMessage = undefined;\n\t\t}\n\t\tif (headers) {\n\t\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\tres.setHeader(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t};\n\n\treturn {\n\t\tres,\n\t\tonReadable,\n\t};\n}\n\ntype ServerResponseResponse = {\n\tres: ServerResponse;\n\tonReadable: (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => void;\n};\n","import { Readable } from \"node:stream\";\n\nexport default function readableToBuffer(req: Readable): Promise<Buffer> {\n\treturn new Promise<Buffer>((resolve, reject) => {\n\t\tconst chunks: Buffer[] = [];\n\t\treq.on(\"data\", (chunk: Buffer) => {\n\t\t\tchunks.push(chunk);\n\t\t});\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(Buffer.concat(chunks));\n\t\t});\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n","import { type IncomingMessage } from \"node:http\";\nimport { Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\nconst DUMMY_BASE_URL = \"http://localhost\";\n\n/**\n * Creates an IncomingMessage object from a web Request.\n *\n * @param {Request} request - The web Request object.\n * @returns {IncomingMessage} An IncomingMessage-like object compatible with Node.js HTTP module.\n */\nexport default function requestToNodeMessage(request: Request): IncomingMessage {\n\tconst parsedUrl = new URL(request.url, DUMMY_BASE_URL);\n\tconst pathAndQuery = (parsedUrl.pathname || \"\") + (parsedUrl.search || \"\");\n\t// HACK: Using Readable.fromWeb locks request.body so that the request cannot be used again\n\t// As we're only using this for Vite middlewares, it's safe to discard the body for now?\n\tconst body = /*request.body ? Readable.fromWeb(request.body as any) :*/ Readable.from([]);\n\n\treturn Object.assign(body, {\n\t\turl: pathAndQuery,\n\t\tmethod: request.method,\n\t\theaders: Object.fromEntries(request.headers),\n\t}) as IncomingMessage;\n}\n","import { IncomingMessage, ServerResponse } from \"node:http\";\nimport type MiddlewareFunction from \"../types/MiddlewareFunction\";\nimport flattenHeaders from \"./flattenHeaders\";\nimport nodeMessageToNodeResponse from \"./nodeMessageToNodeResponse\";\nimport readableToBuffer from \"./readableToBuffer\";\nimport requestToNodeMessage from \"./requestToNodeMessage\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\n/**\n * Converts a Connect-style middleware to a web-compatible request handler.\n *\n * @param handler - The Connect-style middleware function to be converted.\n * @returns A function that handles web requests and returns a Response or undefined.\n */\nexport default function connectMiddleware(\n\thandler: ConnectMiddleware | ConnectMiddlewareBoolean,\n): MiddlewareFunction {\n\treturn async (ev, next) => {\n\t\tconst req = requestToNodeMessage(ev.request);\n\t\tconst { res, onReadable } = nodeMessageToNodeResponse(req);\n\n\t\treturn new Promise<void>(async (resolve, reject) => {\n\t\t\tonReadable(async ({ readable, headers, status }) => {\n\t\t\t\tconst responseBody = statusCodesWithoutBody.includes(status)\n\t\t\t\t\t? null\n\t\t\t\t\t: //(Readable.toWeb(readable) as ReadableStream);\n\t\t\t\t\t\t// HACK: Chunked bodies are not being\n\t\t\t\t\t\t// read correctly somewhere...\n\t\t\t\t\t\tawait readableToBuffer(readable);\n\t\t\t\tev.response = new Response(responseBody, {\n\t\t\t\t\tstatus,\n\t\t\t\t\theaders: flattenHeaders(headers),\n\t\t\t\t});\n\t\t\t\tresolve();\n\t\t\t});\n\n\t\t\tconst cnext = async (error?: unknown) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t} else {\n\t\t\t\t\t// TODO: Can we nest the next functions less? This is a bit weird\n\t\t\t\t\tawait next();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst handled = await handler(req, res, cnext);\n\t\t\t\tif (handled === false) {\n\t\t\t\t\tres.destroy();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tcnext(e);\n\t\t\t}\n\t\t});\n\t};\n}\n\nconst statusCodesWithoutBody = [\n\t100, // Continue\n\t101, // Switching Protocols\n\t102, // Processing (WebDAV)\n\t103, // Early Hints\n\t204, // No Content\n\t205, // Reset Content\n\t304, // Not Modified\n];\n\ntype NextFunction = (err?: unknown) => void;\ntype ConnectMiddleware<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => void | Promise<void>;\ntype ConnectMiddlewareBoolean<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => boolean | Promise<boolean>;\n"],"mappings":";;;;;;;;AAKA,IAAM,OAAO,MAAM;AAAC;AAKpB,IAAqB,SAArB,MAA4B;AAAA;AAAA,EAE3B,SAAyB,CAAC;AAAA;AAAA,EAE1B,aAAmC,CAAC;AAAA,EAEpC,cAAc;AACb,SAAK,SAAS,CAAC;AACf,SAAK,aAAa,CAAC;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAQ,OAAO,OAA0B,SAA0C;AAClF,UAAM,UAAU,IAAI,QAAQ,OAAO,IAAI;AACvC,UAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,UAAM,QAAQ,KAAK,MAAM,IAAI,QAAQ;AACrC,QAAI,KAAK,IAAI,YAAY,SAAS,OAAO,MAAM;AAE/C,QAAI,KAAK,WAAW,QAAQ;AAG3B,UAASA,aAAT,SAAmB,YAAkC,GAAuC;AAC3F,YAAI,GAAG,UAAU;AAChB,iBAAO;AAAA,QACR;AAEA,YAAI,IAAI,WAAW,SAAS,GAAG;AAC9B,cAAI,OAAO,WAAW,IAAI,CAAC;AAC3B,iBAAO,YAAY,KAAK,IAAIA,WAAU,YAAY,IAAI,CAAC,CAAC;AAAA,QACzD,OAAO;AACN,iBAAO,QACJ,YAAY;AACZ,eAAG,WAAW,MAAM,MAAM,GAAG,EAAE;AAAA,UAChC,IACC;AAAA,QACJ;AAAA,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AAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACD;","names":["buildNext","v","Readable"]}
@@ -0,0 +1,15 @@
1
+ // src/state/$page.ts
2
+ import { $watch } from "@torpor/view";
3
+ var $page = $watch(
4
+ {
5
+ status: 404,
6
+ url: new URL("http://localhost")
7
+ },
8
+ { shallow: true }
9
+ );
10
+ var page_default = $page;
11
+
12
+ export {
13
+ page_default
14
+ };
15
+ //# sourceMappingURL=chunk-WMHM5RGZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\n\ntype Page = {\n\tstatus: number;\n\turl: URL;\n};\n\nconst $page: Page = $watch(\n\t{\n\t\tstatus: 404,\n\t\turl: new URL(\"http://localhost\"),\n\t},\n\t{ shallow: true },\n);\n\nexport default $page;\n"],"mappings":";AAAA,SAAS,cAAc;AAOvB,IAAM,QAAc;AAAA,EACnB;AAAA,IACC,QAAQ;AAAA,IACR,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAChC;AAAA,EACA,EAAE,SAAS,KAAK;AACjB;AAEA,IAAO,eAAQ;","names":[]}
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  serverError
3
- } from "./chunk-PTCWU3AW.js";
3
+ } from "./chunk-D6LHMH2C.js";
4
4
  import {
5
5
  Server,
6
6
  connectMiddleware
7
- } from "./chunk-27LTVTCS.js";
7
+ } from "./chunk-FMRCLIWE.js";
8
8
 
9
9
  // src/site/runBuild.ts
10
10
  import torpor from "@torpor/unplugin/vite";
@@ -355,4 +355,4 @@ export {
355
355
  runPreview,
356
356
  run
357
357
  };
358
- //# sourceMappingURL=chunk-GWXPZFMX.js.map
358
+ //# sourceMappingURL=chunk-XLNPB3GH.js.map