@valbuild/core 0.124.0 → 0.125.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,86 @@
1
1
  # @valbuild/core
2
2
 
3
+ ## 0.125.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#638](https://github.com/valbuild/val/pull/638) [`c390397`](https://github.com/valbuild/val/commit/c390397cb5e203eb1bedae3a6fab15726e850b90) Thanks [@freekh](https://github.com/freekh)! - Val now runs on TanStack Start.
8
+
9
+ `@valbuild/tanstack` is a new package with everything `@valbuild/next` has: Val
10
+ Studio at `/val`, the on-page overlay and canvas, draft mode, the client hooks,
11
+ server-side content reads, images, and the MCP tools.
12
+
13
+ ```sh
14
+ npm install @valbuild/tanstack
15
+ ```
16
+
17
+ ```ts
18
+ // val.config.ts
19
+ import { initVal } from "@valbuild/tanstack";
20
+ const { s, c, config, tanstackRouter } = initVal({ project: "org/project" });
21
+ ```
22
+
23
+ **Routes are first class.** A Val module for a route is named after the route
24
+ file it sits beside — `src/routes/posts.$postId.tsx` is served content by
25
+ `src/routes/posts.$postId.val.ts` — and its keys are the URLs that route serves:
26
+
27
+ ```ts
28
+ export default c.define(
29
+ "/src/routes/posts.$postId.val.ts",
30
+ s.router(tanstackRouter, s.object({ title: s.string() })),
31
+ { "/posts/hello-world": { title: "Hello world" } },
32
+ );
33
+ ```
34
+
35
+ `.` and `/` both separate segments, `$param` is a parameter, `$` is a splat, and
36
+ `index`, `route`, `(groups)` and `_pathless` layouts add no URL segment — the
37
+ same rules TanStack Router uses for the route file itself. Val validates every
38
+ key against that pattern, and Val Studio shows these modules as a sitemap under
39
+ **Pages**, where an editor can add a page.
40
+
41
+ Point the route generator away from your content files, in `vite.config.ts` and
42
+ `tsr.config.json`:
43
+
44
+ ```ts
45
+ tanstackStart({ router: { routeFileIgnorePattern: "\\.val\\.[tj]sx?$" } });
46
+ ```
47
+
48
+ See the [README](https://github.com/valbuild/val/blob/main/packages/tanstack/README.md)
49
+ for the full wiring, and `examples/tanstack` for a working app.
50
+
51
+ **Also fixed, for everyone:** `Internal.VERSION.core` was `null` in any ESM
52
+ bundle — it was read with `require("../package.json")` inside a `try`, so the
53
+ failure was silent. That version goes into every remote file ref and proxy mode
54
+ refuses to start without it. Every package now reads its version through a
55
+ static JSON import, which is inlined at build time.
56
+
57
+ Two smaller fixes that came out of running the whole toolchain against a
58
+ TanStack project:
59
+
60
+ - `val versions` reports `@valbuild/tanstack`, and `val debug` writes a snapshot
61
+ that names whichever framework package the captured project actually has.
62
+ - `@valbuild/eslint-plugin` reads a `tsconfig.json` that has comments in it. A
63
+ tsconfig is JSONC, and `JSON.parse` is not — so on any project whose tsconfig
64
+ carries a comment (the TanStack starter's does) the
65
+ `module-in-val-modules` rule threw `Expected double-quoted property name in
66
+ JSON` on the first file and took the whole lint run with it.
67
+
68
+ Three fixes found by driving the Studio against a real TanStack app:
69
+
70
+ - **A draft image now loads on the page.** The source the Studio pushes to the
71
+ host page carries `patch_id` for any file whose bytes are still in a patch, so
72
+ the page asks `/api/val/files/...?patch_id=` rather than a `/public` path that
73
+ nothing has written yet. This was silent — the image just did not appear — and
74
+ it affects any page that reads media through the hooks rather than on the
75
+ server, `@valbuild/next` included.
76
+ - **A splat route no longer logs an error on every render.** TanStack returns
77
+ both `_splat` and `*` for the same parameter; Val reported the second as a
78
+ parameter it could not place in the path.
79
+ - The TanStack example and starter render a 404 page instead of throwing
80
+ `notFound()` from a component, which escaped to the error boundary and logged
81
+ `Error in renderToReadableStream` (and, with no not-found component
82
+ configured, aborted the response) on every miss.
83
+
3
84
  ## 0.124.0
4
85
 
5
86
  ### Minor Changes
@@ -2,14 +2,23 @@ import type { ModuleFilePath, SourcePath } from "./val/index.js";
2
2
  import type { SerializedSchema } from "./schema/index.js";
3
3
  /**
4
4
  * Given a URL pathname (e.g. "/blogs/blog-1") and all serialized module schemas,
5
- * finds the matching next-app-router module and returns the module file path
6
- * and the source path for that route's content.
5
+ * finds the page-router module that serves that route and returns the module
6
+ * file path and the source path for that route's content.
7
7
  *
8
8
  * External routers (e.g. external-url-router) are intentionally skipped.
9
- * Returns null if no next-app-router module matches the pathname.
9
+ * Returns null if no page-router module matches the pathname.
10
10
  */
11
11
  export declare function getSourcePathFromRoute(pathname: string, schemas: Record<ModuleFilePath, SerializedSchema>): {
12
12
  moduleFilePath: ModuleFilePath;
13
13
  sourcePath: SourcePath;
14
14
  route: string;
15
15
  } | null;
16
+ /**
17
+ * Whether a router id is one whose keys are routes of this site.
18
+ *
19
+ * The same question `getSourcePathFromRoute` asks, exported because the Studio
20
+ * asks it too — a page router gets the sitemap and the "Pages" menu, an
21
+ * external one gets a flat list of URLs — and the two must not disagree about
22
+ * which is which.
23
+ */
24
+ export declare function isPageRouter(routerId: string): boolean;
@@ -69,14 +69,15 @@ export { deserializeSchema } from "./schema/deserialize.js";
69
69
  export { type PreviewItem, type ItemPreviewInput, type RecordPreview, type ArrayPreview, type ReifiedPreview, type PreviewScope, previewScope, } from "./preview.js";
70
70
  export { type InlineRender, type FieldRender, isInlineRender } from "./render.js";
71
71
  export type { ValRouter, RouteValidationError } from "./router.js";
72
- export { getSourcePathFromRoute } from "./getSourcePathFromRoute.js";
72
+ export { parseNextJsRoutePattern, parseTanStackRoutePattern, tanStackSegmentsOfRoutePath, validateUrlAgainstPattern, } from "./router.js";
73
+ export { getSourcePathFromRoute, isPageRouter } from "./getSourcePathFromRoute.js";
73
74
  export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
74
75
  export type FatalErrorType = (typeof FATAL_ERROR_TYPES)[number];
75
76
  export declare const DEFAULT_CONTENT_HOST = "https://content.val.build";
76
77
  export declare const DEFAULT_APP_HOST = "https://admin.val.build";
77
78
  declare const Internal: {
78
79
  VERSION: {
79
- core: string | null;
80
+ core: string;
80
81
  };
81
82
  mediaUrl: typeof mediaUrl;
82
83
  resolveMedia: typeof resolveMedia;
@@ -93,6 +94,7 @@ declare const Internal: {
93
94
  splitModuleFilePathAndModulePath: typeof splitModuleFilePathAndModulePath;
94
95
  joinModuleFilePathAndModulePath: typeof joinModuleFilePathAndModulePath;
95
96
  nextAppRouter: import("./router.js").ValRouter;
97
+ tanstackRouter: import("./router.js").ValRouter;
96
98
  externalPageRouter: import("./router.js").ValRouter;
97
99
  color: {
98
100
  parseColor: typeof parseColor;
@@ -23,6 +23,51 @@ export declare const nextAppRouter: ValRouter;
23
23
  * - /app/(..)(dashboard)/feed/page.val.ts -> ["feed"] (interception route)
24
24
  */
25
25
  export declare function parseNextJsRoutePattern(moduleFilePath: string): string[];
26
+ /**
27
+ * Parse a TanStack Router route pattern out of a Val module file path.
28
+ *
29
+ * TanStack Router's file conventions are not Next's, so this is a different
30
+ * parser rather than a flag on the one above. A Val module for a route lives
31
+ * beside the route file and is named the same way — `routes/posts.$postId.tsx`
32
+ * is served content by `routes/posts.$postId.val.ts` — so the pattern is the
33
+ * file path with the conventions applied:
34
+ *
35
+ * - `.` and `/` both separate segments (`posts.$postId.val.ts` and
36
+ * `posts/$postId.val.ts` are the same route)
37
+ * - `$param` is a dynamic segment, `$` on its own is a splat
38
+ * - `index` is the directory's own route and contributes no segment
39
+ * - `route` is a layout for the directory, likewise
40
+ * - `(group)` folders and `_pathless` layout segments are not in the URL
41
+ * - a trailing `_` on a segment opts out of nesting and is not in the URL
42
+ *
43
+ * The result is expressed in the SAME vocabulary the Next parser uses
44
+ * (`[param]`, `[...param]`), because everything downstream — validation, the
45
+ * sitemap, the key inputs in the Studio — is written against that vocabulary
46
+ * and there is no reason for two.
47
+ *
48
+ * - /src/routes/posts.$postId.val.ts -> ["posts", "[postId]"]
49
+ * - /routes/posts/$postId.val.ts -> ["posts", "[postId]"]
50
+ * - /src/routes/index.val.ts -> []
51
+ * - /src/routes/files.$.val.ts -> ["files", "[..._splat]"]
52
+ * - /src/routes/(app)/_layout.about.val.ts -> ["about"]
53
+ */
54
+ export declare function parseTanStackRoutePattern(moduleFilePath: string): string[];
55
+ /**
56
+ * The URL segments of a TanStack route path, given relative to `routes/`.
57
+ *
58
+ * Exported because the Studio derives the same pattern from the same file path
59
+ * and must not disagree with validation about what a route is.
60
+ */
61
+ export declare function tanStackSegmentsOfRoutePath(routePath: string): string[];
62
+ /**
63
+ * The router for a TanStack Router (and TanStack Start) app.
64
+ *
65
+ * Like `nextAppRouter` this does not belong in core — it is here for the same
66
+ * reason that one is: the serialized schema carries only a router id, so the
67
+ * thing that turns an id back into a validator has to be somewhere every
68
+ * consumer can reach.
69
+ */
70
+ export declare const tanstackRouter: ValRouter;
26
71
  export interface ValRouter {
27
72
  getRouterId(): string;
28
73
  validate(moduleFilePath: ModuleFilePath, urlPaths: string[]): RouteValidationError[];
@@ -10449,23 +10449,190 @@ function parseNextJsRoutePattern(moduleFilePath) {
10449
10449
  return [];
10450
10450
  }
10451
10451
 
10452
+ /**
10453
+ * Parse a TanStack Router route pattern out of a Val module file path.
10454
+ *
10455
+ * TanStack Router's file conventions are not Next's, so this is a different
10456
+ * parser rather than a flag on the one above. A Val module for a route lives
10457
+ * beside the route file and is named the same way — `routes/posts.$postId.tsx`
10458
+ * is served content by `routes/posts.$postId.val.ts` — so the pattern is the
10459
+ * file path with the conventions applied:
10460
+ *
10461
+ * - `.` and `/` both separate segments (`posts.$postId.val.ts` and
10462
+ * `posts/$postId.val.ts` are the same route)
10463
+ * - `$param` is a dynamic segment, `$` on its own is a splat
10464
+ * - `index` is the directory's own route and contributes no segment
10465
+ * - `route` is a layout for the directory, likewise
10466
+ * - `(group)` folders and `_pathless` layout segments are not in the URL
10467
+ * - a trailing `_` on a segment opts out of nesting and is not in the URL
10468
+ *
10469
+ * The result is expressed in the SAME vocabulary the Next parser uses
10470
+ * (`[param]`, `[...param]`), because everything downstream — validation, the
10471
+ * sitemap, the key inputs in the Studio — is written against that vocabulary
10472
+ * and there is no reason for two.
10473
+ *
10474
+ * - /src/routes/posts.$postId.val.ts -> ["posts", "[postId]"]
10475
+ * - /routes/posts/$postId.val.ts -> ["posts", "[postId]"]
10476
+ * - /src/routes/index.val.ts -> []
10477
+ * - /src/routes/files.$.val.ts -> ["files", "[..._splat]"]
10478
+ * - /src/routes/(app)/_layout.about.val.ts -> ["about"]
10479
+ */
10480
+ function parseTanStackRoutePattern(moduleFilePath) {
10481
+ var segments = tanStackRouteSegments(moduleFilePath);
10482
+ if (segments === null) {
10483
+ return [];
10484
+ }
10485
+ return segments;
10486
+ }
10487
+
10488
+ /**
10489
+ * The segments, or `null` when the path is not a TanStack route module at all.
10490
+ *
10491
+ * Distinct from `parseTanStackRoutePattern`'s empty array, which is a real
10492
+ * answer: the root route `/` has no segments.
10493
+ */
10494
+ function tanStackRouteSegments(moduleFilePath) {
10495
+ if (!moduleFilePath || typeof moduleFilePath !== "string") {
10496
+ return null;
10497
+ }
10498
+ var match = moduleFilePath.match(/^(?:\/src)?\/routes\/(.+)\.val\.[tj]sx?$/);
10499
+ if (!match) {
10500
+ return null;
10501
+ }
10502
+ return tanStackSegmentsOfRoutePath(match[1]);
10503
+ }
10504
+
10505
+ /**
10506
+ * The URL segments of a TanStack route path, given relative to `routes/`.
10507
+ *
10508
+ * Exported because the Studio derives the same pattern from the same file path
10509
+ * and must not disagree with validation about what a route is.
10510
+ */
10511
+ function tanStackSegmentsOfRoutePath(routePath) {
10512
+ // `.` is a separator exactly like `/`, so flatten both before looking at any
10513
+ // segment: `posts/$postId.edit` and `posts.$postId.edit` are one route.
10514
+ var rawSegments = routePath.split("/").flatMap(function (part) {
10515
+ return part.split(".");
10516
+ }).filter(function (part) {
10517
+ return part !== "";
10518
+ });
10519
+ var segments = [];
10520
+ var _iterator3 = _createForOfIteratorHelper(rawSegments),
10521
+ _step3;
10522
+ try {
10523
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
10524
+ var rawSegment = _step3.value;
10525
+ // A route group: a folder that organises files without appearing in the URL.
10526
+ if (rawSegment.startsWith("(") && rawSegment.endsWith(")")) {
10527
+ continue;
10528
+ }
10529
+ // A pathless layout route. `_layout` nests its children without adding a
10530
+ // segment; `index`/`route` are the directory's own route and its layout.
10531
+ if (rawSegment.startsWith("_")) {
10532
+ continue;
10533
+ }
10534
+ if (rawSegment === "index" || rawSegment === "route") {
10535
+ continue;
10536
+ }
10537
+ // A trailing `_` opts the segment out of layout nesting; the URL keeps the
10538
+ // name without it.
10539
+ var segment = rawSegment.endsWith("_") ? rawSegment.slice(0, -1) : rawSegment;
10540
+ if (segment === "$") {
10541
+ // A splat. Named `_splat` because that is the param name TanStack gives
10542
+ // it, so `useValRoute(pageVal, params)` can be handed the route's own
10543
+ // params object unchanged.
10544
+ segments.push("[..._splat]");
10545
+ continue;
10546
+ }
10547
+ if (segment.startsWith("$")) {
10548
+ segments.push("[".concat(segment.slice(1), "]"));
10549
+ continue;
10550
+ }
10551
+ segments.push(segment);
10552
+ }
10553
+ } catch (err) {
10554
+ _iterator3.e(err);
10555
+ } finally {
10556
+ _iterator3.f();
10557
+ }
10558
+ return segments;
10559
+ }
10560
+
10561
+ /**
10562
+ * The router for a TanStack Router (and TanStack Start) app.
10563
+ *
10564
+ * Like `nextAppRouter` this does not belong in core — it is here for the same
10565
+ * reason that one is: the serialized schema carries only a router id, so the
10566
+ * thing that turns an id back into a validator has to be somewhere every
10567
+ * consumer can reach.
10568
+ */
10569
+ var tanstackRouter = {
10570
+ getRouterId: function getRouterId() {
10571
+ return "tanstack-router";
10572
+ },
10573
+ validate: function validate(moduleFilePath, urlPaths) {
10574
+ var routePattern = parseTanStackRoutePattern(moduleFilePath);
10575
+ var errors = [];
10576
+ var _iterator4 = _createForOfIteratorHelper(urlPaths),
10577
+ _step4;
10578
+ try {
10579
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
10580
+ var urlPath = _step4.value;
10581
+ var validation = validateUrlAgainstPattern(urlPath, routePattern);
10582
+ if (!validation.isValid) {
10583
+ errors.push({
10584
+ error: {
10585
+ message: "URL path \"".concat(urlPath, "\" does not match the route pattern for \"").concat(moduleFilePath, "\""),
10586
+ urlPath: urlPath,
10587
+ expectedPath: validation.expectedPath || null
10588
+ }
10589
+ });
10590
+ }
10591
+ }
10592
+ } catch (err) {
10593
+ _iterator4.e(err);
10594
+ } finally {
10595
+ _iterator4.f();
10596
+ }
10597
+ return errors;
10598
+ }
10599
+ };
10600
+
10601
+ /**
10602
+ * The routers whose keys are URL paths of THIS site, and how to read the route
10603
+ * pattern a module of each serves.
10604
+ *
10605
+ * Keyed by router id because that is all a serialized schema carries. A router
10606
+ * that is not in here — `external-url-router` today — has keys that are URLs of
10607
+ * somewhere else, so matching this site's pathname against them is meaningless
10608
+ * rather than merely unsupported.
10609
+ */
10610
+ var PAGE_ROUTE_PATTERN_PARSERS = {
10611
+ "next-app-router": parseNextJsRoutePattern,
10612
+ "tanstack-router": parseTanStackRoutePattern
10613
+ };
10614
+
10452
10615
  /**
10453
10616
  * Given a URL pathname (e.g. "/blogs/blog-1") and all serialized module schemas,
10454
- * finds the matching next-app-router module and returns the module file path
10455
- * and the source path for that route's content.
10617
+ * finds the page-router module that serves that route and returns the module
10618
+ * file path and the source path for that route's content.
10456
10619
  *
10457
10620
  * External routers (e.g. external-url-router) are intentionally skipped.
10458
- * Returns null if no next-app-router module matches the pathname.
10621
+ * Returns null if no page-router module matches the pathname.
10459
10622
  */
10460
10623
  function getSourcePathFromRoute(pathname, schemas) {
10461
10624
  for (var _i = 0, _arr = Object.entries(schemas); _i < _arr.length; _i++) {
10462
10625
  var _arr$_i = _slicedToArray(_arr[_i], 2),
10463
10626
  moduleFilePath = _arr$_i[0],
10464
10627
  schema = _arr$_i[1];
10465
- if (schema.type !== "record" || schema.router !== "next-app-router") {
10628
+ if (schema.type !== "record" || !schema.router) {
10466
10629
  continue;
10467
10630
  }
10468
- var routePattern = parseNextJsRoutePattern(moduleFilePath);
10631
+ var parseRoutePattern = PAGE_ROUTE_PATTERN_PARSERS[schema.router];
10632
+ if (!parseRoutePattern) {
10633
+ continue;
10634
+ }
10635
+ var routePattern = parseRoutePattern(moduleFilePath);
10469
10636
  var _validateUrlAgainstPa = validateUrlAgainstPattern(pathname, routePattern),
10470
10637
  isValid = _validateUrlAgainstPa.isValid;
10471
10638
  if (isValid) {
@@ -10480,20 +10647,81 @@ function getSourcePathFromRoute(pathname, schemas) {
10480
10647
  return null;
10481
10648
  }
10482
10649
 
10650
+ /**
10651
+ * Whether a router id is one whose keys are routes of this site.
10652
+ *
10653
+ * The same question `getSourcePathFromRoute` asks, exported because the Studio
10654
+ * asks it too — a page router gets the sitemap and the "Pages" menu, an
10655
+ * external one gets a flat list of URLs — and the two must not disagree about
10656
+ * which is which.
10657
+ */
10658
+ function isPageRouter(routerId) {
10659
+ return routerId in PAGE_ROUTE_PATTERN_PARSERS;
10660
+ }
10661
+
10662
+ var corePackageJson = {
10663
+ name: "@valbuild/core",
10664
+ version: "0.125.0",
10665
+ "private": false,
10666
+ description: "Val - supercharged hard-coded content",
10667
+ repository: {
10668
+ type: "git",
10669
+ url: "git+https://github.com/valbuild/val.git"
10670
+ },
10671
+ scripts: {
10672
+ typecheck: "tsc --noEmit",
10673
+ test: "jest",
10674
+ "analyze-trace": "npx tsc -p tsconfig.json --skipLibCheck --generateTrace trace; npx -p @typescript/analyze-trace analyze-trace trace; npx speedscope trace/trace.json"
10675
+ },
10676
+ main: "dist/valbuild-core.cjs.js",
10677
+ module: "dist/valbuild-core.esm.js",
10678
+ exports: {
10679
+ ".": {
10680
+ module: "./dist/valbuild-core.esm.js",
10681
+ "default": "./dist/valbuild-core.cjs.js"
10682
+ },
10683
+ "./fp": {
10684
+ module: "./fp/dist/valbuild-core-fp.esm.js",
10685
+ "default": "./fp/dist/valbuild-core-fp.cjs.js"
10686
+ },
10687
+ "./patch": {
10688
+ module: "./patch/dist/valbuild-core-patch.esm.js",
10689
+ "default": "./patch/dist/valbuild-core-patch.cjs.js"
10690
+ },
10691
+ "./package.json": "./package.json"
10692
+ },
10693
+ types: "dist/valbuild-core.cjs.d.ts",
10694
+ preconstruct: {
10695
+ entrypoints: [
10696
+ "./index.ts",
10697
+ "./fp/index.ts",
10698
+ "./patch/index.ts"
10699
+ ],
10700
+ exports: true
10701
+ },
10702
+ devDependencies: {
10703
+ typescript: "^6.0.3"
10704
+ },
10705
+ dependencies: {
10706
+ "ts-toolbelt": "^9.6.0"
10707
+ },
10708
+ files: [
10709
+ "CHANGELOG.md",
10710
+ "dist",
10711
+ "fp/dist",
10712
+ "fp/package.json",
10713
+ "patch/dist",
10714
+ "patch/package.json"
10715
+ ]
10716
+ };
10717
+
10483
10718
  var ModuleFilePathSep = "?p=";
10484
10719
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
10485
10720
  var DEFAULT_CONTENT_HOST = "https://content.val.build";
10486
10721
  var DEFAULT_APP_HOST = "https://admin.val.build";
10487
10722
  var Internal = {
10488
10723
  VERSION: {
10489
- core: function () {
10490
- try {
10491
- // eslint-disable-next-line @typescript-eslint/no-require-imports
10492
- return require("../package.json").version;
10493
- } catch (_unused) {
10494
- return null;
10495
- }
10496
- }()
10724
+ core: corePackageJson.version
10497
10725
  },
10498
10726
  mediaUrl: mediaUrl,
10499
10727
  resolveMedia: resolveMedia,
@@ -10510,6 +10738,7 @@ var Internal = {
10510
10738
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
10511
10739
  joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
10512
10740
  nextAppRouter: nextAppRouter,
10741
+ tanstackRouter: tanstackRouter,
10513
10742
  externalPageRouter: externalPageRouter,
10514
10743
  color: {
10515
10744
  parseColor: parseColor,
@@ -10598,9 +10827,9 @@ var Internal = {
10598
10827
  function tryJsonParse(str) {
10599
10828
  try {
10600
10829
  return JSON.parse(str);
10601
- } catch (_unused2) {
10830
+ } catch (_unused) {
10602
10831
  return str;
10603
10832
  }
10604
10833
  }
10605
10834
 
10606
- export { ArraySchema as A, BooleanSchema as B, ColorSchema as C, DEFAULT_CONTENT_HOST as D, COLOR_FORMATS as E, FATAL_ERROR_TYPES as F, GenericSelector as G, DEFAULT_COLOR_FORMAT as H, Internal as I, DateTimeSchema as J, KeyOfSchema as K, RouteSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RichTextSchema as Q, RecordSchema as R, Schema as S, LiteralSchema as T, UnionSchema as U, VAL_EXTENSION as V, deserializeSchema as W, previewScope as X, isInlineRender as Y, getSourcePathFromRoute as Z, _typeof as _, _slicedToArray as a, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, extractValModules as f, computeValModuleShas as g, hasRemoteFileSchema as h, initVal as i, hasMediaSchema as j, DEFAULT_VAL_REMOTE_HOST as k, derefPatch as l, modules as m, StringSchema as n, ImageSchema as o, FileSchema as p, DateSchema as q, SettingsSchema as r, splitModuleFilePathAndModulePath as s, ASSISTANT_SETTINGS_MAX_LENGTH as t, assistantAvailability as u, SETTINGS_MODULE_CONVENTION as v, isRootModuleFilePath as w, resolveSettingsModule as x, CodeSchema as y, CODE_LANGUAGES as z };
10835
+ export { parseTanStackRoutePattern as $, ArraySchema as A, BooleanSchema as B, ColorSchema as C, DEFAULT_CONTENT_HOST as D, COLOR_FORMATS as E, FATAL_ERROR_TYPES as F, GenericSelector as G, DEFAULT_COLOR_FORMAT as H, Internal as I, DateTimeSchema as J, KeyOfSchema as K, RouteSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RichTextSchema as Q, RecordSchema as R, Schema as S, LiteralSchema as T, UnionSchema as U, VAL_EXTENSION as V, deserializeSchema as W, previewScope as X, isInlineRender as Y, parseNextJsRoutePattern as Z, _typeof as _, _slicedToArray as a, tanStackSegmentsOfRoutePath as a0, validateUrlAgainstPattern as a1, getSourcePathFromRoute as a2, isPageRouter as a3, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, extractValModules as f, computeValModuleShas as g, hasRemoteFileSchema as h, initVal as i, hasMediaSchema as j, DEFAULT_VAL_REMOTE_HOST as k, derefPatch as l, modules as m, StringSchema as n, ImageSchema as o, FileSchema as p, DateSchema as q, SettingsSchema as r, splitModuleFilePathAndModulePath as s, ASSISTANT_SETTINGS_MAX_LENGTH as t, assistantAvailability as u, SETTINGS_MODULE_CONVENTION as v, isRootModuleFilePath as w, resolveSettingsModule as x, CodeSchema as y, CODE_LANGUAGES as z };
@@ -10451,23 +10451,190 @@ function parseNextJsRoutePattern(moduleFilePath) {
10451
10451
  return [];
10452
10452
  }
10453
10453
 
10454
+ /**
10455
+ * Parse a TanStack Router route pattern out of a Val module file path.
10456
+ *
10457
+ * TanStack Router's file conventions are not Next's, so this is a different
10458
+ * parser rather than a flag on the one above. A Val module for a route lives
10459
+ * beside the route file and is named the same way — `routes/posts.$postId.tsx`
10460
+ * is served content by `routes/posts.$postId.val.ts` — so the pattern is the
10461
+ * file path with the conventions applied:
10462
+ *
10463
+ * - `.` and `/` both separate segments (`posts.$postId.val.ts` and
10464
+ * `posts/$postId.val.ts` are the same route)
10465
+ * - `$param` is a dynamic segment, `$` on its own is a splat
10466
+ * - `index` is the directory's own route and contributes no segment
10467
+ * - `route` is a layout for the directory, likewise
10468
+ * - `(group)` folders and `_pathless` layout segments are not in the URL
10469
+ * - a trailing `_` on a segment opts out of nesting and is not in the URL
10470
+ *
10471
+ * The result is expressed in the SAME vocabulary the Next parser uses
10472
+ * (`[param]`, `[...param]`), because everything downstream — validation, the
10473
+ * sitemap, the key inputs in the Studio — is written against that vocabulary
10474
+ * and there is no reason for two.
10475
+ *
10476
+ * - /src/routes/posts.$postId.val.ts -> ["posts", "[postId]"]
10477
+ * - /routes/posts/$postId.val.ts -> ["posts", "[postId]"]
10478
+ * - /src/routes/index.val.ts -> []
10479
+ * - /src/routes/files.$.val.ts -> ["files", "[..._splat]"]
10480
+ * - /src/routes/(app)/_layout.about.val.ts -> ["about"]
10481
+ */
10482
+ function parseTanStackRoutePattern(moduleFilePath) {
10483
+ var segments = tanStackRouteSegments(moduleFilePath);
10484
+ if (segments === null) {
10485
+ return [];
10486
+ }
10487
+ return segments;
10488
+ }
10489
+
10490
+ /**
10491
+ * The segments, or `null` when the path is not a TanStack route module at all.
10492
+ *
10493
+ * Distinct from `parseTanStackRoutePattern`'s empty array, which is a real
10494
+ * answer: the root route `/` has no segments.
10495
+ */
10496
+ function tanStackRouteSegments(moduleFilePath) {
10497
+ if (!moduleFilePath || typeof moduleFilePath !== "string") {
10498
+ return null;
10499
+ }
10500
+ var match = moduleFilePath.match(/^(?:\/src)?\/routes\/(.+)\.val\.[tj]sx?$/);
10501
+ if (!match) {
10502
+ return null;
10503
+ }
10504
+ return tanStackSegmentsOfRoutePath(match[1]);
10505
+ }
10506
+
10507
+ /**
10508
+ * The URL segments of a TanStack route path, given relative to `routes/`.
10509
+ *
10510
+ * Exported because the Studio derives the same pattern from the same file path
10511
+ * and must not disagree with validation about what a route is.
10512
+ */
10513
+ function tanStackSegmentsOfRoutePath(routePath) {
10514
+ // `.` is a separator exactly like `/`, so flatten both before looking at any
10515
+ // segment: `posts/$postId.edit` and `posts.$postId.edit` are one route.
10516
+ var rawSegments = routePath.split("/").flatMap(function (part) {
10517
+ return part.split(".");
10518
+ }).filter(function (part) {
10519
+ return part !== "";
10520
+ });
10521
+ var segments = [];
10522
+ var _iterator3 = result._createForOfIteratorHelper(rawSegments),
10523
+ _step3;
10524
+ try {
10525
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
10526
+ var rawSegment = _step3.value;
10527
+ // A route group: a folder that organises files without appearing in the URL.
10528
+ if (rawSegment.startsWith("(") && rawSegment.endsWith(")")) {
10529
+ continue;
10530
+ }
10531
+ // A pathless layout route. `_layout` nests its children without adding a
10532
+ // segment; `index`/`route` are the directory's own route and its layout.
10533
+ if (rawSegment.startsWith("_")) {
10534
+ continue;
10535
+ }
10536
+ if (rawSegment === "index" || rawSegment === "route") {
10537
+ continue;
10538
+ }
10539
+ // A trailing `_` opts the segment out of layout nesting; the URL keeps the
10540
+ // name without it.
10541
+ var segment = rawSegment.endsWith("_") ? rawSegment.slice(0, -1) : rawSegment;
10542
+ if (segment === "$") {
10543
+ // A splat. Named `_splat` because that is the param name TanStack gives
10544
+ // it, so `useValRoute(pageVal, params)` can be handed the route's own
10545
+ // params object unchanged.
10546
+ segments.push("[..._splat]");
10547
+ continue;
10548
+ }
10549
+ if (segment.startsWith("$")) {
10550
+ segments.push("[".concat(segment.slice(1), "]"));
10551
+ continue;
10552
+ }
10553
+ segments.push(segment);
10554
+ }
10555
+ } catch (err) {
10556
+ _iterator3.e(err);
10557
+ } finally {
10558
+ _iterator3.f();
10559
+ }
10560
+ return segments;
10561
+ }
10562
+
10563
+ /**
10564
+ * The router for a TanStack Router (and TanStack Start) app.
10565
+ *
10566
+ * Like `nextAppRouter` this does not belong in core — it is here for the same
10567
+ * reason that one is: the serialized schema carries only a router id, so the
10568
+ * thing that turns an id back into a validator has to be somewhere every
10569
+ * consumer can reach.
10570
+ */
10571
+ var tanstackRouter = {
10572
+ getRouterId: function getRouterId() {
10573
+ return "tanstack-router";
10574
+ },
10575
+ validate: function validate(moduleFilePath, urlPaths) {
10576
+ var routePattern = parseTanStackRoutePattern(moduleFilePath);
10577
+ var errors = [];
10578
+ var _iterator4 = result._createForOfIteratorHelper(urlPaths),
10579
+ _step4;
10580
+ try {
10581
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
10582
+ var urlPath = _step4.value;
10583
+ var validation = validateUrlAgainstPattern(urlPath, routePattern);
10584
+ if (!validation.isValid) {
10585
+ errors.push({
10586
+ error: {
10587
+ message: "URL path \"".concat(urlPath, "\" does not match the route pattern for \"").concat(moduleFilePath, "\""),
10588
+ urlPath: urlPath,
10589
+ expectedPath: validation.expectedPath || null
10590
+ }
10591
+ });
10592
+ }
10593
+ }
10594
+ } catch (err) {
10595
+ _iterator4.e(err);
10596
+ } finally {
10597
+ _iterator4.f();
10598
+ }
10599
+ return errors;
10600
+ }
10601
+ };
10602
+
10603
+ /**
10604
+ * The routers whose keys are URL paths of THIS site, and how to read the route
10605
+ * pattern a module of each serves.
10606
+ *
10607
+ * Keyed by router id because that is all a serialized schema carries. A router
10608
+ * that is not in here — `external-url-router` today — has keys that are URLs of
10609
+ * somewhere else, so matching this site's pathname against them is meaningless
10610
+ * rather than merely unsupported.
10611
+ */
10612
+ var PAGE_ROUTE_PATTERN_PARSERS = {
10613
+ "next-app-router": parseNextJsRoutePattern,
10614
+ "tanstack-router": parseTanStackRoutePattern
10615
+ };
10616
+
10454
10617
  /**
10455
10618
  * Given a URL pathname (e.g. "/blogs/blog-1") and all serialized module schemas,
10456
- * finds the matching next-app-router module and returns the module file path
10457
- * and the source path for that route's content.
10619
+ * finds the page-router module that serves that route and returns the module
10620
+ * file path and the source path for that route's content.
10458
10621
  *
10459
10622
  * External routers (e.g. external-url-router) are intentionally skipped.
10460
- * Returns null if no next-app-router module matches the pathname.
10623
+ * Returns null if no page-router module matches the pathname.
10461
10624
  */
10462
10625
  function getSourcePathFromRoute(pathname, schemas) {
10463
10626
  for (var _i = 0, _arr = Object.entries(schemas); _i < _arr.length; _i++) {
10464
10627
  var _arr$_i = _slicedToArray(_arr[_i], 2),
10465
10628
  moduleFilePath = _arr$_i[0],
10466
10629
  schema = _arr$_i[1];
10467
- if (schema.type !== "record" || schema.router !== "next-app-router") {
10630
+ if (schema.type !== "record" || !schema.router) {
10468
10631
  continue;
10469
10632
  }
10470
- var routePattern = parseNextJsRoutePattern(moduleFilePath);
10633
+ var parseRoutePattern = PAGE_ROUTE_PATTERN_PARSERS[schema.router];
10634
+ if (!parseRoutePattern) {
10635
+ continue;
10636
+ }
10637
+ var routePattern = parseRoutePattern(moduleFilePath);
10471
10638
  var _validateUrlAgainstPa = validateUrlAgainstPattern(pathname, routePattern),
10472
10639
  isValid = _validateUrlAgainstPa.isValid;
10473
10640
  if (isValid) {
@@ -10482,20 +10649,81 @@ function getSourcePathFromRoute(pathname, schemas) {
10482
10649
  return null;
10483
10650
  }
10484
10651
 
10652
+ /**
10653
+ * Whether a router id is one whose keys are routes of this site.
10654
+ *
10655
+ * The same question `getSourcePathFromRoute` asks, exported because the Studio
10656
+ * asks it too — a page router gets the sitemap and the "Pages" menu, an
10657
+ * external one gets a flat list of URLs — and the two must not disagree about
10658
+ * which is which.
10659
+ */
10660
+ function isPageRouter(routerId) {
10661
+ return routerId in PAGE_ROUTE_PATTERN_PARSERS;
10662
+ }
10663
+
10664
+ var corePackageJson = {
10665
+ name: "@valbuild/core",
10666
+ version: "0.125.0",
10667
+ "private": false,
10668
+ description: "Val - supercharged hard-coded content",
10669
+ repository: {
10670
+ type: "git",
10671
+ url: "git+https://github.com/valbuild/val.git"
10672
+ },
10673
+ scripts: {
10674
+ typecheck: "tsc --noEmit",
10675
+ test: "jest",
10676
+ "analyze-trace": "npx tsc -p tsconfig.json --skipLibCheck --generateTrace trace; npx -p @typescript/analyze-trace analyze-trace trace; npx speedscope trace/trace.json"
10677
+ },
10678
+ main: "dist/valbuild-core.cjs.js",
10679
+ module: "dist/valbuild-core.esm.js",
10680
+ exports: {
10681
+ ".": {
10682
+ module: "./dist/valbuild-core.esm.js",
10683
+ "default": "./dist/valbuild-core.cjs.js"
10684
+ },
10685
+ "./fp": {
10686
+ module: "./fp/dist/valbuild-core-fp.esm.js",
10687
+ "default": "./fp/dist/valbuild-core-fp.cjs.js"
10688
+ },
10689
+ "./patch": {
10690
+ module: "./patch/dist/valbuild-core-patch.esm.js",
10691
+ "default": "./patch/dist/valbuild-core-patch.cjs.js"
10692
+ },
10693
+ "./package.json": "./package.json"
10694
+ },
10695
+ types: "dist/valbuild-core.cjs.d.ts",
10696
+ preconstruct: {
10697
+ entrypoints: [
10698
+ "./index.ts",
10699
+ "./fp/index.ts",
10700
+ "./patch/index.ts"
10701
+ ],
10702
+ exports: true
10703
+ },
10704
+ devDependencies: {
10705
+ typescript: "^6.0.3"
10706
+ },
10707
+ dependencies: {
10708
+ "ts-toolbelt": "^9.6.0"
10709
+ },
10710
+ files: [
10711
+ "CHANGELOG.md",
10712
+ "dist",
10713
+ "fp/dist",
10714
+ "fp/package.json",
10715
+ "patch/dist",
10716
+ "patch/package.json"
10717
+ ]
10718
+ };
10719
+
10485
10720
  var ModuleFilePathSep = "?p=";
10486
10721
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
10487
10722
  var DEFAULT_CONTENT_HOST = "https://content.val.build";
10488
10723
  var DEFAULT_APP_HOST = "https://admin.val.build";
10489
10724
  var Internal = {
10490
10725
  VERSION: {
10491
- core: function () {
10492
- try {
10493
- // eslint-disable-next-line @typescript-eslint/no-require-imports
10494
- return require("../package.json").version;
10495
- } catch (_unused) {
10496
- return null;
10497
- }
10498
- }()
10726
+ core: corePackageJson.version
10499
10727
  },
10500
10728
  mediaUrl: mediaUrl,
10501
10729
  resolveMedia: resolveMedia,
@@ -10512,6 +10740,7 @@ var Internal = {
10512
10740
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
10513
10741
  joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
10514
10742
  nextAppRouter: nextAppRouter,
10743
+ tanstackRouter: tanstackRouter,
10515
10744
  externalPageRouter: externalPageRouter,
10516
10745
  color: {
10517
10746
  parseColor: parseColor,
@@ -10600,7 +10829,7 @@ var Internal = {
10600
10829
  function tryJsonParse(str) {
10601
10830
  try {
10602
10831
  return JSON.parse(str);
10603
- } catch (_unused2) {
10832
+ } catch (_unused) {
10604
10833
  return str;
10605
10834
  }
10606
10835
  }
@@ -10653,8 +10882,13 @@ exports.hasMediaSchema = hasMediaSchema;
10653
10882
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
10654
10883
  exports.initVal = initVal;
10655
10884
  exports.isInlineRender = isInlineRender;
10885
+ exports.isPageRouter = isPageRouter;
10656
10886
  exports.isRootModuleFilePath = isRootModuleFilePath;
10657
10887
  exports.modules = modules;
10888
+ exports.parseNextJsRoutePattern = parseNextJsRoutePattern;
10889
+ exports.parseTanStackRoutePattern = parseTanStackRoutePattern;
10658
10890
  exports.previewScope = previewScope;
10659
10891
  exports.resolveSettingsModule = resolveSettingsModule;
10660
10892
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
10893
+ exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
10894
+ exports.validateUrlAgainstPattern = validateUrlAgainstPattern;
@@ -10451,23 +10451,190 @@ function parseNextJsRoutePattern(moduleFilePath) {
10451
10451
  return [];
10452
10452
  }
10453
10453
 
10454
+ /**
10455
+ * Parse a TanStack Router route pattern out of a Val module file path.
10456
+ *
10457
+ * TanStack Router's file conventions are not Next's, so this is a different
10458
+ * parser rather than a flag on the one above. A Val module for a route lives
10459
+ * beside the route file and is named the same way — `routes/posts.$postId.tsx`
10460
+ * is served content by `routes/posts.$postId.val.ts` — so the pattern is the
10461
+ * file path with the conventions applied:
10462
+ *
10463
+ * - `.` and `/` both separate segments (`posts.$postId.val.ts` and
10464
+ * `posts/$postId.val.ts` are the same route)
10465
+ * - `$param` is a dynamic segment, `$` on its own is a splat
10466
+ * - `index` is the directory's own route and contributes no segment
10467
+ * - `route` is a layout for the directory, likewise
10468
+ * - `(group)` folders and `_pathless` layout segments are not in the URL
10469
+ * - a trailing `_` on a segment opts out of nesting and is not in the URL
10470
+ *
10471
+ * The result is expressed in the SAME vocabulary the Next parser uses
10472
+ * (`[param]`, `[...param]`), because everything downstream — validation, the
10473
+ * sitemap, the key inputs in the Studio — is written against that vocabulary
10474
+ * and there is no reason for two.
10475
+ *
10476
+ * - /src/routes/posts.$postId.val.ts -> ["posts", "[postId]"]
10477
+ * - /routes/posts/$postId.val.ts -> ["posts", "[postId]"]
10478
+ * - /src/routes/index.val.ts -> []
10479
+ * - /src/routes/files.$.val.ts -> ["files", "[..._splat]"]
10480
+ * - /src/routes/(app)/_layout.about.val.ts -> ["about"]
10481
+ */
10482
+ function parseTanStackRoutePattern(moduleFilePath) {
10483
+ var segments = tanStackRouteSegments(moduleFilePath);
10484
+ if (segments === null) {
10485
+ return [];
10486
+ }
10487
+ return segments;
10488
+ }
10489
+
10490
+ /**
10491
+ * The segments, or `null` when the path is not a TanStack route module at all.
10492
+ *
10493
+ * Distinct from `parseTanStackRoutePattern`'s empty array, which is a real
10494
+ * answer: the root route `/` has no segments.
10495
+ */
10496
+ function tanStackRouteSegments(moduleFilePath) {
10497
+ if (!moduleFilePath || typeof moduleFilePath !== "string") {
10498
+ return null;
10499
+ }
10500
+ var match = moduleFilePath.match(/^(?:\/src)?\/routes\/(.+)\.val\.[tj]sx?$/);
10501
+ if (!match) {
10502
+ return null;
10503
+ }
10504
+ return tanStackSegmentsOfRoutePath(match[1]);
10505
+ }
10506
+
10507
+ /**
10508
+ * The URL segments of a TanStack route path, given relative to `routes/`.
10509
+ *
10510
+ * Exported because the Studio derives the same pattern from the same file path
10511
+ * and must not disagree with validation about what a route is.
10512
+ */
10513
+ function tanStackSegmentsOfRoutePath(routePath) {
10514
+ // `.` is a separator exactly like `/`, so flatten both before looking at any
10515
+ // segment: `posts/$postId.edit` and `posts.$postId.edit` are one route.
10516
+ var rawSegments = routePath.split("/").flatMap(function (part) {
10517
+ return part.split(".");
10518
+ }).filter(function (part) {
10519
+ return part !== "";
10520
+ });
10521
+ var segments = [];
10522
+ var _iterator3 = result._createForOfIteratorHelper(rawSegments),
10523
+ _step3;
10524
+ try {
10525
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
10526
+ var rawSegment = _step3.value;
10527
+ // A route group: a folder that organises files without appearing in the URL.
10528
+ if (rawSegment.startsWith("(") && rawSegment.endsWith(")")) {
10529
+ continue;
10530
+ }
10531
+ // A pathless layout route. `_layout` nests its children without adding a
10532
+ // segment; `index`/`route` are the directory's own route and its layout.
10533
+ if (rawSegment.startsWith("_")) {
10534
+ continue;
10535
+ }
10536
+ if (rawSegment === "index" || rawSegment === "route") {
10537
+ continue;
10538
+ }
10539
+ // A trailing `_` opts the segment out of layout nesting; the URL keeps the
10540
+ // name without it.
10541
+ var segment = rawSegment.endsWith("_") ? rawSegment.slice(0, -1) : rawSegment;
10542
+ if (segment === "$") {
10543
+ // A splat. Named `_splat` because that is the param name TanStack gives
10544
+ // it, so `useValRoute(pageVal, params)` can be handed the route's own
10545
+ // params object unchanged.
10546
+ segments.push("[..._splat]");
10547
+ continue;
10548
+ }
10549
+ if (segment.startsWith("$")) {
10550
+ segments.push("[".concat(segment.slice(1), "]"));
10551
+ continue;
10552
+ }
10553
+ segments.push(segment);
10554
+ }
10555
+ } catch (err) {
10556
+ _iterator3.e(err);
10557
+ } finally {
10558
+ _iterator3.f();
10559
+ }
10560
+ return segments;
10561
+ }
10562
+
10563
+ /**
10564
+ * The router for a TanStack Router (and TanStack Start) app.
10565
+ *
10566
+ * Like `nextAppRouter` this does not belong in core — it is here for the same
10567
+ * reason that one is: the serialized schema carries only a router id, so the
10568
+ * thing that turns an id back into a validator has to be somewhere every
10569
+ * consumer can reach.
10570
+ */
10571
+ var tanstackRouter = {
10572
+ getRouterId: function getRouterId() {
10573
+ return "tanstack-router";
10574
+ },
10575
+ validate: function validate(moduleFilePath, urlPaths) {
10576
+ var routePattern = parseTanStackRoutePattern(moduleFilePath);
10577
+ var errors = [];
10578
+ var _iterator4 = result._createForOfIteratorHelper(urlPaths),
10579
+ _step4;
10580
+ try {
10581
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
10582
+ var urlPath = _step4.value;
10583
+ var validation = validateUrlAgainstPattern(urlPath, routePattern);
10584
+ if (!validation.isValid) {
10585
+ errors.push({
10586
+ error: {
10587
+ message: "URL path \"".concat(urlPath, "\" does not match the route pattern for \"").concat(moduleFilePath, "\""),
10588
+ urlPath: urlPath,
10589
+ expectedPath: validation.expectedPath || null
10590
+ }
10591
+ });
10592
+ }
10593
+ }
10594
+ } catch (err) {
10595
+ _iterator4.e(err);
10596
+ } finally {
10597
+ _iterator4.f();
10598
+ }
10599
+ return errors;
10600
+ }
10601
+ };
10602
+
10603
+ /**
10604
+ * The routers whose keys are URL paths of THIS site, and how to read the route
10605
+ * pattern a module of each serves.
10606
+ *
10607
+ * Keyed by router id because that is all a serialized schema carries. A router
10608
+ * that is not in here — `external-url-router` today — has keys that are URLs of
10609
+ * somewhere else, so matching this site's pathname against them is meaningless
10610
+ * rather than merely unsupported.
10611
+ */
10612
+ var PAGE_ROUTE_PATTERN_PARSERS = {
10613
+ "next-app-router": parseNextJsRoutePattern,
10614
+ "tanstack-router": parseTanStackRoutePattern
10615
+ };
10616
+
10454
10617
  /**
10455
10618
  * Given a URL pathname (e.g. "/blogs/blog-1") and all serialized module schemas,
10456
- * finds the matching next-app-router module and returns the module file path
10457
- * and the source path for that route's content.
10619
+ * finds the page-router module that serves that route and returns the module
10620
+ * file path and the source path for that route's content.
10458
10621
  *
10459
10622
  * External routers (e.g. external-url-router) are intentionally skipped.
10460
- * Returns null if no next-app-router module matches the pathname.
10623
+ * Returns null if no page-router module matches the pathname.
10461
10624
  */
10462
10625
  function getSourcePathFromRoute(pathname, schemas) {
10463
10626
  for (var _i = 0, _arr = Object.entries(schemas); _i < _arr.length; _i++) {
10464
10627
  var _arr$_i = _slicedToArray(_arr[_i], 2),
10465
10628
  moduleFilePath = _arr$_i[0],
10466
10629
  schema = _arr$_i[1];
10467
- if (schema.type !== "record" || schema.router !== "next-app-router") {
10630
+ if (schema.type !== "record" || !schema.router) {
10468
10631
  continue;
10469
10632
  }
10470
- var routePattern = parseNextJsRoutePattern(moduleFilePath);
10633
+ var parseRoutePattern = PAGE_ROUTE_PATTERN_PARSERS[schema.router];
10634
+ if (!parseRoutePattern) {
10635
+ continue;
10636
+ }
10637
+ var routePattern = parseRoutePattern(moduleFilePath);
10471
10638
  var _validateUrlAgainstPa = validateUrlAgainstPattern(pathname, routePattern),
10472
10639
  isValid = _validateUrlAgainstPa.isValid;
10473
10640
  if (isValid) {
@@ -10482,20 +10649,81 @@ function getSourcePathFromRoute(pathname, schemas) {
10482
10649
  return null;
10483
10650
  }
10484
10651
 
10652
+ /**
10653
+ * Whether a router id is one whose keys are routes of this site.
10654
+ *
10655
+ * The same question `getSourcePathFromRoute` asks, exported because the Studio
10656
+ * asks it too — a page router gets the sitemap and the "Pages" menu, an
10657
+ * external one gets a flat list of URLs — and the two must not disagree about
10658
+ * which is which.
10659
+ */
10660
+ function isPageRouter(routerId) {
10661
+ return routerId in PAGE_ROUTE_PATTERN_PARSERS;
10662
+ }
10663
+
10664
+ var corePackageJson = {
10665
+ name: "@valbuild/core",
10666
+ version: "0.125.0",
10667
+ "private": false,
10668
+ description: "Val - supercharged hard-coded content",
10669
+ repository: {
10670
+ type: "git",
10671
+ url: "git+https://github.com/valbuild/val.git"
10672
+ },
10673
+ scripts: {
10674
+ typecheck: "tsc --noEmit",
10675
+ test: "jest",
10676
+ "analyze-trace": "npx tsc -p tsconfig.json --skipLibCheck --generateTrace trace; npx -p @typescript/analyze-trace analyze-trace trace; npx speedscope trace/trace.json"
10677
+ },
10678
+ main: "dist/valbuild-core.cjs.js",
10679
+ module: "dist/valbuild-core.esm.js",
10680
+ exports: {
10681
+ ".": {
10682
+ module: "./dist/valbuild-core.esm.js",
10683
+ "default": "./dist/valbuild-core.cjs.js"
10684
+ },
10685
+ "./fp": {
10686
+ module: "./fp/dist/valbuild-core-fp.esm.js",
10687
+ "default": "./fp/dist/valbuild-core-fp.cjs.js"
10688
+ },
10689
+ "./patch": {
10690
+ module: "./patch/dist/valbuild-core-patch.esm.js",
10691
+ "default": "./patch/dist/valbuild-core-patch.cjs.js"
10692
+ },
10693
+ "./package.json": "./package.json"
10694
+ },
10695
+ types: "dist/valbuild-core.cjs.d.ts",
10696
+ preconstruct: {
10697
+ entrypoints: [
10698
+ "./index.ts",
10699
+ "./fp/index.ts",
10700
+ "./patch/index.ts"
10701
+ ],
10702
+ exports: true
10703
+ },
10704
+ devDependencies: {
10705
+ typescript: "^6.0.3"
10706
+ },
10707
+ dependencies: {
10708
+ "ts-toolbelt": "^9.6.0"
10709
+ },
10710
+ files: [
10711
+ "CHANGELOG.md",
10712
+ "dist",
10713
+ "fp/dist",
10714
+ "fp/package.json",
10715
+ "patch/dist",
10716
+ "patch/package.json"
10717
+ ]
10718
+ };
10719
+
10485
10720
  var ModuleFilePathSep = "?p=";
10486
10721
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
10487
10722
  var DEFAULT_CONTENT_HOST = "https://content.val.build";
10488
10723
  var DEFAULT_APP_HOST = "https://admin.val.build";
10489
10724
  var Internal = {
10490
10725
  VERSION: {
10491
- core: function () {
10492
- try {
10493
- // eslint-disable-next-line @typescript-eslint/no-require-imports
10494
- return require("../package.json").version;
10495
- } catch (_unused) {
10496
- return null;
10497
- }
10498
- }()
10726
+ core: corePackageJson.version
10499
10727
  },
10500
10728
  mediaUrl: mediaUrl,
10501
10729
  resolveMedia: resolveMedia,
@@ -10512,6 +10740,7 @@ var Internal = {
10512
10740
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
10513
10741
  joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
10514
10742
  nextAppRouter: nextAppRouter,
10743
+ tanstackRouter: tanstackRouter,
10515
10744
  externalPageRouter: externalPageRouter,
10516
10745
  color: {
10517
10746
  parseColor: parseColor,
@@ -10600,7 +10829,7 @@ var Internal = {
10600
10829
  function tryJsonParse(str) {
10601
10830
  try {
10602
10831
  return JSON.parse(str);
10603
- } catch (_unused2) {
10832
+ } catch (_unused) {
10604
10833
  return str;
10605
10834
  }
10606
10835
  }
@@ -10653,8 +10882,13 @@ exports.hasMediaSchema = hasMediaSchema;
10653
10882
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
10654
10883
  exports.initVal = initVal;
10655
10884
  exports.isInlineRender = isInlineRender;
10885
+ exports.isPageRouter = isPageRouter;
10656
10886
  exports.isRootModuleFilePath = isRootModuleFilePath;
10657
10887
  exports.modules = modules;
10888
+ exports.parseNextJsRoutePattern = parseNextJsRoutePattern;
10889
+ exports.parseTanStackRoutePattern = parseTanStackRoutePattern;
10658
10890
  exports.previewScope = previewScope;
10659
10891
  exports.resolveSettingsModule = resolveSettingsModule;
10660
10892
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
10893
+ exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
10894
+ exports.validateUrlAgainstPattern = validateUrlAgainstPattern;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-fcd087bd.cjs.dev.js');
5
+ var dist_valbuildCore = require('./index-daa122af.cjs.dev.js');
6
6
  require('./result-bb1f436e.cjs.dev.js');
7
7
 
8
8
 
@@ -49,7 +49,12 @@ exports.hasMediaSchema = dist_valbuildCore.hasMediaSchema;
49
49
  exports.hasRemoteFileSchema = dist_valbuildCore.hasRemoteFileSchema;
50
50
  exports.initVal = dist_valbuildCore.initVal;
51
51
  exports.isInlineRender = dist_valbuildCore.isInlineRender;
52
+ exports.isPageRouter = dist_valbuildCore.isPageRouter;
52
53
  exports.isRootModuleFilePath = dist_valbuildCore.isRootModuleFilePath;
53
54
  exports.modules = dist_valbuildCore.modules;
55
+ exports.parseNextJsRoutePattern = dist_valbuildCore.parseNextJsRoutePattern;
56
+ exports.parseTanStackRoutePattern = dist_valbuildCore.parseTanStackRoutePattern;
54
57
  exports.previewScope = dist_valbuildCore.previewScope;
55
58
  exports.resolveSettingsModule = dist_valbuildCore.resolveSettingsModule;
59
+ exports.tanStackSegmentsOfRoutePath = dist_valbuildCore.tanStackSegmentsOfRoutePath;
60
+ exports.validateUrlAgainstPattern = dist_valbuildCore.validateUrlAgainstPattern;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('./index-22a40d42.cjs.prod.js');
5
+ var dist_valbuildCore = require('./index-a3846321.cjs.prod.js');
6
6
  require('./result-787e35f6.cjs.prod.js');
7
7
 
8
8
 
@@ -49,7 +49,12 @@ exports.hasMediaSchema = dist_valbuildCore.hasMediaSchema;
49
49
  exports.hasRemoteFileSchema = dist_valbuildCore.hasRemoteFileSchema;
50
50
  exports.initVal = dist_valbuildCore.initVal;
51
51
  exports.isInlineRender = dist_valbuildCore.isInlineRender;
52
+ exports.isPageRouter = dist_valbuildCore.isPageRouter;
52
53
  exports.isRootModuleFilePath = dist_valbuildCore.isRootModuleFilePath;
53
54
  exports.modules = dist_valbuildCore.modules;
55
+ exports.parseNextJsRoutePattern = dist_valbuildCore.parseNextJsRoutePattern;
56
+ exports.parseTanStackRoutePattern = dist_valbuildCore.parseTanStackRoutePattern;
54
57
  exports.previewScope = dist_valbuildCore.previewScope;
55
58
  exports.resolveSettingsModule = dist_valbuildCore.resolveSettingsModule;
59
+ exports.tanStackSegmentsOfRoutePath = dist_valbuildCore.tanStackSegmentsOfRoutePath;
60
+ exports.validateUrlAgainstPattern = dist_valbuildCore.validateUrlAgainstPattern;
@@ -1,2 +1,2 @@
1
- export { t as ASSISTANT_SETTINGS_MAX_LENGTH, A as ArraySchema, B as BooleanSchema, z as CODE_LANGUAGES, E as COLOR_FORMATS, y as CodeSchema, C as ColorSchema, e as DEFAULT_APP_HOST, H as DEFAULT_COLOR_FORMAT, D as DEFAULT_CONTENT_HOST, k as DEFAULT_VAL_REMOTE_HOST, q as DateSchema, J as DateTimeSchema, F as FATAL_ERROR_TYPES, p as FileSchema, G as GenericSelector, o as ImageSchema, I as Internal, K as KeyOfSchema, T as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, Q as RichTextSchema, L as RouteSchema, v as SETTINGS_MODULE_CONVENTION, S as Schema, r as SettingsSchema, n as StringSchema, U as UnionSchema, V as VAL_EXTENSION, u as assistantAvailability, g as computeValModuleShas, l as derefPatch, W as deserializeSchema, f as extractValModules, Z as getSourcePathFromRoute, j as hasMediaSchema, h as hasRemoteFileSchema, i as initVal, Y as isInlineRender, w as isRootModuleFilePath, m as modules, X as previewScope, x as resolveSettingsModule } from './index-9c14df37.esm.js';
1
+ export { t as ASSISTANT_SETTINGS_MAX_LENGTH, A as ArraySchema, B as BooleanSchema, z as CODE_LANGUAGES, E as COLOR_FORMATS, y as CodeSchema, C as ColorSchema, e as DEFAULT_APP_HOST, H as DEFAULT_COLOR_FORMAT, D as DEFAULT_CONTENT_HOST, k as DEFAULT_VAL_REMOTE_HOST, q as DateSchema, J as DateTimeSchema, F as FATAL_ERROR_TYPES, p as FileSchema, G as GenericSelector, o as ImageSchema, I as Internal, K as KeyOfSchema, T as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, Q as RichTextSchema, L as RouteSchema, v as SETTINGS_MODULE_CONVENTION, S as Schema, r as SettingsSchema, n as StringSchema, U as UnionSchema, V as VAL_EXTENSION, u as assistantAvailability, g as computeValModuleShas, l as derefPatch, W as deserializeSchema, f as extractValModules, a2 as getSourcePathFromRoute, j as hasMediaSchema, h as hasRemoteFileSchema, i as initVal, Y as isInlineRender, a3 as isPageRouter, w as isRootModuleFilePath, m as modules, Z as parseNextJsRoutePattern, $ as parseTanStackRoutePattern, X as previewScope, x as resolveSettingsModule, a0 as tanStackSegmentsOfRoutePath, a1 as validateUrlAgainstPattern } from './index-915dd675.esm.js';
2
2
  import './result-daff1cae.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.124.0",
3
+ "version": "0.125.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "repository": {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('../../dist/index-fcd087bd.cjs.dev.js');
5
+ var dist_valbuildCore = require('../../dist/index-daa122af.cjs.dev.js');
6
6
  var result = require('../../dist/result-bb1f436e.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dist_valbuildCore = require('../../dist/index-22a40d42.cjs.prod.js');
5
+ var dist_valbuildCore = require('../../dist/index-a3846321.cjs.prod.js');
6
6
  var result = require('../../dist/result-787e35f6.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
8
 
@@ -1,5 +1,5 @@
1
- import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-9c14df37.esm.js';
2
- export { P as PatchError } from '../../dist/index-9c14df37.esm.js';
1
+ import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-915dd675.esm.js';
2
+ export { P as PatchError } from '../../dist/index-915dd675.esm.js';
3
3
  import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-daff1cae.esm.js';
4
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
5
5