@valbuild/shared 0.83.0 → 0.84.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.
@@ -0,0 +1,2 @@
1
+ import { ModuleFilePath } from "@valbuild/core";
2
+ export declare function getNextAppRouterSourceFolder(moduleFilePath: ModuleFilePath): "/app" | "/src/app" | null;
@@ -0,0 +1,30 @@
1
+ import { ModuleFilePath, SourcePath } from "@valbuild/core";
2
+ export type PageNode = {
3
+ type: "leaf";
4
+ name: string;
5
+ fullPath?: string;
6
+ moduleFilePath: ModuleFilePath;
7
+ sourcePath: SourcePath | ModuleFilePath;
8
+ pattern?: string;
9
+ children: (SitemapNode | PageNode)[];
10
+ };
11
+ export type SitemapNode = {
12
+ type: "node";
13
+ name: string;
14
+ page?: {
15
+ /** If a page is present this is a folder that is also a page */
16
+ fullPath: string;
17
+ };
18
+ /** If a pattern is present you can add new children to this node */
19
+ pattern?: string;
20
+ /** Means that there is only one child essentially */
21
+ isLinear?: true;
22
+ children: (SitemapNode | PageNode)[];
23
+ moduleFilePath?: ModuleFilePath;
24
+ sourcePath?: SourcePath | ModuleFilePath;
25
+ };
26
+ export declare function getNextAppRouterSitemapTree(srcFolder: string, paths: {
27
+ urlPath: string;
28
+ moduleFilePath: string;
29
+ }[]): SitemapNode;
30
+ export declare function getPatternFromModuleFilePath(moduleFilePath: string, srcFolder: string): string;
@@ -8,3 +8,6 @@ export * from "./listeners.js";
8
8
  export * from "./SharedValConfig.js";
9
9
  export * from "./zod/ValCommit.js";
10
10
  export * from "./zod/ValDeployment.js";
