@k8ordo/framework 3.0.0 → 4.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 (55) hide show
  1. package/README.md +6 -4
  2. package/dist/cli.mjs +3 -3
  3. package/dist/generated.d.mts +12 -13
  4. package/dist/index.d.mts +3 -3
  5. package/dist/index.mjs +1 -1
  6. package/dist/paths-type-DXpmjaOr.d.mts +43 -0
  7. package/dist/runtime/app-router.mjs +1 -1
  8. package/dist/runtime/browser-payloads.mjs +1 -1
  9. package/dist/runtime/cookies.d.mts +2 -0
  10. package/dist/runtime/cookies.mjs +2 -1
  11. package/dist/runtime/ended.d.mts +7 -0
  12. package/dist/runtime/ended.mjs +14 -0
  13. package/dist/runtime/entry.browser.mjs +1 -1
  14. package/dist/runtime/entry.rsc.d.mts +17 -7
  15. package/dist/runtime/entry.rsc.mjs +42 -33
  16. package/dist/runtime/entry.ssr.d.mts +1 -0
  17. package/dist/runtime/entry.ssr.mjs +4 -3
  18. package/dist/runtime/guard.d.mts +15 -10
  19. package/dist/runtime/guard.mjs +8 -2
  20. package/dist/runtime/mount.mjs +1 -1
  21. package/dist/runtime/page-boundary.mjs +2 -2
  22. package/dist/runtime/params.d.mts +5 -4
  23. package/dist/runtime/params.mjs +2 -2
  24. package/dist/runtime/redirect.d.mts +13 -7
  25. package/dist/runtime/redirect.mjs +25 -9
  26. package/dist/runtime/request-scope.d.mts +37 -2
  27. package/dist/runtime/request-scope.mjs +60 -3
  28. package/dist/runtime/request.d.mts +6 -1
  29. package/dist/runtime/request.mjs +7 -2
  30. package/dist/runtime/route.d.mts +4 -2
  31. package/dist/runtime/route.mjs +13 -5
  32. package/dist/runtime/server.d.mts +5 -5
  33. package/dist/runtime/server.mjs +2 -2
  34. package/dist/runtime/shell.d.mts +2 -1
  35. package/dist/serve.d.mts +4 -0
  36. package/dist/serve.mjs +26 -13
  37. package/dist/{static-c-nX9Juk.d.mts → static-Be3xIqd8.d.mts} +19 -12
  38. package/dist/{static-file-BEk_xO5y.mjs → static-file-BS-WEiwu.mjs} +180 -136
  39. package/dist/{static-host-CyAmsL_7.mjs → static-host-tIDLqV8c.mjs} +1 -1
  40. package/dist/vercel.d.mts +18 -1
  41. package/dist/vercel.mjs +104 -7
  42. package/dist/vite.d.mts +6 -3
  43. package/dist/vite.mjs +155 -65
  44. package/docs/GUIDE.md +149 -21
  45. package/docs/llms.txt +102 -47
  46. package/docs/references/actions.md +14 -5
  47. package/docs/references/boundaries.md +23 -2
  48. package/docs/references/csp.md +91 -2
  49. package/docs/references/deploy.md +85 -16
  50. package/docs/references/errors.md +18 -10
  51. package/docs/references/guards.md +100 -29
  52. package/docs/references/params.md +91 -22
  53. package/docs/references/routing.md +171 -31
  54. package/package.json +15 -10
  55. package/dist/paths-type-DtsL8JuC.d.mts +0 -19
@@ -16,6 +16,7 @@ const CONVENTION = {
16
16
  };
17
17
  const ROUTE_FILES = Object.keys(CONVENTION).join(", ");
18
18
  const PARAM = /^\[([A-Za-z_][A-Za-z0-9_]*)\]$/u;
19
+ const REST = /^\[\.\.\.([A-Za-z_][A-Za-z0-9_]*)\]$/u;
19
20
  const GROUP = /^\(([A-Za-z0-9_-]+)\)$/u;
20
21
  const LITERAL = /^[A-Za-z0-9._~-]+$/u;
