@valbuild/core 0.88.0 → 0.89.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 +1 -0
- package/dist/declarations/src/initSchema.d.ts +41 -0
- package/dist/declarations/src/schema/index.d.ts +2 -1
- package/dist/declarations/src/schema/route.d.ts +64 -0
- package/dist/declarations/src/schema/router.d.ts +5 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/{index-eb1a6b1f.cjs.dev.js → index-3f815afd.cjs.dev.js} +169 -13
- package/dist/{index-11591a0b.esm.js → index-52848948.esm.js} +169 -14
- package/dist/{index-34063fba.cjs.prod.js → index-55f6a997.cjs.prod.js} +169 -13
- package/dist/valbuild-core.cjs.dev.js +2 -1
- package/dist/valbuild-core.cjs.prod.js +2 -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
|
@@ -48,6 +48,7 @@ export { type SerializedImageSchema, ImageSchema } from "./schema/image.js";
|
|
|
48
48
|
export { type SerializedFileSchema, FileSchema } from "./schema/file.js";
|
|
49
49
|
export { type SerializedDateSchema, DateSchema } from "./schema/date.js";
|
|
50
50
|
export { type SerializedKeyOfSchema, KeyOfSchema } from "./schema/keyOf.js";
|
|
51
|
+
export { type SerializedRouteSchema, RouteSchema } from "./schema/route.js";
|
|
51
52
|
export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtext.js";
|
|
52
53
|
export { type SerializedUnionSchema, UnionSchema, type SerializedStringUnionSchema, type SerializedObjectUnionSchema, } from "./schema/union.js";
|
|
53
54
|
export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
|
|
@@ -11,6 +11,8 @@ import { keyOf } from "./schema/keyOf.js";
|
|
|
11
11
|
import { record } from "./schema/record.js";
|
|
12
12
|
import { file } from "./schema/file.js";
|
|
13
13
|
import { date } from "./schema/date.js";
|
|
14
|
+
import { route } from "./schema/route.js";
|
|
15
|
+
import { router } from "./schema/router.js";
|
|
14
16
|
export type InitSchema = {
|
|
15
17
|
/**
|
|
16
18
|
* Define a string.
|
|
@@ -156,6 +158,43 @@ export type InitSchema = {
|
|
|
156
158
|
*
|
|
157
159
|
*/
|
|
158
160
|
readonly date: typeof date;
|
|
161
|
+
/**
|
|
162
|
+
* Define a string that references a route path in your application.
|
|
163
|
+
*
|
|
164
|
+
* To create router pages you can use the s.router() function.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const schema = s.route();
|
|
169
|
+
* export default c.define("/example.val.ts", schema, "/a-page-slug");
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
readonly route: typeof route;
|
|
173
|
+
/**
|
|
174
|
+
* Create a page router.
|
|
175
|
+
* Each key is the path of the page.
|
|
176
|
+
*
|
|
177
|
+
* The router will be used to validate the paths of the pages.
|
|
178
|
+
*
|
|
179
|
+
* If you need to link to these pages you can use the s.route() to reference page paths.
|
|
180
|
+
*
|
|
181
|
+
* @example Next.js App Router
|
|
182
|
+
* ```typescript
|
|
183
|
+
* import { s, c, nextAppRouter } from "../val.config";
|
|
184
|
+
* const schema = s.object({
|
|
185
|
+
* title: s.string(),
|
|
186
|
+
* });
|
|
187
|
+
* export default c.define("/app/[slug]/page.val.ts", s.router(nextAppRouter, schema), {
|
|
188
|
+
* "/a-page-slug": { title: "First Page" },
|
|
189
|
+
* "/another-page-slug": { title: "Second Page" },
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @param router - The router configuration (e.g., nextAppRouter)
|
|
194
|
+
* @param schema - The schema for each route item
|
|
195
|
+
* @returns A RecordSchema configured as a router
|
|
196
|
+
*/
|
|
197
|
+
readonly router: typeof router;
|
|
159
198
|
};
|
|
160
199
|
export declare function initSchema(): {
|
|
161
200
|
string: <T extends string>(options?: Record<string, never> | undefined) => import("./schema/string.js").StringSchema<T>;
|
|
@@ -214,4 +253,6 @@ export declare function initSchema(): {
|
|
|
214
253
|
record: typeof record;
|
|
215
254
|
file: (options?: import("./schema/file.js").FileOptions | undefined) => import("./schema/file.js").FileSchema<import("./index.js").FileSource<import("./schema/file.js").FileMetadata>>;
|
|
216
255
|
date: (options?: Record<string, never> | undefined) => import("./schema/date.js").DateSchema<import("./schema/string.js").RawString>;
|
|
256
|
+
route: <T_3 extends string>(options?: Record<string, never> | undefined) => import("./schema/route.js").RouteSchema<T_3>;
|
|
257
|
+
router: typeof router;
|
|
217
258
|
};
|
|
@@ -13,11 +13,12 @@ import { SerializedRichTextSchema } from "./richtext.js";
|
|
|
13
13
|
import { RawString, SerializedStringSchema } from "./string.js";
|
|
14
14
|
import { SerializedUnionSchema } from "./union.js";
|
|
15
15
|
import { SerializedDateSchema } from "./date.js";
|
|
16
|
+
import { SerializedRouteSchema } from "./route.js";
|
|
16
17
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
17
18
|
import { FileSource } from "../source/file.js";
|
|
18
19
|
import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
|
|
19
20
|
import { ReifiedRender } from "../render.js";
|
|
20
|
-
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedImageSchema;
|
|
21
|
+
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedRouteSchema | SerializedImageSchema;
|
|
21
22
|
type Primitives = number | string | boolean | null | FileSource;
|
|
22
23
|
export type AssertError = {
|
|
23
24
|
message: string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
+
import { SourcePath } from "../val/index.js";
|
|
3
|
+
import { ReifiedRender } from "../render.js";
|
|
4
|
+
import { ValidationErrors } from "./validation/ValidationError.js";
|
|
5
|
+
type RouteOptions = {
|
|
6
|
+
include?: RegExp;
|
|
7
|
+
exclude?: RegExp;
|
|
8
|
+
};
|
|
9
|
+
export type SerializedRouteSchema = {
|
|
10
|
+
type: "route";
|
|
11
|
+
options?: {
|
|
12
|
+
include?: {
|
|
13
|
+
source: string;
|
|
14
|
+
flags: string;
|
|
15
|
+
};
|
|
16
|
+
exclude?: {
|
|
17
|
+
source: string;
|
|
18
|
+
flags: string;
|
|
19
|
+
};
|
|
20
|
+
customValidate?: boolean;
|
|
21
|
+
};
|
|
22
|
+
opt: boolean;
|
|
23
|
+
customValidate?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare class RouteSchema<Src extends string | null> extends Schema<Src> {
|
|
26
|
+
private readonly options?;
|
|
27
|
+
private readonly opt;
|
|
28
|
+
private readonly customValidateFunctions;
|
|
29
|
+
constructor(options?: RouteOptions | undefined, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[]);
|
|
30
|
+
/**
|
|
31
|
+
* Specify a pattern for which routes are allowed.
|
|
32
|
+
*
|
|
33
|
+
* Semantics:
|
|
34
|
+
* - If only include is set: route must match include pattern
|
|
35
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
36
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* s.route().include(/^\/(home|about|contact)$/) // Only these specific routes
|
|
40
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
41
|
+
*/
|
|
42
|
+
include(pattern: RegExp): RouteSchema<Src>;
|
|
43
|
+
/**
|
|
44
|
+
* Specify a pattern for which routes should be excluded.
|
|
45
|
+
*
|
|
46
|
+
* Semantics:
|
|
47
|
+
* - If only include is set: route must match include pattern
|
|
48
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
49
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* s.route().exclude(/^\/admin/) // Exclude all admin routes
|
|
53
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
54
|
+
*/
|
|
55
|
+
exclude(pattern: RegExp): RouteSchema<Src>;
|
|
56
|
+
validate(validationFunction: (src: Src) => false | string): RouteSchema<Src>;
|
|
57
|
+
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
58
|
+
protected executeAssert(path: SourcePath, src: unknown): SchemaAssertResult<Src>;
|
|
59
|
+
nullable(): RouteSchema<Src | null>;
|
|
60
|
+
protected executeSerialize(): SerializedSchema;
|
|
61
|
+
protected executeRender(): ReifiedRender;
|
|
62
|
+
}
|
|
63
|
+
export declare const route: <T extends string>(options?: Record<string, never>) => RouteSchema<T>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Schema, SelectorOfSchema } from "./index.js";
|
|
2
|
+
import { ValRouter } from "../router.js";
|
|
3
|
+
import { SelectorSource } from "../selector/index.js";
|
|
4
|
+
import { RecordSchema } from "./record.js";
|
|
5
|
+
export declare function router<T extends Schema<SelectorSource>, Src extends Record<string, SelectorOfSchema<T>>>(router: ValRouter, item: T): RecordSchema<T, Schema<string>, Src>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const ValidationFix: readonly ["image:
|
|
1
|
+
export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "keyof:check-keys", "router:check-route"];
|
|
2
2
|
export type ValidationFix = (typeof ValidationFix)[number];
|
|
@@ -447,8 +447,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
447
447
|
if (src[VAL_EXTENSION] !== "file") {
|
|
448
448
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
449
449
|
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
450
|
-
value: src
|
|
451
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
450
|
+
value: src
|
|
452
451
|
}]));
|
|
453
452
|
}
|
|
454
453
|
var _ref8 = this.options || {},
|
|
@@ -458,8 +457,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
458
457
|
if (accept && mimeType && !mimeType.includes("/")) {
|
|
459
458
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
460
459
|
message: "Invalid mime type format. Got: ".concat(mimeType),
|
|
461
|
-
value: src
|
|
462
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
460
|
+
value: src
|
|
463
461
|
}]));
|
|
464
462
|
}
|
|
465
463
|
if (accept && mimeType && mimeType.includes("/")) {
|
|
@@ -479,8 +477,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
479
477
|
if (!isValidMimeType) {
|
|
480
478
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
481
479
|
message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
|
|
482
|
-
value: src
|
|
483
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
480
|
+
value: src
|
|
484
481
|
}]));
|
|
485
482
|
}
|
|
486
483
|
}
|
|
@@ -488,15 +485,13 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
488
485
|
if (!fileMimeType) {
|
|
489
486
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
490
487
|
message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
|
|
491
|
-
value: src
|
|
492
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
488
|
+
value: src
|
|
493
489
|
}]));
|
|
494
490
|
}
|
|
495
491
|
if (fileMimeType !== mimeType) {
|
|
496
492
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
497
493
|
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
498
|
-
value: src
|
|
499
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
494
|
+
value: src
|
|
500
495
|
}]));
|
|
501
496
|
}
|
|
502
497
|
if (src.metadata) {
|
|
@@ -1785,8 +1780,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1785
1780
|
if (src[VAL_EXTENSION] !== "file") {
|
|
1786
1781
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1787
1782
|
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
1788
|
-
value: src
|
|
1789
|
-
fixes: ["image:change-extension", "image:check-metadata"]
|
|
1783
|
+
value: src
|
|
1790
1784
|
}]));
|
|
1791
1785
|
}
|
|
1792
1786
|
var _ref8 = this.options || {},
|
|
@@ -3762,6 +3756,157 @@ var date = function date(options) {
|
|
|
3762
3756
|
return new DateSchema(options);
|
|
3763
3757
|
};
|
|
3764
3758
|
|
|
3759
|
+
var RouteSchema = /*#__PURE__*/function (_Schema) {
|
|
3760
|
+
function RouteSchema(options) {
|
|
3761
|
+
var _this;
|
|
3762
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3763
|
+
var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
3764
|
+
_classCallCheck(this, RouteSchema);
|
|
3765
|
+
_this = _callSuper(this, RouteSchema);
|
|
3766
|
+
_this.options = options;
|
|
3767
|
+
_this.opt = opt;
|
|
3768
|
+
_this.customValidateFunctions = customValidateFunctions;
|
|
3769
|
+
return _this;
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
/**
|
|
3773
|
+
* Specify a pattern for which routes are allowed.
|
|
3774
|
+
*
|
|
3775
|
+
* Semantics:
|
|
3776
|
+
* - If only include is set: route must match include pattern
|
|
3777
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3778
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3779
|
+
*
|
|
3780
|
+
* @example
|
|
3781
|
+
* s.route().include(/^\/(home|about|contact)$/) // Only these specific routes
|
|
3782
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3783
|
+
*/
|
|
3784
|
+
_inherits(RouteSchema, _Schema);
|
|
3785
|
+
return _createClass(RouteSchema, [{
|
|
3786
|
+
key: "include",
|
|
3787
|
+
value: function include(pattern) {
|
|
3788
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3789
|
+
include: pattern
|
|
3790
|
+
}), this.opt, this.customValidateFunctions);
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
/**
|
|
3794
|
+
* Specify a pattern for which routes should be excluded.
|
|
3795
|
+
*
|
|
3796
|
+
* Semantics:
|
|
3797
|
+
* - If only include is set: route must match include pattern
|
|
3798
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3799
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3800
|
+
*
|
|
3801
|
+
* @example
|
|
3802
|
+
* s.route().exclude(/^\/admin/) // Exclude all admin routes
|
|
3803
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3804
|
+
*/
|
|
3805
|
+
}, {
|
|
3806
|
+
key: "exclude",
|
|
3807
|
+
value: function exclude(pattern) {
|
|
3808
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3809
|
+
exclude: pattern
|
|
3810
|
+
}), this.opt, this.customValidateFunctions);
|
|
3811
|
+
}
|
|
3812
|
+
}, {
|
|
3813
|
+
key: "validate",
|
|
3814
|
+
value: function validate(validationFunction) {
|
|
3815
|
+
return new RouteSchema(this.options, this.opt, this.customValidateFunctions.concat(validationFunction));
|
|
3816
|
+
}
|
|
3817
|
+
}, {
|
|
3818
|
+
key: "executeValidate",
|
|
3819
|
+
value: function executeValidate(path, src) {
|
|
3820
|
+
var _this$options, _this$options2;
|
|
3821
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
3822
|
+
path: path
|
|
3823
|
+
});
|
|
3824
|
+
if (this.opt && (src === null || src === undefined)) {
|
|
3825
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
3826
|
+
}
|
|
3827
|
+
if (typeof src !== "string") {
|
|
3828
|
+
return _defineProperty({}, path, [{
|
|
3829
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3830
|
+
value: src
|
|
3831
|
+
}]);
|
|
3832
|
+
}
|
|
3833
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
3834
|
+
fixes: ["router:check-route"],
|
|
3835
|
+
message: "Did not validate route (router). This error (router:check-route) should typically be processed by Val internally. Seeing this error most likely means you have a Val version mismatch.",
|
|
3836
|
+
value: {
|
|
3837
|
+
route: src,
|
|
3838
|
+
sourcePath: path,
|
|
3839
|
+
include: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.include,
|
|
3840
|
+
exclude: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.exclude
|
|
3841
|
+
}
|
|
3842
|
+
}]));
|
|
3843
|
+
}
|
|
3844
|
+
}, {
|
|
3845
|
+
key: "executeAssert",
|
|
3846
|
+
value: function executeAssert(path, src) {
|
|
3847
|
+
if (this.opt && src === null) {
|
|
3848
|
+
return {
|
|
3849
|
+
success: true,
|
|
3850
|
+
data: src
|
|
3851
|
+
};
|
|
3852
|
+
}
|
|
3853
|
+
if (typeof src === "string") {
|
|
3854
|
+
return {
|
|
3855
|
+
success: true,
|
|
3856
|
+
data: src
|
|
3857
|
+
};
|
|
3858
|
+
}
|
|
3859
|
+
return {
|
|
3860
|
+
success: false,
|
|
3861
|
+
errors: _defineProperty({}, path, [{
|
|
3862
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3863
|
+
typeError: true
|
|
3864
|
+
}])
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
}, {
|
|
3868
|
+
key: "nullable",
|
|
3869
|
+
value: function nullable() {
|
|
3870
|
+
return new RouteSchema(this.options, true, this.customValidateFunctions);
|
|
3871
|
+
}
|
|
3872
|
+
}, {
|
|
3873
|
+
key: "executeSerialize",
|
|
3874
|
+
value: function executeSerialize() {
|
|
3875
|
+
var _this$options3, _this$options4, _this$customValidateF, _this$customValidateF2;
|
|
3876
|
+
return {
|
|
3877
|
+
type: "route",
|
|
3878
|
+
options: {
|
|
3879
|
+
include: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.include) && {
|
|
3880
|
+
source: this.options.include.source,
|
|
3881
|
+
flags: this.options.include.flags
|
|
3882
|
+
},
|
|
3883
|
+
exclude: ((_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.exclude) && {
|
|
3884
|
+
source: this.options.exclude.source,
|
|
3885
|
+
flags: this.options.exclude.flags
|
|
3886
|
+
},
|
|
3887
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
|
3888
|
+
},
|
|
3889
|
+
opt: this.opt,
|
|
3890
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
}, {
|
|
3894
|
+
key: "executeRender",
|
|
3895
|
+
value: function executeRender() {
|
|
3896
|
+
return {};
|
|
3897
|
+
}
|
|
3898
|
+
}]);
|
|
3899
|
+
}(Schema);
|
|
3900
|
+
var route = function route(options) {
|
|
3901
|
+
return new RouteSchema(options);
|
|
3902
|
+
};
|
|
3903
|
+
|
|
3904
|
+
function router(router, item) {
|
|
3905
|
+
var keySchema = string();
|
|
3906
|
+
var recordSchema = new RecordSchema(item, false, [], router, keySchema);
|
|
3907
|
+
return recordSchema;
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3765
3910
|
// import type { F } from "ts-toolbelt";
|
|
3766
3911
|
// import { i18n, I18n } from "./schema/future/i18n";
|
|
3767
3912
|
// import { oneOf } from "./schema/future/oneOf";
|
|
@@ -3785,7 +3930,9 @@ function initSchema() {
|
|
|
3785
3930
|
keyOf: keyOf,
|
|
3786
3931
|
record: record,
|
|
3787
3932
|
file: file,
|
|
3788
|
-
date: date
|
|
3933
|
+
date: date,
|
|
3934
|
+
route: route,
|
|
3935
|
+
router: router
|
|
3789
3936
|
// i18n: i18n(locales),
|
|
3790
3937
|
};
|
|
3791
3938
|
}
|
|
@@ -5239,6 +5386,14 @@ function deserializeSchema(serialized) {
|
|
|
5239
5386
|
return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null);
|
|
5240
5387
|
case "keyOf":
|
|
5241
5388
|
return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt);
|
|
5389
|
+
case "route":
|
|
5390
|
+
{
|
|
5391
|
+
var routeOptions = serialized.options ? {
|
|
5392
|
+
include: serialized.options.include ? new RegExp(serialized.options.include.source, serialized.options.include.flags) : undefined,
|
|
5393
|
+
exclude: serialized.options.exclude ? new RegExp(serialized.options.exclude.source, serialized.options.exclude.flags) : undefined
|
|
5394
|
+
} : undefined;
|
|
5395
|
+
return new RouteSchema(routeOptions, serialized.opt);
|
|
5396
|
+
}
|
|
5242
5397
|
case "file":
|
|
5243
5398
|
return new FileSchema(serialized.options, serialized.opt);
|
|
5244
5399
|
case "image":
|
|
@@ -5568,6 +5723,7 @@ exports.ObjectSchema = ObjectSchema;
|
|
|
5568
5723
|
exports.PatchError = PatchError;
|
|
5569
5724
|
exports.RecordSchema = RecordSchema;
|
|
5570
5725
|
exports.RichTextSchema = RichTextSchema;
|
|
5726
|
+
exports.RouteSchema = RouteSchema;
|
|
5571
5727
|
exports.Schema = Schema;
|
|
5572
5728
|
exports.StringSchema = StringSchema;
|
|
5573
5729
|
exports.UnionSchema = UnionSchema;
|
|
@@ -445,8 +445,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
445
445
|
if (src[VAL_EXTENSION] !== "file") {
|
|
446
446
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
447
447
|
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
448
|
-
value: src
|
|
449
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
448
|
+
value: src
|
|
450
449
|
}]));
|
|
451
450
|
}
|
|
452
451
|
var _ref8 = this.options || {},
|
|
@@ -456,8 +455,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
456
455
|
if (accept && mimeType && !mimeType.includes("/")) {
|
|
457
456
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
458
457
|
message: "Invalid mime type format. Got: ".concat(mimeType),
|
|
459
|
-
value: src
|
|
460
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
458
|
+
value: src
|
|
461
459
|
}]));
|
|
462
460
|
}
|
|
463
461
|
if (accept && mimeType && mimeType.includes("/")) {
|
|
@@ -477,8 +475,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
477
475
|
if (!isValidMimeType) {
|
|
478
476
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
479
477
|
message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
|
|
480
|
-
value: src
|
|
481
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
478
|
+
value: src
|
|
482
479
|
}]));
|
|
483
480
|
}
|
|
484
481
|
}
|
|
@@ -486,15 +483,13 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
486
483
|
if (!fileMimeType) {
|
|
487
484
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
488
485
|
message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
|
|
489
|
-
value: src
|
|
490
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
486
|
+
value: src
|
|
491
487
|
}]));
|
|
492
488
|
}
|
|
493
489
|
if (fileMimeType !== mimeType) {
|
|
494
490
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
495
491
|
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
496
|
-
value: src
|
|
497
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
492
|
+
value: src
|
|
498
493
|
}]));
|
|
499
494
|
}
|
|
500
495
|
if (src.metadata) {
|
|
@@ -1783,8 +1778,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1783
1778
|
if (src[VAL_EXTENSION] !== "file") {
|
|
1784
1779
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1785
1780
|
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
1786
|
-
value: src
|
|
1787
|
-
fixes: ["image:change-extension", "image:check-metadata"]
|
|
1781
|
+
value: src
|
|
1788
1782
|
}]));
|
|
1789
1783
|
}
|
|
1790
1784
|
var _ref8 = this.options || {},
|
|
@@ -3760,6 +3754,157 @@ var date = function date(options) {
|
|
|
3760
3754
|
return new DateSchema(options);
|
|
3761
3755
|
};
|
|
3762
3756
|
|
|
3757
|
+
var RouteSchema = /*#__PURE__*/function (_Schema) {
|
|
3758
|
+
function RouteSchema(options) {
|
|
3759
|
+
var _this;
|
|
3760
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3761
|
+
var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
3762
|
+
_classCallCheck(this, RouteSchema);
|
|
3763
|
+
_this = _callSuper(this, RouteSchema);
|
|
3764
|
+
_this.options = options;
|
|
3765
|
+
_this.opt = opt;
|
|
3766
|
+
_this.customValidateFunctions = customValidateFunctions;
|
|
3767
|
+
return _this;
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
/**
|
|
3771
|
+
* Specify a pattern for which routes are allowed.
|
|
3772
|
+
*
|
|
3773
|
+
* Semantics:
|
|
3774
|
+
* - If only include is set: route must match include pattern
|
|
3775
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3776
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3777
|
+
*
|
|
3778
|
+
* @example
|
|
3779
|
+
* s.route().include(/^\/(home|about|contact)$/) // Only these specific routes
|
|
3780
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3781
|
+
*/
|
|
3782
|
+
_inherits(RouteSchema, _Schema);
|
|
3783
|
+
return _createClass(RouteSchema, [{
|
|
3784
|
+
key: "include",
|
|
3785
|
+
value: function include(pattern) {
|
|
3786
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3787
|
+
include: pattern
|
|
3788
|
+
}), this.opt, this.customValidateFunctions);
|
|
3789
|
+
}
|
|
3790
|
+
|
|
3791
|
+
/**
|
|
3792
|
+
* Specify a pattern for which routes should be excluded.
|
|
3793
|
+
*
|
|
3794
|
+
* Semantics:
|
|
3795
|
+
* - If only include is set: route must match include pattern
|
|
3796
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3797
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3798
|
+
*
|
|
3799
|
+
* @example
|
|
3800
|
+
* s.route().exclude(/^\/admin/) // Exclude all admin routes
|
|
3801
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3802
|
+
*/
|
|
3803
|
+
}, {
|
|
3804
|
+
key: "exclude",
|
|
3805
|
+
value: function exclude(pattern) {
|
|
3806
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3807
|
+
exclude: pattern
|
|
3808
|
+
}), this.opt, this.customValidateFunctions);
|
|
3809
|
+
}
|
|
3810
|
+
}, {
|
|
3811
|
+
key: "validate",
|
|
3812
|
+
value: function validate(validationFunction) {
|
|
3813
|
+
return new RouteSchema(this.options, this.opt, this.customValidateFunctions.concat(validationFunction));
|
|
3814
|
+
}
|
|
3815
|
+
}, {
|
|
3816
|
+
key: "executeValidate",
|
|
3817
|
+
value: function executeValidate(path, src) {
|
|
3818
|
+
var _this$options, _this$options2;
|
|
3819
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
3820
|
+
path: path
|
|
3821
|
+
});
|
|
3822
|
+
if (this.opt && (src === null || src === undefined)) {
|
|
3823
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
3824
|
+
}
|
|
3825
|
+
if (typeof src !== "string") {
|
|
3826
|
+
return _defineProperty({}, path, [{
|
|
3827
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3828
|
+
value: src
|
|
3829
|
+
}]);
|
|
3830
|
+
}
|
|
3831
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
3832
|
+
fixes: ["router:check-route"],
|
|
3833
|
+
message: "Did not validate route (router). This error (router:check-route) should typically be processed by Val internally. Seeing this error most likely means you have a Val version mismatch.",
|
|
3834
|
+
value: {
|
|
3835
|
+
route: src,
|
|
3836
|
+
sourcePath: path,
|
|
3837
|
+
include: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.include,
|
|
3838
|
+
exclude: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.exclude
|
|
3839
|
+
}
|
|
3840
|
+
}]));
|
|
3841
|
+
}
|
|
3842
|
+
}, {
|
|
3843
|
+
key: "executeAssert",
|
|
3844
|
+
value: function executeAssert(path, src) {
|
|
3845
|
+
if (this.opt && src === null) {
|
|
3846
|
+
return {
|
|
3847
|
+
success: true,
|
|
3848
|
+
data: src
|
|
3849
|
+
};
|
|
3850
|
+
}
|
|
3851
|
+
if (typeof src === "string") {
|
|
3852
|
+
return {
|
|
3853
|
+
success: true,
|
|
3854
|
+
data: src
|
|
3855
|
+
};
|
|
3856
|
+
}
|
|
3857
|
+
return {
|
|
3858
|
+
success: false,
|
|
3859
|
+
errors: _defineProperty({}, path, [{
|
|
3860
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3861
|
+
typeError: true
|
|
3862
|
+
}])
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
}, {
|
|
3866
|
+
key: "nullable",
|
|
3867
|
+
value: function nullable() {
|
|
3868
|
+
return new RouteSchema(this.options, true, this.customValidateFunctions);
|
|
3869
|
+
}
|
|
3870
|
+
}, {
|
|
3871
|
+
key: "executeSerialize",
|
|
3872
|
+
value: function executeSerialize() {
|
|
3873
|
+
var _this$options3, _this$options4, _this$customValidateF, _this$customValidateF2;
|
|
3874
|
+
return {
|
|
3875
|
+
type: "route",
|
|
3876
|
+
options: {
|
|
3877
|
+
include: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.include) && {
|
|
3878
|
+
source: this.options.include.source,
|
|
3879
|
+
flags: this.options.include.flags
|
|
3880
|
+
},
|
|
3881
|
+
exclude: ((_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.exclude) && {
|
|
3882
|
+
source: this.options.exclude.source,
|
|
3883
|
+
flags: this.options.exclude.flags
|
|
3884
|
+
},
|
|
3885
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
|
3886
|
+
},
|
|
3887
|
+
opt: this.opt,
|
|
3888
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
}, {
|
|
3892
|
+
key: "executeRender",
|
|
3893
|
+
value: function executeRender() {
|
|
3894
|
+
return {};
|
|
3895
|
+
}
|
|
3896
|
+
}]);
|
|
3897
|
+
}(Schema);
|
|
3898
|
+
var route = function route(options) {
|
|
3899
|
+
return new RouteSchema(options);
|
|
3900
|
+
};
|
|
3901
|
+
|
|
3902
|
+
function router(router, item) {
|
|
3903
|
+
var keySchema = string();
|
|
3904
|
+
var recordSchema = new RecordSchema(item, false, [], router, keySchema);
|
|
3905
|
+
return recordSchema;
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3763
3908
|
// import type { F } from "ts-toolbelt";
|
|
3764
3909
|
// import { i18n, I18n } from "./schema/future/i18n";
|
|
3765
3910
|
// import { oneOf } from "./schema/future/oneOf";
|
|
@@ -3783,7 +3928,9 @@ function initSchema() {
|
|
|
3783
3928
|
keyOf: keyOf,
|
|
3784
3929
|
record: record,
|
|
3785
3930
|
file: file,
|
|
3786
|
-
date: date
|
|
3931
|
+
date: date,
|
|
3932
|
+
route: route,
|
|
3933
|
+
router: router
|
|
3787
3934
|
// i18n: i18n(locales),
|
|
3788
3935
|
};
|
|
3789
3936
|
}
|
|
@@ -5237,6 +5384,14 @@ function deserializeSchema(serialized) {
|
|
|
5237
5384
|
return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null);
|
|
5238
5385
|
case "keyOf":
|
|
5239
5386
|
return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt);
|
|
5387
|
+
case "route":
|
|
5388
|
+
{
|
|
5389
|
+
var routeOptions = serialized.options ? {
|
|
5390
|
+
include: serialized.options.include ? new RegExp(serialized.options.include.source, serialized.options.include.flags) : undefined,
|
|
5391
|
+
exclude: serialized.options.exclude ? new RegExp(serialized.options.exclude.source, serialized.options.exclude.flags) : undefined
|
|
5392
|
+
} : undefined;
|
|
5393
|
+
return new RouteSchema(routeOptions, serialized.opt);
|
|
5394
|
+
}
|
|
5240
5395
|
case "file":
|
|
5241
5396
|
return new FileSchema(serialized.options, serialized.opt);
|
|
5242
5397
|
case "image":
|
|
@@ -5545,4 +5700,4 @@ function tryJsonParse(str) {
|
|
|
5545
5700
|
}
|
|
5546
5701
|
}
|
|
5547
5702
|
|
|
5548
|
-
export { ArraySchema as A, BooleanSchema as B, DEFAULT_CONTENT_HOST as D, FATAL_ERROR_TYPES as F, GenericSelector as G, Internal as I, KeyOfSchema as K, LiteralSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RecordSchema as R, Schema as S, UnionSchema as U, VAL_EXTENSION as V, _typeof as _, _slicedToArray as a, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, DEFAULT_VAL_REMOTE_HOST as f, FILE_REF_PROP as g, FILE_REF_SUBTYPE_TAG as h, initVal as i, derefPatch as j, StringSchema as k, ImageSchema as l, modules as m, FileSchema as n, DateSchema as o,
|
|
5703
|
+
export { ArraySchema as A, BooleanSchema as B, DEFAULT_CONTENT_HOST as D, FATAL_ERROR_TYPES as F, GenericSelector as G, Internal as I, KeyOfSchema as K, LiteralSchema as L, ModuleFilePathSep as M, NumberSchema as N, ObjectSchema as O, PatchError as P, RecordSchema as R, Schema as S, UnionSchema as U, VAL_EXTENSION as V, _typeof as _, _slicedToArray as a, _createClass as b, _classCallCheck as c, _toConsumableArray as d, DEFAULT_APP_HOST as e, DEFAULT_VAL_REMOTE_HOST as f, FILE_REF_PROP as g, FILE_REF_SUBTYPE_TAG as h, initVal as i, derefPatch as j, StringSchema as k, ImageSchema as l, modules as m, FileSchema as n, DateSchema as o, RouteSchema as p, RichTextSchema as q, deserializeSchema as r, splitModuleFilePathAndModulePath as s };
|
|
@@ -447,8 +447,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
447
447
|
if (src[VAL_EXTENSION] !== "file") {
|
|
448
448
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
449
449
|
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
450
|
-
value: src
|
|
451
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
450
|
+
value: src
|
|
452
451
|
}]));
|
|
453
452
|
}
|
|
454
453
|
var _ref8 = this.options || {},
|
|
@@ -458,8 +457,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
458
457
|
if (accept && mimeType && !mimeType.includes("/")) {
|
|
459
458
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
460
459
|
message: "Invalid mime type format. Got: ".concat(mimeType),
|
|
461
|
-
value: src
|
|
462
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
460
|
+
value: src
|
|
463
461
|
}]));
|
|
464
462
|
}
|
|
465
463
|
if (accept && mimeType && mimeType.includes("/")) {
|
|
@@ -479,8 +477,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
479
477
|
if (!isValidMimeType) {
|
|
480
478
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
481
479
|
message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
|
|
482
|
-
value: src
|
|
483
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
480
|
+
value: src
|
|
484
481
|
}]));
|
|
485
482
|
}
|
|
486
483
|
}
|
|
@@ -488,15 +485,13 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
488
485
|
if (!fileMimeType) {
|
|
489
486
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
490
487
|
message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
|
|
491
|
-
value: src
|
|
492
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
488
|
+
value: src
|
|
493
489
|
}]));
|
|
494
490
|
}
|
|
495
491
|
if (fileMimeType !== mimeType) {
|
|
496
492
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
497
493
|
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
498
|
-
value: src
|
|
499
|
-
fixes: ["file:change-extension", "file:check-metadata"]
|
|
494
|
+
value: src
|
|
500
495
|
}]));
|
|
501
496
|
}
|
|
502
497
|
if (src.metadata) {
|
|
@@ -1785,8 +1780,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1785
1780
|
if (src[VAL_EXTENSION] !== "file") {
|
|
1786
1781
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1787
1782
|
message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
1788
|
-
value: src
|
|
1789
|
-
fixes: ["image:change-extension", "image:check-metadata"]
|
|
1783
|
+
value: src
|
|
1790
1784
|
}]));
|
|
1791
1785
|
}
|
|
1792
1786
|
var _ref8 = this.options || {},
|
|
@@ -3762,6 +3756,157 @@ var date = function date(options) {
|
|
|
3762
3756
|
return new DateSchema(options);
|
|
3763
3757
|
};
|
|
3764
3758
|
|
|
3759
|
+
var RouteSchema = /*#__PURE__*/function (_Schema) {
|
|
3760
|
+
function RouteSchema(options) {
|
|
3761
|
+
var _this;
|
|
3762
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3763
|
+
var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
3764
|
+
_classCallCheck(this, RouteSchema);
|
|
3765
|
+
_this = _callSuper(this, RouteSchema);
|
|
3766
|
+
_this.options = options;
|
|
3767
|
+
_this.opt = opt;
|
|
3768
|
+
_this.customValidateFunctions = customValidateFunctions;
|
|
3769
|
+
return _this;
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
/**
|
|
3773
|
+
* Specify a pattern for which routes are allowed.
|
|
3774
|
+
*
|
|
3775
|
+
* Semantics:
|
|
3776
|
+
* - If only include is set: route must match include pattern
|
|
3777
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3778
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3779
|
+
*
|
|
3780
|
+
* @example
|
|
3781
|
+
* s.route().include(/^\/(home|about|contact)$/) // Only these specific routes
|
|
3782
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3783
|
+
*/
|
|
3784
|
+
_inherits(RouteSchema, _Schema);
|
|
3785
|
+
return _createClass(RouteSchema, [{
|
|
3786
|
+
key: "include",
|
|
3787
|
+
value: function include(pattern) {
|
|
3788
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3789
|
+
include: pattern
|
|
3790
|
+
}), this.opt, this.customValidateFunctions);
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
/**
|
|
3794
|
+
* Specify a pattern for which routes should be excluded.
|
|
3795
|
+
*
|
|
3796
|
+
* Semantics:
|
|
3797
|
+
* - If only include is set: route must match include pattern
|
|
3798
|
+
* - If only exclude is set: route must NOT match exclude pattern
|
|
3799
|
+
* - If both are set: route must match include AND must NOT match exclude
|
|
3800
|
+
*
|
|
3801
|
+
* @example
|
|
3802
|
+
* s.route().exclude(/^\/admin/) // Exclude all admin routes
|
|
3803
|
+
* s.route().include(/^\/api\//).exclude(/^\/api\/internal\//) // API routes except internal
|
|
3804
|
+
*/
|
|
3805
|
+
}, {
|
|
3806
|
+
key: "exclude",
|
|
3807
|
+
value: function exclude(pattern) {
|
|
3808
|
+
return new RouteSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
3809
|
+
exclude: pattern
|
|
3810
|
+
}), this.opt, this.customValidateFunctions);
|
|
3811
|
+
}
|
|
3812
|
+
}, {
|
|
3813
|
+
key: "validate",
|
|
3814
|
+
value: function validate(validationFunction) {
|
|
3815
|
+
return new RouteSchema(this.options, this.opt, this.customValidateFunctions.concat(validationFunction));
|
|
3816
|
+
}
|
|
3817
|
+
}, {
|
|
3818
|
+
key: "executeValidate",
|
|
3819
|
+
value: function executeValidate(path, src) {
|
|
3820
|
+
var _this$options, _this$options2;
|
|
3821
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
3822
|
+
path: path
|
|
3823
|
+
});
|
|
3824
|
+
if (this.opt && (src === null || src === undefined)) {
|
|
3825
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
3826
|
+
}
|
|
3827
|
+
if (typeof src !== "string") {
|
|
3828
|
+
return _defineProperty({}, path, [{
|
|
3829
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3830
|
+
value: src
|
|
3831
|
+
}]);
|
|
3832
|
+
}
|
|
3833
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
3834
|
+
fixes: ["router:check-route"],
|
|
3835
|
+
message: "Did not validate route (router). This error (router:check-route) should typically be processed by Val internally. Seeing this error most likely means you have a Val version mismatch.",
|
|
3836
|
+
value: {
|
|
3837
|
+
route: src,
|
|
3838
|
+
sourcePath: path,
|
|
3839
|
+
include: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.include,
|
|
3840
|
+
exclude: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.exclude
|
|
3841
|
+
}
|
|
3842
|
+
}]));
|
|
3843
|
+
}
|
|
3844
|
+
}, {
|
|
3845
|
+
key: "executeAssert",
|
|
3846
|
+
value: function executeAssert(path, src) {
|
|
3847
|
+
if (this.opt && src === null) {
|
|
3848
|
+
return {
|
|
3849
|
+
success: true,
|
|
3850
|
+
data: src
|
|
3851
|
+
};
|
|
3852
|
+
}
|
|
3853
|
+
if (typeof src === "string") {
|
|
3854
|
+
return {
|
|
3855
|
+
success: true,
|
|
3856
|
+
data: src
|
|
3857
|
+
};
|
|
3858
|
+
}
|
|
3859
|
+
return {
|
|
3860
|
+
success: false,
|
|
3861
|
+
errors: _defineProperty({}, path, [{
|
|
3862
|
+
message: "Expected 'string', got '".concat(_typeof(src), "'"),
|
|
3863
|
+
typeError: true
|
|
3864
|
+
}])
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
}, {
|
|
3868
|
+
key: "nullable",
|
|
3869
|
+
value: function nullable() {
|
|
3870
|
+
return new RouteSchema(this.options, true, this.customValidateFunctions);
|
|
3871
|
+
}
|
|
3872
|
+
}, {
|
|
3873
|
+
key: "executeSerialize",
|
|
3874
|
+
value: function executeSerialize() {
|
|
3875
|
+
var _this$options3, _this$options4, _this$customValidateF, _this$customValidateF2;
|
|
3876
|
+
return {
|
|
3877
|
+
type: "route",
|
|
3878
|
+
options: {
|
|
3879
|
+
include: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.include) && {
|
|
3880
|
+
source: this.options.include.source,
|
|
3881
|
+
flags: this.options.include.flags
|
|
3882
|
+
},
|
|
3883
|
+
exclude: ((_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.exclude) && {
|
|
3884
|
+
source: this.options.exclude.source,
|
|
3885
|
+
flags: this.options.exclude.flags
|
|
3886
|
+
},
|
|
3887
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
|
|
3888
|
+
},
|
|
3889
|
+
opt: this.opt,
|
|
3890
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF2 = this.customValidateFunctions) === null || _this$customValidateF2 === void 0 ? void 0 : _this$customValidateF2.length) > 0
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
}, {
|
|
3894
|
+
key: "executeRender",
|
|
3895
|
+
value: function executeRender() {
|
|
3896
|
+
return {};
|
|
3897
|
+
}
|
|
3898
|
+
}]);
|
|
3899
|
+
}(Schema);
|
|
3900
|
+
var route = function route(options) {
|
|
3901
|
+
return new RouteSchema(options);
|
|
3902
|
+
};
|
|
3903
|
+
|
|
3904
|
+
function router(router, item) {
|
|
3905
|
+
var keySchema = string();
|
|
3906
|
+
var recordSchema = new RecordSchema(item, false, [], router, keySchema);
|
|
3907
|
+
return recordSchema;
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3765
3910
|
// import type { F } from "ts-toolbelt";
|
|
3766
3911
|
// import { i18n, I18n } from "./schema/future/i18n";
|
|
3767
3912
|
// import { oneOf } from "./schema/future/oneOf";
|
|
@@ -3785,7 +3930,9 @@ function initSchema() {
|
|
|
3785
3930
|
keyOf: keyOf,
|
|
3786
3931
|
record: record,
|
|
3787
3932
|
file: file,
|
|
3788
|
-
date: date
|
|
3933
|
+
date: date,
|
|
3934
|
+
route: route,
|
|
3935
|
+
router: router
|
|
3789
3936
|
// i18n: i18n(locales),
|
|
3790
3937
|
};
|
|
3791
3938
|
}
|
|
@@ -5239,6 +5386,14 @@ function deserializeSchema(serialized) {
|
|
|
5239
5386
|
return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null);
|
|
5240
5387
|
case "keyOf":
|
|
5241
5388
|
return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt);
|
|
5389
|
+
case "route":
|
|
5390
|
+
{
|
|
5391
|
+
var routeOptions = serialized.options ? {
|
|
5392
|
+
include: serialized.options.include ? new RegExp(serialized.options.include.source, serialized.options.include.flags) : undefined,
|
|
5393
|
+
exclude: serialized.options.exclude ? new RegExp(serialized.options.exclude.source, serialized.options.exclude.flags) : undefined
|
|
5394
|
+
} : undefined;
|
|
5395
|
+
return new RouteSchema(routeOptions, serialized.opt);
|
|
5396
|
+
}
|
|
5242
5397
|
case "file":
|
|
5243
5398
|
return new FileSchema(serialized.options, serialized.opt);
|
|
5244
5399
|
case "image":
|
|
@@ -5568,6 +5723,7 @@ exports.ObjectSchema = ObjectSchema;
|
|
|
5568
5723
|
exports.PatchError = PatchError;
|
|
5569
5724
|
exports.RecordSchema = RecordSchema;
|
|
5570
5725
|
exports.RichTextSchema = RichTextSchema;
|
|
5726
|
+
exports.RouteSchema = RouteSchema;
|
|
5571
5727
|
exports.Schema = Schema;
|
|
5572
5728
|
exports.StringSchema = StringSchema;
|
|
5573
5729
|
exports.UnionSchema = UnionSchema;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_valbuildCore = require('./index-
|
|
5
|
+
var dist_valbuildCore = require('./index-3f815afd.cjs.dev.js');
|
|
6
6
|
require('./result-bb1f436e.cjs.dev.js');
|
|
7
7
|
|
|
8
8
|
|
|
@@ -27,6 +27,7 @@ exports.NumberSchema = dist_valbuildCore.NumberSchema;
|
|
|
27
27
|
exports.ObjectSchema = dist_valbuildCore.ObjectSchema;
|
|
28
28
|
exports.RecordSchema = dist_valbuildCore.RecordSchema;
|
|
29
29
|
exports.RichTextSchema = dist_valbuildCore.RichTextSchema;
|
|
30
|
+
exports.RouteSchema = dist_valbuildCore.RouteSchema;
|
|
30
31
|
exports.Schema = dist_valbuildCore.Schema;
|
|
31
32
|
exports.StringSchema = dist_valbuildCore.StringSchema;
|
|
32
33
|
exports.UnionSchema = dist_valbuildCore.UnionSchema;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_valbuildCore = require('./index-
|
|
5
|
+
var dist_valbuildCore = require('./index-55f6a997.cjs.prod.js');
|
|
6
6
|
require('./result-787e35f6.cjs.prod.js');
|
|
7
7
|
|
|
8
8
|
|
|
@@ -27,6 +27,7 @@ exports.NumberSchema = dist_valbuildCore.NumberSchema;
|
|
|
27
27
|
exports.ObjectSchema = dist_valbuildCore.ObjectSchema;
|
|
28
28
|
exports.RecordSchema = dist_valbuildCore.RecordSchema;
|
|
29
29
|
exports.RichTextSchema = dist_valbuildCore.RichTextSchema;
|
|
30
|
+
exports.RouteSchema = dist_valbuildCore.RouteSchema;
|
|
30
31
|
exports.Schema = dist_valbuildCore.Schema;
|
|
31
32
|
exports.StringSchema = dist_valbuildCore.StringSchema;
|
|
32
33
|
exports.UnionSchema = dist_valbuildCore.UnionSchema;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema,
|
|
1
|
+
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, q as RichTextSchema, p as RouteSchema, S as Schema, k as StringSchema, U as UnionSchema, V as VAL_EXTENSION, j as derefPatch, r as deserializeSchema, i as initVal, m as modules } from './index-52848948.esm.js';
|
|
2
2
|
import './result-daff1cae.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-3f815afd.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-55f6a997.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-52848948.esm.js';
|
|
2
|
+
export { P as PatchError } from '../../dist/index-52848948.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-daff1cae.esm.js';
|
|
4
4
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
|
5
5
|
|