11
+ export * from "./getSitemapTree.js";
12
+ export * from "./parseRoutePattern.js";
13
+ export * from "./getNextAppRouterSourceFolder.js";
@@ -0,0 +1,13 @@
1
+ export type RoutePattern = {
2
+ type: "literal";
3
+ name: string;
4
+ } | {
5
+ type: "string-param";
6
+ paramName: string;
7
+ optional: boolean;
8
+ } | {
9
+ type: "array-param";
10
+ paramName: string;
11
+ optional: boolean;
12
+ };
13
+ export declare function parseRoutePattern(pattern: string): RoutePattern[];
@@ -1299,7 +1299,14 @@ var SerializedKeyOfSchema = zod.z.lazy(function () {
1299
1299
  return zod.z.object({
1300
1300
  type: zod.z.literal("keyOf"),
1301
1301
  path: SourcePath,
1302
- schema: SerializedSchema,
1302
+ schema: zod.z.union([zod.z.object({
1303
+ type: zod.z.literal("object"),
1304
+ keys: zod.z.array(zod.z.string()),
1305
+ opt: zod.z["boolean"]().optional()
1306
+ }), zod.z.object({
1307
+ type: zod.z.literal("record"),
1308
+ opt: zod.z["boolean"]().optional()
1309
+ })]).optional(),
1303
1310
  values: zod.z.union([zod.z.literal("string"), zod.z.array(zod.z.string())]),
1304
1311
  opt: zod.z["boolean"]()
1305
1312
  });
@@ -2427,6 +2434,170 @@ var ValDeployment = zod.z.object({
2427
2434
  createdAt: zod.z.string()
2428
2435
  });
2429
2436
 
2437
+ // Strictly speaking this should be in the next package but it's shared, because we want to use it in the ui package. We want to resolve that somehow
2438
+ function getNextAppRouterSitemapTree(srcFolder, paths) {
2439
+ var root = {
2440
+ type: "node",
2441
+ name: "/",
2442
+ children: []
2443
+ };
2444
+ var _iterator = _createForOfIteratorHelper(paths),
2445
+ _step;
2446
+ try {
2447
+ var _loop = function _loop() {
2448
+ var path = _step.value;
2449
+ var urlPath = path.urlPath,
2450
+ moduleFilePathS = path.moduleFilePath;
2451
+ var moduleFilePath = moduleFilePathS;
2452
+ if (!urlPath.startsWith("/")) {
2453
+ console.error("urlPath must start with /: ".concat(urlPath));
2454
+ return 0; // continue
2455
+ }
2456
+ var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2457
+ if (urlPath === "/") {
2458
+ var fullPath = "/";
2459
+ root.pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2460
+ root.page = {
2461
+ fullPath: fullPath
2462
+ };
2463
+ root.sourcePath = core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, fullPath);
2464
+ root.moduleFilePath = moduleFilePath;
2465
+ return 0; // continue
2466
+ }
2467
+ var pathParts = urlPath.split("/").slice(1).filter(Boolean);
2468
+ var currentNode = root;
2469
+ pathParts.forEach(function (part, index) {
2470
+ var hasChildren = index < pathParts.length - 1;
2471
+ var isLast = index === pathParts.length - 1;
2472
+ var fullPath = "/" + pathParts.slice(0, index + 1).join("/");
2473
+ var sourcePath = core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, "\"".concat(fullPath, "\""));
2474
+ var node = hasChildren ? _objectSpread2(_objectSpread2({
2475
+ type: "node",
2476
+ name: part,
2477
+ pattern: pattern,
2478
+ moduleFilePath: moduleFilePath
2479
+ }, isLast ? {
2480
+ page: {
2481
+ fullPath: fullPath
2482
+ },
2483
+ sourcePath: sourcePath
2484
+ } : {}), {}, {
2485
+ children: []
2486
+ }) : {
2487
+ type: "leaf",
2488
+ name: part,
2489
+ pattern: pattern,
2490
+ fullPath: fullPath,
2491
+ moduleFilePath: moduleFilePath,
2492
+ sourcePath: sourcePath,
2493
+ children: []
2494
+ };
2495
+ var existingNodeIndex = currentNode.children.findIndex(function (node) {
2496
+ return node.name === part;
2497
+ });
2498
+ if (existingNodeIndex === -1) {
2499
+ currentNode.children.push(node);
2500
+ if (currentNode.type === "node") {
2501
+ currentNode.isLinear = true;
2502
+ if (currentNode.children.length > 1) {
2503
+ delete currentNode.isLinear;
2504
+ }
2505
+ }
2506
+ currentNode = node;
2507
+ } else {
2508
+ var existingNode = currentNode.children[existingNodeIndex];
2509
+ if (existingNode.type === "leaf" && hasChildren) {
2510
+ var _sourcePath = existingNode.sourcePath;
2511
+ // convert leaf to node
2512
+ currentNode.children[existingNodeIndex] = {
2513
+ type: "node",
2514
+ name: part,
2515
+ pattern: pattern,
2516
+ page: {
2517
+ fullPath: fullPath
2518
+ },
2519
+ sourcePath: _sourcePath,
2520
+ children: existingNode.children,
2521
+ moduleFilePath: moduleFilePath
2522
+ };
2523
+ currentNode = currentNode.children[existingNodeIndex];
2524
+ } else if (existingNode.type === "node" && isLast) {
2525
+ // add page, source path and module file path
2526
+ existingNode.page = {
2527
+ fullPath: fullPath
2528
+ };
2529
+ existingNode.sourcePath = sourcePath;
2530
+ existingNode.moduleFilePath = moduleFilePath;
2531
+ existingNode.pattern = pattern;
2532
+ } else {
2533
+ currentNode = currentNode.children[existingNodeIndex];
2534
+ }
2535
+ }
2536
+ });
2537
+ },
2538
+ _ret;
2539
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2540
+ _ret = _loop();
2541
+ if (_ret === 0) continue;
2542
+ }
2543
+ } catch (err) {
2544
+ _iterator.e(err);
2545
+ } finally {
2546
+ _iterator.f();
2547
+ }
2548
+ return root;
2549
+ }
2550
+ function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
2551
+ return moduleFilePath.replace(srcFolder, "")
2552
+ // TODO: hacky!
2553
+ // remove route groups
2554
+ .replace(/\/\([^/]+\)/g, "") // not sure we want to do this?
2555
+ .replace("/page.val.ts", "").replace("/page.val.js", "");
2556
+ }
2557
+
2558
+ function parseRoutePattern(pattern) {
2559
+ if (pattern === "" || pattern === "/") {
2560
+ return [];
2561
+ }
2562
+ var p = pattern.startsWith("/") ? pattern.slice(1) : pattern;
2563
+ return p.split("/").map(function (part) {
2564
+ var isOptionalParam = part.startsWith("[[") && part.endsWith("]]");
2565
+ var isNonOptionalParam = part.startsWith("[") && part.endsWith("]");
2566
+ var nameStart = isOptionalParam ? 2 : isNonOptionalParam ? 1 : 0;
2567
+ var nameEnd = part.indexOf("]", nameStart);
2568
+ var isArrayParam = part.slice(nameStart, nameStart + 3) === "...";
2569
+ var paramName = part.slice(nameStart + (isArrayParam ? 3 : 0), nameEnd);
2570
+ if (isOptionalParam || isNonOptionalParam) {
2571
+ if (isArrayParam) {
2572
+ return {
2573
+ type: "array-param",
2574
+ paramName: paramName,
2575
+ optional: isOptionalParam
2576
+ };
2577
+ } else {
2578
+ return {
2579
+ type: "string-param",
2580
+ paramName: paramName,
2581
+ optional: isOptionalParam
2582
+ };
2583
+ }
2584
+ }
2585
+ return {
2586
+ type: "literal",
2587
+ name: part
2588
+ };
2589
+ });
2590
+ }
2591
+
2592
+ function getNextAppRouterSourceFolder(moduleFilePath) {
2593
+ if (moduleFilePath.startsWith("/app")) {
2594
+ return "/app";
2595
+ } else if (moduleFilePath.startsWith("/src/app")) {
2596
+ return "/src/app";
2597
+ }
2598
+ return null;
2599
+ }
2600
+
2430
2601
  exports.Api = Api;
