@valbuild/core 0.83.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.
@@ -191,7 +191,7 @@ var Schema = /*#__PURE__*/function () {
191
191
  }
192
192
  return _createClass(Schema, [{
193
193
  key: "executeCustomValidateFunctions",
194
- value: function executeCustomValidateFunctions(src, customValidateFunctions) {
194
+ value: function executeCustomValidateFunctions(src, customValidateFunctions, ctx) {
195
195
  var errors = [];
196
196
  var _iterator = result._createForOfIteratorHelper(customValidateFunctions),
197
197
  _step;
@@ -199,7 +199,7 @@ var Schema = /*#__PURE__*/function () {
199
199
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
200
200
  var customValidateFunction = _step.value;
201
201
  try {
202
- var result$1 = customValidateFunction(src);
202
+ var result$1 = customValidateFunction(src, ctx);
203
203
  if (result$1) {
204
204
  errors.push({
205
205
  message: result$1,
@@ -405,7 +405,9 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
405
405
  }, {
406
406
  key: "executeValidate",
407
407
  value: function executeValidate(path, src) {
408
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
408
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
409
+ path: path
410
+ });
409
411
  if (this.opt && (src === null || src === undefined)) {
410
412
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
411
413
  }
@@ -668,6 +670,170 @@ function unsafeCreateSourcePath(path, itemKey) {
668
670
  return "".concat(path).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(itemKey));
669
671
  }
670
672
 
673
+ var StringSchema = /*#__PURE__*/function (_Schema) {
674
+ function StringSchema(options) {
675
+ var _this;
676
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
677
+ var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
678
+ var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
679
+ _classCallCheck(this, StringSchema);
680
+ _this = _callSuper(this, StringSchema);
681
+ _this.options = options;
682
+ _this.opt = opt;
683
+ _this.isRaw = isRaw;
684
+ _this.customValidateFunctions = customValidateFunctions;
685
+ return _this;
686
+ }
687
+
688
+ /**
689
+ * @deprecated Use `minLength` instead
690
+ */
691
+ _inherits(StringSchema, _Schema);
692
+ return _createClass(StringSchema, [{
693
+ key: "min",
694
+ value: function min(minLength) {
695
+ return this.minLength(minLength);
696
+ }
697
+ }, {
698
+ key: "minLength",
699
+ value: function minLength(_minLength) {
700
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
701
+ minLength: _minLength
702
+ }), this.opt, this.isRaw);
703
+ }
704
+
705
+ /**
706
+ * @deprecated Use `maxLength` instead
707
+ */
708
+ }, {
709
+ key: "max",
710
+ value: function max(maxLength) {
711
+ return this.maxLength(maxLength);
712
+ }
713
+ }, {
714
+ key: "maxLength",
715
+ value: function maxLength(_maxLength) {
716
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
717
+ maxLength: _maxLength
718
+ }), this.opt, this.isRaw);
719
+ }
720
+ }, {
721
+ key: "regexp",
722
+ value: function regexp(_regexp, message) {
723
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
724
+ regexp: _regexp,
725
+ regExpMessage: message
726
+ }), this.opt, this.isRaw);
727
+ }
728
+ }, {
729
+ key: "validate",
730
+ value: function validate(validationFunction) {
731
+ return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions.concat(validationFunction));
732
+ }
733
+ }, {
734
+ key: "executeValidate",
735
+ value: function executeValidate(path, src) {
736
+ var _this$options, _this$options2, _this$options3;
737
+ var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
738
+ path: path
739
+ });
740
+ if (this.opt && (src === null || src === undefined)) {
741
+ return errors.length > 0 ? _defineProperty({}, path, errors) : false;
742
+ }
743
+ if (typeof src !== "string") {
744
+ return _defineProperty({}, path, [{
745
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
746
+ value: src
747
+ }]);
748
+ }
749
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.maxLength && src.length > this.options.maxLength) {
750
+ errors.push({
751
+ message: "Expected string to be at most ".concat(this.options.maxLength, " characters long, got ").concat(src.length),
752
+ value: src
753
+ });
754
+ }
755
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.minLength && src.length < this.options.minLength) {
756
+ errors.push({
757
+ message: "Expected string to be at least ".concat(this.options.minLength, " characters long, got ").concat(src.length),
758
+ value: src
759
+ });
760
+ }
761
+ if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.regexp && !this.options.regexp.test(src)) {
762
+ errors.push({
763
+ message: this.options.regExpMessage || "Expected string to match reg exp: ".concat(this.options.regexp.toString(), ", got '").concat(src, "'"),
764
+ value: src
765
+ });
766
+ }
767
+ if (errors.length > 0) {
768
+ return _defineProperty({}, path, errors);
769
+ }
770
+ return false;
771
+ }
772
+ }, {
773
+ key: "executeAssert",
774
+ value: function executeAssert(path, src) {
775
+ if (this.opt && src === null) {
776
+ return {
777
+ success: true,
778
+ data: src
779
+ };
780
+ }
781
+ if (typeof src === "string") {
782
+ return {
783
+ success: true,
784
+ data: src
785
+ };
786
+ }
787
+ return {
788
+ success: false,
789
+ errors: _defineProperty({}, path, [{
790
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
791
+ typeError: true
792
+ }])
793
+ };
794
+ }
795
+ }, {
796
+ key: "nullable",
797
+ value: function nullable() {
798
+ return new StringSchema(this.options, true, this.isRaw);
799
+ }
800
+ }, {
801
+ key: "raw",
802
+ value: function raw() {
803
+ return new StringSchema(this.options, this.opt, true);
804
+ }
805
+ }, {
806
+ key: "executeSerialize",
807
+ value: function executeSerialize() {
808
+ var _this$options4, _this$options5, _this$options6, _this$customValidateF, _this$customValidateF2;
809
+ return {
810
+ type: "string",
811
+ options: {
812
+ maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
813
+ minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
814
+ regexp: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.regexp) && {
815
+ message: this.options.regExpMessage,
816
+ source: this.options.regexp.source,
817
+ flags: this.options.regexp.flags
818
+ },
819
+ customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
820
+ },
821
+ opt: this.opt,
822
+ raw: this.isRaw,
823
+ customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
824
+ };
825
+ }
826
+ }, {
827
+ key: "executeRender",
828
+ value: function executeRender() {
829
+ return {};
830
+ }
831
+ }]);
832
+ }(Schema);
833
+ var string = function string(options) {
834
+ return new StringSchema(options);
835
+ };
836
+
671
837
  var ObjectSchema = /*#__PURE__*/function (_Schema) {
672
838
  function ObjectSchema(items) {
673
839
  var _this;
@@ -690,7 +856,9 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
690
856
  key: "executeValidate",
691
857
  value: function executeValidate(path, src) {
692
858
  var error = false;
693
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
859
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
860
+ path: path
861
+ });
694
862
  if (this.opt && (src === null || src === undefined)) {
695
863
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
696
864
  }
@@ -850,6 +1018,11 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
850
1018
  var object = function object(schema) {
851
1019
  return new ObjectSchema(schema);
852
1020
  };
1021
+ object({
1022
+ get test() {
1023
+ return string();
1024
+ }
1025
+ });
853
1026
 
854
1027
  var ArraySchema = /*#__PURE__*/function (_Schema) {
855
1028
  function ArraySchema(item) {
@@ -1047,7 +1220,9 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1047
1220
  }, {
1048
1221
  key: "executeValidate",
1049
1222
  value: function executeValidate(path, src) {
1050
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
1223
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1224
+ path: path
1225
+ });
1051
1226
  if (this.opt && (src === null || src === undefined)) {
1052
1227
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
1053
1228
  }
@@ -1149,7 +1324,9 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1149
1324
  }, {
1150
1325
  key: "executeValidate",
1151
1326
  value: function executeValidate(path, src) {
1152
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
1327
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1328
+ path: path
1329
+ });
1153
1330
  var unknownSrc = src;
1154
1331
  if (this.opt && unknownSrc === null) {
1155
1332
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
@@ -1542,7 +1719,9 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1542
1719
  }, {
1543
1720
  key: "executeValidate",
1544
1721
  value: function executeValidate(path, src) {
1545
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
1722
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1723
+ path: path
1724
+ });
1546
1725
  if (this.opt && (src === null || src === undefined)) {
1547
1726
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
1548
1727
  }
@@ -1769,7 +1948,9 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1769
1948
  }, {
1770
1949
  key: "executeValidate",
1771
1950
  value: function executeValidate(path, src) {
1772
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
1951
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1952
+ path: path
1953
+ });
1773
1954
  var assertRes = this.executeAssert(path, src);
