@valbuild/core 0.82.0 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/index.d.ts +3 -1
- package/dist/declarations/src/{preview.d.ts → render.d.ts} +5 -5
- package/dist/declarations/src/router.d.ts +24 -0
- package/dist/declarations/src/schema/array.d.ts +6 -6
- package/dist/declarations/src/schema/boolean.d.ts +2 -2
- package/dist/declarations/src/schema/date.d.ts +2 -2
- package/dist/declarations/src/schema/file.d.ts +2 -2
- package/dist/declarations/src/schema/image.d.ts +2 -2
- package/dist/declarations/src/schema/index.d.ts +8 -4
- package/dist/declarations/src/schema/keyOf.d.ts +12 -4
- package/dist/declarations/src/schema/literal.d.ts +2 -2
- package/dist/declarations/src/schema/number.d.ts +2 -2
- package/dist/declarations/src/schema/object.d.ts +2 -2
- package/dist/declarations/src/schema/record.d.ts +13 -8
- package/dist/declarations/src/schema/richtext.d.ts +2 -2
- package/dist/declarations/src/schema/string.d.ts +2 -2
- package/dist/declarations/src/schema/union.d.ts +2 -2
- package/dist/{index-bcc230b2.esm.js → index-396ad310.esm.js} +523 -234
- package/dist/{index-74fe6f44.cjs.prod.js → index-a820d34c.cjs.prod.js} +523 -234
- package/dist/{index-5a7e1014.cjs.dev.js → index-f6af10b1.cjs.dev.js} +523 -234
- 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
@@ -189,7 +189,7 @@ var Schema = /*#__PURE__*/function () {
|
|
189
189
|
}
|
190
190
|
return _createClass(Schema, [{
|
191
191
|
key: "executeCustomValidateFunctions",
|
192
|
-
value: function executeCustomValidateFunctions(src, customValidateFunctions) {
|
192
|
+
value: function executeCustomValidateFunctions(src, customValidateFunctions, ctx) {
|
193
193
|
var errors = [];
|
194
194
|
var _iterator = _createForOfIteratorHelper(customValidateFunctions),
|
195
195
|
_step;
|
@@ -197,7 +197,7 @@ var Schema = /*#__PURE__*/function () {
|
|
197
197
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
198
198
|
var customValidateFunction = _step.value;
|
199
199
|
try {
|
200
|
-
var result = customValidateFunction(src);
|
200
|
+
var result = customValidateFunction(src, ctx);
|
201
201
|
if (result) {
|
202
202
|
errors.push({
|
203
203
|
message: result,
|
@@ -403,7 +403,9 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
403
403
|
}, {
|
404
404
|
key: "executeValidate",
|
405
405
|
value: function executeValidate(path, src) {
|
406
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
406
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
407
|
+
path: path
|
408
|
+
});
|
407
409
|
if (this.opt && (src === null || src === undefined)) {
|
408
410
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
409
411
|
}
|
@@ -577,8 +579,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
577
579
|
};
|
578
580
|
}
|
579
581
|
}, {
|
580
|
-
key: "
|
581
|
-
value: function
|
582
|
+
key: "executeRender",
|
583
|
+
value: function executeRender() {
|
582
584
|
return {};
|
583
585
|
}
|
584
586
|
}]);
|
@@ -666,6 +668,170 @@ function unsafeCreateSourcePath(path, itemKey) {
|
|
666
668
|
return "".concat(path).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(itemKey));
|
667
669
|
}
|
668
670
|
|
671
|
+
var StringSchema = /*#__PURE__*/function (_Schema) {
|
672
|
+
function StringSchema(options) {
|
673
|
+
var _this;
|
674
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
675
|
+
var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
676
|
+
var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
677
|
+
_classCallCheck(this, StringSchema);
|
678
|
+
_this = _callSuper(this, StringSchema);
|
679
|
+
_this.options = options;
|
680
|
+
_this.opt = opt;
|
681
|
+
_this.isRaw = isRaw;
|
682
|
+
_this.customValidateFunctions = customValidateFunctions;
|
683
|
+
return _this;
|
684
|
+
}
|
685
|
+
|
686
|
+
/**
|
687
|
+
* @deprecated Use `minLength` instead
|
688
|
+
*/
|
689
|
+
_inherits(StringSchema, _Schema);
|
690
|
+
return _createClass(StringSchema, [{
|
691
|
+
key: "min",
|
692
|
+
value: function min(minLength) {
|
693
|
+
return this.minLength(minLength);
|
694
|
+
}
|
695
|
+
}, {
|
696
|
+
key: "minLength",
|
697
|
+
value: function minLength(_minLength) {
|
698
|
+
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
699
|
+
minLength: _minLength
|
700
|
+
}), this.opt, this.isRaw);
|
701
|
+
}
|
702
|
+
|
703
|
+
/**
|
704
|
+
* @deprecated Use `maxLength` instead
|
705
|
+
*/
|
706
|
+
}, {
|
707
|
+
key: "max",
|
708
|
+
value: function max(maxLength) {
|
709
|
+
return this.maxLength(maxLength);
|
710
|
+
}
|
711
|
+
}, {
|
712
|
+
key: "maxLength",
|
713
|
+
value: function maxLength(_maxLength) {
|
714
|
+
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
715
|
+
maxLength: _maxLength
|
716
|
+
}), this.opt, this.isRaw);
|
717
|
+
}
|
718
|
+
}, {
|
719
|
+
key: "regexp",
|
720
|
+
value: function regexp(_regexp, message) {
|
721
|
+
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
722
|
+
regexp: _regexp,
|
723
|
+
regExpMessage: message
|
724
|
+
}), this.opt, this.isRaw);
|
725
|
+
}
|
726
|
+
}, {
|
727
|
+
key: "validate",
|
728
|
+
value: function validate(validationFunction) {
|
729
|
+
return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions.concat(validationFunction));
|
730
|
+
}
|
731
|
+
}, {
|
732
|
+
key: "executeValidate",
|
733
|
+
value: function executeValidate(path, src) {
|
734
|
+
var _this$options, _this$options2, _this$options3;
|
735
|
+
var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
736
|
+
path: path
|
737
|
+
});
|
738
|
+
if (this.opt && (src === null || src === undefined)) {
|
739
|
+
return errors.length > 0 ? _defineProperty({}, path, errors) : false;
|
740
|
+
}
|
741
|
+
if (typeof src !== "string") {
|
742
|
+
return _defineProperty({}, path, [{
|
743
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
744
|
+
value: src
|
745
|
+
}]);
|
746
|
+
}
|
747
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.maxLength && src.length > this.options.maxLength) {
|
748
|
+
errors.push({
|
749
|
+
message: "Expected string to be at most ".concat(this.options.maxLength, " characters long, got ").concat(src.length),
|
750
|
+
value: src
|
751
|
+
});
|
752
|
+
}
|
753
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.minLength && src.length < this.options.minLength) {
|
754
|
+
errors.push({
|
755
|
+
message: "Expected string to be at least ".concat(this.options.minLength, " characters long, got ").concat(src.length),
|
756
|
+
value: src
|
757
|
+
});
|
758
|
+
}
|
759
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.regexp && !this.options.regexp.test(src)) {
|
760
|
+
errors.push({
|
761
|
+
message: this.options.regExpMessage || "Expected string to match reg exp: ".concat(this.options.regexp.toString(), ", got '").concat(src, "'"),
|
762
|
+
value: src
|
763
|
+
});
|
764
|
+
}
|
765
|
+
if (errors.length > 0) {
|
766
|
+
return _defineProperty({}, path, errors);
|
767
|
+
}
|
768
|
+
return false;
|
769
|
+
}
|
770
|
+
}, {
|
771
|
+
key: "executeAssert",
|
772
|
+
value: function executeAssert(path, src) {
|
773
|
+
if (this.opt && src === null) {
|
774
|
+
return {
|
775
|
+
success: true,
|
776
|
+
data: src
|
777
|
+
};
|
778
|
+
}
|
779
|
+
if (typeof src === "string") {
|
780
|
+
return {
|
781
|
+
success: true,
|
782
|
+
data: src
|
783
|
+
};
|
784
|
+
}
|
785
|
+
return {
|
786
|
+
success: false,
|
787
|
+
errors: _defineProperty({}, path, [{
|
788
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
789
|
+
typeError: true
|
790
|
+
}])
|
791
|
+
};
|
792
|
+
}
|
793
|
+
}, {
|
794
|
+
key: "nullable",
|
795
|
+
value: function nullable() {
|
796
|
+
return new StringSchema(this.options, true, this.isRaw);
|
797
|
+
}
|
798
|
+
}, {
|
799
|
+
key: "raw",
|
800
|
+
value: function raw() {
|
801
|
+
return new StringSchema(this.options, this.opt, true);
|
802
|
+
}
|
803
|
+
}, {
|
804
|
+
key: "executeSerialize",
|
805
|
+
value: function executeSerialize() {
|
806
|
+
var _this$options4, _this$options5, _this$options6, _this$customValidateF, _this$customValidateF2;
|
807
|
+
return {
|
808
|
+
type: "string",
|
809
|
+
options: {
|
810
|
+
maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
|
811
|
+
minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
|
812
|
+
regexp: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.regexp) && {
|
813
|
+
message: this.options.regExpMessage,
|
814
|
+
source: this.options.regexp.source,
|
815
|
+
flags: this.options.regexp.flags
|
816
|
+
},
|
817
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
818
|
+
},
|
819
|
+
opt: this.opt,
|
820
|
+
raw: this.isRaw,
|
821
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
|
822
|
+
};
|
823
|
+
}
|
824
|
+
}, {
|
825
|
+
key: "executeRender",
|
826
|
+
value: function executeRender() {
|
827
|
+
return {};
|
828
|
+
}
|
829
|
+
}]);
|
830
|
+
}(Schema);
|
831
|
+
var string = function string(options) {
|
832
|
+
return new StringSchema(options);
|
833
|
+
};
|
834
|
+
|
669
835
|
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
670
836
|
function ObjectSchema(items) {
|
671
837
|
var _this;
|
@@ -688,7 +854,9 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
688
854
|
key: "executeValidate",
|
689
855
|
value: function executeValidate(path, src) {
|
690
856
|
var error = false;
|
691
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
857
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
858
|
+
path: path
|
859
|
+
});
|
692
860
|
if (this.opt && (src === null || src === undefined)) {
|
693
861
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
694
862
|
}
|
@@ -823,8 +991,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
823
991
|
};
|
824
992
|
}
|
825
993
|
}, {
|
826
|
-
key: "
|
827
|
-
value: function
|
994
|
+
key: "executeRender",
|
995
|
+
value: function executeRender(sourcePath, src) {
|
828
996
|
var res = {};
|
829
997
|
if (src === null) {
|
830
998
|
return res;
|
@@ -835,7 +1003,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
835
1003
|
continue;
|
836
1004
|
}
|
837
1005
|
var subPath = unsafeCreateSourcePath(sourcePath, _key3);
|
838
|
-
var itemResult = this.items[_key3]["
|
1006
|
+
var itemResult = this.items[_key3]["executeRender"](subPath, itemSrc);
|
839
1007
|
for (var keyS in itemResult) {
|
840
1008
|
var _key4 = keyS;
|
841
1009
|
res[_key4] = itemResult[_key4];
|
@@ -848,6 +1016,11 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
848
1016
|
var object = function object(schema) {
|
849
1017
|
return new ObjectSchema(schema);
|
850
1018
|
};
|
1019
|
+
object({
|
1020
|
+
get test() {
|
1021
|
+
return string();
|
1022
|
+
}
|
1023
|
+
});
|
851
1024
|
|
852
1025
|
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
853
1026
|
function ArraySchema(item) {
|
@@ -856,7 +1029,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
856
1029
|
var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
857
1030
|
_classCallCheck(this, ArraySchema);
|
858
1031
|
_this = _callSuper(this, ArraySchema);
|
859
|
-
_defineProperty(_this, "
|
1032
|
+
_defineProperty(_this, "renderInput", null);
|
860
1033
|
_this.item = item;
|
861
1034
|
_this.opt = opt;
|
862
1035
|
_this.customValidateFunctions = customValidateFunctions;
|
@@ -952,8 +1125,8 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
952
1125
|
};
|
953
1126
|
}
|
954
1127
|
}, {
|
955
|
-
key: "
|
956
|
-
value: function
|
1128
|
+
key: "executeRender",
|
1129
|
+
value: function executeRender(sourcePath, src) {
|
957
1130
|
var res = {};
|
958
1131
|
if (src === null) {
|
959
1132
|
return res;
|
@@ -965,16 +1138,16 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
965
1138
|
continue;
|
966
1139
|
}
|
967
1140
|
var subPath = unsafeCreateSourcePath(sourcePath, key);
|
968
|
-
var itemResult = this.item["
|
1141
|
+
var itemResult = this.item["executeRender"](subPath, itemSrc);
|
969
1142
|
for (var keyS in itemResult) {
|
970
1143
|
var _key = keyS;
|
971
1144
|
res[_key] = itemResult[_key];
|
972
1145
|
}
|
973
1146
|
}
|
974
|
-
if (this.
|
975
|
-
var _this$
|
976
|
-
|
977
|
-
layout = _this$
|
1147
|
+
if (this.renderInput) {
|
1148
|
+
var _this$renderInput = this.renderInput,
|
1149
|
+
select = _this$renderInput.select,
|
1150
|
+
layout = _this$renderInput.layout;
|
978
1151
|
if (layout !== "list") {
|
979
1152
|
res[sourcePath] = {
|
980
1153
|
status: "error",
|
@@ -989,12 +1162,12 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
989
1162
|
parent: "array",
|
990
1163
|
items: src.map(function (val) {
|
991
1164
|
// NB NB: display is actually defined by the user
|
992
|
-
var
|
1165
|
+
var _select = select({
|
993
1166
|
val: val
|
994
1167
|
}),
|
995
|
-
title =
|
996
|
-
subtitle =
|
997
|
-
image =
|
1168
|
+
title = _select.title,
|
1169
|
+
subtitle = _select.subtitle,
|
1170
|
+
image = _select.image;
|
998
1171
|
return {
|
999
1172
|
title: title,
|
1000
1173
|
subtitle: subtitle,
|
@@ -1013,9 +1186,9 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
1013
1186
|
return res;
|
1014
1187
|
}
|
1015
1188
|
}, {
|
1016
|
-
key: "
|
1017
|
-
value: function
|
1018
|
-
this.
|
1189
|
+
key: "render",
|
1190
|
+
value: function render(input) {
|
1191
|
+
this.renderInput = input;
|
1019
1192
|
return this;
|
1020
1193
|
}
|
1021
1194
|
}]);
|
@@ -1045,7 +1218,9 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
|
1045
1218
|
}, {
|
1046
1219
|
key: "executeValidate",
|
1047
1220
|
value: function executeValidate(path, src) {
|
1048
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
1221
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
1222
|
+
path: path
|
1223
|
+
});
|
1049
1224
|
if (this.opt && (src === null || src === undefined)) {
|
1050
1225
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
1051
1226
|
}
|
@@ -1115,8 +1290,8 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
|
1115
1290
|
};
|
1116
1291
|
}
|
1117
1292
|
}, {
|
1118
|
-
key: "
|
1119
|
-
value: function
|
1293
|
+
key: "executeRender",
|
1294
|
+
value: function executeRender() {
|
1120
1295
|
return {};
|
1121
1296
|
}
|
1122
1297
|
}]);
|
@@ -1147,7 +1322,9 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
1147
1322
|
}, {
|
1148
1323
|
key: "executeValidate",
|
1149
1324
|
value: function executeValidate(path, src) {
|
1150
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
1325
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
1326
|
+
path: path
|
1327
|
+
});
|
1151
1328
|
var unknownSrc = src;
|
1152
1329
|
if (this.opt && unknownSrc === null) {
|
1153
1330
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
@@ -1462,8 +1639,8 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
1462
1639
|
};
|
1463
1640
|
}
|
1464
1641
|
}, {
|
1465
|
-
key: "
|
1466
|
-
value: function
|
1642
|
+
key: "executeRender",
|
1643
|
+
value: function executeRender(sourcePath, src) {
|
1467
1644
|
var res = {};
|
1468
1645
|
if (src === null) {
|
1469
1646
|
return res;
|
@@ -1485,7 +1662,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
1485
1662
|
return false;
|
1486
1663
|
});
|
1487
1664
|
if (thisSchema) {
|
1488
|
-
var itemResult = thisSchema["
|
1665
|
+
var itemResult = thisSchema["executeRender"](sourcePath, src);
|
1489
1666
|
for (var keyS in itemResult) {
|
1490
1667
|
var _key3 = keyS;
|
1491
1668
|
res[_key3] = itemResult[_key3];
|
@@ -1540,7 +1717,9 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
1540
1717
|
}, {
|
1541
1718
|
key: "executeValidate",
|
1542
1719
|
value: function executeValidate(path, src) {
|
1543
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
1720
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
1721
|
+
path: path
|
1722
|
+
});
|
1544
1723
|
if (this.opt && (src === null || src === undefined)) {
|
1545
1724
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
1546
1725
|
}
|
@@ -1722,8 +1901,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
1722
1901
|
};
|
1723
1902
|
}
|
1724
1903
|
}, {
|
1725
|
-
key: "
|
1726
|
-
value: function
|
1904
|
+
key: "executeRender",
|
1905
|
+
value: function executeRender() {
|
1727
1906
|
return {};
|
1728
1907
|
}
|
1729
1908
|
}]);
|
@@ -1767,7 +1946,9 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
|
1767
1946
|
}, {
|
1768
1947
|
key: "executeValidate",
|
1769
1948
|
value: function executeValidate(path, src) {
|
1770
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
1949
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
1950
|
+
path: path
|
1951
|
+
});
|
1771
1952
|
var assertRes = this.executeAssert(path, src);
|
1772
1953
|
if (!assertRes.success) {
|
1773
1954
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : assertRes.errors;
|
@@ -2180,8 +2361,8 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
|
2180
2361
|
};
|
2181
2362
|
}
|
2182
2363
|
}, {
|
2183
|
-
key: "
|
2184
|
-
value: function
|
2364
|
+
key: "executeRender",
|
2365
|
+
value: function executeRender() {
|
2185
2366
|
return {};
|
2186
2367
|
}
|
2187
2368
|
}]);
|
@@ -2195,12 +2376,14 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2195
2376
|
var _this;
|
2196
2377
|
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2197
2378
|
var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
2379
|
+
var currentRouter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
2198
2380
|
_classCallCheck(this, RecordSchema);
|
2199
2381
|
_this = _callSuper(this, RecordSchema);
|
2200
|
-
_defineProperty(_this, "
|
2382
|
+
_defineProperty(_this, "renderInput", null);
|
2201
2383
|
_this.item = item;
|
2202
2384
|
_this.opt = opt;
|
2203
2385
|
_this.customValidateFunctions = customValidateFunctions;
|
2386
|
+
_this.currentRouter = currentRouter;
|
2204
2387
|
return _this;
|
2205
2388
|
}
|
2206
2389
|
_inherits(RecordSchema, _Schema);
|
@@ -2214,7 +2397,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2214
2397
|
value: function executeValidate(path, src) {
|
2215
2398
|
var _this2 = this;
|
2216
2399
|
var error = false;
|
2217
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
2400
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
2401
|
+
path: path
|
2402
|
+
});
|
2218
2403
|
if (this.opt && (src === null || src === undefined)) {
|
2219
2404
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
2220
2405
|
}
|
@@ -2233,6 +2418,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2233
2418
|
message: "Expected 'object', got 'array'"
|
2234
2419
|
}]));
|
2235
2420
|
}
|
2421
|
+
var routerValidations = this.getRouterValidations(path, src);
|
2422
|
+
if (routerValidations) {
|
2423
|
+
return routerValidations;
|
2424
|
+
}
|
2236
2425
|
var _iterator = _createForOfIteratorHelper(customValidationErrors),
|
2237
2426
|
_step;
|
2238
2427
|
try {
|
@@ -2302,20 +2491,68 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2302
2491
|
value: function nullable() {
|
2303
2492
|
return new RecordSchema(this.item, true);
|
2304
2493
|
}
|
2494
|
+
}, {
|
2495
|
+
key: "router",
|
2496
|
+
value: function router(_router) {
|
2497
|
+
return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router);
|
2498
|
+
}
|
2499
|
+
}, {
|
2500
|
+
key: "getRouterValidations",
|
2501
|
+
value: function getRouterValidations(path, src) {
|
2502
|
+
if (!this.currentRouter) {
|
2503
|
+
return false;
|
2504
|
+
}
|
2505
|
+
if (src === null) {
|
2506
|
+
return false;
|
2507
|
+
}
|
2508
|
+
var _splitModuleFilePathA = splitModuleFilePathAndModulePath(path),
|
2509
|
+
_splitModuleFilePathA2 = _slicedToArray(_splitModuleFilePathA, 2),
|
2510
|
+
moduleFilePath = _splitModuleFilePathA2[0],
|
2511
|
+
modulePath = _splitModuleFilePathA2[1];
|
2512
|
+
if (modulePath) {
|
2513
|
+
return _defineProperty({}, path, [{
|
2514
|
+
message: "This field was configured as a router, but it is not defined at the root of the module",
|
2515
|
+
schemaError: true
|
2516
|
+
}]);
|
2517
|
+
}
|
2518
|
+
var routerValidations = this.currentRouter.validate(moduleFilePath, Object.keys(src));
|
2519
|
+
if (routerValidations.length > 0) {
|
2520
|
+
return Object.fromEntries(routerValidations.map(function (validation) {
|
2521
|
+
if (!validation.error.urlPath) {
|
2522
|
+
return [path, [{
|
2523
|
+
message: "Router validation error: ".concat(validation.error.message, " has no url path"),
|
2524
|
+
schemaError: true
|
2525
|
+
}]];
|
2526
|
+
}
|
2527
|
+
var subPath = createValPathOfItem(path, validation.error.urlPath);
|
2528
|
+
if (!subPath) {
|
2529
|
+
return [path, [{
|
2530
|
+
message: "Could not create path for router validation error",
|
2531
|
+
schemaError: true
|
2532
|
+
}]];
|
2533
|
+
}
|
2534
|
+
return [subPath, [{
|
2535
|
+
message: validation.error.message
|
2536
|
+
}]];
|
2537
|
+
}));
|
2538
|
+
}
|
2539
|
+
return false;
|
2540
|
+
}
|
2305
2541
|
}, {
|
2306
2542
|
key: "executeSerialize",
|
2307
2543
|
value: function executeSerialize() {
|
2308
|
-
var _this$customValidateF;
|
2544
|
+
var _this$currentRouter, _this$customValidateF;
|
2309
2545
|
return {
|
2310
2546
|
type: "record",
|
2311
2547
|
item: this.item["executeSerialize"](),
|
2312
2548
|
opt: this.opt,
|
2549
|
+
router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
|
2313
2550
|
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
2314
2551
|
};
|
2315
2552
|
}
|
2316
2553
|
}, {
|
2317
|
-
key: "
|
2318
|
-
value: function
|
2554
|
+
key: "executeRender",
|
2555
|
+
value: function executeRender(sourcePath, src) {
|
2319
2556
|
var res = {};
|
2320
2557
|
if (src === null) {
|
2321
2558
|
return res;
|
@@ -2326,16 +2563,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2326
2563
|
continue;
|
2327
2564
|
}
|
2328
2565
|
var subPath = unsafeCreateSourcePath(sourcePath, key);
|
2329
|
-
var itemResult = this.item["
|
2566
|
+
var itemResult = this.item["executeRender"](subPath, itemSrc);
|
2330
2567
|
for (var keyS in itemResult) {
|
2331
2568
|
var _key = keyS;
|
2332
2569
|
res[_key] = itemResult[_key];
|
2333
2570
|
}
|
2334
2571
|
}
|
2335
|
-
if (this.
|
2336
|
-
var _this$
|
2337
|
-
prepare = _this$
|
2338
|
-
layout = _this$
|
2572
|
+
if (this.renderInput) {
|
2573
|
+
var _this$renderInput = this.renderInput,
|
2574
|
+
prepare = _this$renderInput.select,
|
2575
|
+
layout = _this$renderInput.layout;
|
2339
2576
|
if (layout !== "list") {
|
2340
2577
|
res[sourcePath] = {
|
2341
2578
|
status: "error",
|
@@ -2348,10 +2585,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2348
2585
|
data: {
|
2349
2586
|
layout: "list",
|
2350
2587
|
parent: "record",
|
2351
|
-
items: Object.entries(src).map(function (
|
2352
|
-
var
|
2353
|
-
key =
|
2354
|
-
val =
|
2588
|
+
items: Object.entries(src).map(function (_ref8) {
|
2589
|
+
var _ref9 = _slicedToArray(_ref8, 2),
|
2590
|
+
key = _ref9[0],
|
2591
|
+
val = _ref9[1];
|
2355
2592
|
// NB NB: display is actually defined by the user
|
2356
2593
|
var _prepare = prepare({
|
2357
2594
|
key: key,
|
@@ -2378,9 +2615,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
2378
2615
|
return res;
|
2379
2616
|
}
|
2380
2617
|
}, {
|
2381
|
-
key: "
|
2382
|
-
value: function
|
2383
|
-
this.
|
2618
|
+
key: "render",
|
2619
|
+
value: function render(input) {
|
2620
|
+
this.renderInput = input;
|
2384
2621
|
return this;
|
2385
2622
|
}
|
2386
2623
|
}]);
|
@@ -2911,7 +3148,9 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
2911
3148
|
key: "executeValidate",
|
2912
3149
|
value: function executeValidate(path, src) {
|
2913
3150
|
var _this$options, _this$options2;
|
2914
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
3151
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
3152
|
+
path: path
|
3153
|
+
});
|
2915
3154
|
if (this.opt && (src === null || src === undefined)) {
|
2916
3155
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
2917
3156
|
}
|
@@ -3001,8 +3240,8 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
3001
3240
|
};
|
3002
3241
|
}
|
3003
3242
|
}, {
|
3004
|
-
key: "
|
3005
|
-
value: function
|
3243
|
+
key: "executeRender",
|
3244
|
+
value: function executeRender() {
|
3006
3245
|
return {};
|
3007
3246
|
}
|
3008
3247
|
}]);
|
@@ -3011,168 +3250,6 @@ var number = function number(options) {
|
|
3011
3250
|
return new NumberSchema(options);
|
3012
3251
|
};
|
3013
3252
|
|
3014
|
-
var StringSchema = /*#__PURE__*/function (_Schema) {
|
3015
|
-
function StringSchema(options) {
|
3016
|
-
var _this;
|
3017
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
3018
|
-
var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
3019
|
-
var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
3020
|
-
_classCallCheck(this, StringSchema);
|
3021
|
-
_this = _callSuper(this, StringSchema);
|
3022
|
-
_this.options = options;
|
3023
|
-
_this.opt = opt;
|
3024
|
-
_this.isRaw = isRaw;
|
3025
|
-
_this.customValidateFunctions = customValidateFunctions;
|
3026
|
-
return _this;
|
3027
|
-
}
|
3028
|
-
|
3029
|
-
/**
|
3030
|
-
* @deprecated Use `minLength` instead
|
3031
|
-
*/
|
3032
|
-
_inherits(StringSchema, _Schema);
|
3033
|
-
return _createClass(StringSchema, [{
|
3034
|
-
key: "min",
|
3035
|
-
value: function min(minLength) {
|
3036
|
-
return this.minLength(minLength);
|
3037
|
-
}
|
3038
|
-
}, {
|
3039
|
-
key: "minLength",
|
3040
|
-
value: function minLength(_minLength) {
|
3041
|
-
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
3042
|
-
minLength: _minLength
|
3043
|
-
}), this.opt, this.isRaw);
|
3044
|
-
}
|
3045
|
-
|
3046
|
-
/**
|
3047
|
-
* @deprecated Use `maxLength` instead
|
3048
|
-
*/
|
3049
|
-
}, {
|
3050
|
-
key: "max",
|
3051
|
-
value: function max(maxLength) {
|
3052
|
-
return this.maxLength(maxLength);
|
3053
|
-
}
|
3054
|
-
}, {
|
3055
|
-
key: "maxLength",
|
3056
|
-
value: function maxLength(_maxLength) {
|
3057
|
-
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
3058
|
-
maxLength: _maxLength
|
3059
|
-
}), this.opt, this.isRaw);
|
3060
|
-
}
|
3061
|
-
}, {
|
3062
|
-
key: "regexp",
|
3063
|
-
value: function regexp(_regexp, message) {
|
3064
|
-
return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
3065
|
-
regexp: _regexp,
|
3066
|
-
regExpMessage: message
|
3067
|
-
}), this.opt, this.isRaw);
|
3068
|
-
}
|
3069
|
-
}, {
|
3070
|
-
key: "validate",
|
3071
|
-
value: function validate(validationFunction) {
|
3072
|
-
return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions.concat(validationFunction));
|
3073
|
-
}
|
3074
|
-
}, {
|
3075
|
-
key: "executeValidate",
|
3076
|
-
value: function executeValidate(path, src) {
|
3077
|
-
var _this$options, _this$options2, _this$options3;
|
3078
|
-
var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
|
3079
|
-
if (this.opt && (src === null || src === undefined)) {
|
3080
|
-
return errors.length > 0 ? _defineProperty({}, path, errors) : false;
|
3081
|
-
}
|
3082
|
-
if (typeof src !== "string") {
|
3083
|
-
return _defineProperty({}, path, [{
|
3084
|
-
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
3085
|
-
value: src
|
3086
|
-
}]);
|
3087
|
-
}
|
3088
|
-
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.maxLength && src.length > this.options.maxLength) {
|
3089
|
-
errors.push({
|
3090
|
-
message: "Expected string to be at most ".concat(this.options.maxLength, " characters long, got ").concat(src.length),
|
3091
|
-
value: src
|
3092
|
-
});
|
3093
|
-
}
|
3094
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.minLength && src.length < this.options.minLength) {
|
3095
|
-
errors.push({
|
3096
|
-
message: "Expected string to be at least ".concat(this.options.minLength, " characters long, got ").concat(src.length),
|
3097
|
-
value: src
|
3098
|
-
});
|
3099
|
-
}
|
3100
|
-
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.regexp && !this.options.regexp.test(src)) {
|
3101
|
-
errors.push({
|
3102
|
-
message: this.options.regExpMessage || "Expected string to match reg exp: ".concat(this.options.regexp.toString(), ", got '").concat(src, "'"),
|
3103
|
-
value: src
|
3104
|
-
});
|
3105
|
-
}
|
3106
|
-
if (errors.length > 0) {
|
3107
|
-
return _defineProperty({}, path, errors);
|
3108
|
-
}
|
3109
|
-
return false;
|
3110
|
-
}
|
3111
|
-
}, {
|
3112
|
-
key: "executeAssert",
|
3113
|
-
value: function executeAssert(path, src) {
|
3114
|
-
if (this.opt && src === null) {
|
3115
|
-
return {
|
3116
|
-
success: true,
|
3117
|
-
data: src
|
3118
|
-
};
|
3119
|
-
}
|
3120
|
-
if (typeof src === "string") {
|
3121
|
-
return {
|
3122
|
-
success: true,
|
3123
|
-
data: src
|
3124
|
-
};
|
3125
|
-
}
|
3126
|
-
return {
|
3127
|
-
success: false,
|
3128
|
-
errors: _defineProperty({}, path, [{
|
3129
|
-
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
3130
|
-
typeError: true
|
3131
|
-
}])
|
3132
|
-
};
|
3133
|
-
}
|
3134
|
-
}, {
|
3135
|
-
key: "nullable",
|
3136
|
-
value: function nullable() {
|
3137
|
-
return new StringSchema(this.options, true, this.isRaw);
|
3138
|
-
}
|
3139
|
-
}, {
|
3140
|
-
key: "raw",
|
3141
|
-
value: function raw() {
|
3142
|
-
return new StringSchema(this.options, this.opt, true);
|
3143
|
-
}
|
3144
|
-
}, {
|
3145
|
-
key: "executeSerialize",
|
3146
|
-
value: function executeSerialize() {
|
3147
|
-
var _this$options4, _this$options5, _this$options6, _this$customValidateF, _this$customValidateF2;
|
3148
|
-
return {
|
3149
|
-
type: "string",
|
3150
|
-
options: {
|
3151
|
-
maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
|
3152
|
-
minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
|
3153
|
-
regexp: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.regexp) && {
|
3154
|
-
message: this.options.regExpMessage,
|
3155
|
-
source: this.options.regexp.source,
|
3156
|
-
flags: this.options.regexp.flags
|
3157
|
-
},
|
3158
|
-
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
3159
|
-
},
|
3160
|
-
opt: this.opt,
|
3161
|
-
raw: this.isRaw,
|
3162
|
-
customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
|
3163
|
-
};
|
3164
|
-
}
|
3165
|
-
}, {
|
3166
|
-
key: "executePreview",
|
3167
|
-
value: function executePreview() {
|
3168
|
-
return {};
|
3169
|
-
}
|
3170
|
-
}]);
|
3171
|
-
}(Schema);
|
3172
|
-
var string = function string(options) {
|
3173
|
-
return new StringSchema(options);
|
3174
|
-
};
|
3175
|
-
|
3176
3253
|
var BooleanSchema = /*#__PURE__*/function (_Schema) {
|
3177
3254
|
function BooleanSchema() {
|
3178
3255
|
var _this;
|
@@ -3252,8 +3329,8 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
|
|
3252
3329
|
};
|
3253
3330
|
}
|
3254
3331
|
}, {
|
3255
|
-
key: "
|
3256
|
-
value: function
|
3332
|
+
key: "executeRender",
|
3333
|
+
value: function executeRender() {
|
3257
3334
|
return {};
|
3258
3335
|
}
|
3259
3336
|
}]);
|
@@ -3284,7 +3361,9 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3284
3361
|
}, {
|
3285
3362
|
key: "executeValidate",
|
3286
3363
|
value: function executeValidate(path, src) {
|
3287
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions
|
3364
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
3365
|
+
path: path
|
3366
|
+
});
|
3288
3367
|
if (this.opt && (src === null || src === undefined)) {
|
3289
3368
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
3290
3369
|
}
|
@@ -3296,7 +3375,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3296
3375
|
var serializedSchema = this.schema;
|
3297
3376
|
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
3298
3377
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
3299
|
-
|
3378
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3379
|
+
message: "Schema in keyOf must be an 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'")
|
3300
3380
|
}]));
|
3301
3381
|
}
|
3302
3382
|
if (serializedSchema.opt && (src === null || src === undefined)) {
|
@@ -3308,7 +3388,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3308
3388
|
}]));
|
3309
3389
|
}
|
3310
3390
|
if (serializedSchema.type === "object") {
|
3311
|
-
var keys =
|
3391
|
+
var keys = serializedSchema.keys;
|
3312
3392
|
if (!keys.includes(src)) {
|
3313
3393
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
3314
3394
|
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
|
@@ -3368,7 +3448,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3368
3448
|
return {
|
3369
3449
|
success: false,
|
3370
3450
|
errors: _defineProperty({}, path, [{
|
3371
|
-
|
3451
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3452
|
+
message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'"),
|
3372
3453
|
typeError: true
|
3373
3454
|
}])
|
3374
3455
|
};
|
@@ -3386,7 +3467,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3386
3467
|
// and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
|
3387
3468
|
// missing one would lead to a runtime error. At least this is what we are thinking currently.
|
3388
3469
|
if (serializedSchema.type === "object") {
|
3389
|
-
var keys =
|
3470
|
+
var keys = serializedSchema.keys;
|
3390
3471
|
if (!keys.includes(src)) {
|
3391
3472
|
return {
|
3392
3473
|
success: false,
|
@@ -3425,10 +3506,11 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3425
3506
|
values = "string";
|
3426
3507
|
break;
|
3427
3508
|
case "object":
|
3428
|
-
values =
|
3509
|
+
values = serializedSchema.keys;
|
3429
3510
|
break;
|
3430
3511
|
default:
|
3431
|
-
throw new Error(
|
3512
|
+
throw new Error(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3513
|
+
"Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type || "unknown", "'"));
|
3432
3514
|
}
|
3433
3515
|
return {
|
3434
3516
|
type: "keyOf",
|
@@ -3440,15 +3522,34 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
3440
3522
|
};
|
3441
3523
|
}
|
3442
3524
|
}, {
|
3443
|
-
key: "
|
3444
|
-
value: function
|
3525
|
+
key: "executeRender",
|
3526
|
+
value: function executeRender() {
|
3445
3527
|
return {};
|
3446
3528
|
}
|
3447
3529
|
}]);
|
3448
3530
|
}(Schema);
|
3449
3531
|
var keyOf = function keyOf(valModule) {
|
3450
|
-
var
|
3451
|
-
|
3532
|
+
var refSchema = valModule === null || valModule === void 0 ? void 0 : valModule[GetSchema];
|
3533
|
+
var serializedRefSchema = undefined;
|
3534
|
+
if (refSchema instanceof ObjectSchema) {
|
3535
|
+
var keys = [];
|
3536
|
+
try {
|
3537
|
+
keys = Object.keys((refSchema === null || refSchema === void 0 ? void 0 : refSchema["items"]) || {});
|
3538
|
+
} catch (e) {
|
3539
|
+
// ignore this error here
|
3540
|
+
}
|
3541
|
+
serializedRefSchema = {
|
3542
|
+
type: "object",
|
3543
|
+
keys: keys,
|
3544
|
+
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
3545
|
+
};
|
3546
|
+
} else if (refSchema instanceof RecordSchema) {
|
3547
|
+
serializedRefSchema = {
|
3548
|
+
type: "record",
|
3549
|
+
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
3550
|
+
};
|
3551
|
+
}
|
3552
|
+
return new KeyOfSchema(serializedRefSchema, getValPath(valModule));
|
3452
3553
|
};
|
3453
3554
|
|
3454
3555
|
var DateSchema = /*#__PURE__*/function (_Schema) {
|
@@ -3583,8 +3684,8 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
|
|
3583
3684
|
};
|
3584
3685
|
}
|
3585
3686
|
}, {
|
3586
|
-
key: "
|
3587
|
-
value: function
|
3687
|
+
key: "executeRender",
|
3688
|
+
value: function executeRender() {
|
3588
3689
|
return {};
|
3589
3690
|
}
|
3590
3691
|
}]);
|
@@ -5087,6 +5188,193 @@ function deserializeSchema(serialized) {
|
|
5087
5188
|
}
|
5088
5189
|
}
|
5089
5190
|
|
5191
|
+
// Helper function to validate a URL path against a route pattern
|
5192
|
+
function validateUrlAgainstPattern(urlPath, routePattern) {
|
5193
|
+
// Remove leading slash and split URL path
|
5194
|
+
var urlSegments = urlPath.startsWith("/") ? urlPath.slice(1).split("/") : urlPath.split("/");
|
5195
|
+
|
5196
|
+
// Handle empty patterns (root route)
|
5197
|
+
if (routePattern.length === 0) {
|
5198
|
+
return {
|
5199
|
+
isValid: urlSegments.length === 0 || urlSegments.length === 1 && urlSegments[0] === "",
|
5200
|
+
expectedPath: "/"
|
5201
|
+
};
|
5202
|
+
}
|
5203
|
+
|
5204
|
+
// Check if segment counts match (accounting for optional segments and catch-all)
|
5205
|
+
var minSegments = 0;
|
5206
|
+
var maxSegments = 0;
|
5207
|
+
var hasCatchAll = false;
|
5208
|
+
var catchAllIndex = -1;
|
5209
|
+
for (var i = 0; i < routePattern.length; i++) {
|
5210
|
+
var segment = routePattern[i];
|
5211
|
+
if (segment.startsWith("[[") && segment.endsWith("]]")) {
|
5212
|
+
// Optional catch-all segment
|
5213
|
+
hasCatchAll = true;
|
5214
|
+
catchAllIndex = i;
|
5215
|
+
maxSegments = Infinity;
|
5216
|
+
} else if (segment.startsWith("[...") && segment.endsWith("]")) {
|
5217
|
+
// Required catch-all segment
|
5218
|
+
hasCatchAll = true;
|
5219
|
+
catchAllIndex = i;
|
5220
|
+
minSegments++;
|
5221
|
+
maxSegments = Infinity;
|
5222
|
+
} else if (segment.startsWith("[[") && segment.endsWith("]")) {
|
5223
|
+
// Optional segment
|
5224
|
+
maxSegments++;
|
5225
|
+
} else if (segment.startsWith("[") && segment.endsWith("]")) {
|
5226
|
+
// Required segment
|
5227
|
+
minSegments++;
|
5228
|
+
maxSegments++;
|
5229
|
+
} else {
|
5230
|
+
// Static segment
|
5231
|
+
minSegments++;
|
5232
|
+
maxSegments++;
|
5233
|
+
}
|
5234
|
+
}
|
5235
|
+
|
5236
|
+
// Check segment count
|
5237
|
+
if (urlSegments.length < minSegments || !hasCatchAll && urlSegments.length > maxSegments) {
|
5238
|
+
var expectedSegments = routePattern.map(function (seg) {
|
5239
|
+
if (seg.startsWith("[[") && seg.endsWith("]]")) {
|
5240
|
+
return "[optional:".concat(seg.slice(2, -2), "]");
|
5241
|
+
} else if (seg.startsWith("[...") && seg.endsWith("]")) {
|
5242
|
+
return "[...".concat(seg.slice(4, -1), "]");
|
5243
|
+
} else if (seg.startsWith("[[") && seg.endsWith("]")) {
|
5244
|
+
return "[optional:".concat(seg.slice(2, -1), "]");
|
5245
|
+
} else if (seg.startsWith("[") && seg.endsWith("]")) {
|
5246
|
+
return "[".concat(seg.slice(1, -1), "]");
|
5247
|
+
}
|
5248
|
+
return seg;
|
5249
|
+
}).join("/");
|
5250
|
+
return {
|
5251
|
+
isValid: false,
|
5252
|
+
expectedPath: "/".concat(expectedSegments)
|
5253
|
+
};
|
5254
|
+
}
|
5255
|
+
|
5256
|
+
// Validate each segment up to the catch-all or the end of the pattern
|
5257
|
+
var segmentsToValidate = hasCatchAll ? catchAllIndex : routePattern.length;
|
5258
|
+
for (var _i = 0; _i < segmentsToValidate; _i++) {
|
5259
|
+
var patternSegment = routePattern[_i];
|
5260
|
+
var urlSegment = urlSegments[_i];
|
5261
|
+
|
5262
|
+
// Handle optional segments
|
5263
|
+
if (patternSegment.startsWith("[[") && patternSegment.endsWith("]]")) {
|
5264
|
+
// Optional segment - can be empty or match
|
5265
|
+
if (urlSegment !== "" && urlSegment !== undefined) {
|
5266
|
+
// If provided, validate it's not empty
|
5267
|
+
if (urlSegment === "") {
|
5268
|
+
return {
|
5269
|
+
isValid: false,
|
5270
|
+
expectedPath: "/".concat(routePattern.join("/"))
|
5271
|
+
};
|
5272
|
+
}
|
5273
|
+
}
|
5274
|
+
} else if (patternSegment.startsWith("[") && patternSegment.endsWith("]")) {
|
5275
|
+
// Required dynamic segment - just check it's not empty
|
5276
|
+
if (urlSegment === "" || urlSegment === undefined) {
|
5277
|
+
return {
|
5278
|
+
isValid: false,
|
5279
|
+
expectedPath: "/".concat(routePattern.join("/"))
|
5280
|
+
};
|
5281
|
+
}
|
5282
|
+
} else {
|
5283
|
+
// Static segment - must match exactly
|
5284
|
+
if (patternSegment !== urlSegment) {
|
5285
|
+
return {
|
5286
|
+
isValid: false,
|
5287
|
+
expectedPath: "/".concat(routePattern.join("/"))
|
5288
|
+
};
|
5289
|
+
}
|
5290
|
+
}
|
5291
|
+
}
|
5292
|
+
return {
|
5293
|
+
isValid: true
|
5294
|
+
};
|
5295
|
+
}
|
5296
|
+
|
5297
|
+
// This router should not be in core package
|
5298
|
+
var nextAppRouter = {
|
5299
|
+
getRouterId: function getRouterId() {
|
5300
|
+
return "next-app-router";
|
5301
|
+
},
|
5302
|
+
validate: function validate(moduleFilePath, urlPaths) {
|
5303
|
+
var routePattern = parseNextJsRoutePattern(moduleFilePath);
|
5304
|
+
var errors = [];
|
5305
|
+
var _iterator = _createForOfIteratorHelper(urlPaths),
|
5306
|
+
_step;
|
5307
|
+
try {
|
5308
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
5309
|
+
var urlPath = _step.value;
|
5310
|
+
var validation = validateUrlAgainstPattern(urlPath, routePattern);
|
5311
|
+
if (!validation.isValid) {
|
5312
|
+
errors.push({
|
5313
|
+
error: {
|
5314
|
+
message: "URL path \"".concat(urlPath, "\" does not match the route pattern for \"").concat(moduleFilePath, "\""),
|
5315
|
+
urlPath: urlPath,
|
5316
|
+
expectedPath: validation.expectedPath || null
|
5317
|
+
}
|
5318
|
+
});
|
5319
|
+
}
|
5320
|
+
}
|
5321
|
+
} catch (err) {
|
5322
|
+
_iterator.e(err);
|
5323
|
+
} finally {
|
5324
|
+
_iterator.f();
|
5325
|
+
}
|
5326
|
+
return errors;
|
5327
|
+
}
|
5328
|
+
};
|
5329
|
+
|
5330
|
+
/**
|
5331
|
+
* Parse Next.js route pattern from file path
|
5332
|
+
* Support multiple Next.js app directory structures:
|
5333
|
+
* - /app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
|
5334
|
+
* - /src/app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
|
5335
|
+
* - /pages/blogs/[blog].tsx -> ["blogs", "[blog]"] (Pages Router)
|
5336
|
+
* - /app/(group)/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"] (with groups)
|
5337
|
+
* - /app/(.)feed/page.val.ts -> ["feed"] (interception route)
|
5338
|
+
* - /app/(..)(dashboard)/feed/page.val.ts -> ["feed"] (interception route)
|
5339
|
+
*/
|
5340
|
+
function parseNextJsRoutePattern(moduleFilePath) {
|
5341
|
+
if (!moduleFilePath || typeof moduleFilePath !== "string") {
|
5342
|
+
return [];
|
5343
|
+
}
|
5344
|
+
|
5345
|
+
// Try App Router patterns first
|
5346
|
+
var appRouterPatterns = [/\/app\/(.+)\/page\.val\.ts$/,
|
5347
|
+
// /app/...
|
5348
|
+
/\/src\/app\/(.+)\/page\.val\.ts$/,
|
5349
|
+
// /src/app/...
|
5350
|
+
/\/app\/(.+)\/page\.tsx?$/,
|
5351
|
+
// /app/... with .tsx
|
5352
|
+
/\/src\/app\/(.+)\/page\.tsx?$/ // /src/app/... with .tsx
|
5353
|
+
];
|
5354
|
+
for (var _i2 = 0, _appRouterPatterns = appRouterPatterns; _i2 < _appRouterPatterns.length; _i2++) {
|
5355
|
+
var pattern = _appRouterPatterns[_i2];
|
5356
|
+
var match = moduleFilePath.match(pattern);
|
5357
|
+
if (match) {
|
5358
|
+
var routePath = match[1];
|
5359
|
+
// Remove group and interception segments
|
5360
|
+
// Group: (group), Interception: (.), (..), (..)(dashboard), etc.
|
5361
|
+
return routePath.split("/").flatMap(function (segment) {
|
5362
|
+
// Remove group segments (but not interception segments)
|
5363
|
+
if (segment.startsWith("(") && segment.endsWith(")") && !segment.includes(".")) return [];
|
5364
|
+
// Interception segments: (.)feed, (..)(dashboard)/feed, etc.
|
5365
|
+
// If segment starts with (.) or (..), strip the interception marker and keep the rest
|
5366
|
+
var interceptionMatch = segment.match(/^(\([.]+\)(\(.+\))?)(.*)$/);
|
5367
|
+
if (interceptionMatch) {
|
5368
|
+
var rest = interceptionMatch[3] || interceptionMatch[4];
|
5369
|
+
return rest ? [rest] : [];
|
5370
|
+
}
|
5371
|
+
return [segment];
|
5372
|
+
});
|
5373
|
+
}
|
5374
|
+
}
|
5375
|
+
return [];
|
5376
|
+
}
|
5377
|
+
|
5090
5378
|
var ModuleFilePathSep = "?p=";
|
5091
5379
|
var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
|
5092
5380
|
var DEFAULT_CONTENT_HOST = "https://content.val.build";
|
@@ -5111,6 +5399,7 @@ var Internal = {
|
|
5111
5399
|
safeResolvePath: safeResolvePath,
|
5112
5400
|
splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
|
5113
5401
|
joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
|
5402
|
+
nextAppRouter: nextAppRouter,
|
5114
5403
|
remote: {
|
5115
5404
|
createRemoteRef: createRemoteRef,
|
5116
5405
|
getValidationBasis: getValidationBasis,
|