@valbuild/shared 0.124.0 → 0.126.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 +210 -0
- package/client/dist/valbuild-shared-client.cjs.dev.js +5 -2
- package/client/dist/valbuild-shared-client.cjs.prod.js +5 -2
- package/client/dist/valbuild-shared-client.esm.js +1 -1
- package/dist/declarations/src/internal/ApiRoutes.d.ts +8 -0
- package/dist/declarations/src/internal/getNextAppRouterSourceFolder.d.ts +24 -0
- package/dist/declarations/src/internal/getSitemapTree.d.ts +10 -1
- package/dist/declarations/src/internal/resolveSchemaSourceFixes.d.ts +25 -0
- package/dist/declarations/src/internal/zod/SerializedSchema.d.ts +3 -2
- package/dist/declarations/src/internal/zod/ValDeployment.d.ts +1 -0
- package/dist/{getSitemapTree-d3e98a2e.esm.js → getSitemapTree-a6cb37cb.esm.js} +66 -4
- package/dist/{getSitemapTree-77b1203a.cjs.prod.js → getSitemapTree-b320d033.cjs.prod.js} +68 -3
- package/dist/{getSitemapTree-a0c9a0e3.cjs.dev.js → getSitemapTree-d1977d3e.cjs.dev.js} +68 -3
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +189 -91
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +189 -91
- package/internal/dist/valbuild-shared-internal.esm.js +183 -91
- package/package.json +2 -2
|
@@ -137,6 +137,45 @@ function getNextAppRouterSourceFolder(moduleFilePath) {
|
|
|
137
137
|
return null;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The folder a TanStack Router app keeps its route files in.
|
|
142
|
+
*
|
|
143
|
+
* The same question as above for the other convention: `routes/` at the project
|
|
144
|
+
* root, or under `src/`. A Val module for a route lives beside the route file
|
|
145
|
+
* and is named the same way, so this is the prefix to strip before reading the
|
|
146
|
+
* route pattern out of the rest.
|
|
147
|
+
*/
|
|
148
|
+
function getTanStackRouterSourceFolder(moduleFilePath) {
|
|
149
|
+
if (moduleFilePath.startsWith("/routes/")) {
|
|
150
|
+
return "/routes";
|
|
151
|
+
} else if (moduleFilePath.startsWith("/src/routes/")) {
|
|
152
|
+
return "/src/routes";
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The route folder of whichever page router this module belongs to.
|
|
159
|
+
*
|
|
160
|
+
* The two conventions have disjoint prefixes — `app/` versus `routes/` — so a
|
|
161
|
+
* module file path answers this on its own, which is what the Studio needs: it
|
|
162
|
+
* walks every schema in the project and has no framework to ask.
|
|
163
|
+
*/
|
|
164
|
+
function getPageRouterSourceFolder(moduleFilePath) {
|
|
165
|
+
var _getNextAppRouterSour;
|
|
166
|
+
return (_getNextAppRouterSour = getNextAppRouterSourceFolder(moduleFilePath)) !== null && _getNextAppRouterSour !== void 0 ? _getNextAppRouterSour : getTanStackRouterSourceFolder(moduleFilePath);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether a route folder is a TanStack Router one.
|
|
171
|
+
*
|
|
172
|
+
* Exported so the pattern derivation and the source-folder detection cannot
|
|
173
|
+
* drift apart about what `/src/routes` means.
|
|
174
|
+
*/
|
|
175
|
+
function isTanStackRoutesFolder(srcFolder) {
|
|
176
|
+
return srcFolder === "/routes" || srcFolder === "/src/routes";
|
|
177
|
+
}
|
|
178
|
+
|
|
140
179
|
function _toPrimitive(t, r) {
|
|
141
180
|
if ("object" != typeof t || !t) return t;
|
|
142
181
|
var e = t[Symbol.toPrimitive];
|
|
@@ -247,8 +286,14 @@ function _createForOfIteratorHelper(r, e) {
|
|
|
247
286
|
};
|
|
248
287
|
}
|
|
249
288
|
|
|
250
|
-
// Strictly speaking this should be in the
|
|
251
|
-
|
|
289
|
+
// Strictly speaking this should be in the framework packages but it's shared,
|
|
290
|
+
// because we want to use it in the ui package. We want to resolve that somehow.
|
|
291
|
+
//
|
|
292
|
+
// It is one function for both page routers because the tree it builds is made
|
|
293
|
+
// of URL paths, which is the same thing in either: only `srcFolder` and the
|
|
294
|
+
// pattern derivation differ, and both of those are arguments (or the one call
|
|
295
|
+
// below).
|
|
296
|
+
function getPageRouterSitemapTree(srcFolder, paths) {
|
|
252
297
|
var root = {
|
|
253
298
|
type: "node",
|
|
254
299
|
name: "/",
|
|
@@ -360,7 +405,24 @@ function getNextAppRouterSitemapTree(srcFolder, paths) {
|
|
|
360
405
|
}
|
|
361
406
|
return root;
|
|
362
407
|
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The route pattern a page-router module serves, e.g. `/blogs/[blog]`.
|
|
411
|
+
*
|
|
412
|
+
* Written in Next's vocabulary for both routers on purpose: the pattern is read
|
|
413
|
+
* by `parseRoutePattern`, the sitemap and the Studio's key inputs, none of which
|
|
414
|
+
* should have to know which framework the project uses. The TanStack branch
|
|
415
|
+
* translates that framework's conventions into it; see
|
|
416
|
+
* `tanStackSegmentsOfRoutePath` in `@valbuild/core` for the rules.
|
|
417
|
+
*/
|
|
363
418
|
function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
|
|
419
|
+
if (isTanStackRoutesFolder(srcFolder)) {
|
|
420
|
+
var routePath = moduleFilePath.slice(srcFolder.length).replace(/\.val\.[tj]sx?$/, "");
|
|
421
|
+
var segments = core.tanStackSegmentsOfRoutePath(routePath);
|
|
422
|
+
// "" rather than "/" for the root, so it matches what the Next branch
|
|
423
|
+
// returns for `/app/page.val.ts` — `parseRoutePattern` reads both as [].
|
|
424
|
+
return segments.length === 0 ? "" : "/".concat(segments.join("/"));
|
|
425
|
+
}
|
|
364
426
|
return moduleFilePath.replace(srcFolder, "")
|
|
365
427
|
// TODO: hacky!
|
|
366
428
|
// remove route groups
|
|
@@ -379,9 +441,12 @@ exports._defineProperty = _defineProperty;
|
|
|
379
441
|
exports._objectSpread2 = _objectSpread2;
|
|
380
442
|
exports._typeof = _typeof;
|
|
381
443
|
exports._unsupportedIterableToArray = _unsupportedIterableToArray;
|
|
382
|
-
exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
|
|
383
444
|
exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
|
|
445
|
+
exports.getPageRouterSitemapTree = getPageRouterSitemapTree;
|
|
446
|
+
exports.getPageRouterSourceFolder = getPageRouterSourceFolder;
|
|
384
447
|
exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
|
|
448
|
+
exports.getTanStackRouterSourceFolder = getTanStackRouterSourceFolder;
|
|
449
|
+
exports.isTanStackRoutesFolder = isTanStackRoutesFolder;
|
|
385
450
|
exports.isValCanvasFrame = isValCanvasFrame;
|
|
386
451
|
exports.isValCanvasPageMessage = isValCanvasPageMessage;
|
|
387
452
|
exports.isValCanvasStudioMessage = isValCanvasStudioMessage;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@valbuild/core');
|
|
6
|
-
var getSitemapTree = require('../../dist/getSitemapTree-
|
|
6
|
+
var getSitemapTree = require('../../dist/getSitemapTree-d1977d3e.cjs.dev.js');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var zodValidationError = require('zod-validation-error');
|
|
9
9
|
var FlexSearch = require('flexsearch');
|
|
@@ -989,19 +989,19 @@ var SerializedArraySchema = zod.z.lazy(function () {
|
|
|
989
989
|
opt: zod.z["boolean"]()
|
|
990
990
|
}));
|
|
991
991
|
});
|
|
992
|
-
var
|
|
993
|
-
return zod.z.
|
|
994
|
-
type: zod.z.literal("union"),
|
|
995
|
-
key: SerializedLiteralSchema,
|
|
996
|
-
items: zod.z.array(SerializedLiteralSchema),
|
|
997
|
-
opt: zod.z["boolean"]()
|
|
998
|
-
})), zod.z.object(getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, commonSchemaFields), {}, {
|
|
999
|
-
type: zod.z.literal("union"),
|
|
992
|
+
var SerializedDiscriminatedUnionSchema = zod.z.lazy(function () {
|
|
993
|
+
return zod.z.object(getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, commonSchemaFields), {}, {
|
|
994
|
+
type: zod.z.literal("discriminated-union"),
|
|
1000
995
|
key: zod.z.string(),
|
|
1001
996
|
items: zod.z.array(SerializedObjectSchema),
|
|
1002
997
|
opt: zod.z["boolean"]()
|
|
1003
|
-
}))
|
|
998
|
+
}));
|
|
1004
999
|
});
|
|
1000
|
+
var SerializedEnumSchema = zod.z.object(getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, commonSchemaFields), {}, {
|
|
1001
|
+
type: zod.z.literal("enum"),
|
|
1002
|
+
values: zod.z.array(zod.z.string()),
|
|
1003
|
+
opt: zod.z["boolean"]()
|
|
1004
|
+
}));
|
|
1005
1005
|
var ImageEncodeOption = zod.z.union([zod.z.literal(false), zod.z.object({
|
|
1006
1006
|
type: zod.z.literal("webp"),
|
|
1007
1007
|
quality: zod.z.number().optional(),
|
|
@@ -1153,7 +1153,7 @@ var SerializedSettingsSchema = zod.z.lazy(function () {
|
|
|
1153
1153
|
opt: zod.z["boolean"]()
|
|
1154
1154
|
}));
|
|
1155
1155
|
});
|
|
1156
|
-
var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema,
|
|
1156
|
+
var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema]);
|
|
1157
1157
|
|
|
1158
1158
|
var ValCommit = zod.z.object({
|
|
1159
1159
|
commitSha: zod.z.string(),
|
|
@@ -1165,6 +1165,31 @@ var ValCommit = zod.z.object({
|
|
|
1165
1165
|
commitMessage: zod.z.string().nullable()
|
|
1166
1166
|
});
|
|
1167
1167
|
|
|
1168
|
+
var ValDeployment = zod.z.object({
|
|
1169
|
+
deploymentId: zod.z.string(),
|
|
1170
|
+
deploymentState: zod.z.string(),
|
|
1171
|
+
commitSha: zod.z.string(),
|
|
1172
|
+
updatedAt: zod.z.string(),
|
|
1173
|
+
createdAt: zod.z.string(),
|
|
1174
|
+
/**
|
|
1175
|
+
* The commit message, as the deployment's host reported it.
|
|
1176
|
+
*
|
|
1177
|
+
* Val's OWN publishes carry their message on the commit (`ValCommit`), and
|
|
1178
|
+
* that is the one the Studio prefers — it is the message Val wrote. This is
|
|
1179
|
+
* for every OTHER deployment: a developer's push, a merged pull request, a
|
|
1180
|
+
* revert. Those have no Val commit at all, so without this the deploy feed
|
|
1181
|
+
* could only name them by their short sha, and "what went out at 14:02?" had
|
|
1182
|
+
* no answer inside the Studio.
|
|
1183
|
+
*
|
|
1184
|
+
* Optional AND nullable, and the two mean different things: absent is a
|
|
1185
|
+
* content service that does not report messages (or an older one), null is
|
|
1186
|
+
* one that reports having none. Both render as the short sha, so nothing
|
|
1187
|
+
* depends on telling them apart — but a schema that demanded the field would
|
|
1188
|
+
* reject the whole deployment feed of a service that does not send it.
|
|
1189
|
+
*/
|
|
1190
|
+
commitMessage: zod.z.string().nullable().optional()
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1168
1193
|
/**
|
|
1169
1194
|
* The wire shapes for reading history.
|
|
1170
1195
|
*
|
|
@@ -1757,6 +1782,21 @@ var Api = {
|
|
|
1757
1782
|
*/
|
|
1758
1783
|
headCommitSha: zod.z.string().optional(),
|
|
1759
1784
|
commits: zod.z.array(ValCommit),
|
|
1785
|
+
/**
|
|
1786
|
+
* The publishes the content service knows about.
|
|
1787
|
+
*
|
|
1788
|
+
* Declared, at last. `getStat` has always returned these in
|
|
1789
|
+
* `http` mode and the Studio has always read them - the response
|
|
1790
|
+
* validator strips unknown keys rather than rejecting them, and
|
|
1791
|
+
* the raw json is what the client hands back, so they arrived
|
|
1792
|
+
* while the contract said they could not. That was survivable
|
|
1793
|
+
* until a deployment started carrying a commit MESSAGE: a field
|
|
1794
|
+
* nobody has declared is a field the next person deletes.
|
|
1795
|
+
*
|
|
1796
|
+
* Optional, because a content service that reports no
|
|
1797
|
+
* deployments sends none.
|
|
1798
|
+
*/
|
|
1799
|
+
deployments: zod.z.array(ValDeployment).optional(),
|
|
1760
1800
|
config: ValConfig,
|
|
1761
1801
|
profileId: zod.z.string().nullable(),
|
|
1762
1802
|
mode: zod.z.union([zod.z.literal("http"), zod.z.literal("fs")])
|
|
@@ -3249,19 +3289,9 @@ function explainIncompatible(reason) {
|
|
|
3249
3289
|
* not a failure: it is what makes the caller return `unknown` rather than guess.
|
|
3250
3290
|
*/
|
|
3251
3291
|
function variantOf(schema, value) {
|
|
3252
|
-
if (schema.type !== "union") {
|
|
3292
|
+
if (schema.type !== "discriminated-union") {
|
|
3253
3293
|
return undefined;
|
|
3254
3294
|
}
|
|
3255
|
-
// String union: the value IS the discriminator.
|
|
3256
|
-
if (typeof schema.key !== "string") {
|
|
3257
|
-
if (typeof value !== "string") {
|
|
3258
|
-
return undefined;
|
|
3259
|
-
}
|
|
3260
|
-
return schema.items.find(function (item) {
|
|
3261
|
-
return item.type === "literal" && item.value === value;
|
|
3262
|
-
});
|
|
3263
|
-
}
|
|
3264
|
-
// Object union: the discriminator is a literal at `key`.
|
|
3265
3295
|
var discriminator = schema.key;
|
|
3266
3296
|
if (!isJsonObject(value)) {
|
|
3267
3297
|
return undefined;
|
|
@@ -3279,9 +3309,6 @@ function variantOf(schema, value) {
|
|
|
3279
3309
|
});
|
|
3280
3310
|
}
|
|
3281
3311
|
function describeVariant(schema, key) {
|
|
3282
|
-
if (schema.type === "literal") {
|
|
3283
|
-
return schema.value;
|
|
3284
|
-
}
|
|
3285
3312
|
if (schema.type === "object") {
|
|
3286
3313
|
var tag = schema.items[key];
|
|
3287
3314
|
if ((tag === null || tag === void 0 ? void 0 : tag.type) === "literal") {
|
|
@@ -3299,11 +3326,24 @@ function checkCompatibility(from, to) {
|
|
|
3299
3326
|
});
|
|
3300
3327
|
}
|
|
3301
3328
|
|
|
3329
|
+
// An enum's domain IS its schema, so the value decides: whatever the old
|
|
3330
|
+
// schema was — an enum, a literal, a plain string — the only question is
|
|
3331
|
+
// whether this string is still offered here.
|
|
3332
|
+
if (to.schema.type === "enum") {
|
|
3333
|
+
if (typeof from.value === "string" && to.schema.values.includes(from.value)) {
|
|
3334
|
+
return compatible;
|
|
3335
|
+
}
|
|
3336
|
+
return incompatible({
|
|
3337
|
+
kind: "no-matching-variant",
|
|
3338
|
+
variants: to.schema.values
|
|
3339
|
+
});
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3302
3342
|
// A changed union is not itself disqualifying. What matters is whether the
|
|
3303
3343
|
// variant being restored still has somewhere to go — comparing the unions
|
|
3304
3344
|
// wholesale would refuse a restore that is perfectly safe.
|
|
3305
|
-
if (to.schema.type === "union") {
|
|
3306
|
-
var key =
|
|
3345
|
+
if (to.schema.type === "discriminated-union") {
|
|
3346
|
+
var key = to.schema.key;
|
|
3307
3347
|
var _iterator = getSitemapTree._createForOfIteratorHelper(to.schema.items),
|
|
3308
3348
|
_step;
|
|
3309
3349
|
try {
|
|
@@ -3328,9 +3368,9 @@ function checkCompatibility(from, to) {
|
|
|
3328
3368
|
});
|
|
3329
3369
|
}
|
|
3330
3370
|
|
|
3331
|
-
// Coming FROM a union into something that is not one: only the
|
|
3332
|
-
// value actually is matters, so narrow before comparing.
|
|
3333
|
-
if (from.schema.type === "union") {
|
|
3371
|
+
// Coming FROM a discriminated union into something that is not one: only the
|
|
3372
|
+
// variant this value actually is matters, so narrow before comparing.
|
|
3373
|
+
if (from.schema.type === "discriminated-union") {
|
|
3334
3374
|
var _variant = variantOf(from.schema, from.value);
|
|
3335
3375
|
if (_variant === undefined) {
|
|
3336
3376
|
return {
|
|
@@ -3343,6 +3383,25 @@ function checkCompatibility(from, to) {
|
|
|
3343
3383
|
value: from.value
|
|
3344
3384
|
}, to);
|
|
3345
3385
|
}
|
|
3386
|
+
|
|
3387
|
+
// Coming FROM an enum into something that is not one: the value it holds is
|
|
3388
|
+
// all the old schema contributes, so compare as that one value.
|
|
3389
|
+
if (from.schema.type === "enum") {
|
|
3390
|
+
if (typeof from.value !== "string") {
|
|
3391
|
+
return {
|
|
3392
|
+
status: "unknown",
|
|
3393
|
+
message: "The old value is not one of the options it was stored as, so we cannot tell whether it fits here."
|
|
3394
|
+
};
|
|
3395
|
+
}
|
|
3396
|
+
return checkCompatibility({
|
|
3397
|
+
schema: {
|
|
3398
|
+
type: "literal",
|
|
3399
|
+
value: from.value,
|
|
3400
|
+
opt: from.schema.opt
|
|
3401
|
+
},
|
|
3402
|
+
value: from.value
|
|
3403
|
+
}, to);
|
|
3404
|
+
}
|
|
3346
3405
|
if (from.schema.type !== to.schema.type) {
|
|
3347
3406
|
return incompatible({
|
|
3348
3407
|
kind: "type-changed",
|
|
@@ -3576,14 +3635,6 @@ var SharedValConfig = zod.z.object({
|
|
|
3576
3635
|
* Config that is shared between the client and server.
|
|
3577
3636
|
*/
|
|
3578
3637
|
|
|
3579
|
-
var ValDeployment = zod.z.object({
|
|
3580
|
-
deploymentId: zod.z.string(),
|
|
3581
|
-
deploymentState: zod.z.string(),
|
|
3582
|
-
commitSha: zod.z.string(),
|
|
3583
|
-
updatedAt: zod.z.string(),
|
|
3584
|
-
createdAt: zod.z.string()
|
|
3585
|
-
});
|
|
3586
|
-
|
|
3587
3638
|
/**
|
|
3588
3639
|
* Shared route validation utilities
|
|
3589
3640
|
*/
|
|
@@ -3756,6 +3807,16 @@ function findSimilar(key, targets) {
|
|
|
3756
3807
|
return a.distance - b.distance;
|
|
3757
3808
|
});
|
|
3758
3809
|
}
|
|
3810
|
+
/**
|
|
3811
|
+
* The record a `keyof:check-keys` error resolves against — the value and the
|
|
3812
|
+
* schema at the error's `sourcePath`.
|
|
3813
|
+
*
|
|
3814
|
+
* Exported for the one consumer that has to know what a resolution DEPENDED
|
|
3815
|
+
* on rather than what it concluded: `ValidationStore` re-reads the keys here
|
|
3816
|
+
* to decide whether a change to the referenced module can have moved the
|
|
3817
|
+
* answer. Keep this and {@link checkKeyIsValid} reading the same record, or the
|
|
3818
|
+
* store will invalidate on one record and the resolution answer from another.
|
|
3819
|
+
*/
|
|
3759
3820
|
function getKeyOfRecordAt(sourcePath, snapshot) {
|
|
3760
3821
|
var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(sourcePath),
|
|
3761
3822
|
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 2),
|
|
@@ -3899,6 +3960,29 @@ function checkRouteIsValid(route, includePattern, excludePattern, snapshot) {
|
|
|
3899
3960
|
error: false
|
|
3900
3961
|
};
|
|
3901
3962
|
}
|
|
3963
|
+
/**
|
|
3964
|
+
* The record a `keyof:check-keys` error resolves against, or null for any other
|
|
3965
|
+
* error — including a malformed marker, which
|
|
3966
|
+
* {@link resolveSchemaSourceFixForError} reports and this has nothing to say
|
|
3967
|
+
* about.
|
|
3968
|
+
*
|
|
3969
|
+
* For a consumer that needs to know what the resolution READS, not what it
|
|
3970
|
+
* concludes: `ValidationStore` keeps this per validated module, so that a change
|
|
3971
|
+
* to the referenced record can invalidate the module holding the reference.
|
|
3972
|
+
*/
|
|
3973
|
+
function keyOfRecordPath(error) {
|
|
3974
|
+
var _error$fixes;
|
|
3975
|
+
if (!((_error$fixes = error.fixes) !== null && _error$fixes !== void 0 ? _error$fixes : []).includes("keyof:check-keys")) {
|
|
3976
|
+
return null;
|
|
3977
|
+
}
|
|
3978
|
+
var value = error.value;
|
|
3979
|
+
if (!value || getSitemapTree._typeof(value) !== "object") {
|
|
3980
|
+
return null;
|
|
3981
|
+
}
|
|
3982
|
+
var sourcePath = value.sourcePath;
|
|
3983
|
+
return typeof sourcePath === "string" ? sourcePath : null;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3902
3986
|
/**
|
|
3903
3987
|
* Resolves a single `keyof:check-keys` or `router:check-route` error against
|
|
3904
3988
|
* the given schema/source snapshot. Returns:
|
|
@@ -3907,8 +3991,8 @@ function checkRouteIsValid(route, includePattern, excludePattern, snapshot) {
|
|
|
3907
3991
|
* - { status: "remaining"; error } if invalid (rewritten error to surface)
|
|
3908
3992
|
*/
|
|
3909
3993
|
function resolveSchemaSourceFixForError(error, snapshot) {
|
|
3910
|
-
var _error$
|
|
3911
|
-
var fixes = (_error$
|
|
3994
|
+
var _error$fixes2;
|
|
3995
|
+
var fixes = (_error$fixes2 = error.fixes) !== null && _error$fixes2 !== void 0 ? _error$fixes2 : [];
|
|
3912
3996
|
if (fixes.includes("keyof:check-keys")) {
|
|
3913
3997
|
if (!error.value) {
|
|
3914
3998
|
return {
|
|
@@ -4137,11 +4221,20 @@ function emptyOf(schema) {
|
|
|
4137
4221
|
return null; // returning null is the only thing we can do, however, it means that the patches cannot be applied yet since that might fail
|
|
4138
4222
|
} else if (schema.type === "literal") {
|
|
4139
4223
|
return schema.value;
|
|
4140
|
-
} else if (schema.type === "union") {
|
|
4141
|
-
|
|
4142
|
-
|
|
4224
|
+
} else if (schema.type === "discriminated-union") {
|
|
4225
|
+
// The first variant is what a new value starts as. `s.discriminatedUnion`
|
|
4226
|
+
// requires one, so an empty `items` means a serialized schema that was not
|
|
4227
|
+
// built by it — say so rather than returning `undefined`, which is not
|
|
4228
|
+
// JSON and would be written into a patch as a missing key.
|
|
4229
|
+
if (schema.items.length === 0) {
|
|
4230
|
+
throw Error("Cannot create an empty value for a discriminated union with no variants");
|
|
4143
4231
|
}
|
|
4144
|
-
return schema.
|
|
4232
|
+
return emptyOf(schema.items[0]);
|
|
4233
|
+
} else if (schema.type === "enum") {
|
|
4234
|
+
if (schema.values.length === 0) {
|
|
4235
|
+
throw Error("Cannot create an empty value for an enum with no values");
|
|
4236
|
+
}
|
|
4237
|
+
return schema.values[0];
|
|
4145
4238
|
} else if (schema.type === "date") {
|
|
4146
4239
|
return clampDateString(formatLocalDate(new Date()), schema.options);
|
|
4147
4240
|
} else if (schema.type === "dateTime") {
|
|
@@ -4229,24 +4322,19 @@ function resolveSerializedSchemaAtPath(schema, path) {
|
|
|
4229
4322
|
schema: current,
|
|
4230
4323
|
remainingPath: path.slice(i)
|
|
4231
4324
|
};
|
|
4232
|
-
} else if (current.type === "union") {
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
if (resolved.kind !== "unresolved") return resolved;
|
|
4241
|
-
}
|
|
4242
|
-
} catch (err) {
|
|
4243
|
-
_iterator2.e(err);
|
|
4244
|
-
} finally {
|
|
4245
|
-
_iterator2.f();
|
|
4325
|
+
} else if (current.type === "discriminated-union") {
|
|
4326
|
+
var _iterator2 = getSitemapTree._createForOfIteratorHelper(current.items),
|
|
4327
|
+
_step2;
|
|
4328
|
+
try {
|
|
4329
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
4330
|
+
var variant = _step2.value;
|
|
4331
|
+
var resolved = resolveSerializedSchemaAtPath(variant, path.slice(i));
|
|
4332
|
+
if (resolved.kind !== "unresolved") return resolved;
|
|
4246
4333
|
}
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4334
|
+
} catch (err) {
|
|
4335
|
+
_iterator2.e(err);
|
|
4336
|
+
} finally {
|
|
4337
|
+
_iterator2.f();
|
|
4250
4338
|
}
|
|
4251
4339
|
return {
|
|
4252
4340
|
kind: "unresolved"
|
|
@@ -5175,6 +5263,18 @@ function traverseSchemaSource(source, schema, path, callback) {
|
|
|
5175
5263
|
return;
|
|
5176
5264
|
}
|
|
5177
5265
|
|
|
5266
|
+
// Handle enum: a leaf, like a literal with more than one allowed value
|
|
5267
|
+
if (schema.type === "enum") {
|
|
5268
|
+
if (typeof source === "string") {
|
|
5269
|
+
callback({
|
|
5270
|
+
source: source,
|
|
5271
|
+
schema: schema,
|
|
5272
|
+
path: path
|
|
5273
|
+
});
|
|
5274
|
+
}
|
|
5275
|
+
return;
|
|
5276
|
+
}
|
|
5277
|
+
|
|
5178
5278
|
// Handle route
|
|
5179
5279
|
if (schema.type === "route") {
|
|
5180
5280
|
if (typeof source === "string") {
|
|
@@ -5222,36 +5322,24 @@ function traverseSchemaSource(source, schema, path, callback) {
|
|
|
5222
5322
|
return;
|
|
5223
5323
|
}
|
|
5224
5324
|
|
|
5225
|
-
// Handle union
|
|
5226
|
-
if (schema.type === "union") {
|
|
5325
|
+
// Handle discriminated union: descend through the variant the value takes
|
|
5326
|
+
if (schema.type === "discriminated-union") {
|
|
5227
5327
|
var schemaKey = schema.key;
|
|
5228
|
-
if (
|
|
5229
|
-
|
|
5230
|
-
if (
|
|
5231
|
-
var
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
if ((itemKeySchema === null || itemKeySchema === void 0 ? void 0 : itemKeySchema.type) === "literal") {
|
|
5238
|
-
return itemKeySchema.value === itemKey;
|
|
5239
|
-
}
|
|
5240
|
-
return false;
|
|
5241
|
-
});
|
|
5242
|
-
if (schemaOfItem) {
|
|
5243
|
-
traverseSchemaSource(source, schemaOfItem, path, callback);
|
|
5328
|
+
if (source && getSitemapTree._typeof(source) === "object" && !Array.isArray(source) && schemaKey in source) {
|
|
5329
|
+
var itemKey = source[schemaKey];
|
|
5330
|
+
if (typeof itemKey === "string") {
|
|
5331
|
+
var schemaOfItem = schema.items.filter(function (item) {
|
|
5332
|
+
return item.type === "object";
|
|
5333
|
+
}).find(function (item) {
|
|
5334
|
+
var itemKeySchema = item.items[schemaKey];
|
|
5335
|
+
if ((itemKeySchema === null || itemKeySchema === void 0 ? void 0 : itemKeySchema.type) === "literal") {
|
|
5336
|
+
return itemKeySchema.value === itemKey;
|
|
5244
5337
|
}
|
|
5245
|
-
|
|
5246
|
-
}
|
|
5247
|
-
} else {
|
|
5248
|
-
// Literal union - treat as primitive
|
|
5249
|
-
if (typeof source === "string") {
|
|
5250
|
-
callback({
|
|
5251
|
-
source: source,
|
|
5252
|
-
schema: schema,
|
|
5253
|
-
path: path
|
|
5338
|
+
return false;
|
|
5254
5339
|
});
|
|
5340
|
+
if (schemaOfItem) {
|
|
5341
|
+
traverseSchemaSource(source, schemaOfItem, path, callback);
|
|
5342
|
+
}
|
|
5255
5343
|
}
|
|
5256
5344
|
}
|
|
5257
5345
|
return;
|
|
@@ -5411,7 +5499,11 @@ function indexModule(searchIndex, moduleFilePath, source, schema) {
|
|
|
5411
5499
|
var label = "";
|
|
5412
5500
|
|
|
5413
5501
|
// Handle primitives
|
|
5414
|
-
if (schema.type === "string" || schema.type === "number" || schema.type === "boolean" || schema.type === "date" || schema.type === "dateTime" || schema.type === "color" || schema.type === "code" || schema.type === "keyOf" || schema.type === "route"
|
|
5502
|
+
if (schema.type === "string" || schema.type === "number" || schema.type === "boolean" || schema.type === "date" || schema.type === "dateTime" || schema.type === "color" || schema.type === "code" || schema.type === "keyOf" || schema.type === "route" ||
|
|
5503
|
+
// An enum's value is a string the editor chose; it is as searchable as
|
|
5504
|
+
// any other string leaf. The old string union was never indexed at all,
|
|
5505
|
+
// which is the gap this closes.
|
|
5506
|
+
schema.type === "enum") {
|
|
5415
5507
|
var _source$toString, _source$toString2;
|
|
5416
5508
|
searchText = (_source$toString = source === null || source === void 0 ? void 0 : source.toString()) !== null && _source$toString !== void 0 ? _source$toString : "";
|
|
5417
5509
|
label = (_source$toString2 = source === null || source === void 0 ? void 0 : source.toString()) !== null && _source$toString2 !== void 0 ? _source$toString2 : "";
|
|
@@ -5557,9 +5649,12 @@ exports.VAL_CANVAS_MESSAGE = getSitemapTree.VAL_CANVAS_MESSAGE;
|
|
|
5557
5649
|
exports.VAL_CANVAS_PARAM = getSitemapTree.VAL_CANVAS_PARAM;
|
|
5558
5650
|
exports.VAL_CONFIG_SESSION_STORAGE_KEY = getSitemapTree.VAL_CONFIG_SESSION_STORAGE_KEY;
|
|
5559
5651
|
exports.VAL_THEME_SESSION_STORAGE_KEY = getSitemapTree.VAL_THEME_SESSION_STORAGE_KEY;
|
|
5560
|
-
exports.getNextAppRouterSitemapTree = getSitemapTree.getNextAppRouterSitemapTree;
|
|
5561
5652
|
exports.getNextAppRouterSourceFolder = getSitemapTree.getNextAppRouterSourceFolder;
|
|
5653
|
+
exports.getPageRouterSitemapTree = getSitemapTree.getPageRouterSitemapTree;
|
|
5654
|
+
exports.getPageRouterSourceFolder = getSitemapTree.getPageRouterSourceFolder;
|
|
5562
5655
|
exports.getPatternFromModuleFilePath = getSitemapTree.getPatternFromModuleFilePath;
|
|
5656
|
+
exports.getTanStackRouterSourceFolder = getSitemapTree.getTanStackRouterSourceFolder;
|
|
5657
|
+
exports.isTanStackRoutesFolder = getSitemapTree.isTanStackRoutesFolder;
|
|
5563
5658
|
exports.isValCanvasFrame = getSitemapTree.isValCanvasFrame;
|
|
5564
5659
|
exports.isValCanvasPageMessage = getSitemapTree.isValCanvasPageMessage;
|
|
5565
5660
|
exports.isValCanvasStudioMessage = getSitemapTree.isValCanvasStudioMessage;
|
|
@@ -5609,6 +5704,8 @@ exports.SerializedCodeSchema = SerializedCodeSchema;
|
|
|
5609
5704
|
exports.SerializedColorSchema = SerializedColorSchema;
|
|
5610
5705
|
exports.SerializedDateSchema = SerializedDateSchema;
|
|
5611
5706
|
exports.SerializedDateTimeSchema = SerializedDateTimeSchema;
|
|
5707
|
+
exports.SerializedDiscriminatedUnionSchema = SerializedDiscriminatedUnionSchema;
|
|
5708
|
+
exports.SerializedEnumSchema = SerializedEnumSchema;
|
|
5612
5709
|
exports.SerializedFileSchema = SerializedFileSchema;
|
|
5613
5710
|
exports.SerializedImageSchema = SerializedImageSchema;
|
|
5614
5711
|
exports.SerializedKeyOfSchema = SerializedKeyOfSchema;
|
|
@@ -5621,7 +5718,6 @@ exports.SerializedRouteSchema = SerializedRouteSchema;
|
|
|
5621
5718
|
exports.SerializedSchema = SerializedSchema;
|
|
5622
5719
|
exports.SerializedSettingsSchema = SerializedSettingsSchema;
|
|
5623
5720
|
exports.SerializedStringSchema = SerializedStringSchema;
|
|
5624
|
-
exports.SerializedUnionSchema = SerializedUnionSchema;
|
|
5625
5721
|
exports.SharedValConfig = SharedValConfig;
|
|
5626
5722
|
exports.VAL_ENABLE_COOKIE_NAME = VAL_ENABLE_COOKIE_NAME;
|
|
5627
5723
|
exports.VAL_SESSION_COOKIE = VAL_SESSION_COOKIE;
|
|
@@ -5651,6 +5747,7 @@ exports.flattenRichText = flattenRichText;
|
|
|
5651
5747
|
exports.getErrorMessageFromUnknownJson = getErrorMessageFromUnknownJson;
|
|
5652
5748
|
exports.getFilenameFromRef = getFilenameFromRef;
|
|
5653
5749
|
exports.getInlineImgInfo = getInlineImgInfo;
|
|
5750
|
+
exports.getKeyOfRecordAt = getKeyOfRecordAt;
|
|
5654
5751
|
exports.getRefParts = getRefParts;
|
|
5655
5752
|
exports.getRoutesOf = getRoutesOf;
|
|
5656
5753
|
exports.getRoutesWithModulePaths = getRoutesWithModulePaths;
|
|
@@ -5659,6 +5756,7 @@ exports.indexModule = indexModule;
|
|
|
5659
5756
|
exports.isMimeTypeAccepted = isMimeTypeAccepted;
|
|
5660
5757
|
exports.isRemoteSchema = isRemoteSchema;
|
|
5661
5758
|
exports.isSkippedSource = isSkippedSource;
|
|
5759
|
+
exports.keyOfRecordPath = keyOfRecordPath;
|
|
5662
5760
|
exports.levenshtein = levenshtein;
|
|
5663
5761
|
exports.newestCommitSha = newestCommitSha;
|
|
5664
5762
|
exports.partitionValidationErrors = partitionValidationErrors;
|