2431
2602
  exports.ParentRef = ParentRef$1;
2432
2603
  exports.Patch = Patch;
@@ -2453,6 +2624,10 @@ exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
2453
2624
  exports.ValCommit = ValCommit;
2454
2625
  exports.ValDeployment = ValDeployment;
2455
2626
  exports.createValClient = createValClient;
2627
+ exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
2628
+ exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
2629
+ exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
2630
+ exports.parseRoutePattern = parseRoutePattern;
2456
2631
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
2457
2632
  exports.richTextToRemirror = richTextToRemirror;
2458
2633
  exports.urlOf = urlOf;
@@ -1299,7 +1299,14 @@ var SerializedKeyOfSchema = zod.z.lazy(function () {
1299
1299
  return zod.z.object({
1300
1300
  type: zod.z.literal("keyOf"),
1301
1301
  path: SourcePath,
1302
- schema: SerializedSchema,
1302
+ schema: zod.z.union([zod.z.object({
1303
+ type: zod.z.literal("object"),
1304
+ keys: zod.z.array(zod.z.string()),
1305
+ opt: zod.z["boolean"]().optional()
1306
+ }), zod.z.object({
1307
+ type: zod.z.literal("record"),
1308
+ opt: zod.z["boolean"]().optional()
1309
+ })]).optional(),
1303
1310
  values: zod.z.union([zod.z.literal("string"), zod.z.array(zod.z.string())]),
1304
1311
  opt: zod.z["boolean"]()
1305
1312
  });
@@ -2427,6 +2434,170 @@ var ValDeployment = zod.z.object({
2427
2434
  createdAt: zod.z.string()
2428
2435
  });
2429
2436
 
2437
+ // Strictly speaking this should be in the next package but it's shared, because we want to use it in the ui package. We want to resolve that somehow
2438
+ function getNextAppRouterSitemapTree(srcFolder, paths) {
2439
+ var root = {
2440
+ type: "node",
2441
+ name: "/",
2442
+ children: []
2443
+ };
2444
+ var _iterator = _createForOfIteratorHelper(paths),
2445
+ _step;
2446
+ try {
2447
+ var _loop = function _loop() {
2448
+ var path = _step.value;
2449
+ var urlPath = path.urlPath,
2450
+ moduleFilePathS = path.moduleFilePath;
2451
+ var moduleFilePath = moduleFilePathS;
2452
+ if (!urlPath.startsWith("/")) {
2453
+ console.error("urlPath must start with /: ".concat(urlPath));
2454
+ return 0; // continue
2455
+ }
2456
+ var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2457
+ if (urlPath === "/") {
2458
+ var fullPath = "/";
2459
+ root.pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2460
+ root.page = {
2461
+ fullPath: fullPath
2462
+ };
2463
+ root.sourcePath = core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, fullPath);
2464
+ root.moduleFilePath = moduleFilePath;
2465
+ return 0; // continue
2466
+ }
2467
+ var pathParts = urlPath.split("/").slice(1).filter(Boolean);
2468
+ var currentNode = root;
2469
+ pathParts.forEach(function (part, index) {
2470
+ var hasChildren = index < pathParts.length - 1;
2471
+ var isLast = index === pathParts.length - 1;
2472
+ var fullPath = "/" + pathParts.slice(0, index + 1).join("/");
2473
+ var sourcePath = core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, "\"".concat(fullPath, "\""));
2474
+ var node = hasChildren ? _objectSpread2(_objectSpread2({
2475
+ type: "node",
2476
+ name: part,
2477
+ pattern: pattern,
2478
+ moduleFilePath: moduleFilePath
2479
+ }, isLast ? {
2480
+ page: {
2481
+ fullPath: fullPath
2482
+ },
2483
+ sourcePath: sourcePath
2484
+ } : {}), {}, {
2485
+ children: []
2486
+ }) : {
2487
+ type: "leaf",
2488
+ name: part,
2489
+ pattern: pattern,
2490
+ fullPath: fullPath,
2491
+ moduleFilePath: moduleFilePath,
2492
+ sourcePath: sourcePath,
2493
+ children: []
2494
+ };
2495
+ var existingNodeIndex = currentNode.children.findIndex(function (node) {
2496
+ return node.name === part;
2497
+ });
2498
+ if (existingNodeIndex === -1) {
2499
+ currentNode.children.push(node);
2500
+ if (currentNode.type === "node") {
2501
+ currentNode.isLinear = true;
2502
+ if (currentNode.children.length > 1) {
2503
+ delete currentNode.isLinear;
2504
+ }
2505
+ }
2506
+ currentNode = node;
2507
+ } else {
2508
+ var existingNode = currentNode.children[existingNodeIndex];
2509
+ if (existingNode.type === "leaf" && hasChildren) {
2510
+ var _sourcePath = existingNode.sourcePath;
2511
+ // convert leaf to node
2512
+ currentNode.children[existingNodeIndex] = {
2513
+ type: "node",
2514
+ name: part,
2515
+ pattern: pattern,
2516
+ page: {
2517
+ fullPath: fullPath
2518
+ },
2519
+ sourcePath: _sourcePath,
2520
+ children: existingNode.children,
2521
+ moduleFilePath: moduleFilePath
2522
+ };
2523
+ currentNode = currentNode.children[existingNodeIndex];
2524
+ } else if (existingNode.type === "node" && isLast) {
2525
+ // add page, source path and module file path
2526
+ existingNode.page = {
2527
+ fullPath: fullPath
2528
+ };
2529
+ existingNode.sourcePath = sourcePath;
2530
+ existingNode.moduleFilePath = moduleFilePath;
2531
+ existingNode.pattern = pattern;
2532
+ } else {
2533
+ currentNode = currentNode.children[existingNodeIndex];
2534
+ }
2535
+ }
2536
+ });
2537
+ },
2538
+ _ret;
2539
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2540
+ _ret = _loop();
2541
+ if (_ret === 0) continue;
2542
+ }
2543
+ } catch (err) {
2544
+ _iterator.e(err);
2545
+ } finally {
2546
+ _iterator.f();
2547
+ }
2548
+ return root;
2549
+ }
2550
+ function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
2551
+ return moduleFilePath.replace(srcFolder, "")
2552
+ // TODO: hacky!
2553
+ // remove route groups
2554
+ .replace(/\/\([^/]+\)/g, "") // not sure we want to do this?
2555
+ .replace("/page.val.ts", "").replace("/page.val.js", "");
2556
+ }
2557
+
2558
+ function parseRoutePattern(pattern) {
2559
+ if (pattern === "" || pattern === "/") {
2560
+ return [];
2561
+ }
2562
+ var p = pattern.startsWith("/") ? pattern.slice(1) : pattern;
2563
+ return p.split("/").map(function (part) {
2564
+ var isOptionalParam = part.startsWith("[[") && part.endsWith("]]");
2565
+ var isNonOptionalParam = part.startsWith("[") && part.endsWith("]");
2566
+ var nameStart = isOptionalParam ? 2 : isNonOptionalParam ? 1 : 0;
2567
+ var nameEnd = part.indexOf("]", nameStart);
2568
+ var isArrayParam = part.slice(nameStart, nameStart + 3) === "...";
2569
+ var paramName = part.slice(nameStart + (isArrayParam ? 3 : 0), nameEnd);
2570
+ if (isOptionalParam || isNonOptionalParam) {
2571
+ if (isArrayParam) {
2572
+ return {
2573
+ type: "array-param",
2574
+ paramName: paramName,
2575
+ optional: isOptionalParam
2576
+ };
2577
+ } else {
2578
+ return {
2579
+ type: "string-param",
2580
+ paramName: paramName,
2581
+ optional: isOptionalParam
2582
+ };
2583
+ }
2584
+ }
2585
+ return {
2586
+ type: "literal",
2587
+ name: part
2588
+ };
2589
+ });
2590
+ }
2591
+
2592
+ function getNextAppRouterSourceFolder(moduleFilePath) {
2593
+ if (moduleFilePath.startsWith("/app")) {
2594
+ return "/app";
2595
+ } else if (moduleFilePath.startsWith("/src/app")) {
2596
+ return "/src/app";
2597
+ }
2598
+ return null;
2599
+ }
2600
+
2430
2601
  exports.Api = Api;
