@torpor/build 1.0.2 → 1.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 (55) hide show
  1. package/dist/Router-COdQuVUi.d.mts +59 -0
  2. package/dist/Router-COdQuVUi.d.mts.map +1 -0
  3. package/dist/{Server-BnjLJleZ.mjs → Server-Dr6yqVa5.mjs} +2 -2
  4. package/dist/{Server-BnjLJleZ.mjs.map → Server-Dr6yqVa5.mjs.map} +1 -1
  5. package/dist/{ServerEvent-Dljn5i7A.mjs → ServerEvent-gmOvC_Yf.mjs} +3 -2
  6. package/dist/{ServerEvent-Dljn5i7A.mjs.map → ServerEvent-gmOvC_Yf.mjs.map} +1 -1
  7. package/dist/ServerHook-BlLArueW.d.mts +91 -0
  8. package/dist/ServerHook-BlLArueW.d.mts.map +1 -0
  9. package/dist/{Site-CE0_o5Ci.d.mts → Site-CTADVh7d.d.mts} +12 -91
  10. package/dist/Site-CTADVh7d.d.mts.map +1 -0
  11. package/dist/bin/index.js +1 -1
  12. package/dist/clientEntry.mjs +3 -2
  13. package/dist/clientEntry.mjs.map +1 -1
  14. package/dist/dev.d.mts +1 -1
  15. package/dist/dev.mjs +2 -2
  16. package/dist/index.d.mts +3 -57
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +153 -3
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{load-BntzvmwL.mjs → load-C9RpS_4j.mjs} +32 -26
  21. package/dist/{load-BntzvmwL.mjs.map → load-C9RpS_4j.mjs.map} +1 -1
  22. package/dist/nav.mjs +7 -5
  23. package/dist/nav.mjs.map +1 -1
  24. package/dist/openapi.d.mts +1 -1
  25. package/dist/pathTrie-D4Ax2Mu9.mjs.map +1 -1
  26. package/dist/{response-Bg4w2S1q.mjs → response-CuNPcxsY.mjs} +2 -2
  27. package/dist/{response-Bg4w2S1q.mjs.map → response-CuNPcxsY.mjs.map} +1 -1
  28. package/dist/response.mjs +2 -2
  29. package/dist/run.d.mts +1 -1
  30. package/dist/run.mjs +1 -1
  31. package/dist/{runOpenApi-C8eI2Fh0.mjs → runOpenApi-yIzYasNN.mjs} +15 -15
  32. package/dist/{runOpenApi-C8eI2Fh0.mjs.map → runOpenApi-yIzYasNN.mjs.map} +1 -1
  33. package/dist/server/Server.mjs +1 -1
  34. package/dist/server.mjs +2 -2
  35. package/dist/serverEntry-DVv9YI3I.d.mts +13 -0
  36. package/dist/serverEntry-DVv9YI3I.d.mts.map +1 -0
  37. package/dist/serverEntry-LyB5pl0E.mjs +11 -0
  38. package/dist/serverEntry-LyB5pl0E.mjs.map +1 -0
  39. package/dist/serverEntry.d.mts +1 -1
  40. package/dist/serverEntry.mjs +1 -1
  41. package/dist/{serverEntry-1qY3wZig.mjs → serverHandlers-DeL1qZJa.mjs} +199 -71
  42. package/dist/serverHandlers-DeL1qZJa.mjs.map +1 -0
  43. package/dist/test.d.mts +1 -1
  44. package/dist/test.d.mts.map +1 -1
  45. package/dist/test.mjs +7 -242
  46. package/dist/test.mjs.map +1 -1
  47. package/dist/{unprocessable-DAZbrDeR.mjs → unprocessable-D6RcYLh6.mjs} +7 -5
  48. package/dist/{unprocessable-DAZbrDeR.mjs.map → unprocessable-D6RcYLh6.mjs.map} +1 -1
  49. package/package.json +5 -5
  50. package/dist/Site-CE0_o5Ci.d.mts.map +0 -1
  51. package/dist/endpoint-EULRGCKA.mjs +0 -108
  52. package/dist/endpoint-EULRGCKA.mjs.map +0 -1
  53. package/dist/serverEntry-1qY3wZig.mjs.map +0 -1
  54. package/dist/serverEntry-BAO8m03V.d.mts +0 -6
  55. package/dist/serverEntry-BAO8m03V.d.mts.map +0 -1
@@ -0,0 +1,59 @@
1
+ import { t as ServerHook } from "./ServerHook-BlLArueW.mjs";
2
+ //#region src/types/ManifestRoute.d.ts
3
+ interface ManifestRoute {
4
+ path: string;
5
+ type: number;
6
+ endPoint: () => Promise<any>;
7
+ subFolder: string | undefined;
8
+ }
9
+ //#endregion
10
+ //#region src/types/RouteLayoutHandler.d.ts
11
+ interface RouteLayoutHandler {
12
+ path: string;
13
+ endPoint: () => Promise<any>;
14
+ serverEndPoint?: () => Promise<any>;
15
+ }
16
+ //#endregion
17
+ //#region src/types/RouteHandler.d.ts
18
+ /**
19
+ * A handler for a route in the Router.
20
+ */
21
+ interface RouteHandler {
22
+ path: string;
23
+ type: number;
24
+ endPoint: () => Promise<any>;
25
+ subFolder?: string;
26
+ loaded?: boolean;
27
+ layouts?: RouteLayoutHandler[];
28
+ serverEndPoint?: () => Promise<any>;
29
+ serverHooks?: (() => Promise<any>)[];
30
+ modulePromise?: Promise<any>;
31
+ resolvedModule?: any;
32
+ resolvedHooks?: Promise<ServerHook[]>;
33
+ }
34
+ //#endregion
35
+ //#region src/site/Router.d.ts
36
+ /**
37
+ * A router that handles file routes with layouts, hooks, etc.
38
+ */
39
+ declare class Router {
40
+ #private;
41
+ routes: Route[];
42
+ constructor();
43
+ addPages(routes: ManifestRoute[]): this;
44
+ addPage(path: string, type: number, endPoint: () => Promise<any>, subFolder?: string): this;
45
+ match(path: string, query: URLSearchParams): RouteMatch | undefined;
46
+ }
47
+ declare class Route {
48
+ path: string;
49
+ handler: RouteHandler;
50
+ constructor(path: string, handler: RouteHandler);
51
+ }
52
+ interface RouteMatch {
53
+ handler: RouteHandler;
54
+ params?: Record<string, string>;
55
+ query: URLSearchParams;
56
+ }
57
+ //#endregion
58
+ export { Router as t };
59
+ //# sourceMappingURL=Router-COdQuVUi.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router-COdQuVUi.d.mts","names":[],"sources":["../src/types/ManifestRoute.ts","../src/types/RouteLayoutHandler.ts","../src/types/RouteHandler.ts","../src/site/Router.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA,gBAAgB;EAChB;;;;UCJwB;EACxB;EACA,gBAAgB;EAChB,uBAAuB;;;;;;;UCGC;EACxB;EACA;EACA,gBAAgB;EAChB;EAEA;EACA,UAAU;EACV,uBAAuB;EACvB,qBAAqB;EAIrB,gBAAgB;EAChB;EACA,gBAAgB,QAAQ;;;;;;;cCbJ;;EACpB,QAAQ;EAMR;EAOA,SAAS,QAAQ;EAQjB,QAAQ,cAAc,cAAc,gBAAgB,cAAc;EAuBlE,MAAM,cAAc,OAAO,kBAAkB;;cA2GxC;EACL;EACA,SAAS;EAET,YAAY,cAAc,SAAS;;UAM1B;EACT,SAAS;EACT,SAAS;EACT,OAAO"}
@@ -1,5 +1,5 @@
1
1
  import { t as PathTrie } from "./pathTrie-D4Ax2Mu9.mjs";
