@torpor/build 0.4.13 → 1.0.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 (176) hide show
  1. package/README.md +20 -2
  2. package/dist/Jsonify-Dg6gChd3.d.mts +10 -0
  3. package/dist/Jsonify-Dg6gChd3.d.mts.map +1 -0
  4. package/dist/ParseRouteParams-DBmqlmLh.d.mts +42 -0
  5. package/dist/ParseRouteParams-DBmqlmLh.d.mts.map +1 -0
  6. package/dist/{RouteType-B6BMOyYw.mjs → Router-C4ADUfhv.mjs} +30 -42
  7. package/dist/Router-C4ADUfhv.mjs.map +1 -0
  8. package/dist/{Server-CF5wDJp6.d.mts → Server-C_IKav_e.d.mts} +44 -16
  9. package/dist/Server-C_IKav_e.d.mts.map +1 -0
  10. package/dist/{ServerEvent-CxPwA4lH.mjs → ServerEvent-Dljn5i7A.mjs} +37 -11
  11. package/dist/ServerEvent-Dljn5i7A.mjs.map +1 -0
  12. package/dist/Site-CMa153FA.d.mts +565 -0
  13. package/dist/Site-CMa153FA.d.mts.map +1 -0
  14. package/dist/StandardSchema-D28L8_zZ.d.mts +100 -0
  15. package/dist/StandardSchema-D28L8_zZ.d.mts.map +1 -0
  16. package/dist/TypedResponse-6lznqN4U.d.mts +22 -0
  17. package/dist/TypedResponse-6lznqN4U.d.mts.map +1 -0
  18. package/dist/{_page-BQs4WvCO.mjs → _page-4cQKs_Dn.mjs} +3 -5
  19. package/dist/_page-4cQKs_Dn.mjs.map +1 -0
  20. package/dist/bin/index.d.mts +1 -1
  21. package/dist/bin/index.js +15 -11
  22. package/dist/bin/index.js.map +1 -1
  23. package/dist/flattenHeaders-C_YYLdOq.mjs +114 -0
  24. package/dist/flattenHeaders-C_YYLdOq.mjs.map +1 -0
  25. package/dist/form.d.mts +35 -0
  26. package/dist/form.d.mts.map +1 -0
  27. package/dist/form.mjs +48 -0
  28. package/dist/form.mjs.map +1 -0
  29. package/dist/index.d.mts +72 -156
  30. package/dist/index.d.mts.map +1 -1
  31. package/dist/index.mjs +164 -32
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/nav.d.mts +58 -5
  34. package/dist/nav.d.mts.map +1 -1
  35. package/dist/nav.mjs +116 -38
  36. package/dist/nav.mjs.map +1 -1
  37. package/dist/openapi.d.mts +144 -0
  38. package/dist/openapi.d.mts.map +1 -0
  39. package/dist/openapi.mjs +2 -0
  40. package/dist/pathTrie-D4Ax2Mu9.mjs +160 -0
  41. package/dist/pathTrie-D4Ax2Mu9.mjs.map +1 -0
  42. package/dist/plugin-D8Www11B.mjs +202 -0
  43. package/dist/plugin-D8Www11B.mjs.map +1 -0
  44. package/dist/{response-C5TtAsh1.mjs → response-Bg4w2S1q.mjs} +16 -39
  45. package/dist/response-Bg4w2S1q.mjs.map +1 -0
  46. package/dist/response.d.mts +309 -289
  47. package/dist/response.d.mts.map +1 -1
  48. package/dist/response.mjs +3 -4
  49. package/dist/run.d.mts +11 -4
  50. package/dist/run.d.mts.map +1 -1
  51. package/dist/run.mjs +2 -8
  52. package/dist/runOpenApi-BUi1RH1l.mjs +1381 -0
  53. package/dist/runOpenApi-BUi1RH1l.mjs.map +1 -0
  54. package/dist/schema.d.mts +32 -0
  55. package/dist/schema.d.mts.map +1 -0
  56. package/dist/schema.mjs +2 -0
  57. package/dist/server.d.mts +10 -8
  58. package/dist/server.d.mts.map +1 -1
  59. package/dist/server.mjs +132 -4
  60. package/dist/server.mjs.map +1 -0
  61. package/dist/state.d.mts.map +1 -1
  62. package/dist/state.mjs +2 -3
  63. package/dist/test.d.mts +8 -10
  64. package/dist/test.d.mts.map +1 -1
  65. package/dist/test.mjs +286 -82
  66. package/dist/test.mjs.map +1 -1
  67. package/dist/{seeOther-B4Yhu9iq.mjs → unprocessable-DAZbrDeR.mjs} +34 -13
  68. package/dist/unprocessable-DAZbrDeR.mjs.map +1 -0
  69. package/dist/validate-Ok4krlkX.mjs +40 -0
  70. package/dist/validate-Ok4krlkX.mjs.map +1 -0
  71. package/package.json +28 -17
  72. package/src/bin/index.ts +13 -2
  73. package/src/dev.ts +10 -0
  74. package/src/form/formDataToRecord.ts +23 -0
  75. package/src/form/readForm.ts +71 -0
  76. package/src/form.ts +4 -0
  77. package/src/index.ts +53 -1
  78. package/src/nav/api.test-d.ts +79 -0
  79. package/src/nav/api.ts +104 -0
  80. package/src/nav/formSubmit.ts +18 -4
  81. package/src/nav/navigate.ts +40 -15
  82. package/src/nav/route.ts +38 -0
  83. package/src/nav.ts +3 -1
  84. package/src/openapi/docsHtml.ts +25 -0
  85. package/src/openapi/document.ts +154 -0
  86. package/src/openapi/plugin.ts +78 -0
  87. package/src/openapi/types.ts +82 -0
  88. package/src/openapi.ts +14 -0
  89. package/src/response/TypedResponse.ts +17 -0
  90. package/src/response/badRequest.ts +14 -2
  91. package/src/response/created.ts +13 -2
  92. package/src/response/found.ts +2 -2
  93. package/src/response/movedPermanently.ts +2 -2
  94. package/src/response/notModified.ts +2 -2
  95. package/src/response/ok.ts +13 -4
  96. package/src/response/response.ts +4 -4
  97. package/src/response/unprocessable.ts +14 -2
  98. package/src/run/depCache.ts +175 -0
  99. package/src/run/devPlugin.ts +128 -0
  100. package/src/run/prepareTemplate.ts +6 -3
  101. package/src/run/run.ts +63 -39
  102. package/src/run/runBuild.ts +63 -12
  103. package/src/run/runDev.ts +146 -58
  104. package/src/run/runOpenApi.ts +52 -0
  105. package/src/run/runPreview.ts +17 -26
  106. package/src/run/staleTorpCopies.ts +100 -0
  107. package/src/run.ts +2 -1
  108. package/src/schema.ts +7 -0
  109. package/src/server/CookieHelper.ts +17 -7
  110. package/src/server/Server.ts +54 -30
  111. package/src/server/ServerEvent.ts +24 -1
  112. package/src/server/connect/connectMiddleware.ts +44 -40
  113. package/src/server/connect/flattenHeaders.ts +1 -23
  114. package/src/server/connect/requestToNodeMessage.ts +6 -3
  115. package/src/server/types/MiddlewareFunction.ts +18 -4
  116. package/src/site/Router.ts +52 -41
  117. package/src/site/Site.ts +184 -10
  118. package/src/site/checkLayoutSlots.ts +114 -0
  119. package/src/site/checkRoutes.ts +435 -0
  120. package/src/site/clientEntry.ts +22 -9
  121. package/src/site/layoutSlots.ts +53 -0
  122. package/src/site/manifest.ts +125 -6
  123. package/src/site/serverEntry.ts +352 -133
  124. package/src/state/$page.ts +2 -1
  125. package/src/state/$serverPage.ts +22 -0
  126. package/src/test/runTest.ts +306 -118
  127. package/src/types/Adapter.ts +12 -0
  128. package/src/types/Jsonify.ts +20 -0
  129. package/src/types/PageData.test-d.ts +136 -0
  130. package/src/types/PageData.ts +35 -0
  131. package/src/types/PageEndPoint.ts +25 -9
  132. package/src/types/PageForm.test-d.ts +78 -0
  133. package/src/types/PageForm.ts +29 -0
  134. package/src/types/PageLoadEvent.ts +16 -4
  135. package/src/types/PageLoadReturn.ts +13 -0
  136. package/src/types/PageProps.ts +14 -0
  137. package/src/types/PageServerAction.ts +8 -2
  138. package/src/types/PageServerEndPoint.test-d.ts +105 -0
  139. package/src/types/PageServerEndPoint.ts +99 -5
  140. package/src/types/PageServerLoad.ts +11 -3
  141. package/src/types/ParseRouteParams.test-d.ts +84 -0
  142. package/src/types/ParseRouteParams.ts +64 -0
  143. package/src/types/Route.ts +20 -1
  144. package/src/types/RouteHandler.ts +8 -1
  145. package/src/types/ServerEndPoint.test-d.ts +77 -0
  146. package/src/types/ServerEndPoint.ts +148 -16
  147. package/src/types/ServerHook.ts +10 -3
  148. package/src/types/ServerLoadEvent.ts +48 -3
  149. package/src/types/ServerRequest.ts +10 -2
  150. package/src/types/SitePlugin.ts +24 -0
  151. package/src/types/StandardSchema.ts +109 -0
  152. package/src/utils/pathToRegex.ts +4 -2
  153. package/src/utils/pathTrie.ts +182 -0
  154. package/src/utils/searchParamsToRecord.ts +18 -0
  155. package/src/utils/torporPackages.ts +150 -0
  156. package/src/utils/tsconfigAliases.ts +90 -0
  157. package/src/validation/ValidationError.ts +18 -0
  158. package/src/validation/endpoint.ts +83 -0
  159. package/src/validation/validate.ts +26 -0
  160. package/dist/RouteType-B6BMOyYw.mjs.map +0 -1
  161. package/dist/Server-CF5wDJp6.d.mts.map +0 -1
  162. package/dist/ServerEvent-CxPwA4lH.mjs.map +0 -1
  163. package/dist/Site-DgC6WWn1.d.mts +0 -78
  164. package/dist/Site-DgC6WWn1.d.mts.map +0 -1
  165. package/dist/_page-BQs4WvCO.mjs.map +0 -1
  166. package/dist/connectMiddleware-D7nehjj3.mjs +0 -252
  167. package/dist/connectMiddleware-D7nehjj3.mjs.map +0 -1
  168. package/dist/pathToRegex-TUAMc3zS.mjs +0 -11
  169. package/dist/pathToRegex-TUAMc3zS.mjs.map +0 -1
  170. package/dist/response-C5TtAsh1.mjs.map +0 -1
  171. package/dist/run-DiZgkMnG.mjs +0 -332
  172. package/dist/run-DiZgkMnG.mjs.map +0 -1
  173. package/dist/seeOther-B4Yhu9iq.mjs.map +0 -1
  174. package/src/server/Routerx.ts +0 -72
  175. package/src/server/connect/bufferToArrayBuffer.ts +0 -8
  176. package/src/server/connect/readableToBuffer.ts +0 -16