1774
1955
  if (!assertRes.success) {
1775
1956
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : assertRes.errors;
@@ -2197,12 +2378,14 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2197
2378
  var _this;
2198
2379
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2199
2380
  var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
2381
+ var currentRouter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
2200
2382
  _classCallCheck(this, RecordSchema);
2201
2383
  _this = _callSuper(this, RecordSchema);
2202
2384
  _defineProperty(_this, "renderInput", null);
2203
2385
  _this.item = item;
2204
2386
  _this.opt = opt;
2205
2387
  _this.customValidateFunctions = customValidateFunctions;
2388
+ _this.currentRouter = currentRouter;
2206
2389
  return _this;
2207
2390
  }
2208
2391
  _inherits(RecordSchema, _Schema);
@@ -2216,7 +2399,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2216
2399
  value: function executeValidate(path, src) {
2217
2400
  var _this2 = this;
2218
2401
  var error = false;
2219
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
2402
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2403
+ path: path
2404
+ });
2220
2405
  if (this.opt && (src === null || src === undefined)) {
2221
2406
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
2222
2407
  }
@@ -2235,6 +2420,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2235
2420
  message: "Expected 'object', got 'array'"
2236
2421
  }]));
2237
2422
  }
2423
+ var routerValidations = this.getRouterValidations(path, src);
2424
+ if (routerValidations) {
2425
+ return routerValidations;
2426
+ }
2238
2427
  var _iterator = result._createForOfIteratorHelper(customValidationErrors),
