@torpor/build 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/Server-CB99REgs.d.cts +74 -0
  4. package/dist/Server-CB99REgs.d.ts +74 -0
  5. package/dist/Site-CgoeDt8k.d.cts +29 -0
  6. package/dist/Site-D95nwrAg.d.ts +29 -0
  7. package/dist/adapters/cloudflare/index.cjs +125 -0
  8. package/dist/adapters/cloudflare/index.cjs.map +1 -0
  9. package/dist/adapters/cloudflare/index.d.cts +13 -0
  10. package/dist/adapters/cloudflare/index.d.ts +13 -0
  11. package/dist/adapters/cloudflare/index.js +80 -0
  12. package/dist/adapters/cloudflare/index.js.map +1 -0
  13. package/dist/adapters/node/index.cjs +152 -0
  14. package/dist/adapters/node/index.cjs.map +1 -0
  15. package/dist/adapters/node/index.d.cts +8 -0
  16. package/dist/adapters/node/index.d.ts +8 -0
  17. package/dist/adapters/node/index.js +8 -0
  18. package/dist/adapters/node/index.js.map +1 -0
  19. package/dist/bin/index.cjs +541 -93
  20. package/dist/bin/index.cjs.map +1 -1
  21. package/dist/bin/index.js +511 -22
  22. package/dist/bin/index.js.map +1 -1
  23. package/dist/chunk-5X4T3PZN.js +23 -0
  24. package/dist/chunk-5X4T3PZN.js.map +1 -0
  25. package/dist/chunk-ALHFYD7U.js +113 -0
  26. package/dist/chunk-ALHFYD7U.js.map +1 -0
  27. package/dist/chunk-V4XTDQEV.js +19 -0
  28. package/dist/chunk-V4XTDQEV.js.map +1 -0
  29. package/dist/chunk-VAGHGWM5.js +110 -0
  30. package/dist/chunk-VAGHGWM5.js.map +1 -0
  31. package/dist/index.cjs +200 -97
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +20 -28
  34. package/dist/index.d.ts +20 -28
  35. package/dist/index.js +85 -17
  36. package/dist/index.js.map +1 -1
  37. package/dist/metafile-cjs.json +1 -1
  38. package/dist/metafile-esm.json +1 -1
  39. package/dist/response.js +17 -91
  40. package/dist/response.js.map +1 -1
  41. package/package.json +24 -7
  42. package/src/adapters/cloudflare/_worker.ts +38 -0
  43. package/src/adapters/cloudflare/index.ts +98 -0
  44. package/src/adapters/node/constants.ts +1 -0
  45. package/src/adapters/node/createFetchHandler.ts +29 -0
  46. package/src/adapters/node/createMiddlewareHandler.ts +79 -0
  47. package/src/adapters/node/createNodeServer.ts +8 -0
  48. package/src/adapters/node/flattenHeaders.ts +44 -0
  49. package/src/adapters/node/index.ts +18 -0
  50. package/src/adapters/node/nodeMessageToNodeResponse.ts +89 -0
  51. package/src/adapters/node/nodeMessageToRequest.ts +43 -0
  52. package/src/adapters/node/readableToBuffer.ts +16 -0
  53. package/src/adapters/node/requestToNodeMessage.ts +26 -0
  54. package/src/adapters/node/responseToNodeResponse.ts +44 -0
  55. package/src/bin/index.ts +43 -36
  56. package/src/index.ts +6 -14
  57. package/src/server/CookieHelper.ts +36 -0
  58. package/src/server/HeaderHelper.ts +25 -0
  59. package/src/server/Server.ts +119 -0
  60. package/src/server/ServerEvent.ts +33 -0
  61. package/src/server/ServerFunction.ts +5 -0
  62. package/src/server/contentType.ts +85 -0
  63. package/src/site/Router.ts +136 -0
  64. package/src/site/Routerx.ts +67 -0
  65. package/src/site/Site.ts +114 -0
  66. package/src/site/clientEntry.ts +22 -20
  67. package/src/site/manifest.ts +49 -0
  68. package/src/site/pathToRegex.ts +10 -0
  69. package/src/site/prepareTemplate.ts +20 -0
  70. package/src/site/runBuild.ts +92 -0
  71. package/src/site/runDev.ts +84 -0
  72. package/src/site/runPreview.ts +83 -0
  73. package/src/site/serverEntry.ts +113 -200
  74. package/src/types/Adapter.ts +10 -0
  75. package/src/types/HttpMethod.ts +12 -0
  76. package/src/types/LayoutHandler.ts +7 -0
  77. package/src/types/ManifestRoute.ts +8 -0
  78. package/src/types/MiddlewareFunction.ts +8 -0
  79. package/src/types/PageEndPoint.ts +4 -3
  80. package/src/types/{PageEvent.ts → PageLoadEvent.ts} +3 -2
  81. package/src/types/PageServerAction.ts +5 -2
  82. package/src/types/PageServerEndPoint.ts +1 -0
  83. package/src/types/PageServerLoad.ts +5 -2
  84. package/src/types/RouteHandler.ts +6 -5
  85. package/src/types/RouteHandlerCollection.ts +1 -0
  86. package/src/types/RouteLayoutHandler.ts +3 -2
  87. package/src/types/RouteMatchResult.ts +3 -2
  88. package/src/types/RouteType.ts +7 -0
  89. package/src/types/ServerEndPoint.ts +1 -0
  90. package/src/types/ServerHook.ts +3 -2
  91. package/src/types/{ServerEvent.ts → ServerLoadEvent.ts} +13 -6
  92. package/src/types/ServerRequest.ts +5 -2
  93. package/src/types/manifest.d.ts +7 -0
  94. package/test/app.test.ts +47 -0
  95. package/tsconfig.json +1 -1
  96. package/tsup.config.ts +11 -1
  97. package/vitest.config.ts +3 -0
  98. package/dist/chunk-IE5EKBNX.js +0 -93
  99. package/dist/chunk-IE5EKBNX.js.map +0 -1
  100. package/src/site/FileSystemRouter.ts +0 -25
  101. package/src/site/buildRoutePath.ts +0 -25
  102. package/src/site/defineConfig.ts +0 -75
  103. package/src/site/lazyRoute.ts +0 -72
  104. package/src/site/routeHandlers.ts +0 -126
  105. package/src/types/CookieHelper.ts +0 -8
  106. package/src/types/UserConfig.ts +0 -4
