@torpor/build 1.9.0 → 1.10.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.
- package/dist/{MiddlewareFunction-BZilnEei.d.mts → MiddlewareFunction-7rIvFkjl.d.mts} +7 -1
- package/dist/MiddlewareFunction-7rIvFkjl.d.mts.map +1 -0
- package/dist/{Router-By9Nlg39.d.mts → Router-Bxm7K20d.d.mts} +4 -4
- package/dist/Router-Bxm7K20d.d.mts.map +1 -0
- package/dist/{Server-dcRbdPXf.mjs → Server-Djd9-NkU.mjs} +2 -2
- package/dist/{Server-dcRbdPXf.mjs.map → Server-Djd9-NkU.mjs.map} +1 -1
- package/dist/{Server-qn5Ws_d0.d.mts → Server-hwbZ7P2g.d.mts} +2 -2
- package/dist/{Server-qn5Ws_d0.d.mts.map → Server-hwbZ7P2g.d.mts.map} +1 -1
- package/dist/{ServerEvent-BY4f3RVF.mjs → ServerEvent-L0rT_mBJ.mjs} +10 -1
- package/dist/{ServerEvent-BY4f3RVF.mjs.map → ServerEvent-L0rT_mBJ.mjs.map} +1 -1
- package/dist/{ServerHook-W111nEhe.d.mts → ServerHook-CyVEr5OL.d.mts} +2 -2
- package/dist/{ServerHook-W111nEhe.d.mts.map → ServerHook-CyVEr5OL.d.mts.map} +1 -1
- package/dist/{ServerLoadEvent-BH6oG1o6.d.mts → ServerLoadEvent-F60w1TZt.d.mts} +14 -4
- package/dist/ServerLoadEvent-F60w1TZt.d.mts.map +1 -0
- package/dist/{Site-DGZJB7Do.d.mts → Site-CAeAqjkk.d.mts} +192 -7
- package/dist/Site-CAeAqjkk.d.mts.map +1 -0
- package/dist/bin/index.js +37 -2
- package/dist/bin/index.js.map +1 -1
- package/dist/dev.d.mts +2 -2
- package/dist/dev.mjs +2 -2
- package/dist/{devPlugin-lLzauETn.mjs → devPlugin-D9b5uhzm.mjs} +2 -2
- package/dist/{devPlugin-lLzauETn.mjs.map → devPlugin-D9b5uhzm.mjs.map} +1 -1
- package/dist/discovery.d.mts +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/nav.d.mts +28 -2
- package/dist/nav.d.mts.map +1 -1
- package/dist/nav.mjs +37 -9
- package/dist/nav.mjs.map +1 -1
- package/dist/nodeDev.d.mts +1 -1
- package/dist/nodeDev.mjs +1 -1
- package/dist/openapi.d.mts +24 -80
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +36 -1
- package/dist/openapi.mjs.map +1 -0
- package/dist/{plugin-D8Www11B.mjs → plugin-BQsMnkTj.mjs} +42 -3
- package/dist/plugin-BQsMnkTj.mjs.map +1 -0
- package/dist/run.d.mts +1 -1
- package/dist/run.mjs +1 -1
- package/dist/{runOpenApi-C5yMpQU1.mjs → runOpenApi-BZ314IiI.mjs} +44 -21
- package/dist/runOpenApi-BZ314IiI.mjs.map +1 -0
- package/dist/server/Server.d.mts +1 -1
- package/dist/server/Server.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.mjs +2 -2
- package/dist/{serverEntry-D1hE-Jzt.mjs → serverEntry-8YnfpKTj.mjs} +2 -2
- package/dist/{serverEntry-D1hE-Jzt.mjs.map → serverEntry-8YnfpKTj.mjs.map} +1 -1
- package/dist/{serverEntry-BGii8bB6.d.mts → serverEntry-Da1PFlIU.d.mts} +3 -3
- package/dist/{serverEntry-BGii8bB6.d.mts.map → serverEntry-Da1PFlIU.d.mts.map} +1 -1
- package/dist/serverEntry.d.mts +1 -1
- package/dist/serverEntry.mjs +1 -1
- package/dist/{serverHandlers-CSBUEgJt.mjs → serverHandlers-Ba_35jpO.mjs} +38 -12
- package/dist/serverHandlers-Ba_35jpO.mjs.map +1 -0
- package/dist/{sitemap-xmE0zfme.d.mts → sitemap-CnIYTLhu.d.mts} +2 -2
- package/dist/{sitemap-xmE0zfme.d.mts.map → sitemap-CnIYTLhu.d.mts.map} +1 -1
- package/dist/test.d.mts +2 -2
- package/dist/test.mjs +2 -2
- package/package.json +10 -7
- package/dist/MiddlewareFunction-BZilnEei.d.mts.map +0 -1
- package/dist/Router-By9Nlg39.d.mts.map +0 -1
- package/dist/ServerLoadEvent-BH6oG1o6.d.mts.map +0 -1
- package/dist/Site-DGZJB7Do.d.mts.map +0 -1
- package/dist/plugin-D8Www11B.mjs.map +0 -1
- package/dist/runOpenApi-C5yMpQU1.mjs.map +0 -1
- package/dist/serverHandlers-CSBUEgJt.mjs.map +0 -1
|
@@ -24,6 +24,12 @@ declare class ServerEvent {
|
|
|
24
24
|
* Reads the request body as JSON.
|
|
25
25
|
*/
|
|
26
26
|
json(): Promise<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Reads the request body as the web standard FormData object. The body is
|
|
29
|
+
* parsed at most once per request, so that everything that reads the form
|
|
30
|
+
* (schema validation, `event.form()`, `event.formData()`) shares the read.
|
|
31
|
+
*/
|
|
32
|
+
formData(): Promise<FormData>;
|
|
27
33
|
}
|
|
28
34
|
//#endregion
|
|
29
35
|
//#region src/server/types/MiddlewareFunction.d.ts
|
|
@@ -47,4 +53,4 @@ type MiddlewareFunction = {
|
|
|
47
53
|
};
|
|
48
54
|
//#endregion
|
|
49
55
|
export { ServerEvent as n, MiddlewareFunction as t };
|
|
50
|
-
//# sourceMappingURL=MiddlewareFunction-
|
|
56
|
+
//# sourceMappingURL=MiddlewareFunction-7rIvFkjl.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareFunction-7rIvFkjl.d.mts","names":[],"sources":["../src/server/ServerEvent.ts","../src/server/types/MiddlewareFunction.ts"],"mappings":";;cAMqB;;EACpB,SAAS;EACT,UAAU;;;;;;EAMV;EAEA,SAAS;EAET;EAEA,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;;MAYH,OAAO;EAIX,YAAY,SAAS,SAAS,SAAS,wBAAwB,MAAM;EAcrE;;;;EA4CA,QAAQ;;;;;;EASR,YAAY,QAAQ;;;;KCxGhB;;;;;;EAMJ,SAAS,IAAI,gBAAgB,kBAAkB,QAAQ;;;;;;;;;;EAUvD,QAAQ,IAAI,gBAAgB,kBAAkB,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ServerHook } from "./ServerHook-
|
|
1
|
+
import { t as ServerHook } from "./ServerHook-CyVEr5OL.mjs";
|
|
2
2
|
//#region src/types/ManifestRoute.d.ts
|
|
3
3
|
interface ManifestRoute {
|
|
4
4
|
path: string;
|
|
@@ -27,9 +27,9 @@ interface RouteHandler {
|
|
|
27
27
|
layouts?: RouteLayoutHandler[];
|
|
28
28
|
serverEndPoint?: () => Promise<any>;
|
|
29
29
|
serverHooks?: (() => Promise<any>)[];
|
|
30
|
-
modulePromise?: Promise<any>;
|
|
31
30
|
resolvedModule?: any;
|
|
32
|
-
|
|
31
|
+
resolvedServerModule?: any;
|
|
32
|
+
resolvedHooks?: ServerHook[];
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/site/Router.d.ts
|
|
@@ -56,4 +56,4 @@ interface RouteMatch {
|
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
58
|
export { Router as t };
|
|
59
|
-
//# sourceMappingURL=Router-
|
|
59
|
+
//# sourceMappingURL=Router-Bxm7K20d.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router-Bxm7K20d.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;EAQrB;EACA;EACA,gBAAgB;;;;;;;cCjBI;;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-
|
|
2
|
+
import { t as ServerEvent } from "./ServerEvent-L0rT_mBJ.mjs";
|
|
3
3
|
import { t as runHooks } from "./runHooks-D5p1Rh7i.mjs";
|
|
4
4
|
//#region src/server/Server.ts
|
|
5
5
|
/**
|
|
@@ -83,4 +83,4 @@ var RouteHandler = class {
|
|
|
83
83
|
//#endregion
|
|
84
84
|
export { Server as t };
|
|
85
85
|
|
|
86
|
-
//# sourceMappingURL=Server-
|
|
86
|
+
//# sourceMappingURL=Server-Djd9-NkU.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server-
|
|
1
|
+
{"version":3,"file":"Server-Djd9-NkU.mjs","names":[],"sources":["../src/server/Server.ts"],"sourcesContent":["import PathTrie from \"../utils/pathTrie\";\nimport ServerEvent from \"./ServerEvent\";\nimport runHooks from \"./runHooks\";\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// Route-scoped middleware is set on server endpoints (or globally on\n\t\t\t// `site.middleware`); this list is the low-level, per-Server primitive\n\t\t\tconst { response, error } = await runHooks(\n\t\t\t\t[{ hooks: this.middleware, arg: ev }],\n\t\t\t\tasync (): Promise<Response | undefined> => {\n\t\t\t\t\tif (!match) return undefined;\n\t\t\t\t\treturn (await match.fn(ev)) || undefined;\n\t\t\t\t},\n\t\t\t\t{ event: ev },\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":";;;;;;;AASA,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,Q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7C,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ServerEvent, t as MiddlewareFunction } from "./MiddlewareFunction-
|
|
1
|
+
import { n as ServerEvent, t as MiddlewareFunction } from "./MiddlewareFunction-7rIvFkjl.mjs";
|
|
2
2
|
//#region src/server/types/ServerFunction.d.ts
|
|
3
3
|
type ServerFunction = (e: ServerEvent) => Response | undefined | void | Promise<Response | undefined | void>;
|
|
4
4
|
//#endregion
|
|
@@ -38,4 +38,4 @@ interface Match {
|
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
export { Server as t };
|
|
41
|
-
//# sourceMappingURL=Server-
|
|
41
|
+
//# sourceMappingURL=Server-hwbZ7P2g.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server-
|
|
1
|
+
{"version":3,"file":"Server-hwbZ7P2g.d.mts","names":[],"sources":["../src/server/types/ServerFunction.ts","../src/server/Server.ts"],"mappings":";;KAEK,kBACJ,GAAG,gBACC,8BAA8B,QAAQ;;;;;;cCKtB;;EAEpB,QAAQ;EAIR,YAAY;EAEZ;;;;;;EAUA,QAAe,OAAO,cAAc,KAAK,OAAO,gBAAc,QAAQ;;;;;;;EAyCtE,IAAI,cAAc,IAAI,iBAAiB;EAQvC,MAAM,eAAe;EAarB,OAAO,IAAI,uBAAuB;;cAyB7B;EACL;EACA,IAAI;EAEJ,YAAY,cAAc,IAAI;;UAkBrB;EACT,IAAI;EACJ,SAAS"}
|
|
@@ -295,6 +295,7 @@ var ServerEvent = class {
|
|
|
295
295
|
session;
|
|
296
296
|
flash;
|
|
297
297
|
#url;
|
|
298
|
+
#formData;
|
|
298
299
|
/** The request URL, parsed lazily. */
|
|
299
300
|
get url() {
|
|
300
301
|
return this.#url ??= new URL(this.request.url);
|
|
@@ -337,8 +338,16 @@ var ServerEvent = class {
|
|
|
337
338
|
json() {
|
|
338
339
|
return this.request.json();
|
|
339
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Reads the request body as the web standard FormData object. The body is
|
|
343
|
+
* parsed at most once per request, so that everything that reads the form
|
|
344
|
+
* (schema validation, `event.form()`, `event.formData()`) shares the read.
|
|
345
|
+
*/
|
|
346
|
+
formData() {
|
|
347
|
+
return this.#formData ??= this.request.formData();
|
|
348
|
+
}
|
|
340
349
|
};
|
|
341
350
|
//#endregion
|
|
342
351
|
export { HeaderHelper as n, CookieHelper as r, ServerEvent as t };
|
|
343
352
|
|
|
344
|
-
//# sourceMappingURL=ServerEvent-
|
|
353
|
+
//# sourceMappingURL=ServerEvent-L0rT_mBJ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerEvent-BY4f3RVF.mjs","names":["COOKIE_NAME"],"sources":["../src/server/CookieHelper.ts","../src/server/FlashHelper.ts","../src/server/HeaderHelper.ts","../src/server/SessionHelper.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","import CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-flash\";\n\n/**\n * A one-time values store set in a form action and shown on the next page\n * render, which survives the redirect. Available as `event.flash`; the\n * framework reads it into `$page.flash` when a page is rendered, so\n * components display it reactively:\n *\n * ```ts\n * actions: {\n * \tsave: async (event) => {\n * \t\t// ...save...\n * \t\tevent.flash.set(\"Project saved\"); // { message: \"Project saved\" }\n * \t\tevent.flash.set({ error: \"Import failed\", retryable: true });\n * \t\treturn seeOther(`/projects/${id}`);\n * \t},\n * }\n * ```\n *\n * ```torp\n * @if ($page.flash?.message) {\n * \t<p class=\"flash\">{$page.flash.message}</p>\n * }\n * ```\n *\n * The values ride in a (session-lifetime) cookie that is deleted when it is\n * read, so a page refresh shows them once. No signing: the only person who\n * can fake a flash is the one seeing it, and values are rendered as text.\n * They must be JSON-safe and small enough to fit in the cookie (~4KB). A\n * common shape for a styled banner is `{ type, message }`, for use e.g.\n * with the Notification component -- but the framework only requires the\n * values to be an object. Without cookies the message is simply lost --\n * the action itself still completes.\n */\nexport default class FlashHelper {\n\t#cookies: CookieHelper;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * Reads the flash values, if any, and clears them: the same response\n\t * deletes the cookie, so the message shows exactly once. (When the\n\t * message was set during this same request, e.g. a form action that\n\t * re-renders instead of redirecting, the cookie is consumed without it\n\t * ever reaching the browser.)\n\t */\n\tget(): Record<string, unknown> | undefined {\n\t\tconst cookie = this.#cookies.get(COOKIE_NAME);\n\t\tif (!cookie) return undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t\ttry {\n\t\t\tconst decoded = JSON.parse(decodeURIComponent(cookie));\n\t\t\tif (typeof decoded !== \"object\" || decoded === null || Array.isArray(decoded)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn decoded as Record<string, unknown>;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Sets the flash values. A string is stored as `{ message: value }`, an\n\t * object as-is, e.g. `flash.set({ error: \"Import failed\" })`.\n\t */\n\tset(value: string | Record<string, unknown>): void {\n\t\tconst data = typeof value === \"string\" ? { message: value } : value;\n\t\tthis.#cookies.set(COOKIE_NAME, encodeURIComponent(JSON.stringify(data)), { path: \"/\" });\n\t}\n\n\t/**\n\t * Clears an unread flash message, e.g. so it isn't shown on a later\n\t * re-render of the same page.\n\t */\n\tclear(): void {\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\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 env from \"../env\";\nimport CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-session\";\nconst DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days, in seconds\n\n/**\n * The data stored in the session. Must be JSON-safe, and small enough to\n * fit in a cookie (4KB) along with the id, expiry and signature.\n */\ntype SessionData = Record<string, unknown>;\n\ntype SessionPayload = {\n\tid: string;\n\tdata: SessionData;\n\t/** Expiry, as a Unix epoch in milliseconds */\n\texp: number;\n};\n\n// The imported signing key, cached per secret so repeated calls (per\n// request) don't re-import\nconst keys = new Map<string, Promise<CryptoKey>>();\n\n/**\n * A helper for reading and writing the signed session cookie, available as\n * `event.session` in load functions, actions, +server endpoints and hooks.\n *\n * The value is signed with HMAC-SHA256 using `TORPOR_SESSION_SECRET` from\n * the environment, so it can't be forged or tampered with -- but it is\n * still client-side storage: everything rides in the cookie, it can't be\n * revoked individually, and it is limited to ~4KB. When you need\n * revocation, store `session.id` in your database, check it on each\n * authed request (e.g. in a `_hook.server.ts`), and delete the row to\n * revoke.\n *\n * ```ts\n * // Login action\n * const user = await checkPassword(event.form());\n * await event.session.regenerate({ userId: user.id });\n *\n * // Root hook\n * const session = await event.session.get();\n * if (session) {\n * \tevent.appData.user = await getUser(session.userId);\n * }\n * ```\n */\nexport default class SessionHelper {\n\t#cookies: CookieHelper;\n\t#id: string | undefined;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * The id embedded in the current session cookie, or undefined when\n\t * there is no valid session. Stable across `set` calls, so it can be\n\t * used as a database key; `regenerate` mints a new one.\n\t */\n\tget id(): string | undefined {\n\t\treturn this.#id;\n\t}\n\n\t/**\n\t * Reads and verifies the session, returning its data, or undefined when\n\t * there is no cookie, the signature doesn't match, or the session has\n\t * expired.\n\t */\n\tasync get(): Promise<SessionData | undefined> {\n\t\tconst value = this.#cookies.get(COOKIE_NAME);\n\t\tif (!value) return undefined;\n\t\tconst payload = await verifyValue(value);\n\t\tif (!payload) return undefined;\n\t\tthis.#id = payload.id;\n\t\treturn payload.data;\n\t}\n\n\t/**\n\t * Writes the session, signing the data and setting the cookie. Keeps\n\t * the current session id, minting one when there isn't a valid session\n\t * yet. Call `regenerate` instead when the session's identity should\n\t * change (e.g. at login, to prevent session fixation).\n\t */\n\tasync set(data: SessionData, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = this.#id ?? crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Writes the session with a fresh id, replacing any existing one. Use\n\t * it when a session's privilege level changes (login, permission\n\t * upgrade), so a cookie that was set before the change can't be reused.\n\t */\n\tasync regenerate(data: SessionData = {}, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Deletes the session cookie. Note that a server-side record (if you\n\t * keep one) must be deleted or revoked separately.\n\t */\n\tasync destroy(): Promise<void> {\n\t\tthis.#id = undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t}\n\n\tasync #write(\n\t\tid: string,\n\t\tdata: SessionData,\n\t\toptions: { maxAge?: number } | undefined,\n\t): Promise<void> {\n\t\tconst maxAge = options?.maxAge ?? DEFAULT_MAX_AGE;\n\t\tconst payload: SessionPayload = { id, data, exp: Date.now() + maxAge * 1000 };\n\t\tconst encoded = encodeBase64Url(new TextEncoder().encode(JSON.stringify(payload)));\n\t\tconst signature = await sign(encoded);\n\t\tthis.#cookies.set(COOKIE_NAME, `${encoded}.${signature}`, { path: \"/\", maxAge });\n\t}\n}\n\nfunction secret(): string {\n\tconst value = env().TORPOR_SESSION_SECRET;\n\tif (!value) {\n\t\tthrow new Error(\n\t\t\t\"TORPOR_SESSION_SECRET is not set. Add it to the environment (or to a .env \" +\n\t\t\t\t\"file in dev and preview) to use sessions.\",\n\t\t);\n\t}\n\treturn value;\n}\n\nfunction signingKey(): Promise<CryptoKey> {\n\tconst value = secret();\n\tlet key = keys.get(value);\n\tif (!key) {\n\t\tkey = crypto.subtle.importKey(\n\t\t\t\"raw\",\n\t\t\tnew TextEncoder().encode(value),\n\t\t\t{ name: \"HMAC\", hash: \"SHA-256\" },\n\t\t\tfalse,\n\t\t\t[\"sign\", \"verify\"],\n\t\t);\n\t\tkeys.set(value, key);\n\t}\n\treturn key;\n}\n\nasync function sign(payload: string): Promise<string> {\n\tconst signature = await crypto.subtle.sign(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tnew TextEncoder().encode(payload),\n\t);\n\treturn encodeBase64Url(new Uint8Array(signature));\n}\n\nasync function verifyValue(value: string): Promise<SessionPayload | undefined> {\n\tconst dot = value.lastIndexOf(\".\");\n\tif (dot === -1) return undefined;\n\tconst encoded = value.slice(0, dot);\n\tconst valid = await crypto.subtle.verify(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tdecodeBase64Url(value.slice(dot + 1)),\n\t\tnew TextEncoder().encode(encoded),\n\t);\n\tif (!valid) return undefined;\n\n\tlet payload: SessionPayload;\n\ttry {\n\t\tpayload = JSON.parse(new TextDecoder().decode(decodeBase64Url(encoded)));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (\n\t\ttypeof payload?.id !== \"string\" ||\n\t\ttypeof payload?.exp !== \"number\" ||\n\t\ttypeof payload?.data !== \"object\" ||\n\t\tpayload.data === null ||\n\t\tpayload.exp < Date.now()\n\t) {\n\t\treturn undefined;\n\t}\n\treturn payload;\n}\n\nfunction encodeBase64Url(bytes: Uint8Array): string {\n\t// btoa can't take raw bytes, and long argument lists overflow, so\n\t// convert in chunks\n\tlet binary = \"\";\n\tfor (let i = 0; i < bytes.length; i += 0x1000) {\n\t\tbinary += String.fromCharCode(...bytes.subarray(i, i + 0x1000));\n\t}\n\treturn btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nfunction decodeBase64Url(value: string): Uint8Array<ArrayBuffer> {\n\tconst binary = atob(value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\"));\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\treturn bytes;\n}\n","import { addBaseToPath, getBasePath } from \"../site/basePath\";\nimport CookieHelper from \"./CookieHelper\";\nimport FlashHelper from \"./FlashHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\nimport SessionHelper from \"./SessionHelper\";\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\tsession: SessionHelper;\n\tflash: FlashHelper;\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\t\tthis.session = new SessionHelper(this.cookies);\n\t\tthis.flash = new FlashHelper(this.cookies);\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\ttry {\n\t\t\tthis.#addHeaders();\n\t\t} catch (e) {\n\t\t\t// The headers of a Response obtained from `fetch()` are immutable,\n\t\t\t// so an endpoint that returns a fetched Response directly would\n\t\t\t// otherwise kill the whole request (and process) -- swap in a\n\t\t\t// mutable clone and write the headers to that instead\n\t\t\tif (!(e instanceof TypeError)) throw e;\n\t\t\tthis.response = new Response(this.response.body, this.response);\n\t\t\tthis.#addHeaders();\n\t\t}\n\t}\n\n\t#addHeaders(): void {\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\n\t\t// Redirect locations are written base-free, so that user code isn't\n\t\t// aware of the base path\n\t\tconst base = getBasePath();\n\t\tif (base) {\n\t\t\tconst location = this.response!.headers.get(\"Location\");\n\t\t\tif (location) {\n\t\t\t\tconst rewritten = addBaseToPath(location, base);\n\t\t\t\tif (rewritten !== location) {\n\t\t\t\t\tthis.response!.headers.set(\"Location\", rewritten);\n\t\t\t\t}\n\t\t\t}\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,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AAS,GAAG;GAKX,IAAI,EAAE,aAAa,YAAY,MAAM;GACrC,KAAK,WAAW,IAAI,SAAS,KAAK,SAAS,MAAM,KAAK,QAAQ;GAC9D,KAAK,YAAY;EAClB;CACD;CAEA,cAAoB;EACnB,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,OAAO,GAC9C,KAAK,SAAU,QAAQ,OAAO,cAAc,MAAM;EAGnD,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAC/C,KAAK,SAAU,QAAQ,OAAO,OAAO,IAAI,OAAO,EAAE;EAKnD,MAAM,OAAO,YAAY;EACzB,IAAI,MAAM;GACT,MAAM,WAAW,KAAK,SAAU,QAAQ,IAAI,UAAU;GACtD,IAAI,UAAU;IACb,MAAM,YAAY,cAAc,UAAU,IAAI;IAC9C,IAAI,cAAc,UACjB,KAAK,SAAU,QAAQ,IAAI,YAAY,SAAS;GAElD;EACD;CACD;;;;CAKA,OAAyB;EACxB,OAAO,KAAK,QAAQ,KAAK;CAC1B;AACD"}
|
|
1
|
+
{"version":3,"file":"ServerEvent-L0rT_mBJ.mjs","names":["COOKIE_NAME"],"sources":["../src/server/CookieHelper.ts","../src/server/FlashHelper.ts","../src/server/HeaderHelper.ts","../src/server/SessionHelper.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","import CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-flash\";\n\n/**\n * A one-time values store set in a form action and shown on the next page\n * render, which survives the redirect. Available as `event.flash`; the\n * framework reads it into `$page.flash` when a page is rendered, so\n * components display it reactively:\n *\n * ```ts\n * actions: {\n * \tsave: async (event) => {\n * \t\t// ...save...\n * \t\tevent.flash.set(\"Project saved\"); // { message: \"Project saved\" }\n * \t\tevent.flash.set({ error: \"Import failed\", retryable: true });\n * \t\treturn seeOther(`/projects/${id}`);\n * \t},\n * }\n * ```\n *\n * ```torp\n * @if ($page.flash?.message) {\n * \t<p class=\"flash\">{$page.flash.message}</p>\n * }\n * ```\n *\n * The values ride in a (session-lifetime) cookie that is deleted when it is\n * read, so a page refresh shows them once. No signing: the only person who\n * can fake a flash is the one seeing it, and values are rendered as text.\n * They must be JSON-safe and small enough to fit in the cookie (~4KB). A\n * common shape for a styled banner is `{ type, message }`, for use e.g.\n * with the Notification component -- but the framework only requires the\n * values to be an object. Without cookies the message is simply lost --\n * the action itself still completes.\n */\nexport default class FlashHelper {\n\t#cookies: CookieHelper;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * Reads the flash values, if any, and clears them: the same response\n\t * deletes the cookie, so the message shows exactly once. (When the\n\t * message was set during this same request, e.g. a form action that\n\t * re-renders instead of redirecting, the cookie is consumed without it\n\t * ever reaching the browser.)\n\t */\n\tget(): Record<string, unknown> | undefined {\n\t\tconst cookie = this.#cookies.get(COOKIE_NAME);\n\t\tif (!cookie) return undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t\ttry {\n\t\t\tconst decoded = JSON.parse(decodeURIComponent(cookie));\n\t\t\tif (typeof decoded !== \"object\" || decoded === null || Array.isArray(decoded)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn decoded as Record<string, unknown>;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Sets the flash values. A string is stored as `{ message: value }`, an\n\t * object as-is, e.g. `flash.set({ error: \"Import failed\" })`.\n\t */\n\tset(value: string | Record<string, unknown>): void {\n\t\tconst data = typeof value === \"string\" ? { message: value } : value;\n\t\tthis.#cookies.set(COOKIE_NAME, encodeURIComponent(JSON.stringify(data)), { path: \"/\" });\n\t}\n\n\t/**\n\t * Clears an unread flash message, e.g. so it isn't shown on a later\n\t * re-render of the same page.\n\t */\n\tclear(): void {\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\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 env from \"../env\";\nimport CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-session\";\nconst DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days, in seconds\n\n/**\n * The data stored in the session. Must be JSON-safe, and small enough to\n * fit in a cookie (4KB) along with the id, expiry and signature.\n */\ntype SessionData = Record<string, unknown>;\n\ntype SessionPayload = {\n\tid: string;\n\tdata: SessionData;\n\t/** Expiry, as a Unix epoch in milliseconds */\n\texp: number;\n};\n\n// The imported signing key, cached per secret so repeated calls (per\n// request) don't re-import\nconst keys = new Map<string, Promise<CryptoKey>>();\n\n/**\n * A helper for reading and writing the signed session cookie, available as\n * `event.session` in load functions, actions, +server endpoints and hooks.\n *\n * The value is signed with HMAC-SHA256 using `TORPOR_SESSION_SECRET` from\n * the environment, so it can't be forged or tampered with -- but it is\n * still client-side storage: everything rides in the cookie, it can't be\n * revoked individually, and it is limited to ~4KB. When you need\n * revocation, store `session.id` in your database, check it on each\n * authed request (e.g. in a `_hook.server.ts`), and delete the row to\n * revoke.\n *\n * ```ts\n * // Login action\n * const user = await checkPassword(event.form());\n * await event.session.regenerate({ userId: user.id });\n *\n * // Root hook\n * const session = await event.session.get();\n * if (session) {\n * \tevent.appData.user = await getUser(session.userId);\n * }\n * ```\n */\nexport default class SessionHelper {\n\t#cookies: CookieHelper;\n\t#id: string | undefined;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * The id embedded in the current session cookie, or undefined when\n\t * there is no valid session. Stable across `set` calls, so it can be\n\t * used as a database key; `regenerate` mints a new one.\n\t */\n\tget id(): string | undefined {\n\t\treturn this.#id;\n\t}\n\n\t/**\n\t * Reads and verifies the session, returning its data, or undefined when\n\t * there is no cookie, the signature doesn't match, or the session has\n\t * expired.\n\t */\n\tasync get(): Promise<SessionData | undefined> {\n\t\tconst value = this.#cookies.get(COOKIE_NAME);\n\t\tif (!value) return undefined;\n\t\tconst payload = await verifyValue(value);\n\t\tif (!payload) return undefined;\n\t\tthis.#id = payload.id;\n\t\treturn payload.data;\n\t}\n\n\t/**\n\t * Writes the session, signing the data and setting the cookie. Keeps\n\t * the current session id, minting one when there isn't a valid session\n\t * yet. Call `regenerate` instead when the session's identity should\n\t * change (e.g. at login, to prevent session fixation).\n\t */\n\tasync set(data: SessionData, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = this.#id ?? crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Writes the session with a fresh id, replacing any existing one. Use\n\t * it when a session's privilege level changes (login, permission\n\t * upgrade), so a cookie that was set before the change can't be reused.\n\t */\n\tasync regenerate(data: SessionData = {}, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Deletes the session cookie. Note that a server-side record (if you\n\t * keep one) must be deleted or revoked separately.\n\t */\n\tasync destroy(): Promise<void> {\n\t\tthis.#id = undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t}\n\n\tasync #write(\n\t\tid: string,\n\t\tdata: SessionData,\n\t\toptions: { maxAge?: number } | undefined,\n\t): Promise<void> {\n\t\tconst maxAge = options?.maxAge ?? DEFAULT_MAX_AGE;\n\t\tconst payload: SessionPayload = { id, data, exp: Date.now() + maxAge * 1000 };\n\t\tconst encoded = encodeBase64Url(new TextEncoder().encode(JSON.stringify(payload)));\n\t\tconst signature = await sign(encoded);\n\t\tthis.#cookies.set(COOKIE_NAME, `${encoded}.${signature}`, { path: \"/\", maxAge });\n\t}\n}\n\nfunction secret(): string {\n\tconst value = env().TORPOR_SESSION_SECRET;\n\tif (!value) {\n\t\tthrow new Error(\n\t\t\t\"TORPOR_SESSION_SECRET is not set. Add it to the environment (or to a .env \" +\n\t\t\t\t\"file in dev and preview) to use sessions.\",\n\t\t);\n\t}\n\treturn value;\n}\n\nfunction signingKey(): Promise<CryptoKey> {\n\tconst value = secret();\n\tlet key = keys.get(value);\n\tif (!key) {\n\t\tkey = crypto.subtle.importKey(\n\t\t\t\"raw\",\n\t\t\tnew TextEncoder().encode(value),\n\t\t\t{ name: \"HMAC\", hash: \"SHA-256\" },\n\t\t\tfalse,\n\t\t\t[\"sign\", \"verify\"],\n\t\t);\n\t\tkeys.set(value, key);\n\t}\n\treturn key;\n}\n\nasync function sign(payload: string): Promise<string> {\n\tconst signature = await crypto.subtle.sign(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tnew TextEncoder().encode(payload),\n\t);\n\treturn encodeBase64Url(new Uint8Array(signature));\n}\n\nasync function verifyValue(value: string): Promise<SessionPayload | undefined> {\n\tconst dot = value.lastIndexOf(\".\");\n\tif (dot === -1) return undefined;\n\tconst encoded = value.slice(0, dot);\n\tconst valid = await crypto.subtle.verify(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tdecodeBase64Url(value.slice(dot + 1)),\n\t\tnew TextEncoder().encode(encoded),\n\t);\n\tif (!valid) return undefined;\n\n\tlet payload: SessionPayload;\n\ttry {\n\t\tpayload = JSON.parse(new TextDecoder().decode(decodeBase64Url(encoded)));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (\n\t\ttypeof payload?.id !== \"string\" ||\n\t\ttypeof payload?.exp !== \"number\" ||\n\t\ttypeof payload?.data !== \"object\" ||\n\t\tpayload.data === null ||\n\t\tpayload.exp < Date.now()\n\t) {\n\t\treturn undefined;\n\t}\n\treturn payload;\n}\n\nfunction encodeBase64Url(bytes: Uint8Array): string {\n\t// btoa can't take raw bytes, and long argument lists overflow, so\n\t// convert in chunks\n\tlet binary = \"\";\n\tfor (let i = 0; i < bytes.length; i += 0x1000) {\n\t\tbinary += String.fromCharCode(...bytes.subarray(i, i + 0x1000));\n\t}\n\treturn btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nfunction decodeBase64Url(value: string): Uint8Array<ArrayBuffer> {\n\tconst binary = atob(value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\"));\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\treturn bytes;\n}\n","import { addBaseToPath, getBasePath } from \"../site/basePath\";\nimport CookieHelper from \"./CookieHelper\";\nimport FlashHelper from \"./FlashHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\nimport SessionHelper from \"./SessionHelper\";\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\tsession: SessionHelper;\n\tflash: FlashHelper;\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's form body, parsed at most once per request: the schema\n\t// validation and the event's `form()`/`formData()` accessors share a\n\t// single read, since a request body can't be read twice\n\t#formData: Promise<FormData> | 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\t\tthis.session = new SessionHelper(this.cookies);\n\t\tthis.flash = new FlashHelper(this.cookies);\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\ttry {\n\t\t\tthis.#addHeaders();\n\t\t} catch (e) {\n\t\t\t// The headers of a Response obtained from `fetch()` are immutable,\n\t\t\t// so an endpoint that returns a fetched Response directly would\n\t\t\t// otherwise kill the whole request (and process) -- swap in a\n\t\t\t// mutable clone and write the headers to that instead\n\t\t\tif (!(e instanceof TypeError)) throw e;\n\t\t\tthis.response = new Response(this.response.body, this.response);\n\t\t\tthis.#addHeaders();\n\t\t}\n\t}\n\n\t#addHeaders(): void {\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\n\t\t// Redirect locations are written base-free, so that user code isn't\n\t\t// aware of the base path\n\t\tconst base = getBasePath();\n\t\tif (base) {\n\t\t\tconst location = this.response!.headers.get(\"Location\");\n\t\t\tif (location) {\n\t\t\t\tconst rewritten = addBaseToPath(location, base);\n\t\t\t\tif (rewritten !== location) {\n\t\t\t\t\tthis.response!.headers.set(\"Location\", rewritten);\n\t\t\t\t}\n\t\t\t}\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\t/**\n\t * Reads the request body as the web standard FormData object. The body is\n\t * parsed at most once per request, so that everything that reads the form\n\t * (schema validation, `event.form()`, `event.formData()`) shares the read.\n\t */\n\tformData(): Promise<FormData> {\n\t\treturn (this.#formData ??= this.request.formData());\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,Q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aAAa,OAAO;EACvC,KAAK,UAAU,IAAI,cAAc,KAAK,OAAO;EAC7C,KAAK,QAAQ,IAAI,YAAY,KAAK,OAAO;EAIzC,KAAK,UAAU,WAAW;CAC3B;CAEA,aAAmB;EAClB,IAAI,CAAC,KAAK,UACT,MAAM,IAAI,MAAM,0BAA0B;EAG3C,IAAI;GACH,KAAK,YAAY;EAClB,SAAS,GAAG;GAKX,IAAI,EAAE,aAAa,YAAY,MAAM;GACrC,KAAK,WAAW,IAAI,SAAS,KAAK,SAAS,MAAM,KAAK,QAAQ;GAC9D,KAAK,YAAY;EAClB;CACD;CAEA,cAAoB;EACnB,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,OAAO,GAC9C,KAAK,SAAU,QAAQ,OAAO,cAAc,MAAM;EAGnD,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAC/C,KAAK,SAAU,QAAQ,OAAO,OAAO,IAAI,OAAO,EAAE;EAKnD,MAAM,OAAO,YAAY;EACzB,IAAI,MAAM;GACT,MAAM,WAAW,KAAK,SAAU,QAAQ,IAAI,UAAU;GACtD,IAAI,UAAU;IACb,MAAM,YAAY,cAAc,UAAU,IAAI;IAC9C,IAAI,cAAc,UACjB,KAAK,SAAU,QAAQ,IAAI,YAAY,SAAS;GAElD;EACD;CACD;;;;CAKA,OAAyB;EACxB,OAAO,KAAK,QAAQ,KAAK;CAC1B;;;;;;CAOA,WAA8B;EAC7B,OAAQ,KAAK,cAAc,KAAK,QAAQ,SAAS;CAClD;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as ServerLoadEvent } from "./ServerLoadEvent-
|
|
1
|
+
import { r as ServerLoadEvent } from "./ServerLoadEvent-F60w1TZt.mjs";
|
|
2
2
|
//#region src/types/ServerHook.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* For _hook.server.
|
|
@@ -18,4 +18,4 @@ interface ServerHook<Route extends string | undefined = undefined> {
|
|
|
18
18
|
}
|
|
19
19
|
//#endregion
|
|
20
20
|
export { ServerHook as t };
|
|
21
|
-
//# sourceMappingURL=ServerHook-
|
|
21
|
+
//# sourceMappingURL=ServerHook-CyVEr5OL.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerHook-
|
|
1
|
+
{"version":3,"file":"ServerHook-CyVEr5OL.d.mts","names":[],"sources":["../src/types/ServerHook.ts"],"mappings":";;;;;UAKyB,WAAW;;;;;;EAMnC,SAAS,OAAO,gBAAgB,WAAW,QAAQ,mBAAmB;;;;;EAKtE,QAAQ,OAAO,gBAAgB,WAAW"}
|
|
@@ -43,11 +43,21 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
|
|
|
43
43
|
*/
|
|
44
44
|
json: () => Promise<Body>;
|
|
45
45
|
/**
|
|
46
|
-
* Reads the request body as form data, returning a record of field
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* Reads the request body as form data, returning a record of the field
|
|
47
|
+
* values: one value per field, or an array when a field was submitted with
|
|
48
|
+
* multiple values (e.g. a multi select). This is a plain object, not the
|
|
49
|
+
* web standard `FormData` -- for that, use `formData()`. When the endpoint
|
|
50
|
+
* declares a schema for the form, the values are validated and typed by
|
|
51
|
+
* the schema's output.
|
|
49
52
|
*/
|
|
50
53
|
form: () => Promise<FormBody>;
|
|
54
|
+
/**
|
|
55
|
+
* Reads the request body as the web standard `FormData` object, for
|
|
56
|
+
* `get(name)` / `getAll(name)` access to individual fields. For a plain
|
|
57
|
+
* record of the values -- validated and typed when the endpoint declares a
|
|
58
|
+
* schema for the form -- use `form()`.
|
|
59
|
+
*/
|
|
60
|
+
formData: () => Promise<FormData>;
|
|
51
61
|
/**
|
|
52
62
|
* Reads the URL's query string, returning a record of param values. When
|
|
53
63
|
* the endpoint declares a schema for the query (get/head handlers and the
|
|
@@ -80,4 +90,4 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
|
|
|
80
90
|
}
|
|
81
91
|
//#endregion
|
|
82
92
|
export { QueryRecord as n, ServerLoadEvent as r, FormDataRecord as t };
|
|
83
|
-
//# sourceMappingURL=ServerLoadEvent-
|
|
93
|
+
//# sourceMappingURL=ServerLoadEvent-F60w1TZt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerLoadEvent-F60w1TZt.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts"],"mappings":";;;;;;;KAUY,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;;;;;;;;;EASpB,YAAY,QAAQ;;;;;;;EAOpB,gBAAgB,QAAQ;;;;;;;EAOxB,aAAa,QAAQ;;;;EAIrB,SAAS;;;;;EAKT,SAAS;;;;;EAKT,OAAO;;;;EAIP,SAAS;;;;EAIT,SAAS,OAAO"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as MiddlewareFunction } from "./MiddlewareFunction-
|
|
2
|
-
import { t as Server } from "./Server-
|
|
1
|
+
import { t as MiddlewareFunction } from "./MiddlewareFunction-7rIvFkjl.mjs";
|
|
2
|
+
import { t as Server } from "./Server-hwbZ7P2g.mjs";
|
|
3
3
|
import { a as RouteParamsOf } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
4
|
-
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-
|
|
5
|
-
import { t as ServerHook } from "./ServerHook-
|
|
6
|
-
import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-
|
|
4
|
+
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-F60w1TZt.mjs";
|
|
5
|
+
import { t as ServerHook } from "./ServerHook-CyVEr5OL.mjs";
|
|
6
|
+
import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-CnIYTLhu.mjs";
|
|
7
7
|
import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
|
|
8
8
|
import { Plugin, UserConfig } from "vite";
|
|
9
9
|
//#region src/types/Adapter.d.ts
|
|
@@ -153,6 +153,168 @@ interface PageServerEndPoint<Route extends string | undefined = undefined, Data
|
|
|
153
153
|
middleware?: MiddlewareFunction[];
|
|
154
154
|
}
|
|
155
155
|
//#endregion
|
|
156
|
+
//#region src/openapi/types.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* A JSON Schema object, as produced by a schema library's converter (e.g.
|
|
159
|
+
* `z.toJSONSchema`, valibot's `toJsonSchema`, arktype's `toJsonSchema`).
|
|
160
|
+
*/
|
|
161
|
+
type JsonSchema = Record<string, unknown>;
|
|
162
|
+
/**
|
|
163
|
+
* Converts a Standard Schema (zod, valibot, arktype, ...) into a JSON Schema
|
|
164
|
+
* object, for inclusion in an OpenAPI document. Supplied to the openApi
|
|
165
|
+
* plugin, since each schema library has its own conversion function:
|
|
166
|
+
*
|
|
167
|
+
* ```ts
|
|
168
|
+
* // zod
|
|
169
|
+
* openApi({ toJsonSchema: (s) => z.toJSONSchema(s as z.ZodType, { io: "input" }) })
|
|
170
|
+
* // arktype
|
|
171
|
+
* openApi({ toJsonSchema: (s) => (s as Type).toJsonSchema() })
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
type ToJsonSchema = (schema: StandardSchemaV1) => JsonSchema;
|
|
175
|
+
/**
|
|
176
|
+
* Extends the generated document per request, for documents whose content
|
|
177
|
+
* comes from data rather than the route tree alone: one document per
|
|
178
|
+
* tenant/workspace served from a dynamic route segment, extra paths built from
|
|
179
|
+
* a database, and so on. Gets a fresh copy of the base document (mutating it
|
|
180
|
+
* is safe) and the request's event, which carries `url`, `params`,
|
|
181
|
+
* `cookies`, `session`, `appData` and the rest.
|
|
182
|
+
*/
|
|
183
|
+
type OpenApiExtend = (doc: Record<string, unknown>, event: ServerLoadEvent) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
184
|
+
/**
|
|
185
|
+
* Options for the openApi plugin.
|
|
186
|
+
*/
|
|
187
|
+
type OpenApiPluginOptions = {
|
|
188
|
+
/**
|
|
189
|
+
* The path to serve the OpenAPI document at. Defaults to `/openapi.json`.
|
|
190
|
+
*/
|
|
191
|
+
path?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The path to serve interactive API docs at, or `false` to disable the
|
|
194
|
+
* docs page. Defaults to `/docs`.
|
|
195
|
+
*/
|
|
196
|
+
docs?: string | false;
|
|
197
|
+
/**
|
|
198
|
+
* The API title for the document's `info` section. Defaults to `"API"`.
|
|
199
|
+
*/
|
|
200
|
+
title?: string;
|
|
201
|
+
/**
|
|
202
|
+
* The API version for the document's `info` section. Defaults to
|
|
203
|
+
* `"1.0.0"`.
|
|
204
|
+
*/
|
|
205
|
+
version?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Converts an endpoint's schemas into JSON Schema. Required for endpoints
|
|
208
|
+
* that declare schemas; endpoints without schemas are documented with
|
|
209
|
+
* their paths and methods only.
|
|
210
|
+
*/
|
|
211
|
+
toJsonSchema?: ToJsonSchema;
|
|
212
|
+
/**
|
|
213
|
+
* Extends the generated document per request, e.g. for one document per
|
|
214
|
+
* workspace served from a dynamic route segment, or for paths built from
|
|
215
|
+
* data the route tree doesn't describe. The hook is given a fresh copy of
|
|
216
|
+
* the base document and the request's event (`params` included).
|
|
217
|
+
*
|
|
218
|
+
* `tb --openapi` writes the base document: the hook needs a request, so it
|
|
219
|
+
* isn't applied to the file.
|
|
220
|
+
*/
|
|
221
|
+
extend?: OpenApiExtend;
|
|
222
|
+
/**
|
|
223
|
+
* Document-level components, referenced from operations with `$ref`:
|
|
224
|
+
* `schemas`, `responses`, `parameters`, `headers`, `securitySchemes` and
|
|
225
|
+
* so on. Use it for definitions shared between operations, e.g. one
|
|
226
|
+
* `Error` schema that every endpoint's 4xx responses reference:
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* openApi({
|
|
230
|
+
* components: {
|
|
231
|
+
* schemas: { Error: { type: "object", properties: { message: { type: "string" } } } },
|
|
232
|
+
* },
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
components?: Record<string, unknown>;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* OpenApi options with defaults applied. Created by the openApi plugin and
|
|
240
|
+
* consumed by the document builder.
|
|
241
|
+
*/
|
|
242
|
+
type ResolvedOpenApiOptions = {
|
|
243
|
+
path: string;
|
|
244
|
+
/** Undefined when the docs page is disabled */
|
|
245
|
+
docs: string | undefined;
|
|
246
|
+
title: string;
|
|
247
|
+
version: string;
|
|
248
|
+
toJsonSchema: ToJsonSchema | undefined;
|
|
249
|
+
extend: OpenApiExtend | undefined;
|
|
250
|
+
components: Record<string, unknown> | undefined;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* A ServerEndPoint shape, loosely typed so that endpoint modules loaded from
|
|
254
|
+
* anywhere can be passed to the document builder.
|
|
255
|
+
*/
|
|
256
|
+
type OpenApiEndPoint = {
|
|
257
|
+
schema?: Record<string, StandardSchemaV1 | undefined> | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Raw OpenAPI overrides for this endpoint's operations, keyed by handler
|
|
260
|
+
* name, merged over what the document builder derives from the schemas.
|
|
261
|
+
*/
|
|
262
|
+
openapi?: OpenApiEndpointOverrides | undefined;
|
|
263
|
+
[method: string]: unknown;
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* A single API endpoint to include in an OpenAPI document: its route path
|
|
267
|
+
* (with `[param]` segments) and its default-exported endpoint object.
|
|
268
|
+
*/
|
|
269
|
+
type OpenApiRouteEntry = {
|
|
270
|
+
path: string;
|
|
271
|
+
endPoint: OpenApiEndPoint;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Loads one route's default-exported endpoint module, used by the generated
|
|
275
|
+
* document route to import each `+server` endpoint lazily.
|
|
276
|
+
*/
|
|
277
|
+
type OpenApiLoader = () => Promise<{
|
|
278
|
+
default: OpenApiEndPoint;
|
|
279
|
+
}>;
|
|
280
|
+
/**
|
|
281
|
+
* The handler names of a `+server` endpoint, as keys in its raw OpenAPI
|
|
282
|
+
* overrides (`del` is the DELETE handler).
|
|
283
|
+
*/
|
|
284
|
+
type OpenApiMethod = "get" | "post" | "patch" | "put" | "del" | "options" | "head";
|
|
285
|
+
/**
|
|
286
|
+
* A raw OpenAPI operation, merged over the generated one. Use it for what the
|
|
287
|
+
* endpoint's schemas can't express:
|
|
288
|
+
*
|
|
289
|
+
* - a JSON Schema `requestBody` directly, with no Standard Schema wrapper
|
|
290
|
+
* - response statuses and headers (`responses` replaces the generated stubs)
|
|
291
|
+
* - extra `parameters` (headers like `If-Match` sit alongside the generated
|
|
292
|
+
* path/query parameters)
|
|
293
|
+
* - `summary`, `description`, `operationId` and `tags`, for tools that name
|
|
294
|
+
* and group operations
|
|
295
|
+
*
|
|
296
|
+
* Any other OpenAPI operation field (`security`, `deprecated`, ...) passes
|
|
297
|
+
* through.
|
|
298
|
+
*/
|
|
299
|
+
type OpenApiOperation = {
|
|
300
|
+
summary?: string;
|
|
301
|
+
description?: string;
|
|
302
|
+
operationId?: string;
|
|
303
|
+
tags?: string[];
|
|
304
|
+
parameters?: Record<string, unknown>[];
|
|
305
|
+
requestBody?: Record<string, unknown>;
|
|
306
|
+
responses?: Record<string, unknown>;
|
|
307
|
+
[key: string]: unknown;
|
|
308
|
+
};
|
|
309
|
+
/** The raw OpenAPI overrides for one endpoint, keyed by handler name. */
|
|
310
|
+
type OpenApiEndpointOverrides = Partial<Record<OpenApiMethod, OpenApiOperation>> & {
|
|
311
|
+
/**
|
|
312
|
+
* Tags applied to every operation in this endpoint, for tools that group
|
|
313
|
+
* operations by tag. A handler's own `tags` override them.
|
|
314
|
+
*/
|
|
315
|
+
tags?: string[];
|
|
316
|
+
};
|
|
317
|
+
//#endregion
|
|
156
318
|
//#region src/types/ServerRequest.d.ts
|
|
157
319
|
type ServerRequest<Route extends string | undefined = undefined, Body = unknown, FormBody = FormDataRecord, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> = (event: ServerLoadEvent<Route, Body, FormBody, QueryBody, Params>) => Response | undefined | void | Promise<Response | undefined | void>;
|
|
158
320
|
//#endregion
|
|
@@ -228,6 +390,29 @@ type ServerEndPoint<Route extends string | undefined = undefined, Schemas extend
|
|
|
228
390
|
* ```
|
|
229
391
|
*/
|
|
230
392
|
schema?: Schemas | undefined;
|
|
393
|
+
/**
|
|
394
|
+
* Raw OpenAPI overrides for this endpoint's operations, keyed by handler
|
|
395
|
+
* name (`del` for DELETE), merged over what the `openApi()` plugin derives
|
|
396
|
+
* from the schemas. Use it for a JSON Schema request body (no Standard
|
|
397
|
+
* Schema wrapper needed), response statuses and headers, extra parameters,
|
|
398
|
+
* or an operation's summary/operationId/tags, e.g.
|
|
399
|
+
*
|
|
400
|
+
* ```ts
|
|
401
|
+
* export default {
|
|
402
|
+
* openapi: {
|
|
403
|
+
* post: {
|
|
404
|
+
* requestBody: { content: { "application/json": { schema: postJsonSchema } } },
|
|
405
|
+
* responses: {
|
|
406
|
+
* "201": { description: "Created", headers: { Location: { schema: { type: "string" } } } },
|
|
407
|
+
* "409": { description: "Conflict" },
|
|
408
|
+
* },
|
|
409
|
+
* },
|
|
410
|
+
* },
|
|
411
|
+
* post: async (event) => created(await createPost(await event.json())),
|
|
412
|
+
* } satisfies ServerEndPoint;
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
openapi?: OpenApiEndpointOverrides | undefined;
|
|
231
416
|
/**
|
|
232
417
|
* Performs a GET. Its schema validates the query string.
|
|
233
418
|
*/
|
|
@@ -538,5 +723,5 @@ declare class Site {
|
|
|
538
723
|
}, subFolder?: string): void;
|
|
539
724
|
}
|
|
540
725
|
//#endregion
|
|
541
|
-
export { ServerEndPoint as a,
|
|
542
|
-
//# sourceMappingURL=Site-
|
|
726
|
+
export { PageServerEndPoint as C, Adapter as D, SitePlugin as E, PageServerActionSchemas as S, PageServerAction as T, ResolvedOpenApiOptions as _, ServerEndPoint as a, LoadParams as b, JsonSchema as c, OpenApiExtend as d, OpenApiLoader as f, OpenApiRouteEntry as g, OpenApiPluginOptions as h, SchemaQuery as i, OpenApiEndPoint as l, OpenApiOperation as m, ParamsOf as n, ServerEndPointSchemas as o, OpenApiMethod as p, SchemaBody as r, ServerRequest as s, Site as t, OpenApiEndpointOverrides as u, ToJsonSchema as v, PageServerLoad as w, LoadQuery as x, ActionBody as y };
|
|
727
|
+
//# sourceMappingURL=Site-CAeAqjkk.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Site-CAeAqjkk.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/openapi/types.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;;;;;;;;;;;;;;;;;;;;;;;KCG1C,cAAc,MAAM,gBAAgB;;;KCjBpC,iBACJ,8CACA,WAAW,gBACX,SAAS,cAAc,WAEvB,OAAO,gBAAgB,gBAAgB,UAAU,aAAa,YAC1D,8BAA8B,QAAQ;;;KCLtC,eACJ,8CACA,OAAO,qBACP,YAAY,aACZ,SAAS,cAAc,WAEvB,OAAO,gBAAgB,gBAAgB,gBAAgB,WAAW,YAC9D,eAAe,QAAQ,QAAQ,eAAe;;;;;;;;;;;;;;;;;;;;;KCavC;EACX,SAAS;EACT,OAAO;GAC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;;cCOoB;;EACpB;;;;;;;;;;EAUA;EACA,QAAQ;;;;;;EAMR;IAAgB;IAAgB;;;;;;;;EAOhC,SAAS;;;;EAIT,aAAa;;;;;;;;;;EAUb,SAAS;;;;;;EAMT;;;;;;;EAOA,aAAa;;;;;EAKb;;;;;;;;;;;;;;;;EAgBA,aAAa,IAAI;;;;;;;EAOjB;;;;;;;EAOA;;;;;;;;;EASA,sBAAsB;;;;;;EAMtB;;;;;;;;;;;;EAYA,YAAY;;;;;;;;;;;EAWZ,UAAU;;;;;;;;;EASV,MAAM,0BAA0B;;;;;EAKhC,iBAAiB,eAAe;EAEhC;;MAKI;;;;;;;;;EAYJ,eAAqB,gBAAgB,qBAAqB;;;;;;;;;;;;EA0C1D,gBAAgB,OAAO;;;;;;;;EAwBvB,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,39 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-
|
|
2
|
+
import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-BZ314IiI.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import fpath from "node:path";
|
|
5
|
+
//#region src/run/runCheck.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type-checks the site's `.ts` and `.torp` files with `@torpor/check`, which
|
|
8
|
+
* compiles each component to TypeScript and reports diagnostics mapped back
|
|
9
|
+
* to the source. This is the check that `tsc --noEmit` can't do: a `.torp`
|
|
10
|
+
* file isn't part of the tsconfig program, so its script block is only ever
|
|
11
|
+
* checked by the editor.
|
|
12
|
+
*
|
|
13
|
+
* `@torpor/check` is deliberately not a dependency of `@torpor/build` (it
|
|
14
|
+
* pulls in a full TypeScript install), so it is resolved from the site's own
|
|
15
|
+
* dependencies. When it's missing, the command says what to install instead
|
|
16
|
+
* of failing mysteriously.
|
|
17
|
+
*/
|
|
18
|
+
function runCheck(workingDir) {
|
|
19
|
+
const require = createRequire(fpath.join(workingDir, "package.json"));
|
|
20
|
+
let checker;
|
|
21
|
+
try {
|
|
22
|
+
checker = require("@torpor/check");
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (!(error instanceof Error ? error.message : String(error)).includes("@torpor/check")) throw error;
|
|
25
|
+
console.log("@torpor/check is not installed, so the site's .torp files can't be type-checked.\nInstall it as a dev dependency (e.g. \"npm install -D @torpor/check\") and run tb --check again.");
|
|
26
|
+
process.exitCode = 1;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const errors = checker.check(workingDir);
|
|
30
|
+
if (errors.length > 0) {
|
|
31
|
+
checker.printErrors(workingDir, errors);
|
|
32
|
+
console.log(`Found ${errors.length} error${errors.length === 1 ? "" : "s"}`);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
} else console.log("No errors found");
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
3
37
|
//#region src/bin/index.ts
|
|
4
38
|
const workingDir = process.cwd();
|
|
5
39
|
if (process.argv.includes("--openapi")) {
|
|
@@ -12,7 +46,8 @@ if (process.argv.includes("--openapi")) {
|
|
|
12
46
|
} finally {
|
|
13
47
|
await vite.close();
|
|
14
48
|
}
|
|
15
|
-
} else if (process.argv.includes("--
|
|
49
|
+
} else if (process.argv.includes("--check")) runCheck(workingDir);
|
|
50
|
+
else if (process.argv.includes("--dev")) await run(workingDir, "dev");
|
|
16
51
|
else if (process.argv.includes("--build")) await run(workingDir, "build");
|
|
17
52
|
else if (process.argv.includes("--preview")) await run(workingDir, "preview");
|
|
18
53
|
//#endregion
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run, { loadSite } from \"../run/run\";\nimport runOpenApi from \"../run/runOpenApi\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--openapi\")) {\n\tconst flagIndex = process.argv.indexOf(\"--openapi\");\n\tconst next = process.argv[flagIndex + 1];\n\tconst outFile = next && !next.startsWith(\"-\") ? next : \"openapi.json\";\n\tconst { site, vite } = await loadSite(workingDir);\n\ttry {\n\t\tawait runOpenApi(site, vite, outFile);\n\t} finally {\n\t\tawait vite.close();\n\t}\n} else if (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\");\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","names":["path"],"sources":["../../src/run/runCheck.ts","../../src/bin/index.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\n/**\n * The shape of the `@torpor/check` module that `tb --check` uses.\n */\ntype Diagnostic = {\n\tpath: string;\n\tmessage: string;\n\tcode?: number;\n\trange: {\n\t\tstart: { line: number; character: number };\n\t\tend: { line: number; character: number };\n\t};\n\tlineText?: string;\n};\n\ntype CheckModule = {\n\tcheck: (folder: string) => Diagnostic[];\n\tprintErrors: (folder: string, errors: Diagnostic[]) => void;\n};\n\n/**\n * Type-checks the site's `.ts` and `.torp` files with `@torpor/check`, which\n * compiles each component to TypeScript and reports diagnostics mapped back\n * to the source. This is the check that `tsc --noEmit` can't do: a `.torp`\n * file isn't part of the tsconfig program, so its script block is only ever\n * checked by the editor.\n *\n * `@torpor/check` is deliberately not a dependency of `@torpor/build` (it\n * pulls in a full TypeScript install), so it is resolved from the site's own\n * dependencies. When it's missing, the command says what to install instead\n * of failing mysteriously.\n */\nexport default function runCheck(workingDir: string): void {\n\tconst require = createRequire(path.join(workingDir, \"package.json\"));\n\tlet checker: CheckModule;\n\ttry {\n\t\tchecker = require(\"@torpor/check\") as CheckModule;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t// Anything else is a real load error (e.g. a broken dependency of the\n\t\t// checker itself), which shouldn't be dressed up as advice\n\t\tif (!message.includes(\"@torpor/check\")) {\n\t\t\tthrow error;\n\t\t}\n\t\tconsole.log(\n\t\t\t`@torpor/check is not installed, so the site's .torp files can't be type-checked.\\n` +\n\t\t\t\t`Install it as a dev dependency (e.g. \"npm install -D @torpor/check\") and run tb --check again.`,\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\n\tconst errors = checker.check(workingDir);\n\tif (errors.length > 0) {\n\t\tchecker.printErrors(workingDir, errors);\n\t\tconsole.log(`Found ${errors.length} error${errors.length === 1 ? \"\" : \"s\"}`);\n\t\tprocess.exitCode = 1;\n\t} else {\n\t\tconsole.log(\"No errors found\");\n\t}\n}\n","#! /usr/bin/env node\nimport run, { loadSite } from \"../run/run\";\nimport runCheck from \"../run/runCheck\";\nimport runOpenApi from \"../run/runOpenApi\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--openapi\")) {\n\tconst flagIndex = process.argv.indexOf(\"--openapi\");\n\tconst next = process.argv[flagIndex + 1];\n\tconst outFile = next && !next.startsWith(\"-\") ? next : \"openapi.json\";\n\tconst { site, vite } = await loadSite(workingDir);\n\ttry {\n\t\tawait runOpenApi(site, vite, outFile);\n\t} finally {\n\t\tawait vite.close();\n\t}\n} else if (process.argv.includes(\"--check\")) {\n\trunCheck(workingDir);\n} else if (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,SAAwB,SAAS,YAA0B;CAC1D,MAAM,UAAU,cAAcA,MAAK,KAAK,YAAY,cAAc,CAAC;CACn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+
import { t as load } from "./serverEntry-Da1PFlIU.mjs";
|
|
3
3
|
export { Server, load };
|
package/dist/dev.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
2
|
-
import { t as load } from "./serverEntry-
|
|
1
|
+
import { t as Server } from "./Server-Djd9-NkU.mjs";
|
|
2
|
+
import { t as load } from "./serverEntry-8YnfpKTj.mjs";
|
|
3
3
|
export { Server, load };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as serverError } from "./response-C5EZsszY.mjs";
|
|
2
|
-
import { t as Server } from "./Server-
|
|
2
|
+
import { t as Server } from "./Server-Djd9-NkU.mjs";
|
|
3
3
|
import { t as flattenHeaders } from "./flattenHeaders-DM5qsSqO.mjs";
|
|
4
4
|
import { existsSync, promises, realpathSync } from "node:fs";
|
|
5
5
|
import fpath from "node:path";
|
|
@@ -141,4 +141,4 @@ async function sendResponse(response, res) {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
export { siteEntryPaths as i, prepareTemplate as n, detectSourceMode as r, devPlugin as t };
|
|
143
143
|
|
|
144
|
-
//# sourceMappingURL=devPlugin-
|
|
144
|
+
//# sourceMappingURL=devPlugin-D9b5uhzm.mjs.map
|