2239
2428
  _step;
2240
2429
  try {
@@ -2304,14 +2493,62 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2304
2493
  value: function nullable() {
2305
2494
  return new RecordSchema(this.item, true);
2306
2495
  }
2496
+ }, {
2497
+ key: "router",
2498
+ value: function router(_router) {
2499
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router);
2500
+ }
2501
+ }, {
2502
+ key: "getRouterValidations",
2503
+ value: function getRouterValidations(path, src) {
2504
+ if (!this.currentRouter) {
2505
+ return false;
2506
+ }
2507
+ if (src === null) {
2508
+ return false;
2509
+ }
2510
+ var _splitModuleFilePathA = splitModuleFilePathAndModulePath(path),
2511
+ _splitModuleFilePathA2 = _slicedToArray(_splitModuleFilePathA, 2),
2512
+ moduleFilePath = _splitModuleFilePathA2[0],
2513
+ modulePath = _splitModuleFilePathA2[1];
2514
+ if (modulePath) {
2515
+ return _defineProperty({}, path, [{
2516
+ message: "This field was configured as a router, but it is not defined at the root of the module",
2517
+ schemaError: true
2518
+ }]);
2519
+ }
2520
+ var routerValidations = this.currentRouter.validate(moduleFilePath, Object.keys(src));
2521
+ if (routerValidations.length > 0) {
2522
+ return Object.fromEntries(routerValidations.map(function (validation) {
2523
+ if (!validation.error.urlPath) {
2524
+ return [path, [{
2525
+ message: "Router validation error: ".concat(validation.error.message, " has no url path"),
2526
+ schemaError: true
2527
+ }]];
2528
+ }
2529
+ var subPath = createValPathOfItem(path, validation.error.urlPath);
2530
+ if (!subPath) {
2531
+ return [path, [{
2532
+ message: "Could not create path for router validation error",
2533
+ schemaError: true
2534
+ }]];
2535
+ }
2536
+ return [subPath, [{
2537
+ message: validation.error.message
2538
+ }]];
2539
+ }));
2540
+ }
2541
+ return false;
2542
+ }
2307
2543
  }, {
2308
2544
  key: "executeSerialize",
2309
2545
  value: function executeSerialize() {
2310
- var _this$customValidateF;
2546
+ var _this$currentRouter, _this$customValidateF;
2311
2547
  return {
2312
2548
  type: "record",
2313
2549
  item: this.item["executeSerialize"](),
2314
2550
  opt: this.opt,
2551
+ router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
2315
2552
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
2316
2553
  };
2317
2554
  }
@@ -2350,10 +2587,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2350
2587
  data: {
2351
2588
  layout: "list",
2352
2589
  parent: "record",
2353
- items: Object.entries(src).map(function (_ref7) {
2354
- var _ref8 = _slicedToArray(_ref7, 2),
2355
- key = _ref8[0],
2356
- val = _ref8[1];
2590
+ items: Object.entries(src).map(function (_ref8) {
2591
+ var _ref9 = _slicedToArray(_ref8, 2),
2592
+ key = _ref9[0],
2593
+ val = _ref9[1];
2357
2594
  // NB NB: display is actually defined by the user
2358
2595
  var _prepare = prepare({
2359
2596
  key: key,
@@ -2913,7 +3150,9 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2913
3150
  key: "executeValidate",
2914
3151
  value: function executeValidate(path, src) {
2915
3152
  var _this$options, _this$options2;
2916
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
3153
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
3154
+ path: path
3155
+ });
2917
3156
  if (this.opt && (src === null || src === undefined)) {
2918
3157
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
2919
3158
  }
@@ -3013,168 +3252,6 @@ var number = function number(options) {
3013
3252
  return new NumberSchema(options);
3014
3253
  };
3015
3254
 
3016
- var StringSchema = /*#__PURE__*/function (_Schema) {
3017
- function StringSchema(options) {
3018
- var _this;
3019
- var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3020
- var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3021
- var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
3022
- _classCallCheck(this, StringSchema);
3023
- _this = _callSuper(this, StringSchema);
3024
- _this.options = options;
3025
- _this.opt = opt;
3026
- _this.isRaw = isRaw;
3027
- _this.customValidateFunctions = customValidateFunctions;
3028
- return _this;
3029
- }
3030
-
3031
- /**
3032
- * @deprecated Use `minLength` instead
3033
- */
3034
- _inherits(StringSchema, _Schema);
3035
- return _createClass(StringSchema, [{
3036
- key: "min",
3037
- value: function min(minLength) {
3038
- return this.minLength(minLength);
3039
- }
3040
- }, {
3041
- key: "minLength",
3042
- value: function minLength(_minLength) {
3043
- return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
3044
- minLength: _minLength
3045
- }), this.opt, this.isRaw);
3046
- }
3047
-
3048
- /**
3049
- * @deprecated Use `maxLength` instead
3050
- */
3051
- }, {
3052
- key: "max",
3053
- value: function max(maxLength) {
3054
- return this.maxLength(maxLength);
3055
- }
3056
- }, {
3057
- key: "maxLength",
3058
- value: function maxLength(_maxLength) {
3059
- return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
3060
- maxLength: _maxLength
3061
- }), this.opt, this.isRaw);
3062
- }
3063
- }, {
3064
- key: "regexp",
3065
- value: function regexp(_regexp, message) {
3066
- return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
3067
- regexp: _regexp,
3068
- regExpMessage: message
3069
- }), this.opt, this.isRaw);
3070
- }
3071
- }, {
3072
- key: "validate",
3073
- value: function validate(validationFunction) {
3074
- return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions.concat(validationFunction));
3075
- }
3076
- }, {
3077
- key: "executeValidate",
3078
- value: function executeValidate(path, src) {
3079
- var _this$options, _this$options2, _this$options3;
3080
- var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
3081
- if (this.opt && (src === null || src === undefined)) {
3082
- return errors.length > 0 ? _defineProperty({}, path, errors) : false;
3083
- }
3084
- if (typeof src !== "string") {
3085
- return _defineProperty({}, path, [{
3086
- message: "Expected 'string', got '".concat(_typeof(src), "'"),
3087
- value: src
3088
- }]);
3089
- }
3090
- if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.maxLength && src.length > this.options.maxLength) {
3091
- errors.push({
3092
- message: "Expected string to be at most ".concat(this.options.maxLength, " characters long, got ").concat(src.length),
3093
- value: src
3094
- });
3095
- }
3096
- if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.minLength && src.length < this.options.minLength) {
3097
- errors.push({
3098
- message: "Expected string to be at least ".concat(this.options.minLength, " characters long, got ").concat(src.length),
3099
- value: src
3100
- });
3101
- }
3102
- if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.regexp && !this.options.regexp.test(src)) {
3103
- errors.push({
3104
- message: this.options.regExpMessage || "Expected string to match reg exp: ".concat(this.options.regexp.toString(), ", got '").concat(src, "'"),
3105
- value: src
3106
- });
3107
- }
3108
- if (errors.length > 0) {
3109
- return _defineProperty({}, path, errors);
3110
- }
3111
- return false;
3112
- }
3113
- }, {
3114
- key: "executeAssert",
3115
- value: function executeAssert(path, src) {
3116
- if (this.opt && src === null) {
3117
- return {
3118
- success: true,
3119
- data: src
3120
- };
3121
- }
3122
- if (typeof src === "string") {
3123
- return {
3124
- success: true,
3125
- data: src
3126
- };
3127
- }
3128
- return {
3129
- success: false,
3130
- errors: _defineProperty({}, path, [{
3131
- message: "Expected 'string', got '".concat(_typeof(src), "'"),
3132
- typeError: true
3133
- }])
3134
- };
3135
- }
3136
- }, {
3137
- key: "nullable",
3138
- value: function nullable() {
3139
- return new StringSchema(this.options, true, this.isRaw);
3140
- }
3141
- }, {
3142
- key: "raw",
3143
- value: function raw() {
3144
- return new StringSchema(this.options, this.opt, true);
3145
- }
3146
- }, {
3147
- key: "executeSerialize",
3148
- value: function executeSerialize() {
3149
- var _this$options4, _this$options5, _this$options6, _this$customValidateF, _this$customValidateF2;
3150
- return {
3151
- type: "string",
3152
- options: {
3153
- maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
3154
- minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
3155
- regexp: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.regexp) && {
3156
- message: this.options.regExpMessage,
3157
- source: this.options.regexp.source,
3158
- flags: this.options.regexp.flags
3159
- },
3160
- customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
3161
- },
3162
- opt: this.opt,
3163
- raw: this.isRaw,
3164
- customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
3165
- };
3166
- }
3167
- }, {
3168
- key: "executeRender",
3169
- value: function executeRender() {
3170
- return {};
3171
- }
3172
- }]);
3173
- }(Schema);
3174
- var string = function string(options) {
3175
- return new StringSchema(options);
3176
- };
3177
-
3178
3255
  var BooleanSchema = /*#__PURE__*/function (_Schema) {
3179
3256
  function BooleanSchema() {
3180
3257
  var _this;
@@ -3286,7 +3363,9 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3286
3363
  }, {
3287
3364
  key: "executeValidate",
3288
3365
  value: function executeValidate(path, src) {
3289
- var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions);
3366
+ var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
3367
+ path: path
3368
+ });
3290
3369
  if (this.opt && (src === null || src === undefined)) {
3291
3370
  return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
3292
3371
  }