@@ -0,0 +1,565 @@
1
+ import { a as CookieHelper, i as HeaderHelper, t as Server } from "./Server-C_IKav_e.mjs";
2
+ import { a as RouteParamsOf, n as ParseRouteParams, t as ExactRouteParams } from "./ParseRouteParams-DBmqlmLh.mjs";
3
+ import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
4
+ import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
5
+ import { Component } from "@torpor/view";
6
+ import { Plugin, UserConfig } from "vite";
7
+ //#region src/types/ServerLoadEvent.d.ts
8
+ /**
9
+ * The values read from a form submission: one value per field, or an array
10
+ * when a field was submitted with multiple values (e.g. a multi select).
11
+ */
12
+ type FormDataRecord = Record<string, FormDataEntryValue | FormDataEntryValue[]>;
13
+ /**
14
+ * The values read from a URL's query string: one string per param, or an
15
+ * array when a param was repeated.
16
+ */
17
+ type QueryRecord = Record<string, string | string[]>;
18
+ /**
19
+ * The event passed to server functions. Annotate with a route path to get
20
+ * typed params, e.g. `ServerLoadEvent<"/posts/[id]">`, and with a body type
21
+ * to get typed request bodies in API endpoints, e.g.
22
+ * `ServerLoadEvent<"/api/posts", { title: string }>` — which also types the
23
+ * `body` param of client calls made with `makeApi`.
24
+ */
25
+ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = unknown, FormBody = FormDataRecord, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> {
26
+ /**
27
+ * The URL for the server function.
28
+ */
29
+ url: URL;
30
+ /**
31
+ * Route params from the URL and route path. When the endpoint declares a
32
+ * `params` schema, the values are validated and typed by the schema's
33
+ * output.
34
+ */
35
+ params: Params;
36
+ /**
37
+ * Data that is available to functions in +server hooks, layouts, endpoints
38
+ * and pages. It flows down in that order.
39
+ */
40
+ appData: Record<string, any>;
41
+ /**
42
+ * The server request.
43
+ */
44
+ request: Request;
45
+ /**
46
+ * Reads the request body as JSON, typed by the event's `Body` annotation.
47
+ */
48
+ json: () => Promise<Body>;
49
+ /**
50
+ * Reads the request body as form data, returning a record of field values.
51
+ * When the endpoint declares a schema for the form, the values are
52
+ * validated and typed by the schema's output.
53
+ */
54
+ form: () => Promise<FormBody>;
55
+ /**
56
+ * Reads the URL's query string, returning a record of param values. When
57
+ * the endpoint declares a schema for the query (get/head handlers and the
58
+ * load function), the values are validated and typed by the schema's
59
+ * output.
60
+ */
61
+ query: () => Promise<QueryBody>;
62
+ /**
63
+ * A helper for getting and setting cookie data.
64
+ */
65
+ cookies: CookieHelper;
66
+ /**
67
+ * A helper for getting and setting headers.
68
+ */
69
+ headers: HeaderHelper;
70
+ /**
71
+ * An optional adapter object, containing adapter-specific functionality.
72
+ */
73
+ adapter: Record<PropertyKey, any>;
74
+ }
75
+ //#endregion
76
+ //#region src/types/ServerHook.d.ts
77
+ /**
78
+ * For _hook.server.
79
+ */
80
+ interface ServerHook<Route extends string | undefined = undefined> {
81
+ /**
82
+ * Called before each server request is handled. Return a Response to
83
+ * short-circuit the request, skipping the load, action or view rendering
84
+ * (e.g. a redirect for unauthenticated users).
85
+ */
86
+ enter?: (event: ServerLoadEvent<Route>) => Promise<Response | void> | Response | void;
87
+ /**
88
+ * Called after the request has been handled, even if the handler threw
89
+ * an error or the enter hook short-circuited it.
90
+ */
91
+ exit?: (event: ServerLoadEvent<Route>) => Promise<void> | void;
92
+ }
93
+ //#endregion
94
+ //#region src/types/Adapter.d.ts
95
+ interface Adapter {
96
+ prebuild?: (site: Site) => Promise<void> | void;
97
+ postbuild?: (site: Site) => Promise<void> | void;
98
+ /**
99
+ * Vite plugin(s) used to drive dev mode. The adapter owns where server code
100
+ * runs (e.g. the default Node runtime, or workerd via miniflare) and how
101
+ * requests reach it. When omitted, the framework's default Node-runtime dev
102
+ * plugin is used.
103
+ */
104
+ dev?: (site: Site) => Plugin | Plugin[] | void;
105
+ /**
106
+ * Serve the built output (preview). Receives a torpor Server configured to
107
+ * load the built server entry.
108
+ */
109
+ serve: (server: Server, site: Site) => void;
110
+ }
111
+ //#endregion
112
+ //#region src/types/SitePlugin.d.ts
113
+ /**
114
+ * A Torpor site plugin. A plugin is a function that receives the Site and
115
+ * sets itself up on it, typically by registering routes (e.g. an OpenAPI
116
+ * document endpoint) or adding configuration.
117
+ *
118
+ * Plugins are added to `site.plugins` in the site config file, and are run
119
+ * once when the config is loaded (for dev and build), and once when the
120
+ * server starts up in production:
121
+ *
122
+ * ```ts
123
+ * import { Site } from "@torpor/build";
124
+ * import { openApi } from "@torpor/build/openapi";
125
+ *
126
+ * const site = new Site();
127
+ * site.addRouteFolder("src/routes");
128
+ * site.plugins = [openApi()];
129
+ * export default site;
130
+ * ```
131
+ */
132
+ type SitePlugin = (site: Site) => void | Promise<void>;
133
+ //#endregion
134
+ //#region src/types/PageLoadEvent.d.ts
135
+ /**
136
+ * The event passed to client load functions. Annotate with a route path to
137
+ * get typed params, e.g. `PageLoadEvent<"/posts/[id]">`, and with a data type
138
+ * to type the data accumulated from the layouts above, e.g.
139
+ * `PageLoadEvent<"/posts/[id]", PageData<typeof layoutServer>>`.
140
+ */
141
+ interface PageLoadEvent<Route extends string | undefined = undefined, Data = Record<string, any>> {
142
+ /**
143
+ * The URL for the server function.
144
+ */
145
+ url: URL;
146
+ /**
147
+ * Route params from the URL and route path.
148
+ */
149
+ params: RouteParamsOf<Route>;
150
+ /**
151
+ * Data loaded by the layouts above, accumulated top down. Loads may add to
152
+ * it, and the merged result is passed into the page as `$props.data`.
153
+ */
154
+ data: Data;
155
+ }
156
+ //#endregion
157
+ //#region src/types/PageLoadReturn.d.ts
158
+ /**
159
+ * What a load function may return. When `Data` is provided, a typed response
160
+ * (e.g. `ok({ ... })`) must only contain keys the page expects; untyped
161
+ * responses (redirects, errors, plain text) are always allowed.
162
+ */
163
+ type PageLoadReturn<Data> = TypedResponse<Partial<Data>> | UntypedResponse | undefined | void;
164
+ //#endregion
165
+ //#region src/types/PageEndPoint.d.ts
166
+ /**
167
+ * For +page. Annotate with a route path to get typed params, and with a data
168
+ * shape to flag loads that return keys the page doesn't expect, e.g.
169
+ * `PageEndPoint<"/posts/[id]", PageData<typeof server>>`.
170
+ */
171
+ interface PageEndPoint<Route extends string | undefined = undefined, Data = Record<string, any>> {
172
+ /**
173
+ * Builds the route path for the page in a type-safe manner. The params
174
+ * object is checked for exact keys when `Route` is annotated.
175
+ *
176
+ * NOTE: The rest args conditional must stay INLINE — routing it through a
177
+ * type alias defeats `Params` inference, and excess keys stop being checked
178
+ */
179
+ route?: <Params extends RouteParamsOf<Route>>(...args: Route extends string ? string extends Route ? [params?: Record<string, string>] : keyof ParseRouteParams<Route> extends never ? [] : [params: Params & ExactRouteParams<Params, ParseRouteParams<Route>>] : [params?: Record<string, string>]) => string;
180
+ /**
181
+ * Loads data for the page.
182
+ */
183
+ load?: (event: PageLoadEvent<Route>) => PageLoadReturn<Data> | Promise<PageLoadReturn<Data>>;
184
+ /**
185
+ * The component that is displayed for the page.
186
+ */
187
+ component?: Component;
188
+ /**
189
+ * The head element data for the page, which may include a <title> and <meta> elements.
190
+ */
191
+ head?: HeadElement[] | ((event: PageLoadEvent<Route>) => HeadElement[]);
192
+ }
193
+ type HeadElement = TitleElement | MetaElement;
194
+ interface TitleElement {
195
+ title: string;
196
+ }
197
+ interface MetaElement {
198
+ name: string;
199
+ content: string;
200
+ }
201
+ //#endregion
202
+ //#region src/types/PageServerAction.d.ts
203
+ type PageServerAction<Route extends string | undefined = undefined, FormBody = FormDataRecord, Params = RouteParamsOf<Route>> = (event: ServerLoadEvent<Route, unknown, FormBody, QueryRecord, Params>) => Response | undefined | void | Promise<Response | undefined | void>;
204
+ //#endregion
205
+ //#region src/types/PageServerLoad.d.ts
206
+ type PageServerLoad<Route extends string | undefined = undefined, Data = Record<string, any>, QueryBody = QueryRecord, Params = RouteParamsOf<Route>> = (event: ServerLoadEvent<Route, unknown, FormDataRecord, QueryBody, Params>) => PageLoadReturn<Data> | Promise<PageLoadReturn<Data>>;
207
+ //#endregion
208
+ //#region src/types/PageServerEndPoint.d.ts
209
+ /**
210
+ * Optional standard schemas for +page.server endpoints, keyed by name. Any
211
+ * schema implementing the Standard Schema interface (zod, valibot, arktype,
212
+ * etc) can be used.
213
+ *
214
+ * - action name schemas validate the submitted form data, surfaced through
215
+ * `event.form()` in the action
216
+ * - the `load` key validates the URL's query string, surfaced through
217
+ * `event.query()` in the load function
218
+ * - a `params` key validates (and generally coerces) the route params,
219
+ * surfaced through `event.params` in the load function and actions
220
+ *
221
+ * When a submitted form or query string fails validation, the action or load
222
+ * function is not called and a 422 response with the schema's issues is
223
+ * returned (which becomes the page's `$props.form` for actions). When route
224
+ * params fail validation, a 404 response is returned, since the URL can't
225
+ * refer to an existing resource.
226
+ */
227
+ type PageServerActionSchemas = {
228
+ params?: StandardSchemaV1;
229
+ load?: StandardSchemaV1;
230
+ [action: string]: StandardSchemaV1 | undefined;
231
+ };
232
+ /**
233
+ * The form values type for an action, inferred from its schema. Falls back
234
+ * to a loose record for actions without a declared schema.
235
+ */
236
+ type ActionBody<Schemas extends PageServerActionSchemas, Name extends string> = [Name] extends [keyof Schemas & string] ? Schemas[Name] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schemas[Name]> : FormDataRecord : FormDataRecord;
237
+ /**
238
+ * The query type for the load function, inferred from its schema.
239
+ */
240
+ type LoadQuery<Schemas extends PageServerActionSchemas> = Schemas extends {
241
+ load: StandardSchemaV1;
242
+ } ? StandardSchemaV1.InferOutput<Schemas["load"]> : QueryRecord;
243
+ /**
244
+ * The route params type, inferred from the `params` schema.
245
+ */
246
+ type LoadParams<Schemas extends PageServerActionSchemas, Route extends string | undefined> = Schemas extends {
247
+ params: StandardSchemaV1;
248
+ } ? StandardSchemaV1.InferOutput<Schemas["params"]> : RouteParamsOf<Route>;
249
+ /**
250
+ * For +page.server. Annotate with a route path to get typed params, and with
251
+ * a data shape to flag loads that return keys the page doesn't expect, e.g.
252
+ * `PageServerEndPoint<"/posts/[id]", { posts: Post[] }>`. Annotate with a
253
+ * schemas object to get typed (and validated) form values, query strings and
254
+ * params, e.g. `PageServerEndPoint<"/posts", Record<string, any>, typeof schema>`.
255
+ */
256
+ interface PageServerEndPoint<Route extends string | undefined = undefined, Data = Record<string, any>, Schemas extends PageServerActionSchemas = PageServerActionSchemas> {
257
+ /**
258
+ * Loads data from the server for a page. Its schema (the `load` key)
259
+ * validates the URL's query string.
260
+ */
261
+ load?: PageServerLoad<Route, Data, LoadQuery<Schemas>, LoadParams<Schemas, Route>>;
262
+ /**
263
+ * A map of actions that can be performed on the server for a page, generally from a form submit.
264
+ */
265
+ actions?: { [Name in string]: PageServerAction<Route, ActionBody<Schemas, Name>, LoadParams<Schemas, Route>>; };
266
+ /**
267
+ * Optional standard schemas for validating requests, keyed by action name
268
+ * (plus `load` for the query string and `params` for the route params),
269
+ * e.g.
270
+ *
271
+ * ```ts
272
+ * const schema = {
273
+ * params: z.object({ id: z.coerce.number() }),
274
+ * load: z.object({ page: z.coerce.number() }),
275
+ * default: z.object({ title: z.string() }),
276
+ * };
277
+ * export default {
278
+ * schema,
279
+ * load: async ({ query }) => ok(await query()),
280
+ * actions: {
281
+ * default: async ({ form }) => ok((await form()).title),
282
+ * },
283
+ * } satisfies PageServerEndPoint<"/posts/[id]", Record<string, any>, typeof schema>;
284
+ * ```
285
+ */
286
+ schema?: Schemas | undefined;
287
+ }
288
+ //#endregion
289
+ //#region src/types/ServerRequest.d.ts
290
+ 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>;
291
+ //#endregion
292
+ //#region src/types/ServerEndPoint.d.ts
293
+ /**
294
+ * Optional standard schemas for +server endpoints, keyed by handler name.
295
+ * Any schema implementing the Standard Schema interface (zod, valibot,
296
+ * arktype, etc) can be used.
297
+ *
298
+ * - `get`/`head` schemas validate the URL's query string, surfaced through
299
+ * `event.query()`
300
+ * - `post`/`patch`/`put`/`del`/`options` schemas validate the JSON request
301
+ * body, surfaced through `event.json()`
302
+ * - a `params` schema validates (and generally coerces) the route params,
303
+ * surfaced through `event.params`
304
+ *
305
+ * When a request body or query string fails validation, the handler is not
306
+ * called and a 422 response with the schema's issues is returned. When route
307
+ * params fail validation, a 404 response is returned, since the URL can't
308
+ * refer to an existing resource.
309
+ */
310
+ type ServerEndPointSchemas = {
311
+ params?: StandardSchemaV1;
312
+ get?: StandardSchemaV1;
313
+ post?: StandardSchemaV1;
314
+ patch?: StandardSchemaV1;
315
+ put?: StandardSchemaV1;
316
+ del?: StandardSchemaV1;
317
+ options?: StandardSchemaV1;
318
+ head?: StandardSchemaV1;
319
+ };
320
+ /**
321
+ * The json body type for a handler, inferred from its schema. Falls back to
322
+ * `unknown` for handlers without a declared schema.
323
+ */
324
+ type SchemaBody<Schemas extends ServerEndPointSchemas, Method extends string> = [Method] extends [keyof Schemas & string] ? Schemas[Method] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schemas[Method]> : unknown : unknown;
325
+ /**
326
+ * The query type for a handler, inferred from its schema. Falls back to a
327
+ * loose record for handlers without a declared schema.
328
+ */
329
+ type SchemaQuery<Schemas extends ServerEndPointSchemas, Method extends string> = [Method] extends [keyof Schemas & string] ? Schemas[Method] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schemas[Method]> : QueryRecord : QueryRecord;
330
+ /**
331
+ * The route params type for an endpoint, inferred from its `params` schema.
332
+ * Falls back to the route's string params when no schema is declared.
333
+ */
334
+ type ParamsOf<Schemas extends {
335
+ params?: StandardSchemaV1;
336
+ }, Route extends string | undefined> = Schemas extends {
337
+ params: StandardSchemaV1;
338
+ } ? StandardSchemaV1.InferOutput<Schemas["params"]> : RouteParamsOf<Route>;
339
+ /**
340
+ * For +server. Annotate with a route path to get typed params, e.g.
341
+ * `ServerEndPoint<"/api/posts/[id]">`, and with a schemas object to get
342
+ * typed (and validated) request bodies, query strings and params, e.g.
343
+ * `ServerEndPoint<"/api/posts", typeof schema>`.
344
+ */
345
+ type ServerEndPoint<Route extends string | undefined = undefined, Schemas extends ServerEndPointSchemas = ServerEndPointSchemas> = {
346
+ /**
347
+ * Optional standard schemas for validating requests, keyed by handler
348
+ * name (plus a `params` schema for the route params), e.g.
349
+ *
350
+ * ```ts
351
+ * const schema = {
352
+ * params: z.object({ id: z.coerce.number() }),
353
+ * get: z.object({ sort: z.enum(["asc", "desc"]) }),
354
+ * post: z.object({ title: z.string() }),
355
+ * };
356
+ * export default {
357
+ * schema,
358
+ * get: async (event) => ok(await event.query()),
359
+ * post: async (event) => ok((await event.json()).title),
360
+ * } satisfies ServerEndPoint<"/api/posts/[id]", typeof schema>;
361
+ * ```
362
+ */
363
+ schema?: Schemas | undefined;
364
+ /**
365
+ * Performs a GET. Its schema validates the query string.
366
+ */
367
+ get?: ServerRequest<Route, unknown, FormDataRecord, SchemaQuery<Schemas, "get">, ParamsOf<Schemas, Route>>;
368
+ /**
369
+ * Performs a POST. Its schema validates the JSON request body.
370
+ */
371
+ post?: ServerRequest<Route, SchemaBody<Schemas, "post">, FormDataRecord, QueryRecord, ParamsOf<Schemas, Route>>;
372
+ /**
373
+ * Performs a PATCH. Its schema validates the JSON request body.
374
+ */
375
+ patch?: ServerRequest<Route, SchemaBody<Schemas, "patch">, FormDataRecord, QueryRecord, ParamsOf<Schemas, Route>>;
376
+ /**
377
+ * Performs a PUT. Its schema validates the JSON request body.
378
+ */
379
+ put?: ServerRequest<Route, SchemaBody<Schemas, "put">, FormDataRecord, QueryRecord, ParamsOf<Schemas, Route>>;
380
+ /**
381
+ * Performs a DELETE. Its schema validates the JSON request body.
382
+ */
383
+ del?: ServerRequest<Route, SchemaBody<Schemas, "del">, FormDataRecord, QueryRecord, ParamsOf<Schemas, Route>>;
384
+ /**
385
+ * Performs an OPTIONS request. Its schema validates the JSON request body.
386
+ */
387
+ options?: ServerRequest<Route, SchemaBody<Schemas, "options">, FormDataRecord, QueryRecord, ParamsOf<Schemas, Route>>;
388
+ /**
389
+ * Performs a HEAD request. Its schema validates the query string.
390
+ */
391
+ head?: ServerRequest<Route, unknown, FormDataRecord, SchemaQuery<Schemas, "head">, ParamsOf<Schemas, Route>>;
392
+ };
393
+ //#endregion
394
+ //#region src/types/RouteType.d.ts
395
+ declare const PAGE_ROUTE = 0;
396
+ declare const PAGE_SERVER_ROUTE = 1;
397
+ declare const SERVER_ROUTE = 3;
398
+ declare const LAYOUT_ROUTE = 4;
399
+ declare const LAYOUT_SERVER_ROUTE = 5;
400
+ declare const HOOK_ROUTE = 6;
401
+ declare const HOOK_SERVER_ROUTE = 7;
402
+ declare const ERROR_ROUTE = 8;
403
+ type RouteType = typeof PAGE_ROUTE | typeof PAGE_SERVER_ROUTE | typeof SERVER_ROUTE | typeof LAYOUT_ROUTE | typeof LAYOUT_SERVER_ROUTE | typeof HOOK_ROUTE | typeof HOOK_SERVER_ROUTE | typeof ERROR_ROUTE | -1;
404
+ //#endregion
405
+ //#region src/types/Route.d.ts
406
+ /**
407
+ * Any endpoint shape that can be stored inline on a Route.
408
+ */
409
+ type InlineEndPoint = PageServerEndPoint | ServerEndPoint | ServerHook | PageEndPoint;
410
+ /**
411
+ * A route that is added to the Site.
412
+ */
413
+ interface Route {
414
+ path: string;
415
+ /**
416
+ * The file for this route, relative to the site root. Omitted for inline
417
+ * endpoints (see `endPoint`).
418
+ */
419
+ file?: string;
420
+ /**
421
+ * For inline routes (defined in code rather than by file), the endpoint
422
+ * object itself. The shape depends on the route type
423
+ * (`PageServerEndPoint`, `ServerEndPoint`, `ServerHook`, etc.).
424
+ */
425
+ endPoint?: InlineEndPoint;
426
+ type: RouteType;
427
+ subFolder?: string;
428
+ }
429
+ //#endregion
430
+ //#region src/site/Site.d.ts
431
+ /**
432
+ * The Site class contains the information necessary to setup a @torpor/build
433
+ * site, including routes, plugins, and options.
434
+ */
435
+ declare class Site {
436
+ #private;
437
+ root: string;
438
+ routes: Route[];
439
+ /**
440
+ * Torpor site plugins, run when the site config is loaded (for dev and
441
+ * build) and when the server starts up. Use these to register extra
442
+ * routes (e.g. `openApi()` from `@torpor/build/openapi`) or add other
443
+ * framework-level functionality
444
+ */
445
+ plugins: SitePlugin[];
446
+ /**
447
+ * Vite plugins to add to the client and server builds
448
+ */
449
+ vitePlugins: Plugin[];
450
+ adapter: Adapter;
451
+ /**
452
+ * Extra inputs, as absolute file paths, that will be compiled with the
453
+ * output. What you do with them after that is up to you. File paths ending
454
+ * with server.ts/js will only be compiled with the server output
455
+ */
456
+ inputs: string[];
457
+ /**
458
+ * Vite config options to merge with the standard Torpor build options.
459
+ * `plugins` and `build.rollupOptions.input` will be overridden, so you
460
+ * should set `Site.vitePlugins` and `Site.inputs` instead. Other options may be
461
+ * overridden or incompatible, so experimentation may be required
462
+ */
463
+ viteConfig?: UserConfig;
464
+ /**
465
+ * The path to the site.config file. Set automatically by the CLI; used by
466
+ * the manifest plugin to import inline endpoints for server builds.
467
+ */
468
+ configFile?: string;
469
+ /**
470
+ * A state map for plugins to store their configuration and state on the
471
+ * site, so that framework internals (e.g. the manifest plugin) and other
472
+ * plugins can read them back:
473
+ *
474
+ * ```ts
475
+ * const myKey = Symbol.for("my-plugin");
476
+ * site.pluginState.set(myKey, options);
477
+ * ```
478
+ *
479
+ * Prefer `Symbol.for("...")` keys (or plain strings) over `Symbol()`,
480
+ * because the user's config file and framework internals can be loaded as
481
+ * separate module instances -- registry symbols are shared across
482
+ * instances, `Symbol()` ones are not.
483
+ */
484
+ pluginState: Map<PropertyKey, unknown>;
485
+ /**
486
+ * Inline endpoints keyed by `"path:type"`. Populated by `addRoute` when
487
+ * the user passes an inline endpoint object instead of a file path.
488
+ */
489
+ inlineEndPoints: Record<string, InlineEndPoint>;
490
+ constructor();
491
+ /**
492
+ * Adds a folder of routes, based on the names of the files in the folder
493
+ * @param folder The folder containing the routes
494
+ * @param subFolder If a subFolder is set, all routes in the folder will be
495
+ * placed under the subFolder, and only hooks, layouts etc will be used if
496
+ * they have the same subFolder. This can be used to create e.g. an `api`
497
+ * set of routes with their own hook for authorization from various clients
498
+ */
499
+ addRouteFolder(folder: string, subFolder?: string): Promise<void>;
500
+ /**
501
+ * Adds a file route, which can have a standard name (e.g. +page.ts) or any
502
+ * name if you pass the type
503
+ * @param path The route path
504
+ * @param file The file
505
+ * @param type The file type (if the file name is non-standard)
506
+ */
507
+ addRouteFile(path: string, file: string, type?: "+page" | "+page.server" | "+server" | "_layout" | "_layout.server" | "_hook" | "_hook.server" | "_error", subFolder?: string): void;
508
+ /**
509
+ * Adds a route in code, without needing the standard file naming
510
+ * conventions (+page.ts, +page.server.ts, etc). This is useful for small
511
+ * sites with one or two pages.
512
+ *
513
+ * Any combination of options may be provided; each maps to the
514
+ * corresponding file-route type:
515
+ *
516
+ * - `page` — a `+page` (`.torp` component or `.ts`/`.js` `PageEndPoint`)
517
+ * - `pageServer` — a `+page.server` (`PageServerEndPoint`, file or inline)
518
+ * - `server` — a `+server` HTTP endpoint (`ServerEndPoint`, file or inline)
519
+ * - `layout` — a `_layout` (`.torp` component or `.ts`/`.js` `PageEndPoint`)
520
+ * - `layoutServer` — a `_layout.server` (`PageServerEndPoint`, file or inline)
521
+ * - `hookServer` — a `_hook.server` (`ServerHook`, file or inline)
522
+ * - `error` — an `_error` page (`.torp` component or `.ts`/`.js` `PageEndPoint`)
523
+ *
524
+ * Options that need a component (`page`, `layout`, `error`) must be file
525
+ * paths so the component is included in the client bundle. Server-only
526
+ * options (`pageServer`, `server`, `layoutServer`, `hookServer`) accept
527
+ * either a file path or an inline object; inline server code is kept out
528
+ * of the client bundle automatically.
529
+ *
530
+ * @example
531
+ * // A page with an inline server action
532
+ * site.addRoute("/", {
533
+ * page: "./src/Counter.torp",
534
+ * pageServer: { actions: { set: async ({ request }) => ok() } },
535
+ * });
536
+ * @example
537
+ * // A JSON API endpoint
538
+ * site.addRoute("/api/time", {
539
+ * server: { get: async () => ok({ time: Date.now() }) },
540
+ * });
541
+ * @example
542
+ * // A root layout, server hook, and error page
543
+ * site.addRoute("/", {
544
+ * layout: "./src/Layout.torp",
545
+ * hookServer: { enter: async (event) => {} },
546
+ * error: "./src/ErrorPage.torp",
547
+ * });
548
+ *
549
+ * @param path The route path, e.g. `/` or `/about`
550
+ * @param options File paths and/or inline endpoints for the route
551
+ * @param subFolder An optional subFolder for grouping routes
552
+ */
553
+ addRoute(path: string, options: {
554
+ page?: string;
555
+ pageServer?: string | PageServerEndPoint;
556
+ server?: string | ServerEndPoint;
557
+ layout?: string;
558
+ layoutServer?: string | PageServerEndPoint;
559
+ hookServer?: string | ServerHook;
560
+ error?: string;
561
+ }, subFolder?: string): void;
562
+ }
563
+ //#endregion
564
+ export { ServerLoadEvent as C, QueryRecord as S, PageLoadEvent as _, ServerEndPoint as a, ServerHook as b, ActionBody as c, PageServerActionSchemas as d, PageServerEndPoint as f, PageLoadReturn as g, PageEndPoint as h, SchemaQuery as i, LoadParams as l, PageServerAction as m, ParamsOf as n, ServerEndPointSchemas as o, PageServerLoad as p, SchemaBody as r, ServerRequest as s, Site as t, LoadQuery as u, SitePlugin as v, FormDataRecord as x, Adapter as y };
565
+ //# sourceMappingURL=Site-CMa153FA.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Site-CMa153FA.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts","../src/types/ServerHook.ts","../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageLoadEvent.ts","../src/types/PageLoadReturn.ts","../src/types/PageEndPoint.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/site/Site.ts"],"mappings":"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"}
@@ -0,0 +1,100 @@
1
+ //#region src/types/StandardSchema.d.ts
2
+ /**
3
+ * The Standard Schema interface, per the spec at https://standardschema.dev.
4
+ *
5
+ * It is implemented by Zod, Valibot, ArkType, Effect Schema and others, so
6
+ * endpoints can validate request bodies with whichever library they prefer
7
+ * without this package depending on any of them.
8
+ */
9
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
10
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
11
+ }
12
+ declare namespace StandardSchemaV1 {
13
+ /** The Standard Schema props interface. */
14
+ export interface Props<Input = unknown, Output = Input> {
15
+ /**
16
+ * The Standard Schema version.
17
+ */
18
+ readonly version: 1;
19
+ /**
20
+ * The vendor name of the schema library.
21
+ */
22
+ readonly vendor: string;
23
+ /**
24
+ * Validates unknown input values and returns the parsed output.
25
+ */
26
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
27
+ /**
28
+ * Inferred types associated with the schema.
29
+ */
30
+ readonly types?: Types<Input, Output> | undefined;
31
+ }
32
+ /**
33
+ * The result of a validation: a success with a value, or a failure with
34
+ * issues.
35
+ */
36
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
37
+ /**
38
+ * The result of a successful validation.
39
+ */
40
+ export interface SuccessResult<Output> {
41
+ /**
42
+ * The typed output value.
43
+ */
44
+ readonly value: Output;
45
+ /**
46
+ * Only set when there are issues, so a success can be tested with
47
+ * `if (result.issues)`.
48
+ */
49
+ readonly issues?: undefined;
50
+ }
51
+ /**
52
+ * The result of a failed validation.
53
+ */
54
+ export interface FailureResult {
55
+ /**
56
+ * The issues detected during validation.
57
+ */
58
+ readonly issues: ReadonlyArray<Issue>;
59
+ }
60
+ /**
61
+ * An issue encountered during validation.
62
+ */
63
+ export interface Issue {
64
+ /**
65
+ * The error message.
66
+ */
67
+ readonly message: string;
68
+ /**
69
+ * The path to the property the issue belongs to.
70
+ */
71
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
72
+ }
73
+ /**
74
+ * A segment of the path to an issue.
75
+ */
76
+ export interface PathSegment {
77
+ /**
78
+ * The key of the property.
79
+ */
80
+ readonly key: PropertyKey;
81
+ }
82
+ /**
83
+ * The input and output types inferred from a schema.
84
+ */
85
+ export interface Types<Input = unknown, Output = Input> {
86
+ readonly input: Input;
87
+ readonly output: Output;
88
+ }
89
+ /**
90
+ * Infers the input type of a schema.
91
+ */
92
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
93
+ /**
94
+ * Infers the output type of a schema.
95
+ */
96
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
97
+ }
98
+ //#endregion
99
+ export { StandardSchemaV1 as t };
100
+ //# sourceMappingURL=StandardSchema-D28L8_zZ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardSchema-D28L8_zZ.d.mts","names":[],"sources":["../src/types/StandardSchema.ts"],"mappings":";;;;;;;;UAOiB,iBAAiB,iBAAiB,SAAS;WAClD,aAAa,iBAAiB,MAAM,OAAO;;kBAG5B;;mBAEP,MAAM,iBAAiB,SAAS;;;;aAIvC;;;;aAIA;;;;aAIA,WAAW,mBAAmB,OAAO,UAAU,QAAQ,OAAO;;;;aAI9D,QAAQ,MAAM,OAAO;;;;;;cAOnB,OAAO,UAAU,cAAc,UAAU;;;;mBAKpC,cAAc;;;;aAIrB,OAAO;;;;;aAKP;;;;;mBAMO;;;;aAIP,QAAQ,cAAc;;;;;mBAMf;;;;aAIP;;;;aAIA,OAAO,cAAc,cAAc;;;;;mBAM5B;;;;aAIP,KAAK;;;;;mBAME,MAAM,iBAAiB,SAAS;aACvC,OAAO;aACP,QAAQ;;;;;cAMN,WAAW,eAAe,oBAAoB,YACzD;;;;cAMW,YAAY,eAAe,oBAAoB,YAC1D"}