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