@valbuild/shared 0.82.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.
- package/dist/declarations/src/internal/ApiRoutes.d.ts +7 -7
- package/dist/declarations/src/internal/getNextAppRouterSourceFolder.d.ts +2 -0
- package/dist/declarations/src/internal/getSitemapTree.d.ts +30 -0
- package/dist/declarations/src/internal/index.d.ts +3 -0
- package/dist/declarations/src/internal/parseRoutePattern.d.ts +13 -0
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +177 -2
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +177 -2
- package/internal/dist/valbuild-shared-internal.esm.js +174 -3
- package/package.json +2 -2
@@ -3069,7 +3069,7 @@ export declare const Api: {
|
|
3069
3069
|
schemaSha: z.ZodString;
|
3070
3070
|
sourcesSha: z.ZodString;
|
3071
3071
|
modules: z.ZodRecord<z.ZodEffects<z.ZodString, ModuleFilePath, string>, z.ZodObject<{
|
3072
|
-
|
3072
|
+
render: z.ZodAny;
|
3073
3073
|
source: z.ZodAny;
|
3074
3074
|
patches: z.ZodOptional<z.ZodObject<{
|
3075
3075
|
applied: z.ZodArray<z.ZodEffects<z.ZodString, import("@valbuild/core").PatchId, string>, "many">;
|
@@ -3118,7 +3118,7 @@ export declare const Api: {
|
|
3118
3118
|
}>> | undefined;
|
3119
3119
|
skipped?: import("@valbuild/core").PatchId[] | undefined;
|
3120
3120
|
} | undefined;
|
3121
|
-
|
3121
|
+
render?: any;
|
3122
3122
|
source?: any;
|
3123
3123
|
validationErrors?: Record<string, {
|
3124
3124
|
message: string;
|
@@ -3134,7 +3134,7 @@ export declare const Api: {
|
|
3134
3134
|
}> | undefined;
|
3135
3135
|
skipped?: string[] | undefined;
|
3136
3136
|
} | undefined;
|
3137
|
-
|
3137
|
+
render?: any;
|
3138
3138
|
source?: any;
|
3139
3139
|
validationErrors?: Record<string, {
|
3140
3140
|
message: string;
|
@@ -3154,7 +3154,7 @@ export declare const Api: {
|
|
3154
3154
|
}>> | undefined;
|
3155
3155
|
skipped?: import("@valbuild/core").PatchId[] | undefined;
|
3156
3156
|
} | undefined;
|
3157
|
-
|
3157
|
+
render?: any;
|
3158
3158
|
source?: any;
|
3159
3159
|
validationErrors?: Record<string, {
|
3160
3160
|
message: string;
|
@@ -3174,7 +3174,7 @@ export declare const Api: {
|
|
3174
3174
|
}> | undefined;
|
3175
3175
|
skipped?: string[] | undefined;
|
3176
3176
|
} | undefined;
|
3177
|
-
|
3177
|
+
render?: any;
|
3178
3178
|
source?: any;
|
3179
3179
|
validationErrors?: Record<string, {
|
3180
3180
|
message: string;
|
@@ -3197,7 +3197,7 @@ export declare const Api: {
|
|
3197
3197
|
}>> | undefined;
|
3198
3198
|
skipped?: import("@valbuild/core").PatchId[] | undefined;
|
3199
3199
|
} | undefined;
|
3200
|
-
|
3200
|
+
render?: any;
|
3201
3201
|
source?: any;
|
3202
3202
|
validationErrors?: Record<string, {
|
3203
3203
|
message: string;
|
@@ -3220,7 +3220,7 @@ export declare const Api: {
|
|
3220
3220
|
}> | undefined;
|
3221
3221
|
skipped?: string[] | undefined;
|
3222
3222
|
} | undefined;
|
3223
|
-
|
3223
|
+
render?: any;
|
3224
3224
|
source?: any;
|
3225
3225
|
validationErrors?: Record<string, {
|
3226
3226
|
message: string;
|
@@ -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:
|
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
|
});
|
@@ -1964,7 +1971,7 @@ var Api = {
|
|
1964
1971
|
schemaSha: zod.z.string(),
|
1965
1972
|
sourcesSha: zod.z.string(),
|
1966
1973
|
modules: zod.z.record(ModuleFilePath, zod.z.object({
|
1967
|
-
|
1974
|
+
render: zod.z.any(),
|
1968
1975
|
// TODO: improve this type
|
1969
1976
|
source: zod.z.any(),
|
1970
1977
|
//.optional(), // TODO: Json zod type
|
@@ -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:
|
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
|
});
|
@@ -1964,7 +1971,7 @@ var Api = {
|
|
1964
1971
|
schemaSha: zod.z.string(),
|
1965
1972
|
sourcesSha: zod.z.string(),
|
1966
1973
|
modules: zod.z.record(ModuleFilePath, zod.z.object({
|
1967
|
-
|
1974
|
+
render: zod.z.any(),
|
1968
1975
|
// TODO: improve this type
|
1969
1976
|
source: zod.z.any(),
|
1970
1977
|
//.optional(), // TODO: Json zod type
|
@@ -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:
|
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
|
});
|
@@ -1960,7 +1967,7 @@ var Api = {
|
|
1960
1967
|
schemaSha: z.string(),
|
1961
1968
|
sourcesSha: z.string(),
|
1962
1969
|
modules: z.record(ModuleFilePath, z.object({
|
1963
|
-
|
1970
|
+
render: z.any(),
|
1964
1971
|
// TODO: improve this type
|
1965
1972
|
source: z.any(),
|
1966
1973
|
//.optional(), // TODO: Json zod type
|
@@ -2423,4 +2430,168 @@ var ValDeployment = z.object({
|
|
2423
2430
|
createdAt: z.string()
|
2424
2431
|
});
|
2425
2432
|
|
2426
|
-
|
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.
|
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.
|
32
|
+
"@valbuild/core": "~0.84.0",
|
33
33
|
"zod": "^3.22.4",
|
34
34
|
"zod-validation-error": "^3.3.0"
|
35
35
|
},
|