@tsed/schema 7.10.1 → 7.11.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/lib/browser/schema.umd.min.js +1 -1
- package/lib/browser/schema.umd.min.js.map +1 -1
- package/lib/cjs/decorators/collections/maxItems.js +4 -3
- package/lib/cjs/decorators/collections/maxItems.js.map +1 -1
- package/lib/cjs/decorators/collections/maxProperties.js +4 -3
- package/lib/cjs/decorators/collections/maxProperties.js.map +1 -1
- package/lib/cjs/decorators/collections/minItems.js +4 -3
- package/lib/cjs/decorators/collections/minItems.js.map +1 -1
- package/lib/cjs/decorators/collections/minProperties.js +4 -3
- package/lib/cjs/decorators/collections/minProperties.js.map +1 -1
- package/lib/cjs/decorators/collections/uniqueItems.js +4 -3
- package/lib/cjs/decorators/collections/uniqueItems.js.map +1 -1
- package/lib/cjs/decorators/common/defaultMsg.js +41 -0
- package/lib/cjs/decorators/common/defaultMsg.js.map +1 -0
- package/lib/cjs/decorators/common/enum.js +100 -2
- package/lib/cjs/decorators/common/enum.js.map +1 -1
- package/lib/cjs/decorators/common/errorMsg.js +20 -0
- package/lib/cjs/decorators/common/errorMsg.js.map +1 -0
- package/lib/cjs/decorators/common/exclusiveMaximum.js +4 -3
- package/lib/cjs/decorators/common/exclusiveMaximum.js.map +1 -1
- package/lib/cjs/decorators/common/exclusiveMinimum.js +4 -3
- package/lib/cjs/decorators/common/exclusiveMinimum.js.map +1 -1
- package/lib/cjs/decorators/common/format.js +28 -27
- package/lib/cjs/decorators/common/format.js.map +1 -1
- package/lib/cjs/decorators/common/maxLength.js +4 -3
- package/lib/cjs/decorators/common/maxLength.js.map +1 -1
- package/lib/cjs/decorators/common/maximum.js +5 -7
- package/lib/cjs/decorators/common/maximum.js.map +1 -1
- package/lib/cjs/decorators/common/minLength.js +4 -3
- package/lib/cjs/decorators/common/minLength.js.map +1 -1
- package/lib/cjs/decorators/common/minimum.js +5 -7
- package/lib/cjs/decorators/common/minimum.js.map +1 -1
- package/lib/cjs/decorators/common/multipleOf.js +4 -3
- package/lib/cjs/decorators/common/multipleOf.js.map +1 -1
- package/lib/cjs/decorators/common/pattern.js +4 -3
- package/lib/cjs/decorators/common/pattern.js.map +1 -1
- package/lib/cjs/decorators/common/required.js +3 -3
- package/lib/cjs/decorators/common/required.js.map +1 -1
- package/lib/cjs/decorators/common/typeError.js +18 -0
- package/lib/cjs/decorators/common/typeError.js.map +1 -0
- package/lib/cjs/index.js +4 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils/withErrorMsg.js +18 -0
- package/lib/cjs/utils/withErrorMsg.js.map +1 -0
- package/lib/esm/decorators/collections/maxItems.js +4 -2
- package/lib/esm/decorators/collections/maxItems.js.map +1 -1
- package/lib/esm/decorators/collections/maxProperties.js +4 -2
- package/lib/esm/decorators/collections/maxProperties.js.map +1 -1
- package/lib/esm/decorators/collections/minItems.js +4 -2
- package/lib/esm/decorators/collections/minItems.js.map +1 -1
- package/lib/esm/decorators/collections/minProperties.js +4 -2
- package/lib/esm/decorators/collections/minProperties.js.map +1 -1
- package/lib/esm/decorators/collections/uniqueItems.js +4 -2
- package/lib/esm/decorators/collections/uniqueItems.js.map +1 -1
- package/lib/esm/decorators/common/defaultMsg.js +37 -0
- package/lib/esm/decorators/common/defaultMsg.js.map +1 -0
- package/lib/esm/decorators/common/enum.js +100 -1
- package/lib/esm/decorators/common/enum.js.map +1 -1
- package/lib/esm/decorators/common/errorMsg.js +16 -0
- package/lib/esm/decorators/common/errorMsg.js.map +1 -0
- package/lib/esm/decorators/common/exclusiveMaximum.js +4 -2
- package/lib/esm/decorators/common/exclusiveMaximum.js.map +1 -1
- package/lib/esm/decorators/common/exclusiveMinimum.js +4 -2
- package/lib/esm/decorators/common/exclusiveMinimum.js.map +1 -1
- package/lib/esm/decorators/common/format.js +22 -14
- package/lib/esm/decorators/common/format.js.map +1 -1
- package/lib/esm/decorators/common/maxLength.js +4 -2
- package/lib/esm/decorators/common/maxLength.js.map +1 -1
- package/lib/esm/decorators/common/maximum.js +5 -5
- package/lib/esm/decorators/common/maximum.js.map +1 -1
- package/lib/esm/decorators/common/minLength.js +4 -2
- package/lib/esm/decorators/common/minLength.js.map +1 -1
- package/lib/esm/decorators/common/minimum.js +5 -5
- package/lib/esm/decorators/common/minimum.js.map +1 -1
- package/lib/esm/decorators/common/multipleOf.js +4 -2
- package/lib/esm/decorators/common/multipleOf.js.map +1 -1
- package/lib/esm/decorators/common/pattern.js +4 -2
- package/lib/esm/decorators/common/pattern.js.map +1 -1
- package/lib/esm/decorators/common/required.js +3 -2
- package/lib/esm/decorators/common/required.js.map +1 -1
- package/lib/esm/decorators/common/typeError.js +14 -0
- package/lib/esm/decorators/common/typeError.js.map +1 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils/withErrorMsg.js +14 -0
- package/lib/esm/utils/withErrorMsg.js.map +1 -0
- package/lib/types/decorators/collections/maxItems.d.ts +2 -1
- package/lib/types/decorators/collections/maxProperties.d.ts +2 -1
- package/lib/types/decorators/collections/minItems.d.ts +2 -1
- package/lib/types/decorators/collections/minProperties.d.ts +2 -1
- package/lib/types/decorators/collections/uniqueItems.d.ts +2 -1
- package/lib/types/decorators/common/defaultMsg.d.ts +32 -0
- package/lib/types/decorators/common/enum.d.ts +4 -1
- package/lib/types/decorators/common/errorMsg.d.ts +8 -0
- package/lib/types/decorators/common/exclusiveMaximum.d.ts +2 -1
- package/lib/types/decorators/common/exclusiveMinimum.d.ts +2 -1
- package/lib/types/decorators/common/format.d.ts +14 -7
- package/lib/types/decorators/common/maxLength.d.ts +2 -1
- package/lib/types/decorators/common/maximum.d.ts +3 -2
- package/lib/types/decorators/common/minLength.d.ts +2 -1
- package/lib/types/decorators/common/minimum.d.ts +3 -2
- package/lib/types/decorators/common/multipleOf.d.ts +2 -1
- package/lib/types/decorators/common/pattern.d.ts +2 -1
- package/lib/types/decorators/common/required.d.ts +1 -1
- package/lib/types/decorators/common/typeError.d.ts +8 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/utils/withErrorMsg.d.ts +6 -0
- package/package.json +6 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
* An array instance is valid against `minItems` if its size is greater than, or equal to, the value of this keyword.
|
|
@@ -48,13 +49,14 @@ import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
|
48
49
|
* @schema
|
|
49
50
|
* @input
|
|
50
51
|
* @collections
|
|
52
|
+
* @ajv-errors
|
|
51
53
|
*/
|
|
52
|
-
export
|
|
54
|
+
export const MinItems = withErrorMsg("minItems", (minItems) => {
|
|
53
55
|
if (minItems < 0) {
|
|
54
56
|
throw new Error("The value of minItems MUST be a non-negative integer.");
|
|
55
57
|
}
|
|
56
58
|
return JsonEntityFn((storedJson) => {
|
|
57
59
|
storedJson.schema.minItems(minItems);
|
|
58
60
|
});
|
|
59
|
-
}
|
|
61
|
+
});
|
|
60
62
|
//# sourceMappingURL=minItems.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minItems.js","sourceRoot":"","sources":["../../../../src/decorators/collections/minItems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"minItems.js","sourceRoot":"","sources":["../../../../src/decorators/collections/minItems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC,UAAU,EAAE,CAAC,QAAgB,EAAE,EAAE;IACpE,IAAI,QAAQ,GAAG,CAAC,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;KAC1E;IAED,OAAO,YAAY,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"../common/jsonEntityFn\";\n\n/**\n * An array instance is valid against `minItems` if its size is greater than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value `minItems` MUST be a non-negative integer.\n * :::\n *\n * ::: tip\n * Omitting this keyword has the same behavior as a value of 0.\n * :::\n *\n * ::: warning\n * For v6 user, use @@MinItems@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n *\n * ```typescript\n * class Model {\n * @CollectionOf(String)\n * @MinItems(10)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"minItems\": 10,\n * \"items\": {\n * \"type\": \"string\"\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {number} minItems\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @collections\n * @ajv-errors\n */\nexport const MinItems = withErrorMsg(\"minItems\", (minItems: number) => {\n if (minItems < 0) {\n throw new Error(\"The value of minItems MUST be a non-negative integer.\");\n }\n\n return JsonEntityFn((storedJson) => {\n storedJson.schema.minItems(minItems);\n });\n});\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
* An object instance is valid against `minProperties` if its number of properties is less than, or equal to, the value of this keyword.
|
|
@@ -66,13 +67,14 @@ import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
|
66
67
|
* @schema
|
|
67
68
|
* @input
|
|
68
69
|
* @collections
|
|
70
|
+
* @ajv-errors
|
|
69
71
|
*/
|
|
70
|
-
export
|
|
72
|
+
export const MinProperties = withErrorMsg("minProperties", (minProperties) => {
|
|
71
73
|
if (minProperties < 0) {
|
|
72
74
|
throw new Error("The value of minProperties MUST be a non-negative integer.");
|
|
73
75
|
}
|
|
74
76
|
return JsonEntityFn((store) => {
|
|
75
77
|
store.isCollection ? store.schema.minProperties(minProperties) : store.itemSchema.minProperties(minProperties);
|
|
76
78
|
});
|
|
77
|
-
}
|
|
79
|
+
});
|
|
78
80
|
//# sourceMappingURL=minProperties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minProperties.js","sourceRoot":"","sources":["../../../../src/decorators/collections/minProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"minProperties.js","sourceRoot":"","sources":["../../../../src/decorators/collections/minProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC,eAAe,EAAE,CAAC,aAAqB,EAAE,EAAE;IACnF,IAAI,aAAa,GAAG,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;KAC/E;IAED,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"../common/jsonEntityFn\";\n\n/**\n * An object instance is valid against `minProperties` if its number of properties is less than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value of this keyword MUST be a non-negative integer.\n * :::\n *\n * ::: warning\n * For v6 user, use @@MinProperties@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### On prop\n * ```typescript\n * class Model {\n * @MinProperties(10)\n * property: any;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"any\",\n * \"minProperties\": 10\n * }\n * }\n * }\n * ```\n *\n * ### On class\n *\n * ```typescript\n * @MinProperties(10)\n * class Model {\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"minProperties\": 10\n * }\n * ```\n *\n * ### On Parameter\n *\n * ```typescript\n *\n * class Model {\n * method(@Any() @MinProperties(10) obj: any){}\n * }\n * ```\n *\n * @param {number} minProperties The minimum properties allowed on the object.\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @collections\n * @ajv-errors\n */\nexport const MinProperties = withErrorMsg(\"minProperties\", (minProperties: number) => {\n if (minProperties < 0) {\n throw new Error(\"The value of minProperties MUST be a non-negative integer.\");\n }\n\n return JsonEntityFn((store) => {\n store.isCollection ? store.schema.minProperties(minProperties) : store.itemSchema.minProperties(minProperties);\n });\n});\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
* If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.
|
|
@@ -47,10 +48,11 @@ import { JsonEntityFn } from "../common/jsonEntityFn.js";
|
|
|
47
48
|
* @schema
|
|
48
49
|
* @input
|
|
49
50
|
* @collections
|
|
51
|
+
* @ajv-errors
|
|
50
52
|
*/
|
|
51
|
-
export
|
|
53
|
+
export const UniqueItems = withErrorMsg("uniqueItems", (uniqueItems = true) => {
|
|
52
54
|
return JsonEntityFn((store) => {
|
|
53
55
|
store.schema.uniqueItems(uniqueItems);
|
|
54
56
|
});
|
|
55
|
-
}
|
|
57
|
+
});
|
|
56
58
|
//# sourceMappingURL=uniqueItems.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueItems.js","sourceRoot":"","sources":["../../../../src/decorators/collections/uniqueItems.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"uniqueItems.js","sourceRoot":"","sources":["../../../../src/decorators/collections/uniqueItems.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,EAAE,CAAC,cAAuB,IAAI,EAAE,EAAE;IACrF,OAAO,YAAY,CAAC,CAAC,KAAsB,EAAE,EAAE;QAC7C,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"../common/jsonEntityFn\";\n\n/**\n * If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.\n *\n * ::: warning\n * For v6 user, use @@UniqueItems@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n *\n * ```typescript\n * class Model {\n * @UniqueItems() // default true\n * property: number[];\n * }\n * ```\n *\n * * ```typescript\n * class Model {\n * @CollectionOf(String)\n * @UniqueItems()\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"uniqueItems\": true,\n * \"items\": {\n * \"type\": \"string\"\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {boolean} uniqueItems\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @collections\n * @ajv-errors\n */\nexport const UniqueItems = withErrorMsg(\"uniqueItems\", (uniqueItems: boolean = true) => {\n return JsonEntityFn((store: JsonEntityStore) => {\n store.schema.uniqueItems(uniqueItems);\n });\n});\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useDecorators } from "@tsed/core";
|
|
2
|
+
import { ErrorMsg } from "./errorMsg.js";
|
|
3
|
+
/**
|
|
4
|
+
* Set default error message.
|
|
5
|
+
*
|
|
6
|
+
* ## Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @DefaultMessage("foo should be a string")
|
|
10
|
+
* class Model {
|
|
11
|
+
* property: number;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Will produce:
|
|
16
|
+
*
|
|
17
|
+
* ```json
|
|
18
|
+
* {
|
|
19
|
+
* "type": "object",
|
|
20
|
+
* "properties": {
|
|
21
|
+
* "property": "number"
|
|
22
|
+
* }
|
|
23
|
+
* "errorMessage": {
|
|
24
|
+
* "_": "foo should be a string"
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @decorator
|
|
30
|
+
* @validation
|
|
31
|
+
* @swagger
|
|
32
|
+
* @schema
|
|
33
|
+
*/
|
|
34
|
+
export function DefaultMsg(message) {
|
|
35
|
+
return useDecorators(ErrorMsg({ _: message }));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=defaultMsg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultMsg.js","sourceRoot":"","sources":["../../../../src/decorators/common/defaultMsg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,OAAO,aAAa,CAAC,QAAQ,CAAC,EAAC,CAAC,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {ErrorMsg} from \"./errorMsg\";\n\n/**\n * Set default error message.\n *\n * ## Example\n *\n * ```typescript\n * @DefaultMessage(\"foo should be a string\")\n * class Model {\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": \"number\"\n * }\n * \"errorMessage\": {\n * \"_\": \"foo should be a string\"\n * }\n * }\n * ```\n *\n * @decorator\n * @validation\n * @swagger\n * @schema\n */\nexport function DefaultMsg(message: string): ClassDecorator {\n return useDecorators(ErrorMsg({_: message}));\n}\n"]}
|
|
@@ -1,7 +1,106 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
|
-
|
|
3
|
+
function EnumFn(enumValue, ...enumValues) {
|
|
3
4
|
return JsonEntityFn((store) => {
|
|
4
5
|
store.itemSchema.enum(enumValue, ...enumValues);
|
|
5
6
|
});
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* The enum keyword is used to restrict a value to a fixed set of values.
|
|
10
|
+
* It must be an array with at least one element, where each element is unique.
|
|
11
|
+
*
|
|
12
|
+
* Elements in the array might be of any value, including null.
|
|
13
|
+
*
|
|
14
|
+
* ::: warning
|
|
15
|
+
* For v6 user, use @@Enum@@ from @tsed/schema instead of @tsed/common.
|
|
16
|
+
* :::
|
|
17
|
+
*
|
|
18
|
+
* ## Example
|
|
19
|
+
* ### With primitive type
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class Model {
|
|
23
|
+
* @Enum("value1", "value2")
|
|
24
|
+
* property: "value1" | "value2";
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Will produce:
|
|
29
|
+
*
|
|
30
|
+
* ```json
|
|
31
|
+
* {
|
|
32
|
+
* "type": "object",
|
|
33
|
+
* "properties": {
|
|
34
|
+
* "property": {
|
|
35
|
+
* "type": "string",
|
|
36
|
+
* "enum": ["value1", "value2"]
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### With array type
|
|
43
|
+
*
|
|
44
|
+
* ```typescript
|
|
45
|
+
* class Model {
|
|
46
|
+
* @Enum("value1", "value2")
|
|
47
|
+
* property: ("value1" | "value2")[];
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* Will produce:
|
|
52
|
+
*
|
|
53
|
+
* ```json
|
|
54
|
+
* {
|
|
55
|
+
* "type": "object",
|
|
56
|
+
* "properties": {
|
|
57
|
+
* "property": {
|
|
58
|
+
* "type": "array",
|
|
59
|
+
* "items": {
|
|
60
|
+
* "type": "string",
|
|
61
|
+
* "enum": ["value1", "value2"]
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ### With Typescript Enum
|
|
69
|
+
*
|
|
70
|
+
* ```typescript
|
|
71
|
+
* enum SomeEnum {
|
|
72
|
+
* ENUM_1 = "enum1",
|
|
73
|
+
* ENUM_2 = "enum2"
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* class Model {
|
|
77
|
+
* @Enum(SomeEnum)
|
|
78
|
+
* property: SomeEnum;
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* Will produce:
|
|
83
|
+
*
|
|
84
|
+
* ```json
|
|
85
|
+
* {
|
|
86
|
+
* "type": "object",
|
|
87
|
+
* "properties": {
|
|
88
|
+
* "property": {
|
|
89
|
+
* "type": "string",
|
|
90
|
+
* "enum": ["enum1", "enum2"]
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param {string | number | boolean | {}} enumValue
|
|
97
|
+
* @param enumValues
|
|
98
|
+
* @decorator
|
|
99
|
+
* @validation
|
|
100
|
+
* @swagger
|
|
101
|
+
* @schema
|
|
102
|
+
* @input
|
|
103
|
+
* @ajv-errors
|
|
104
|
+
*/
|
|
105
|
+
export const Enum = withErrorMsg("enum", EnumFn);
|
|
7
106
|
//# sourceMappingURL=enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../src/decorators/common/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../src/decorators/common/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,SAAS,MAAM,CAAC,SAAgC,EAAE,GAAG,UAA6B;IAChF,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,UAAU,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import type {JSONSchema6Type} from \"json-schema\";\nimport {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\nfunction EnumFn(...enumValues: (JSONSchema6Type | any)[]): Function;\nfunction EnumFn(enumValue: JSONSchema6Type | any, ...enumValues: JSONSchema6Type[]) {\n return JsonEntityFn((store) => {\n store.itemSchema.enum(enumValue, ...enumValues);\n });\n}\n\n/**\n * The enum keyword is used to restrict a value to a fixed set of values.\n * It must be an array with at least one element, where each element is unique.\n *\n * Elements in the array might be of any value, including null.\n *\n * ::: warning\n * For v6 user, use @@Enum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Enum(\"value1\", \"value2\")\n * property: \"value1\" | \"value2\";\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"enum\": [\"value1\", \"value2\"]\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Enum(\"value1\", \"value2\")\n * property: (\"value1\" | \"value2\")[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"enum\": [\"value1\", \"value2\"]\n * }\n * }\n * }\n * }\n * ```\n *\n * ### With Typescript Enum\n *\n * ```typescript\n * enum SomeEnum {\n * ENUM_1 = \"enum1\",\n * ENUM_2 = \"enum2\"\n * }\n *\n * class Model {\n * @Enum(SomeEnum)\n * property: SomeEnum;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"enum\": [\"enum1\", \"enum2\"]\n * }\n * }\n * }\n * ```\n *\n * @param {string | number | boolean | {}} enumValue\n * @param enumValues\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\n\nexport const Enum = withErrorMsg(\"enum\", EnumFn);\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new custom formats validator
|
|
4
|
+
* @param name
|
|
5
|
+
* @param options
|
|
6
|
+
* @decorator
|
|
7
|
+
* @ajv
|
|
8
|
+
*/
|
|
9
|
+
export function ErrorMsg(obj) {
|
|
10
|
+
return JsonEntityFn((store) => {
|
|
11
|
+
// since errorMessage is a custom key, it is prefixed with a # to avoid conflict with JSON Schema keywords
|
|
12
|
+
const errorMessage = store.parentSchema.get("#errorMessage") || {};
|
|
13
|
+
store.parentSchema.customKey("errorMessage", { ...errorMessage, ...obj });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errorMsg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMsg.js","sourceRoot":"","sources":["../../../../src/decorators/common/errorMsg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAA2B;IAClD,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,0GAA0G;QAC1G,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QACnE,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,cAAc,EAAE,EAAC,GAAG,YAAY,EAAE,GAAG,GAAG,EAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * Create a new custom formats validator\n * @param name\n * @param options\n * @decorator\n * @ajv\n */\nexport function ErrorMsg(obj: Record<string, string>) {\n return JsonEntityFn((store) => {\n // since errorMessage is a custom key, it is prefixed with a # to avoid conflict with JSON Schema keywords\n const errorMessage = store.parentSchema.get(\"#errorMessage\") || {};\n store.parentSchema.customKey(\"errorMessage\", {...errorMessage, ...obj});\n });\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { Maximum } from "./maximum.js";
|
|
2
3
|
/**
|
|
3
4
|
* The value of `exclusiveMaximum` MUST be number, representing an exclusive upper limit for a numeric instance.
|
|
@@ -66,8 +67,9 @@ import { Maximum } from "./maximum.js";
|
|
|
66
67
|
* @swagger
|
|
67
68
|
* @schema
|
|
68
69
|
* @input
|
|
70
|
+
* @ajv-errors
|
|
69
71
|
*/
|
|
70
|
-
export
|
|
72
|
+
export const ExclusiveMaximum = withErrorMsg("exclusiveMaximum", (maximum, exclusiveMaximum = true) => {
|
|
71
73
|
return Maximum(maximum, exclusiveMaximum);
|
|
72
|
-
}
|
|
74
|
+
});
|
|
73
75
|
//# sourceMappingURL=exclusiveMaximum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusiveMaximum.js","sourceRoot":"","sources":["../../../../src/decorators/common/exclusiveMaximum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"exclusiveMaximum.js","sourceRoot":"","sources":["../../../../src/decorators/common/exclusiveMaximum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC,kBAAkB,EAAE,CAAC,OAAe,EAAE,mBAA4B,IAAI,EAAE,EAAE;IACrH,OAAO,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {Maximum} from \"./maximum\";\n\n/**\n * The value of `exclusiveMaximum` MUST be number, representing an exclusive upper limit for a numeric instance.\n *\n * If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to) `exclusiveMaximum`.\n *\n * ::: warning\n * For v6 user, use @@ExclusiveMaximum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @ExclusiveMaximum(10)\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"number\",\n * \"exclusiveMaximum\": 10\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @ExclusiveMaximum(10)\n * @CollectionOf(Number)\n * property: number[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"number\",\n * \"exclusiveMaximum\": 10\n * }\n * }\n * }\n * }\n * ```\n *\n * @param maximum\n * @param {boolean} exclusiveMaximum\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\nexport const ExclusiveMaximum = withErrorMsg(\"exclusiveMaximum\", (maximum: number, exclusiveMaximum: boolean = true) => {\n return Maximum(maximum, exclusiveMaximum);\n});\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { Minimum } from "./minimum.js";
|
|
2
3
|
/**
|
|
3
4
|
* The value of `exclusiveMinimum` MUST be number, representing an exclusive upper limit for a numeric instance.
|
|
@@ -66,8 +67,9 @@ import { Minimum } from "./minimum.js";
|
|
|
66
67
|
* @swagger
|
|
67
68
|
* @schema
|
|
68
69
|
* @input
|
|
70
|
+
* @ajv-errors
|
|
69
71
|
*/
|
|
70
|
-
export
|
|
72
|
+
export const ExclusiveMinimum = withErrorMsg("exclusiveMinimum", (minimum, exclusiveMinimum = true) => {
|
|
71
73
|
return Minimum(minimum, exclusiveMinimum);
|
|
72
|
-
}
|
|
74
|
+
});
|
|
73
75
|
//# sourceMappingURL=exclusiveMinimum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusiveMinimum.js","sourceRoot":"","sources":["../../../../src/decorators/common/exclusiveMinimum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"exclusiveMinimum.js","sourceRoot":"","sources":["../../../../src/decorators/common/exclusiveMinimum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC,kBAAkB,EAAE,CAAC,OAAe,EAAE,mBAA4B,IAAI,EAAE,EAAE;IACrH,OAAO,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {Minimum} from \"./minimum\";\n\n/**\n * The value of `exclusiveMinimum` MUST be number, representing an exclusive upper limit for a numeric instance.\n *\n * If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to) `exclusiveMinimum`.\n *\n * ::: warning\n * For v6 user, use @@ExclusiveMinimum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @ExclusiveMinimum(10)\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"number\",\n * \"exclusiveMinimum\": 10\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @ExclusiveMinimum(10)\n * @CollectionOf(Number)\n * property: number[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"number\",\n * \"exclusiveMinimum\": 10\n * }\n * }\n * }\n * }\n * ```\n *\n * @param minimum\n * @param {boolean} exclusiveMinimum\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\nexport const ExclusiveMinimum = withErrorMsg(\"exclusiveMinimum\", (minimum: number, exclusiveMinimum: boolean = true) => {\n return Minimum(minimum, exclusiveMinimum);\n});\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JsonFormatTypes } from "../../domain/JsonFormatTypes.js";
|
|
2
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
2
3
|
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
3
4
|
/**
|
|
4
5
|
* The following formats are supported for string validation with `format` keyword:
|
|
@@ -72,12 +73,13 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
72
73
|
* @swagger
|
|
73
74
|
* @schema
|
|
74
75
|
* @input
|
|
76
|
+
* @ajv-errors
|
|
75
77
|
*/
|
|
76
|
-
export
|
|
78
|
+
export const Format = withErrorMsg("format", (format) => {
|
|
77
79
|
return JsonEntityFn((store) => {
|
|
78
80
|
store.itemSchema.format(format);
|
|
79
81
|
});
|
|
80
|
-
}
|
|
82
|
+
});
|
|
81
83
|
/**
|
|
82
84
|
* Apply an email validation on property.
|
|
83
85
|
*
|
|
@@ -143,10 +145,11 @@ export function Format(format) {
|
|
|
143
145
|
* @schema
|
|
144
146
|
* @swagger
|
|
145
147
|
* @input
|
|
148
|
+
* @ajv-errors
|
|
146
149
|
*/
|
|
147
|
-
export
|
|
150
|
+
export const Email = withErrorMsg("format", () => {
|
|
148
151
|
return Format(JsonFormatTypes.EMAIL);
|
|
149
|
-
}
|
|
152
|
+
});
|
|
150
153
|
/**
|
|
151
154
|
* Apply a date-time validation on property.
|
|
152
155
|
*
|
|
@@ -209,10 +212,11 @@ export function Email() {
|
|
|
209
212
|
* @parameter
|
|
210
213
|
* @schema
|
|
211
214
|
* @auto-map The data will be stored on the right place according to the type and collectionType (primitive or collection).
|
|
215
|
+
* @ajv-errors
|
|
212
216
|
*/
|
|
213
|
-
export
|
|
217
|
+
export const DateTime = withErrorMsg("format", () => {
|
|
214
218
|
return Format(JsonFormatTypes.DATE_TIME);
|
|
215
|
-
}
|
|
219
|
+
});
|
|
216
220
|
/**
|
|
217
221
|
* Apply a time validation on property.
|
|
218
222
|
*
|
|
@@ -274,10 +278,11 @@ export function DateTime() {
|
|
|
274
278
|
* @property
|
|
275
279
|
* @parameter
|
|
276
280
|
* @schema
|
|
281
|
+
* @ajv-errors
|
|
277
282
|
*/
|
|
278
|
-
export
|
|
283
|
+
export const DateFormat = withErrorMsg("format", () => {
|
|
279
284
|
return Format(JsonFormatTypes.DATE);
|
|
280
|
-
}
|
|
285
|
+
});
|
|
281
286
|
/**
|
|
282
287
|
* Apply a time validation on property.
|
|
283
288
|
*
|
|
@@ -339,10 +344,11 @@ export function DateFormat() {
|
|
|
339
344
|
* @property
|
|
340
345
|
* @parameter
|
|
341
346
|
* @schema
|
|
347
|
+
* @ajv-errors
|
|
342
348
|
*/
|
|
343
|
-
export
|
|
349
|
+
export const TimeFormat = withErrorMsg("format", () => {
|
|
344
350
|
return Format(JsonFormatTypes.TIME);
|
|
345
|
-
}
|
|
351
|
+
});
|
|
346
352
|
/**
|
|
347
353
|
* Apply a uri validation on property.
|
|
348
354
|
*
|
|
@@ -404,10 +410,11 @@ export function TimeFormat() {
|
|
|
404
410
|
* @property
|
|
405
411
|
* @parameter
|
|
406
412
|
* @schema
|
|
413
|
+
* @ajv-errors
|
|
407
414
|
*/
|
|
408
|
-
export
|
|
415
|
+
export const Uri = withErrorMsg("format", () => {
|
|
409
416
|
return Format(JsonFormatTypes.URI);
|
|
410
|
-
}
|
|
417
|
+
});
|
|
411
418
|
/**
|
|
412
419
|
* Apply a url validation on property.
|
|
413
420
|
*
|
|
@@ -469,8 +476,9 @@ export function Uri() {
|
|
|
469
476
|
* @property
|
|
470
477
|
* @parameter
|
|
471
478
|
* @schema
|
|
479
|
+
* @ajv-errors
|
|
472
480
|
*/
|
|
473
|
-
export
|
|
481
|
+
export const Url = withErrorMsg("format", () => {
|
|
474
482
|
return Format(JsonFormatTypes.URL);
|
|
475
|
-
}
|
|
483
|
+
});
|
|
476
484
|
//# sourceMappingURL=format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/decorators/common/format.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,MAAM,UAAU,MAAM,CAAC,MAAkD;IACvE,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,UAAU,KAAK;IACnB,OAAO,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {ValueOf} from \"@tsed/core\";\nimport {JsonFormatTypes} from \"../../domain/JsonFormatTypes\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * The following formats are supported for string validation with `format` keyword:\n *\n * - **date**: full-date according to [RFC3339](https://json-schema.org/latest/json-schema-validation.html#RFC3339).\n * - **time**: time with optional time-zone.\n * - **date-time**: date-time from the same source (time-zone is mandatory).\n * - **uri**: full uri with optional protocol.\n * - **email**: email address.\n * - **hostname**: host name according to [RFC1034](https://tools.ietf.org/html/rfc1034#section-3.1).\n * - **ipv4**: IP address v4.\n * - **ipv6**: IP address v6.\n * - **regex**: tests whether a string is a valid regular expression by passing it to RegExp constructor.\n *\n * ::: warning\n * For v6 user, use @@Format@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Format(\"email\")\n * property: string;\n * }\n * ```\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Format(\"email\")\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {string} format\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Format(format: JsonFormatTypes | ValueOf<JsonFormatTypes>) {\n return JsonEntityFn((store) => {\n store.itemSchema.format(format);\n });\n}\n\n/**\n * Apply an email validation on property.\n *\n * ::: warning\n * For v6 user, use @@Email@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Email()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Email()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @schema\n * @swagger\n * @input\n */\nexport function Email() {\n return Format(JsonFormatTypes.EMAIL);\n}\n\n/**\n * Apply a date-time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @DateTime()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"date-time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @DateTime()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"date-time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @auto-map The data will be stored on the right place according to the type and collectionType (primitive or collection).\n */\nexport function DateTime() {\n return Format(JsonFormatTypes.DATE_TIME);\n}\n\n/**\n * Apply a time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Time()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Time()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n */\nexport function DateFormat() {\n return Format(JsonFormatTypes.DATE);\n}\n\n/**\n * Apply a time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @TimeFormat()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @TimeFormat()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n */\nexport function TimeFormat() {\n return Format(JsonFormatTypes.TIME);\n}\n\n/**\n * Apply a uri validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Uri()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"uri\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Uri()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"uri\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n */\nexport function Uri() {\n return Format(JsonFormatTypes.URI);\n}\n\n/**\n * Apply a url validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Url()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"url\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Url()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"url\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n */\nexport function Url() {\n return Format(JsonFormatTypes.URL);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/decorators/common/format.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,MAAkD,EAAE,EAAE;IAClG,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IAC/C,OAAO,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IAClD,OAAO,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;AAC3C,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IACpD,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IACpD,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IAC7C,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE;IAC7C,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC","sourcesContent":["import {ValueOf} from \"@tsed/core\";\nimport {JsonFormatTypes} from \"../../domain/JsonFormatTypes\";\nimport {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * The following formats are supported for string validation with `format` keyword:\n *\n * - **date**: full-date according to [RFC3339](https://json-schema.org/latest/json-schema-validation.html#RFC3339).\n * - **time**: time with optional time-zone.\n * - **date-time**: date-time from the same source (time-zone is mandatory).\n * - **uri**: full uri with optional protocol.\n * - **email**: email address.\n * - **hostname**: host name according to [RFC1034](https://tools.ietf.org/html/rfc1034#section-3.1).\n * - **ipv4**: IP address v4.\n * - **ipv6**: IP address v6.\n * - **regex**: tests whether a string is a valid regular expression by passing it to RegExp constructor.\n *\n * ::: warning\n * For v6 user, use @@Format@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Format(\"email\")\n * property: string;\n * }\n * ```\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Format(\"email\")\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {string} format\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\nexport const Format = withErrorMsg(\"format\", (format: JsonFormatTypes | ValueOf<JsonFormatTypes>) => {\n return JsonEntityFn((store) => {\n store.itemSchema.format(format);\n });\n});\n\n/**\n * Apply an email validation on property.\n *\n * ::: warning\n * For v6 user, use @@Email@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Email()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Email()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"email\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @schema\n * @swagger\n * @input\n * @ajv-errors\n */\nexport const Email = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.EMAIL);\n});\n\n/**\n * Apply a date-time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @DateTime()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"date-time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @DateTime()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"date-time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @auto-map The data will be stored on the right place according to the type and collectionType (primitive or collection).\n * @ajv-errors\n */\nexport const DateTime = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.DATE_TIME);\n});\n\n/**\n * Apply a time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Time()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Time()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @ajv-errors\n */\nexport const DateFormat = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.DATE);\n});\n\n/**\n * Apply a time validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @TimeFormat()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @TimeFormat()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"time\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @ajv-errors\n */\nexport const TimeFormat = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.TIME);\n});\n\n/**\n * Apply a uri validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Uri()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"uri\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Uri()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"uri\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @ajv-errors\n */\nexport const Uri = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.URI);\n});\n\n/**\n * Apply a url validation on property.\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Url()\n * property: string;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"format\": \"url\"\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Url()\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"format\": \"url\"\n * }\n * }\n * }\n * }\n * ```\n *\n * > See [Format](api/common/jsonschema/schema) decorator.\n * @returns {Function}\n * @decorator\n * @validation\n * @property\n * @parameter\n * @schema\n * @ajv-errors\n */\nexport const Url = withErrorMsg(\"format\", () => {\n return Format(JsonFormatTypes.URL);\n});\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
* A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
|
|
@@ -73,13 +74,14 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
73
74
|
* @swagger
|
|
74
75
|
* @schema
|
|
75
76
|
* @input
|
|
77
|
+
* @ajv-errors
|
|
76
78
|
*/
|
|
77
|
-
export
|
|
79
|
+
export const MaxLength = withErrorMsg("maxLength", (maxLength) => {
|
|
78
80
|
if (maxLength < 0) {
|
|
79
81
|
throw new Error("The value of maxLength MUST be a non-negative integer.");
|
|
80
82
|
}
|
|
81
83
|
return JsonEntityFn((store) => {
|
|
82
84
|
store.itemSchema.maxLength(maxLength);
|
|
83
85
|
});
|
|
84
|
-
}
|
|
86
|
+
});
|
|
85
87
|
//# sourceMappingURL=maxLength.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maxLength.js","sourceRoot":"","sources":["../../../../src/decorators/common/maxLength.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"maxLength.js","sourceRoot":"","sources":["../../../../src/decorators/common/maxLength.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC,SAAiB,EAAE,EAAE;IACvE,IAAI,SAAS,GAAG,CAAC,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;KAC3E;IAED,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.\n *\n * The length of a string instance is defined as the number of its characters as defined by [RFC 7159](http://json-schema.org/latest/json-schema-validation.html#RFC7159).\n *\n * ::: warning\n * The value of maxLength MUST be a non-negative integer.\n * :::\n *\n * ::: tip\n * Omitting this keyword has the same behavior as a value of 0.\n * :::\n *\n * ::: warning\n * For v6 user, use @@MaxLength@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @MaxLength(10)\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"maxLength\": 10\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @MaxLength(10)\n * @CollectionOf(String)\n * property: string[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"maxLength\": 10\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {number} maxLength The maximum length allowed\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\nexport const MaxLength = withErrorMsg(\"maxLength\", (maxLength: number) => {\n if (maxLength < 0) {\n throw new Error(\"The value of maxLength MUST be a non-negative integer.\");\n }\n\n return JsonEntityFn((store) => {\n store.itemSchema.maxLength(maxLength);\n });\n});\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
* The value of `maximum` MUST be a number, representing an inclusive upper limit for a numeric instance.
|
|
@@ -66,12 +67,13 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
66
67
|
* @swagger
|
|
67
68
|
* @schema
|
|
68
69
|
* @input
|
|
70
|
+
* @ajv-errors
|
|
69
71
|
*/
|
|
70
|
-
export
|
|
72
|
+
export const Maximum = withErrorMsg("maximum", (maximum, exclusive = false) => {
|
|
71
73
|
return JsonEntityFn((store) => {
|
|
72
74
|
exclusive ? store.itemSchema.exclusiveMaximum(maximum) : store.itemSchema.maximum(maximum);
|
|
73
75
|
});
|
|
74
|
-
}
|
|
76
|
+
});
|
|
75
77
|
/**
|
|
76
78
|
* The value of `maximum` MUST be a number, representing an inclusive upper limit for a numeric instance.
|
|
77
79
|
*
|
|
@@ -140,7 +142,5 @@ export function Maximum(maximum, exclusive = false) {
|
|
|
140
142
|
* @schema
|
|
141
143
|
* @input
|
|
142
144
|
*/
|
|
143
|
-
export
|
|
144
|
-
return Maximum(maximum, exclusive);
|
|
145
|
-
}
|
|
145
|
+
export const Max = Maximum;
|
|
146
146
|
//# sourceMappingURL=maximum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maximum.js","sourceRoot":"","sources":["../../../../src/decorators/common/maximum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"maximum.js","sourceRoot":"","sources":["../../../../src/decorators/common/maximum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC,OAAe,EAAE,YAAqB,KAAK,EAAE,EAAE;IAC7F,OAAO,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAC","sourcesContent":["import {withErrorMsg} from \"../../utils/withErrorMsg\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * The value of `maximum` MUST be a number, representing an inclusive upper limit for a numeric instance.\n *\n * If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to `maximum`.\n *\n * ::: warning\n * For v6 user, use @@Maximum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Maximum(10)\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"number\",\n * \"maximum\": 10\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Maximum(10)\n * @CollectionOf(Number)\n * property: number[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"number\",\n * \"maximum\": 10\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {number} maximum The maximum value allowed\n * @param {boolean} exclusive Same effect as ExclusiveMaximum decorator.\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @ajv-errors\n */\nexport const Maximum = withErrorMsg(\"maximum\", (maximum: number, exclusive: boolean = false) => {\n return JsonEntityFn((store) => {\n exclusive ? store.itemSchema.exclusiveMaximum(maximum) : store.itemSchema.maximum(maximum);\n });\n});\n/**\n * The value of `maximum` MUST be a number, representing an inclusive upper limit for a numeric instance.\n *\n * If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to `maximum`.\n *\n * ::: warning\n * For v6 user, use @@Maximum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Max(10)\n * property: number;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"number\",\n * \"maximum\": 10\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Max(10)\n * @CollectionOf(Number)\n * property: number[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"number\",\n * \"maximum\": 10\n * }\n * }\n * }\n * }\n * ```\n *\n * @param {number} maximum The maximum value allowed\n * @param {boolean} exclusive Same effect as ExclusiveMaximum decorator.\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport const Max = Maximum;\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withErrorMsg } from "../../utils/withErrorMsg.js";
|
|
1
2
|
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
@@ -74,13 +75,14 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
74
75
|
* @swagger
|
|
75
76
|
* @schema
|
|
76
77
|
* @input
|
|
78
|
+
* @ajv-errors
|
|
77
79
|
*/
|
|
78
|
-
export
|
|
80
|
+
export const MinLength = withErrorMsg("minLength", (minLength) => {
|
|
79
81
|
if (minLength < 0) {
|
|
80
82
|
throw new Error("The value of minLength MUST be a non-negative integer.");
|
|
81
83
|
}
|
|
82
84
|
return JsonEntityFn((store) => {
|
|
83
85
|
store.itemSchema.minLength(minLength);
|
|
84
86
|
});
|
|
85
|
-
}
|
|
87
|
+
});
|
|
86
88
|
//# sourceMappingURL=minLength.js.map
|