21
22
  /**
@@ -37,6 +38,17 @@ const slotOf = (file) => {
37
38
  if (basename === void 0) return null;
38
39
  return CONVENTION[basename] ?? null;
39
40
  };
41
+ /**
42
+ * The `[...name]` directory a route file sits in, relative to the routes
43
+ * root — `null` for a file in none, or one the grammar does not read. One
44
+ * module at a time, like `slotOf`.
45
+ */
46
+ const restDirOf = (file) => {
47
+ const segments = file.split("/").filter((segment) => segment !== "");
48
+ if (segments.some((segment) => isHidden(segment))) return null;
49
+ const index = segments.slice(0, -1).findIndex((segment) => REST.test(segment));
50
+ return index === -1 ? null : segments.slice(0, index + 1).join("/");
51
+ };
40
52
  const emptyDir = () => ({
41
53
  files: /* @__PURE__ */ new Map(),
42
54
  dirs: /* @__PURE__ */ new Map()
@@ -68,12 +80,22 @@ const classify = (name, path, problems) => {
68
80
  key: `/:${param[1]}`,
69
81
  param: param[1]
70
82
  };
83
+ const rest = REST.exec(name);
84
+ if (rest !== null) return {
85
+ kind: "rest",
86
+ key: `/:${rest[1]}+`,
87
+ param: rest[1]
88
+ };
71
89
  if (GROUP.exec(name) !== null) return {
72
90
  kind: "group",
73
91
  key: `/${name}`,
74
92
  param: null
75
93
  };
76
- if (name.startsWith("[") || name.endsWith("]")) problems.push({
94
+ if (name.startsWith("[...")) problems.push({
95
+ path,
96
+ message: `"${name}" is not a valid rest directory — use [...name] with a letter or underscore first`
97
+ });
98
+ else if (name.startsWith("[") || name.endsWith("]")) problems.push({
77
99
  path,
78
100
  message: `"${name}" is not a valid param directory — use [name] with a letter or underscore first`
79
101
  });
@@ -121,11 +143,24 @@ const convert = (raw, name, path, kind, key, problems) => {
121
143
  path: slots.paths,
122
144
  message: `paths.ts gives the values of its directory's parameter, and "${here}" is not a [param] directory — move it into the parameter's directory`
123
145
  });
146
+ if (kind === "rest" && slots.notFound !== void 0) problems.push({
147
+ path: slots.notFound,
148
+ message: `not-found.tsx answers what nothing below its directory did, and nothing is below "${here}" — [...${name.slice(4, -1)}] takes the rest of the pathname; move it one directory up`
149
+ });
124
150
  const children = [...raw.dirs.entries()].map(([childName, childRaw]) => {
125
151
  const childPath = path === "" ? childName : `${path}/${childName}`;
152
+ if (kind === "rest") problems.push({
153
+ path: childPath,
154
+ message: `"${name}" takes the rest of the pathname, so it is the last directory of its path — move "${childName}" out of "${here}"`
155
+ });
126
156
  const classified = classify(childName, childPath, problems);
127
157
  return convert(childRaw, childName, childPath, classified.kind, classified.key, problems);
128
158
  });
159
+ const rests = children.filter((child) => child.kind === "rest");
160
+ for (const other of rests.slice(1)) problems.push({
161
+ path: other.path,
162
+ message: `"${other.name}" cannot sit beside "${rests[0]?.name ?? ""}" — each takes the rest of the pathname below "${here}"; keep one`
163
+ });
129
164
  return {
130
165
  name,
131
166
  kind,
@@ -144,6 +179,12 @@ const convert = (raw, name, path, kind, key, problems) => {
144
179
  children
145
180
  };
146
181
  };
182
+ /** The param a directory names — `id` for `[id]`, `path` for `[...path]` — or `null`. */
183
+ const paramOf = (dir) => {
184
+ if (dir.kind === "param") return dir.key.slice(2);
185
+ if (dir.kind === "rest") return dir.key.slice(2, -1);
186
+ return null;
187
+ };
147
188
  const declaresRoute = (dir) => dir.page !== null || dir.route !== null || dir.notFound !== null || dir.redirect !== null || dir.children.some(declaresRoute);
148
189
  /**
149
190
  * Walks the tree the way the router's own table walk does, so the patterns
@@ -183,6 +224,7 @@ const checkFallback = (dir, file, pattern, params, above) => {
183
224
  path: file,
184
225
  message
185
226
  } });
227
+ if (dir.kind === "rest") return refuse(`fallback.tsx is the shell a build into files answers a parameter's unwritten values with, and "${here}" is a [...name] directory, which no build into files writes; remove it`);
186
228
  if (dir.page === null) return refuse(`fallback.tsx stands in for the page.tsx beside it, and "${here}" has none`);
187
229
  if (dir.layout !== null) return refuse(`fallback.tsx cannot sit beside layout.tsx — that layout receives every parameter of "${here}", so no shell could leave one to the browser; move the layout one directory up, or into page.tsx and fallback.tsx`);
188
230
  if (params.length === 0) return refuse(`fallback.tsx stands in for values the build did not write, and "${pattern}" has no parameter; remove it`);
@@ -209,7 +251,8 @@ const checkFallbacks = (tree) => {
209
251
  const walk = (dir, prefix, inherited, above) => {
210
252
  if (!declaresRoute(dir)) return;
211
253
  const here = dir.kind === "root" ? "" : prefix;
212
- const params = dir.kind === "param" ? [...inherited, dir.key.slice(2)] : inherited;
254
+ const own = paramOf(dir);
255
+ const params = own === null ? inherited : [...inherited, own];
213
256
  if (dir.fallback !== null) found.push(checkFallback(dir, dir.fallback, here === "" ? "/" : here, params, above));
214
257
  const below = dir.layout === null ? above : {
215
258
  file: dir.layout,
@@ -229,8 +272,8 @@ const fallbackShapes = (tree) => checkFallbacks(tree).flatMap((each) => each.sha
229
272
  const validate = (root, problems) => {
230
273
  const walk = (dir, inherited) => {
231
274
  let params = inherited;
232
- if (dir.kind === "param") {
233
- const name = dir.key.slice(2);
275
+ const name = paramOf(dir);
276
+ if (name !== null) {
234
277
  if (params.includes(name)) problems.push({
235
278
  path: dir.path,
236
279
  message: `":${name}" is already taken by an ancestor — params must be unique within a path`
@@ -273,6 +316,14 @@ const parseRouteTree = (files) => {
273
316
  problems
274
317
  };
275
318
  };
319
+ // ../framework-engine/dist/host.mjs
320
+ /**
321
+ * The package the application actually installed. This engine is bundled
322
+ * into it rather than published on its own, so it is the only name
323
+ * resolvable from the project root: anything the optimizer is asked to
324
+ * prebundle is addressed through it, and the generated files name it.
325
+ */
326
+ const FRAMEWORK = "@k8ordo/framework";
276
327
  // ../framework-engine/dist/runtime/route.mjs
277
328
  /** The request methods a `route.ts` answers by exporting a function named so. */
278
329
  const ROUTE_METHODS = [
@@ -284,14 +335,6 @@ const ROUTE_METHODS = [
284
335
  "DELETE",
285
336
  "OPTIONS"
286
337
  ];
287
- // ../framework-engine/dist/host.mjs
288
- /**
289
- * The package the application actually installed. This engine is bundled
290
- * into it rather than published on its own, so it is the only name
291
- * resolvable from the project root: anything the optimizer is asked to
292
- * prebundle is addressed through it, and the generated files name it.
293
- */
294
- const FRAMEWORK = "@k8ordo/framework";
295
338
  // ../framework-engine/dist/generate/emit.mjs
296
339
  /** What answers a directory's own URL: its page, or its route.ts. */
297
340
  const ownFile = (dir) => dir.page ?? dir.route;
@@ -309,22 +352,25 @@ const placeOf = (dir) => ownFile(dir) ?? dir.redirect;
309
352
  */
310
353
  const isLeaf = (dir) => dir.kind !== "group" && placeOf(dir) !== null && dir.layout === null && dir.error === null && dir.loading === null && dir.notFound === null && dir.children.length === 0;
311
354
  /**
312
- * What a subtree offers the matcher first: a literal, a parameter, or only a
313
- * catch-all. A group contributes its children's URLs rather than one of its
314
- * own, so it ranks as whatever the best of them is — otherwise a `[slug]`
315
- * tucked inside a group would still be tried before a literal sibling.
355
+ * What a subtree offers the matcher first: a literal, a parameter, a rest
356
+ * parameter, or only a catch-all. A group contributes its children's URLs
357
+ * rather than one of its own, so it ranks as whatever the best of them is —
358
+ * otherwise a `[slug]` tucked inside a group would still be tried before a
359
+ * literal sibling.
316
360
  */
317
361
  const rank = (dir) => {
318
362
  if (dir.kind === "param") return 1;
363
+ if (dir.kind === "rest") return 2;
319
364
  if (dir.kind !== "group") return 0;
320
365
  const children = dir.children.map(rank);
321
366
  if (dir.page !== null) children.push(0);
322
- if (dir.notFound !== null) children.push(2);
323
- return Math.min(...children, 2);
367
+ if (dir.notFound !== null) children.push(3);
368
+ return Math.min(...children, 3);
324
369
  };
325
370
  /**
326
- * Literal segments before parameters, and otherwise the order the directories
327
- * came in. The table matches in declaration order, and the directories arrive
371
+ * Literal segments before parameters, a parameter before a rest parameter —
372
+ * `[...path]` also takes the one segment `[id]` takes, so it comes after or
373
+ * `[id]` never answers — and otherwise the order the directories came in. The table matches in declaration order, and the directories arrive
328
374
  * sorted by name — under which `[slug]` precedes `about`, because `[` sorts
329
375
  * before letters. Left alone, the most ordinary layout there is would make
330
376
  * `/about` unreachable behind `/:slug`.
@@ -424,6 +470,8 @@ const ROUTE_REQUEST_FROM = `${FRAMEWORK}/server`;
424
470
  const I18N = "@k8ordo/i18n";
425
471
  /** Where an application declares its locale set, from its root. */
426
472
  const LOCALES_MODULE = "src/i18n.ts";
473
+ /** Where an application's route files live, from its root. */
474
+ const ROUTES_DIR = "src/routes";
427
475
  const bannerFrom = (...sources) => `// Generated by ${FRAMEWORK} from ${sources.join(" and ")}. Do not edit.`;
428
476
  const sanitize = (path) => {
429
477
  const base = path.replace(/\.[jt]sx?$/u, "").replaceAll(/[^A-Za-z0-9]+/gu, "_").replaceAll(/^_+|_+$/gu, "");
@@ -477,7 +525,9 @@ const believed = (name, asserted) => {
477
525
  * the render's context and never refuse it — a catch-all answers what nothing
478
526
  * else did, so its params stay strings. A fallback's carries the layouts'
479
527
  * above it too: a shell runs them over the params it fills, and its page's
480
- * own never, since a shell has no value.
528
+ * own never, since a shell has no value. A paths.ts's carries only the
529
+ * layouts' above its directory: a layout in its own directory, and the page
530
+ * beside it, may read the parameter it is asked for, which has no value yet.
481
531
  */
482
532
  const beliefs = (tree, withParams) => {
483
533
  const found = /* @__PURE__ */ new Map();
@@ -516,6 +566,11 @@ const beliefs = (tree, withParams) => {
516
566
  kind: "fallback",
517
567
  schemas: layoutSchemas
518
568
  });
569
+ if (dir.paths !== null) found.set(dir.paths, {
570
+ pattern: own,
571
+ kind: "paths",
572
+ schemas: inherited
573
+ });
519
574
  for (const child of dir.children) walk(child, child.kind === "group" ? here : `${here}${child.key}`, layoutSchemas);
520
575
  };
521
576
  walk(tree, "", []);
@@ -584,7 +639,8 @@ const emitRoutesModule = (tree, options) => {
584
639
  }));
585
640
  const shells = options.mode === "static" ? fallbackShapes(tree) : [];
586
641
  for (const shape of shells) namer.take(shape.file);
587
- const supplies = options.mode === "static" ? pathsFiles(tree) : [];
642
+ const typedSupplies = pathsFiles(tree);
643
+ const supplies = options.mode === "static" ? typedSupplies : [];
588
644
  for (const supply of supplies) namer.take(supply.file);
589
645
  const guarded = guardsOf(tree);
590
646
  const guardStacks = new Map([...guarded.stacks].map(([pattern, files]) => [pattern, files.map((file) => namer.take(file))]));
@@ -631,6 +687,11 @@ const emitRoutesModule = (tree, options) => {
631
687
  const routeChecks = routeFiles.map(({ pattern, name }) => stacks.has(pattern) ? `${pad(1)}Checked<Loaded<typeof ${name}>, RouteModule<'${pattern}', ParamSchemas['${pattern}']>>,` : `${pad(1)}Checked<Loaded<typeof ${name}>, RouteModule<'${pattern}'>>,`);
632
688
  const fallbackChecks = shells.map(({ file }) => `${pad(1)}Checked<Loaded<typeof ${namer.take(file)}>['default'], ComponentType>,`);
633
689
  const pathsChecks = supplies.map(({ pattern, file }) => `${pad(1)}Checked<Loaded<typeof ${namer.take(file)}>['default'], Paths<'${pattern}'>>,`);
690
+ const layoutSchemasOf = (file) => byFile.get(file).schemas.map((layout) => schemaName(namer.take(layout)));
691
+ const pathsSchemas = [...Map.groupBy(typedSupplies, ({ pattern }) => pattern)].map(([pattern, files]) => {
692
+ const tuples = new Set(files.map(({ file }) => `[${layoutSchemasOf(file).map((schema) => `typeof ${schema}`).join(", ")}]`));
693
+ return `${pad(1)}'${pattern}': ${[...tuples].join(" | ")};`;
694
+ });
634
695
  const hasChecks = schemaChecks.length + routeChecks.length + fallbackChecks.length + pathsChecks.length + guardChecks.length > 0;
635
696
  const readsLate = routeFiles.length > 0 || shells.length > 0 || supplies.length > 0 || searchReaders.size > 0 || [...namer.names.keys()].some((file) => withParams.has(file) && isLate(file));
636
697
  const hasRoutes = routeFiles.length > 0;
@@ -818,7 +879,7 @@ const emitRoutesModule = (tree, options) => {
818
879
  `${pad(1)}'${pattern}': {`,
819
880
  `${pad(2)}load: ${namer.take(file)},`,
820
881
  `${pad(2)}open: [${open.map((param) => `'${param}'`).join(", ")}],`,
821
- `${pad(2)}schemas: [${byFile.get(file).schemas.map((layout) => schemaName(namer.take(layout))).join(", ")}],`,
882
+ `${pad(2)}schemas: [${layoutSchemasOf(file).join(", ")}],`,
822
883
  `${pad(1)}},`
823
884
  ]),
824
885
  "} as const;",
@@ -833,9 +894,16 @@ const emitRoutesModule = (tree, options) => {
833
894
  "",
834
895
  ...options.mode === "static" ? [
835
896
  "// Per paths.ts, by its file: what reads the values its directory's",
836
- "// parameter takes. Only the build asks.",
897
+ "// parameter takes, and the schemas of the layouts above its directory,",
898
+ "// which read the params above before it is asked. The build and",
899
+ "// `vite dev` ask through `pathValues`.",
837
900
  "export const paths = {",
838
- ...supplies.map(({ file }) => `${pad(1)}'${file}': ${namer.take(file)},`),
901
+ ...supplies.flatMap(({ file }) => [
902
+ `${pad(1)}'${file}': {`,
903
+ `${pad(2)}load: ${namer.take(file)},`,
904
+ `${pad(2)}schemas: [${layoutSchemasOf(file).join(", ")}],`,
905
+ `${pad(1)}},`
906
+ ]),
839
907
  "} as const;",
840
908
  ...pathsChecks.length > 0 ? [
841
909
  "",
@@ -846,6 +914,12 @@ const emitRoutesModule = (tree, options) => {
846
914
  ] : []
847
915
  ] : ["// A running server renders whatever value arrives: no values to list.", "export const paths = {} as const;"],
848
916
  "",
917
+ "// What a paths.ts receives, by its directory's pattern: the params above",
918
+ "// it as the layouts above its directory read them.",
919
+ "export type PathsSchemas = {",
920
+ ...pathsSchemas,
921
+ "};",
922
+ "",
849
923
  "export const routes = defineRoutes({",
850
924
  ...body,
851
925
  "});",
@@ -853,15 +927,13 @@ const emitRoutesModule = (tree, options) => {
853
927
  ].join("\n");
854
928
  };
855
929
  /**
856
- * Both packages read the app's route table through declaration merging, so
857
- * the app gets typed paths everywhere without writing the ceremony itself.
858
- * The router's `Register` is augmented through the framework's re-export of
859
- * it, which TypeScript merges into the router's own declaration. The locale
860
- * set reaches `@k8ordo/i18n`'s `Register` the same way, so every message is
861
- * held to it.
930
+ * The router reads the app's route table through declaration merging, so the
931
+ * app gets typed links everywhere without writing the ceremony itself. Its
932
+ * `Register` is augmented through the framework's re-export of it, which
933
+ * TypeScript merges into the router's own declaration. The locale set reaches
934
+ * `@k8ordo/i18n`'s `Register` the same way, so every message is held to it.
862
935
  */
863
936
  const emitRegisterModule = (options) => {
864
- const wantsState = options.stateModule !== null && options.stateModule !== void 0;
865
937
  const localesModule = options.localesModule ?? null;
866
938
  const withRequest = options.mode === "server";
867
939
  const lines = [
@@ -870,22 +942,22 @@ const emitRegisterModule = (options) => {
870
942
  `import type { ParsedParamsMap } from '${GENERATED_FROM}';`,
871
943
  ...withRequest ? [`import type { RouteRequest } from '${ROUTE_REQUEST_FROM}';`] : [],
872
944
  ...localesModule === null ? [] : [`import type { LocaleOf } from '${I18N}';`],
873
- ...wantsState ? [`import type {} from '${options.stateModule}';`] : [],
874
945
  ...localesModule === null ? [] : [`import type { locales } from '${localesModule}';`],
875
- `import type { ParamSchemas, routes, SearchReads } from '${options.routesModule}';`,
946
+ `import type { ParamSchemas, PathsSchemas, routes, SearchReads } from '${options.routesModule}';`,
876
947
  "",
877
948
  `declare module '${GENERATED_FROM}' {`,
878
949
  " interface Register {",
879
950
  " routes: typeof routes;",
880
951
  " // A link takes a param as the page receives it — typed by its schema.",
881
952
  " params: ParsedParamsMap<ParamSchemas>;",
953
+ " // A paths.ts receives the params above it as the layouts above read them.",
954
+ " pathsParams: ParsedParamsMap<PathsSchemas>;",
882
955
  " // A page that exports `search` receives what it reads.",
883
956
  " search: SearchReads;",
884
957
  ...withRequest ? [" // A route file receives the request: this is a running server.", " request: RouteRequest;"] : [],
885
958
  " }",
886
959
  "}"
887
960
  ];
888
- if (wantsState) lines.push("", `declare module '${options.stateModule}' {`, " interface Register {", " routes: typeof routes;", " }", "}");
889
961
  if (localesModule !== null) lines.push("", `declare module '${I18N}' {`, " interface Register {", " locale: LocaleOf<typeof locales>;", " }", "}");
890
962
  lines.push("");
891
963
  return lines.join("\n");
@@ -969,12 +1041,12 @@ const readServerStylesheets = (value) => JSON.parse(decodeURIComponent(value));
969
1041
  const CLIENT_FILES_PATH = "/client-files.json";
970
1042
  // src/paths.ts
971
1043
  /**
972
- * Every pattern the table declares — pages, redirects and catch-alls — in
973
- * the order the matcher will try them. The engine's one walk, so the build
974
- * and the prerenderer agree; a redirect is a URL the site has, so it is a
975
- * file the site writes.
1044
+ * Every pattern the table declares that answers a URL of its own — pages,
1045
+ * route.ts and redirects, not the catch-alls — in the order the matcher
1046
+ * will try them. The engine's one walk, so the build and the prerenderer
1047
+ * agree; a redirect is a URL the site has, so it is a file the site writes.
976
1048
  */
977
- const patternsOf = (dir) => declaredPatterns(dir).map((each) => each.pattern);
1049
+ const answeringPatterns = (dir) => declaredPatterns(dir).filter((each) => each.kind !== "notFound");
978
1050
  /** A `:name` segment: a parameter a pattern, or a shell location, leaves open. */
979
1051
  const PARAM_SEGMENT = /^:[A-Za-z_]\w*$/u;
980
1052
  const isParamSegment = (segment) => PARAM_SEGMENT.test(segment);
@@ -989,7 +1061,7 @@ const isConcrete = (pattern) => !pattern.includes("*") && !pattern.split("/").so
989
1061
  * be represented: whichever one the build picked, the other would never be
990
1062
  * served. The build says so rather than choosing.
991
1063
  */
992
- const catchAllPatterns = (dir) => patternsOf(dir).filter((pattern) => pattern.endsWith("/*"));
1064
+ const catchAllPatterns = (dir) => declaredPatterns(dir).filter((each) => each.kind === "notFound").map((each) => each.pattern);
993
1065
  /** A table with more than one catch-all, which no static host can serve. */
994
1066
  const catchAllRefusals = (dir) => {
995
1067
  const catchAlls = catchAllPatterns(dir);
@@ -1012,7 +1084,7 @@ const catchAllPath = (dir) => {
1012
1084
  const [pattern] = catchAllPatterns(dir);
1013
1085
  if (pattern === void 0) return null;
1014
1086
  const prefix = pattern.slice(0, -2).split("/").filter(Boolean).map((segment) => segment.startsWith(":") ? NOT_FOUND_SEGMENT : segment);
1015
- const depth = Math.max(prefix.length + 1, ...patternsOf(dir).filter((each) => !each.endsWith("/*")).map((each) => each.split("/").filter(Boolean).length + 1));
1087
+ const depth = Math.max(prefix.length + 1, ...answeringPatterns(dir).map(({ pattern: each }) => each.split("/").filter(Boolean).length + 1));
1016
1088
  const filler = Array.from({ length: depth - prefix.length }, () => NOT_FOUND_SEGMENT);
1017
1089
  return `/${[...prefix, ...filler].join("/")}`;
1018
1090
  };
@@ -1020,7 +1092,7 @@ const catchAllPath = (dir) => {
1020
1092
  * The patterns the build cannot answer on its own. A catch-all is excluded:
1021
1093
  * it is rendered as the not-found file, never as a page of its own.
1022
1094
  */
1023
- const patternsNeedingPaths = (dir) => patternsOf(dir).filter((pattern) => !isConcrete(pattern) && !pattern.endsWith("/*"));
1095
+ const patternsNeedingPaths = (dir) => answeringPatterns(dir).map((each) => each.pattern).filter((pattern) => !isConcrete(pattern));
1024
1096
  /**
1025
1097
  * A shell location's pathname: each segment it leaves to the browser replaced
1026
1098
  * by the reserved one. `/ja/posts/:id` → `/ja/posts/!fallback`.
@@ -1029,21 +1101,6 @@ const shellPathname = (location) => location.split("/").map((segment) => isParam
1029
1101
  /** The params a shell location still holds, in order. */
1030
1102
  const unknownOf = (location) => location.split("/").filter((segment) => isParamSegment(segment)).map((segment) => segment.slice(1));
1031
1103
  /**
1032
- * Whether a location is one the pattern answers, segment by segment: a
1033
- * literal needs the same literal; a parameter takes a value, or the same
1034
- * `:name` left open — any `:name`, when names are not compared.
1035
- */
1036
- const fits = (pattern, location, byName = true) => {
1037
- const wanted = pattern.split("/");
1038
- const given = location.split("/");
1039
- if (wanted.length !== given.length) return false;
1040
- return wanted.every((segment, index) => {
1041
- const at = given[index];
1042
- if (!isParamSegment(segment)) return segment === at;
1043
- return !isParamSegment(at) || !byName || at === segment;
1044
- });
1045
- };
1046
- /**
1047
1104
  * Static rendering cannot invent parameter values, and quietly shipping a
1048
1105
  * site missing half its pages is worse than refusing to build one. Every
1049
1106
  * parameterised pattern must be covered by a supplied path — or, for a page
@@ -1051,82 +1108,54 @@ const fits = (pattern, location, byName = true) => {
1051
1108
  * build did not write.
1052
1109
  *
1053
1110
  * The other direction counts too: a supplied path nothing matched is a typo
1054
- * that would cost exactly the page it was meant to add, and a supplied value
1055
- * that still contains a parameter (`/ja/blog/:slug` — what expanding only one
1056
- * of two parameters leaves behind) would be written to disk as a directory
1057
- * literally named `:slug` — unless its page has a fallback.tsx, when it is
1058
- * where that shell stands. URLPattern accepts both, so this has to say no.
1059
- *
1060
- * A location goes to the first pattern in table order it fits, which is the
1061
- * pattern whose URLs a host's rule for it will catch.
1111
+ * that would cost exactly the page it was meant to add, so it is named.
1062
1112
  */
1063
1113
  const planPaths = (tree, supplied) => {
1064
- const patterns = patternsOf(tree);
1065
- const declared = declaredPatterns(tree).filter((each) => each.kind !== "notFound");
1114
+ const declared = answeringPatterns(tree);
1066
1115
  const shapes = new Map(fallbackShapes(tree).map((shape) => [shape.pattern, shape]));
1067
- const paths = patterns.filter((pattern) => isConcrete(pattern));
1116
+ const paths = declared.map((each) => each.pattern).filter((pattern) => isConcrete(pattern));
1068
1117
  const unresolved = [];
1069
1118
  const unusable = [];
1070
- const held = [];
1071
- const misnamed = [];
1072
1119
  const closed = [];
1073
1120
  const reserved = [];
1074
1121
  const located = /* @__PURE__ */ new Map();
1075
1122
  const offered = /* @__PURE__ */ new Set();
1123
+ const keptForShells = (path) => path.split("/").some((segment) => decodePathname(segment) === FALLBACK_SEGMENT);
1076
1124
  const usable = [];
1077
- for (const raw of supplied) {
1125
+ for (const raw of supplied.paths) {
1078
1126
  const path = normalizePathname(raw);
1079
- if (path.split("/").some((segment) => decodePathname(segment) === "!fallback")) {
1080
- reserved.push(path);
1081
- continue;
1082
- }
1083
- if (isConcrete(path)) {
1084
- usable.push(path);
1085
- continue;
1086
- }
1087
- if (path.includes("*")) {
1088
- unusable.push(path);
1089
- continue;
1090
- }
1091
- const first = declared.find((each) => fits(each.pattern, path));
1092
- if (first === void 0) {
1093
- const loosely = declared.find((each) => fits(each.pattern, path, false));
1094
- if (loosely === void 0) unusable.push(path);
1095
- else misnamed.push({
1096
- location: path,
1097
- pattern: loosely.pattern
1098
- });
1099
- continue;
1100
- }
1101
- const shape = shapes.get(first.pattern);
1102
- if (shape === void 0) {
1103
- held.push({
1104
- location: path,
1105
- file: first.file
1106
- });
1127
+ if (keptForShells(path)) reserved.push(path);
1128
+ else usable.push(path);
1129
+ }
1130
+ for (const { location: raw, pattern } of supplied.shells) {
1131
+ const location = normalizePathname(raw);
1132
+ if (keptForShells(location)) {
1133
+ reserved.push(location);
1107
1134
  continue;
1108
1135
  }
1109
- offered.add(first.pattern);
1110
- const outside = unknownOf(path).filter((name) => !shape.open.includes(name));
1136
+ const shape = shapes.get(pattern);
1137
+ if (shape === void 0) throw new TypeError(`${location} is a shell location for ${pattern}, whose page has no fallback.tsx`);
1138
+ offered.add(pattern);
1139
+ const outside = unknownOf(location).filter((name) => !shape.open.includes(name));
1111
1140
  if (outside.length > 0) {
1112
1141
  closed.push({
1113
- location: path,
1142
+ location,
1114
1143
  params: outside,
1115
1144
  layout: shape.layout ?? "",
1116
1145
  supplied: true
1117
1146
  });
1118
1147
  continue;
1119
1148
  }
1120
- located.set(first.pattern, [...located.get(first.pattern) ?? [], {
1121
- pattern: first.pattern,
1122
- location: path,
1123
- pathname: shellPathname(path)
1149
+ located.set(pattern, [...located.get(pattern) ?? [], {
1150
+ pattern,
1151
+ location,
1152
+ pathname: shellPathname(location)
1124
1153
  }]);
1125
1154
  }
1126
1155
  const used = new Set(paths);
1127
1156
  const shells = [];
1128
- for (const pattern of patterns) {
1129
- if (isConcrete(pattern) || pattern.endsWith("/*")) continue;
1157
+ for (const { pattern } of declared) {
1158
+ if (isConcrete(pattern)) continue;
1130
1159
  const matcher = new URLPattern({ pathname: pattern });
1131
1160
  const covered = usable.filter((path) => matcher.test({ pathname: path }));
1132
1161
  paths.push(...covered);
@@ -1161,8 +1190,6 @@ const planPaths = (tree, supplied) => {
1161
1190
  shells: shells.filter((shell, index) => shells.findIndex((each) => each.pathname === shell.pathname) === index),
1162
1191
  unresolved,
1163
1192
  unusable,
1164
- held,
1165
- misnamed,
1166
1193
  closed,
1167
1194
  reserved
1168
1195
  };
@@ -1172,8 +1199,9 @@ const planPaths = (tree, supplied) => {
1172
1199
  * characters this module reads a pathname by: `*`, and the `:` that would
1173
1200
  * make a value starting with one a parameter left open.
1174
1201
  */
1175
- const segmentOf = (value) => encodeURIComponent(value).replaceAll("*", "%2A").replaceAll(":", "%3A");
1176
- const valuesFrom = (returned) => Array.isArray(returned) && returned.every((value) => typeof value === "string" && value !== "") ? [...new Set(returned)] : null;
1202
+ const segmentOf = (spelling) => encodeURIComponent(spelling).replaceAll("*", "%2A").replaceAll(":", "%3A");
1203
+ const isValue = (value) => typeof value === "string" && value !== "" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean";
1204
+ const spellingsFrom = (returned) => Array.isArray(returned) && returned.every(isValue) ? [...new Set(returned.map(String))] : null;
1177
1205
  /**
1178
1206
  * What the `paths.ts` files say the site holds: each is asked for its
1179
1207
  * directory's parameter, once per combination of the values above it, and
@@ -1188,23 +1216,35 @@ const valuesFrom = (returned) => Array.isArray(returned) && returned.every((valu
1188
1216
  * keeps a shell for the rest. Everything else is left for `planPaths` to
1189
1217
  * call unresolved.
1190
1218
  *
1191
- * A value is the segment as a visitor reads it, escaped here for the URL.
1219
+ * A value is what a link to the page takes, and is spelled here as `href`
1220
+ * spells it. A paths.ts below is handed the spellings above it, so
1221
+ * `valuesOf` can read them as the layouts above its directory do — not the
1222
+ * values as returned, which no page ever receives — and a paths.ts under
1223
+ * values one of those refuses is a problem, as a shell there is.
1192
1224
  */
1193
1225
  const suppliedFrom = async (tree, valuesOf) => {
1194
- const locations = [];
1226
+ const paths = [];
1227
+ const shells = [];
1195
1228
  const problems = /* @__PURE__ */ new Set();
1196
- const walk = async (dir, ats) => {
1229
+ const refused = [];
1230
+ const walk = async (dir, ats, pattern) => {
1197
1231
  const answers = dir.page ?? dir.route ?? dir.redirect;
1198
1232
  const shell = dir.page !== null && dir.fallback !== null;
1199
1233
  if (answers !== null) {
1200
- for (const at of ats) if (at.open ? shell : Object.keys(at.params).length > 0) locations.push(at.path);
1234
+ for (const at of ats) if (at.open) {
1235
+ if (shell) shells.push({
1236
+ location: at.path,
1237
+ pattern
1238
+ });
1239
+ } else if (Object.keys(at.params).length > 0) paths.push(at.path);
1201
1240
  }
1202
1241
  await Promise.all(dir.children.map(async (child) => {
1203
- if (child.kind === "group") return walk(child, ats);
1242
+ if (child.kind === "group") return walk(child, ats, pattern);
1243
+ const below = `${pattern === "/" ? "" : pattern}${child.key}`;
1204
1244
  if (child.kind !== "param") return walk(child, ats.map((at) => ({
1205
1245
  ...at,
1206
1246
  path: `${at.path}${child.key}`
1207
- })));
1247
+ })), below);
1208
1248
  const name = child.key.slice(2);
1209
1249
  const opened = (at) => ({
1210
1250
  ...at,
@@ -1212,37 +1252,43 @@ const suppliedFrom = async (tree, valuesOf) => {
1212
1252
  open: true
1213
1253
  });
1214
1254
  const { paths: file } = child;
1215
- if (file === null) return walk(child, ats.map(opened));
1216
- const below = await Promise.all(ats.map(async (at) => {
1255
+ if (file === null) return walk(child, ats.map(opened), below);
1256
+ const reached = await Promise.all(ats.map(async (at) => {
1217
1257
  if (at.open) {
1218
1258
  problems.add(`${file} is asked for its values once per value of the parameters above it, and ${at.path} still holds one — give that parameter's directory a paths.ts too`);
1219
1259
  return [];
1220
1260
  }
1221
- const values = valuesFrom(await valuesOf(file, at.params));
1222
- if (values === null) {
1223
- problems.add(`${file} has to return an array of non-empty strings, the values of :${name}`);
1261
+ const asked = await valuesOf(file, at.params);
1262
+ if (asked === null) {
1263
+ refused.push(`${at.path}/:${name} (${file})`);
1264
+ return [];
1265
+ }
1266
+ const spellings = spellingsFrom(asked.values);
1267
+ if (spellings === null) {
1268
+ problems.add(`${file} has to return an array of the values of :${name}, each a non-empty string, a number, a bigint or a boolean`);
1224
1269
  return [];
1225
1270
  }
1226
- return [...values.map((value) => ({
1227
- path: `${at.path}/${segmentOf(value)}`,
1271
+ return [...spellings.map((spelling) => ({
1272
+ path: `${at.path}/${segmentOf(spelling)}`,
1228
1273
  params: {
1229
1274
  ...at.params,
1230
- [name]: value
1275
+ [name]: spelling
1231
1276
  },
1232
1277
  open: false
1233
1278
  })), ...child.page !== null && child.fallback !== null ? [opened(at)] : []];
1234
1279
  }));
1235
- return walk(child, below.flat());
1280
+ return walk(child, reached.flat(), below);
1236
1281
  }));
1237
1282
  };
1238
1283
  await walk(tree, [{
1239
1284
  path: "",
1240
1285
  params: {},
1241
1286
  open: false
1242
- }]);
1287
+ }], "/");
1243
1288
  return {
1244
- locations,
1245
- problems: [...problems]
1289
+ paths,
1290
+ shells,
1291
+ problems: [...problems, ...refused.length > 0 ? [`the paths.ts files stand where a params schema refuses the values above them, so they were not asked: ${refused.toSorted().join(", ")}`] : []]
1246
1292
  };
1247
1293
  };
1248
1294
  /**
@@ -1254,7 +1300,7 @@ const suppliedFrom = async (tree, valuesOf) => {
1254
1300
  * URL, only when the build did not write it, since the written file answers.
1255
1301
  */
1256
1302
  const shadowedShells = (tree, shells, built) => {
1257
- const declared = declaredPatterns(tree).filter((each) => each.kind !== "notFound");
1303
+ const declared = answeringPatterns(tree);
1258
1304
  const shapes = new Map(fallbackShapes(tree).map((shape) => [shape.pattern, shape]));
1259
1305
  const found = [];
1260
1306
  for (const shell of shells) {
@@ -1310,8 +1356,6 @@ const planRefusals = (plan, shadowed) => {
1310
1356
  return [
1311
1357
  ...plan.unresolved.length > 0 ? [`static build needs the values of ${plan.unresolved.join(", ")} — a paths.ts in each parameter's directory returns them, and a fallback.tsx beside a page answers the ones the build does not write`] : [],
1312
1358
  ...plan.unusable.length > 0 ? [`the paths.ts files returned pathnames no route wants: ${plan.unusable.join(", ")}`] : [],
1313
- ...plan.held.length > 0 ? [`these pathnames still hold a parameter, and only a page with a fallback.tsx beside it takes one: ${plan.held.map(({ location, file }) => `${location} (${file} ${isPage(file) ? "has none" : "cannot have one"})`).join(", ")}`] : [],
1314
- ...plan.misnamed.length > 0 ? [`these shell locations name parameters that are not their pattern's: ${plan.misnamed.map(({ location, pattern }) => `${location} (${pattern})`).join(", ")}`] : [],
1315
1359
  ...suppliedClosed.length > 0 ? [`these shells leave out a parameter a layout above their fallback.tsx receives, so its directory needs a paths.ts: ${suppliedClosed.map(({ location, params, layout }) => `${location} (${paramList(params)}, received by ${layout})`).join(", ")}`] : [],
1316
1360
  ...bare.length > 0 ? [bare.map(({ location, params, layout }) => `static build needs the values of ${paramList(params)} for the shell of ${location} — ${layout} receives ${params.length === 1 ? "it" : "them"}, so ${params.length === 1 ? "that parameter's directory needs" : "those parameters' directories need"} a paths.ts, which puts the shell at ${location.split("/").map((segment) => params.some((name) => segment === `:${name}`) ? `<${segment.slice(1)}>` : segment).join("/")}`).join("\n")] : [],
1317
1361
  ...plan.reserved.length > 0 ? [`a paths.ts returned ${FALLBACK_SEGMENT}, which the build keeps for shells: ${plan.reserved.join(", ")}`] : [],
@@ -1342,7 +1386,7 @@ const SITEMAP_PATHNAME = "/sitemap.xml";
1342
1386
  * pathname the build was given.
1343
1387
  */
1344
1388
  const answersOf = (dir, pathnames) => {
1345
- const declared = declaredPatterns(dir).filter((each) => each.kind !== "notFound");
1389
+ const declared = answeringPatterns(dir);
1346
1390
  return new Map(pathnames.flatMap((pathname) => {
1347
1391
  const answer = declared.find((each) => new URLPattern({ pathname: each.pattern }).test({ pathname }));
1348
1392
  return answer === void 0 ? [] : [[pathname, answer]];
@@ -1404,4 +1448,4 @@ const isFile = async (candidate) => {
1404
1448
  return false;
1405
1449
  }
1406
1450
  };
1407
- export { emitRoutesModule as A, SHELL_HEADER as C, decodePathname as D, FALLBACK_SEGMENT as E, parseRouteTree as F, slotOf as I, FRAMEWORK as M, ROUTE_METHODS as N, LOCALES_MODULE as O, fallbackShapes as P, SERVER_STYLESHEETS_HEADER as S, readServerStylesheets as T, suppliedFrom as _, catchAllPath as a, NONCE_HEADER as b, fileAt as c, patternsNeedingPaths as d, patternsOf as f, shadowedShells as g, routeFileRefusals as h, answersOf as i, unreachableRoutes as j, emitRegisterModule as k, isConcrete as l, planRefusals as m, safeJoin as n, catchAllRefusals as o, planPaths as p, SITEMAP_PATHNAME as r, dirFor as s, isFile as t, isParamSegment as u, CLIENT_DEPS_HEADER as v, readClientDeps as w, NOT_FOUND_HEADER as x, CLIENT_FILES_PATH as y };
1451
+ export { emitRegisterModule as A, SHELL_HEADER as C, decodePathname as D, FALLBACK_SEGMENT as E, fallbackShapes as F, parseRouteTree as I, restDirOf as L, unreachableRoutes as M, ROUTE_METHODS as N, LOCALES_MODULE as O, FRAMEWORK as P, slotOf as R, SERVER_STYLESHEETS_HEADER as S, readServerStylesheets as T, suppliedFrom as _, answersOf as a, NONCE_HEADER as b, dirFor as c, isParamSegment as d, patternsNeedingPaths as f, shadowedShells as g, routeFileRefusals as h, answeringPatterns as i, emitRoutesModule as j, ROUTES_DIR as k, fileAt as l, planRefusals as m, safeJoin as n, catchAllPath as o, planPaths as p, SITEMAP_PATHNAME as r, catchAllRefusals as s, isFile as t, isConcrete as u, CLIENT_DEPS_HEADER as v, readClientDeps as w, NOT_FOUND_HEADER as x, CLIENT_FILES_PATH as y };
@@ -1,4 +1,4 @@
1
- import { E as FALLBACK_SEGMENT, n as safeJoin, t as isFile, u as isParamSegment } from "./static-file-BEk_xO5y.mjs";
1
+ import { E as FALLBACK_SEGMENT, d as isParamSegment, n as safeJoin, t as isFile } from "./static-file-BS-WEiwu.mjs";
2
2
  import { normalizePathname, withBase, withoutBase } from "@k8ordo/router";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import path from "node:path";