@torpor/build 1.9.0 → 1.11.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 (107) hide show
  1. package/README.md +1 -1
  2. package/dist/{SessionHelper-MaodMaLU.d.mts → CacheOptions-C4-ebVt9.d.mts} +58 -8
  3. package/dist/CacheOptions-C4-ebVt9.d.mts.map +1 -0
  4. package/dist/{MiddlewareFunction-BZilnEei.d.mts → MiddlewareFunction-DMYxjzF4.d.mts} +31 -2
  5. package/dist/MiddlewareFunction-DMYxjzF4.d.mts.map +1 -0
  6. package/dist/{Router-By9Nlg39.d.mts → Router-DyK3DTWQ.d.mts} +4 -4
  7. package/dist/Router-DyK3DTWQ.d.mts.map +1 -0
  8. package/dist/{Server-dcRbdPXf.mjs → Server-BCijhgZp.mjs} +3 -3
  9. package/dist/{Server-dcRbdPXf.mjs.map → Server-BCijhgZp.mjs.map} +1 -1
  10. package/dist/{Server-qn5Ws_d0.d.mts → Server-ClwvuilS.d.mts} +2 -2
  11. package/dist/{Server-qn5Ws_d0.d.mts.map → Server-ClwvuilS.d.mts.map} +1 -1
  12. package/dist/{ServerEvent-BY4f3RVF.mjs → ServerEvent-BBRkd4Ya.mjs} +136 -31
  13. package/dist/ServerEvent-BBRkd4Ya.mjs.map +1 -0
  14. package/dist/{ServerHook-W111nEhe.d.mts → ServerHook-DY-NSG6n.d.mts} +2 -2
  15. package/dist/{ServerHook-W111nEhe.d.mts.map → ServerHook-DY-NSG6n.d.mts.map} +1 -1
  16. package/dist/{ServerLoadEvent-BH6oG1o6.d.mts → ServerLoadEvent-CpcgsKCU.d.mts} +32 -8
  17. package/dist/ServerLoadEvent-CpcgsKCU.d.mts.map +1 -0
  18. package/dist/{Site-DGZJB7Do.d.mts → Site-BEMQW1_y.d.mts} +216 -11
  19. package/dist/Site-BEMQW1_y.d.mts.map +1 -0
  20. package/dist/{basePath-DQnbHc7o.mjs → basePath-B6hmOMl4.mjs} +89 -4
  21. package/dist/basePath-B6hmOMl4.mjs.map +1 -0
  22. package/dist/bin/index.js +37 -2
  23. package/dist/bin/index.js.map +1 -1
  24. package/dist/clientEntry.mjs +10 -5
  25. package/dist/clientEntry.mjs.map +1 -1
  26. package/dist/dev.d.mts +2 -2
  27. package/dist/dev.mjs +2 -2
  28. package/dist/{devPlugin-lLzauETn.mjs → devPlugin-BGrTpcC2.mjs} +3 -3
  29. package/dist/{devPlugin-lLzauETn.mjs.map → devPlugin-BGrTpcC2.mjs.map} +1 -1
  30. package/dist/discovery.d.mts +1 -1
  31. package/dist/discovery.mjs +1 -1
  32. package/dist/index.d.mts +22 -6
  33. package/dist/index.d.mts.map +1 -1
  34. package/dist/index.mjs +10 -0
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/{load-BODDzmH0.mjs → load-Dw187nJ_.mjs} +95 -52
  37. package/dist/load-Dw187nJ_.mjs.map +1 -0
  38. package/dist/nav.d.mts +30 -3
  39. package/dist/nav.d.mts.map +1 -1
  40. package/dist/nav.mjs +40 -12
  41. package/dist/nav.mjs.map +1 -1
  42. package/dist/nodeDev.d.mts +1 -1
  43. package/dist/nodeDev.mjs +1 -1
  44. package/dist/openapi.d.mts +24 -80
  45. package/dist/openapi.d.mts.map +1 -1
  46. package/dist/openapi.mjs +36 -1
  47. package/dist/openapi.mjs.map +1 -0
  48. package/dist/{plugin-D8Www11B.mjs → plugin-BQsMnkTj.mjs} +42 -3
  49. package/dist/plugin-BQsMnkTj.mjs.map +1 -0
  50. package/dist/{read-DxMVAh5Y.mjs → read-CPW2iPum.mjs} +21 -2
  51. package/dist/read-CPW2iPum.mjs.map +1 -0
  52. package/dist/{response-C5EZsszY.mjs → response-B4UoOJvv.mjs} +3 -24
  53. package/dist/response-B4UoOJvv.mjs.map +1 -0
  54. package/dist/response.mjs +2 -2
  55. package/dist/run.d.mts +1 -1
  56. package/dist/run.d.mts.map +1 -1
  57. package/dist/run.mjs +1 -1
  58. package/dist/{runHooks-D5p1Rh7i.mjs → runHooks-C7kt7SEo.mjs} +36 -2
  59. package/dist/runHooks-C7kt7SEo.mjs.map +1 -0
  60. package/dist/{runOpenApi-C5yMpQU1.mjs → runOpenApi-DK-QnYEr.mjs} +279 -35
  61. package/dist/runOpenApi-DK-QnYEr.mjs.map +1 -0
  62. package/dist/server/Server.d.mts +1 -1
  63. package/dist/server/Server.mjs +1 -1
  64. package/dist/server.d.mts +30 -6
  65. package/dist/server.d.mts.map +1 -1
  66. package/dist/server.mjs +47 -3
  67. package/dist/server.mjs.map +1 -1
  68. package/dist/{serverEntry-BGii8bB6.d.mts → serverEntry-BFad1k1C.d.mts} +3 -3
  69. package/dist/serverEntry-BFad1k1C.d.mts.map +1 -0
  70. package/dist/{serverEntry-D1hE-Jzt.mjs → serverEntry-DAT7o7o2.mjs} +3 -5
  71. package/dist/serverEntry-DAT7o7o2.mjs.map +1 -0
  72. package/dist/serverEntry.d.mts +1 -1
  73. package/dist/serverEntry.mjs +1 -1
  74. package/dist/{serverHandlers-CSBUEgJt.mjs → serverHandlers-B1L8I72-.mjs} +434 -202
  75. package/dist/serverHandlers-B1L8I72-.mjs.map +1 -0
  76. package/dist/{sitemap-xmE0zfme.d.mts → sitemap-CKmagPyL.d.mts} +2 -2
  77. package/dist/{sitemap-xmE0zfme.d.mts.map → sitemap-CKmagPyL.d.mts.map} +1 -1
  78. package/dist/{sitemap-4imxJVrG.mjs → sitemap-DdzFjGlo.mjs} +2 -2
  79. package/dist/{sitemap-4imxJVrG.mjs.map → sitemap-DdzFjGlo.mjs.map} +1 -1
  80. package/dist/state.d.mts +1 -4
  81. package/dist/state.d.mts.map +1 -1
  82. package/dist/state.mjs +1 -1
  83. package/dist/test.d.mts +2 -2
  84. package/dist/test.mjs +2 -2
  85. package/dist/{unprocessable-DwAG44Rh.mjs → unprocessable-BZXwyN0n.mjs} +23 -2
  86. package/dist/unprocessable-BZXwyN0n.mjs.map +1 -0
  87. package/package.json +10 -7
  88. package/src/types/manifest.d.ts +3 -0
  89. package/dist/MiddlewareFunction-BZilnEei.d.mts.map +0 -1
  90. package/dist/Router-By9Nlg39.d.mts.map +0 -1
  91. package/dist/ServerEvent-BY4f3RVF.mjs.map +0 -1
  92. package/dist/ServerLoadEvent-BH6oG1o6.d.mts.map +0 -1
  93. package/dist/SessionHelper-MaodMaLU.d.mts.map +0 -1
  94. package/dist/Site-DGZJB7Do.d.mts.map +0 -1
  95. package/dist/_page-CW6SLuT4.mjs +0 -14
  96. package/dist/_page-CW6SLuT4.mjs.map +0 -1
  97. package/dist/basePath-DQnbHc7o.mjs.map +0 -1
  98. package/dist/load-BODDzmH0.mjs.map +0 -1
  99. package/dist/plugin-D8Www11B.mjs.map +0 -1
  100. package/dist/read-DxMVAh5Y.mjs.map +0 -1
  101. package/dist/response-C5EZsszY.mjs.map +0 -1
  102. package/dist/runHooks-D5p1Rh7i.mjs.map +0 -1
  103. package/dist/runOpenApi-C5yMpQU1.mjs.map +0 -1
  104. package/dist/serverEntry-BGii8bB6.d.mts.map +0 -1
  105. package/dist/serverEntry-D1hE-Jzt.mjs.map +0 -1
  106. package/dist/serverHandlers-CSBUEgJt.mjs.map +0 -1
  107. package/dist/unprocessable-DwAG44Rh.mjs.map +0 -1
package/dist/nav.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { n as getBasePath, t as addBaseToPath } from "./basePath-DQnbHc7o.mjs";
2
- import { i as reload, t as load } from "./load-BODDzmH0.mjs";
3
- import { n as DATA_REQUEST_HEADER, r as DATA_REUSE_HEADER } from "./read-DxMVAh5Y.mjs";
1
+ import { n as getBasePath, t as addBaseToPath } from "./basePath-B6hmOMl4.mjs";
2
+ import { i as reload, t as load } from "./load-Dw187nJ_.mjs";
3
+ import { n as DATA_REQUEST_HEADER, r as DATA_REUSE_HEADER } from "./read-CPW2iPum.mjs";
4
4
  //#region src/nav/route.ts
5
5
  /**
6
6
  * Builds a route path in a type-safe manner, filling in dynamic segments, e.g.
@@ -47,6 +47,11 @@ const METHODS = [
47
47
  * parsed; non-JSON responses resolve to the raw Response. Failed requests
48
48
  * (non-2xx) throw.
49
49
  *
50
+ * `get` and `head` take a query object, typed by the handler's schema when it
51
+ * declares one, which is serialized into the query string (arrays repeat the
52
+ * key, `undefined`/`null` values are skipped). Other methods take a request
53
+ * body: objects are sent as JSON.
54
+ *
50
55
  * @param path The endpoint's route path
51
56
  * @param params The route params, required if the path has dynamic segments
52
57
  * @returns An object with one caller per handler defined by the endpoint
@@ -54,24 +59,47 @@ const METHODS = [
54
59
  function makeApi(path, ...args) {
55
60
  const url = route(path, ...args);
56
61
  const api = {};
57
- for (const method of METHODS) api[method] = (body, init) => request(method, url, body, init);
62
+ for (const method of METHODS) api[method] = (arg, init) => request(method, url, arg, init);
58
63
  return api;
59
64
  }
60
- async function request(method, url, body, init) {
65
+ async function request(method, url, arg, init) {
66
+ const httpMethod = method === "del" ? "delete" : method;
67
+ const isQueryMethod = method === "get" || method === "head";
68
+ const target = isQueryMethod ? appendQuery(url, arg) : url;
61
69
  const options = {
62
- method: (method === "del" ? "delete" : method).toUpperCase(),
70
+ method: httpMethod.toUpperCase(),
63
71
  ...init
64
72
  };
65
- if (body !== void 0 && options.body === void 0 && method !== "get" && method !== "head") {
66
- if (typeof body === "object") {
73
+ if (!isQueryMethod && arg !== void 0 && options.body === void 0) {
74
+ if (typeof arg === "object") {
67
75
  options.headers ??= { "Content-Type": "application/json" };
68
- options.body = JSON.stringify(body);
69
- } else options.body = body;
76
+ options.body = JSON.stringify(arg);
77
+ } else options.body = arg;
70
78
  }
71
- const response = await fetch(url, options);
72
- if (!response.ok) throw new Error(`API ${method.toUpperCase()} ${url} failed: ${response.status}`);
79
+ const response = await fetch(target, options);
80
+ if (!response.ok) throw new Error(`API ${method.toUpperCase()} ${target} failed: ${response.status}`);
73
81
  return (response.headers.get("Content-Type") ?? "").includes("application/json") ? await response.json() : response;
74
82
  }
83
+ /**
84
+ * Appends a query object to a url: arrays repeat the key, `undefined` and
85
+ * `null` values are skipped, and `Date`s are sent as ISO strings. Values are
86
+ * URI-encoded. Nested objects can't be represented in a query string, so they
87
+ * throw rather than being silently stringified.
88
+ */
89
+ function appendQuery(url, query) {
90
+ if (query === void 0 || query === null) return url;
91
+ if (typeof query !== "object" || Array.isArray(query)) throw new TypeError("A GET or HEAD query must be an object");
92
+ const params = new URLSearchParams();
93
+ for (const [key, value] of Object.entries(query)) for (const item of Array.isArray(value) ? value : [value]) {
94
+ if (item === void 0 || item === null) continue;
95
+ if (item instanceof Date) params.append(key, item.toISOString());
96
+ else if (typeof item === "object") throw new TypeError(`Cannot serialize the query value for "${key}": only strings, numbers, booleans, bigints, Dates and arrays of them are supported`);
97
+ else params.append(key, String(item));
98
+ }
99
+ const search = params.toString();
100
+ if (!search) return url;
101
+ return url + (url.includes("?") ? "&" : "?") + search;
102
+ }
75
103
  //#endregion
