@wener/common 1.0.2 → 1.0.4
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/cn/DivisionCode.js +311 -0
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/Mod11Checksum.js +42 -0
- package/lib/cn/Mod11Checksum.js.map +1 -0
- package/lib/cn/Mod31Checksum.js +48 -0
- package/lib/cn/Mod31Checksum.js.map +1 -0
- package/lib/cn/ResidentIdentityCardNumber.js +50 -0
- package/lib/cn/ResidentIdentityCardNumber.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +118 -0
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/formatDate.js +15 -0
- package/lib/cn/formatDate.js.map +1 -0
- package/lib/cn/index.js +4 -0
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/parseSex.js +22 -0
- package/lib/cn/parseSex.js.map +1 -0
- package/lib/cn/types.d.js +8 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/data/formatSort.js +15 -0
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +4 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +22 -0
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +95 -0
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +36 -0
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +3 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/jsonschema/JsonSchema.js +4 -4
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineFileType.js +44 -0
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineInit.js.map +1 -1
- package/lib/meta/defineMetadata.js +14 -3
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -1
- package/lib/password/PHC.js +8 -8
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/Password.js.map +1 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/search/AdvanceSearch.js.map +1 -1
- package/lib/search/formatAdvanceSearch.js +1 -1
- package/lib/search/formatAdvanceSearch.js.map +1 -1
- package/lib/search/optimizeAdvanceSearch.js.map +1 -1
- package/lib/search/parseAdvanceSearch.js.map +1 -1
- package/lib/search/parser.d.js.map +1 -1
- package/lib/search/parser.js +380 -76
- package/lib/search/parser.js.map +1 -1
- package/lib/search/types.d.js.map +1 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -1
- package/package.json +14 -5
- package/src/cn/DivisionCode.test.ts +43 -0
- package/src/cn/DivisionCode.ts +209 -0
- package/src/cn/Mod11Checksum.ts +24 -0
- package/src/cn/Mod31Checksum.ts +36 -0
- package/src/cn/ResidentIdentityCardNumber.test.ts +17 -0
- package/src/cn/ResidentIdentityCardNumber.ts +96 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +16 -0
- package/src/cn/UnifiedSocialCreditCode.ts +143 -0
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +15 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +41 -0
- package/src/cn/formatDate.ts +12 -0
- package/src/cn/index.ts +3 -0
- package/src/cn/parseSex.ts +13 -0
- package/src/cn/types.d.ts +51 -0
- package/src/data/formatSort.test.ts +13 -0
- package/src/data/formatSort.ts +18 -0
- package/src/data/index.ts +5 -0
- package/src/data/maybeNumber.ts +23 -0
- package/src/data/parseSort.test.ts +67 -0
- package/src/data/parseSort.ts +108 -0
- package/src/data/resolvePagination.test.ts +58 -0
- package/src/data/resolvePagination.ts +60 -0
- package/src/data/types.d.ts +33 -0
- package/src/index.ts +8 -2
- package/src/jsonschema/JsonSchema.test.ts +13 -22
- package/src/jsonschema/JsonSchema.ts +145 -177
- package/src/jsonschema/types.d.ts +151 -161
- package/src/meta/defineFileType.tsx +68 -0
- package/src/meta/defineInit.ts +32 -53
- package/src/meta/defineMetadata.test.ts +5 -7
- package/src/meta/defineMetadata.ts +35 -40
- package/src/meta/index.ts +2 -0
- package/src/password/PHC.test.ts +186 -277
- package/src/password/PHC.ts +243 -243
- package/src/password/Password.test.ts +38 -50
- package/src/password/Password.ts +73 -95
- package/src/password/createArgon2PasswordAlgorithm.ts +65 -69
- package/src/password/createBase64PasswordAlgorithm.ts +9 -9
- package/src/password/createBcryptPasswordAlgorithm.ts +20 -22
- package/src/password/createPBKDF2PasswordAlgorithm.ts +49 -61
- package/src/password/createScryptPasswordAlgorithm.ts +48 -59
- package/src/search/AdvanceSearch.test.ts +136 -143
- package/src/search/AdvanceSearch.ts +6 -6
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +3 -3
- package/src/search/formatAdvanceSearch.ts +44 -53
- package/src/search/optimizeAdvanceSearch.ts +70 -83
- package/src/search/parseAdvanceSearch.ts +16 -19
- package/src/search/parser.d.ts +3 -3
- package/src/search/parser.js +325 -73
- package/src/search/parser.peggy +42 -9
- package/src/search/types.d.ts +28 -54
- package/src/tools/renderJsonSchemaToMarkdownDoc.ts +69 -69
- package/lib/normalizePagination.js +0 -14
- package/lib/normalizePagination.js.map +0 -1
- package/lib/parseSort.js +0 -91
- package/lib/parseSort.js.map +0 -1
- package/src/normalizePagination.ts +0 -25
- package/src/parseSort.test.ts +0 -42
- package/src/parseSort.ts +0 -115
|
@@ -8,190 +8,158 @@ import { match, P } from 'ts-pattern';
|
|
|
8
8
|
import type { JsonSchemaDef } from './types';
|
|
9
9
|
|
|
10
10
|
function _createAjv(opt: Options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const ajv = new Ajv(opt);
|
|
12
|
+
addKeywords(ajv);
|
|
13
|
+
addFormats(ajv);
|
|
14
|
+
return ajv;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
type ValidateOptions = {
|
|
18
|
-
mutate?: boolean;
|
|
19
|
-
clone?: boolean;
|
|
20
|
-
ajv?: Ajv;
|
|
21
|
-
};
|
|
17
|
+
type ValidateOptions = { mutate?: boolean; clone?: boolean; ajv?: Ajv };
|
|
22
18
|
|
|
23
19
|
type ValidateResult<T> =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
useDefaults: true,
|
|
56
|
-
coerceTypes: true,
|
|
57
|
-
allErrors: true,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (clone) {
|
|
62
|
-
data = structuredClone(data);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!ajv) {
|
|
66
|
-
ajv = JsonSchema.createAjv(opts);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const validate = ajv.compile(schema);
|
|
70
|
-
|
|
71
|
-
// consider reusing validate instance
|
|
72
|
-
|
|
73
|
-
const valid = validate(data);
|
|
74
|
-
const errors = validate.errors;
|
|
75
|
-
localize(errors);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
data,
|
|
79
|
-
success: valid,
|
|
80
|
-
message: ajv.errorsText(errors),
|
|
81
|
-
errors: errors,
|
|
82
|
-
};
|
|
20
|
+
| { data: T; success: true; message: undefined }
|
|
21
|
+
| { data: undefined; success: false; message: string; errors: ErrorObject[] };
|
|
22
|
+
|
|
23
|
+
function validate({ schema, data, mutate, clone, ajv }: ValidateOptions & { schema: any; data: any }) {
|
|
24
|
+
let opts: Options = {
|
|
25
|
+
// strict: 'log',
|
|
26
|
+
strict: true,
|
|
27
|
+
strictSchema: 'log', // skip unknown keywords in schema
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (mutate) {
|
|
31
|
+
Object.assign(opts, { removeAdditional: true, useDefaults: true, coerceTypes: true, allErrors: true });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (clone) {
|
|
35
|
+
data = structuredClone(data);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!ajv) {
|
|
39
|
+
ajv = JsonSchema.createAjv(opts);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const validate = ajv.compile(schema);
|
|
43
|
+
|
|
44
|
+
// consider reusing validate instance
|
|
45
|
+
|
|
46
|
+
const valid = validate(data);
|
|
47
|
+
const errors = validate.errors;
|
|
48
|
+
localize(errors);
|
|
49
|
+
|
|
50
|
+
return { data, success: valid, message: ajv.errorsText(errors), errors: errors };
|
|
83
51
|
}
|
|
84
52
|
|
|
85
53
|
type TypeOfSchema<S> = S extends TSchema ? Static<S> : any;
|
|
86
54
|
|
|
87
55
|
export namespace JsonSchema {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
56
|
+
export let schemas: JsonSchemaDef[] = [];
|
|
57
|
+
|
|
58
|
+
export const createAjv = _createAjv;
|
|
59
|
+
|
|
60
|
+
export function addSchema(
|
|
61
|
+
schema: JsonSchemaDef,
|
|
62
|
+
{
|
|
63
|
+
onConflict = 'throw',
|
|
64
|
+
}: {
|
|
65
|
+
onConflict?: 'throw' | 'ignore' | 'replace' | ((old: JsonSchemaDef, neo: JsonSchemaDef) => JsonSchemaDef);
|
|
66
|
+
} = {},
|
|
67
|
+
) {
|
|
68
|
+
if (!schema.$id) throw new Error('Schema must have $id');
|
|
69
|
+
switch (onConflict) {
|
|
70
|
+
case 'ignore':
|
|
71
|
+
onConflict = (old) => old;
|
|
72
|
+
break;
|
|
73
|
+
case 'replace':
|
|
74
|
+
onConflict = (_, neo) => neo;
|
|
75
|
+
break;
|
|
76
|
+
case 'throw':
|
|
77
|
+
onConflict = (old, neo) => {
|
|
78
|
+
throw new Error(`Schema ${neo.$id} already exists`);
|
|
79
|
+
};
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
let idx = schemas.findIndex((s) => s.$id === schema.$id);
|
|
83
|
+
if (idx >= 0) {
|
|
84
|
+
schemas[idx] = onConflict(schemas[idx], schema);
|
|
85
|
+
} else {
|
|
86
|
+
schemas.push(schema);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check data is valid, will not use default
|
|
92
|
+
*/
|
|
93
|
+
export function check<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {
|
|
94
|
+
return validate({ schema, data, mutate: false, clone: true }) as any;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Parse data with default value and coerceTypes
|
|
99
|
+
*/
|
|
100
|
+
export function safeParse<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {
|
|
101
|
+
return validate({ schema, data, mutate: true, clone: true }) as any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function parse<S>(schema: S, data: any): TypeOfSchema<S> {
|
|
105
|
+
const { data: out, message, errors } = validate({ schema, data, mutate: true, clone: true });
|
|
106
|
+
if (errors) {
|
|
107
|
+
throw new Error(message);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function create<S>(schema: S, data?: any): TypeOfSchema<S> {
|
|
113
|
+
// will not ensure value match the rule
|
|
114
|
+
return match(schema as JsonSchemaDef)
|
|
115
|
+
.returnType<any>()
|
|
116
|
+
.with({ const: P.select() }, (v) => v)
|
|
117
|
+
.with({ default: P.select() }, (v) => v)
|
|
118
|
+
.with({ anyOf: P.nonNullable }, (schema) => {
|
|
119
|
+
return create(schema.anyOf[0]);
|
|
120
|
+
})
|
|
121
|
+
.with({ oneOf: P.nonNullable }, (schema) => {
|
|
122
|
+
return create(schema.oneOf[0]);
|
|
123
|
+
})
|
|
124
|
+
.with({ type: 'string' }, (schema) => '')
|
|
125
|
+
.with({ type: P.union('number', 'integer') }, (schema) => 0)
|
|
126
|
+
.with({ type: 'object' }, (schema) => {
|
|
127
|
+
let out = validate({ schema, data: data ?? {}, mutate: true });
|
|
128
|
+
if (!out.success) {
|
|
129
|
+
// fallback
|
|
130
|
+
let obj = data || {};
|
|
131
|
+
schema.required?.forEach((key) => {
|
|
132
|
+
if (!(key in obj)) {
|
|
133
|
+
let last = obj[key];
|
|
134
|
+
let prop = schema.properties?.[key];
|
|
135
|
+
if (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
out = validate({ schema, data: obj, mutate: true });
|
|
139
|
+
if (!out.success) {
|
|
140
|
+
console.warn(`Failed to create object with schema: ${out.message}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return out.data;
|
|
144
|
+
})
|
|
145
|
+
.with({ type: 'null' }, () => null)
|
|
146
|
+
.with({ type: 'boolean' }, (schema) => false)
|
|
147
|
+
.with({ type: 'array' }, (schema) => [])
|
|
148
|
+
.otherwise(() => {
|
|
149
|
+
return undefined;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function isPrimitiveType(schema: any): boolean {
|
|
154
|
+
return match(schema as JsonSchemaDef)
|
|
155
|
+
.returnType<boolean>()
|
|
156
|
+
.with({ type: P.union('number', 'integer', 'string', 'boolean') }, () => true)
|
|
157
|
+
.with({ anyOf: P.nonNullable }, (schema) => {
|
|
158
|
+
return isPrimitiveType(schema.anyOf[0]);
|
|
159
|
+
})
|
|
160
|
+
.with({ oneOf: P.nonNullable }, (schema) => {
|
|
161
|
+
return isPrimitiveType(schema.oneOf[0]);
|
|
162
|
+
})
|
|
163
|
+
.otherwise(() => false);
|
|
164
|
+
}
|
|
197
165
|
}
|
|
@@ -1,173 +1,163 @@
|
|
|
1
1
|
type JsonSchemaTypeName =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
| 'string' //
|
|
3
|
+
| 'number'
|
|
4
|
+
| 'integer'
|
|
5
|
+
| 'boolean'
|
|
6
|
+
| 'object'
|
|
7
|
+
| 'array'
|
|
8
|
+
| 'null';
|
|
9
9
|
|
|
10
10
|
type JsonValue =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| JsonValue[]
|
|
18
|
-
| null;
|
|
11
|
+
| string //
|
|
12
|
+
| number
|
|
13
|
+
| boolean
|
|
14
|
+
| { [key: string]: JsonValue }
|
|
15
|
+
| JsonValue[]
|
|
16
|
+
| null;
|
|
19
17
|
|
|
20
18
|
type JsonSchemaVersion =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
| 'http://json-schema.org/schema' // latest
|
|
20
|
+
| 'https://json-schema.org/draft/2020-12/schema'
|
|
21
|
+
// draft-07
|
|
22
|
+
| 'http://json-schema.org/draft-07/schema#' //
|
|
23
|
+
| 'http://json-schema.org/draft-07/hyper-schema#';
|
|
26
24
|
|
|
27
25
|
type JsonSchemaFormatName =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
//
|
|
27
|
+
| 'date-time'
|
|
28
|
+
| 'date'
|
|
29
|
+
| 'time'
|
|
30
|
+
| 'duration'
|
|
31
|
+
//
|
|
32
|
+
| 'email'
|
|
33
|
+
| 'idn-email'
|
|
34
|
+
//
|
|
35
|
+
| 'hostname'
|
|
36
|
+
| 'idn-hostname'
|
|
37
|
+
| 'ipv4'
|
|
38
|
+
| 'ipv6'
|
|
39
|
+
//
|
|
40
|
+
| 'uri'
|
|
41
|
+
| 'uri-reference'
|
|
42
|
+
| 'iri'
|
|
43
|
+
| 'iri-reference'
|
|
44
|
+
| 'uuid'
|
|
45
|
+
| 'uri-template'
|
|
46
|
+
| 'regex'
|
|
47
|
+
| 'json-pointer'
|
|
48
|
+
| 'relative-json-pointer';
|
|
51
49
|
|
|
52
50
|
export type JsonSchemaDef = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
title?: string;
|
|
163
|
-
description?: string;
|
|
164
|
-
default?: JsonValue;
|
|
165
|
-
readOnly?: boolean;
|
|
166
|
-
writeOnly?: boolean;
|
|
167
|
-
examples?: JsonValue;
|
|
168
|
-
deprecated?: boolean;
|
|
51
|
+
$id?: string;
|
|
52
|
+
$ref?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Meta schema
|
|
55
|
+
*
|
|
56
|
+
* Recommended values:
|
|
57
|
+
* - 'http://json-schema.org/schema#'
|
|
58
|
+
* - 'http://json-schema.org/hyper-schema#'
|
|
59
|
+
* - 'http://json-schema.org/draft-07/schema#'
|
|
60
|
+
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
61
|
+
*
|
|
62
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
63
|
+
*/
|
|
64
|
+
$schema?: JsonSchemaVersion | string;
|
|
65
|
+
$comment?: string;
|
|
66
|
+
|
|
67
|
+
$defs?: { [key: string]: JsonSchemaDef };
|
|
68
|
+
|
|
69
|
+
type?: JsonSchemaTypeName | JsonSchemaTypeName[];
|
|
70
|
+
enum?: JsonValue[];
|
|
71
|
+
const?: JsonValue;
|
|
72
|
+
|
|
73
|
+
//region Numeric Validation
|
|
74
|
+
|
|
75
|
+
multipleOf?: number;
|
|
76
|
+
maximum?: number;
|
|
77
|
+
exclusiveMaximum?: number;
|
|
78
|
+
minimum?: number;
|
|
79
|
+
exclusiveMinimum?: number;
|
|
80
|
+
|
|
81
|
+
//endregion
|
|
82
|
+
|
|
83
|
+
//region String Validation
|
|
84
|
+
|
|
85
|
+
maxLength?: number;
|
|
86
|
+
minLength?: number;
|
|
87
|
+
pattern?: string;
|
|
88
|
+
|
|
89
|
+
//endregion
|
|
90
|
+
|
|
91
|
+
//region Array Validation
|
|
92
|
+
|
|
93
|
+
items?: JsonSchemaDef | JsonSchemaDef[];
|
|
94
|
+
additionalItems?: JsonSchemaDef;
|
|
95
|
+
maxItems?: number;
|
|
96
|
+
minItems?: number;
|
|
97
|
+
uniqueItems?: boolean;
|
|
98
|
+
contains?: JsonSchemaDef;
|
|
99
|
+
//endregion
|
|
100
|
+
|
|
101
|
+
//region Object Validation
|
|
102
|
+
|
|
103
|
+
maxProperties?: number;
|
|
104
|
+
minProperties?: number;
|
|
105
|
+
required?: string[];
|
|
106
|
+
properties?: { [key: string]: JsonSchemaDef };
|
|
107
|
+
patternProperties?: { [key: string]: JsonSchemaDef };
|
|
108
|
+
additionalProperties?: JsonSchemaDef;
|
|
109
|
+
dependencies?: { [key: string]: JsonSchemaDef | string[] };
|
|
110
|
+
propertyNames?: JsonSchemaDef;
|
|
111
|
+
//endregion
|
|
112
|
+
|
|
113
|
+
//region Conditional
|
|
114
|
+
|
|
115
|
+
if?: JsonSchemaDef;
|
|
116
|
+
then?: JsonSchemaDef;
|
|
117
|
+
else?: JsonSchemaDef;
|
|
118
|
+
|
|
119
|
+
//endregion
|
|
120
|
+
|
|
121
|
+
//region Boolean Logic
|
|
122
|
+
|
|
123
|
+
allOf?: JsonSchemaDef[];
|
|
124
|
+
anyOf?: JsonSchemaDef[];
|
|
125
|
+
oneOf?: JsonSchemaDef[];
|
|
126
|
+
not?: JsonSchemaDef;
|
|
127
|
+
//endregion
|
|
128
|
+
|
|
129
|
+
//region Semantic
|
|
130
|
+
|
|
131
|
+
format?: JsonSchemaFormatName | string;
|
|
132
|
+
|
|
133
|
+
//endregion
|
|
134
|
+
|
|
135
|
+
//region String-Encoding Non-JSON Data
|
|
136
|
+
|
|
137
|
+
contentMediaType?: string;
|
|
138
|
+
contentEncoding?: string;
|
|
139
|
+
contentSchema?: JsonSchemaDef;
|
|
140
|
+
//endregion
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* use {@link $defs} instead
|
|
144
|
+
*/
|
|
145
|
+
definitions?: Record<string, JsonSchemaDef>;
|
|
146
|
+
|
|
147
|
+
//region Meta-Data Annotations
|
|
148
|
+
/**
|
|
149
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
title?: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
default?: JsonValue;
|
|
155
|
+
readOnly?: boolean;
|
|
156
|
+
writeOnly?: boolean;
|
|
157
|
+
examples?: JsonValue;
|
|
158
|
+
deprecated?: boolean;
|
|
169
159
|
|
|
170
|
-
|
|
160
|
+
//endregion
|
|
171
161
|
|
|
172
|
-
|
|
162
|
+
nullable?: boolean;
|
|
173
163
|
};
|