2431
2602
  exports.ParentRef = ParentRef$1;
2432
2603
  exports.Patch = Patch;
@@ -2453,6 +2624,10 @@ exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
2453
2624
  exports.ValCommit = ValCommit;
2454
2625
  exports.ValDeployment = ValDeployment;
2455
2626
  exports.createValClient = createValClient;
2627
+ exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
2628
+ exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
2629
+ exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
2630
+ exports.parseRoutePattern = parseRoutePattern;
2456
2631
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
2457
2632
  exports.richTextToRemirror = richTextToRemirror;
2458
2633
  exports.urlOf = urlOf;
@@ -1295,7 +1295,14 @@ var SerializedKeyOfSchema = z.lazy(function () {
1295
1295
  return z.object({
1296
1296
  type: z.literal("keyOf"),
1297
1297
  path: SourcePath,
1298
- schema: SerializedSchema,
1298
+ schema: z.union([z.object({
1299
+ type: z.literal("object"),
1300
+ keys: z.array(z.string()),
1301
+ opt: z["boolean"]().optional()
1302
+ }), z.object({
1303
+ type: z.literal("record"),
1304
+ opt: z["boolean"]().optional()
1305
+ })]).optional(),
1299
1306
  values: z.union([z.literal("string"), z.array(z.string())]),
1300
1307
  opt: z["boolean"]()
1301
1308
  });
@@ -2423,4 +2430,168 @@ var ValDeployment = z.object({
2423
2430
  createdAt: z.string()
2424
2431
  });
2425
2432
 
2426
- export { Api, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, SharedValConfig, VAL_CONFIG_LISTENER, VAL_CONFIG_RECEIVED_LISTENER, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValCommit, ValDeployment, createValClient, remirrorToRichTextSource, richTextToRemirror, urlOf };
2433
+ // Strictly speaking this should be in the next package but it's shared, because we want to use it in the ui package. We want to resolve that somehow
2434
+ function getNextAppRouterSitemapTree(srcFolder, paths) {
2435
+ var root = {
2436
+ type: "node",
2437
+ name: "/",
2438
+ children: []
2439
+ };
2440
+ var _iterator = _createForOfIteratorHelper(paths),
2441
+ _step;
2442
+ try {
2443
+ var _loop = function _loop() {
2444
+ var path = _step.value;
2445
+ var urlPath = path.urlPath,
2446
+ moduleFilePathS = path.moduleFilePath;
2447
+ var moduleFilePath = moduleFilePathS;
2448
+ if (!urlPath.startsWith("/")) {
2449
+ console.error("urlPath must start with /: ".concat(urlPath));
2450
+ return 0; // continue
2451
+ }
2452
+ var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2453
+ if (urlPath === "/") {
2454
+ var fullPath = "/";
2455
+ root.pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
2456
+ root.page = {
2457
+ fullPath: fullPath
2458
+ };
2459
+ root.sourcePath = Internal.joinModuleFilePathAndModulePath(moduleFilePath, fullPath);
2460
+ root.moduleFilePath = moduleFilePath;
2461
+ return 0; // continue
2462
+ }
2463
+ var pathParts = urlPath.split("/").slice(1).filter(Boolean);
2464
+ var currentNode = root;
2465
+ pathParts.forEach(function (part, index) {
2466
+ var hasChildren = index < pathParts.length - 1;
2467
+ var isLast = index === pathParts.length - 1;
2468
+ var fullPath = "/" + pathParts.slice(0, index + 1).join("/");
2469
+ var sourcePath = Internal.joinModuleFilePathAndModulePath(moduleFilePath, "\"".concat(fullPath, "\""));
2470
+ var node = hasChildren ? _objectSpread2(_objectSpread2({
2471
+ type: "node",
2472
+ name: part,
2473
+ pattern: pattern,
2474
+ moduleFilePath: moduleFilePath
2475
+ }, isLast ? {
2476
+ page: {
2477
+ fullPath: fullPath
2478
+ },
2479
+ sourcePath: sourcePath
2480
+ } : {}), {}, {
2481
+ children: []
2482
+ }) : {
2483
+ type: "leaf",
2484
+ name: part,
2485
+ pattern: pattern,
2486
+ fullPath: fullPath,
2487
+ moduleFilePath: moduleFilePath,
2488
+ sourcePath: sourcePath,
2489
+ children: []
2490
+ };
2491
+ var existingNodeIndex = currentNode.children.findIndex(function (node) {
2492
+ return node.name === part;
2493
+ });
2494
+ if (existingNodeIndex === -1) {
2495
+ currentNode.children.push(node);
2496
+ if (currentNode.type === "node") {
2497
+ currentNode.isLinear = true;
2498
+ if (currentNode.children.length > 1) {
2499
+ delete currentNode.isLinear;
2500
+ }
2501
+ }
2502
+ currentNode = node;
2503
+ } else {
2504
+ var existingNode = currentNode.children[existingNodeIndex];
2505
+ if (existingNode.type === "leaf" && hasChildren) {
2506
+ var _sourcePath = existingNode.sourcePath;
2507
+ // convert leaf to node
2508
+ currentNode.children[existingNodeIndex] = {
2509
+ type: "node",
2510
+ name: part,
2511
+ pattern: pattern,
2512
+ page: {
2513
+ fullPath: fullPath
2514
+ },
2515
+ sourcePath: _sourcePath,
2516
+ children: existingNode.children,
2517
+ moduleFilePath: moduleFilePath
2518
+ };
2519
+ currentNode = currentNode.children[existingNodeIndex];
2520
+ } else if (existingNode.type === "node" && isLast) {
2521
+ // add page, source path and module file path
2522
+ existingNode.page = {
2523
+ fullPath: fullPath
2524
+ };
2525
+ existingNode.sourcePath = sourcePath;
2526
+ existingNode.moduleFilePath = moduleFilePath;
2527
+ existingNode.pattern = pattern;
2528
+ } else {
2529
+ currentNode = currentNode.children[existingNodeIndex];
2530
+ }
2531
+ }
2532
+ });
2533
+ },
2534
+ _ret;
2535
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2536
+ _ret = _loop();
2537
+ if (_ret === 0) continue;
2538
+ }
2539
+ } catch (err) {
2540
+ _iterator.e(err);
2541
+ } finally {
2542
+ _iterator.f();
2543
+ }
2544
+ return root;
2545
+ }
2546
+ function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
2547
+ return moduleFilePath.replace(srcFolder, "")
2548
+ // TODO: hacky!
2549
+ // remove route groups
2550
+ .replace(/\/\([^/]+\)/g, "") // not sure we want to do this?
2551
+ .replace("/page.val.ts", "").replace("/page.val.js", "");
2552
+ }
2553
+
2554
+ function parseRoutePattern(pattern) {
2555
+ if (pattern === "" || pattern === "/") {
2556
+ return [];
2557
+ }
2558
+ var p = pattern.startsWith("/") ? pattern.slice(1) : pattern;
2559
+ return p.split("/").map(function (part) {
2560
+ var isOptionalParam = part.startsWith("[[") && part.endsWith("]]");
2561
+ var isNonOptionalParam = part.startsWith("[") && part.endsWith("]");
2562
+ var nameStart = isOptionalParam ? 2 : isNonOptionalParam ? 1 : 0;
2563
+ var nameEnd = part.indexOf("]", nameStart);
2564
+ var isArrayParam = part.slice(nameStart, nameStart + 3) === "...";
2565
+ var paramName = part.slice(nameStart + (isArrayParam ? 3 : 0), nameEnd);
2566
+ if (isOptionalParam || isNonOptionalParam) {
2567
+ if (isArrayParam) {
2568
+ return {
2569
+ type: "array-param",
2570
+ paramName: paramName,
2571
+ optional: isOptionalParam
2572
+ };
2573
+ } else {
2574
+ return {
2575
+ type: "string-param",
2576
+ paramName: paramName,
2577
+ optional: isOptionalParam
2578
+ };
2579
+ }
2580
+ }
2581
+ return {
2582
+ type: "literal",
2583
+ name: part
2584
+ };
2585
+ });
2586
+ }
2587
+
2588
+ function getNextAppRouterSourceFolder(moduleFilePath) {
2589
+ if (moduleFilePath.startsWith("/app")) {
2590
+ return "/app";
2591
+ } else if (moduleFilePath.startsWith("/src/app")) {
2592
+ return "/src/app";
2593
+ }
2594
+ return null;
2595
+ }
2596
+
2597
+ export { Api, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, SharedValConfig, VAL_CONFIG_LISTENER, VAL_CONFIG_RECEIVED_LISTENER, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValCommit, ValDeployment, createValClient, getNextAppRouterSitemapTree, getNextAppRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern, remirrorToRichTextSource, richTextToRemirror, urlOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.83.0",
3
+ "version": "0.84.0",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "exports": true
30
30
  },
31
31
  "dependencies": {
32
- "@valbuild/core": "~0.83.0",
32
+ "@valbuild/core": "~0.84.0",
33
33
  "zod": "^3.22.4",
34
34
  "zod-validation-error": "^3.3.0"
35
35
  },