2
- import { t as ServerEvent } from "./ServerEvent-Dljn5i7A.mjs";
2
+ import { t as ServerEvent } from "./ServerEvent-gmOvC_Yf.mjs";
3
3
  //#region src/server/Server.ts
4
4
  /**
5
5
  * A Fetch API Request/Response server.
@@ -101,4 +101,4 @@ var RouteHandler = class {
101
101
  //#endregion
102
102
  export { Server as t };
103
103
 
104
- //# sourceMappingURL=Server-BnjLJleZ.mjs.map
104
+ //# sourceMappingURL=Server-Dr6yqVa5.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Server-BnjLJleZ.mjs","names":["#trie","#sortRoutes"],"sources":["../src/server/Server.ts"],"sourcesContent":["import PathTrie from \"../utils/pathTrie\";\nimport ServerEvent from \"./ServerEvent\";\nimport type MiddlewareFunction from \"./types/MiddlewareFunction\";\nimport type ServerFunction from \"./types/ServerFunction\";\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// Match index for the routes above\n\t#trie = new PathTrie<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\t// Use the request as-is when we were given one, so that the adapter\n\t\t// doesn't pay for constructing it twice\n\t\tconst request = input instanceof Request && !init ? input : 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, url);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tlet entered = 0;\n\t\t\tlet response: Response | undefined = undefined;\n\t\t\tlet error: unknown = undefined;\n\t\t\ttry {\n\t\t\t\tfor (; entered < this.middleware.length && !response; entered++) {\n\t\t\t\t\t// A middleware returns a Response to short-circuit the request\n\t\t\t\t\tconst result = await this.middleware[entered].enter?.(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!response && match) {\n\t\t\t\t\tconst result = await match.fn(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Exits can handle the error by returning a Response; if none\n\t\t\t\t// does, it is rethrown below\n\t\t\t\terror = e;\n\t\t\t\tev.error = e;\n\t\t\t} finally {\n\t\t\t\tif (response) {\n\t\t\t\t\tev.response = response;\n\t\t\t\t}\n\t\t\t\t// Run exit hooks in reverse order for the middleware that were\n\t\t\t\t// entered. An exit hook can return a Response to replace the\n\t\t\t\t// response, or to handle ev.error\n\t\t\t\twhile (entered > 0) {\n\t\t\t\t\tentered--;\n\t\t\t\t\tconst result = await this.middleware[entered].exit?.(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t\tev.response = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (error && !response) {\n\t\t\t\tthrow error;\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\tlet handler = new RouteHandler(path, fn);\n\t\tthis.routes.push(handler);\n\t\tthis.#trie.insert(path, handler);\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\tmatch(path: string): Match | undefined {\n\t\tconst found = this.#trie.match(path);\n\t\tif (found) {\n\t\t\treturn {\n\t\t\t\tfn: found.value.fn,\n\t\t\t\tparams: found.params,\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\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = 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\ninterface Match {\n\tfn: ServerFunction;\n\tparams?: Record<string, string>;\n}\n"],"mappings":";;;;;;AAQA,IAAqB,SAArB,MAA4B;CAE3B,SAAyB,CAAC;CAE1B,QAAQ,IAAI,SAAuB;CAEnC,aAAmC,CAAC;CAEpC,cAAc;EACb,KAAK,SAAS,CAAC;EACf,KAAK,aAAa,CAAC;CACpB;;;;;;CAOA,QAAQ,OAAO,OAA0B,SAA0C;EAGlF,MAAM,UAAU,iBAAiB,WAAW,CAAC,OAAO,QAAQ,IAAI,QAAQ,OAAO,IAAI;EACnF,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;EAC/B,MAAM,QAAQ,KAAK,MAAM,IAAI,QAAQ;EACrC,IAAI,KAAK,IAAI,YAAY,SAAS,OAAO,QAAQ,GAAG;EAEpD,IAAI,KAAK,WAAW,QAAQ;GAE3B,IAAI,UAAU;GACd,IAAI,WAAiC,KAAA;GACrC,IAAI,QAAiB,KAAA;GACrB,IAAI;IACH,OAAO,UAAU,KAAK,WAAW,UAAU,CAAC,UAAU,WAAW;KAEhE,MAAM,SAAS,MAAM,KAAK,WAAW,QAAQ,CAAC,QAAQ,EAAE;KACxD,IAAI,QACH,WAAW;IAEb;IACA,IAAI,CAAC,YAAY,OAAO;KACvB,MAAM,SAAS,MAAM,MAAM,GAAG,EAAE;KAChC,IAAI,QACH,WAAW;IAEb;GACD,SAAS,GAAG;IAGX,QAAQ;IACR,GAAG,QAAQ;GACZ,UAAU;IACT,IAAI,UACH,GAAG,WAAW;IAKf,OAAO,UAAU,GAAG;KACnB;KACA,MAAM,SAAS,MAAM,KAAK,WAAW,QAAQ,CAAC,OAAO,EAAE;KACvD,IAAI,QAAQ;MACX,WAAW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AY,MAAc,IAAoB;EAC7C,KAAK,OAAO;EACZ,KAAK,KAAK;CACX;AACD"}
1
+ {"version":3,"file":"Server-Dr6yqVa5.mjs","names":["#trie","#sortRoutes"],"sources":["../src/server/Server.ts"],"sourcesContent":["import PathTrie from \"../utils/pathTrie\";\nimport ServerEvent from \"./ServerEvent\";\nimport type MiddlewareFunction from \"./types/MiddlewareFunction\";\nimport type ServerFunction from \"./types/ServerFunction\";\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// Match index for the routes above\n\t#trie = new PathTrie<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\t// Use the request as-is when we were given one, so that the adapter\n\t\t// doesn't pay for constructing it twice\n\t\tconst request = input instanceof Request && !init ? input : 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, url);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tlet entered = 0;\n\t\t\tlet response: Response | undefined = undefined;\n\t\t\tlet error: unknown = undefined;\n\t\t\ttry {\n\t\t\t\tfor (; entered < this.middleware.length && !response; entered++) {\n\t\t\t\t\t// A middleware returns a Response to short-circuit the request\n\t\t\t\t\tconst result = await this.middleware[entered].enter?.(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!response && match) {\n\t\t\t\t\tconst result = await match.fn(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Exits can handle the error by returning a Response; if none\n\t\t\t\t// does, it is rethrown below\n\t\t\t\terror = e;\n\t\t\t\tev.error = e;\n\t\t\t} finally {\n\t\t\t\tif (response) {\n\t\t\t\t\tev.response = response;\n\t\t\t\t}\n\t\t\t\t// Run exit hooks in reverse order for the middleware that were\n\t\t\t\t// entered. An exit hook can return a Response to replace the\n\t\t\t\t// response, or to handle ev.error\n\t\t\t\twhile (entered > 0) {\n\t\t\t\t\tentered--;\n\t\t\t\t\tconst result = await this.middleware[entered].exit?.(ev);\n\t\t\t\t\tif (result) {\n\t\t\t\t\t\tresponse = result;\n\t\t\t\t\t\tev.response = result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (error && !response) {\n\t\t\t\tthrow error;\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\tlet handler = new RouteHandler(path, fn);\n\t\tthis.routes.push(handler);\n\t\tthis.#trie.insert(path, handler);\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\tmatch(path: string): Match | undefined {\n\t\tconst found = this.#trie.match(path);\n\t\tif (found) {\n\t\t\treturn {\n\t\t\t\tfn: found.value.fn,\n\t\t\t\tparams: found.params,\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\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = 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\ninterface Match {\n\tfn: ServerFunction;\n\tparams?: Record<string, string>;\n}\n"],"mappings":";;;;;;AAQA,IAAqB,SAArB,MAA4B;CAE3B,SAAyB,CAAC;CAE1B,QAAQ,IAAI,SAAuB;CAEnC,aAAmC,CAAC;CAEpC,cAAc;EACb,KAAK,SAAS,CAAC;EACf,KAAK,aAAa,CAAC;CACpB;;;;;;CAOA,QAAQ,OAAO,OAA0B,SAA0C;EAGlF,MAAM,UAAU,iBAAiB,WAAW,CAAC,OAAO,QAAQ,IAAI,QAAQ,OAAO,IAAI;EACnF,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;EAC/B,MAAM,QAA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AQ,MAAM;EACf;EAED,QAAQ,IAAI,0BAA0B,MAAM;CAC7C;CAIA,IAAI,GAAG,IAAkC;EACxC,KAAK,aAAa,KAAK,WAAW,OAAO,EAAE;EAC3C,OAAO;CACR;CAEA,cAAc;EACb,KAAK,SAAS,KAAK,OAAO,MAAM,GAAG,MAAM;GAGxC,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,GAAG,KAC3D,IAAI,EAAE,KAAK,OAAO,OAAO,EAAE,KAAK,OAAO,KACtC,OAAO;QACD,IAAI,EAAE,KAAK,OAAO,OAAO,EAAE,KAAK,OAAO,KAC7C,OAAO;QACD,IAAI,EAAE,KAAK,OAAO,EAAE,KAAK,IAAI,CAEpC,OACC,OAAO,EAAE,KAAK,EAAE,CAAC,cAAc,EAAE,KAAK,EAAE;GAG1C,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK;EAC/B,CAAC;CACF;AACD;AAEA,IAAM,eAAN,MAAmB;CAClB;CACA;CAEA,YAAY,MAAc,IAAoB;EAC7C,KAAK,OAAO;EACZ,KAAK,KAAK;CACX;AACD"}
@@ -8,7 +8,8 @@ var CookieHelper = class {
8
8
  }
9
9
  get(name) {
10
10
  if (this.cookies.has(name)) return parseCookie(this.cookies.get(name))[name];
11
- return parseCookie(this.request.headers.get("Cookie") ?? "")[name];
11
+ const header = this.request.headers.get("Cookie");
12
+ return parseCookie(header ?? "")[name];
12
13
  }
13
14
  set(name, value, options) {
14
15
  options ??= {};
@@ -96,4 +97,4 @@ var ServerEvent = class {
96
97
  //#endregion
97
98
  export { HeaderHelper as n, CookieHelper as r, ServerEvent as t };
98
99
 
99
- //# sourceMappingURL=ServerEvent-Dljn5i7A.mjs.map
100
+ //# sourceMappingURL=ServerEvent-gmOvC_Yf.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServerEvent-Dljn5i7A.mjs","names":["#url"],"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } 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 value from the map\n\t\tif (this.cookies.has(name)) {\n\t\t\t// The stored value is a serialized Set-Cookie header; pull the\n\t\t\t// \"name=value\" prefix off and re-parse to get just the value\n\t\t\treturn parseCookie(this.cookies.get(name)!)[name];\n\t\t}\n\n\t\t// Otherwise, return the value from the `cookie` header\n\t\tconst header = this.request.headers.get(\"Cookie\");\n\t\treturn parseCookie(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\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value, ...options }));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with an empty value and an immediate expiry date.\n\t\t// Apply the same secure defaults as `set` so a previously-set Secure\n\t\t// cookie is actually overridden by the deletion.\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\toptions.expires = new Date(0);\n\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value: \"\", ...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 | undefined | void;\n\t/**\n\t * Set when the route handler (or a middleware enter hook) threw an\n\t * error. Exit hooks can return a Response to handle it; if none does,\n\t * the error is rethrown to the caller.\n\t */\n\terror: unknown;\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\t// Parsed once per request; Server.fetch passes the URL it already needed\n\t// for matching so it isn't parsed twice\n\t#url: URL | undefined;\n\n\t/** The request URL, parsed lazily. */\n\tget url(): URL {\n\t\treturn (this.#url ??= new URL(this.request.url));\n\t}\n\n\tconstructor(request: Request, params?: Record<string, string>, url?: URL) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.#url = url;\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\t/**\n\t * Reads the request body as JSON.\n\t */\n\tjson(): Promise<unknown> {\n\t\treturn this.request.json();\n\t}\n}\n"],"mappings":";;AAEA,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,IAAI;CAEvC,YAAY,SAAkB;EAC7B,KAAK,UAAU;CAChB;CAEA,IAAI,MAAkC;EAErC,IAAI,KAAK,QAAQ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KA,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,OAAO;EACvC,KAAK,UAAU,IAAI,aAAa,OAAO;EAIvC,KAAK,UAAU,WAAW;CAC3B;CAEA,aAAmB;EAClB,IAAI,CAAC,KAAK,UACT,MAAM,IAAI,MAAM,0BAA0B;EAG3C,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,OAAO,GAC9C,KAAK,SAAS,QAAQ,OAAO,cAAc,MAAM;EAGlD,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAC/C,KAAK,SAAS,QAAQ,OAAO,OAAO,IAAI,OAAO,EAAE;CAEnD;;;;CAKA,OAAyB;EACxB,OAAO,KAAK,QAAQ,KAAK;CAC1B;AACD"}
1
+ {"version":3,"file":"ServerEvent-gmOvC_Yf.mjs","names":["#url"],"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } 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 value from the map\n\t\tif (this.cookies.has(name)) {\n\t\t\t// The stored value is a serialized Set-Cookie header; pull the\n\t\t\t// \"name=value\" prefix off and re-parse to get just the value\n\t\t\treturn parseCookie(this.cookies.get(name)!)[name];\n\t\t}\n\n\t\t// Otherwise, return the value from the `cookie` header\n\t\tconst header = this.request.headers.get(\"Cookie\");\n\t\treturn parseCookie(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\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value, ...options }));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with an empty value and an immediate expiry date.\n\t\t// Apply the same secure defaults as `set` so a previously-set Secure\n\t\t// cookie is actually overridden by the deletion.\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\toptions.expires = new Date(0);\n\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value: \"\", ...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 | undefined | void;\n\t/**\n\t * Set when the route handler (or a middleware enter hook) threw an\n\t * error. Exit hooks can return a Response to handle it; if none does,\n\t * the error is rethrown to the caller.\n\t */\n\terror: unknown;\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\t// Parsed once per request; Server.fetch passes the URL it already needed\n\t// for matching so it isn't parsed twice\n\t#url: URL | undefined;\n\n\t/** The request URL, parsed lazily. */\n\tget url(): URL {\n\t\treturn (this.#url ??= new URL(this.request.url));\n\t}\n\n\tconstructor(request: Request, params?: Record<string, string>, url?: URL) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.#url = url;\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\t/**\n\t * Reads the request body as JSON.\n\t */\n\tjson(): Promise<unknown> {\n\t\treturn this.request.json();\n\t}\n}\n"],"mappings":";;AAEA,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,IAAI;CAEvC,YAAY,SAAkB;EAC7B,KAAK,UAAU;CAChB;CAEA,IAAI,MAAkC;EAErC,IAAI,KAAK,QAAQ,IAAI,IAAI,GAGxB,OAAO,YAAY,KAAK,QAAQ,IAAI,IAAI,CAAE,CAAC,CAAC;EAI7C,MAAM,SAAS,KAAK,QAAQ,QAAQ,IAAI,QAAQ;EAChD,OAAO,YAAY,UAAU,EAAE,CAAC,CAAC;CAClC;CAEA,IAAI,MAAc,OAAe,SAAkC;EAElE,YAAY,CAAC;EACb,QAAQ,aAAa;EACrB,QAAQ,WAAW;EACnB,QAAQ,aAAa;EAErB,KAAK,QAAQ,IAAI,MAAM,mBAAmB;GAAE;GAAM;GAAO,GAAG;EAAQ,CAAC,CAAC;CACvE;CAEA,OAAO,MAAc,SAAkC;EAItD,YAAY,CAAC;EACb,QAAQ,aAAa;EACrB,QAAQ,WAAW;EACnB,QAAQ,aAAa;EACrB,QAAQ,0BAAU,IAAI,KAAK,CAAC;EAE5B,KAAK,QAAQ,IAAI,MAAM,mBAAmB;GAAE;GAAM,OAAO;GAAI,GAAG;EAAQ,CAAC,CAAC;CAC3E;AACD;;;AC7CA,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,IAAI;CAEvC,YAAY,SAAkB;EAC7B,KAAK,UAAU;CAChB;CAEA,IAAI,MAAkC;EAErC,IAAI,KAAK,QAAQ,IAAI,IAAI,GACxB,OAAO,KAAK,QAAQ,IAAI,IAAI;EAG7B,OAAO,KAAK,QAAQ,QAAQ,IAAI,IAAI,KAAK,KAAA;CAC1C;CAEA,IAAI,MAAc,OAAqB;EACtC,KAAK,QAAQ,IAAI,MAAM,KAAK;CAC7B;CAEA,OAAO,MAAoB;EAC1B,KAAK,QAAQ,OAAO,IAAI;CACzB;AACD;;;ACrBA,IAAqB,cAArB,MAAiC;CAChC;CACA;;;;;;CAMA;CAEA;CAEA;CAEA;CACA;CAIA;;CAGA,IAAI,MAAW;EACd,OAAQ,KAAKA,SAAS,IAAI,IAAI,KAAK,QAAQ,GAAG;CAC/C;CAEA,YAAY,SAAkB,QAAiC,KAAW;EACzE,KAAK,UAAU;EACf,KAAK,SAAS;EACd,KAAKA,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,OAAO;EACvC,KAAK,UAAU,IAAI,aAAa,OAAO;EAIvC,KAAK,UAAU,WAAW;CAC3B;CAEA,aAAmB;EAClB,IAAI,CAAC,KAAK,UACT,MAAM,IAAI,MAAM,0BAA0B;EAG3C,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,OAAO,GAC9C,KAAK,SAAS,QAAQ,OAAO,cAAc,MAAM;EAGlD,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAC/C,KAAK,SAAS,QAAQ,OAAO,OAAO,IAAI,OAAO,EAAE;CAEnD;;;;CAKA,OAAyB;EACxB,OAAO,KAAK,QAAQ,KAAK;CAC1B;AACD"}
@@ -0,0 +1,91 @@
1
+ import { n as HeaderHelper, r as CookieHelper } from "./ServerEvent-CTx3Q-hk.mjs";
2
+ import { a as RouteParamsOf } from "./ParseRouteParams-DBmqlmLh.mjs";
3
+ //#region src/types/ServerLoadEvent.d.ts
4
+ /**
5
+ * The values read from a form submission: one value per field, or an array
6
+ * when a field was submitted with multiple values (e.g. a multi select).
7
+ */
8
+ type FormDataRecord = Record<string, FormDataEntryValue | FormDataEntryValue[]>;
9
+ /**
10
+ * The values read from a URL's query string: one string per param, or an
11
+ * array when a param was repeated.
12
+ */
13
+ type QueryRecord = Record<string, string | string[]>;
14
+ /**
15
+ * The event passed to server functions. Annotate with a route path to get
16
+ * typed params, e.g. `ServerLoadEvent<"/posts/[id]">`, and with a body type
17
+ * to get typed request bodies in API endpoints, e.g.
18
+ * `ServerLoadEvent<"/api/posts", { title: string }>` — which also types the
19
+ * `body` param of client calls made with `makeApi`.
20
+ */
21
+ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = unknown, FormBody = FormDataRecord, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> {
22
+ /**
23
+ * The URL for the server function.
24
+ */
25
+ url: URL;
26
+ /**
27
+ * Route params from the URL and route path. When the endpoint declares a
28
+ * `params` schema, the values are validated and typed by the schema's
29
+ * output.
30
+ */
31
+ params: Params;
32
+ /**
33
+ * Data that is available to functions in +server hooks, layouts, endpoints
34
+ * and pages. It flows down in that order.
35
+ */
36
+ appData: Record<string, any>;
37
+ /**
38
+ * The server request.
39
+ */
40
+ request: Request;
41
+ /**
42
+ * Reads the request body as JSON, typed by the event's `Body` annotation.
43
+ */
44
+ json: () => Promise<Body>;
45
+ /**
46
+ * Reads the request body as form data, returning a record of field values.
47
+ * When the endpoint declares a schema for the form, the values are
48
+ * validated and typed by the schema's output.
49
+ */
50
+ form: () => Promise<FormBody>;
51
+ /**
52
+ * Reads the URL's query string, returning a record of param values. When
53
+ * the endpoint declares a schema for the query (get/head handlers and the
54
+ * load function), the values are validated and typed by the schema's
55
+ * output.
56
+ */
57
+ query: () => Promise<QueryBody>;
58
+ /**
59
+ * A helper for getting and setting cookie data.
60
+ */
61
+ cookies: CookieHelper;
62
+ /**
63
+ * A helper for getting and setting headers.
64
+ */
65
+ headers: HeaderHelper;
66
+ /**
67
+ * An optional adapter object, containing adapter-specific functionality.
68
+ */
69
+ adapter: Record<PropertyKey, any>;
70
+ }
71
+ //#endregion
72
+ //#region src/types/ServerHook.d.ts
73
+ /**
74
+ * For _hook.server.
75
+ */
76
+ interface ServerHook<Route extends string | undefined = undefined> {
77
+ /**
78
+ * Called before each server request is handled. Return a Response to
79
+ * short-circuit the request, skipping the load, action or view rendering
80
+ * (e.g. a redirect for unauthenticated users).
81
+ */
82
+ enter?: (event: ServerLoadEvent<Route>) => Promise<Response | void> | Response | void;
83
+ /**
84
+ * Called after the request has been handled, even if the handler threw
85
+ * an error or the enter hook short-circuited it.
86
+ */
87
+ exit?: (event: ServerLoadEvent<Route>) => Promise<void> | void;
88
+ }
89
+ //#endregion
90
+ export { ServerLoadEvent as i, FormDataRecord as n, QueryRecord as r, ServerHook as t };
91
+ //# sourceMappingURL=ServerHook-BlLArueW.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerHook-BlLArueW.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts","../src/types/ServerHook.ts"],"mappings":";;;;;;;KAQY,iBAAiB,eAAe,qBAAqB;;;;;KAMrD,cAAc;;;;;;;;UASD,gBACxB,8CACA,gBACA,WAAW,gBACX,YAAY,aACZ,SAAS,cAAc;;;;EAKvB,KAAK;;;;;;EAML,QAAQ;;;;;EAOR,SAAS;;;;EAIT,SAAS;;;;EAKT,YAAY,QAAQ;;;;;;EAMpB,YAAY,QAAQ;;;;;;;EAOpB,aAAa,QAAQ;;;;EAIrB,SAAS;;;;EAIT,SAAS;;;;EAIT,SAAS,OAAO;;;;;;;UC3EQ,WAAW;;;;;;EAMnC,SAAS,OAAO,gBAAgB,WAAW,QAAQ,mBAAmB;;;;;EAKtE,QAAQ,OAAO,gBAAgB,WAAW"}
@@ -1,97 +1,10 @@
1
- import { n as HeaderHelper, r as CookieHelper } from "./ServerEvent-CTx3Q-hk.mjs";
2
1
  import { t as Server } from "./Server-Cler2w5O.mjs";
