@valbuild/core 0.97.4 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/schema/index.d.ts +9 -0
- package/dist/declarations/src/schema/router.d.ts +2 -1
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/{index-30ac56b6.cjs.prod.js → index-11f47a61.cjs.prod.js} +57 -43
- package/dist/{index-a169d6a7.cjs.dev.js → index-233a49d6.cjs.dev.js} +57 -43
- package/dist/{index-6aa8e224.esm.js → index-d152e3e2.esm.js} +57 -43
- package/dist/valbuild-core.cjs.dev.js +1 -1
- package/dist/valbuild-core.cjs.prod.js +1 -1
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
|
@@ -86,6 +86,15 @@ export declare abstract class Schema<Src extends SelectorSource> {
|
|
|
86
86
|
protected abstract executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
|
|
87
87
|
/** MUTATES! since internal and perf sensitive */
|
|
88
88
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown, schemaError?: boolean): ValidationErrors;
|
|
89
|
+
/**
|
|
90
|
+
* Merges two sets of validation errors path-wise: errors on the same path are
|
|
91
|
+
* concatenated, not overwritten. Object spread cannot be used for this, since
|
|
92
|
+
* it replaces the array of the colliding path. A record, for example, validates
|
|
93
|
+
* the key and the item on the same path, so both sets must survive.
|
|
94
|
+
*
|
|
95
|
+
* MUTATES! since internal and perf sensitive
|
|
96
|
+
*/
|
|
97
|
+
protected mergeValidationErrors(current: ValidationErrors, incoming: ValidationErrors): ValidationErrors;
|
|
89
98
|
}
|
|
90
99
|
export type SelectorOfSchema<T extends Schema<SelectorSource>> = T extends Schema<infer Src> ? Src : never;
|
|
91
100
|
export {};
|
|
@@ -2,4 +2,5 @@ import { Schema, SelectorOfSchema } from "./index.js";
|
|
|
2
2
|
import { ValRouter } from "../router.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
4
|
import { RecordSchema } from "./record.js";
|
|
5
|
-
export declare function router<
|
|
5
|
+
export declare function router<K extends Schema<string>, T extends Schema<SelectorSource>>(router: ValRouter, key: K, item: T): RecordSchema<T, K, Record<SelectorOfSchema<K>, SelectorOfSchema<T>>>;
|
|
6
|
+
export declare function router<T extends Schema<SelectorSource>>(router: ValRouter, item: T): RecordSchema<T, Schema<string>, Record<string, SelectorOfSchema<T>>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "images:check-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "files:check-remote", "keyof:check-keys", "router:check-route", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files"];
|
|
1
|
+
export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "images:check-remote", "images:upload-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "files:check-remote", "files:upload-remote", "keyof:check-keys", "router:check-route", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files"];
|
|
2
2
|
export type ValidationFix = (typeof ValidationFix)[number];
|
|
@@ -222,6 +222,34 @@ var Schema = /*#__PURE__*/function () {
|
|
|
222
222
|
}]);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Merges two sets of validation errors path-wise: errors on the same path are
|
|
228
|
+
* concatenated, not overwritten. Object spread cannot be used for this, since
|
|
229
|
+
* it replaces the array of the colliding path. A record, for example, validates
|
|
230
|
+
* the key and the item on the same path, so both sets must survive.
|
|
231
|
+
*
|
|
232
|
+
* MUTATES! since internal and perf sensitive
|
|
233
|
+
*/
|
|
234
|
+
}, {
|
|
235
|
+
key: "mergeValidationErrors",
|
|
236
|
+
value: function mergeValidationErrors(current, incoming) {
|
|
237
|
+
if (!incoming) {
|
|
238
|
+
return current;
|
|
239
|
+
}
|
|
240
|
+
if (!current) {
|
|
241
|
+
return incoming;
|
|
242
|
+
}
|
|
243
|
+
for (var pathS in incoming) {
|
|
244
|
+
var _path = pathS;
|
|
245
|
+
if (current[_path]) {
|
|
246
|
+
current[_path] = current[_path].concat(incoming[_path]);
|
|
247
|
+
} else {
|
|
248
|
+
current[_path] = incoming[_path];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return current;
|
|
252
|
+
}
|
|
225
253
|
}]);
|
|
226
254
|
}();
|
|
227
255
|
|
|
@@ -1007,11 +1035,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1007
1035
|
src);
|
|
1008
1036
|
} else {
|
|
1009
1037
|
var subError = schema["executeValidate"](subPath, src[_key]);
|
|
1010
|
-
|
|
1011
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1012
|
-
} else if (subError) {
|
|
1013
|
-
error = subError;
|
|
1014
|
-
}
|
|
1038
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1015
1039
|
}
|
|
1016
1040
|
}
|
|
1017
1041
|
return error;
|
|
@@ -1185,7 +1209,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1185
1209
|
if (assertRes.data === null) {
|
|
1186
1210
|
return false;
|
|
1187
1211
|
}
|
|
1188
|
-
var error =
|
|
1212
|
+
var error = false;
|
|
1189
1213
|
for (var _i = 0, _Object$entries = Object.entries(assertRes.data); _i < _Object$entries.length; _i++) {
|
|
1190
1214
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1191
1215
|
idx = _Object$entries$_i[0],
|
|
@@ -1193,12 +1217,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1193
1217
|
var subPath = unsafeCreateSourcePath(path, Number(idx));
|
|
1194
1218
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1195
1219
|
var subError = this.item["executeValidate"](subPath, i);
|
|
1196
|
-
|
|
1197
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
if (Object.keys(error).length === 0) {
|
|
1201
|
-
return false;
|
|
1220
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1202
1221
|
}
|
|
1203
1222
|
return error;
|
|
1204
1223
|
}
|
|
@@ -2981,9 +3000,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2981
3000
|
}]));
|
|
2982
3001
|
}
|
|
2983
3002
|
var routerValidations = this.getRouterValidations(path, src);
|
|
2984
|
-
|
|
2985
|
-
return routerValidations;
|
|
2986
|
-
}
|
|
3003
|
+
error = this.mergeValidationErrors(error, routerValidations);
|
|
2987
3004
|
var _iterator = result._createForOfIteratorHelper(customValidationErrors),
|
|
2988
3005
|
_step;
|
|
2989
3006
|
try {
|
|
@@ -3047,15 +3064,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3047
3064
|
keyError: true
|
|
3048
3065
|
});
|
|
3049
3066
|
});
|
|
3050
|
-
|
|
3051
|
-
if (error[keyPath]) {
|
|
3052
|
-
error[keyPath] = [].concat(_toConsumableArray(error[keyPath]), _toConsumableArray(keyError[keyPath]));
|
|
3053
|
-
} else {
|
|
3054
|
-
error[keyPath] = keyError[keyPath];
|
|
3055
|
-
}
|
|
3056
|
-
} else {
|
|
3057
|
-
error = keyError;
|
|
3058
|
-
}
|
|
3067
|
+
error = _this2.mergeValidationErrors(error, keyError);
|
|
3059
3068
|
}
|
|
3060
3069
|
}
|
|
3061
3070
|
var subPath = createValPathOfItem(path, key);
|
|
@@ -3070,20 +3079,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3070
3079
|
var keyErr = _this2.validateMediaKey(subPath, key);
|
|
3071
3080
|
if (keyErr) {
|
|
3072
3081
|
_this2.markKeyErrorsAtPath(keyErr, subPath);
|
|
3073
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), keyErr) : keyErr;
|
|
3074
3082
|
}
|
|
3083
|
+
error = _this2.mergeValidationErrors(error, keyErr);
|
|
3075
3084
|
var entryErr = _this2.validateMediaEntry(subPath, elem);
|
|
3076
3085
|
if (entryErr) {
|
|
3077
3086
|
_this2.markKeyErrorsAtPath(entryErr, subPath);
|
|
3078
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), entryErr) : entryErr;
|
|
3079
3087
|
}
|
|
3088
|
+
error = _this2.mergeValidationErrors(error, entryErr);
|
|
3080
3089
|
} else {
|
|
3081
3090
|
var subError = _this2.item["executeValidate"](subPath, elem);
|
|
3082
|
-
|
|
3083
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
3084
|
-
} else if (subError) {
|
|
3085
|
-
error = subError;
|
|
3086
|
-
}
|
|
3091
|
+
error = _this2.mergeValidationErrors(error, subError);
|
|
3087
3092
|
}
|
|
3088
3093
|
});
|
|
3089
3094
|
return error;
|
|
@@ -3149,6 +3154,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3149
3154
|
value: key
|
|
3150
3155
|
}]);
|
|
3151
3156
|
}
|
|
3157
|
+
// Local path in a remote gallery: needs to be uploaded to remote.
|
|
3158
|
+
var uploadRemoteFix = type === "images" ? "images:upload-remote" : "files:upload-remote";
|
|
3159
|
+
return _defineProperty({}, path, [{
|
|
3160
|
+
message: "Expected a remote ".concat(type === "images" ? "image" : "file", ", but got a local path. Use Val tooling (CLI --fix, VS Code extension, or Val Studio) to upload it. Got: ").concat(key),
|
|
3161
|
+
value: key,
|
|
3162
|
+
fixes: [uploadRemoteFix]
|
|
3163
|
+
}]);
|
|
3152
3164
|
} else {
|
|
3153
3165
|
// When remote is disabled, only accept local paths
|
|
3154
3166
|
if (isRemoteUrl) {
|
|
@@ -3442,10 +3454,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3442
3454
|
data: {
|
|
3443
3455
|
layout: "list",
|
|
3444
3456
|
parent: "record",
|
|
3445
|
-
items: Object.entries(src).map(function (
|
|
3446
|
-
var
|
|
3447
|
-
key =
|
|
3448
|
-
val =
|
|
3457
|
+
items: Object.entries(src).map(function (_ref14) {
|
|
3458
|
+
var _ref15 = _slicedToArray(_ref14, 2),
|
|
3459
|
+
key = _ref15[0],
|
|
3460
|
+
val = _ref15[1];
|
|
3449
3461
|
// NB NB: display is actually defined by the user
|
|
3450
3462
|
var _prepare = prepare({
|
|
3451
3463
|
key: key,
|
|
@@ -4907,10 +4919,11 @@ var datetime = function datetime(options) {
|
|
|
4907
4919
|
return new DateTimeSchema(options);
|
|
4908
4920
|
};
|
|
4909
4921
|
|
|
4910
|
-
function router(router,
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4922
|
+
function router(router, keyOrItem, maybeItem) {
|
|
4923
|
+
if (maybeItem) {
|
|
4924
|
+
return new RecordSchema(maybeItem, false, [], router, keyOrItem);
|
|
4925
|
+
}
|
|
4926
|
+
return new RecordSchema(keyOrItem, false, [], router, string());
|
|
4914
4927
|
}
|
|
4915
4928
|
|
|
4916
4929
|
/**
|
|
@@ -5636,10 +5649,11 @@ var getSHA256Hash = function getSHA256Hash(bits) {
|
|
|
5636
5649
|
return createHash().update(bits).digest("hex");
|
|
5637
5650
|
};
|
|
5638
5651
|
|
|
5639
|
-
// Lazily constructed: this module is also evaluated inside the
|
|
5640
|
-
//
|
|
5641
|
-
// has no `TextEncoder` global. `hash()` is never called from
|
|
5642
|
-
// sandbox, so deferring construction avoids a ReferenceError at
|
|
5652
|
+
// Lazily constructed: this module is also evaluated inside the `vm` sandbox
|
|
5653
|
+
// used by loadValModules (when user val modules import @valbuild/core), and
|
|
5654
|
+
// that sandbox has no `TextEncoder` global. `hash()` is never called from
|
|
5655
|
+
// inside the sandbox, so deferring construction avoids a ReferenceError at
|
|
5656
|
+
// import time.
|
|
5643
5657
|
var textEncoder;
|
|
5644
5658
|
function getTextEncoder() {
|
|
5645
5659
|
if (!textEncoder) {
|
|
@@ -222,6 +222,34 @@ var Schema = /*#__PURE__*/function () {
|
|
|
222
222
|
}]);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Merges two sets of validation errors path-wise: errors on the same path are
|
|
228
|
+
* concatenated, not overwritten. Object spread cannot be used for this, since
|
|
229
|
+
* it replaces the array of the colliding path. A record, for example, validates
|
|
230
|
+
* the key and the item on the same path, so both sets must survive.
|
|
231
|
+
*
|
|
232
|
+
* MUTATES! since internal and perf sensitive
|
|
233
|
+
*/
|
|
234
|
+
}, {
|
|
235
|
+
key: "mergeValidationErrors",
|
|
236
|
+
value: function mergeValidationErrors(current, incoming) {
|
|
237
|
+
if (!incoming) {
|
|
238
|
+
return current;
|
|
239
|
+
}
|
|
240
|
+
if (!current) {
|
|
241
|
+
return incoming;
|
|
242
|
+
}
|
|
243
|
+
for (var pathS in incoming) {
|
|
244
|
+
var _path = pathS;
|
|
245
|
+
if (current[_path]) {
|
|
246
|
+
current[_path] = current[_path].concat(incoming[_path]);
|
|
247
|
+
} else {
|
|
248
|
+
current[_path] = incoming[_path];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return current;
|
|
252
|
+
}
|
|
225
253
|
}]);
|
|
226
254
|
}();
|
|
227
255
|
|
|
@@ -1007,11 +1035,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1007
1035
|
src);
|
|
1008
1036
|
} else {
|
|
1009
1037
|
var subError = schema["executeValidate"](subPath, src[_key]);
|
|
1010
|
-
|
|
1011
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1012
|
-
} else if (subError) {
|
|
1013
|
-
error = subError;
|
|
1014
|
-
}
|
|
1038
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1015
1039
|
}
|
|
1016
1040
|
}
|
|
1017
1041
|
return error;
|
|
@@ -1185,7 +1209,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1185
1209
|
if (assertRes.data === null) {
|
|
1186
1210
|
return false;
|
|
1187
1211
|
}
|
|
1188
|
-
var error =
|
|
1212
|
+
var error = false;
|
|
1189
1213
|
for (var _i = 0, _Object$entries = Object.entries(assertRes.data); _i < _Object$entries.length; _i++) {
|
|
1190
1214
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1191
1215
|
idx = _Object$entries$_i[0],
|
|
@@ -1193,12 +1217,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1193
1217
|
var subPath = unsafeCreateSourcePath(path, Number(idx));
|
|
1194
1218
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1195
1219
|
var subError = this.item["executeValidate"](subPath, i);
|
|
1196
|
-
|
|
1197
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
if (Object.keys(error).length === 0) {
|
|
1201
|
-
return false;
|
|
1220
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1202
1221
|
}
|
|
1203
1222
|
return error;
|
|
1204
1223
|
}
|
|
@@ -2981,9 +3000,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2981
3000
|
}]));
|
|
2982
3001
|
}
|
|
2983
3002
|
var routerValidations = this.getRouterValidations(path, src);
|
|
2984
|
-
|
|
2985
|
-
return routerValidations;
|
|
2986
|
-
}
|
|
3003
|
+
error = this.mergeValidationErrors(error, routerValidations);
|
|
2987
3004
|
var _iterator = result._createForOfIteratorHelper(customValidationErrors),
|
|
2988
3005
|
_step;
|
|
2989
3006
|
try {
|
|
@@ -3047,15 +3064,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3047
3064
|
keyError: true
|
|
3048
3065
|
});
|
|
3049
3066
|
});
|
|
3050
|
-
|
|
3051
|
-
if (error[keyPath]) {
|
|
3052
|
-
error[keyPath] = [].concat(_toConsumableArray(error[keyPath]), _toConsumableArray(keyError[keyPath]));
|
|
3053
|
-
} else {
|
|
3054
|
-
error[keyPath] = keyError[keyPath];
|
|
3055
|
-
}
|
|
3056
|
-
} else {
|
|
3057
|
-
error = keyError;
|
|
3058
|
-
}
|
|
3067
|
+
error = _this2.mergeValidationErrors(error, keyError);
|
|
3059
3068
|
}
|
|
3060
3069
|
}
|
|
3061
3070
|
var subPath = createValPathOfItem(path, key);
|
|
@@ -3070,20 +3079,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3070
3079
|
var keyErr = _this2.validateMediaKey(subPath, key);
|
|
3071
3080
|
if (keyErr) {
|
|
3072
3081
|
_this2.markKeyErrorsAtPath(keyErr, subPath);
|
|
3073
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), keyErr) : keyErr;
|
|
3074
3082
|
}
|
|
3083
|
+
error = _this2.mergeValidationErrors(error, keyErr);
|
|
3075
3084
|
var entryErr = _this2.validateMediaEntry(subPath, elem);
|
|
3076
3085
|
if (entryErr) {
|
|
3077
3086
|
_this2.markKeyErrorsAtPath(entryErr, subPath);
|
|
3078
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), entryErr) : entryErr;
|
|
3079
3087
|
}
|
|
3088
|
+
error = _this2.mergeValidationErrors(error, entryErr);
|
|
3080
3089
|
} else {
|
|
3081
3090
|
var subError = _this2.item["executeValidate"](subPath, elem);
|
|
3082
|
-
|
|
3083
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
3084
|
-
} else if (subError) {
|
|
3085
|
-
error = subError;
|
|
3086
|
-
}
|
|
3091
|
+
error = _this2.mergeValidationErrors(error, subError);
|
|
3087
3092
|
}
|
|
3088
3093
|
});
|
|
3089
3094
|
return error;
|
|
@@ -3149,6 +3154,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3149
3154
|
value: key
|
|
3150
3155
|
}]);
|
|
3151
3156
|
}
|
|
3157
|
+
// Local path in a remote gallery: needs to be uploaded to remote.
|
|
3158
|
+
var uploadRemoteFix = type === "images" ? "images:upload-remote" : "files:upload-remote";
|
|
3159
|
+
return _defineProperty({}, path, [{
|
|
3160
|
+
message: "Expected a remote ".concat(type === "images" ? "image" : "file", ", but got a local path. Use Val tooling (CLI --fix, VS Code extension, or Val Studio) to upload it. Got: ").concat(key),
|
|
3161
|
+
value: key,
|
|
3162
|
+
fixes: [uploadRemoteFix]
|
|
3163
|
+
}]);
|
|
3152
3164
|
} else {
|
|
3153
3165
|
// When remote is disabled, only accept local paths
|
|
3154
3166
|
if (isRemoteUrl) {
|
|
@@ -3442,10 +3454,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3442
3454
|
data: {
|
|
3443
3455
|
layout: "list",
|
|
3444
3456
|
parent: "record",
|
|
3445
|
-
items: Object.entries(src).map(function (
|
|
3446
|
-
var
|
|
3447
|
-
key =
|
|
3448
|
-
val =
|
|
3457
|
+
items: Object.entries(src).map(function (_ref14) {
|
|
3458
|
+
var _ref15 = _slicedToArray(_ref14, 2),
|
|
3459
|
+
key = _ref15[0],
|
|
3460
|
+
val = _ref15[1];
|
|
3449
3461
|
// NB NB: display is actually defined by the user
|
|
3450
3462
|
var _prepare = prepare({
|
|
3451
3463
|
key: key,
|
|
@@ -4907,10 +4919,11 @@ var datetime = function datetime(options) {
|
|
|
4907
4919
|
return new DateTimeSchema(options);
|
|
4908
4920
|
};
|
|
4909
4921
|
|
|
4910
|
-
function router(router,
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4922
|
+
function router(router, keyOrItem, maybeItem) {
|
|
4923
|
+
if (maybeItem) {
|
|
4924
|
+
return new RecordSchema(maybeItem, false, [], router, keyOrItem);
|
|
4925
|
+
}
|
|
4926
|
+
return new RecordSchema(keyOrItem, false, [], router, string());
|
|
4914
4927
|
}
|
|
4915
4928
|
|
|
4916
4929
|
/**
|
|
@@ -5636,10 +5649,11 @@ var getSHA256Hash = function getSHA256Hash(bits) {
|
|
|
5636
5649
|
return createHash().update(bits).digest("hex");
|
|
5637
5650
|
};
|
|
5638
5651
|
|
|
5639
|
-
// Lazily constructed: this module is also evaluated inside the
|
|
5640
|
-
//
|
|
5641
|
-
// has no `TextEncoder` global. `hash()` is never called from
|
|
5642
|
-
// sandbox, so deferring construction avoids a ReferenceError at
|
|
5652
|
+
// Lazily constructed: this module is also evaluated inside the `vm` sandbox
|
|
5653
|
+
// used by loadValModules (when user val modules import @valbuild/core), and
|
|
5654
|
+
// that sandbox has no `TextEncoder` global. `hash()` is never called from
|
|
5655
|
+
// inside the sandbox, so deferring construction avoids a ReferenceError at
|
|
5656
|
+
// import time.
|
|
5643
5657
|
var textEncoder;
|
|
5644
5658
|
function getTextEncoder() {
|
|
5645
5659
|
if (!textEncoder) {
|
|
@@ -220,6 +220,34 @@ var Schema = /*#__PURE__*/function () {
|
|
|
220
220
|
}]);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Merges two sets of validation errors path-wise: errors on the same path are
|
|
226
|
+
* concatenated, not overwritten. Object spread cannot be used for this, since
|
|
227
|
+
* it replaces the array of the colliding path. A record, for example, validates
|
|
228
|
+
* the key and the item on the same path, so both sets must survive.
|
|
229
|
+
*
|
|
230
|
+
* MUTATES! since internal and perf sensitive
|
|
231
|
+
*/
|
|
232
|
+
}, {
|
|
233
|
+
key: "mergeValidationErrors",
|
|
234
|
+
value: function mergeValidationErrors(current, incoming) {
|
|
235
|
+
if (!incoming) {
|
|
236
|
+
return current;
|
|
237
|
+
}
|
|
238
|
+
if (!current) {
|
|
239
|
+
return incoming;
|
|
240
|
+
}
|
|
241
|
+
for (var pathS in incoming) {
|
|
242
|
+
var _path = pathS;
|
|
243
|
+
if (current[_path]) {
|
|
244
|
+
current[_path] = current[_path].concat(incoming[_path]);
|
|
245
|
+
} else {
|
|
246
|
+
current[_path] = incoming[_path];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return current;
|
|
250
|
+
}
|
|
223
251
|
}]);
|
|
224
252
|
}();
|
|
225
253
|
|
|
@@ -1005,11 +1033,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1005
1033
|
src);
|
|
1006
1034
|
} else {
|
|
1007
1035
|
var subError = schema["executeValidate"](subPath, src[_key]);
|
|
1008
|
-
|
|
1009
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1010
|
-
} else if (subError) {
|
|
1011
|
-
error = subError;
|
|
1012
|
-
}
|
|
1036
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1013
1037
|
}
|
|
1014
1038
|
}
|
|
1015
1039
|
return error;
|
|
@@ -1183,7 +1207,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1183
1207
|
if (assertRes.data === null) {
|
|
1184
1208
|
return false;
|
|
1185
1209
|
}
|
|
1186
|
-
var error =
|
|
1210
|
+
var error = false;
|
|
1187
1211
|
for (var _i = 0, _Object$entries = Object.entries(assertRes.data); _i < _Object$entries.length; _i++) {
|
|
1188
1212
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1189
1213
|
idx = _Object$entries$_i[0],
|
|
@@ -1191,12 +1215,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1191
1215
|
var subPath = unsafeCreateSourcePath(path, Number(idx));
|
|
1192
1216
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1193
1217
|
var subError = this.item["executeValidate"](subPath, i);
|
|
1194
|
-
|
|
1195
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
if (Object.keys(error).length === 0) {
|
|
1199
|
-
return false;
|
|
1218
|
+
error = this.mergeValidationErrors(error, subError);
|
|
1200
1219
|
}
|
|
1201
1220
|
return error;
|
|
1202
1221
|
}
|
|
@@ -2979,9 +2998,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2979
2998
|
}]));
|
|
2980
2999
|
}
|
|
2981
3000
|
var routerValidations = this.getRouterValidations(path, src);
|
|
2982
|
-
|
|
2983
|
-
return routerValidations;
|
|
2984
|
-
}
|
|
3001
|
+
error = this.mergeValidationErrors(error, routerValidations);
|
|
2985
3002
|
var _iterator = _createForOfIteratorHelper(customValidationErrors),
|
|
2986
3003
|
_step;
|
|
2987
3004
|
try {
|
|
@@ -3045,15 +3062,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3045
3062
|
keyError: true
|
|
3046
3063
|
});
|
|
3047
3064
|
});
|
|
3048
|
-
|
|
3049
|
-
if (error[keyPath]) {
|
|
3050
|
-
error[keyPath] = [].concat(_toConsumableArray(error[keyPath]), _toConsumableArray(keyError[keyPath]));
|
|
3051
|
-
} else {
|
|
3052
|
-
error[keyPath] = keyError[keyPath];
|
|
3053
|
-
}
|
|
3054
|
-
} else {
|
|
3055
|
-
error = keyError;
|
|
3056
|
-
}
|
|
3065
|
+
error = _this2.mergeValidationErrors(error, keyError);
|
|
3057
3066
|
}
|
|
3058
3067
|
}
|
|
3059
3068
|
var subPath = createValPathOfItem(path, key);
|
|
@@ -3068,20 +3077,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3068
3077
|
var keyErr = _this2.validateMediaKey(subPath, key);
|
|
3069
3078
|
if (keyErr) {
|
|
3070
3079
|
_this2.markKeyErrorsAtPath(keyErr, subPath);
|
|
3071
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), keyErr) : keyErr;
|
|
3072
3080
|
}
|
|
3081
|
+
error = _this2.mergeValidationErrors(error, keyErr);
|
|
3073
3082
|
var entryErr = _this2.validateMediaEntry(subPath, elem);
|
|
3074
3083
|
if (entryErr) {
|
|
3075
3084
|
_this2.markKeyErrorsAtPath(entryErr, subPath);
|
|
3076
|
-
error = error ? _objectSpread2(_objectSpread2({}, error), entryErr) : entryErr;
|
|
3077
3085
|
}
|
|
3086
|
+
error = _this2.mergeValidationErrors(error, entryErr);
|
|
3078
3087
|
} else {
|
|
3079
3088
|
var subError = _this2.item["executeValidate"](subPath, elem);
|
|
3080
|
-
|
|
3081
|
-
error = _objectSpread2(_objectSpread2({}, subError), error);
|
|
3082
|
-
} else if (subError) {
|
|
3083
|
-
error = subError;
|
|
3084
|
-
}
|
|
3089
|
+
error = _this2.mergeValidationErrors(error, subError);
|
|
3085
3090
|
}
|
|
3086
3091
|
});
|
|
3087
3092
|
return error;
|
|
@@ -3147,6 +3152,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3147
3152
|
value: key
|
|
3148
3153
|
}]);
|
|
3149
3154
|
}
|
|
3155
|
+
// Local path in a remote gallery: needs to be uploaded to remote.
|
|
3156
|
+
var uploadRemoteFix = type === "images" ? "images:upload-remote" : "files:upload-remote";
|
|
3157
|
+
return _defineProperty({}, path, [{
|
|
3158
|
+
message: "Expected a remote ".concat(type === "images" ? "image" : "file", ", but got a local path. Use Val tooling (CLI --fix, VS Code extension, or Val Studio) to upload it. Got: ").concat(key),
|
|
3159
|
+
value: key,
|
|
3160
|
+
fixes: [uploadRemoteFix]
|
|
3161
|
+
}]);
|
|
3150
3162
|
} else {
|
|
3151
3163
|
// When remote is disabled, only accept local paths
|
|
3152
3164
|
if (isRemoteUrl) {
|
|
@@ -3440,10 +3452,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3440
3452
|
data: {
|
|
3441
3453
|
layout: "list",
|
|
3442
3454
|
parent: "record",
|
|
3443
|
-
items: Object.entries(src).map(function (
|
|
3444
|
-
var
|
|
3445
|
-
key =
|
|
3446
|
-
val =
|
|
3455
|
+
items: Object.entries(src).map(function (_ref14) {
|
|
3456
|
+
var _ref15 = _slicedToArray(_ref14, 2),
|
|
3457
|
+
key = _ref15[0],
|
|
3458
|
+
val = _ref15[1];
|
|
3447
3459
|
// NB NB: display is actually defined by the user
|
|
3448
3460
|
var _prepare = prepare({
|
|
3449
3461
|
key: key,
|
|
@@ -4905,10 +4917,11 @@ var datetime = function datetime(options) {
|
|
|
4905
4917
|
return new DateTimeSchema(options);
|
|
4906
4918
|
};
|
|
4907
4919
|
|
|
4908
|
-
function router(router,
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4920
|
+
function router(router, keyOrItem, maybeItem) {
|
|
4921
|
+
if (maybeItem) {
|
|
4922
|
+
return new RecordSchema(maybeItem, false, [], router, keyOrItem);
|
|
4923
|
+
}
|
|
4924
|
+
return new RecordSchema(keyOrItem, false, [], router, string());
|
|
4912
4925
|
}
|
|
4913
4926
|
|
|
4914
4927
|
/**
|
|
@@ -5634,10 +5647,11 @@ var getSHA256Hash = function getSHA256Hash(bits) {
|
|
|
5634
5647
|
return createHash().update(bits).digest("hex");
|
|
5635
5648
|
};
|
|
5636
5649
|
|
|
5637
|
-
// Lazily constructed: this module is also evaluated inside the
|
|
5638
|
-
//
|
|
5639
|
-
// has no `TextEncoder` global. `hash()` is never called from
|
|
5640
|
-
// sandbox, so deferring construction avoids a ReferenceError at
|
|
5650
|
+
// Lazily constructed: this module is also evaluated inside the `vm` sandbox
|
|
5651
|
+
// used by loadValModules (when user val modules import @valbuild/core), and
|
|
5652
|
+
// that sandbox has no `TextEncoder` global. `hash()` is never called from
|
|
5653
|
+
// inside the sandbox, so deferring construction avoids a ReferenceError at
|
|
5654
|
+
// import time.
|
|
5641
5655
|
var textEncoder;
|
|
5642
5656
|
function getTextEncoder() {
|
|
5643
5657
|
if (!textEncoder) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, g as DEFAULT_VAL_REMOTE_HOST, p as DateSchema, q as DateTimeSchema, F as FATAL_ERROR_TYPES, h as FILE_REF_PROP, j as FILE_REF_SUBTYPE_TAG, o as FileSchema, G as GenericSelector, n as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, t as RichTextSchema, r as RouteSchema, S as Schema, l as StringSchema, U as UnionSchema, V as VAL_EXTENSION, k as derefPatch, u as deserializeSchema, f as extractValModules, v as getSourcePathFromRoute, i as initVal, m as modules } from './index-
|
|
1
|
+
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, g as DEFAULT_VAL_REMOTE_HOST, p as DateSchema, q as DateTimeSchema, F as FATAL_ERROR_TYPES, h as FILE_REF_PROP, j as FILE_REF_SUBTYPE_TAG, o as FileSchema, G as GenericSelector, n as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, t as RichTextSchema, r as RouteSchema, S as Schema, l as StringSchema, U as UnionSchema, V as VAL_EXTENSION, k as derefPatch, u as deserializeSchema, f as extractValModules, v as getSourcePathFromRoute, i as initVal, m as modules } from './index-d152e3e2.esm.js';
|
|
2
2
|
import './result-4bd63123.esm.js';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_valbuildCore = require('../../dist/index-
|
|
5
|
+
var dist_valbuildCore = require('../../dist/index-233a49d6.cjs.dev.js');
|
|
6
6
|
var result = require('../../dist/result-bb1f436e.cjs.dev.js');
|
|
7
7
|
var util = require('../../dist/util-b213092b.cjs.dev.js');
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_valbuildCore = require('../../dist/index-
|
|
5
|
+
var dist_valbuildCore = require('../../dist/index-11f47a61.cjs.prod.js');
|
|
6
6
|
var result = require('../../dist/result-787e35f6.cjs.prod.js');
|
|
7
7
|
var util = require('../../dist/util-030d8a1f.cjs.prod.js');
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-
|
|
2
|
-
export { P as PatchError } from '../../dist/index-
|
|
1
|
+
import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-d152e3e2.esm.js';
|
|
2
|
+
export { P as PatchError } from '../../dist/index-d152e3e2.esm.js';
|
|
3
3
|
import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-4bd63123.esm.js';
|
|
4
4
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
|
5
5
|
|