@valbuild/shared 0.87.5 → 0.89.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/README.md +5 -19
- package/dist/declarations/src/internal/ApiRoutes.d.ts +9 -9
- package/dist/declarations/src/internal/index.d.ts +1 -0
- package/dist/declarations/src/internal/routeValidation.d.ts +24 -0
- package/dist/declarations/src/internal/sessionStorage.d.ts +1 -0
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +129 -2
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +129 -2
- package/internal/dist/valbuild-shared-internal.esm.js +126 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
# Shared
|
|
1
|
+
# Val Shared
|
|
2
2
|
|
|
3
|
-
This package contains
|
|
3
|
+
This package contains Val's shared types and utilities used across different runtimes and packages.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
NOTE: do not use this directly, use the package corresponding to your meta-framework (e.g. Next) instead.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Contributors
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- Types and utility functions that does **NOT** belong in core because they:
|
|
12
|
-
1. is not required to execute Val files; or
|
|
13
|
-
1. have dependency on a lib
|
|
14
|
-
- Types and utility functions that does **NOT** semantically belong in any other package. Examples:
|
|
15
|
-
1. parser tools
|
|
16
|
-
1. API layer
|
|
17
|
-
|
|
18
|
-
See the rules to what does NOT belong in this package below.
|
|
19
|
-
|
|
20
|
-
## What **DOES NOT** go into this package?
|
|
21
|
-
|
|
22
|
-
- Any function / type that depends on a UI framework, even transitively (React, ProseMirror, NextJS, Vite...).
|
|
23
|
-
- Any function that cannot execute both on server-side and client-side.
|
|
9
|
+
This package provides cross-platform types and utilities that work in all runtimes (node, browser, QuickJS) and bundlers, including API layer types, parser tools, and shared validation logic.
|
|
@@ -3098,17 +3098,17 @@ export declare const Api: {
|
|
|
3098
3098
|
message: z.ZodString;
|
|
3099
3099
|
value: z.ZodOptional<z.ZodUnknown>;
|
|
3100
3100
|
fatal: z.ZodOptional<z.ZodBoolean>;
|
|
3101
|
-
fixes: z.ZodOptional<z.ZodArray<z.ZodType<"image:
|
|
3101
|
+
fixes: z.ZodOptional<z.ZodArray<z.ZodType<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route", z.ZodTypeDef, "image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route">, "many">>;
|
|
3102
3102
|
}, "strip", z.ZodTypeAny, {
|
|
3103
3103
|
message: string;
|
|
3104
3104
|
value?: unknown;
|
|
3105
3105
|
fatal?: boolean | undefined;
|
|
3106
|
-
fixes?: ("image:
|
|
3106
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3107
3107
|
}, {
|
|
3108
3108
|
message: string;
|
|
3109
3109
|
value?: unknown;
|
|
3110
3110
|
fatal?: boolean | undefined;
|
|
3111
|
-
fixes?: ("image:
|
|
3111
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3112
3112
|
}>, "many">>>;
|
|
3113
3113
|
}, "strip", z.ZodTypeAny, {
|
|
3114
3114
|
patches?: {
|
|
@@ -3124,7 +3124,7 @@ export declare const Api: {
|
|
|
3124
3124
|
message: string;
|
|
3125
3125
|
value?: unknown;
|
|
3126
3126
|
fatal?: boolean | undefined;
|
|
3127
|
-
fixes?: ("image:
|
|
3127
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3128
3128
|
}[]> | undefined;
|
|
3129
3129
|
}, {
|
|
3130
3130
|
patches?: {
|
|
@@ -3140,7 +3140,7 @@ export declare const Api: {
|
|
|
3140
3140
|
message: string;
|
|
3141
3141
|
value?: unknown;
|
|
3142
3142
|
fatal?: boolean | undefined;
|
|
3143
|
-
fixes?: ("image:
|
|
3143
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3144
3144
|
}[]> | undefined;
|
|
3145
3145
|
}>>;
|
|
3146
3146
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -3160,7 +3160,7 @@ export declare const Api: {
|
|
|
3160
3160
|
message: string;
|
|
3161
3161
|
value?: unknown;
|
|
3162
3162
|
fatal?: boolean | undefined;
|
|
3163
|
-
fixes?: ("image:
|
|
3163
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3164
3164
|
}[]> | undefined;
|
|
3165
3165
|
}>>;
|
|
3166
3166
|
}, {
|
|
@@ -3180,7 +3180,7 @@ export declare const Api: {
|
|
|
3180
3180
|
message: string;
|
|
3181
3181
|
value?: unknown;
|
|
3182
3182
|
fatal?: boolean | undefined;
|
|
3183
|
-
fixes?: ("image:
|
|
3183
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3184
3184
|
}[]> | undefined;
|
|
3185
3185
|
}>;
|
|
3186
3186
|
}>;
|
|
@@ -3203,7 +3203,7 @@ export declare const Api: {
|
|
|
3203
3203
|
message: string;
|
|
3204
3204
|
value?: unknown;
|
|
3205
3205
|
fatal?: boolean | undefined;
|
|
3206
|
-
fixes?: ("image:
|
|
3206
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3207
3207
|
}[]> | undefined;
|
|
3208
3208
|
}>>;
|
|
3209
3209
|
};
|
|
@@ -3226,7 +3226,7 @@ export declare const Api: {
|
|
|
3226
3226
|
message: string;
|
|
3227
3227
|
value?: unknown;
|
|
3228
3228
|
fatal?: boolean | undefined;
|
|
3229
|
-
fixes?: ("image:
|
|
3229
|
+
fixes?: ("image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "keyof:check-keys" | "router:check-route")[] | undefined;
|
|
3230
3230
|
}[]> | undefined;
|
|
3231
3231
|
}>;
|
|
3232
3232
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared route validation utilities
|
|
3
|
+
*/
|
|
4
|
+
export type SerializedRegExpPattern = {
|
|
5
|
+
source: string;
|
|
6
|
+
flags: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Filter routes by include/exclude patterns
|
|
10
|
+
*/
|
|
11
|
+
export declare function filterRoutesByPatterns(routes: string[], includePattern?: SerializedRegExpPattern, excludePattern?: SerializedRegExpPattern): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Validate a single route against include/exclude patterns
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateRoutePatterns(route: string, includePattern?: SerializedRegExpPattern, excludePattern?: SerializedRegExpPattern): {
|
|
16
|
+
valid: true;
|
|
17
|
+
} | {
|
|
18
|
+
valid: false;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create RegExp from pattern (with error handling)
|
|
23
|
+
*/
|
|
24
|
+
export declare function createRegExpFromPattern(pattern: SerializedRegExpPattern): RegExp | null;
|
|
@@ -1131,7 +1131,23 @@ var SerializedDateSchema = zod.z.object({
|
|
|
1131
1131
|
type: zod.z.literal("date"),
|
|
1132
1132
|
opt: zod.z["boolean"]()
|
|
1133
1133
|
});
|
|
1134
|
-
var
|
|
1134
|
+
var SerializedRouteSchema = zod.z.object({
|
|
1135
|
+
type: zod.z.literal("route"),
|
|
1136
|
+
options: zod.z.object({
|
|
1137
|
+
include: zod.z.object({
|
|
1138
|
+
source: zod.z.string(),
|
|
1139
|
+
flags: zod.z.string()
|
|
1140
|
+
}).optional(),
|
|
1141
|
+
exclude: zod.z.object({
|
|
1142
|
+
source: zod.z.string(),
|
|
1143
|
+
flags: zod.z.string()
|
|
1144
|
+
}).optional(),
|
|
1145
|
+
customValidate: zod.z["boolean"]().optional()
|
|
1146
|
+
}).optional(),
|
|
1147
|
+
opt: zod.z["boolean"](),
|
|
1148
|
+
customValidate: zod.z["boolean"]().optional()
|
|
1149
|
+
});
|
|
1150
|
+
var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
|
|
1135
1151
|
|
|
1136
1152
|
var ValCommit = zod.z.object({
|
|
1137
1153
|
commitSha: zod.z.string(),
|
|
@@ -1163,7 +1179,7 @@ var ValConfig = zod.z.object({
|
|
|
1163
1179
|
gitCommit: zod.z.string().optional(),
|
|
1164
1180
|
gitBranch: zod.z.string().optional()
|
|
1165
1181
|
});
|
|
1166
|
-
var ValidationFixZ = zod.z.union([zod.z.literal("image:
|
|
1182
|
+
var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route")]);
|
|
1167
1183
|
var ValidationError = zod.z.object({
|
|
1168
1184
|
message: zod.z.string(),
|
|
1169
1185
|
value: zod.z.unknown().optional(),
|
|
@@ -2214,6 +2230,7 @@ var urlOf = function urlOf() {
|
|
|
2214
2230
|
};
|
|
2215
2231
|
|
|
2216
2232
|
var VAL_CONFIG_SESSION_STORAGE_KEY = "val-config";
|
|
2233
|
+
var VAL_THEME_SESSION_STORAGE_KEY = "val-theme";
|
|
2217
2234
|
|
|
2218
2235
|
var SharedValConfig = zod.z.object({
|
|
2219
2236
|
contentHostUrl: zod.z.string().optional(),
|
|
@@ -2409,6 +2426,112 @@ function getNextAppRouterSourceFolder(moduleFilePath) {
|
|
|
2409
2426
|
return null;
|
|
2410
2427
|
}
|
|
2411
2428
|
|
|
2429
|
+
/**
|
|
2430
|
+
* Shared route validation utilities
|
|
2431
|
+
*/
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* Filter routes by include/exclude patterns
|
|
2435
|
+
*/
|
|
2436
|
+
function filterRoutesByPatterns(routes, includePattern, excludePattern) {
|
|
2437
|
+
// Validate patterns upfront and warn about issues
|
|
2438
|
+
var includeRegex = null;
|
|
2439
|
+
var excludeRegex = null;
|
|
2440
|
+
if (includePattern) {
|
|
2441
|
+
try {
|
|
2442
|
+
includeRegex = new RegExp(includePattern.source, includePattern.flags);
|
|
2443
|
+
} catch (e) {
|
|
2444
|
+
console.warn("[Val] Invalid include pattern: /".concat(includePattern.source, "/").concat(includePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed include pattern.");
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
if (excludePattern) {
|
|
2448
|
+
try {
|
|
2449
|
+
excludeRegex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2450
|
+
} catch (e) {
|
|
2451
|
+
console.warn("[Val] Invalid exclude pattern: /".concat(excludePattern.source, "/").concat(excludePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed exclude pattern.");
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return routes.filter(function (route) {
|
|
2455
|
+
// Check include pattern
|
|
2456
|
+
if (includePattern) {
|
|
2457
|
+
if (!includeRegex) {
|
|
2458
|
+
// Pattern creation failed, filter out this route
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
if (!includeRegex.test(route)) {
|
|
2462
|
+
return false;
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
// Check exclude pattern
|
|
2467
|
+
if (excludePattern) {
|
|
2468
|
+
if (!excludeRegex) {
|
|
2469
|
+
// Pattern creation failed, filter out this route
|
|
2470
|
+
return false;
|
|
2471
|
+
}
|
|
2472
|
+
if (excludeRegex.test(route)) {
|
|
2473
|
+
return false;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
return true;
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Validate a single route against include/exclude patterns
|
|
2482
|
+
*/
|
|
2483
|
+
function validateRoutePatterns(route, includePattern, excludePattern) {
|
|
2484
|
+
// Validate include pattern
|
|
2485
|
+
if (includePattern) {
|
|
2486
|
+
try {
|
|
2487
|
+
var regex = new RegExp(includePattern.source, includePattern.flags);
|
|
2488
|
+
if (!regex.test(route)) {
|
|
2489
|
+
return {
|
|
2490
|
+
valid: false,
|
|
2491
|
+
message: "Route '".concat(route, "' does not match include pattern: /").concat(includePattern.source, "/").concat(includePattern.flags)
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
} catch (e) {
|
|
2495
|
+
return {
|
|
2496
|
+
valid: false,
|
|
2497
|
+
message: "Invalid include pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
// Validate exclude pattern
|
|
2503
|
+
if (excludePattern) {
|
|
2504
|
+
try {
|
|
2505
|
+
var _regex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2506
|
+
if (_regex.test(route)) {
|
|
2507
|
+
return {
|
|
2508
|
+
valid: false,
|
|
2509
|
+
message: "Route '".concat(route, "' matches exclude pattern: /").concat(excludePattern.source, "/").concat(excludePattern.flags)
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
} catch (e) {
|
|
2513
|
+
return {
|
|
2514
|
+
valid: false,
|
|
2515
|
+
message: "Invalid exclude pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
return {
|
|
2520
|
+
valid: true
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
/**
|
|
2525
|
+
* Create RegExp from pattern (with error handling)
|
|
2526
|
+
*/
|
|
2527
|
+
function createRegExpFromPattern(pattern) {
|
|
2528
|
+
try {
|
|
2529
|
+
return new RegExp(pattern.source, pattern.flags);
|
|
2530
|
+
} catch (_unused) {
|
|
2531
|
+
return null;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2412
2535
|
exports.Api = Api;
|
|
2413
2536
|
exports.ParentRef = ParentRef$1;
|
|
2414
2537
|
exports.Patch = Patch;
|
|
@@ -2431,9 +2554,12 @@ exports.VAL_CONFIG_SESSION_STORAGE_KEY = VAL_CONFIG_SESSION_STORAGE_KEY;
|
|
|
2431
2554
|
exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
|
|
2432
2555
|
exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
|
|
2433
2556
|
exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
|
|
2557
|
+
exports.VAL_THEME_SESSION_STORAGE_KEY = VAL_THEME_SESSION_STORAGE_KEY;
|
|
2434
2558
|
exports.ValCommit = ValCommit;
|
|
2435
2559
|
exports.ValDeployment = ValDeployment;
|
|
2560
|
+
exports.createRegExpFromPattern = createRegExpFromPattern;
|
|
2436
2561
|
exports.createValClient = createValClient;
|
|
2562
|
+
exports.filterRoutesByPatterns = filterRoutesByPatterns;
|
|
2437
2563
|
exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
|
|
2438
2564
|
exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
|
|
2439
2565
|
exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
|
|
@@ -2441,3 +2567,4 @@ exports.parseRoutePattern = parseRoutePattern;
|
|
|
2441
2567
|
exports.remirrorToRichTextSource = remirrorToRichTextSource;
|
|
2442
2568
|
exports.richTextToRemirror = richTextToRemirror;
|
|
2443
2569
|
exports.urlOf = urlOf;
|
|
2570
|
+
exports.validateRoutePatterns = validateRoutePatterns;
|
|
@@ -1131,7 +1131,23 @@ var SerializedDateSchema = zod.z.object({
|
|
|
1131
1131
|
type: zod.z.literal("date"),
|
|
1132
1132
|
opt: zod.z["boolean"]()
|
|
1133
1133
|
});
|
|
1134
|
-
var
|
|
1134
|
+
var SerializedRouteSchema = zod.z.object({
|
|
1135
|
+
type: zod.z.literal("route"),
|
|
1136
|
+
options: zod.z.object({
|
|
1137
|
+
include: zod.z.object({
|
|
1138
|
+
source: zod.z.string(),
|
|
1139
|
+
flags: zod.z.string()
|
|
1140
|
+
}).optional(),
|
|
1141
|
+
exclude: zod.z.object({
|
|
1142
|
+
source: zod.z.string(),
|
|
1143
|
+
flags: zod.z.string()
|
|
1144
|
+
}).optional(),
|
|
1145
|
+
customValidate: zod.z["boolean"]().optional()
|
|
1146
|
+
}).optional(),
|
|
1147
|
+
opt: zod.z["boolean"](),
|
|
1148
|
+
customValidate: zod.z["boolean"]().optional()
|
|
1149
|
+
});
|
|
1150
|
+
var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
|
|
1135
1151
|
|
|
1136
1152
|
var ValCommit = zod.z.object({
|
|
1137
1153
|
commitSha: zod.z.string(),
|
|
@@ -1163,7 +1179,7 @@ var ValConfig = zod.z.object({
|
|
|
1163
1179
|
gitCommit: zod.z.string().optional(),
|
|
1164
1180
|
gitBranch: zod.z.string().optional()
|
|
1165
1181
|
});
|
|
1166
|
-
var ValidationFixZ = zod.z.union([zod.z.literal("image:
|
|
1182
|
+
var ValidationFixZ = zod.z.union([zod.z.literal("image:add-metadata"), zod.z.literal("image:check-metadata"), zod.z.literal("image:check-remote"), zod.z.literal("image:upload-remote"), zod.z.literal("image:download-remote"), zod.z.literal("file:add-metadata"), zod.z.literal("file:check-metadata"), zod.z.literal("file:check-remote"), zod.z.literal("file:upload-remote"), zod.z.literal("file:download-remote"), zod.z.literal("keyof:check-keys"), zod.z.literal("router:check-route")]);
|
|
1167
1183
|
var ValidationError = zod.z.object({
|
|
1168
1184
|
message: zod.z.string(),
|
|
1169
1185
|
value: zod.z.unknown().optional(),
|
|
@@ -2214,6 +2230,7 @@ var urlOf = function urlOf() {
|
|
|
2214
2230
|
};
|
|
2215
2231
|
|
|
2216
2232
|
var VAL_CONFIG_SESSION_STORAGE_KEY = "val-config";
|
|
2233
|
+
var VAL_THEME_SESSION_STORAGE_KEY = "val-theme";
|
|
2217
2234
|
|
|
2218
2235
|
var SharedValConfig = zod.z.object({
|
|
2219
2236
|
contentHostUrl: zod.z.string().optional(),
|
|
@@ -2409,6 +2426,112 @@ function getNextAppRouterSourceFolder(moduleFilePath) {
|
|
|
2409
2426
|
return null;
|
|
2410
2427
|
}
|
|
2411
2428
|
|
|
2429
|
+
/**
|
|
2430
|
+
* Shared route validation utilities
|
|
2431
|
+
*/
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* Filter routes by include/exclude patterns
|
|
2435
|
+
*/
|
|
2436
|
+
function filterRoutesByPatterns(routes, includePattern, excludePattern) {
|
|
2437
|
+
// Validate patterns upfront and warn about issues
|
|
2438
|
+
var includeRegex = null;
|
|
2439
|
+
var excludeRegex = null;
|
|
2440
|
+
if (includePattern) {
|
|
2441
|
+
try {
|
|
2442
|
+
includeRegex = new RegExp(includePattern.source, includePattern.flags);
|
|
2443
|
+
} catch (e) {
|
|
2444
|
+
console.warn("[Val] Invalid include pattern: /".concat(includePattern.source, "/").concat(includePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed include pattern.");
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
if (excludePattern) {
|
|
2448
|
+
try {
|
|
2449
|
+
excludeRegex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2450
|
+
} catch (e) {
|
|
2451
|
+
console.warn("[Val] Invalid exclude pattern: /".concat(excludePattern.source, "/").concat(excludePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed exclude pattern.");
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return routes.filter(function (route) {
|
|
2455
|
+
// Check include pattern
|
|
2456
|
+
if (includePattern) {
|
|
2457
|
+
if (!includeRegex) {
|
|
2458
|
+
// Pattern creation failed, filter out this route
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
if (!includeRegex.test(route)) {
|
|
2462
|
+
return false;
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
// Check exclude pattern
|
|
2467
|
+
if (excludePattern) {
|
|
2468
|
+
if (!excludeRegex) {
|
|
2469
|
+
// Pattern creation failed, filter out this route
|
|
2470
|
+
return false;
|
|
2471
|
+
}
|
|
2472
|
+
if (excludeRegex.test(route)) {
|
|
2473
|
+
return false;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
return true;
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Validate a single route against include/exclude patterns
|
|
2482
|
+
*/
|
|
2483
|
+
function validateRoutePatterns(route, includePattern, excludePattern) {
|
|
2484
|
+
// Validate include pattern
|
|
2485
|
+
if (includePattern) {
|
|
2486
|
+
try {
|
|
2487
|
+
var regex = new RegExp(includePattern.source, includePattern.flags);
|
|
2488
|
+
if (!regex.test(route)) {
|
|
2489
|
+
return {
|
|
2490
|
+
valid: false,
|
|
2491
|
+
message: "Route '".concat(route, "' does not match include pattern: /").concat(includePattern.source, "/").concat(includePattern.flags)
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
} catch (e) {
|
|
2495
|
+
return {
|
|
2496
|
+
valid: false,
|
|
2497
|
+
message: "Invalid include pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
// Validate exclude pattern
|
|
2503
|
+
if (excludePattern) {
|
|
2504
|
+
try {
|
|
2505
|
+
var _regex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2506
|
+
if (_regex.test(route)) {
|
|
2507
|
+
return {
|
|
2508
|
+
valid: false,
|
|
2509
|
+
message: "Route '".concat(route, "' matches exclude pattern: /").concat(excludePattern.source, "/").concat(excludePattern.flags)
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
} catch (e) {
|
|
2513
|
+
return {
|
|
2514
|
+
valid: false,
|
|
2515
|
+
message: "Invalid exclude pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
return {
|
|
2520
|
+
valid: true
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
/**
|
|
2525
|
+
* Create RegExp from pattern (with error handling)
|
|
2526
|
+
*/
|
|
2527
|
+
function createRegExpFromPattern(pattern) {
|
|
2528
|
+
try {
|
|
2529
|
+
return new RegExp(pattern.source, pattern.flags);
|
|
2530
|
+
} catch (_unused) {
|
|
2531
|
+
return null;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2412
2535
|
exports.Api = Api;
|
|
2413
2536
|
exports.ParentRef = ParentRef$1;
|
|
2414
2537
|
exports.Patch = Patch;
|
|
@@ -2431,9 +2554,12 @@ exports.VAL_CONFIG_SESSION_STORAGE_KEY = VAL_CONFIG_SESSION_STORAGE_KEY;
|
|
|
2431
2554
|
exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
|
|
2432
2555
|
exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
|
|
2433
2556
|
exports.VAL_STATE_COOKIE = VAL_STATE_COOKIE;
|
|
2557
|
+
exports.VAL_THEME_SESSION_STORAGE_KEY = VAL_THEME_SESSION_STORAGE_KEY;
|
|
2434
2558
|
exports.ValCommit = ValCommit;
|
|
2435
2559
|
exports.ValDeployment = ValDeployment;
|
|
2560
|
+
exports.createRegExpFromPattern = createRegExpFromPattern;
|
|
2436
2561
|
exports.createValClient = createValClient;
|
|
2562
|
+
exports.filterRoutesByPatterns = filterRoutesByPatterns;
|
|
2437
2563
|
exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
|
|
2438
2564
|
exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
|
|
2439
2565
|
exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
|
|
@@ -2441,3 +2567,4 @@ exports.parseRoutePattern = parseRoutePattern;
|
|
|
2441
2567
|
exports.remirrorToRichTextSource = remirrorToRichTextSource;
|
|
2442
2568
|
exports.richTextToRemirror = richTextToRemirror;
|
|
2443
2569
|
exports.urlOf = urlOf;
|
|
2570
|
+
exports.validateRoutePatterns = validateRoutePatterns;
|
|
@@ -1127,7 +1127,23 @@ var SerializedDateSchema = z.object({
|
|
|
1127
1127
|
type: z.literal("date"),
|
|
1128
1128
|
opt: z["boolean"]()
|
|
1129
1129
|
});
|
|
1130
|
-
var
|
|
1130
|
+
var SerializedRouteSchema = z.object({
|
|
1131
|
+
type: z.literal("route"),
|
|
1132
|
+
options: z.object({
|
|
1133
|
+
include: z.object({
|
|
1134
|
+
source: z.string(),
|
|
1135
|
+
flags: z.string()
|
|
1136
|
+
}).optional(),
|
|
1137
|
+
exclude: z.object({
|
|
1138
|
+
source: z.string(),
|
|
1139
|
+
flags: z.string()
|
|
1140
|
+
}).optional(),
|
|
1141
|
+
customValidate: z["boolean"]().optional()
|
|
1142
|
+
}).optional(),
|
|
1143
|
+
opt: z["boolean"](),
|
|
1144
|
+
customValidate: z["boolean"]().optional()
|
|
1145
|
+
});
|
|
1146
|
+
var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
|
|
1131
1147
|
|
|
1132
1148
|
var ValCommit = z.object({
|
|
1133
1149
|
commitSha: z.string(),
|
|
@@ -1159,7 +1175,7 @@ var ValConfig = z.object({
|
|
|
1159
1175
|
gitCommit: z.string().optional(),
|
|
1160
1176
|
gitBranch: z.string().optional()
|
|
1161
1177
|
});
|
|
1162
|
-
var ValidationFixZ = z.union([z.literal("image:
|
|
1178
|
+
var ValidationFixZ = z.union([z.literal("image:add-metadata"), z.literal("image:check-metadata"), z.literal("image:check-remote"), z.literal("image:upload-remote"), z.literal("image:download-remote"), z.literal("file:add-metadata"), z.literal("file:check-metadata"), z.literal("file:check-remote"), z.literal("file:upload-remote"), z.literal("file:download-remote"), z.literal("keyof:check-keys"), z.literal("router:check-route")]);
|
|
1163
1179
|
var ValidationError = z.object({
|
|
1164
1180
|
message: z.string(),
|
|
1165
1181
|
value: z.unknown().optional(),
|
|
@@ -2210,6 +2226,7 @@ var urlOf = function urlOf() {
|
|
|
2210
2226
|
};
|
|
2211
2227
|
|
|
2212
2228
|
var VAL_CONFIG_SESSION_STORAGE_KEY = "val-config";
|
|
2229
|
+
var VAL_THEME_SESSION_STORAGE_KEY = "val-theme";
|
|
2213
2230
|
|
|
2214
2231
|
var SharedValConfig = z.object({
|
|
2215
2232
|
contentHostUrl: z.string().optional(),
|
|
@@ -2405,4 +2422,110 @@ function getNextAppRouterSourceFolder(moduleFilePath) {
|
|
|
2405
2422
|
return null;
|
|
2406
2423
|
}
|
|
2407
2424
|
|
|
2408
|
-
|
|
2425
|
+
/**
|
|
2426
|
+
* Shared route validation utilities
|
|
2427
|
+
*/
|
|
2428
|
+
|
|
2429
|
+
/**
|
|
2430
|
+
* Filter routes by include/exclude patterns
|
|
2431
|
+
*/
|
|
2432
|
+
function filterRoutesByPatterns(routes, includePattern, excludePattern) {
|
|
2433
|
+
// Validate patterns upfront and warn about issues
|
|
2434
|
+
var includeRegex = null;
|
|
2435
|
+
var excludeRegex = null;
|
|
2436
|
+
if (includePattern) {
|
|
2437
|
+
try {
|
|
2438
|
+
includeRegex = new RegExp(includePattern.source, includePattern.flags);
|
|
2439
|
+
} catch (e) {
|
|
2440
|
+
console.warn("[Val] Invalid include pattern: /".concat(includePattern.source, "/").concat(includePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed include pattern.");
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
if (excludePattern) {
|
|
2444
|
+
try {
|
|
2445
|
+
excludeRegex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2446
|
+
} catch (e) {
|
|
2447
|
+
console.warn("[Val] Invalid exclude pattern: /".concat(excludePattern.source, "/").concat(excludePattern.flags), "\nError: ".concat(e instanceof Error ? e.message : String(e)), "\nAll routes will be filtered out due to malformed exclude pattern.");
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
return routes.filter(function (route) {
|
|
2451
|
+
// Check include pattern
|
|
2452
|
+
if (includePattern) {
|
|
2453
|
+
if (!includeRegex) {
|
|
2454
|
+
// Pattern creation failed, filter out this route
|
|
2455
|
+
return false;
|
|
2456
|
+
}
|
|
2457
|
+
if (!includeRegex.test(route)) {
|
|
2458
|
+
return false;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
// Check exclude pattern
|
|
2463
|
+
if (excludePattern) {
|
|
2464
|
+
if (!excludeRegex) {
|
|
2465
|
+
// Pattern creation failed, filter out this route
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
if (excludeRegex.test(route)) {
|
|
2469
|
+
return false;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
return true;
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
/**
|
|
2477
|
+
* Validate a single route against include/exclude patterns
|
|
2478
|
+
*/
|
|
2479
|
+
function validateRoutePatterns(route, includePattern, excludePattern) {
|
|
2480
|
+
// Validate include pattern
|
|
2481
|
+
if (includePattern) {
|
|
2482
|
+
try {
|
|
2483
|
+
var regex = new RegExp(includePattern.source, includePattern.flags);
|
|
2484
|
+
if (!regex.test(route)) {
|
|
2485
|
+
return {
|
|
2486
|
+
valid: false,
|
|
2487
|
+
message: "Route '".concat(route, "' does not match include pattern: /").concat(includePattern.source, "/").concat(includePattern.flags)
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
} catch (e) {
|
|
2491
|
+
return {
|
|
2492
|
+
valid: false,
|
|
2493
|
+
message: "Invalid include pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
// Validate exclude pattern
|
|
2499
|
+
if (excludePattern) {
|
|
2500
|
+
try {
|
|
2501
|
+
var _regex = new RegExp(excludePattern.source, excludePattern.flags);
|
|
2502
|
+
if (_regex.test(route)) {
|
|
2503
|
+
return {
|
|
2504
|
+
valid: false,
|
|
2505
|
+
message: "Route '".concat(route, "' matches exclude pattern: /").concat(excludePattern.source, "/").concat(excludePattern.flags)
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
} catch (e) {
|
|
2509
|
+
return {
|
|
2510
|
+
valid: false,
|
|
2511
|
+
message: "Invalid exclude pattern: ".concat(e instanceof Error ? e.message : String(e))
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
return {
|
|
2516
|
+
valid: true
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
/**
|
|
2521
|
+
* Create RegExp from pattern (with error handling)
|
|
2522
|
+
*/
|
|
2523
|
+
function createRegExpFromPattern(pattern) {
|
|
2524
|
+
try {
|
|
2525
|
+
return new RegExp(pattern.source, pattern.flags);
|
|
2526
|
+
} catch (_unused) {
|
|
2527
|
+
return null;
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
export { Api, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, SharedValConfig, VAL_CONFIG_SESSION_STORAGE_KEY, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_THEME_SESSION_STORAGE_KEY, ValCommit, ValDeployment, createRegExpFromPattern, createValClient, filterRoutesByPatterns, getNextAppRouterSitemapTree, getNextAppRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern, remirrorToRichTextSource, richTextToRemirror, urlOf, validateRoutePatterns };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valbuild/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Val shared types and utilities",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/valbuild/val.git"
|
|
8
|
+
"url": "git+https://github.com/valbuild/val.git"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"typecheck": "tsc --noEmit",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"exports": true
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@valbuild/core": "~0.
|
|
36
|
+
"@valbuild/core": "~0.89.0",
|
|
37
37
|
"zod": "^3.22.4",
|
|
38
38
|
"zod-validation-error": "^3.3.0"
|
|
39
39
|
},
|