package/dist/index.cjs CHANGED
@@ -30,120 +30,223 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- buildRoutePath: () => buildRoutePath,
34
- defineConfig: () => defineConfig
33
+ Site: () => Site
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
37
36
 
38
- // src/site/buildRoutePath.ts
39
- function buildRoutePath(path2, routeParams, urlParams) {
40
- for (let [key, value] of Object.entries(routeParams)) {
41
- path2 = path2.replace(`[${key}]`, value);
42
- }
43
- if (urlParams) {
44
- let params = Object.entries(urlParams).map(([key, value]) => {
45
- if (value != null) {
46
- return `${key}=${value}`;
37
+ // src/site/Site.ts
38
+ var import_node_fs = require("fs");
39
+ var import_node_path = __toESM(require("path"), 1);
40
+ var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
41
+
42
+ // src/adapters/node/createNodeServer.ts
43
+ var import_node_http = require("http");
44
+
45
+ // src/adapters/node/constants.ts
46
+ var INTERNAL_BODY = Symbol("internal_body");
47
+
48
+ // src/adapters/node/nodeMessageToRequest.ts
49
+ var import_node_stream = require("stream");
50
+
51
+ // src/adapters/node/flattenHeaders.ts
52
+ function flattenHeaders(headers) {
53
+ const flatHeaders = new Headers();
54
+ for (const [key, value] of Object.entries(headers)) {
55
+ if (value === void 0 || value === null) {
56
+ continue;
57
+ } else if (Array.isArray(value)) {
58
+ for (const v of value) {
59
+ if (v !== void 0 && v !== null) {
60
+ value.forEach((v2) => flatHeaders.append(key, v2));
61
+ }
47
62
  }
48
- }).filter(Boolean);
49
- if (params.length) {
50
- path2 += `?${params.join("&")}`;
63
+ } else {
64
+ flatHeaders.set(key, String(value));
51
65
  }
52
66
  }
53
- return path2;
67
+ return flatHeaders;
54
68
  }
55
69
 
56
- // src/site/defineConfig.ts
57
- var import_vite = __toESM(require("@torpor/unplugin/vite"), 1);
58
- var import_node_path = __toESM(require("path"), 1);
59
- var import_vinxi = require("vinxi");
60
- var import_config = require("vinxi/plugins/config");
61
-
62
- // src/site/FileSystemRouter.ts
63
- var import_fs_router = require("vinxi/fs-router");
64
- var FileSystemRouter = class extends import_fs_router.BaseFileSystemRouter {
65
- toPath(src) {
66
- let routePath = (0, import_fs_router.cleanPath)(src, this.config).replace(/^\//, "").replace(/_hook.server$/, "_hook/~server").replace(/_layout.server$/, "_layout/~server").replace(/\+page.server$/, "~server").replace(/\+page$/, "").replace(/\+server$/, "").replace(/\/$/, "");
67
- return routePath?.length > 0 ? `/${routePath}` : "/";
70
+ // src/adapters/node/nodeMessageToRequest.ts
71
+ async function nodeMessageToRequest(req) {
72
+ let path2 = req.url;
73
+ if (path2 === void 0) {
74
+ throw new Error(`Empty request URL`);
68
75
  }
69
- toRoute(filePath) {
70
- return {
71
- path: this.toPath(filePath),
72
- $handler: {
73
- src: filePath,
74
- pick: ["default"]
75
- }
76
- };
76
+ if (!path2.startsWith("/")) {
77
+ path2 = "/" + path2;
77
78
  }
78
- };
79
+ const { host } = req.headers;
80
+ if (host == void 0) {
81
+ throw new Error(`Missing "Host" header`);
82
+ }
83
+ const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https" : "http";
84
+ const url = `${protocol}://${host}${path2}`;
85
+ const headers = flattenHeaders(req.headers);
86
+ const body = req.method !== "GET" && req.method !== "HEAD" ? import_node_stream.Readable.toWeb(req) : null;
87
+ return new Request(url, {
88
+ method: req.method,
89
+ headers,
90
+ body,
91
+ // @ts-ignore this is needed for using a Readable for some reason
92
+ duplex: "half"
93
+ });
94
+ }
79
95
 
80
- // src/site/defineConfig.ts
81
- function defineConfig(options) {
82
- process.env.PORT = (options?.port || 7059).toString();
83
- return (0, import_vinxi.createApp)({
84
- name: "torpor",
85
- routers: [
86
- {
87
- name: "assets",
88
- type: "static",
89
- dir: "./src/assets"
90
- },
91
- // Doesn't look like we can have two server routes?
92
- // Have to put api in /routes
93
- // Maybe we can support having /routes/api and routes/site and stripping /site from the start?
94
- //{
95
- // name: "api",
96
- // type: "http",
97
- // target: "server",
98
- // // TODO: change this when published
99
- // handler: "node_modules/@torpor/build/src/site/serverEntry.ts",
100
- // routes: apiRoutes,
101
- // plugins: () => [config("custom", viteOptions())],
102
- //},
103
- {
104
- name: "server",
105
- type: "http",
106
- target: "server",
107
- // TODO: change this when published
108
- handler: "./node_modules/@torpor/build/src/site/serverEntry.ts",
109
- routes,
110
- plugins: () => [(0, import_config.config)("custom", viteOptions()), (0, import_vite.default)({ server: true })]
111
- },
112
- {
113
- name: "client",
114
- type: "client",
115
- target: "browser",
116
- // TODO: change this when published
117
- handler: "./node_modules/@torpor/build/src/site/clientEntry.ts",
118
- base: "/_build",
119
- routes,
120
- plugins: () => [(0, import_config.config)("custom", viteOptions()), (0, import_vite.default)()]
121
- }
122
- ]
96
+ // src/adapters/node/responseToNodeResponse.ts
97
+ var import_types = require("util/types");
98
+ async function responseToNodeResponse(res, outgoing) {
99
+ outgoing.statusCode = res.status;
100
+ outgoing.statusMessage = res.statusText;
101
+ res.headers.forEach((value, key) => {
102
+ outgoing.setHeader(key, value);
123
103
  });
104
+ const body = res[INTERNAL_BODY];
105
+ if (body === null || body === void 0) {
106
+ outgoing.writeHead(res.status, res.statusText);
107
+ outgoing.end();
108
+ } else if (typeof body === "string" || body instanceof Uint8Array) {
109
+ outgoing.writeHead(res.status, res.statusText);
110
+ outgoing.end(body);
111
+ } else if (body instanceof Blob) {
112
+ outgoing.writeHead(res.status, res.statusText);
113
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
114
+ } else if (body instanceof ArrayBuffer) {
115
+ outgoing.writeHead(res.status, res.statusText);
116
+ outgoing.end(new Uint8Array(body));
117
+ } else if ((0, import_types.isArrayBufferView)(body)) {
118
+ outgoing.writeHead(res.status, res.statusText);
119
+ outgoing.end(new Uint8Array(body.buffer));
120
+ } else if (body instanceof FormData) {
121
+ outgoing.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
122
+ outgoing.writeHead(res.status, res.statusText);
123
+ outgoing.end();
124
+ } else {
125
+ outgoing.writeHead(res.status, res.statusText);
126
+ outgoing.end();
127
+ }
128
+ }
129
+
130
+ // src/adapters/node/createFetchHandler.ts
131
+ var GlobalResponse = Response;
132
+ globalThis.Response = class Response2 extends GlobalResponse {
133
+ [INTERNAL_BODY] = null;
134
+ constructor(body, init) {
135
+ super(body, init);
136
+ this[INTERNAL_BODY] = body;
137
+ }
138
+ };
139
+ function createFetchHandler(handler) {
140
+ return async (incoming, outgoing) => {
141
+ const req = await nodeMessageToRequest(incoming);
142
+ const res = await handler(req);
143
+ return await responseToNodeResponse(res, outgoing);
144
+ };
124
145
  }
125
- function routes(router, app) {
126
- return new FileSystemRouter(
127
- {
128
- dir: import_node_path.default.resolve("src/routes"),
129
- extensions: ["js", "ts"]
130
- },
131
- router,
132
- app
133
- );
146
+
147
+ // src/adapters/node/createNodeServer.ts
148
+ function createNodeServer(handler) {
149
+ return (0, import_node_http.createServer)(createFetchHandler(handler));
134
150
  }
135
- function viteOptions() {
136
- return {
137
- resolve: {
138
- alias: {
139
- "@": import_node_path.default.resolve("src")
151
+
152
+ // src/adapters/node/index.ts
153
+ var node_default = {
154
+ serve: (server) => {
155
+ process.env.PROTOCOL ??= "http:";
156
+ process.env.HOST ??= "localhost";
157
+ process.env.PORT ??= "7059";
158
+ console.log(`
159
+ Connecting to ${process.env.HOST}:${process.env.PORT}`);
160
+ const devServer = createNodeServer(server.fetch);
161
+ devServer.listen(parseInt(process.env.PORT), process.env.HOST, () => {
162
+ console.log(`Listening on ${process.env.HOST}:${process.env.PORT}
163
+ `);
164
+ });
165
+ }
166
+ };
167
+
168
+ // src/types/RouteType.ts
169
+ var PAGE_ROUTE = 0;
170
+ var PAGE_SERVER_ROUTE = 1;
171
+ var SERVER_ROUTE = 3;
172
+ var LAYOUT_ROUTE = 4;
173
+ var LAYOUT_SERVER_ROUTE = 5;
174
+ var HOOK_ROUTE = 6;
175
+ var HOOK_SERVER_ROUTE = 7;
176
+
177
+ // src/site/Site.ts
178
+ var Site = class {
179
+ root;
180
+ routes = [];
181
+ // Is default plugins a bad idea?
182
+ // HACK: Set loose because otherwise it uses a list of allowed extensions
183
+ // TODO: Should probably just do this ourselves and let the user pass in
184
+ // tsconfigPaths themselves if they want to do something funky
185
+ plugins = [(0, import_vite_tsconfig_paths.default)({ loose: true })];
186
+ // Is default adapter a bad idea?
187
+ adapter = node_default;
188
+ constructor() {
189
+ this.root = process.cwd();
190
+ }
191
+ async addRouteFolder(folder) {
192
+ const routeFolder = import_node_path.default.join(this.root, folder);
193
+ const routeFiles = await import_node_fs.promises.readdir(routeFolder, { recursive: true });
194
+ for (let file of routeFiles) {
195
+ if (/^(\+|_).+(\.js|\.ts)$/.test(import_node_path.default.basename(file))) {
196
+ let routePath = file.replace(/^\//, "").replace(/(\.ts|\.js)$/, "").replace(/_hook.server$/, "_hook/~server").replace(/_layout.server$/, "_layout/~server").replace(/\+page.server$/, "~server").replace(/\+server$/, "").replace(/\+page$/, "").replace(/\/$/, "");
197
+ routePath = routePath.length > 0 ? `/${routePath}` : "/";
198
+ let type = this.#routeType(file);
199
+ file = import_node_path.default.relative(this.root, import_node_path.default.resolve(routeFolder, file));
200
+ this.routes.push({ path: routePath, file, type });
140
201
  }
141
202
  }
142
- };
143
- }
203
+ this.#sortRoutes();
204
+ }
205
+ addRouteFile(path2, file) {
206
+ let type = this.#routeType(file);
207
+ this.routes.push({ path: path2, file, type });
208
+ this.#sortRoutes();
209
+ }
210
+ #routeType(file) {
211
+ let routePath = file.replace(/^\//, "").replace(/(\.ts|\.js)$/, "");
212
+ if (routePath.endsWith("+page")) {
213
+ return PAGE_ROUTE;
214
+ } else if (routePath.endsWith("+page.server")) {
215
+ return PAGE_SERVER_ROUTE;
216
+ } else if (routePath.endsWith("+server")) {
217
+ return SERVER_ROUTE;
218
+ } else if (routePath.endsWith("_layout")) {
219
+ return LAYOUT_ROUTE;
220
+ } else if (routePath.endsWith("_layout.server")) {
221
+ return LAYOUT_SERVER_ROUTE;
222
+ } else if (routePath.endsWith("_hook")) {
223
+ return HOOK_ROUTE;
224
+ } else if (routePath.endsWith("_hook.server")) {
225
+ return HOOK_SERVER_ROUTE;
226
+ }
227
+ return -1;
228
+ }
229
+ // TODO: You could make your site in a single file, like e.g. Hono...
230
+ //addPage(path: string, endPoint: PageEndPoint, serverEndPoint?: PageServerEndPoint) {}
231
+ //addEndPoint(path: string, endPoint: ServerEndPoint) {}
232
+ #sortRoutes() {
233
+ this.routes = this.routes.sort((a, b) => {
234
+ for (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {
235
+ if (a.path[i] === "[" && b.path[i] !== "[") {
236
+ return 1;
237
+ } else if (b.path[i] === "[" && a.path[i] !== "[") {
238
+ return -1;
239
+ } else if (a.path[i] === b.path[i]) {
240
+ } else {
241
+ return a.path[i].localeCompare(b.path[i]);
242
+ }
243
+ }
244
+ return a.path.length - b.path.length;
245
+ });
246
+ }
247
+ };
144
248
  // Annotate the CommonJS export names for ESM import in node:
145
249
  0 && (module.exports = {
146
- buildRoutePath,
147
- defineConfig
250
+ Site
148
251
  });
149
252
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/site/buildRoutePath.ts","../src/site/defineConfig.ts","../src/site/FileSystemRouter.ts"],"sourcesContent":["import buildRoutePath from \"./site/buildRoutePath\";\nimport defineConfig from \"./site/defineConfig\";\nimport type CookieHelper from \"./types/CookieHelper\";\nimport type PageEndPoint from \"./types/PageEndPoint\";\nimport type PageEvent from \"./types/PageEvent\";\nimport type PageServerAction from \"./types/PageServerAction\";\nimport type PageServerEndPoint from \"./types/PageServerEndPoint\";\nimport type PageServerLoad from \"./types/PageServerLoad\";\nimport type ServerEndPoint from \"./types/ServerEndPoint\";\nimport type ServerEvent from \"./types/ServerEvent\";\nimport type ServerHook from \"./types/ServerHook\";\nimport type ServerRequest from \"./types/ServerRequest\";\nimport type UserConfig from \"./types/UserConfig\";\n\n// NOTE: Do not export anything that relies on vinxi/vite from here, or it will\n// cause problems when they are re-imported when routes are lazily loaded\n\nexport { defineConfig, buildRoutePath };\n\nexport type {\n\tUserConfig,\n\tPageEndPoint,\n\tPageServerEndPoint,\n\tPageServerLoad,\n\tPageServerAction,\n\tServerEndPoint,\n\tServerRequest,\n\tServerHook,\n\tPageEvent,\n\tServerEvent,\n\tCookieHelper,\n};\n","type ParamsType = Record<PropertyKey, any>;\n\nexport default function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(\n\tpath: string,\n\trouteParams: RP,\n\turlParams?: UP,\n) {\n\tfor (let [key, value] of Object.entries(routeParams)) {\n\t\tpath = path.replace(`[${key}]`, value);\n\t}\n\tif (urlParams) {\n\t\t// TODO: More sophisticated url params serialization\n\t\tlet params = Object.entries(urlParams)\n\t\t\t.map(([key, value]) => {\n\t\t\t\tif (value != null) {\n\t\t\t\t\treturn `${key}=${value}`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter(Boolean);\n\t\tif (params.length) {\n\t\t\tpath += `?${params.join(\"&\")}`;\n\t\t}\n\t}\n\treturn path;\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport path from \"node:path\";\nimport { type AppOptions, type RouterSchemaInput, createApp } from \"vinxi\";\nimport { config } from \"vinxi/plugins/config\";\nimport type UserConfig from \"../types/UserConfig\";\nimport FileSystemRouter from \"./FileSystemRouter\";\n\nexport default function defineConfig(options?: UserConfig) {\n\t// Set the port\n\tprocess.env.PORT = (options?.port || 7059).toString();\n\n\t// Get Vinxi to create and serve the app\n\treturn createApp({\n\t\tname: \"torpor\",\n\t\trouters: [\n\t\t\t{\n\t\t\t\tname: \"assets\",\n\t\t\t\ttype: \"static\",\n\t\t\t\tdir: \"./src/assets\",\n\t\t\t},\n\t\t\t// Doesn't look like we can have two server routes?\n\t\t\t// Have to put api in /routes\n\t\t\t// Maybe we can support having /routes/api and routes/site and stripping /site from the start?\n\t\t\t//{\n\t\t\t//\tname: \"api\",\n\t\t\t//\ttype: \"http\",\n\t\t\t//\ttarget: \"server\",\n\t\t\t//\t// TODO: change this when published\n\t\t\t//\thandler: \"node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t//\troutes: apiRoutes,\n\t\t\t//\tplugins: () => [config(\"custom\", viteOptions())],\n\t\t\t//},\n\t\t\t{\n\t\t\t\tname: \"server\",\n\t\t\t\ttype: \"http\",\n\t\t\t\ttarget: \"server\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"./node_modules/@torpor/build/src/site/serverEntry.ts\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor({ server: true })],\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"client\",\n\t\t\t\ttype: \"client\",\n\t\t\t\ttarget: \"browser\",\n\t\t\t\t// TODO: change this when published\n\t\t\t\thandler: \"./node_modules/@torpor/build/src/site/clientEntry.ts\",\n\t\t\t\tbase: \"/_build\",\n\t\t\t\troutes,\n\t\t\t\tplugins: () => [config(\"custom\", viteOptions()), torpor()],\n\t\t\t},\n\t\t],\n\t});\n}\n\nfunction routes(router: RouterSchemaInput, app: AppOptions) {\n\treturn new FileSystemRouter(\n\t\t{\n\t\t\tdir: path.resolve(\"src/routes\"),\n\t\t\textensions: [\"js\", \"ts\"],\n\t\t},\n\t\trouter,\n\t\tapp,\n\t);\n}\n\nfunction viteOptions() {\n\treturn {\n\t\tresolve: {\n\t\t\talias: {\n\t\t\t\t\"@\": path.resolve(\"src\"),\n\t\t\t},\n\t\t},\n\t};\n}\n","import { BaseFileSystemRouter, cleanPath } from \"vinxi/fs-router\";\n\nexport default class FileSystemRouter extends BaseFileSystemRouter {\n\ttoPath(src: string) {\n\t\tlet routePath = cleanPath(src, this.config)\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/_hook.server$/, \"_hook/~server\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath?.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\ttoRoute(filePath: string) {\n\t\treturn {\n\t\t\tpath: this.toPath(filePath),\n\t\t\t$handler: {\n\t\t\t\tsrc: filePath,\n\t\t\t\tpick: [\"default\"],\n\t\t\t},\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEe,SAAR,eACNA,OACA,aACA,WACC;AACD,WAAS,CAAC,KAAK,KAAK,KAA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,MACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAaA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT;AAAA,QACA,SAAS,MAAM,KAAC,sBAAO,UAAU,YAAY,CAAC,OAAG,YAAAC,SAAO,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,MAC1E;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA;AAAA,QAER,SAAS;AAAA,QACT,MAAM;AAAA,QACN;AAAA,QACA,SAAS,MAAM,KAAC,sBAAO,UAAU,YAAY,CAAC,OAAG,YAAAA,SAAO,CAAC;AAAA,MAC1D;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAEA,SAAS,OAAO,QAA2B,KAAiB;AAC3D,SAAO,IAAI;AAAA,IACV;AAAA,MACC,KAAK,iBAAAC,QAAK,QAAQ,YAAY;AAAA,MAC9B,YAAY,CAAC,MAAM,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,cAAc;AACtB,SAAO;AAAA,IACN,SAAS;AAAA,MACR,OAAO;AAAA,QACN,KAAK,iBAAAA,QAAK,QAAQ,KAAK;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACD;","names":["path","torpor","path"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/site/Site.ts","../src/adapters/node/createNodeServer.ts","../src/adapters/node/constants.ts","../src/adapters/node/nodeMessageToRequest.ts","../src/adapters/node/flattenHeaders.ts","../src/adapters/node/responseToNodeResponse.ts","../src/adapters/node/createFetchHandler.ts","../src/adapters/node/index.ts","../src/types/RouteType.ts"],"sourcesContent":["import Site from \"./site/Site\";\nimport type PageEndPoint from \"./types/PageEndPoint\";\nimport type PageLoadEvent from \"./types/PageLoadEvent\";\nimport type PageServerAction from \"./types/PageServerAction\";\nimport type PageServerEndPoint from \"./types/PageServerEndPoint\";\nimport type PageServerLoad from \"./types/PageServerLoad\";\nimport type ServerEndPoint from \"./types/ServerEndPoint\";\nimport type ServerHook from \"./types/ServerHook\";\nimport type ServerLoadEvent from \"./types/ServerLoadEvent\";\nimport type ServerRequest from \"./types/ServerRequest\";\n\nexport { Site };\n\nexport type {\n\tPageEndPoint,\n\tPageServerEndPoint,\n\tPageServerLoad,\n\tPageServerAction,\n\tServerEndPoint,\n\tServerRequest,\n\tServerHook,\n\tPageLoadEvent,\n\tServerLoadEvent,\n};\n","import { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { Plugin } from \"vite\";\nimport tsconfigPaths from \"vite-tsconfig-paths\";\nimport node from \"../adapters/node\";\nimport Adapter from \"../types/Adapter\";\nimport {\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\n\n// 1. The user sets this up\n// 2. It is passed into serverEntry and clientEntry through a Vite plugin\n// (defined in manifest.ts)\n// 3. In those files, it is used to build a Router\n\n/**\n * The Site class contains the information necessary to setup a @torpor/build\n * site, including routes, plugins, and options.\n */\nexport default class Site {\n\troot: string;\n\troutes: { path: string; file: string; type: number }[] = [];\n\t// Is default plugins a bad idea?\n\t// HACK: Set loose because otherwise it uses a list of allowed extensions\n\t// TODO: Should probably just do this ourselves and let the user pass in\n\t// tsconfigPaths themselves if they want to do something funky\n\tplugins: Plugin[] = [tsconfigPaths({ loose: true })];\n\t// Is default adapter a bad idea?\n\tadapter: Adapter = node;\n\n\tconstructor() {\n\t\tthis.root = process.cwd();\n\t}\n\n\tasync addRouteFolder(folder: string) {\n\t\tconst routeFolder = path.join(this.root, folder);\n\t\tconst routeFiles = await fs.readdir(routeFolder, { recursive: true });\n\n\t\tfor (let file of routeFiles) {\n\t\t\t// The file must start with `+` or `_` and end with `.js` or `.ts`\n\t\t\tif (/^(\\+|_).+(\\.js|\\.ts)$/.test(path.basename(file))) {\n\t\t\t\tlet routePath = file\n\t\t\t\t\t.replace(/^\\//, \"\")\n\t\t\t\t\t.replace(/(\\.ts|\\.js)$/, \"\")\n\t\t\t\t\t.replace(/_hook.server$/, \"_hook/~server\")\n\t\t\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t\t\t.replace(/\\/$/, \"\");\n\t\t\t\troutePath = routePath.length > 0 ? `/${routePath}` : \"/\";\n\t\t\t\tlet type = this.#routeType(file);\n\t\t\t\tfile = path.relative(this.root, path.resolve(routeFolder, file));\n\t\t\t\tthis.routes.push({ path: routePath, file, type });\n\t\t\t}\n\t\t}\n\t\tthis.#sortRoutes();\n\t}\n\n\taddRouteFile(path: string, file: string) {\n\t\tlet type = this.#routeType(file);\n\t\tthis.routes.push({ path, file, type });\n\t\tthis.#sortRoutes();\n\t}\n\n\t#routeType(file: string): number {\n\t\tlet routePath = file.replace(/^\\//, \"\").replace(/(\\.ts|\\.js)$/, \"\");\n\t\tif (routePath.endsWith(\"+page\")) {\n\t\t\treturn PAGE_ROUTE;\n\t\t} else if (routePath.endsWith(\"+page.server\")) {\n\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"+server\")) {\n\t\t\treturn SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout\")) {\n\t\t\treturn LAYOUT_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout.server\")) {\n\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook\")) {\n\t\t\treturn HOOK_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook.server\")) {\n\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t}\n\t\treturn -1;\n\t}\n\n\t// TODO: You could make your site in a single file, like e.g. Hono...\n\t//addPage(path: string, endPoint: PageEndPoint, serverEndPoint?: PageServerEndPoint) {}\n\t//addEndPoint(path: string, endPoint: ServerEndPoint) {}\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","import { createServer } from \"node:http\";\nimport { createFetchHandler } from \"./createFetchHandler\";\n\nexport default function createNodeServer(handler: (req: Request) => Response | Promise<Response>) {\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 = 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) {\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) => {\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 Server from \"../../server/Server\";\nimport type Adapter from \"../../types/Adapter\";\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\tconsole.log(`\\nConnecting to ${process.env.HOST}:${process.env.PORT}`);\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 ${process.env.HOST}:${process.env.PORT}\\n`);\n\t\t});\n\t},\n} satisfies Adapter;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA+B;AAC/B,uBAAiB;AAEjB,iCAA0B;;;ACH1B,uBAA6B;;;ACAtB,IAAM,gBAAgB,OAAO,eAAe;;;ACEnD,yBAAyB;;;ACCV,SAAR,eACN,SACc;AACd,QAAM,cAAc,IAAI,QAAQ;AAChC,aAAW,CAAC,KAAK,KAA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I,GAAG,IAAI,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,GAAG,KAAK;AAChE,YAAI,EAAE,KAAK,CAAC,MAAM,OAAO,EAAE,KAAK,CAAC,MAAM,KAAK;AAC3C,iBAAO;AAAA,QACR,WAAW,EAAE,KAAK,CAAC,MAAM,OAAO,EAAE,KAAK,CAAC,MAAM,KAAK;AAClD,iBAAO;AAAA,QACR,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG;AAAA,QAEpC,OAAO;AACN,iBAAO,EAAE,KAAK,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;AAAA,QACzC;AAAA,MACD;AACA,aAAO,EAAE,KAAK,SAAS,EAAE,KAAK;AAAA,IAC/B,CAAC;AAAA,EACF;AACD;","names":["v","path","Response","tsconfigPaths","path","fs"]}
package/dist/index.d.cts CHANGED
@@ -1,24 +1,10 @@
1
- import * as vinxi from 'vinxi';
2
- import { CookieSerializeOptions } from 'vinxi/http';
1
+ export { S as Site } from './Site-CgoeDt8k.cjs';
3
2
  import { Component } from '@torpor/view';
4
- import { ServerResponse } from 'node:http';
3
+ import { C as CookieHelper, H as HeaderHelper } from './Server-CB99REgs.cjs';
4
+ import 'vite';
5
+ import 'cookie';
5
6
 
6
- type ParamsType = Record<PropertyKey, any>;
7
- declare function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(path: string, routeParams: RP, urlParams?: UP): string;
8
-
9
- type UserConfig = {
10
- port?: number;
11
- };
12
-
13
- declare function defineConfig(options?: UserConfig): vinxi.App;
14
-
15
- type CookieHelper = {
16
- get: (name: string) => string | undefined;
17
- set: (name: string, value: string, options?: CookieSerializeOptions) => void;
18
- delete: (name: string, options?: CookieSerializeOptions) => void;
19
- };
20
-
21
- type PageEvent = {
7
+ type PageLoadEvent = {
22
8
  /**
23
9
  * The URL for the server function.
24
10
  */
@@ -45,7 +31,7 @@ type PageEndPoint = {
45
31
  /**
46
32
  * Loads data for the page.
47
33
  */
48
- load?: (event: PageEvent) => any;
34
+ load?: (event: PageLoadEvent) => any;
49
35
  /**
50
36
  * The component that is displayed for the page.
51
37
  */
@@ -53,7 +39,7 @@ type PageEndPoint = {
53
39
  /**
54
40
  * The head element data for the page, which may include a <title> and <meta> elements.
55
41
  */
56
- head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
42
+ head?: HeadElement[] | ((event: PageLoadEvent) => HeadElement[]);
57
43
  };
58
44
 
59
45
  type HeadElement = TitleElement | MetaElement;
@@ -65,7 +51,7 @@ interface MetaElement {
65
51
  content: string;
66
52
  }
67
53
 
68
- type ServerEvent = {
54
+ type ServerLoadEvent = {
69
55
  /**
70
56
  * The URL for the server function.
71
57
  */
@@ -79,17 +65,23 @@ type ServerEvent = {
79
65
  * and pages. It flows down in that order.
80
66
  */
81
67
  appData: Record<string, any>;
68
+ /**
69
+ * The server request.
70
+ */
82
71
  request: Request;
83
- response: ServerResponse;
84
72
  /**
85
73
  * A helper for getting and setting cookie data.
86
74
  */
87
75
  cookies: CookieHelper;
76
+ /**
77
+ * A helper for getting and setting headers.
78
+ */
79
+ headers: HeaderHelper;
88
80
  };
89
81
 
90
- type PageServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
82
+ type PageServerAction = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
91
83
 
92
- type PageServerLoad = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
84
+ type PageServerLoad = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
93
85
 
94
86
  /**
95
87
  * For +page.server.
@@ -105,7 +97,7 @@ type PageServerEndPoint = {
105
97
  actions?: Record<string, PageServerAction>;
106
98
  };
107
99
 
108
- type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
100
+ type ServerRequest = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
109
101
 
110
102
  /**
111
103
  * For +server.
@@ -153,6 +145,6 @@ type ServerHook = {
153
145
  handle?: ServerLoad;
154
146
  };
155
147
 
156
- type ServerLoad = (event: ServerEvent) => Promise<void> | void;
148
+ type ServerLoad = (event: ServerLoadEvent) => Promise<void> | void;
157
149
 
158
- export { type CookieHelper, type PageEndPoint, type PageEvent, type PageServerAction, type PageServerEndPoint, type PageServerLoad, type ServerEndPoint, type ServerEvent, type ServerHook, type ServerRequest, type UserConfig, buildRoutePath, defineConfig };
150
+ export type { PageEndPoint, PageLoadEvent, PageServerAction, PageServerEndPoint, PageServerLoad, ServerEndPoint, ServerHook, ServerLoadEvent, ServerRequest };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,10 @@
1
- import * as vinxi from 'vinxi';
2
- import { CookieSerializeOptions } from 'vinxi/http';
1
+ export { S as Site } from './Site-D95nwrAg.js';
3
2
  import { Component } from '@torpor/view';
4
- import { ServerResponse } from 'node:http';
3
+ import { C as CookieHelper, H as HeaderHelper } from './Server-CB99REgs.js';
4
+ import 'vite';
5
+ import 'cookie';
5
6
 
6
- type ParamsType = Record<PropertyKey, any>;
7
- declare function buildRoutePath<RP extends ParamsType, UP extends ParamsType>(path: string, routeParams: RP, urlParams?: UP): string;
8
-
9
- type UserConfig = {
10
- port?: number;
11
- };
12
-
13
- declare function defineConfig(options?: UserConfig): vinxi.App;
14
-
15
- type CookieHelper = {
16
- get: (name: string) => string | undefined;
17
- set: (name: string, value: string, options?: CookieSerializeOptions) => void;
18
- delete: (name: string, options?: CookieSerializeOptions) => void;
19
- };
20
-
21
- type PageEvent = {
7
+ type PageLoadEvent = {
22
8
  /**
23
9
  * The URL for the server function.
24
10
  */
@@ -45,7 +31,7 @@ type PageEndPoint = {
45
31
  /**
46
32
  * Loads data for the page.
47
33
  */
48
- load?: (event: PageEvent) => any;
34
+ load?: (event: PageLoadEvent) => any;
49
35
  /**
50
36
  * The component that is displayed for the page.
51
37
  */
@@ -53,7 +39,7 @@ type PageEndPoint = {
53
39
  /**
54
40
  * The head element data for the page, which may include a <title> and <meta> elements.
55
41
  */
56
- head?: HeadElement[] | ((event: PageEvent) => HeadElement[]);
42
+ head?: HeadElement[] | ((event: PageLoadEvent) => HeadElement[]);
57
43
  };
58
44
 
59
45
  type HeadElement = TitleElement | MetaElement;
@@ -65,7 +51,7 @@ interface MetaElement {
65
51
  content: string;
66
52
  }
67
53
 
68
- type ServerEvent = {
54
+ type ServerLoadEvent = {
69
55
  /**
70
56
  * The URL for the server function.
71
57
  */
@@ -79,17 +65,23 @@ type ServerEvent = {
79
65
  * and pages. It flows down in that order.
80
66
  */
81
67
  appData: Record<string, any>;
68
+ /**
69
+ * The server request.
70
+ */
82
71
  request: Request;
83
- response: ServerResponse;
84
72
  /**
85
73
  * A helper for getting and setting cookie data.
86
74
  */
87
75
  cookies: CookieHelper;
76
+ /**
77
+ * A helper for getting and setting headers.
78
+ */
79
+ headers: HeaderHelper;
88
80
  };
89
81
 
90
- type PageServerAction = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
82
+ type PageServerAction = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
91
83
 
92
- type PageServerLoad = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
84
+ type PageServerLoad = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
93
85
 
94
86
  /**
95
87
  * For +page.server.
@@ -105,7 +97,7 @@ type PageServerEndPoint = {
105
97
  actions?: Record<string, PageServerAction>;
106
98
  };
107
99
 
108
- type ServerRequest = (event: ServerEvent) => Response | Promise<Response | undefined> | void;
100
+ type ServerRequest = (event: ServerLoadEvent) => Response | Promise<Response | undefined> | Promise<void> | void;
109
101
 
110
102
  /**
111
103
  * For +server.
@@ -153,6 +145,6 @@ type ServerHook = {
153
145
  handle?: ServerLoad;
154
146
  };
155
147
 
156
- type ServerLoad = (event: ServerEvent) => Promise<void> | void;
148
+ type ServerLoad = (event: ServerLoadEvent) => Promise<void> | void;
157
149
 
158
- export { type CookieHelper, type PageEndPoint, type PageEvent, type PageServerAction, type PageServerEndPoint, type PageServerLoad, type ServerEndPoint, type ServerEvent, type ServerHook, type ServerRequest, type UserConfig, buildRoutePath, defineConfig };
150
+ export type { PageEndPoint, PageLoadEvent, PageServerAction, PageServerEndPoint, PageServerLoad, ServerEndPoint, ServerHook, ServerLoadEvent, ServerRequest };