3
2
  import { a as RouteParamsOf, n as ParseRouteParams, t as ExactRouteParams } from "./ParseRouteParams-DBmqlmLh.mjs";
3
+ import { i as ServerLoadEvent, n as FormDataRecord, r as QueryRecord, t as ServerHook } from "./ServerHook-BlLArueW.mjs";
4
4
  import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
5
5
  import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
6
6
  import { Component } from "@torpor/view";
7
7
  import { Plugin, UserConfig } from "vite";
8
- //#region src/types/ServerLoadEvent.d.ts
9
- /**
10
- * The values read from a form submission: one value per field, or an array
11
- * when a field was submitted with multiple values (e.g. a multi select).
12
- */
13
- type FormDataRecord = Record<string, FormDataEntryValue | FormDataEntryValue[]>;
14
- /**
15
- * The values read from a URL's query string: one string per param, or an
16
- * array when a param was repeated.
17
- */
18
- type QueryRecord = Record<string, string | string[]>;
19
- /**
20
- * The event passed to server functions. Annotate with a route path to get
21
- * typed params, e.g. `ServerLoadEvent<"/posts/[id]">`, and with a body type
22
- * to get typed request bodies in API endpoints, e.g.
23
- * `ServerLoadEvent<"/api/posts", { title: string }>` — which also types the
24
- * `body` param of client calls made with `makeApi`.
25
- */
26
- interface ServerLoadEvent<Route extends string | undefined = undefined, Body = unknown, FormBody = FormDataRecord, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> {
27
- /**
28
- * The URL for the server function.
29
- */
30
- url: URL;
31
- /**
32
- * Route params from the URL and route path. When the endpoint declares a
33
- * `params` schema, the values are validated and typed by the schema's
34
- * output.
35
- */
36
- params: Params;
37
- /**
38
- * Data that is available to functions in +server hooks, layouts, endpoints
39
- * and pages. It flows down in that order.
40
- */
41
- appData: Record<string, any>;
42
- /**
43
- * The server request.
44
- */
45
- request: Request;
46
- /**
47
- * Reads the request body as JSON, typed by the event's `Body` annotation.
48
- */
49
- json: () => Promise<Body>;
50
- /**
51
- * Reads the request body as form data, returning a record of field values.
52
- * When the endpoint declares a schema for the form, the values are
53
- * validated and typed by the schema's output.
54
- */
55
- form: () => Promise<FormBody>;
56
- /**
57
- * Reads the URL's query string, returning a record of param values. When
58
- * the endpoint declares a schema for the query (get/head handlers and the
59
- * load function), the values are validated and typed by the schema's
60
- * output.
61
- */
62
- query: () => Promise<QueryBody>;
63
- /**
64
- * A helper for getting and setting cookie data.
65
- */
66
- cookies: CookieHelper;
67
- /**
68
- * A helper for getting and setting headers.
69
- */
70
- headers: HeaderHelper;
71
- /**
72
- * An optional adapter object, containing adapter-specific functionality.
73
- */
74
- adapter: Record<PropertyKey, any>;
75
- }
76
- //#endregion
77
- //#region src/types/ServerHook.d.ts
78
- /**
79
- * For _hook.server.
80
- */
81
- interface ServerHook<Route extends string | undefined = undefined> {
82
- /**
83
- * Called before each server request is handled. Return a Response to
84
- * short-circuit the request, skipping the load, action or view rendering
85
- * (e.g. a redirect for unauthenticated users).
86
- */
87
- enter?: (event: ServerLoadEvent<Route>) => Promise<Response | void> | Response | void;
88
- /**
89
- * Called after the request has been handled, even if the handler threw
90
- * an error or the enter hook short-circuited it.
91
- */
92
- exit?: (event: ServerLoadEvent<Route>) => Promise<void> | void;
93
- }
94
- //#endregion
95
8
  //#region src/types/Adapter.d.ts