@@ -3298,7 +3377,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3298
3377
  var serializedSchema = this.schema;
3299
3378
  if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
3300
3379
  return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
3301
- message: "Schema in keyOf must be an 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
3380
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3381
+ message: "Schema in keyOf must be an 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'")
3302
3382
  }]));
3303
3383
  }
3304
3384
  if (serializedSchema.opt && (src === null || src === undefined)) {
@@ -3310,7 +3390,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3310
3390
  }]));
3311
3391
  }
3312
3392
  if (serializedSchema.type === "object") {
3313
- var keys = Object.keys(serializedSchema.items);
3393
+ var keys = serializedSchema.keys;
3314
3394
  if (!keys.includes(src)) {
3315
3395
  return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
3316
3396
  message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
@@ -3370,7 +3450,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3370
3450
  return {
3371
3451
  success: false,
3372
3452
  errors: _defineProperty({}, path, [{
3373
- message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'"),
3453
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3454
+ message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'"),
3374
3455
  typeError: true
3375
3456
  }])
3376
3457
  };
@@ -3388,7 +3469,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3388
3469
  // and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
3389
3470
  // missing one would lead to a runtime error. At least this is what we are thinking currently.
3390
3471
  if (serializedSchema.type === "object") {
3391
- var keys = Object.keys(serializedSchema.items);
3472
+ var keys = serializedSchema.keys;
3392
3473
  if (!keys.includes(src)) {
3393
3474
  return {
3394
3475
  success: false,
@@ -3427,10 +3508,11 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3427
3508
  values = "string";
3428
3509
  break;
3429
3510
  case "object":
3430
- values = Object.keys(serializedSchema.items);
3511
+ values = serializedSchema.keys;
3431
3512
  break;
3432
3513
  default:
3433
- throw new Error("Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type, "'. keyOf must be used with a Val Module."));
3514
+ throw new Error(// eslint-disable-next-line @typescript-eslint/no-explicit-any
3515
+ "Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type || "unknown", "'"));
3434
3516
  }
3435
3517
  return {
3436
3518
  type: "keyOf",
@@ -3449,8 +3531,27 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3449
3531
  }]);
3450
3532
  }(Schema);
3451
3533
  var keyOf = function keyOf(valModule) {
3452
- var _valModule$GetSchema;
3453
- return new KeyOfSchema(valModule === null || valModule === void 0 || (_valModule$GetSchema = valModule[GetSchema]) === null || _valModule$GetSchema === void 0 ? void 0 : _valModule$GetSchema["executeSerialize"](), getValPath(valModule));
3534
+ var refSchema = valModule === null || valModule === void 0 ? void 0 : valModule[GetSchema];
3535
+ var serializedRefSchema = undefined;
3536
+ if (refSchema instanceof ObjectSchema) {
3537
+ var keys = [];
3538
+ try {
3539
+ keys = Object.keys((refSchema === null || refSchema === void 0 ? void 0 : refSchema["items"]) || {});
3540
+ } catch (e) {
3541
+ // ignore this error here
3542
+ }
3543
+ serializedRefSchema = {
3544
+ type: "object",
3545
+ keys: keys,
3546
+ opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
3547
+ };
3548
+ } else if (refSchema instanceof RecordSchema) {
3549
+ serializedRefSchema = {
3550
+ type: "record",
3551
+ opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
3552
+ };
3553
+ }
3554
+ return new KeyOfSchema(serializedRefSchema, getValPath(valModule));
3454
3555
  };
3455
3556
 
3456
3557
  var DateSchema = /*#__PURE__*/function (_Schema) {
@@ -5089,6 +5190,193 @@ function deserializeSchema(serialized) {
5089
5190
  }
5090
5191
  }
5091
5192
 
5193
+ // Helper function to validate a URL path against a route pattern
5194
+ function validateUrlAgainstPattern(urlPath, routePattern) {
5195
+ // Remove leading slash and split URL path
5196
+ var urlSegments = urlPath.startsWith("/") ? urlPath.slice(1).split("/") : urlPath.split("/");
5197
+
5198
+ // Handle empty patterns (root route)
5199
+ if (routePattern.length === 0) {
5200
+ return {
5201
+ isValid: urlSegments.length === 0 || urlSegments.length === 1 && urlSegments[0] === "",
5202
+ expectedPath: "/"
5203
+ };
5204
+ }
5205
+
5206
+ // Check if segment counts match (accounting for optional segments and catch-all)
5207
+ var minSegments = 0;
5208
+ var maxSegments = 0;
5209
+ var hasCatchAll = false;
5210
+ var catchAllIndex = -1;
5211
+ for (var i = 0; i < routePattern.length; i++) {
5212
+ var segment = routePattern[i];
5213
+ if (segment.startsWith("[[") && segment.endsWith("]]")) {
5214
+ // Optional catch-all segment
5215
+ hasCatchAll = true;
5216
+ catchAllIndex = i;
5217
+ maxSegments = Infinity;
5218
+ } else if (segment.startsWith("[...") && segment.endsWith("]")) {
5219
+ // Required catch-all segment
5220
+ hasCatchAll = true;
5221
+ catchAllIndex = i;
5222
+ minSegments++;
5223
+ maxSegments = Infinity;
5224
+ } else if (segment.startsWith("[[") && segment.endsWith("]")) {
5225
+ // Optional segment
5226
+ maxSegments++;
5227
+ } else if (segment.startsWith("[") && segment.endsWith("]")) {
5228
+ // Required segment
5229
+ minSegments++;
5230
+ maxSegments++;
5231
+ } else {
5232
+ // Static segment
5233
+ minSegments++;
5234
+ maxSegments++;
5235
+ }
5236
+ }
5237
+
5238
+ // Check segment count
5239
+ if (urlSegments.length < minSegments || !hasCatchAll && urlSegments.length > maxSegments) {
5240
+ var expectedSegments = routePattern.map(function (seg) {
5241
+ if (seg.startsWith("[[") && seg.endsWith("]]")) {
5242
+ return "[optional:".concat(seg.slice(2, -2), "]");
5243
+ } else if (seg.startsWith("[...") && seg.endsWith("]")) {
5244
+ return "[...".concat(seg.slice(4, -1), "]");
5245
+ } else if (seg.startsWith("[[") && seg.endsWith("]")) {
5246
+ return "[optional:".concat(seg.slice(2, -1), "]");
5247
+ } else if (seg.startsWith("[") && seg.endsWith("]")) {
5248
+ return "[".concat(seg.slice(1, -1), "]");
5249
+ }
5250
+ return seg;
5251
+ }).join("/");
5252
+ return {
5253
+ isValid: false,
5254
+ expectedPath: "/".concat(expectedSegments)
5255
+ };
5256
+ }
5257
+
5258
+ // Validate each segment up to the catch-all or the end of the pattern
5259
+ var segmentsToValidate = hasCatchAll ? catchAllIndex : routePattern.length;
5260
+ for (var _i = 0; _i < segmentsToValidate; _i++) {
5261
+ var patternSegment = routePattern[_i];
5262
+ var urlSegment = urlSegments[_i];
5263
+
5264
+ // Handle optional segments
5265
+ if (patternSegment.startsWith("[[") && patternSegment.endsWith("]]")) {
5266
+ // Optional segment - can be empty or match
5267
+ if (urlSegment !== "" && urlSegment !== undefined) {
5268
+ // If provided, validate it's not empty
5269
+ if (urlSegment === "") {
5270
+ return {
5271
+ isValid: false,
5272
+ expectedPath: "/".concat(routePattern.join("/"))
5273
+ };
5274
+ }
5275
+ }
5276
+ } else if (patternSegment.startsWith("[") && patternSegment.endsWith("]")) {
5277
+ // Required dynamic segment - just check it's not empty
5278
+ if (urlSegment === "" || urlSegment === undefined) {
5279
+ return {
5280
+ isValid: false,
5281
+ expectedPath: "/".concat(routePattern.join("/"))
5282
+ };
5283
+ }
5284
+ } else {
5285
+ // Static segment - must match exactly
5286
+ if (patternSegment !== urlSegment) {
5287
+ return {
5288
+ isValid: false,
5289
+ expectedPath: "/".concat(routePattern.join("/"))
5290
+ };
5291
+ }
5292
+ }
5293
+ }
5294
+ return {
5295
+ isValid: true
5296
+ };
5297
+ }
5298
+
5299
+ // This router should not be in core package
5300
+ var nextAppRouter = {
5301
+ getRouterId: function getRouterId() {
5302
+ return "next-app-router";
5303
+ },
5304
+ validate: function validate(moduleFilePath, urlPaths) {
5305
+ var routePattern = parseNextJsRoutePattern(moduleFilePath);
5306
+ var errors = [];
5307
+ var _iterator = result._createForOfIteratorHelper(urlPaths),
5308
+ _step;
5309
+ try {
5310
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5311
+ var urlPath = _step.value;
5312
+ var validation = validateUrlAgainstPattern(urlPath, routePattern);
5313
+ if (!validation.isValid) {
5314
+ errors.push({
5315
+ error: {
5316
+ message: "URL path \"".concat(urlPath, "\" does not match the route pattern for \"").concat(moduleFilePath, "\""),
5317
+ urlPath: urlPath,
5318
+ expectedPath: validation.expectedPath || null
5319
+ }
5320
+ });
5321
+ }
5322
+ }
5323
+ } catch (err) {
5324
+ _iterator.e(err);
5325
+ } finally {
5326
+ _iterator.f();
5327
+ }
5328
+ return errors;
5329
+ }
5330
+ };
5331
+
5332
+ /**
5333
+ * Parse Next.js route pattern from file path
5334
+ * Support multiple Next.js app directory structures:
5335
+ * - /app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
5336
+ * - /src/app/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"]
5337
+ * - /pages/blogs/[blog].tsx -> ["blogs", "[blog]"] (Pages Router)
5338
+ * - /app/(group)/blogs/[blog]/page.val.ts -> ["blogs", "[blog]"] (with groups)
5339
+ * - /app/(.)feed/page.val.ts -> ["feed"] (interception route)
5340
+ * - /app/(..)(dashboard)/feed/page.val.ts -> ["feed"] (interception route)
5341
+ */
5342
+ function parseNextJsRoutePattern(moduleFilePath) {
5343
+ if (!moduleFilePath || typeof moduleFilePath !== "string") {
5344
+ return [];
5345
+ }
5346
+
5347
+ // Try App Router patterns first
5348
+ var appRouterPatterns = [/\/app\/(.+)\/page\.val\.ts$/,
5349
+ // /app/...
5350
+ /\/src\/app\/(.+)\/page\.val\.ts$/,
5351
+ // /src/app/...
5352
+ /\/app\/(.+)\/page\.tsx?$/,
5353
+ // /app/... with .tsx
5354
+ /\/src\/app\/(.+)\/page\.tsx?$/ // /src/app/... with .tsx
5355
+ ];
5356
+ for (var _i2 = 0, _appRouterPatterns = appRouterPatterns; _i2 < _appRouterPatterns.length; _i2++) {
5357
+ var pattern = _appRouterPatterns[_i2];
5358
+ var match = moduleFilePath.match(pattern);
5359
+ if (match) {
5360
+ var routePath = match[1];
5361
+ // Remove group and interception segments
5362
+ // Group: (group), Interception: (.), (..), (..)(dashboard), etc.
5363
+ return routePath.split("/").flatMap(function (segment) {
5364
+ // Remove group segments (but not interception segments)
5365
+ if (segment.startsWith("(") && segment.endsWith(")") && !segment.includes(".")) return [];
5366
+ // Interception segments: (.)feed, (..)(dashboard)/feed, etc.
5367
+ // If segment starts with (.) or (..), strip the interception marker and keep the rest
5368
+ var interceptionMatch = segment.match(/^(\([.]+\)(\(.+\))?)(.*)$/);
5369
+ if (interceptionMatch) {
5370
+ var rest = interceptionMatch[3] || interceptionMatch[4];
5371
+ return rest ? [rest] : [];
5372
+ }
5373
+ return [segment];
5374
+ });
5375
+ }
5376
+ }
5377
+ return [];
5378
+ }
5379
+
5092
5380
  var ModuleFilePathSep = "?p=";
5093
5381
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
5094
5382
  var DEFAULT_CONTENT_HOST = "https://content.val.build";
@@ -5113,6 +5401,7 @@ var Internal = {
5113
5401
  safeResolvePath: safeResolvePath,
5114
5402
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
5115
5403
  joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
5404
+ nextAppRouter: nextAppRouter,
5116
5405
  remote: {
5117
5406
  createRemoteRef: createRemoteRef,
5118
5407
  getValidationBasis: getValidationBasis,