@tsed/schema 8.0.7 → 8.2.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/esm/components/default/anyMapper.js +2 -2
- package/lib/esm/components/default/anyMapper.js.map +1 -1
- package/lib/esm/components/default/inheritedClassMapper.js +16 -2
- package/lib/esm/components/default/inheritedClassMapper.js.map +1 -1
- package/lib/esm/decorators/common/labelledAs.js +35 -0
- package/lib/esm/decorators/common/labelledAs.js.map +1 -0
- package/lib/esm/decorators/generics/genericOf.js +1 -1
- package/lib/esm/decorators/generics/genericOf.js.map +1 -1
- package/lib/esm/decorators/operations/returns.js +1 -1
- package/lib/esm/decorators/operations/returns.js.map +1 -1
- package/lib/esm/fn/allOf.js +12 -0
- package/lib/esm/fn/allOf.js.map +1 -0
- package/lib/esm/fn/any.js +10 -0
- package/lib/esm/fn/any.js.map +1 -0
- package/lib/esm/fn/anyOf.js +12 -0
- package/lib/esm/fn/anyOf.js.map +1 -0
- package/lib/esm/fn/boolean.js +10 -0
- package/lib/esm/fn/boolean.js.map +1 -0
- package/lib/esm/fn/collection.js +50 -0
- package/lib/esm/fn/collection.js.map +1 -0
- package/lib/esm/fn/date.js +27 -0
- package/lib/esm/fn/date.js.map +1 -0
- package/lib/esm/fn/email.js +18 -0
- package/lib/esm/fn/email.js.map +1 -0
- package/lib/esm/fn/enums.js +8 -0
- package/lib/esm/fn/enums.js.map +1 -0
- package/lib/esm/fn/from.js +28 -0
- package/lib/esm/fn/from.js.map +1 -0
- package/lib/esm/fn/integer.js +13 -0
- package/lib/esm/fn/integer.js.map +1 -0
- package/lib/esm/fn/lazyRef.js +17 -0
- package/lib/esm/fn/lazyRef.js.map +1 -0
- package/lib/esm/fn/number.js +10 -0
- package/lib/esm/fn/number.js.map +1 -0
- package/lib/esm/fn/object.js +22 -0
- package/lib/esm/fn/object.js.map +1 -0
- package/lib/esm/fn/oneOf.js +13 -0
- package/lib/esm/fn/oneOf.js.map +1 -0
- package/lib/esm/fn/string.js +10 -0
- package/lib/esm/fn/string.js.map +1 -0
- package/lib/esm/fn/uri.js +13 -0
- package/lib/esm/fn/uri.js.map +1 -0
- package/lib/esm/fn/url.js +11 -0
- package/lib/esm/fn/url.js.map +1 -0
- package/lib/esm/index.js +18 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/registries/JsonSchemaMapperContainer.js +1 -1
- package/lib/esm/registries/JsonSchemaMapperContainer.js.map +1 -1
- package/lib/esm/utils/ref.js.map +1 -1
- package/lib/types/decorators/common/labelledAs.d.ts +24 -0
- package/lib/types/fn/allOf.d.ts +9 -0
- package/lib/types/fn/any.d.ts +7 -0
- package/lib/types/fn/anyOf.d.ts +9 -0
- package/lib/types/fn/boolean.d.ts +7 -0
- package/lib/types/fn/collection.d.ts +43 -0
- package/lib/types/fn/date.d.ts +19 -0
- package/lib/types/fn/email.d.ts +14 -0
- package/lib/types/fn/enums.d.ts +1 -0
- package/lib/types/fn/from.d.ts +14 -0
- package/lib/types/fn/integer.d.ts +10 -0
- package/lib/types/fn/lazyRef.d.ts +5 -0
- package/lib/types/fn/number.d.ts +6 -0
- package/lib/types/fn/object.d.ts +21 -0
- package/lib/types/fn/oneOf.d.ts +10 -0
- package/lib/types/fn/string.d.ts +7 -0
- package/lib/types/fn/uri.d.ts +9 -0
- package/lib/types/fn/url.d.ts +7 -0
- package/lib/types/index.d.ts +18 -1
- package/lib/types/registries/JsonSchemaMapperContainer.d.ts +1 -1
- package/package.json +10 -10
- package/src/components/default/anyMapper.ts +2 -2
- package/src/components/default/inheritedClassMapper.ts +19 -2
- package/src/decorators/collections/collectionOf.spec.ts +2 -1
- package/src/decorators/common/allOf.spec.ts +2 -1
- package/src/decorators/common/anyOf.spec.ts +2 -1
- package/src/decorators/common/enum.spec.ts +1 -1
- package/src/decorators/common/labelledAs.spec.ts +85 -0
- package/src/decorators/common/labelledAs.ts +34 -0
- package/src/decorators/common/oneOf.spec.ts +2 -1
- package/src/decorators/generics/genericOf.ts +1 -1
- package/src/decorators/operations/returns.ts +1 -1
- package/src/fn/allOf.ts +13 -0
- package/src/fn/any.ts +11 -0
- package/src/fn/anyOf.ts +13 -0
- package/src/fn/boolean.ts +11 -0
- package/src/fn/collection.ts +53 -0
- package/src/fn/date.ts +30 -0
- package/src/fn/email.ts +19 -0
- package/src/fn/enums.ts +9 -0
- package/src/{utils → fn}/from.spec.ts +14 -83
- package/src/fn/from.ts +33 -0
- package/src/fn/integer.ts +13 -0
- package/src/fn/layzRef.spec.ts +70 -0
- package/src/fn/lazyRef.ts +19 -0
- package/src/fn/number.ts +10 -0
- package/src/fn/object.ts +23 -0
- package/src/fn/oneOf.ts +14 -0
- package/src/fn/string.ts +11 -0
- package/src/fn/uri.ts +14 -0
- package/src/fn/url.ts +12 -0
- package/src/index.ts +18 -1
- package/src/registries/JsonSchemaMapperContainer.ts +1 -1
- package/src/utils/ref.ts +0 -1
- package/lib/esm/utils/from.js +0 -256
- package/lib/esm/utils/from.js.map +0 -1
- package/lib/types/utils/from.d.ts +0 -190
- package/src/utils/from.ts +0 -281
package/src/utils/from.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import {isClass, Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {JsonEntityStore} from "../domain/JsonEntityStore.js";
|
|
4
|
-
import {JsonFormatTypes} from "../domain/JsonFormatTypes.js";
|
|
5
|
-
import {JsonLazyRef} from "../domain/JsonLazyRef.js";
|
|
6
|
-
import {JsonSchema} from "../domain/JsonSchema.js";
|
|
7
|
-
import {enumsRegistry} from "../registries/enumRegistries.js";
|
|
8
|
-
import {getJsonEntityStore} from "./getJsonEntityStore.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create a new model from the given type.
|
|
12
|
-
*
|
|
13
|
-
* ```typescript
|
|
14
|
-
* from(String)
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
18
|
-
*
|
|
19
|
-
* @schemaFunctional
|
|
20
|
-
*/
|
|
21
|
-
export function from(type: Type<any> = Object) {
|
|
22
|
-
if (isClass(type)) {
|
|
23
|
-
const {schema} = getJsonEntityStore(type);
|
|
24
|
-
|
|
25
|
-
schema.properties = function properties(obj: {[key: string]: JsonSchema}) {
|
|
26
|
-
Object.entries(obj).forEach(([propertyKey, propSchema]) => {
|
|
27
|
-
getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return schema;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return JsonSchema.from({type});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Declare a new number model.
|
|
41
|
-
*
|
|
42
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
43
|
-
*
|
|
44
|
-
* @schemaFunctional
|
|
45
|
-
*/
|
|
46
|
-
export function number() {
|
|
47
|
-
return from(Number);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Declare a new integer model.
|
|
52
|
-
*
|
|
53
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
54
|
-
*
|
|
55
|
-
* @schemaFunctional
|
|
56
|
-
*/
|
|
57
|
-
export function integer() {
|
|
58
|
-
return from(Number).integer();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Declare a new string model.
|
|
63
|
-
*
|
|
64
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
65
|
-
*
|
|
66
|
-
* @schemaFunctional
|
|
67
|
-
*/
|
|
68
|
-
export function string() {
|
|
69
|
-
return from(String);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Declare a new boolean model.
|
|
74
|
-
*
|
|
75
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
76
|
-
*
|
|
77
|
-
* @schemaFunctional
|
|
78
|
-
*/
|
|
79
|
-
export function boolean() {
|
|
80
|
-
return from(Boolean);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Declare a new string model with `format: date`.
|
|
85
|
-
*
|
|
86
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
87
|
-
*
|
|
88
|
-
* @schemaFunctional
|
|
89
|
-
*/
|
|
90
|
-
export function date() {
|
|
91
|
-
return from(Date).format(JsonFormatTypes.DATE);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Declare a new string model with `format: datetime`.
|
|
96
|
-
*
|
|
97
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
98
|
-
*
|
|
99
|
-
* @schemaFunctional
|
|
100
|
-
*/
|
|
101
|
-
export function datetime() {
|
|
102
|
-
return from(Date).format(JsonFormatTypes.DATE_TIME);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Declare a new string model with `format: time`.
|
|
107
|
-
*
|
|
108
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
109
|
-
*
|
|
110
|
-
* @schemaFunctional
|
|
111
|
-
*/
|
|
112
|
-
export function time() {
|
|
113
|
-
return from(Date).format(JsonFormatTypes.TIME);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Declare a new string model with `format: email`.
|
|
118
|
-
*
|
|
119
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
120
|
-
*
|
|
121
|
-
* @schemaFunctional
|
|
122
|
-
*/
|
|
123
|
-
export function email() {
|
|
124
|
-
return from(String).format(JsonFormatTypes.EMAIL);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Declare a new string model with `format: uri`.
|
|
129
|
-
*
|
|
130
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
131
|
-
*
|
|
132
|
-
* @schemaFunctional
|
|
133
|
-
*/
|
|
134
|
-
export function uri() {
|
|
135
|
-
return from(String).format(JsonFormatTypes.URI);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Declare a new string model with `format: url`.
|
|
140
|
-
*
|
|
141
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
142
|
-
*
|
|
143
|
-
* @schemaFunctional
|
|
144
|
-
*/
|
|
145
|
-
export function url() {
|
|
146
|
-
return from(String).format(JsonFormatTypes.URL);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Declare a new object model with `additionalProperties: true`.
|
|
151
|
-
*
|
|
152
|
-
* ```json
|
|
153
|
-
* {
|
|
154
|
-
* "type": "array"
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*
|
|
158
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
159
|
-
*
|
|
160
|
-
* @schemaFunctional
|
|
161
|
-
*/
|
|
162
|
-
export function array() {
|
|
163
|
-
return from(Array);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Declare a new object model with `additionalProperties: true`.
|
|
168
|
-
*
|
|
169
|
-
* ```json
|
|
170
|
-
* {
|
|
171
|
-
* "type": "object",
|
|
172
|
-
* "additionalProperties": true
|
|
173
|
-
* }
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
177
|
-
*
|
|
178
|
-
* @schemaFunctional
|
|
179
|
-
*/
|
|
180
|
-
export function map() {
|
|
181
|
-
return from(Map).unknown(true);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Declare a new array model with `uniqueItems: true`.
|
|
186
|
-
*
|
|
187
|
-
* ```json
|
|
188
|
-
* {
|
|
189
|
-
* "type": "array",
|
|
190
|
-
* "uniqueItems": true
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
195
|
-
*
|
|
196
|
-
* @schemaFunctional
|
|
197
|
-
*/
|
|
198
|
-
export function set() {
|
|
199
|
-
return from(Array).uniqueItems(true);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Declare a new object model.
|
|
204
|
-
*
|
|
205
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
206
|
-
*
|
|
207
|
-
* @schemaFunctional
|
|
208
|
-
*/
|
|
209
|
-
export function object(properties: {[key: string]: JsonSchema} = {}) {
|
|
210
|
-
return from(Object).properties(properties);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Declare a model with any type (By default: `integer`, `number`, `string`, `boolean`, `array`, `object`, `null`)
|
|
215
|
-
*
|
|
216
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
217
|
-
*
|
|
218
|
-
* @schemaFunctional
|
|
219
|
-
*/
|
|
220
|
-
export function any(...types: any[]) {
|
|
221
|
-
return from().any(...types);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
|
|
226
|
-
*
|
|
227
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
228
|
-
*
|
|
229
|
-
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
|
|
230
|
-
* @schemaFunctional
|
|
231
|
-
*/
|
|
232
|
-
export function anyOf(...anyOf: any[]) {
|
|
233
|
-
return from().anyOf(anyOf);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
|
|
238
|
-
*
|
|
239
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
240
|
-
*
|
|
241
|
-
* @schemaFunctional
|
|
242
|
-
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
|
|
243
|
-
*/
|
|
244
|
-
export function oneOf(...oneOf: any[]) {
|
|
245
|
-
return from().oneOf(oneOf);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
|
|
250
|
-
*
|
|
251
|
-
* * See @@JsonSchema@@ to discover available methods.
|
|
252
|
-
*
|
|
253
|
-
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
|
|
254
|
-
* @schemaFunctional
|
|
255
|
-
*/
|
|
256
|
-
export function allOf(...allOf: any[]) {
|
|
257
|
-
return from().allOf(allOf);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Declare a sub schema which will be resolved later. Use this function when you have a circular reference between two schemes.
|
|
262
|
-
*
|
|
263
|
-
* @schemaFunctional
|
|
264
|
-
*/
|
|
265
|
-
export function lazyRef(cb: () => Type<any>) {
|
|
266
|
-
try {
|
|
267
|
-
// solve issue with a self referenced model
|
|
268
|
-
if (cb()) {
|
|
269
|
-
// type is already accessible
|
|
270
|
-
return JsonEntityStore.from(cb()).schema as any;
|
|
271
|
-
}
|
|
272
|
-
} catch (er) {}
|
|
273
|
-
|
|
274
|
-
return new JsonLazyRef(cb);
|
|
275
|
-
}
|
|
276
|
-
export function enums(e: Record<string, any>) {
|
|
277
|
-
const schema = string().enum(e);
|
|
278
|
-
enumsRegistry.set(e, schema);
|
|
279
|
-
|
|
280
|
-
return schema;
|
|
281
|
-
}
|