76
104
  export { DATA_REQUEST_HEADER, DATA_REUSE_HEADER, load, makeApi, reload, route };
77
105
 
package/dist/nav.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nav.mjs","names":[],"sources":["../src/nav/route.ts","../src/nav/api.ts"],"sourcesContent":["import { addBaseToPath, getBasePath } from \"../site/basePath\";\nimport type { ExactRouteParams, ParseRouteParams } from \"../types/ParseRouteParams\";\n\n/**\n * Builds a route path in a type-safe manner, filling in dynamic segments, e.g.\n * `route(\"/posts/[id]\", { id: 5 })` returns `/posts/5`. The params object is\n * checked for exact keys: missing or unknown params error at compile time.\n *\n * NOTE: The rest args conditional must stay INLINE — routing it through a type\n * alias defeats `Params` inference, and excess keys stop being checked\n * @param path The route path\n * @param params The route params, required if the path has dynamic segments\n * @returns The path with the params filled in, URI-encoded\n */\nexport default function route<\n\tRoute extends string,\n\tParams extends ParseRouteParams<Route> = ParseRouteParams<Route>,\n>(\n\tpath: Route,\n\t...args: string extends Route\n\t\t? [params?: Record<string, string>]\n\t\t: keyof ParseRouteParams<Route> extends never\n\t\t\t? []\n\t\t\t: [params: Params & ExactRouteParams<Params, ParseRouteParams<Route>>]\n): string {\n\tconst params = ((args as unknown[])[0] ?? {}) as Record<string, string>;\n\tconst filled = path.replace(\n\t\t/\\[(\\.\\.\\.)?([^\\]]+)\\]/g,\n\t\t(_, splat: string | undefined, name: string) => {\n\t\t\tconst value = params[name];\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new Error(`Missing param '${name}' for route '${path}'`);\n\t\t\t}\n\t\t\treturn splat\n\t\t\t\t? value\n\t\t\t\t\t\t.split(\"/\")\n\t\t\t\t\t\t.map((segment) => encodeURIComponent(segment))\n\t\t\t\t\t\t.join(\"/\")\n\t\t\t\t: encodeURIComponent(String(value));\n\t\t},\n\t);\n\t// Links are written base-free; the router strips the base before matching\n\treturn addBaseToPath(filled, getBasePath());\n}\n","import type { ExactRouteParams, ParseRouteParams } from \"../types/ParseRouteParams\";\nimport type TypedResponse from \"../response/TypedResponse\";\nimport route from \"./route\";\n\n/**\n * The value a client call resolves to: the endpoint's typed JSON body when it\n * returns a typed response, or the raw Response when the body isn't JSON.\n * Untyped endpoints resolve to `unknown`.\n */\ntype ApiResult<Handler> = Handler extends (event: any) => any\n\t? Awaited<ReturnType<Handler>> extends TypedResponse<infer Body>\n\t\t? Body | Response\n\t\t: unknown\n\t: never;\n\n/**\n * The body a client call accepts: the endpoint event's annotated JSON body\n * type (from `ServerLoadEvent<Route, Body>`), or a loose value when the\n * handler doesn't annotate one.\n */\ntype ApiRequestBody<Handler> = Handler extends (event: infer Event) => any\n\t? Event extends { json: () => Promise<infer Body> }\n\t\t? unknown extends Body\n\t\t\t? BodyInit | object\n\t\t\t: Body\n\t\t: BodyInit | object\n\t: BodyInit | object;\n\n/** The callable methods of an endpoint, one per handler it defines. */\nexport type ApiMethods<Endpoint extends object> = {\n\t[\n\t\tMethod in string & keyof Endpoint as NonNullable<Endpoint[Method]> extends (event: any) => any\n\t\t\t? Method\n\t\t\t: never\n\t]: (\n\t\tbody?: ApiRequestBody<NonNullable<Endpoint[Method]>>,\n\t\tinit?: RequestInit,\n\t) => Promise<ApiResult<NonNullable<Endpoint[Method]>>>;\n};\n\nconst METHODS = [\"get\", \"post\", \"patch\", \"put\", \"del\", \"options\", \"head\"] as const;\n\n/**\n * Creates typed client callers for a `+server` endpoint, e.g.\n *\n * ```ts\n * import type endpoint from \"@/routes/api/posts/[id]/+server\";\n * const post = makeApi<\"/api/posts/[id]\", typeof endpoint>(\"/api/posts/[id]\");\n * const data = await post.get(); // typed from the endpoint's responses\n * ```\n *\n * Method names match the endpoint's handlers (`del` for DELETE). Params are\n * filled in and URI-encoded from the route path, and JSON responses are\n * parsed; non-JSON responses resolve to the raw Response. Failed requests\n * (non-2xx) throw.\n *\n * @param path The endpoint's route path\n * @param params The route params, required if the path has dynamic segments\n * @returns An object with one caller per handler defined by the endpoint\n */\nexport default function makeApi<\n\tRoute extends string,\n\tEndpoint extends object,\n\tParams extends ParseRouteParams<Route> = ParseRouteParams<Route>,\n>(\n\tpath: Route,\n\t// NOTE: The rest args conditional must stay INLINE — routing it through a\n\t// type alias defeats `Params` inference, and excess keys stop being checked\n\t...args: string extends Route\n\t\t? [params?: Record<string, string>]\n\t\t: keyof ParseRouteParams<Route> extends never\n\t\t\t? []\n\t\t\t: [params: Params & ExactRouteParams<Params, ParseRouteParams<Route>>]\n): ApiMethods<Endpoint> {\n\tconst url = route(path as string, ...(args as [params?: Record<string, string>]));\n\tconst api: Record<string, (body?: unknown, init?: RequestInit) => Promise<unknown>> = {};\n\tfor (const method of METHODS) {\n\t\tapi[method] = (body, init) => request(method, url, body, init);\n\t}\n\treturn api as ApiMethods<Endpoint>;\n}\n\nasync function request(\n\tmethod: string,\n\turl: string,\n\tbody: unknown,\n\tinit?: RequestInit,\n): Promise<unknown> {\n\t// `del` is the endpoint handler name for DELETE requests\n\tconst httpMethod = method === \"del\" ? \"delete\" : method;\n\tconst options: RequestInit = { method: httpMethod.toUpperCase(), ...init };\n\tif (body !== undefined && options.body === undefined && method !== \"get\" && method !== \"head\") {\n\t\tif (typeof body === \"object\") {\n\t\t\toptions.headers ??= { \"Content-Type\": \"application/json\" };\n\t\t\toptions.body = JSON.stringify(body);\n\t\t} else {\n\t\t\toptions.body = body as BodyInit;\n\t\t}\n\t}\n\tconst response = await fetch(url, options);\n\tif (!response.ok) {\n\t\tthrow new Error(`API ${method.toUpperCase()} ${url} failed: ${response.status}`);\n\t}\n\tconst contentType = response.headers.get(\"Content-Type\") ?? \"\";\n\treturn contentType.includes(\"application/json\") ? await response.json() : response;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAwB,MAIvB,MACA,GAAG,MAKM;CACT,MAAM,SAAW,KAAmB,MAAM,CAAC;CAC3C,MAAM,SAAS,KAAK,QACnB,2BACC,GAAG,OAA2B,SAAiB;EAC/C,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kBAAkB,KAAK,eAAe,KAAK,EAAE;EAE9D,OAAO,QACJ,MACC,MAAM,GAAG,CAAC,CACV,KAAK,YAAY,mBAAmB,OAAO,CAAC,CAAC,CAC7C,KAAK,GAAG,IACT,mBAAmB,OAAO,KAAK,CAAC;CACpC,CACD;CAEA,OAAO,cAAc,QAAQ,YAAY,CAAC;AAC3C;;;ACHA,MAAM,UAAU;CAAC;CAAO;CAAQ;CAAS;CAAO;CAAO;CAAW;AAAM;;;;;;;;;;;;;;;;;;;AAoBxE,SAAwB,QAKvB,MAGA,GAAG,MAKoB;CACvB,MAAM,MAAM,MAAM,MAAgB,GAAI,IAA0C;CAChF,MAAM,MAAgF,CAAC;CACvF,KAAK,MAAM,UAAU,SACpB,IAAI,WAAW,MAAM,SAAS,QAAQ,QAAQ,KAAK,MAAM,IAAI;CAE9D,OAAO;AACR;AAEA,eAAe,QACd,QACA,KACA,MACA,MACmB;CAGnB,MAAM,UAAuB;EAAE,SADZ,WAAW,QAAQ,WAAW,OAAA,CACC,YAAY;EAAG,GAAG;CAAK;CACzE,IAAI,SAAS,KAAA,KAAa,QAAQ,SAAS,KAAA,KAAa,WAAW,SAAS,WAAW,QAAQ;EAC9F,IAAI,OAAO,SAAS,UAAU;GAC7B,QAAQ,YAAY,EAAE,gBAAgB,mBAAmB;GACzD,QAAQ,OAAO,KAAK,UAAU,IAAI;EACnC,OACC,QAAQ,OAAO;CAEjB;CACA,MAAM,WAAW,MAAM,MAAM,KAAK,OAAO;CACzC,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,MAAM,OAAO,OAAO,YAAY,EAAE,GAAG,IAAI,WAAW,SAAS,QAAQ;CAGhF,QADoB,SAAS,QAAQ,IAAI,cAAc,KAAK,GAAA,CACzC,SAAS,kBAAkB,IAAI,MAAM,SAAS,KAAK,IAAI;AAC3E"}
1
+ {"version":3,"file":"nav.mjs","names":[],"sources":["../src/nav/route.ts","../src/nav/api.ts"],"sourcesContent":["import { addBaseToPath, getBasePath } from \"../site/basePath\";\nimport type { ExactRouteParams, ParseRouteParams } from \"../types/ParseRouteParams\";\n\n/**\n * Builds a route path in a type-safe manner, filling in dynamic segments, e.g.\n * `route(\"/posts/[id]\", { id: 5 })` returns `/posts/5`. The params object is\n * checked for exact keys: missing or unknown params error at compile time.\n *\n * NOTE: The rest args conditional must stay INLINE — routing it through a type\n * alias defeats `Params` inference, and excess keys stop being checked\n * @param path The route path\n * @param params The route params, required if the path has dynamic segments\n * @returns The path with the params filled in, URI-encoded\n */\nexport default function route<\n\tRoute extends string,\n\tParams extends ParseRouteParams<Route> = ParseRouteParams<Route>,\n>(\n\tpath: Route,\n\t...args: string extends Route\n\t\t? [params?: Record<string, string>]\n\t\t: keyof ParseRouteParams<Route> extends never\n\t\t\t? []\n\t\t\t: [params: Params & ExactRouteParams<Params, ParseRouteParams<Route>>]\n): string {\n\tconst params = ((args as unknown[])[0] ?? {}) as Record<string, string>;\n\tconst filled = path.replace(\n\t\t/\\[(\\.\\.\\.)?([^\\]]+)\\]/g,\n\t\t(_, splat: string | undefined, name: string) => {\n\t\t\tconst value = params[name];\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new Error(`Missing param '${name}' for route '${path}'`);\n\t\t\t}\n\t\t\treturn splat\n\t\t\t\t? value\n\t\t\t\t\t\t.split(\"/\")\n\t\t\t\t\t\t.map((segment) => encodeURIComponent(segment))\n\t\t\t\t\t\t.join(\"/\")\n\t\t\t\t: encodeURIComponent(String(value));\n\t\t},\n\t);\n\t// Links are written base-free; the router strips the base before matching\n\treturn addBaseToPath(filled, getBasePath());\n}\n","import type { ExactRouteParams, ParseRouteParams } from \"../types/ParseRouteParams\";\nimport type { StandardSchemaV1 } from \"../types/StandardSchema\";\nimport type TypedResponse from \"../response/TypedResponse\";\nimport route from \"./route\";\n\n/** The methods whose argument is a query object rather than a request body. */\ntype QueryMethod = \"get\" | \"head\";\n\n/** A value a client call can serialize into a query param. Arrays repeat the key. */\nexport type ApiQueryValue = string | number | boolean | bigint | Date | null | undefined;\n\n/** The loose query object accepted for handlers that declare no schema. */\nexport type ApiQuery = Record<string, ApiQueryValue | readonly ApiQueryValue[]>;\n\n/**\n * The value a client call resolves to: the endpoint's typed JSON body when it\n * returns a typed response, or the raw Response when the body isn't JSON.\n * Untyped endpoints resolve to `unknown`.\n */\ntype ApiResult<Handler> = Handler extends (event: any) => any\n\t? Awaited<ReturnType<Handler>> extends TypedResponse<infer Body>\n\t\t? Body | Response\n\t\t: unknown\n\t: never;\n\n/**\n * The body a client call accepts: the endpoint event's annotated JSON body\n * type (from `ServerLoadEvent<Route, Body>`), or a loose value when the\n * handler doesn't annotate one.\n */\ntype ApiRequestBody<Handler> = Handler extends (event: infer Event) => any\n\t? Event extends { json: () => Promise<infer Body> }\n\t\t? unknown extends Body\n\t\t\t? BodyInit | object\n\t\t\t: Body\n\t\t: BodyInit | object\n\t: BodyInit | object;\n\n/**\n * The endpoint's declared schemas, when it has any. Handles both a `satisfies`\n * export (where `schema` is present) and an endpoint annotated as\n * `ServerEndPoint`, where it is optional. `never` when there are none.\n */\ntype EndpointSchemas<Endpoint extends object> = NonNullable<\n\t[Endpoint] extends [{ schema?: infer Schemas }] ? Schemas : undefined\n>;\n\n/**\n * The query object a client call accepts for a handler: the output of the\n * endpoint's get/head schema (validated and typed by it), or a loose record\n * when the handler declares no schema.\n */\ntype ApiQueryFor<Endpoint extends object, Method extends string> = [\n\tEndpointSchemas<Endpoint>,\n] extends [never]\n\t? ApiQuery\n\t: EndpointSchemas<Endpoint> extends infer Schemas\n\t\t? Schemas extends Record<string, unknown>\n\t\t\t? Method extends keyof Schemas\n\t\t\t\t? Schemas[Method] extends StandardSchemaV1\n\t\t\t\t\t? StandardSchemaV1.InferOutput<Schemas[Method]>\n\t\t\t\t\t: ApiQuery\n\t\t\t\t: ApiQuery\n\t\t\t: ApiQuery\n\t\t: ApiQuery;\n\n/** The callable methods of an endpoint, one per handler it defines. */\nexport type ApiMethods<Endpoint extends object> = {\n\t[\n\t\tMethod in string & keyof Endpoint as NonNullable<Endpoint[Method]> extends (event: any) => any\n\t\t\t? Method\n\t\t\t: never\n\t]: Method extends QueryMethod\n\t\t? (\n\t\t\t\tquery?: ApiQueryFor<Endpoint, Method>,\n\t\t\t\tinit?: RequestInit,\n\t\t\t) => Promise<ApiResult<NonNullable<Endpoint[Method]>>>\n\t\t: (\n\t\t\t\tbody?: ApiRequestBody<NonNullable<Endpoint[Method]>>,\n\t\t\t\tinit?: RequestInit,\n\t\t\t) => Promise<ApiResult<NonNullable<Endpoint[Method]>>>;\n};\n\nconst METHODS = [\"get\", \"post\", \"patch\", \"put\", \"del\", \"options\", \"head\"] as const;\n\n/**\n * Creates typed client callers for a `+server` endpoint, e.g.\n *\n * ```ts\n * import type endpoint from \"@/routes/api/posts/[id]/+server\";\n * const post = makeApi<\"/api/posts/[id]\", typeof endpoint>(\"/api/posts/[id]\");\n * const data = await post.get(); // typed from the endpoint's responses\n * ```\n *\n * Method names match the endpoint's handlers (`del` for DELETE). Params are\n * filled in and URI-encoded from the route path, and JSON responses are\n * parsed; non-JSON responses resolve to the raw Response. Failed requests\n * (non-2xx) throw.\n *\n * `get` and `head` take a query object, typed by the handler's schema when it\n * declares one, which is serialized into the query string (arrays repeat the\n * key, `undefined`/`null` values are skipped). Other methods take a request\n * body: objects are sent as JSON.\n *\n * @param path The endpoint's route path\n * @param params The route params, required if the path has dynamic segments\n * @returns An object with one caller per handler defined by the endpoint\n */\nexport default function makeApi<\n\tRoute extends string,\n\tEndpoint extends object,\n\tParams extends ParseRouteParams<Route> = ParseRouteParams<Route>,\n>(\n\tpath: Route,\n\t// NOTE: The rest args conditional must stay INLINE — routing it through a\n\t// type alias defeats `Params` inference, and excess keys stop being checked\n\t...args: string extends Route\n\t\t? [params?: Record<string, string>]\n\t\t: keyof ParseRouteParams<Route> extends never\n\t\t\t? []\n\t\t\t: [params: Params & ExactRouteParams<Params, ParseRouteParams<Route>>]\n): ApiMethods<Endpoint> {\n\tconst url = route(path as string, ...(args as [params?: Record<string, string>]));\n\tconst api: Record<string, (arg?: unknown, init?: RequestInit) => Promise<unknown>> = {};\n\tfor (const method of METHODS) {\n\t\tapi[method] = (arg, init) => request(method, url, arg, init);\n\t}\n\treturn api as ApiMethods<Endpoint>;\n}\n\nasync function request(\n\tmethod: string,\n\turl: string,\n\targ: unknown,\n\tinit?: RequestInit,\n): Promise<unknown> {\n\t// `del` is the endpoint handler name for DELETE requests\n\tconst httpMethod = method === \"del\" ? \"delete\" : method;\n\tconst isQueryMethod = method === \"get\" || method === \"head\";\n\t// GET and HEAD take a query object (there is no request body to send)\n\tconst target = isQueryMethod ? appendQuery(url, arg) : url;\n\tconst options: RequestInit = { method: httpMethod.toUpperCase(), ...init };\n\tif (!isQueryMethod && arg !== undefined && options.body === undefined) {\n\t\tif (typeof arg === \"object\") {\n\t\t\toptions.headers ??= { \"Content-Type\": \"application/json\" };\n\t\t\toptions.body = JSON.stringify(arg);\n\t\t} else {\n\t\t\toptions.body = arg as BodyInit;\n\t\t}\n\t}\n\tconst response = await fetch(target, options);\n\tif (!response.ok) {\n\t\tthrow new Error(`API ${method.toUpperCase()} ${target} failed: ${response.status}`);\n\t}\n\tconst contentType = response.headers.get(\"Content-Type\") ?? \"\";\n\treturn contentType.includes(\"application/json\") ? await response.json() : response;\n}\n\n/**\n * Appends a query object to a url: arrays repeat the key, `undefined` and\n * `null` values are skipped, and `Date`s are sent as ISO strings. Values are\n * URI-encoded. Nested objects can't be represented in a query string, so they\n * throw rather than being silently stringified.\n */\nfunction appendQuery(url: string, query: unknown): string {\n\tif (query === undefined || query === null) return url;\n\tif (typeof query !== \"object\" || Array.isArray(query)) {\n\t\tthrow new TypeError(\"A GET or HEAD query must be an object\");\n\t}\n\tconst params = new URLSearchParams();\n\tfor (const [key, value] of Object.entries(query as Record<string, unknown>)) {\n\t\tfor (const item of Array.isArray(value) ? value : [value]) {\n\t\t\tif (item === undefined || item === null) continue;\n\t\t\tif (item instanceof Date) {\n\t\t\t\tparams.append(key, item.toISOString());\n\t\t\t} else if (typeof item === \"object\") {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Cannot serialize the query value for \"${key}\": only strings, numbers, ` +\n\t\t\t\t\t\t`booleans, bigints, Dates and arrays of them are supported`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tparams.append(key, String(item));\n\t\t\t}\n\t\t}\n\t}\n\tconst search = params.toString();\n\tif (!search) return url;\n\treturn url + (url.includes(\"?\") ? \"&\" : \"?\") + search;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAwB,MAIvB,MACA,GAAG,MAKM;CACT,MAAM,SAAW,KAAmB,MAAM,CAAC;CAC3C,MAAM,SAAS,KAAK,QACnB,2BACC,GAAG,OAA2B,SAAiB;EAC/C,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kBAAkB,KAAK,eAAe,KAAK,EAAE;EAE9D,OAAO,QACJ,MACC,MAAM,GAAG,CAAC,CACV,KAAK,YAAY,mBAAmB,OAAO,CAAC,CAAC,CAC7C,KAAK,GAAG,IACT,mBAAmB,OAAO,KAAK,CAAC;CACpC,CACD;CAEA,OAAO,cAAc,QAAQ,YAAY,CAAC;AAC3C;;;ACwCA,MAAM,UAAU;CAAC;CAAO;CAAQ;CAAS;CAAO;CAAO;CAAW;AAAM;;;;;;;;;;;;;;;;;;;;;;;;AAyBxE,SAAwB,QAKvB,MAGA,GAAG,MAKoB;CACvB,MAAM,MAAM,MAAM,MAAgB,GAAI,IAA0C;CAChF,MAAM,MAA+E,CAAC;CACtF,KAAK,MAAM,UAAU,SACpB,IAAI,WAAW,KAAK,SAAS,QAAQ,QAAQ,KAAK,KAAK,IAAI;CAE5D,OAAO;AACR;AAEA,eAAe,QACd,QACA,KACA,KACA,MACmB;CAEnB,MAAM,aAAa,WAAW,QAAQ,WAAW;CACjD,MAAM,gBAAgB,WAAW,SAAS,WAAW;CAErD,MAAM,SAAS,gBAAgB,YAAY,KAAK,GAAG,IAAI;CACvD,MAAM,UAAuB;EAAE,QAAQ,WAAW,YAAY;EAAG,GAAG;CAAK;CACzE,IAAI,CAAC,iBAAiB,QAAQ,KAAA,KAAa,QAAQ,SAAS,KAAA,GAAW;EACtE,IAAI,OAAO,QAAQ,UAAU;GAC5B,QAAQ,YAAY,EAAE,gBAAgB,mBAAmB;GACzD,QAAQ,OAAO,KAAK,UAAU,GAAG;EAClC,OACC,QAAQ,OAAO;CAEjB;CACA,MAAM,WAAW,MAAM,MAAM,QAAQ,OAAO;CAC5C,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,MAAM,OAAO,OAAO,YAAY,EAAE,GAAG,OAAO,WAAW,SAAS,QAAQ;CAGnF,QADoB,SAAS,QAAQ,IAAI,cAAc,KAAK,GAAA,CACzC,SAAS,kBAAkB,IAAI,MAAM,SAAS,KAAK,IAAI;AAC3E;;;;;;;AAQA,SAAS,YAAY,KAAa,OAAwB;CACzD,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO;CAClD,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACnD,MAAM,IAAI,UAAU,uCAAuC;CAE5D,MAAM,SAAS,IAAI,gBAAgB;CACnC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAgC,GACzE,KAAK,MAAM,QAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,GAAG;EAC1D,IAAI,SAAS,KAAA,KAAa,SAAS,MAAM;EACzC,IAAI,gBAAgB,MACnB,OAAO,OAAO,KAAK,KAAK,YAAY,CAAC;OAC/B,IAAI,OAAO,SAAS,UAC1B,MAAM,IAAI,UACT,yCAAyC,IAAI,oFAE9C;OAEA,OAAO,OAAO,KAAK,OAAO,IAAI,CAAC;CAEjC;CAED,MAAM,SAAS,OAAO,SAAS;CAC/B,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,OAAO,IAAI,SAAS,GAAG,IAAI,MAAM,OAAO;AAChD"}
@@ -1,4 +1,4 @@
1
- import { t as Site } from "./Site-DGZJB7Do.mjs";
1
+ import { t as Site } from "./Site-BEMQW1_y.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/run/devPlugin.d.ts
4
4
  /**
package/dist/nodeDev.mjs CHANGED
@@ -1 +1 @@
1
- export { t as nodeDev } from "./devPlugin-lLzauETn.mjs";
1
+ export { t as nodeDev } from "./devPlugin-BGrTpcC2.mjs";
@@ -1,82 +1,5 @@
1
- import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
2
- import { h as SitePlugin } from "./Site-DGZJB7Do.mjs";
3
- //#region src/openapi/types.d.ts
4
- /**
5
- * A JSON Schema object, as produced by a schema library's converter (e.g.
6
- * `z.toJSONSchema`, valibot's `toJsonSchema`, arktype's `toJsonSchema`).
7
- */
8
- type JsonSchema = Record<string, unknown>;
9
- /**
10
- * Converts a Standard Schema (zod, valibot, arktype, ...) into a JSON Schema
11
- * object, for inclusion in an OpenAPI document. Supplied to the openApi
12
- * plugin, since each schema library has its own conversion function:
13
- *
14
- * ```ts
15
- * // zod
16
- * openApi({ toJsonSchema: (s) => z.toJSONSchema(s as z.ZodType, { io: "input" }) })
17
- * // arktype
18
- * openApi({ toJsonSchema: (s) => (s as Type).toJsonSchema() })
19
- * ```
20
- */
21
- type ToJsonSchema = (schema: StandardSchemaV1) => JsonSchema;
22
- /**
23
- * Options for the openApi plugin.
24
- */
25
- type OpenApiPluginOptions = {
26
- /**
27
- * The path to serve the OpenAPI document at. Defaults to `/openapi.json`.
28
- */
29
- path?: string;
30
- /**
31
- * The path to serve interactive API docs at, or `false` to disable the
32
- * docs page. Defaults to `/docs`.
33
- */
34
- docs?: string | false;
35
- /**
36
- * The API title for the document's `info` section. Defaults to `"API"`.
37
- */
38
- title?: string;
39
- /**
40
- * The API version for the document's `info` section. Defaults to
41
- * `"1.0.0"`.
42
- */
43
- version?: string;
44
- /**
45
- * Converts an endpoint's schemas into JSON Schema. Required for endpoints
46
- * that declare schemas; endpoints without schemas are documented with
47
- * their paths and methods only.
48
- */
49
- toJsonSchema?: ToJsonSchema;
50
- };
51
- /**
52
- * OpenApi options with defaults applied. Created by the openApi plugin and
53
- * consumed by the document builder.
54
- */
55
- type ResolvedOpenApiOptions = {
56
- path: string;
57
- /** Undefined when the docs page is disabled */
58
- docs: string | undefined;
59
- title: string;
60
- version: string;
61
- toJsonSchema: ToJsonSchema | undefined;
62
- };
63
- /**
64
- * A ServerEndPoint shape, loosely typed so that endpoint modules loaded from
65
- * anywhere can be passed to the document builder.
66
- */
67
- type OpenApiEndPoint = {
68
- schema?: Record<string, StandardSchemaV1 | undefined> | undefined;
69
- [method: string]: unknown;
70
- };
71
- /**
72
- * A single API endpoint to include in an OpenAPI document: its route path
73
- * (with `[param]` segments) and its default-exported endpoint object.
74
- */
75
- type OpenApiRouteEntry = {
76
- path: string;
77
- endPoint: OpenApiEndPoint;
78
- };
79
- //#endregion
1
+ import { r as ServerLoadEvent } from "./ServerLoadEvent-CpcgsKCU.mjs";
2
+ import { D as SitePlugin, _ as OpenApiRouteEntry, d as OpenApiEndpointOverrides, f as OpenApiExtend, g as OpenApiPluginOptions, h as OpenApiOperation, l as JsonSchema, m as OpenApiMethod, p as OpenApiLoader, u as OpenApiEndPoint, v as ResolvedOpenApiOptions, y as ToJsonSchema } from "./Site-BEMQW1_y.mjs";
80
3
  //#region src/openapi/document.d.ts
81
4
  /**
82
5
  * Builds an OpenAPI 3.1 document from a list of +server endpoints.
@@ -134,11 +57,32 @@ export declare const OPEN_API_STATE_KEY: symbol;
134
57
  * parameters, `get`/`head` schemas become query parameters, and
135
58
  * `post`/`patch`/`put`/`del`/`options` schemas become request bodies.
136
59
  *
60
+ * Pass `extend` to build the document per request (e.g. one per workspace),
61
+ * with the request's event available; `tb --openapi` writes the base document
62
+ * only.
63
+ *
137
64
  * The resolved options are stored in `site.pluginState` under
138
65
  * `OPEN_API_STATE_KEY`, which the manifest plugin reads at build time to
139
66
  * generate the document endpoint.
140
67
  */
141
68
  export declare function openApi(options?: OpenApiPluginOptions): SitePlugin;
142
69
  //#endregion
143
- export { type JsonSchema, type OpenApiEndPoint, type OpenApiPluginOptions, type OpenApiRouteEntry, type ResolvedOpenApiOptions, type ToJsonSchema, buildOpenApiDocument, openApiDocsHtml };
70
+ //#region src/openapi/serve.d.ts
71
+ /**
72
+ * Creates the request handler for the OpenAPI document endpoint (the route the
73
+ * manifest plugin generates). The base document is built from the route
74
+ * loaders once, on the first request; each request then gets a copy with the
75
+ * plugin's `extend` hook applied, if it has one.
76
+ *
77
+ * The options come from a getter rather than being captured here: the
78
+ * generated module runs in the site, and reads them from `site.pluginState`
79
+ * at runtime, so functions like `toJsonSchema` and `extend` are the site's
80
+ * real functions instead of being serialized into the generated module.
81
+ *
82
+ * @param loaders Route path (with `[param]` segments) -> endpoint loader
83
+ * @param getOptions Reads the plugin's resolved options
84
+ */
85
+ export declare function createOpenApiHandler(loaders: Record<string, OpenApiLoader>, getOptions: () => OpenApiPluginOptions): (event: ServerLoadEvent) => Promise<Response>;
86
+ //#endregion
87
+ export { type JsonSchema, type OpenApiEndPoint, type OpenApiEndpointOverrides, type OpenApiExtend, type OpenApiLoader, type OpenApiMethod, type OpenApiOperation, type OpenApiPluginOptions, type OpenApiRouteEntry, type ResolvedOpenApiOptions, type ToJsonSchema, buildOpenApiDocument, openApiDocsHtml };
144
88
  //# sourceMappingURL=openapi.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"openapi.d.mts","names":[],"sources":["../src/openapi/types.ts","../src/openapi/document.ts","../src/openapi/docsHtml.ts","../src/openapi/plugin.ts"],"mappings":";;;;;;;KAMY,aAAa;;;;;;;;;;;;;KAcb,gBAAgB,QAAQ,qBAAqB;;;;KAK7C;;;;EAIX;;;;;EAKA;;;;EAIA;;;;;EAKA;;;;;;EAMA,eAAe;;;;;;KAOJ;EACX;;EAEA;EACA;EACA;EACA,cAAc;;;;;;KAOH;EACX,SAAS,eAAe;;;;;;;KAQb;EACX;EACA,UAAU;;;;;;;;;;;;;;;;;iBCvDa,qBACvB,SAAS,qBACT,SAAS,uBACP;;;;;;;iBCxBqB,gBAAgB;;;;;;;;;qBCM3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCG,QAAQ,UAAS,uBAA4B"}
1
+ {"version":3,"file":"openapi.d.mts","names":[],"sources":["../src/openapi/document.ts","../src/openapi/docsHtml.ts","../src/openapi/plugin.ts","../src/openapi/serve.ts"],"mappings":";;;;;;;;;;;;;;;;iBA8BwB,qBACvB,SAAS,qBACT,SAAS,uBACP;;;;;;;iBC7BqB,gBAAgB;;;;;;;;;qBCM3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoCG,QAAQ,UAAS,uBAA4B;;;;;;;;;;;;;;;;;wBC5B7C,qBACf,SAAS,eAAe,gBACxB,kBAAkB,wBACf,OAAO,oBAAoB,QAAQ"}
package/dist/openapi.mjs CHANGED
@@ -1 +1,36 @@
1
- export { t as OPEN_API_STATE_KEY, i as buildOpenApiDocument, n as openApi, r as openApiDocsHtml } from "./plugin-D8Www11B.mjs";
1
+ import { i as buildOpenApiDocument, n as openApi, r as openApiDocsHtml, t as OPEN_API_STATE_KEY } from "./plugin-BQsMnkTj.mjs";
2
+ //#region src/openapi/serve.ts
3
+ /**
4
+ * Creates the request handler for the OpenAPI document endpoint (the route the
5
+ * manifest plugin generates). The base document is built from the route
6
+ * loaders once, on the first request; each request then gets a copy with the
7
+ * plugin's `extend` hook applied, if it has one.
8
+ *
9
+ * The options come from a getter rather than being captured here: the
10
+ * generated module runs in the site, and reads them from `site.pluginState`
11
+ * at runtime, so functions like `toJsonSchema` and `extend` are the site's
12
+ * real functions instead of being serialized into the generated module.
13
+ *
14
+ * @param loaders Route path (with `[param]` segments) -> endpoint loader
15
+ * @param getOptions Reads the plugin's resolved options
16
+ */
17
+ function createOpenApiHandler(loaders, getOptions) {
18
+ let base;
19
+ return async (event) => {
20
+ const options = getOptions();
21
+ if (!base) {
22
+ const entries = [];
23
+ for (const [routePath, load] of Object.entries(loaders)) entries.push({
24
+ path: routePath,
25
+ endPoint: (await load()).default
26
+ });
27
+ base = buildOpenApiDocument(entries, options);
28
+ }
29
+ const doc = options.extend ? await options.extend(structuredClone(base), event) : base;
30
+ return new Response(JSON.stringify(doc), { headers: { "Content-Type": "application/json" } });
31
+ };
32
+ }
33
+ //#endregion
34
+ export { OPEN_API_STATE_KEY, buildOpenApiDocument, createOpenApiHandler, openApi, openApiDocsHtml };
35
+
36
+ //# sourceMappingURL=openapi.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.mjs","names":[],"sources":["../src/openapi/serve.ts"],"sourcesContent":["import type ServerLoadEvent from \"../types/ServerLoadEvent\";\nimport buildOpenApiDocument from \"./document\";\nimport type { OpenApiLoader, OpenApiPluginOptions, OpenApiRouteEntry } from \"./types\";\n\n/**\n * Creates the request handler for the OpenAPI document endpoint (the route the\n * manifest plugin generates). The base document is built from the route\n * loaders once, on the first request; each request then gets a copy with the\n * plugin's `extend` hook applied, if it has one.\n *\n * The options come from a getter rather than being captured here: the\n * generated module runs in the site, and reads them from `site.pluginState`\n * at runtime, so functions like `toJsonSchema` and `extend` are the site's\n * real functions instead of being serialized into the generated module.\n *\n * @param loaders Route path (with `[param]` segments) -> endpoint loader\n * @param getOptions Reads the plugin's resolved options\n */\nexport function createOpenApiHandler(\n\tloaders: Record<string, OpenApiLoader>,\n\tgetOptions: () => OpenApiPluginOptions,\n): (event: ServerLoadEvent) => Promise<Response> {\n\tlet base: Record<string, unknown> | undefined;\n\treturn async (event) => {\n\t\tconst options = getOptions();\n\t\tif (!base) {\n\t\t\tconst entries: OpenApiRouteEntry[] = [];\n\t\t\tfor (const [routePath, load] of Object.entries(loaders)) {\n\t\t\t\tentries.push({ path: routePath, endPoint: (await load()).default });\n\t\t\t}\n\t\t\tbase = buildOpenApiDocument(entries, options);\n\t\t}\n\t\t// A fresh copy per request, so a hook can mutate it (merging in this\n\t\t// request's paths, say) without affecting the cached document or a\n\t\t// concurrent request\n\t\tconst doc = options.extend ? await options.extend(structuredClone(base), event) : base;\n\t\treturn new Response(JSON.stringify(doc), {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,qBACf,SACA,YACgD;CAChD,IAAI;CACJ,OAAO,OAAO,UAAU;EACvB,MAAM,UAAU,WAAW;EAC3B,IAAI,CAAC,MAAM;GACV,MAAM,UAA+B,CAAC;GACtC,KAAK,MAAM,CAAC,WAAW,SAAS,OAAO,QAAQ,OAAO,GACrD,QAAQ,KAAK;IAAE,MAAM;IAAW,WAAW,MAAM,KAAK,EAAA,CAAG;GAAQ,CAAC;GAEnE,OAAO,qBAAqB,SAAS,OAAO;EAC7C;EAIA,MAAM,MAAM,QAAQ,SAAS,MAAM,QAAQ,OAAO,gBAAgB,IAAI,GAAG,KAAK,IAAI;EAClF,OAAO,IAAI,SAAS,KAAK,UAAU,GAAG,GAAG,EACxC,SAAS,EAAE,gBAAgB,mBAAmB,EAC/C,CAAC;CACF;AACD"}
@@ -45,6 +45,7 @@ function buildOpenApiDocument(entries, options) {
45
45
  title: options.title ?? "API",
46
46
  version: options.version ?? "1.0.0"
47
47
  },
48
+ ...options.components ? { components: options.components } : {},
48
49
  paths
49
50
  };
