@valbuild/tanstack 0.124.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/LICENSE.md +7 -0
- package/README.md +380 -0
- package/client/dist/valbuild-tanstack-client.cjs.d.ts +2 -0
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +288 -0
- package/client/dist/valbuild-tanstack-client.cjs.js +7 -0
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +288 -0
- package/client/dist/valbuild-tanstack-client.esm.js +280 -0
- package/client/package.json +4 -0
- package/dist/ValOverlayContext-87cb022d.esm.js +284 -0
- package/dist/ValOverlayContext-abd6ab9a.cjs.prod.js +292 -0
- package/dist/ValOverlayContext-d3bfacb1.cjs.dev.js +292 -0
- package/dist/createForOfIteratorHelper-0324e063.cjs.prod.js +157 -0
- package/dist/createForOfIteratorHelper-485c2ce1.esm.js +151 -0
- package/dist/createForOfIteratorHelper-e75681d7.cjs.dev.js +157 -0
- package/dist/declarations/src/ValApp.d.ts +6 -0
- package/dist/declarations/src/ValImage.d.ts +24 -0
- package/dist/declarations/src/ValModulesClient.d.ts +34 -0
- package/dist/declarations/src/ValProvider.d.ts +6 -0
- package/dist/declarations/src/ValTypes.d.ts +4 -0
- package/dist/declarations/src/client/index.d.ts +1 -0
- package/dist/declarations/src/client/initValClient.d.ts +27 -0
- package/dist/declarations/src/decodeValPathsOfString.d.ts +2 -0
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +41 -0
- package/dist/declarations/src/getUnpatchedUnencodedVal.d.ts +3 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/initVal.d.ts +74 -0
- package/dist/declarations/src/server/index.d.ts +5 -0
- package/dist/declarations/src/server/initValContent.d.ts +122 -0
- package/dist/declarations/src/server/initValMcp.d.ts +27 -0
- package/dist/declarations/src/server/initValServer.d.ts +41 -0
- package/dist/declarations/src/server/valDraftMode.d.ts +49 -0
- package/dist/declarations/src/version.d.ts +1 -0
- package/dist/routeFromVal-6693e037.cjs.prod.js +218 -0
- package/dist/routeFromVal-728295a0.esm.js +212 -0
- package/dist/routeFromVal-a9147ceb.cjs.dev.js +218 -0
- package/dist/valbuild-tanstack.cjs.d.ts +2 -0
- package/dist/valbuild-tanstack.cjs.dev.js +2005 -0
- package/dist/valbuild-tanstack.cjs.js +7 -0
- package/dist/valbuild-tanstack.cjs.prod.js +2005 -0
- package/dist/valbuild-tanstack.esm.js +1950 -0
- package/dist/version-1a88fd21.cjs.dev.js +229 -0
- package/dist/version-5ac70ccf.cjs.prod.js +229 -0
- package/dist/version-ac8df696.esm.js +225 -0
- package/package.json +84 -0
- package/server/dist/valbuild-tanstack-server.cjs.d.ts +2 -0
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +1032 -0
- package/server/dist/valbuild-tanstack-server.cjs.js +7 -0
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +1032 -0
- package/server/dist/valbuild-tanstack-server.esm.js +1005 -0
- package/server/package.json +4 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createForOfIteratorHelper = require('./createForOfIteratorHelper-0324e063.cjs.prod.js');
|
|
4
|
+
var core = require('@valbuild/core');
|
|
5
|
+
var client = require('@valbuild/shared/client');
|
|
6
|
+
|
|
7
|
+
function _typeof(o) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
|
|
10
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
11
|
+
return typeof o;
|
|
12
|
+
} : function (o) {
|
|
13
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
14
|
+
}, _typeof(o);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* True when the module's schema is a `.jsonValues()` record/router — i.e. each
|
|
19
|
+
* entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
|
|
20
|
+
* route helpers to load ONLY the matched entry instead of the whole record.
|
|
21
|
+
*/
|
|
22
|
+
function isJsonValuesRecordSchema(schema) {
|
|
23
|
+
return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
28
|
+
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
29
|
+
* identity transform (the content carries no selector path/schema).
|
|
30
|
+
*
|
|
31
|
+
* Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
|
|
32
|
+
* field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
|
|
33
|
+
* `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
|
|
34
|
+
*/
|
|
35
|
+
function getJsonEntryStegaRoot(
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
selector, key
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
) {
|
|
40
|
+
var modulePath = selector && core.Internal.getValPath(selector);
|
|
41
|
+
if (!modulePath) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
var schema = selector && core.Internal.getSchema(selector);
|
|
45
|
+
if (!(schema instanceof core.RecordSchema)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
var path = core.Internal.createValPathOfItem(modulePath, key);
|
|
49
|
+
if (!path) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
path: path,
|
|
54
|
+
schema: schema["executeSerialize"]().item
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getValRouteUrlFromVal(resolvedParams, methodName,
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
path,
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
schema,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
val) {
|
|
64
|
+
if (!path) {
|
|
65
|
+
console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (val === null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (_typeof(val) !== "object") {
|
|
72
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof(val), " instead)."));
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(val)) {
|
|
76
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (!schema) {
|
|
80
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (!(schema instanceof core.RecordSchema)) {
|
|
84
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
|
|
85
|
+
} else if (!schema["currentRouter"]) {
|
|
86
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
|
|
87
|
+
} else if (schema["currentRouter"].getRouterId() !== core.Internal.tanstackRouter.getRouterId() && schema["currentRouter"].getRouterId() !== core.Internal.externalPageRouter.getRouterId()) {
|
|
88
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the TanStack Router or External URL Page Router)."));
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if (_typeof(resolvedParams) !== "object") {
|
|
92
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path),
|
|
96
|
+
_Internal$splitModule2 = createForOfIteratorHelper._slicedToArray(_Internal$splitModule, 1),
|
|
97
|
+
moduleFilePath = _Internal$splitModule2[0];
|
|
98
|
+
/*
|
|
99
|
+
* A route module is named after the route file it sits beside.
|
|
100
|
+
*
|
|
101
|
+
* There is no `page.val.ts` here, because TanStack Router has no `page.tsx`:
|
|
102
|
+
* the route file IS the name of the route, so `routes/posts.$postId.tsx` is
|
|
103
|
+
* served by `routes/posts.$postId.val.ts` and the file name is the whole of
|
|
104
|
+
* what says which route this is. Being under `routes/` is therefore the only
|
|
105
|
+
* thing to check.
|
|
106
|
+
*/
|
|
107
|
+
var srcFolder = client.getTanStackRouterSourceFolder(moduleFilePath);
|
|
108
|
+
if (!srcFolder) {
|
|
109
|
+
console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /routes or /src/routes folder. Name the module after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
var pattern = client.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
|
|
113
|
+
var parsedPattern = client.parseRoutePattern(pattern);
|
|
114
|
+
var missingPatterns = [];
|
|
115
|
+
var fullPathParts = [];
|
|
116
|
+
var missingParamKeys = _typeof(resolvedParams) === "object" && resolvedParams !== null && !Array.isArray(resolvedParams) ? createForOfIteratorHelper._objectSpread2({}, resolvedParams) : {};
|
|
117
|
+
/*
|
|
118
|
+
* TanStack names a splat twice, and only one of the names is Val's.
|
|
119
|
+
*
|
|
120
|
+
* `useParams()` on a `$` route returns BOTH `_splat` and `*`, set to the same
|
|
121
|
+
* value — see `interpolatePath` in `@tanstack/router-core`. Val's pattern has
|
|
122
|
+
* one param for it, so the other name was left over at the end of the loop
|
|
123
|
+
* below and reported as a parameter that is not in the path: a console error
|
|
124
|
+
* on every render of a working splat route. Dropping it here rather than
|
|
125
|
+
* special-casing the report keeps "what was left over" meaning what it says.
|
|
126
|
+
*/
|
|
127
|
+
if ("*" in missingParamKeys && "_splat" in missingParamKeys) {
|
|
128
|
+
delete missingParamKeys["*"];
|
|
129
|
+
}
|
|
130
|
+
var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
|
|
131
|
+
_step;
|
|
132
|
+
try {
|
|
133
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
134
|
+
var part = _step.value;
|
|
135
|
+
if (part.type === "literal") {
|
|
136
|
+
fullPathParts.push(part.name);
|
|
137
|
+
} else if (part.type === "array-param" || part.type === "string-param") {
|
|
138
|
+
var key = part.paramName;
|
|
139
|
+
var value = resolvedParams === null || resolvedParams === void 0 ? void 0 : resolvedParams[key];
|
|
140
|
+
if (typeof value !== "string" && !Array.isArray(value)) {
|
|
141
|
+
missingPatterns.push(part);
|
|
142
|
+
} else if (Array.isArray(value)) {
|
|
143
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
144
|
+
delete missingParamKeys[key];
|
|
145
|
+
}
|
|
146
|
+
fullPathParts.push(value.join("/"));
|
|
147
|
+
} else {
|
|
148
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
149
|
+
delete missingParamKeys[key];
|
|
150
|
+
}
|
|
151
|
+
fullPathParts.push(value);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_iterator.e(err);
|
|
157
|
+
} finally {
|
|
158
|
+
_iterator.f();
|
|
159
|
+
}
|
|
160
|
+
var lastPattern = missingPatterns === null || missingPatterns === void 0 ? void 0 : missingPatterns[missingPatterns.length - 1];
|
|
161
|
+
var isLastOptional = lastPattern && lastPattern.type === "array-param" && lastPattern.optional;
|
|
162
|
+
if (isLastOptional) {
|
|
163
|
+
// We **think** that if the last pattern is optional we might still want to match
|
|
164
|
+
// An example: /some-path/[[...test]]
|
|
165
|
+
// Or even: /[[...path]]
|
|
166
|
+
// We believe there's no other legal ways to have optional patterns? Right?
|
|
167
|
+
missingPatterns.pop();
|
|
168
|
+
}
|
|
169
|
+
if (missingPatterns.length > 0) {
|
|
170
|
+
var errorMessageParams = missingPatterns.map(function (part) {
|
|
171
|
+
if (part.type === "literal") {
|
|
172
|
+
return part.name;
|
|
173
|
+
} else if (part.type === "string-param") {
|
|
174
|
+
if (part.optional) {
|
|
175
|
+
return "[[".concat(part.paramName, "]]");
|
|
176
|
+
}
|
|
177
|
+
return "[".concat(part.paramName, "]");
|
|
178
|
+
} else if (part.type === "array-param") {
|
|
179
|
+
if (part.optional) {
|
|
180
|
+
return "[[...".concat(part.paramName, "]]");
|
|
181
|
+
}
|
|
182
|
+
return "[...".concat(part.paramName, "]");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is named after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
if (Object.keys(missingParamKeys).length > 0) {
|
|
189
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " is named after the route file it belongs to."));
|
|
190
|
+
// We do not return null here since we found a route that matches the path
|
|
191
|
+
// though chances are that there's something wrong in the way ${methodName} is used
|
|
192
|
+
}
|
|
193
|
+
var fullPath = fullPathParts.join("/");
|
|
194
|
+
return "/".concat(fullPath);
|
|
195
|
+
}
|
|
196
|
+
function initValRouteFromVal(resolvedParams, methodName,
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
path,
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
schema,
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
202
|
+
val) {
|
|
203
|
+
var url = getValRouteUrlFromVal(resolvedParams, methodName, path, schema, val);
|
|
204
|
+
if (!url) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
var actualRoute = val[url];
|
|
208
|
+
if (!actualRoute) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return actualRoute;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
exports._typeof = _typeof;
|
|
215
|
+
exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
|
|
216
|
+
exports.getValRouteUrlFromVal = getValRouteUrlFromVal;
|
|
217
|
+
exports.initValRouteFromVal = initValRouteFromVal;
|
|
218
|
+
exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { a as _slicedToArray, _ as _objectSpread2, b as _createForOfIteratorHelper } from './createForOfIteratorHelper-485c2ce1.esm.js';
|
|
2
|
+
import { RecordSchema, Internal } from '@valbuild/core';
|
|
3
|
+
import { getTanStackRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern } from '@valbuild/shared/client';
|
|
4
|
+
|
|
5
|
+
function _typeof(o) {
|
|
6
|
+
"@babel/helpers - typeof";
|
|
7
|
+
|
|
8
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
9
|
+
return typeof o;
|
|
10
|
+
} : function (o) {
|
|
11
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
12
|
+
}, _typeof(o);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* True when the module's schema is a `.jsonValues()` record/router — i.e. each
|
|
17
|
+
* entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
|
|
18
|
+
* route helpers to load ONLY the matched entry instead of the whole record.
|
|
19
|
+
*/
|
|
20
|
+
function isJsonValuesRecordSchema(schema) {
|
|
21
|
+
return schema instanceof RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
26
|
+
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
27
|
+
* identity transform (the content carries no selector path/schema).
|
|
28
|
+
*
|
|
29
|
+
* Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
|
|
30
|
+
* field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
|
|
31
|
+
* `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
|
|
32
|
+
*/
|
|
33
|
+
function getJsonEntryStegaRoot(
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
selector, key
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
) {
|
|
38
|
+
var modulePath = selector && Internal.getValPath(selector);
|
|
39
|
+
if (!modulePath) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
var schema = selector && Internal.getSchema(selector);
|
|
43
|
+
if (!(schema instanceof RecordSchema)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
var path = Internal.createValPathOfItem(modulePath, key);
|
|
47
|
+
if (!path) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
path: path,
|
|
52
|
+
schema: schema["executeSerialize"]().item
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function getValRouteUrlFromVal(resolvedParams, methodName,
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
path,
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
schema,
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
val) {
|
|
62
|
+
if (!path) {
|
|
63
|
+
console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (val === null) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (_typeof(val) !== "object") {
|
|
70
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof(val), " instead)."));
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(val)) {
|
|
74
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (!schema) {
|
|
78
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (!(schema instanceof RecordSchema)) {
|
|
82
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
|
|
83
|
+
} else if (!schema["currentRouter"]) {
|
|
84
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
|
|
85
|
+
} else if (schema["currentRouter"].getRouterId() !== Internal.tanstackRouter.getRouterId() && schema["currentRouter"].getRouterId() !== Internal.externalPageRouter.getRouterId()) {
|
|
86
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the TanStack Router or External URL Page Router)."));
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
if (_typeof(resolvedParams) !== "object") {
|
|
90
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(path),
|
|
94
|
+
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 1),
|
|
95
|
+
moduleFilePath = _Internal$splitModule2[0];
|
|
96
|
+
/*
|
|
97
|
+
* A route module is named after the route file it sits beside.
|
|
98
|
+
*
|
|
99
|
+
* There is no `page.val.ts` here, because TanStack Router has no `page.tsx`:
|
|
100
|
+
* the route file IS the name of the route, so `routes/posts.$postId.tsx` is
|
|
101
|
+
* served by `routes/posts.$postId.val.ts` and the file name is the whole of
|
|
102
|
+
* what says which route this is. Being under `routes/` is therefore the only
|
|
103
|
+
* thing to check.
|
|
104
|
+
*/
|
|
105
|
+
var srcFolder = getTanStackRouterSourceFolder(moduleFilePath);
|
|
106
|
+
if (!srcFolder) {
|
|
107
|
+
console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /routes or /src/routes folder. Name the module after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
|
|
111
|
+
var parsedPattern = parseRoutePattern(pattern);
|
|
112
|
+
var missingPatterns = [];
|
|
113
|
+
var fullPathParts = [];
|
|
114
|
+
var missingParamKeys = _typeof(resolvedParams) === "object" && resolvedParams !== null && !Array.isArray(resolvedParams) ? _objectSpread2({}, resolvedParams) : {};
|
|
115
|
+
/*
|
|
116
|
+
* TanStack names a splat twice, and only one of the names is Val's.
|
|
117
|
+
*
|
|
118
|
+
* `useParams()` on a `$` route returns BOTH `_splat` and `*`, set to the same
|
|
119
|
+
* value — see `interpolatePath` in `@tanstack/router-core`. Val's pattern has
|
|
120
|
+
* one param for it, so the other name was left over at the end of the loop
|
|
121
|
+
* below and reported as a parameter that is not in the path: a console error
|
|
122
|
+
* on every render of a working splat route. Dropping it here rather than
|
|
123
|
+
* special-casing the report keeps "what was left over" meaning what it says.
|
|
124
|
+
*/
|
|
125
|
+
if ("*" in missingParamKeys && "_splat" in missingParamKeys) {
|
|
126
|
+
delete missingParamKeys["*"];
|
|
127
|
+
}
|
|
128
|
+
var _iterator = _createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
|
|
129
|
+
_step;
|
|
130
|
+
try {
|
|
131
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
132
|
+
var part = _step.value;
|
|
133
|
+
if (part.type === "literal") {
|
|
134
|
+
fullPathParts.push(part.name);
|
|
135
|
+
} else if (part.type === "array-param" || part.type === "string-param") {
|
|
136
|
+
var key = part.paramName;
|
|
137
|
+
var value = resolvedParams === null || resolvedParams === void 0 ? void 0 : resolvedParams[key];
|
|
138
|
+
if (typeof value !== "string" && !Array.isArray(value)) {
|
|
139
|
+
missingPatterns.push(part);
|
|
140
|
+
} else if (Array.isArray(value)) {
|
|
141
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
142
|
+
delete missingParamKeys[key];
|
|
143
|
+
}
|
|
144
|
+
fullPathParts.push(value.join("/"));
|
|
145
|
+
} else {
|
|
146
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
147
|
+
delete missingParamKeys[key];
|
|
148
|
+
}
|
|
149
|
+
fullPathParts.push(value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
_iterator.e(err);
|
|
155
|
+
} finally {
|
|
156
|
+
_iterator.f();
|
|
157
|
+
}
|
|
158
|
+
var lastPattern = missingPatterns === null || missingPatterns === void 0 ? void 0 : missingPatterns[missingPatterns.length - 1];
|
|
159
|
+
var isLastOptional = lastPattern && lastPattern.type === "array-param" && lastPattern.optional;
|
|
160
|
+
if (isLastOptional) {
|
|
161
|
+
// We **think** that if the last pattern is optional we might still want to match
|
|
162
|
+
// An example: /some-path/[[...test]]
|
|
163
|
+
// Or even: /[[...path]]
|
|
164
|
+
// We believe there's no other legal ways to have optional patterns? Right?
|
|
165
|
+
missingPatterns.pop();
|
|
166
|
+
}
|
|
167
|
+
if (missingPatterns.length > 0) {
|
|
168
|
+
var errorMessageParams = missingPatterns.map(function (part) {
|
|
169
|
+
if (part.type === "literal") {
|
|
170
|
+
return part.name;
|
|
171
|
+
} else if (part.type === "string-param") {
|
|
172
|
+
if (part.optional) {
|
|
173
|
+
return "[[".concat(part.paramName, "]]");
|
|
174
|
+
}
|
|
175
|
+
return "[".concat(part.paramName, "]");
|
|
176
|
+
} else if (part.type === "array-param") {
|
|
177
|
+
if (part.optional) {
|
|
178
|
+
return "[[...".concat(part.paramName, "]]");
|
|
179
|
+
}
|
|
180
|
+
return "[...".concat(part.paramName, "]");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is named after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (Object.keys(missingParamKeys).length > 0) {
|
|
187
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " is named after the route file it belongs to."));
|
|
188
|
+
// We do not return null here since we found a route that matches the path
|
|
189
|
+
// though chances are that there's something wrong in the way ${methodName} is used
|
|
190
|
+
}
|
|
191
|
+
var fullPath = fullPathParts.join("/");
|
|
192
|
+
return "/".concat(fullPath);
|
|
193
|
+
}
|
|
194
|
+
function initValRouteFromVal(resolvedParams, methodName,
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
196
|
+
path,
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
schema,
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
val) {
|
|
201
|
+
var url = getValRouteUrlFromVal(resolvedParams, methodName, path, schema, val);
|
|
202
|
+
if (!url) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
var actualRoute = val[url];
|
|
206
|
+
if (!actualRoute) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return actualRoute;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { _typeof as _, getValRouteUrlFromVal as a, initValRouteFromVal as b, getJsonEntryStegaRoot as g, isJsonValuesRecordSchema as i };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createForOfIteratorHelper = require('./createForOfIteratorHelper-e75681d7.cjs.dev.js');
|
|
4
|
+
var core = require('@valbuild/core');
|
|
5
|
+
var client = require('@valbuild/shared/client');
|
|
6
|
+
|
|
7
|
+
function _typeof(o) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
|
|
10
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
11
|
+
return typeof o;
|
|
12
|
+
} : function (o) {
|
|
13
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
14
|
+
}, _typeof(o);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* True when the module's schema is a `.jsonValues()` record/router — i.e. each
|
|
19
|
+
* entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
|
|
20
|
+
* route helpers to load ONLY the matched entry instead of the whole record.
|
|
21
|
+
*/
|
|
22
|
+
function isJsonValuesRecordSchema(schema) {
|
|
23
|
+
return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
28
|
+
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
29
|
+
* identity transform (the content carries no selector path/schema).
|
|
30
|
+
*
|
|
31
|
+
* Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
|
|
32
|
+
* field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
|
|
33
|
+
* `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
|
|
34
|
+
*/
|
|
35
|
+
function getJsonEntryStegaRoot(
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
selector, key
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
) {
|
|
40
|
+
var modulePath = selector && core.Internal.getValPath(selector);
|
|
41
|
+
if (!modulePath) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
var schema = selector && core.Internal.getSchema(selector);
|
|
45
|
+
if (!(schema instanceof core.RecordSchema)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
var path = core.Internal.createValPathOfItem(modulePath, key);
|
|
49
|
+
if (!path) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
path: path,
|
|
54
|
+
schema: schema["executeSerialize"]().item
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getValRouteUrlFromVal(resolvedParams, methodName,
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
path,
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
schema,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
val) {
|
|
64
|
+
if (!path) {
|
|
65
|
+
console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (val === null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (_typeof(val) !== "object") {
|
|
72
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof(val), " instead)."));
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(val)) {
|
|
76
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (!schema) {
|
|
80
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (!(schema instanceof core.RecordSchema)) {
|
|
84
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
|
|
85
|
+
} else if (!schema["currentRouter"]) {
|
|
86
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
|
|
87
|
+
} else if (schema["currentRouter"].getRouterId() !== core.Internal.tanstackRouter.getRouterId() && schema["currentRouter"].getRouterId() !== core.Internal.externalPageRouter.getRouterId()) {
|
|
88
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the TanStack Router or External URL Page Router)."));
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if (_typeof(resolvedParams) !== "object") {
|
|
92
|
+
console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path),
|
|
96
|
+
_Internal$splitModule2 = createForOfIteratorHelper._slicedToArray(_Internal$splitModule, 1),
|
|
97
|
+
moduleFilePath = _Internal$splitModule2[0];
|
|
98
|
+
/*
|
|
99
|
+
* A route module is named after the route file it sits beside.
|
|
100
|
+
*
|
|
101
|
+
* There is no `page.val.ts` here, because TanStack Router has no `page.tsx`:
|
|
102
|
+
* the route file IS the name of the route, so `routes/posts.$postId.tsx` is
|
|
103
|
+
* served by `routes/posts.$postId.val.ts` and the file name is the whole of
|
|
104
|
+
* what says which route this is. Being under `routes/` is therefore the only
|
|
105
|
+
* thing to check.
|
|
106
|
+
*/
|
|
107
|
+
var srcFolder = client.getTanStackRouterSourceFolder(moduleFilePath);
|
|
108
|
+
if (!srcFolder) {
|
|
109
|
+
console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /routes or /src/routes folder. Name the module after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
var pattern = client.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
|
|
113
|
+
var parsedPattern = client.parseRoutePattern(pattern);
|
|
114
|
+
var missingPatterns = [];
|
|
115
|
+
var fullPathParts = [];
|
|
116
|
+
var missingParamKeys = _typeof(resolvedParams) === "object" && resolvedParams !== null && !Array.isArray(resolvedParams) ? createForOfIteratorHelper._objectSpread2({}, resolvedParams) : {};
|
|
117
|
+
/*
|
|
118
|
+
* TanStack names a splat twice, and only one of the names is Val's.
|
|
119
|
+
*
|
|
120
|
+
* `useParams()` on a `$` route returns BOTH `_splat` and `*`, set to the same
|
|
121
|
+
* value — see `interpolatePath` in `@tanstack/router-core`. Val's pattern has
|
|
122
|
+
* one param for it, so the other name was left over at the end of the loop
|
|
123
|
+
* below and reported as a parameter that is not in the path: a console error
|
|
124
|
+
* on every render of a working splat route. Dropping it here rather than
|
|
125
|
+
* special-casing the report keeps "what was left over" meaning what it says.
|
|
126
|
+
*/
|
|
127
|
+
if ("*" in missingParamKeys && "_splat" in missingParamKeys) {
|
|
128
|
+
delete missingParamKeys["*"];
|
|
129
|
+
}
|
|
130
|
+
var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
|
|
131
|
+
_step;
|
|
132
|
+
try {
|
|
133
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
134
|
+
var part = _step.value;
|
|
135
|
+
if (part.type === "literal") {
|
|
136
|
+
fullPathParts.push(part.name);
|
|
137
|
+
} else if (part.type === "array-param" || part.type === "string-param") {
|
|
138
|
+
var key = part.paramName;
|
|
139
|
+
var value = resolvedParams === null || resolvedParams === void 0 ? void 0 : resolvedParams[key];
|
|
140
|
+
if (typeof value !== "string" && !Array.isArray(value)) {
|
|
141
|
+
missingPatterns.push(part);
|
|
142
|
+
} else if (Array.isArray(value)) {
|
|
143
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
144
|
+
delete missingParamKeys[key];
|
|
145
|
+
}
|
|
146
|
+
fullPathParts.push(value.join("/"));
|
|
147
|
+
} else {
|
|
148
|
+
if (missingParamKeys !== null && missingParamKeys !== void 0 && missingParamKeys[key]) {
|
|
149
|
+
delete missingParamKeys[key];
|
|
150
|
+
}
|
|
151
|
+
fullPathParts.push(value);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_iterator.e(err);
|
|
157
|
+
} finally {
|
|
158
|
+
_iterator.f();
|
|
159
|
+
}
|
|
160
|
+
var lastPattern = missingPatterns === null || missingPatterns === void 0 ? void 0 : missingPatterns[missingPatterns.length - 1];
|
|
161
|
+
var isLastOptional = lastPattern && lastPattern.type === "array-param" && lastPattern.optional;
|
|
162
|
+
if (isLastOptional) {
|
|
163
|
+
// We **think** that if the last pattern is optional we might still want to match
|
|
164
|
+
// An example: /some-path/[[...test]]
|
|
165
|
+
// Or even: /[[...path]]
|
|
166
|
+
// We believe there's no other legal ways to have optional patterns? Right?
|
|
167
|
+
missingPatterns.pop();
|
|
168
|
+
}
|
|
169
|
+
if (missingPatterns.length > 0) {
|
|
170
|
+
var errorMessageParams = missingPatterns.map(function (part) {
|
|
171
|
+
if (part.type === "literal") {
|
|
172
|
+
return part.name;
|
|
173
|
+
} else if (part.type === "string-param") {
|
|
174
|
+
if (part.optional) {
|
|
175
|
+
return "[[".concat(part.paramName, "]]");
|
|
176
|
+
}
|
|
177
|
+
return "[".concat(part.paramName, "]");
|
|
178
|
+
} else if (part.type === "array-param") {
|
|
179
|
+
if (part.optional) {
|
|
180
|
+
return "[[...".concat(part.paramName, "]]");
|
|
181
|
+
}
|
|
182
|
+
return "[...".concat(part.paramName, "]");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is named after the route file it belongs to, e.g. /src/routes/posts.$postId.val.ts next to /src/routes/posts.$postId.tsx."));
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
if (Object.keys(missingParamKeys).length > 0) {
|
|
189
|
+
console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " is named after the route file it belongs to."));
|
|
190
|
+
// We do not return null here since we found a route that matches the path
|
|
191
|
+
// though chances are that there's something wrong in the way ${methodName} is used
|
|
192
|
+
}
|
|
193
|
+
var fullPath = fullPathParts.join("/");
|
|
194
|
+
return "/".concat(fullPath);
|
|
195
|
+
}
|
|
196
|
+
function initValRouteFromVal(resolvedParams, methodName,
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
path,
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
schema,
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
202
|
+
val) {
|
|
203
|
+
var url = getValRouteUrlFromVal(resolvedParams, methodName, path, schema, val);
|
|
204
|
+
if (!url) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
var actualRoute = val[url];
|
|
208
|
+
if (!actualRoute) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return actualRoute;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
exports._typeof = _typeof;
|
|
215
|
+
exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
|
|
216
|
+
exports.getValRouteUrlFromVal = getValRouteUrlFromVal;
|
|
217
|
+
exports.initValRouteFromVal = initValRouteFromVal;
|
|
218
|
+
exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtdGFuc3RhY2suY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|