96
9
  interface Adapter {
97
10
  prebuild?: (site: Site) => Promise<void> | void;
@@ -107,7 +20,7 @@ interface Adapter {
107
20
  * Serve the built output (preview). Receives a torpor Server configured to
108
21
  * load the built server entry.
109
22
  */
110
- serve: (server: Server, site: Site) => void;
23
+ serve: (server: Server, site: Site) => void | Promise<void>;
111
24
  }
112
25
  //#endregion
113
26
  //#region src/types/SitePlugin.d.ts
@@ -448,6 +361,14 @@ declare class Site {
448
361
  * Vite plugins to add to the client and server builds
449
362
  */
450
363
  vitePlugins: Plugin[];
364
+ /**
365
+ * The site's adapter, e.g. from `@torpor/adapter-node` or
366
+ * `@torpor/adapter-cloudflare`. When not set, one is resolved when it's
367
+ * needed: a deployment environment (e.g. `CF_PAGES`) picks the platform's
368
+ * adapter when installed, an installed adapter is used otherwise, and
369
+ * preview falls back to serving on the current runtime. See
370
+ * defaultAdapter.ts
371
+ */
451
372
  adapter: Adapter;
452
373
  /**
453
374
  * Extra inputs, as absolute file paths, that will be compiled with the
@@ -562,5 +483,5 @@ declare class Site {
562
483
  }, subFolder?: string): void;
563
484
  }
564
485
  //#endregion
565
- export { ServerLoadEvent as C, QueryRecord as S, PageLoadEvent as _, ServerEndPoint as a, ServerHook as b, ActionBody as c, PageServerActionSchemas as d, PageServerEndPoint as f, PageLoadReturn as g, PageEndPoint as h, SchemaQuery as i, LoadParams as l, PageServerAction as m, ParamsOf as n, ServerEndPointSchemas as o, PageServerLoad as p, SchemaBody as r, ServerRequest as s, Site as t, LoadQuery as u, SitePlugin as v, FormDataRecord as x, Adapter as y };
566
- //# sourceMappingURL=Site-CE0_o5Ci.d.mts.map
486
+ export { PageLoadEvent as _, ServerEndPoint as a, ActionBody as c, PageServerActionSchemas as d, PageServerEndPoint as f, PageLoadReturn as g, PageEndPoint as h, SchemaQuery as i, LoadParams as l, PageServerAction as m, ParamsOf as n, ServerEndPointSchemas as o, PageServerLoad as p, SchemaBody as r, ServerRequest as s, Site as t, LoadQuery as u, SitePlugin as v, Adapter as y };
487
+ //# sourceMappingURL=Site-CTADVh7d.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Site-CTADVh7d.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageLoadEvent.ts","../src/types/PageLoadReturn.ts","../src/types/PageEndPoint.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/site/Site.ts"],"mappings":";;;;;;;;UAIyB;EACxB,YAAY,MAAM,SAAS;EAC3B,aAAa,MAAM,SAAS;;;;;;;EAO5B,OAAO,MAAM,SAAS,SAAS;;;;;EAK/B,QAAQ,QAAQ,QAAQ,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;KCG1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;;;;;KCRE,iBAAiB,qBAAqB,iBAAiB,aAAa;;;;UAKvD;EACxB;;;;;EAKA;;;;;;EAMA,WAAW;EACX,MAAM;EACN;;;;;;;;cCIoB;;EACpB;EACA,QAAQ;;;;;;;EAOR,SAAS;;;;EAIT,aAAa;;;;;;;;;EASb,SAAS;;;;;;EAMT;;;;;;;EAOA,aAAa;;;;;EAKb;;;;;;;;;;;;;;;;EAgBA,aAAa,IAAI;;;;;EAKjB,iBAAiB,eAAe;EAEhC;;;;;;;;;EAYA,eAAqB,gBAAgB,qBAAqB;;;;;;;;EAiC1D,aACC,cACA,cACA,kHASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+HD,SACC,cACA;IACC;IACA,sBAAsB;IACtB,kBAAkB;IAClB;IACA,wBAAwB;IACxB,sBAAsB;IACtB;KAED"}
package/dist/bin/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env node
2
- import { n as loadSite, r as run, t as runOpenApi } from "../runOpenApi-C8eI2Fh0.mjs";
2
+ import { n as loadSite, r as run, t as runOpenApi } from "../runOpenApi-yIzYasNN.mjs";
3
3
  //#region src/bin/index.ts
4
4
  const workingDir = process.cwd();
5
5
  if (process.argv.includes("--openapi")) {
@@ -1,6 +1,6 @@
1
1
  import { t as Router } from "./Router-C4ADUfhv.mjs";
2
2
  import { t as $page } from "./_page-4cQKs_Dn.mjs";
3
- import { a as client, n as navigate, r as loadData } from "./load-BntzvmwL.mjs";
3
+ import { a as client, n as navigate, r as loadData } from "./load-C9RpS_4j.mjs";
4
4
  import manifest from "@torpor/build/manifest";
5
5
  //#region src/site/clientEntry.ts
6
6
  const router = new Router();
@@ -32,7 +32,8 @@ async function maybePrefetch(e) {
32
32
  const handler = route.handler;
33
33
  const params = route.params || {};
34
34
  const clientEndPoint = (await handler.endPoint()).default;
35
- await loadData(handler, params, path, query, [], clientEndPoint, handler.serverEndPoint && (await handler.serverEndPoint())?.default, true);
35
+ const serverEndPoint = handler.serverEndPoint && (await handler.serverEndPoint())?.default;
36
+ await loadData(handler, params, path, query, [], clientEndPoint, serverEndPoint, true);
36
37
  }
37
38
  }
38
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/site/clientEntry.ts"],"sourcesContent":["import manifest from \"@torpor/build/manifest\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport Router from \"./Router.ts\";\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tif (await navigate(url)) {\n\t\t\twindow.history.pushState(null, \"\", url);\n\t\t} else {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n\nasync function maybePrefetch(e: MouseEvent | TouchEvent) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\t// There should be a client endpoint\n\t\t\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\n\t\t\t// There may be a server endpoint\n\t\t\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\t\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\t\t\t// Just dummy this up\n\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, serverEndPoint, true);\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: MouseEvent | TouchEvent) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\treturn (\n\t\te.defaultPrevented ||\n\t\te.altKey ||\n\t\te.ctrlKey ||\n\t\te.metaKey ||\n\t\te.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tawait navigateToLocation(document.location);\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(location: Location, firstTime = false) {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;AAWA,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAGhB,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,EAAE,eAAe;EAEjB,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,IAAI,MAAM,SAAS,GAAG,GACrB,OAAO,QAAQ,UAAU,MAAM,IAAI,GAAG;OAEtC,OAAO,SAAS,OAAO;CAEzB;AACD,CAAC;AAID,OAAO,iBAAiB,aAAa,aAAa;AAClD,OAAO,iBAAiB,cAAc,aAAa;AAEnD,eAAe,cAAc,GAA4B;CACxD,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,MAAM,OAAO,IAAI;EACjB,MAAM,QAAQ,IAAI;EAClB,MAAM,QAAQ,OAAO,MAAM,MAAM,KAAK;EACtC,IAAI,OAAO;GACV,MAAM,UAAU,MAAM;GACtB,MAAM,SAAS,MAAM,UAAU,CAAC;GAGhC,MAAM,kBAA4C,MAAM,QAAQ,SAAS,EAAA,CAAG;GAS5E,MAAM,SAAS,SAAS,QAAQ,MAAM,OAAO,CAAO,GAAG,gBALtD,QAAQ,mBAAmB,MAAM,QAAQ,eAAe,EAAA,EAAI,SAK0B,IAAI;EAC5F;CACD;AACD;AAEA,SAAS,QAAQ,QAA2D;CAI3E,IAAI,EAAE,kBAAkB,UAAU;CAClC,MAAM,OAAO,OAAO,QAAQ,SAAS;CACrC,IAAI,MAAM,aAAa,MAAM,CAAC,EAAE,WAAW,GAAG,GAAG;CACjD,OAAQ,QAA8B,KAAA;AACvC;AAEA,SAAS,uBAAuB,MAAyB,GAA4B;CAKpF,OACC,EAAE,oBACF,EAAE,UACF,EAAE,WACF,EAAE,WACF,EAAE,YACD,KAAK,UAAU,KAAK,WAAW,WAChC,KAAK,QAAQ,cACb,KAAK,aAAa,UAAU,KAC5B,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAC/C,MAAM,mBAAmB,SAAS,QAAQ;AAC3C,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBAAmB,UAAoB,YAAY,OAAO;CAGxE,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
1
+ {"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/site/clientEntry.ts"],"sourcesContent":["import manifest from \"@torpor/build/manifest\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport Router from \"./Router.ts\";\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tif (await navigate(url)) {\n\t\t\twindow.history.pushState(null, \"\", url);\n\t\t} else {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n\nasync function maybePrefetch(e: MouseEvent | TouchEvent) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\t// There should be a client endpoint\n\t\t\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\n\t\t\t// There may be a server endpoint\n\t\t\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\t\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\t\t\t// Just dummy this up\n\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, serverEndPoint, true);\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: MouseEvent | TouchEvent) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\treturn (\n\t\te.defaultPrevented ||\n\t\te.altKey ||\n\t\te.ctrlKey ||\n\t\te.metaKey ||\n\t\te.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tawait navigateToLocation(document.location);\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(location: Location, firstTime = false) {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;AAWA,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAGhB,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,EAAE,eAAe;EAEjB,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,IAAI,MAAM,SAAS,GAAG,GACrB,OAAO,QAAQ,UAAU,MAAM,IAAI,GAAG;OAEtC,OAAO,SAAS,OAAO;CAEzB;AACD,CAAC;AAID,OAAO,iBAAiB,aAAa,aAAa;AAClD,OAAO,iBAAiB,cAAc,aAAa;AAEnD,eAAe,cAAc,GAA4B;CACxD,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,MAAM,OAAO,IAAI;EACjB,MAAM,QAAQ,IAAI;EAClB,MAAM,QAAQ,OAAO,MAAM,MAAM,KAAK;EACtC,IAAI,OAAO;GACV,MAAM,UAAU,MAAM;GACtB,MAAM,SAAS,MAAM,UAAU,CAAC;GAGhC,MAAM,kBAA4C,MAAM,QAAQ,SAAS,EAAA,CAAG;GAG5E,MAAM,iBACL,QAAQ,mBAAmB,MAAM,QAAQ,eAAe,EAAA,EAAI;GAK7D,MAAM,SAAS,SAAS,QAAQ,MAAM,OAAO,CAAO,GAAG,gBAAgB,gBAAgB,IAAI;EAC5F;CACD;AACD;AAEA,SAAS,QAAQ,QAA2D;CAI3E,IAAI,EAAE,kBAAkB,UAAU;CAClC,MAAM,OAAO,OAAO,QAAQ,SAAS;CACrC,IAAI,MAAM,aAAa,MAAM,CAAC,EAAE,WAAW,GAAG,GAAG;CACjD,OAAQ,QAA8B,KAAA;AACvC;AAEA,SAAS,uBAAuB,MAAyB,GAA4B;CAKpF,OACC,EAAE,oBACF,EAAE,UACF,EAAE,WACF,EAAE,WACF,EAAE,YACD,KAAK,UAAU,KAAK,WAAW,WAChC,KAAK,QAAQ,cACb,KAAK,aAAa,UAAU,KAC5B,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAC/C,MAAM,mBAAmB,SAAS,QAAQ;AAC3C,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBAAmB,UAAoB,YAAY,OAAO;CAGxE,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
package/dist/dev.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as Server } from "./Server-Cler2w5O.mjs";
2
- import { t as load } from "./serverEntry-BAO8m03V.mjs";
2
+ import { t as load } from "./serverEntry-DVv9YI3I.mjs";
3
3
  export { Server, load };
package/dist/dev.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as Server } from "./Server-BnjLJleZ.mjs";
2
- import { t as load } from "./serverEntry-1qY3wZig.mjs";
1
+ import { t as Server } from "./Server-Dr6yqVa5.mjs";
2
+ import { t as load } from "./serverEntry-LyB5pl0E.mjs";
3
3
  export { Server, load };
package/dist/index.d.mts CHANGED
@@ -1,64 +1,10 @@
1
+ import { t as Router } from "./Router-COdQuVUi.mjs";
1
2
  import { a as RouteParamsOf, i as RouteArgsOf, n as ParseRouteParams, r as RouteArgs } from "./ParseRouteParams-DBmqlmLh.mjs";
2
- import { C as ServerLoadEvent, S as QueryRecord, _ as PageLoadEvent, a as ServerEndPoint, b as ServerHook, c as ActionBody, d as PageServerActionSchemas, f as PageServerEndPoint, g as PageLoadReturn, h as PageEndPoint, i as SchemaQuery, l as LoadParams, m as PageServerAction, n as ParamsOf, o as ServerEndPointSchemas, p as PageServerLoad, r as SchemaBody, s as ServerRequest, t as Site, u as LoadQuery, v as SitePlugin, x as FormDataRecord, y as Adapter } from "./Site-CE0_o5Ci.mjs";
3
+ import { i as ServerLoadEvent, n as FormDataRecord, r as QueryRecord, t as ServerHook } from "./ServerHook-BlLArueW.mjs";
4
+ import { _ as PageLoadEvent, a as ServerEndPoint, c as ActionBody, d as PageServerActionSchemas, f as PageServerEndPoint, g as PageLoadReturn, h as PageEndPoint, i as SchemaQuery, l as LoadParams, m as PageServerAction, n as ParamsOf, o as ServerEndPointSchemas, p as PageServerLoad, r as SchemaBody, s as ServerRequest, t as Site, u as LoadQuery, v as SitePlugin, y as Adapter } from "./Site-CTADVh7d.mjs";
3
5
  import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
4
6
  import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
5
7
  import { t as Jsonify } from "./Jsonify-Dg6gChd3.mjs";
6
- //#region src/types/ManifestRoute.d.ts
7
- interface ManifestRoute {
8
- path: string;
9
- type: number;
10
- endPoint: () => Promise<any>;
11
- subFolder: string | undefined;
12
- }
13
- //#endregion
14
- //#region src/types/RouteLayoutHandler.d.ts
15
- interface RouteLayoutHandler {
16
- path: string;
17
- endPoint: () => Promise<any>;
18
- serverEndPoint?: () => Promise<any>;
19
- }
20
- //#endregion
21
- //#region src/types/RouteHandler.d.ts
22
- /**
23
- * A handler for a route in the Router.
24
- */
25
- interface RouteHandler {
26
- path: string;
27
- type: number;
28
- endPoint: () => Promise<any>;
29
- subFolder?: string;
30
- loaded?: boolean;
31
- layouts?: RouteLayoutHandler[];
32
- serverEndPoint?: () => Promise<any>;
33
- serverHooks?: (() => Promise<any>)[];
34
- modulePromise?: Promise<any>;
35
- resolvedModule?: any;
36
- resolvedHooks?: Promise<ServerHook[]>;
37
- }
38
- //#endregion
39
- //#region src/site/Router.d.ts
40
- /**
41
- * A router that handles file routes with layouts, hooks, etc.
42
- */
43
- declare class Router {
44
- #private;
45
- routes: Route[];
46
- constructor();
47
- addPages(routes: ManifestRoute[]): this;
48
- addPage(path: string, type: number, endPoint: () => Promise<any>, subFolder?: string): this;
49
- match(path: string, query: URLSearchParams): RouteMatch | undefined;
50
- }
51
- declare class Route {
52
- path: string;
53
- handler: RouteHandler;
54
- constructor(path: string, handler: RouteHandler);
55
- }
56
- interface RouteMatch {
57
- handler: RouteHandler;
58
- params?: Record<string, string>;
59
- query: URLSearchParams;
60
- }
61
- //#endregion
62
8
  //#region src/types/PageData.d.ts
63
9
  /**
64
10
  * The page data produced by an endpoint's `load` function, e.g.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/ManifestRoute.ts","../src/types/RouteLayoutHandler.ts","../src/types/RouteHandler.ts","../src/site/Router.ts","../src/types/PageData.ts","../src/types/PageForm.ts","../src/types/PageProps.ts"],"mappings":";;;;;;UAAyB;EACxB;EACA;EACA,gBAAgB;EAChB;;;;UCJwB;EACxB;EACA,gBAAgB;EAChB,uBAAuB;;;;;;;UCGC;EACxB;EACA;EACA,gBAAgB;EAChB;EAEA;EACA,UAAU;EACV,uBAAuB;EACvB,qBAAqB;EAIrB,gBAAgB;EAChB;EACA,gBAAg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