50
51
  }
@@ -55,6 +56,7 @@ function hasSchemas(entry) {
55
56
  }
56
57
  function buildPathItem(entry, options) {
57
58
  const endPoint = entry.endPoint;
59
+ const overrides = endPoint.openapi;
58
60
  const pathItem = {};
59
61
  let count = 0;
60
62
  for (const method of METHODS) {
@@ -67,7 +69,7 @@ function buildPathItem(entry, options) {
67
69
  if (schema && QUERY_METHODS.includes(method)) parameters.push(...flattenObject(convert(schema, options), "query"));
68
70
  const responses = { "200": { description: "OK" } };
69
71
  if (schema) responses["422"] = { description: "Validation failed" };
70
- pathItem[method === "del" ? "delete" : method] = {
72
+ const generated = {
71
73
  operationId: operationId(method, entry.path),
72
74
  ...parameters.length ? { parameters } : {},
73
75
  ...schema && BODY_METHODS.includes(method) ? { requestBody: {
@@ -76,9 +78,40 @@ function buildPathItem(entry, options) {
76
78
  } } : {},
77
79
  responses
78
80
  };
81
+ pathItem[method === "del" ? "delete" : method] = mergeOperation(generated, overrides?.[method], overrides?.tags);
79
82
  }
80
83
  return count > 0 ? pathItem : void 0;
81
84
  }
85
+ /**
86
+ * Merges a raw operation over the generated one. Generated fields can be
87
+ * overridden or extra ones added; `parameters` are merged by name + location
88
+ * (so an `If-Match` header sits alongside the generated path parameters),
89
+ * while `requestBody` and `responses` replace the generated values -- the
90
+ * generated responses are stubs, so an operation that documents a `201`
91
+ * shouldn't also claim a `200`.
92
+ *
93
+ * The endpoint's `tags` apply to every operation; a handler's own tags win.
94
+ */
95
+ function mergeOperation(generated, raw, sharedTags) {
96
+ const tags = raw?.tags ?? sharedTags;
97
+ const merged = {
98
+ ...generated,
99
+ ...raw
100
+ };
101
+ if (tags) merged.tags = tags;
102
+ const generatedParameters = generated.parameters;
103
+ if (raw?.parameters && generatedParameters) merged.parameters = mergeParameters(generatedParameters, raw.parameters);
104
+ return merged;
105
+ }
106
+ function mergeParameters(generated, raw) {
107
+ const merged = [...generated];
108
+ for (const parameter of raw) {
109
+ const index = merged.findIndex((existing) => existing.name === parameter.name && existing.in === parameter.in);
110
+ if (index === -1) merged.push(parameter);
111
+ else merged[index] = parameter;
112
+ }
113
+ return merged;
114
+ }
82
115
  function convert(schema, options) {
83
116
  return options.toJsonSchema(schema);
84
117
  }
@@ -171,6 +204,10 @@ const OPEN_API_STATE_KEY = Symbol.for("@torpor/build/openapi");
171
204
  * parameters, `get`/`head` schemas become query parameters, and
172
205
  * `post`/`patch`/`put`/`del`/`options` schemas become request bodies.
173
206
  *
207
+ * Pass `extend` to build the document per request (e.g. one per workspace),
208
+ * with the request's event available; `tb --openapi` writes the base document
209
+ * only.
210
+ *
174
211
  * The resolved options are stored in `site.pluginState` under
175
212
  * `OPEN_API_STATE_KEY`, which the manifest plugin reads at build time to
176
213
  * generate the document endpoint.
@@ -184,7 +221,9 @@ function openApi(options = {}) {
184
221
  docs: options.docs === false ? void 0 : withLeadingSlash(options.docs ?? "/docs"),
185
222
  title: options.title ?? "API",
186
223
  version: options.version ?? "1.0.0",
187
- toJsonSchema: options.toJsonSchema
224
+ toJsonSchema: options.toJsonSchema,
225
+ extend: options.extend,
226
+ components: options.components
188
227
  };
189
228
  site.pluginState.set(OPEN_API_STATE_KEY, resolved);
190
229
  if (resolved.docs) {
@@ -199,4 +238,4 @@ function withLeadingSlash(pathName) {
199
238
  //#endregion
200
239
  export { buildOpenApiDocument as i, openApi as n, openApiDocsHtml as r, OPEN_API_STATE_KEY as t };
201
240
 
202
- //# sourceMappingURL=plugin-D8Www11B.mjs.map
241
+ //# sourceMappingURL=plugin-BQsMnkTj.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-BQsMnkTj.mjs","names":[],"sources":["../src/openapi/document.ts","../src/openapi/docsHtml.ts","../src/openapi/plugin.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"../types/StandardSchema\";\nimport type {\n\tJsonSchema,\n\tOpenApiOperation,\n\tOpenApiPluginOptions,\n\tOpenApiRouteEntry,\n} from \"./types\";\n\n// The endpoint handler names, in the order they appear in docs\nconst METHODS = [\"get\", \"post\", \"patch\", \"put\", \"del\", \"options\", \"head\"] as const;\ntype Method = (typeof METHODS)[number];\n\n// Handlers whose schema validates the query string; all others validate the\n// json request body\nconst QUERY_METHODS: readonly string[] = [\"get\", \"head\"];\nconst BODY_METHODS: readonly string[] = [\"post\", \"patch\", \"put\", \"del\", \"options\"];\n\n/**\n * Builds an OpenAPI 3.1 document from a list of +server endpoints.\n *\n * Each endpoint's route path (`/api/posts/[id]`) is converted to OpenAPI\n * syntax (`/api/posts/{id}`); its `params` schema becomes path parameters,\n * its `get`/`head` schema becomes query parameters, and its `post`/`patch`/\n * `put`/`del`/`options` schema becomes a json request body. Responses are\n * stubbed: a `200` for every handler, plus a `422` when the handler declares\n * an input schema (validation errors are returned automatically).\n *\n * Throws if any endpoint declares a schema but the options have no\n * `toJsonSchema` converter.\n */\nexport default function buildOpenApiDocument(\n\tentries: OpenApiRouteEntry[],\n\toptions: OpenApiPluginOptions,\n): Record<string, unknown> {\n\tif (!options.toJsonSchema) {\n\t\tconst withSchema = entries.find(hasSchemas);\n\t\tif (withSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t`The endpoint at ${withSchema.path} declares schema(s), but the openApi() plugin ` +\n\t\t\t\t\t`was not given a \"toJsonSchema\" converter. Pass one, e.g. ` +\n\t\t\t\t\t`openApi({ toJsonSchema: (s) => z.toJSONSchema(s) })`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst paths: Record<string, Record<string, unknown>> = {};\n\tfor (const entry of entries) {\n\t\tconst pathItem = buildPathItem(entry, options);\n\t\tif (pathItem) {\n\t\t\tpaths[openApiPath(entry.path)] = pathItem;\n\t\t}\n\t}\n\n\treturn {\n\t\topenapi: \"3.1.0\",\n\t\tinfo: {\n\t\t\ttitle: options.title ?? \"API\",\n\t\t\tversion: options.version ?? \"1.0.0\",\n\t\t},\n\t\t...(options.components ? { components: options.components } : {}),\n\t\tpaths,\n\t};\n}\n\nfunction hasSchemas(entry: OpenApiRouteEntry): boolean {\n\tconst schema = entry.endPoint?.schema;\n\tif (!schema) return false;\n\treturn METHODS.some((method) => schema[method]) || !!schema.params;\n}\n\nfunction buildPathItem(\n\tentry: OpenApiRouteEntry,\n\toptions: OpenApiPluginOptions,\n): Record<string, unknown> | undefined {\n\tconst endPoint = entry.endPoint;\n\tconst overrides = endPoint.openapi;\n\tconst pathItem: Record<string, unknown> = {};\n\tlet count = 0;\n\n\tfor (const method of METHODS) {\n\t\tif (typeof endPoint[method] !== \"function\") {\n\t\t\tcontinue;\n\t\t}\n\t\tcount++;\n\n\t\tconst schema = endPoint.schema?.[method];\n\t\tconst paramsSchema = endPoint.schema?.params;\n\n\t\tconst parameters: Record<string, unknown>[] = [];\n\t\tif (paramsSchema) {\n\t\t\tparameters.push(...flattenObject(convert(paramsSchema, options), \"path\"));\n\t\t}\n\t\tif (schema && QUERY_METHODS.includes(method)) {\n\t\t\tparameters.push(...flattenObject(convert(schema, options), \"query\"));\n\t\t}\n\n\t\tconst responses: Record<string, unknown> = { \"200\": { description: \"OK\" } };\n\t\tif (schema) {\n\t\t\tresponses[\"422\"] = { description: \"Validation failed\" };\n\t\t}\n\n\t\tconst generated: Record<string, unknown> = {\n\t\t\toperationId: operationId(method, entry.path),\n\t\t\t...(parameters.length ? { parameters } : {}),\n\t\t\t...(schema && BODY_METHODS.includes(method)\n\t\t\t\t? {\n\t\t\t\t\t\trequestBody: {\n\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\tcontent: { \"application/json\": { schema: convert(schema, options) } },\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\tresponses,\n\t\t};\n\t\tpathItem[method === \"del\" ? \"delete\" : method] = mergeOperation(\n\t\t\tgenerated,\n\t\t\toverrides?.[method],\n\t\t\toverrides?.tags,\n\t\t);\n\t}\n\n\treturn count > 0 ? pathItem : undefined;\n}\n\n/**\n * Merges a raw operation over the generated one. Generated fields can be\n * overridden or extra ones added; `parameters` are merged by name + location\n * (so an `If-Match` header sits alongside the generated path parameters),\n * while `requestBody` and `responses` replace the generated values -- the\n * generated responses are stubs, so an operation that documents a `201`\n * shouldn't also claim a `200`.\n *\n * The endpoint's `tags` apply to every operation; a handler's own tags win.\n */\nfunction mergeOperation(\n\tgenerated: Record<string, unknown>,\n\traw: OpenApiOperation | undefined,\n\tsharedTags: string[] | undefined,\n): Record<string, unknown> {\n\tconst tags = raw?.tags ?? sharedTags;\n\tconst merged = { ...generated, ...raw };\n\tif (tags) {\n\t\tmerged.tags = tags;\n\t}\n\tconst generatedParameters = generated.parameters as Record<string, unknown>[] | undefined;\n\tif (raw?.parameters && generatedParameters) {\n\t\tmerged.parameters = mergeParameters(generatedParameters, raw.parameters);\n\t}\n\treturn merged;\n}\n\nfunction mergeParameters(\n\tgenerated: Record<string, unknown>[],\n\traw: Record<string, unknown>[],\n): Record<string, unknown>[] {\n\tconst merged = [...generated];\n\tfor (const parameter of raw) {\n\t\tconst index = merged.findIndex(\n\t\t\t(existing) => existing.name === parameter.name && existing.in === parameter.in,\n\t\t);\n\t\tif (index === -1) {\n\t\t\tmerged.push(parameter);\n\t\t} else {\n\t\t\tmerged[index] = parameter;\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction convert(schema: StandardSchemaV1, options: OpenApiPluginOptions): JsonSchema {\n\treturn options.toJsonSchema!(schema);\n}\n\n/**\n * Flattens a converted object schema into OpenAPI parameters. Path\n * parameters are always required; query parameters take their `required`\n * flag from the schema's `required` array.\n */\nfunction flattenObject(\n\tjsonSchema: JsonSchema,\n\tlocation: \"path\" | \"query\",\n): Record<string, unknown>[] {\n\tconst properties = jsonSchema.properties;\n\tif (!properties || typeof properties !== \"object\") {\n\t\treturn [];\n\t}\n\tconst required = Array.isArray(jsonSchema.required) ? jsonSchema.required : [];\n\treturn Object.entries(properties as Record<string, JsonSchema>).map(([name, propSchema]) => ({\n\t\tname,\n\t\tin: location,\n\t\trequired: location === \"path\" ? true : required.includes(name),\n\t\tschema: propSchema,\n\t}));\n}\n\n/**\n * Converts a route path to OpenAPI syntax: `/api/posts/[id]` becomes\n * `/api/posts/{id}`.\n */\nfunction openApiPath(routePath: string): string {\n\treturn routePath.replace(/\\[\\.\\.\\.([^\\]]+)\\]/g, \"{$1}\").replace(/\\[([^\\]]+)\\]/g, \"{$1}\");\n}\n\nfunction operationId(method: Method, routePath: string): string {\n\tconst segments = openApiPath(routePath)\n\t\t.split(/[^a-zA-Z0-9]+/)\n\t\t.filter((s) => s.length > 0)\n\t\t.map((s) => s.charAt(0).toUpperCase() + s.slice(1));\n\tconst verb = method === \"del\" ? \"delete\" : method;\n\treturn verb + (segments.join(\"\") || \"Root\");\n}\n","/**\n * A standalone HTML page loading Swagger UI from a CDN, pointed at the\n * OpenAPI document endpoint.\n */\nexport default function openApiDocsHtml(docPath: string): string {\n\treturn `<!doctype html>\n<html lang=\"en\">\n<head>\n\t<meta charset=\"utf-8\" />\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t<title>API Docs</title>\n\t<link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui.css\" />\n</head>\n<body>\n\t<div id=\"swagger-ui\"></div>\n\t<script src=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js\" crossorigin></script>\n\t<script>\n\t\twindow.addEventListener(\"DOMContentLoaded\", () => {\n\t\t\tSwaggerUIBundle({ url: ${JSON.stringify(docPath)}, dom_id: \"#swagger-ui\" });\n\t\t});\n\t</script>\n</body>\n</html>\n`;\n}\n","import type SitePlugin from \"../types/SitePlugin\";\nimport openApiDocsHtml from \"./docsHtml\";\nimport type { OpenApiPluginOptions, ResolvedOpenApiOptions } from \"./types\";\n\n/**\n * The `site.pluginState` key the openApi plugin stores its resolved options\n * under. A registry symbol (`Symbol.for`), so that the user's config, the\n * manifest plugin and the generated runtime code all resolve to the same\n * key even when they are loaded as separate module instances.\n */\nexport const OPEN_API_STATE_KEY: symbol = Symbol.for(\"@torpor/build/openapi\");\n\n/**\n * Serves an OpenAPI 3.1 document for the site's `+server` endpoints, plus an\n * optional interactive docs page.\n *\n * ```ts\n * import { Site } from \"@torpor/build\";\n * import { openApi } from \"@torpor/build/openapi\";\n * import { z } from \"zod\";\n *\n * const site = new Site();\n * site.addRouteFolder(\"src/routes\");\n * site.plugins = [\n * \topenApi({\n * \t\ttitle: \"My API\",\n * \t\ttoJsonSchema: (s) => z.toJSONSchema(s as z.ZodType, { io: \"input\" }),\n * \t}),\n * ];\n * export default site;\n * ```\n *\n * The document is served at `/openapi.json` (configurable with `path`) and\n * the docs page at `/docs` (set `docs: false` to disable). Endpoints are\n * picked up from every `+server.ts` route: its `params` schema becomes path\n * parameters, `get`/`head` schemas become query parameters, and\n * `post`/`patch`/`put`/`del`/`options` schemas become request bodies.\n *\n * Pass `extend` to build the document per request (e.g. one per workspace),\n * with the request's event available; `tb --openapi` writes the base document\n * only.\n *\n * The resolved options are stored in `site.pluginState` under\n * `OPEN_API_STATE_KEY`, which the manifest plugin reads at build time to\n * generate the document endpoint.\n */\nexport function openApi(options: OpenApiPluginOptions = {}): SitePlugin {\n\treturn (site) => {\n\t\tconst docPath = withLeadingSlash(options.path ?? \"/openapi.json\");\n\t\tif (site.routes.some((route) => route.path === docPath)) {\n\t\t\tthrow new Error(\n\t\t\t\t`There is already a route registered at ${docPath}, so the OpenAPI document can't be ` +\n\t\t\t\t\t`served there. Pass a different \"path\" to the openApi() plugin`,\n\t\t\t);\n\t\t}\n\n\t\tconst resolved: ResolvedOpenApiOptions = {\n\t\t\tpath: docPath,\n\t\t\tdocs: options.docs === false ? undefined : withLeadingSlash(options.docs ?? \"/docs\"),\n\t\t\ttitle: options.title ?? \"API\",\n\t\t\tversion: options.version ?? \"1.0.0\",\n\t\t\ttoJsonSchema: options.toJsonSchema,\n\t\t\textend: options.extend,\n\t\t\tcomponents: options.components,\n\t\t};\n\t\tsite.pluginState.set(OPEN_API_STATE_KEY, resolved);\n\n\t\tif (resolved.docs) {\n\t\t\tconst html = openApiDocsHtml(docPath);\n\t\t\tsite.addRoute(resolved.docs, {\n\t\t\t\tserver: {\n\t\t\t\t\tget: () =>\n\t\t\t\t\t\tnew Response(html, {\n\t\t\t\t\t\t\theaders: { \"Content-Type\": \"text/html; charset=utf-8\" },\n\t\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t};\n}\n\nfunction withLeadingSlash(pathName: string): string {\n\treturn pathName.startsWith(\"/\") ? pathName : \"/\" + pathName;\n}\n"],"mappings":"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"}
@@ -22,6 +22,25 @@ function findErrorRoute(router, path) {
22
22
  return best?.path;
23
23
  }
24
24
  //#endregion
25
+ //#region src/utils/parseErrorStatus.ts
26
+ /**
27
+ * Parses the `status` query parameter the `/_error` page reads, accepting
28
+ * only a complete 4xx/5xx code. Anything else — missing, non-numeric, out of
29
+ * range, or a 2xx/3xx code — falls back to 404.
30
+ *
31
+ * The query string is user-controlled, so it must not decide the response
32
+ * status unfiltered: `?status=abc` made the response throw, `?status=200`
33
+ * served the error page as a success, and `?status=302` returned a redirect
34
+ * with no `Location`.
35
+ *
36
+ * @param value The raw `status` query value, or null when absent
37
+ * @returns A valid 4xx/5xx status, or 404
38
+ */
39
+ function parseErrorStatus(value) {
40
+ if (value === null || !/^[45]\d{2}$/.test(value)) return 404;
41
+ return Number(value);
42
+ }
43
+ //#endregion
25
44
  //#region src/dataRequest.ts
26
45
  /**
27
46
  * The request header a client data request sets.
@@ -67,6 +86,6 @@ async function readResponseBody(response) {
67
86
  if (response.headers.get("Content-Type")?.includes("application/json")) return await response.json();
68
87
  }
69
88
  //#endregion
70
- export { findErrorRoute as i, DATA_REQUEST_HEADER as n, DATA_REUSE_HEADER as r, readResponseBody as t };
89
+ export { findErrorRoute as a, parseErrorStatus as i, DATA_REQUEST_HEADER as n, DATA_REUSE_HEADER as r, readResponseBody as t };
71
90
 
72
- //# sourceMappingURL=read-DxMVAh5Y.mjs.map
91
+ //# sourceMappingURL=read-CPW2iPum.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-CPW2iPum.mjs","names":[],"sources":["../src/site/findErrorRoute.ts","../src/utils/parseErrorStatus.ts","../src/dataRequest.ts","../src/response/read.ts"],"sourcesContent":["import { ERROR_ROUTE } from \"../types/RouteType\";\nimport type Router from \"./Router\";\n\n/**\n * Finds the path of the nearest error route for a request path: the error\n * route whose base (its path with the `/_error` suffix stripped) is the\n * longest prefix of the request path. E.g. an error route added with\n * `addRoute(\"/admin\", { error })` handles `/admin/nope`, while everything\n * else falls back to the root `/_error`.\n *\n * Returns undefined when the site has no matching error route.\n */\nexport default function findErrorRoute(router: Router, path: string): string | undefined {\n\tlet best: { path: string; length: number } | undefined = undefined;\n\tfor (const route of router.routes) {\n\t\tif (route.handler.type !== ERROR_ROUTE) continue;\n\t\tconst base = route.handler.path.replace(/\\/_error$/, \"\");\n\t\tconst matches = base === \"\" || path === base || path.startsWith(base + \"/\");\n\t\tif (matches && (best === undefined || base.length > best.length)) {\n\t\t\tbest = { path: route.handler.path, length: base.length };\n\t\t}\n\t}\n\treturn best?.path;\n}\n","/**\n * Parses the `status` query parameter the `/_error` page reads, accepting\n * only a complete 4xx/5xx code. Anything else — missing, non-numeric, out of\n * range, or a 2xx/3xx code — falls back to 404.\n *\n * The query string is user-controlled, so it must not decide the response\n * status unfiltered: `?status=abc` made the response throw, `?status=200`\n * served the error page as a success, and `?status=302` returned a redirect\n * with no `Location`.\n *\n * @param value The raw `status` query value, or null when absent\n * @returns A valid 4xx/5xx status, or 404\n */\nexport default function parseErrorStatus(value: string | null): number {\n\tif (value === null || !/^[45]\\d{2}$/.test(value)) return 404;\n\treturn Number(value);\n}\n","/**\n * The request header a client data request sets.\n *\n * A GET to `<page url>/~server` carrying this header is handled specially:\n * the server runs the folder hooks once against the page's url and returns the\n * server data for the page and all of its layouts in a single JSON response\n * (`{ loads: [...] }`). This mirrors the server render, where hooks run once\n * with the page url and every layout and the page load in the same request --\n * fetching each `~server` separately would run hooks with internal paths like\n * `/_layout`.\n *\n * The response's `loads` array lines up with the page's layouts (root to leaf)\n * followed by the page itself, so the client can merge each layout's cached\n * client data with its fresh server data.\n */\nexport const DATA_REQUEST_HEADER = \"X-Torpor-Data\";\n\n/**\n * A JSON array of the layout paths a data request is reusing. Reused layouts\n * keep their already-loaded data, so the server skips their loads (their slot\n * in `loads` is `null`), avoiding redundant work and repeated side effects.\n */\nexport const DATA_REUSE_HEADER = \"X-Torpor-Reuse\";\n","import { INTERNAL_RESPONSE_BODY } from \"./internal\";\n\n/**\n * The object an endpoint passed to `response()`/`ok()`, including any\n * promise-valued properties, or `undefined` for a direct `Response.json` (or\n * a non-object body).\n */\nexport function rawResponseBody(response: Response): Record<string, any> | undefined {\n\tconst body = (response as Response & { [INTERNAL_RESPONSE_BODY]?: unknown })[\n\t\tINTERNAL_RESPONSE_BODY\n\t];\n\treturn body !== null && typeof body === \"object\" ? (body as Record<string, any>) : undefined;\n}\n\n/**\n * Reads a load response's data: the original object when the endpoint used\n * `ok()`/`response()` (so deferred promises survive), otherwise its JSON body.\n */\nexport async function readResponseBody(\n\tresponse: Response | undefined,\n): Promise<Record<string, any> | undefined> {\n\tif (!response) return undefined;\n\tconst raw = rawResponseBody(response);\n\tif (raw !== undefined) return raw;\n\tif (response.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\treturn (await response.json()) as Record<string, any>;\n\t}\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAwB,eAAe,QAAgB,MAAkC;CACxF,IAAI,OAAqD,KAAA;CACzD,KAAK,MAAM,SAAS,OAAO,QAAQ;EAClC,IAAI,MAAM,QAAQ,SAAA,GAAsB;EACxC,MAAM,OAAO,MAAM,QAAQ,KAAK,QAAQ,aAAa,EAAE;EAEvD,KADgB,SAAS,MAAM,SAAS,QAAQ,KAAK,WAAW,OAAO,GAAG,OAC1D,SAAS,KAAA,KAAa,KAAK,SAAS,KAAK,SACxD,OAAO;GAAE,MAAM,MAAM,QAAQ;GAAM,QAAQ,KAAK;EAAO;CAEzD;CACA,OAAO,MAAM;AACd;;;;;;;;;;;;;;;;ACVA,SAAwB,iBAAiB,OAA8B;CACtE,IAAI,UAAU,QAAQ,CAAC,cAAc,KAAK,KAAK,GAAG,OAAO;CACzD,OAAO,OAAO,KAAK;AACpB;;;;;;;;;;;;;;;;;;ACDA,MAAa,sBAAsB;;;;;;AAOnC,MAAa,oBAAoB;;;;;;;;ACfjC,SAAgB,gBAAgB,UAAqD;CACpF,MAAM,OAAQ,SACb;CAED,OAAO,SAAS,QAAQ,OAAO,SAAS,WAAY,OAA+B,KAAA;AACpF;;;;;AAMA,eAAsB,iBACrB,UAC2C;CAC3C,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,MAAM,gBAAgB,QAAQ;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,IAAI,SAAS,QAAQ,IAAI,cAAc,CAAC,EAAE,SAAS,kBAAkB,GACpE,OAAQ,MAAM,SAAS,KAAK;AAG9B"}
@@ -1,4 +1,4 @@
1
- import { i as response } from "./unprocessable-DwAG44Rh.mjs";
1
+ import { a as response } from "./unprocessable-BZXwyN0n.mjs";
2
2
  //#region src/response/badRequest.ts
3
3
  /**
4
4
  * 400 Bad Request
@@ -45,27 +45,6 @@ function created(body) {
45
45
  return response(201, body);
46
46
  }
47
47
  //#endregion
48
- //#region src/response/forbidden.ts
49
- /**
50
- * 403 Forbidden
51
- *
52
- * The HTTP 403 Forbidden client error response status code indicates that the
53
- * server understood the request but refused to process it. This status is
54
- * similar to 401, except that for 403 Forbidden responses, authenticating or
55
- * re-authenticating makes no difference. The request failure is tied to
56
- * application logic, such as insufficient permissions to a resource or action.
57
- *
58
- * Clients that receive a 403 response should expect that repeating the request
59
- * without modification will fail with the same error. Server owners may decide
60
- * to send a 404 response instead of a 403 if acknowledging the existence of a
61
- * resource to clients with insufficient privileges is not desired.
62
- *
63
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403
64
- */
65
- function forbidden(body) {
66
- return response(403, body ?? "Forbidden");
67
- }
68
- //#endregion
69
48
  //#region src/response/transfer.ts
70
49
  /**
71
50
  * Creates a redirect response with the supplied status code.
@@ -309,6 +288,6 @@ function unauthorized(body) {
309
288
  return response(401, body ?? "Unauthorized");
310
289
  }
311
290
  //#endregion
312
- export { permanentRedirect as a, methodNotAllowed as c, forbidden as d, created as f, seeOther as i, found as l, temporaryRedirect as n, notModified as o, badRequest as p, serverError as r, movedPermanently as s, unauthorized as t, transfer as u };
291
+ export { permanentRedirect as a, methodNotAllowed as c, created as d, badRequest as f, seeOther as i, found as l, temporaryRedirect as n, notModified as o, serverError as r, movedPermanently as s, unauthorized as t, transfer as u };
313
292
 
314
- //# sourceMappingURL=response-C5EZsszY.mjs.map
293
+ //# sourceMappingURL=response-B4UoOJvv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-B4UoOJvv.mjs","names":[],"sources":["../src/response/badRequest.ts","../src/response/created.ts","../src/response/transfer.ts","../src/response/found.ts","../src/response/methodNotAllowed.ts","../src/response/movedPermanently.ts","../src/response/notModified.ts","../src/response/permanentRedirect.ts","../src/response/seeOther.ts","../src/response/serverError.ts","../src/response/temporaryRedirect.ts","../src/response/unauthorized.ts"],"sourcesContent":["import response from \"./response\";\nimport type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\n\ntype BadRequestResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 400 Bad Request\n *\n * The HTTP 400 Bad Request client error response status code indicates that the\n * server would not process the request due to something the server considered\n * to be a client error. The reason for a 400 response is typically due to\n * malformed request syntax, invalid request message framing, or deceptive\n * request routing.\n *\n * Clients that receive a 400 response should expect that repeating the request\n * without modification will fail with the same error.\n *\n * An object body is typed: it becomes the page's `$props.form` (with its JSON\n * form) after a form submit, so validation errors can be surfaced with their\n * field types via `PageForm`.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/400\n */\nexport default function badRequest<T extends object | string | undefined>(\n\tbody?: T,\n): BadRequestResponse<T> {\n\treturn response(400, body ?? \"Bad request\") as BadRequestResponse<T>;\n}\n","import type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\nimport response from \"./response\";\n\ntype CreatedResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 201 Created\n *\n * The HTTP 201 Created successful response status code indicates that the HTTP\n * request has led to the creation of a resource. This status code is commonly\n * sent as the result of a POST request.\n *\n * The new resource, or a description and link to the new resource, is created\n * before the response is returned. The newly-created items can be returned in\n * the body of the response message, but must be locatable by the URL of the\n * initiating request or by the URL in the value of the Location header provided\n * with the response.\n *\n * An object body is typed: the client sees its JSON form through\n * `makeApi`-created callers.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/201\n */\nexport default function created<T extends object | string | undefined>(\n\tbody?: T,\n): CreatedResponse<T> {\n\treturn response(201, body) as CreatedResponse<T>;\n}\n","/**\n * Creates a redirect response with the supplied status code.\n */\nexport default function transfer(\n\tstatus: 300 | 301 | 302 | 303 | 304 | 307 | 308,\n\tlocation: string,\n): Response {\n\treturn new Response(null, {\n\t\tstatus,\n\t\theaders: {\n\t\t\tlocation,\n\t\t},\n\t});\n}\n","import transfer from \"./transfer\";\n\n/**\n * 302 Found\n *\n * The HTTP 302 Found redirection response status code indicates that the\n * requested resource has been temporarily moved to the URL in the Location\n * header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will not attribute links to the original URL\n * to the new resource, meaning no SEO value is transferred to the new URL.\n *\n * > Note: In the Fetch Standard, when a user agent receives a 302 in response\n * > to a POST request, it uses the GET method in the subsequent redirection\n * > request, as permitted by the HTTP specification. To avoid user agents\n * > modifying the request, use 307 Temporary Redirect instead, as altering the\n * > method after a 307 response is prohibited.\n *\n * > In cases where you want any request method to be changed to GET, use 303\n * > See Other. This is useful when you want to give a response to a PUT method\n * > that is not the uploaded resource but a confirmation message such as: \"you\n * > successfully uploaded XYZ\".\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302\n */\nexport default function found(location: string): Response {\n\treturn transfer(302, location);\n}\n","import response from \"./response\";\n\n/**\n * 405 Method Not Allowed\n *\n * The HTTP 405 Method Not Allowed client error response status code indicates\n * that the server knows the request method, but the target resource doesn't\n * support this method. The server must generate an Allow header in a 405\n * response with a list of methods that the target resource currently supports.\n *\n * Improper server-side permissions set on files or directories may cause a 405\n * response when the request would otherwise be expected to succeed.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/405\n */\nexport default function methodNotAllowed(body?: object | string): Response {\n\treturn response(405, body ?? \"Method not allowed\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 301 Moved Permanently\n *\n * The HTTP 301 Moved Permanently redirection response status code indicates\n * that the requested resource has been permanently moved to the URL in the\n * Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will attribute links to the original URL to\n * the redirected resource, passing the SEO ranking to the new URL.\n *\n * > Note: In the Fetch Standard, when a user agent receives a 301 in response\n * > to a POST request, it uses the GET method in the subsequent redirection\n * > request, as permitted by the HTTP specification. To avoid user agents\n * > modifying the request, use 308 Permanent Redirect instead, as altering the\n * > method after a 308 response is prohibited.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301\n */\nexport default function movedPermanently(location: string): Response {\n\treturn transfer(301, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 304 Not Modified\n *\n * The HTTP 304 Not Modified redirection response status code indicates that\n * there is no need to retransmit the requested resources.\n *\n * This response code is sent when the request is a conditional GET or HEAD\n * request with an If-None-Match or an If-Modified-Since header and the\n * condition evaluates to 'false'. It confirms that the resource cached by the\n * client is still valid and that the server would have sent a 200 OK response\n * with the resource if the condition evaluated to 'true'. See HTTP caching for\n * more information.\n *\n * The response must not contain a body and must include the headers that would\n * have been sent in an equivalent 200 response, such as:\n *\n * - Cache-Control\n * - Content-Location\n * - Date\n * - ETag\n * - Expires\n * - Vary\n *\n * > Note: Many developer tools' network panels of browsers create extraneous\n * > requests leading to 304 responses, so that access to the local cache is\n * > visible to developers.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304\n */\nexport default function notModified(): Response {\n\treturn transfer(304, \"\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 308 Permanent Redirect\n *\n * The HTTP 308 Permanent Redirect redirection response status code indicates\n * that the requested resource has been permanently moved to the URL given by\n * the Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will attribute links to the original URL to\n * the redirected resource, passing the SEO ranking to the new URL.\n *\n * The request method and the body will not be modified by the client in the\n * redirected request. A 301 Moved Permanently requires the request method and\n * the body to remain unchanged when redirection is performed, but this is\n * incorrectly handled by older clients to use the GET method instead.\n *\n * > Note: Some Web applications may use the 308 Permanent Redirect in a\n * > non-standard way and for different purposes. For example, Google Drive uses\n * > a 308 Resume Incomplete response to indicate to the client when an\n * > unfinished upload has stalled. See Perform a resumable download on the\n * > Google Drive documentation for more information.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308\n */\nexport default function permanentRedirect(location: string): Response {\n\treturn transfer(308, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 303 See Other\n *\n * The HTTP 303 See Other redirection response status code indicates that the\n * browser should redirect to the URL in the Location header instead of\n * rendering the requested resource.\n *\n * This response code is often sent back as a result of PUT or POST methods so\n * the client may retrieve a confirmation, or view a representation of a\n * real-world object (see HTTP range-14). The method to retrieve the redirected\n * resource is always GET.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303\n */\nexport default function seeOther(location: string): Response {\n\treturn transfer(303, location);\n}\n","import response from \"./response\";\n\n/**\n * 500 Server Error\n *\n * The HTTP 500 Internal Server Error server error response status code\n * indicates that the server encountered an unexpected condition that prevented\n * it from fulfilling the request. This error is a generic \"catch-all\" response\n * to server issues, indicating that the server cannot find a more appropriate\n * 5XX error to respond with.\n *\n * If you're a visitor seeing 500 errors on a web page, these issues require\n * investigation by server owners or administrators. There are many possible\n * causes of 500 errors, including: improper server configuration, out-of-memory\n * (OOM) issues, unhandled exceptions, improper file permissions, or other\n * complex factors. Server administrators may proactively log occurrences of\n * server error responses, like the 500 status code, with details about the\n * initiating requests to improve the stability of a service in the future.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body ?? \"Server error\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 307 Temporary Redirect\n *\n * The HTTP 307 Temporary Redirect redirection response status code indicates\n * that the resource requested has been temporarily moved to the URL in the\n * Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will not attribute links to the original URL\n * to the new resource, meaning no SEO value is transferred to the new URL.\n *\n * The method and the body of the original request are reused to perform the\n * redirected request. In the cases where you want the request method to be\n * changed to GET, use 303 See Other instead. This is useful when you want to\n * give an answer to a successful PUT request that is not the uploaded resource,\n * but a status monitor or confirmation message like \"You have successfully\n * uploaded XYZ\".\n *\n * The difference between 307 and 302 is that 307 guarantees that the client\n * will not change the request method and body when the redirected request is\n * made. With 302, older clients incorrectly changed the method to GET. 307 and\n * 302 responses are identical when the request method is GET.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307\n */\nexport default function temporaryRedirect(location: string): Response {\n\treturn transfer(307, location);\n}\n","import response from \"./response\";\n\n/**\n * 401 Unauthorized\n *\n * The HTTP 401 Unauthorized client error response status code indicates that a\n * request was not successful because it lacks valid authentication credentials\n * for the requested resource. This status code is sent with an HTTP\n * WWW-Authenticate response header that contains information on the\n * authentication scheme the server expects the client to include to make the\n * request successfully.\n *\n * A 401 Unauthorized is similar to the 403 Forbidden response, except that a\n * 403 is returned when a request contains valid credentials, but the client\n * does not have permissions to perform a certain action.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401\n */\nexport default function unauthorized(body?: object | string): Response {\n\treturn response(401, body ?? \"Unauthorized\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,SAAwB,WACvB,MACwB;CACxB,OAAO,SAAS,KAAK,QAAQ,aAAa;AAC3C;;;;;;;;;;;;;;;;;;;;;ACJA,SAAwB,QACvB,MACqB;CACrB,OAAO,SAAS,KAAK,IAAI;AAC1B;;;;;;AC3BA,SAAwB,SACvB,QACA,UACW;CACX,OAAO,IAAI,SAAS,MAAM;EACzB;EACA,SAAS,EACR,SACD;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACcA,SAAwB,MAAM,UAA4B;CACzD,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;ACdA,SAAwB,iBAAiB,MAAkC;CAC1E,OAAO,SAAS,KAAK,QAAQ,oBAAoB;AAClD;;;;;;;;;;;;;;;;;;;;;;;ACKA,SAAwB,iBAAiB,UAA4B;CACpE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACOA,SAAwB,cAAwB;CAC/C,OAAO,SAAS,KAAK,EAAE;AACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNA,SAAwB,kBAAkB,UAA4B;CACrE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;ACbA,SAAwB,SAAS,UAA4B;CAC5D,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;;;;ACGA,SAAwB,YAAY,MAAkC;CACrE,OAAO,SAAS,KAAK,QAAQ,cAAc;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACKA,SAAwB,kBAAkB,UAA4B;CACrE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;ACZA,SAAwB,aAAa,MAAkC;CACtE,OAAO,SAAS,KAAK,QAAQ,cAAc;AAC5C"}
package/dist/response.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { i as response, n as ok, r as notFound, t as unprocessable } from "./unprocessable-DwAG44Rh.mjs";
2
- import { a as permanentRedirect, c as methodNotAllowed, d as forbidden, f as created, i as seeOther, l as found, n as temporaryRedirect, o as notModified, p as badRequest, r as serverError, s as movedPermanently, t as unauthorized, u as transfer } from "./response-C5EZsszY.mjs";
1
+ import { a as response, i as forbidden, n as ok, r as notFound, t as unprocessable } from "./unprocessable-BZXwyN0n.mjs";
2
+ import { a as permanentRedirect, c as methodNotAllowed, d as created, f as badRequest, i as seeOther, l as found, n as temporaryRedirect, o as notModified, r as serverError, s as movedPermanently, t as unauthorized, u as transfer } from "./response-B4UoOJvv.mjs";
3
3
  export { badRequest, created, forbidden, found, methodNotAllowed, movedPermanently, notFound, notModified, ok, permanentRedirect, response, seeOther, serverError, temporaryRedirect, transfer, unauthorized, unprocessable };
package/dist/run.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as Site } from "./Site-DGZJB7Do.mjs";
1
+ import { t as Site } from "./Site-BEMQW1_y.mjs";
2
2
  import { ViteDevServer } from "vite";
3
3
  //#region src/run/run.d.ts
4
4
  declare function run(folder: string, mode: "dev" | "build" | "preview"): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.mts","names":[],"sources":["../src/run/run.ts","../src/run/runBuild.ts","../src/run/runDev.ts","../src/run/runOpenApi.ts","../src/run/runPreview.ts"],"mappings":";;;iBAO8B,IAC7B,gBACA,oCACE;;;iBCQ2B,SAAS,MAAM,OAAO;;;;;;;;;iBCoBtB,OAAO,MAAM,MAAM,aAAa,gBAAgB;;;;;;;;iBCxBhD,WAC7B,MAAM,MACN,MAAM,eACN,mBACE;;;iBCR2B,WAAW,MAAM,OAAO"}
1
+ {"version":3,"file":"run.d.mts","names":[],"sources":["../src/run/run.ts","../src/run/runBuild.ts","../src/run/runDev.ts","../src/run/runOpenApi.ts","../src/run/runPreview.ts"],"mappings":";;;iBAO8B,IAC7B,gBACA,oCACE;;;iBCW2B,SAAS,MAAM,OAAO;;;;;;;;;iBCiBtB,OAAO,MAAM,MAAM,aAAa,gBAAgB;;;;;;;;iBCxBhD,WAC7B,MAAM,MACN,MAAM,eACN,mBACE;;;iBCP2B,WAAW,MAAM,OAAO"}
package/dist/run.mjs CHANGED
@@ -1 +1 @@
1
- export { n as run, o as runBuild, i as runDev, t as runOpenApi, r as runPreview } from "./runOpenApi-C5yMpQU1.mjs";
1
+ export { n as run, o as runBuild, i as runDev, t as runOpenApi, r as runPreview } from "./runOpenApi-DK-QnYEr.mjs";