@naturalcycles/nodejs-lib 15.91.0 → 15.92.1
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.
|
@@ -7,13 +7,13 @@ import { AjvValidationError } from './ajvValidationError.js';
|
|
|
7
7
|
* On creation - compiles ajv validation function.
|
|
8
8
|
* Provides convenient methods, error reporting, etc.
|
|
9
9
|
*/
|
|
10
|
-
export declare class AjvSchema<
|
|
11
|
-
schema: JsonSchema<
|
|
10
|
+
export declare class AjvSchema<OUT> {
|
|
11
|
+
schema: JsonSchema<OUT>;
|
|
12
12
|
private constructor();
|
|
13
13
|
/**
|
|
14
14
|
* Shortcut for AjvSchema.create(schema, { lazy: true })
|
|
15
15
|
*/
|
|
16
|
-
static createLazy<
|
|
16
|
+
static createLazy<OUT>(schema: SchemaHandledByAjv<OUT>, cfg?: Partial<AjvSchemaCfg>): AjvSchema<OUT>;
|
|
17
17
|
/**
|
|
18
18
|
* Conveniently allows to pass either JsonSchema or JsonSchemaBuilder, or existing AjvSchema.
|
|
19
19
|
* If it's already an AjvSchema - it'll just return it without any processing.
|
|
@@ -23,8 +23,8 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
23
23
|
* Implementation note: JsonSchemaBuilder goes first in the union type, otherwise TypeScript fails to infer <T> type
|
|
24
24
|
* correctly for some reason.
|
|
25
25
|
*/
|
|
26
|
-
static create<
|
|
27
|
-
static isJsonSchemaBuilder<
|
|
26
|
+
static create<OUT>(schema: SchemaHandledByAjv<OUT>, cfg?: Partial<AjvSchemaCfg>): AjvSchema<OUT>;
|
|
27
|
+
static isJsonSchemaBuilder<OUT>(schema: unknown): schema is JsonSchemaTerminal<OUT, any>;
|
|
28
28
|
readonly cfg: AjvSchemaCfg;
|
|
29
29
|
/**
|
|
30
30
|
* It returns the original object just for convenience.
|
|
@@ -34,16 +34,28 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
34
34
|
*
|
|
35
35
|
* Returned object is always the same object (`===`) that was passed, so it is returned just for convenience.
|
|
36
36
|
*/
|
|
37
|
-
validate(input:
|
|
38
|
-
isValid(input:
|
|
39
|
-
getValidationResult(input:
|
|
40
|
-
getValidationFunction(): ValidationFunction<
|
|
41
|
-
static isSchemaWithCachedAjvSchema<Base,
|
|
42
|
-
static cacheAjvSchema<Base extends AnyObject,
|
|
43
|
-
static requireCachedAjvSchema<Base,
|
|
37
|
+
validate(input: unknown, opt?: AjvValidationOptions): OUT;
|
|
38
|
+
isValid(input: unknown, opt?: AjvValidationOptions): boolean;
|
|
39
|
+
getValidationResult(input: unknown, opt?: AjvValidationOptions): ValidationFunctionResult<OUT, AjvValidationError>;
|
|
40
|
+
getValidationFunction(): ValidationFunction<OUT, AjvValidationError>;
|
|
41
|
+
static isSchemaWithCachedAjvSchema<Base, OUT>(schema: Base): schema is WithCachedAjvSchema<Base, OUT>;
|
|
42
|
+
static cacheAjvSchema<Base extends AnyObject, OUT>(schema: Base, ajvSchema: AjvSchema<OUT>): WithCachedAjvSchema<Base, OUT>;
|
|
43
|
+
static requireCachedAjvSchema<Base, OUT>(schema: WithCachedAjvSchema<Base, OUT>): AjvSchema<OUT>;
|
|
44
44
|
private getAJVValidateFunction;
|
|
45
45
|
private static requireValidJsonSchema;
|
|
46
46
|
private applyImprovementsOnErrorMessages;
|
|
47
|
+
/**
|
|
48
|
+
* Filters out noisy errors produced by nullable anyOf patterns.
|
|
49
|
+
* When `nullable()` wraps a schema in `anyOf: [realSchema, { type: 'null' }]`,
|
|
50
|
+
* AJV produces "must be null" and "must match a schema in anyOf" errors
|
|
51
|
+
* that are confusing. This method splices them out, keeping only the real errors.
|
|
52
|
+
*/
|
|
53
|
+
private filterNullableAnyOfErrors;
|
|
54
|
+
/**
|
|
55
|
+
* Navigates the schema tree using an AJV schemaPath (e.g. "#/properties/foo/anyOf")
|
|
56
|
+
* and returns the parent schema containing the last keyword.
|
|
57
|
+
*/
|
|
58
|
+
private resolveSchemaPath;
|
|
47
59
|
private getErrorMessageForInstancePath;
|
|
48
60
|
private traverseSchemaPath;
|
|
49
61
|
private getChildSchema;
|
|
@@ -51,10 +63,10 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
51
63
|
private getObjectPropertySchema;
|
|
52
64
|
}
|
|
53
65
|
export declare const HIDDEN_AJV_SCHEMA: unique symbol;
|
|
54
|
-
export type WithCachedAjvSchema<Base,
|
|
55
|
-
[HIDDEN_AJV_SCHEMA]: AjvSchema<
|
|
66
|
+
export type WithCachedAjvSchema<Base, OUT> = Base & {
|
|
67
|
+
[HIDDEN_AJV_SCHEMA]: AjvSchema<OUT>;
|
|
56
68
|
};
|
|
57
|
-
export interface AjvValidationOptions
|
|
69
|
+
export interface AjvValidationOptions {
|
|
58
70
|
/**
|
|
59
71
|
* Defaults to true,
|
|
60
72
|
* because that's how AJV works by default,
|
|
@@ -82,7 +94,7 @@ export interface AjvValidationOptions<IN> {
|
|
|
82
94
|
* can include it "how it was" in an error message. So, for that reason we'll use
|
|
83
95
|
* `getOriginalInput()`, if it's provided.
|
|
84
96
|
*/
|
|
85
|
-
getOriginalInput?: () =>
|
|
97
|
+
getOriginalInput?: () => unknown;
|
|
86
98
|
}
|
|
87
99
|
export interface AjvSchemaCfg {
|
|
88
100
|
/**
|
|
@@ -104,21 +116,21 @@ export interface AjvSchemaCfg {
|
|
|
104
116
|
*/
|
|
105
117
|
lazy?: boolean;
|
|
106
118
|
}
|
|
107
|
-
export type SchemaHandledByAjv<
|
|
119
|
+
export type SchemaHandledByAjv<OUT> = JsonSchemaTerminal<OUT, any> | JsonSchema<OUT> | AjvSchema<OUT>;
|
|
108
120
|
export declare const j: {
|
|
109
121
|
/**
|
|
110
122
|
* Matches literally any value - equivalent to TypeScript's `any` type.
|
|
111
123
|
* Use sparingly, as it bypasses type validation entirely.
|
|
112
124
|
*/
|
|
113
|
-
any(): JsonSchemaAnyBuilder<any,
|
|
114
|
-
string(): JsonSchemaStringBuilder<string,
|
|
115
|
-
number(): JsonSchemaNumberBuilder<number,
|
|
116
|
-
boolean(): JsonSchemaBooleanBuilder<boolean,
|
|
125
|
+
any(): JsonSchemaAnyBuilder<any, false>;
|
|
126
|
+
string(): JsonSchemaStringBuilder<string, false>;
|
|
127
|
+
number(): JsonSchemaNumberBuilder<number, false>;
|
|
128
|
+
boolean(): JsonSchemaBooleanBuilder<boolean, false>;
|
|
117
129
|
object: typeof object & {
|
|
118
130
|
dbEntity: typeof objectDbEntity;
|
|
119
131
|
infer: typeof objectInfer;
|
|
120
|
-
any(): JsonSchemaObjectBuilder<AnyObject,
|
|
121
|
-
stringMap<S extends JsonSchemaTerminal<any, any
|
|
132
|
+
any(): JsonSchemaObjectBuilder<AnyObject, false>;
|
|
133
|
+
stringMap<S extends JsonSchemaTerminal<any, any>>(schema: S): JsonSchemaObjectBuilder<StringMap<SchemaOut<S>>, false>;
|
|
122
134
|
/**
|
|
123
135
|
* @experimental Look around, maybe you find a rule that is better for your use-case.
|
|
124
136
|
*
|
|
@@ -154,11 +166,11 @@ export declare const j: {
|
|
|
154
166
|
withEnumKeys: typeof withEnumKeys;
|
|
155
167
|
withRegexKeys: typeof withRegexKeys;
|
|
156
168
|
};
|
|
157
|
-
array<
|
|
158
|
-
tuple<const S extends JsonSchemaAnyBuilder<any, any
|
|
159
|
-
set<
|
|
169
|
+
array<OUT, Opt>(itemSchema: JsonSchemaAnyBuilder<OUT, Opt>): JsonSchemaArrayBuilder<OUT, Opt>;
|
|
170
|
+
tuple<const S extends JsonSchemaAnyBuilder<any, any>[]>(items: S): JsonSchemaTupleBuilder<S>;
|
|
171
|
+
set<OUT, Opt>(itemSchema: JsonSchemaAnyBuilder<OUT, Opt>): JsonSchemaSet2Builder<OUT, Opt>;
|
|
160
172
|
buffer(): JsonSchemaBufferBuilder;
|
|
161
|
-
enum<const T extends any>(input: T, opt?: JsonBuilderRuleOpt | undefined): JsonSchemaEnumBuilder<T extends readonly (infer U)[] ? U : T extends StringEnum ? T[keyof T] : T extends NumberEnum ? T[keyof T] : never,
|
|
173
|
+
enum<const T extends any>(input: T, opt?: JsonBuilderRuleOpt | undefined): JsonSchemaEnumBuilder<T extends readonly (infer U)[] ? U : T extends StringEnum ? T[keyof T] : T extends NumberEnum ? T[keyof T] : never, false>;
|
|
162
174
|
/**
|
|
163
175
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
164
176
|
* To validate objects, use `anyOfBy`.
|
|
@@ -170,7 +182,7 @@ export declare const j: {
|
|
|
170
182
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
171
183
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
172
184
|
*/
|
|
173
|
-
oneOf<B extends readonly JsonSchemaAnyBuilder<any,
|
|
185
|
+
oneOf<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
174
186
|
/**
|
|
175
187
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
176
188
|
* To validate objects, use `anyOfBy` or `anyOfThese`.
|
|
@@ -182,7 +194,7 @@ export declare const j: {
|
|
|
182
194
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
183
195
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
184
196
|
*/
|
|
185
|
-
anyOf<B extends readonly JsonSchemaAnyBuilder<any,
|
|
197
|
+
anyOf<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
186
198
|
/**
|
|
187
199
|
* Pick validation schema for an object based on the value of a specific property.
|
|
188
200
|
*
|
|
@@ -195,7 +207,7 @@ export declare const j: {
|
|
|
195
207
|
* const schema = j.anyOfBy('success', schemaMap)
|
|
196
208
|
* ```
|
|
197
209
|
*/
|
|
198
|
-
anyOfBy<
|
|
210
|
+
anyOfBy<D extends Record<PropertyKey, JsonSchemaTerminal<any, any>>, OUT = AnyOfByOut<D>>(propertyName: string, schemaDictionary: D): JsonSchemaAnyOfByBuilder<OUT>;
|
|
199
211
|
/**
|
|
200
212
|
* Custom version of `anyOf` which - in contrast to the original function - does not mutate the input.
|
|
201
213
|
* This comes with a performance penalty, so do not use it where performance matters.
|
|
@@ -204,37 +216,46 @@ export declare const j: {
|
|
|
204
216
|
* const schema = j.anyOfThese([successSchema, errorSchema])
|
|
205
217
|
* ```
|
|
206
218
|
*/
|
|
207
|
-
anyOfThese<B extends readonly JsonSchemaAnyBuilder<any,
|
|
219
|
+
anyOfThese<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
208
220
|
and(): {
|
|
209
221
|
silentBob: () => never;
|
|
210
222
|
};
|
|
211
|
-
literal<const V extends string | number | boolean | null>(v: V): JsonSchemaEnumBuilder<V,
|
|
223
|
+
literal<const V extends string | number | boolean | null>(v: V): JsonSchemaEnumBuilder<V, false>;
|
|
212
224
|
};
|
|
213
|
-
export declare class JsonSchemaTerminal<
|
|
214
|
-
protected [HIDDEN_AJV_SCHEMA]: AjvSchema<any
|
|
225
|
+
export declare class JsonSchemaTerminal<OUT, Opt> {
|
|
226
|
+
protected [HIDDEN_AJV_SCHEMA]: AjvSchema<any> | undefined;
|
|
215
227
|
protected schema: JsonSchema;
|
|
216
228
|
constructor(schema: JsonSchema);
|
|
217
|
-
get ajvSchema(): AjvSchema<any
|
|
229
|
+
get ajvSchema(): AjvSchema<any>;
|
|
218
230
|
getSchema(): JsonSchema;
|
|
219
231
|
/**
|
|
220
232
|
* Produces a "clean schema object" without methods.
|
|
221
233
|
* Same as if it would be JSON.stringified.
|
|
222
234
|
*/
|
|
223
|
-
build(): JsonSchema<
|
|
235
|
+
build(): JsonSchema<OUT>;
|
|
224
236
|
clone(): this;
|
|
225
237
|
cloneAndUpdateSchema(schema: Partial<JsonSchema>): this;
|
|
226
|
-
validate(input:
|
|
227
|
-
isValid(input:
|
|
228
|
-
getValidationResult(input:
|
|
229
|
-
getValidationFunction(): ValidationFunction<
|
|
238
|
+
validate(input: unknown, opt?: AjvValidationOptions): OUT;
|
|
239
|
+
isValid(input: unknown, opt?: AjvValidationOptions): boolean;
|
|
240
|
+
getValidationResult(input: unknown, opt?: AjvValidationOptions): ValidationFunctionResult<OUT, AjvValidationError>;
|
|
241
|
+
getValidationFunction(): ValidationFunction<OUT, AjvValidationError>;
|
|
242
|
+
/**
|
|
243
|
+
* Specify a function to be called after the normal validation is finished.
|
|
244
|
+
*
|
|
245
|
+
* This function will receive the validated, type-safe data, and you can use it
|
|
246
|
+
* to do further validations, e.g. conditional validations based on certain property values,
|
|
247
|
+
* or to do data modifications either by mutating the input or returning a new value.
|
|
248
|
+
*
|
|
249
|
+
* If you throw an error from this function, it will show up as an error in the validation.
|
|
250
|
+
*/
|
|
251
|
+
postValidation<OUT2 = OUT>(fn: PostValidatonFn<OUT, OUT2>): JsonSchemaTerminal<OUT2, Opt>;
|
|
230
252
|
/**
|
|
231
253
|
* @experimental
|
|
232
254
|
*/
|
|
233
|
-
in: IN;
|
|
234
255
|
out: OUT;
|
|
235
256
|
opt: Opt;
|
|
236
257
|
}
|
|
237
|
-
export declare class JsonSchemaAnyBuilder<
|
|
258
|
+
export declare class JsonSchemaAnyBuilder<OUT, Opt> extends JsonSchemaTerminal<OUT, Opt> {
|
|
238
259
|
protected setErrorMessage(ruleName: string, errorMessage: string | undefined): void;
|
|
239
260
|
/**
|
|
240
261
|
* A helper function that takes a type parameter and compares it with the type inferred from the schema.
|
|
@@ -261,24 +282,24 @@ export declare class JsonSchemaAnyBuilder<IN, OUT, Opt> extends JsonSchemaTermin
|
|
|
261
282
|
type(type: string): this;
|
|
262
283
|
default(v: any): this;
|
|
263
284
|
instanceof(of: string): this;
|
|
264
|
-
optional(): JsonSchemaAnyBuilder<
|
|
265
|
-
nullable(): JsonSchemaAnyBuilder<
|
|
285
|
+
optional(): JsonSchemaAnyBuilder<OUT | undefined, true>;
|
|
286
|
+
nullable(): JsonSchemaAnyBuilder<OUT | null, Opt>;
|
|
266
287
|
/**
|
|
267
288
|
* @deprecated
|
|
268
289
|
* The usage of this function is discouraged as it defeats the purpose of having type-safe validation.
|
|
269
290
|
*/
|
|
270
|
-
castAs<T>(): JsonSchemaAnyBuilder<T,
|
|
291
|
+
castAs<T>(): JsonSchemaAnyBuilder<T, Opt>;
|
|
271
292
|
/**
|
|
272
293
|
* Locks the given schema chain and no other modification can be done to it.
|
|
273
294
|
*/
|
|
274
|
-
final(): JsonSchemaTerminal<
|
|
295
|
+
final(): JsonSchemaTerminal<OUT, Opt>;
|
|
275
296
|
/**
|
|
276
297
|
*
|
|
277
298
|
* @param validator A validator function that returns an error message or undefined.
|
|
278
299
|
*
|
|
279
300
|
* You may add multiple custom validators and they will be executed in the order you added them.
|
|
280
301
|
*/
|
|
281
|
-
custom<OUT2 = OUT>(validator: CustomValidatorFn): JsonSchemaAnyBuilder<
|
|
302
|
+
custom<OUT2 = OUT>(validator: CustomValidatorFn): JsonSchemaAnyBuilder<OUT2, Opt>;
|
|
282
303
|
/**
|
|
283
304
|
*
|
|
284
305
|
* @param converter A converter function that returns a new value.
|
|
@@ -289,9 +310,9 @@ export declare class JsonSchemaAnyBuilder<IN, OUT, Opt> extends JsonSchemaTermin
|
|
|
289
310
|
* This feature only works when the current schema is nested in an object or array schema,
|
|
290
311
|
* due to how mutability works in Ajv.
|
|
291
312
|
*/
|
|
292
|
-
convert<OUT2>(converter: CustomConverterFn<OUT2>): JsonSchemaAnyBuilder<
|
|
313
|
+
convert<OUT2>(converter: CustomConverterFn<OUT2>): JsonSchemaAnyBuilder<OUT2, Opt>;
|
|
293
314
|
}
|
|
294
|
-
export declare class JsonSchemaStringBuilder<
|
|
315
|
+
export declare class JsonSchemaStringBuilder<OUT extends string | undefined = string, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
295
316
|
constructor();
|
|
296
317
|
/**
|
|
297
318
|
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
@@ -304,7 +325,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
304
325
|
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
305
326
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
306
327
|
*/
|
|
307
|
-
optional<T extends readonly (string | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<
|
|
328
|
+
optional<T extends readonly (string | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<OUT | undefined, true> : JsonSchemaStringBuilder<OUT | undefined, true> : JsonSchemaStringBuilder<OUT | undefined, true>;
|
|
308
329
|
regex(pattern: RegExp, opt?: JsonBuilderRuleOpt): this;
|
|
309
330
|
pattern(pattern: string, opt?: JsonBuilderRuleOpt): this;
|
|
310
331
|
minLength(minLength: number): this;
|
|
@@ -316,7 +337,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
316
337
|
toLowerCase(): this;
|
|
317
338
|
toUpperCase(): this;
|
|
318
339
|
truncate(toLength: number): this;
|
|
319
|
-
branded<B extends string>(): JsonSchemaStringBuilder<B,
|
|
340
|
+
branded<B extends string>(): JsonSchemaStringBuilder<B, Opt>;
|
|
320
341
|
/**
|
|
321
342
|
* Validates that the input is a fully-specified YYYY-MM-DD formatted valid IsoDate value.
|
|
322
343
|
*
|
|
@@ -324,7 +345,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
324
345
|
* because this call effectively starts a new schema chain.
|
|
325
346
|
*/
|
|
326
347
|
isoDate(): JsonSchemaIsoDateBuilder;
|
|
327
|
-
isoDateTime(): JsonSchemaStringBuilder<IsoDateTime
|
|
348
|
+
isoDateTime(): JsonSchemaStringBuilder<IsoDateTime, Opt>;
|
|
328
349
|
isoMonth(): JsonSchemaIsoMonthBuilder;
|
|
329
350
|
/**
|
|
330
351
|
* Validates the string format to be JWT.
|
|
@@ -345,14 +366,14 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
345
366
|
* All previous expectations in the schema chain are dropped - including `.optional()` -
|
|
346
367
|
* because this call effectively starts a new schema chain as an `enum` validation.
|
|
347
368
|
*/
|
|
348
|
-
ianaTimezone(): JsonSchemaEnumBuilder<
|
|
369
|
+
ianaTimezone(): JsonSchemaEnumBuilder<IANATimezone, false>;
|
|
349
370
|
base64Url(): this;
|
|
350
371
|
uuid(): this;
|
|
351
372
|
}
|
|
352
373
|
export interface JsonSchemaStringEmailOptions {
|
|
353
374
|
checkTLD: boolean;
|
|
354
375
|
}
|
|
355
|
-
export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<
|
|
376
|
+
export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<IsoDate, Opt> {
|
|
356
377
|
constructor();
|
|
357
378
|
/**
|
|
358
379
|
* @param nullValue Pass `null` to have `null` values be considered/converted as `undefined`.
|
|
@@ -363,7 +384,7 @@ export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> exten
|
|
|
363
384
|
* When `null` is passed, the return type becomes `JsonSchemaTerminal`
|
|
364
385
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
365
386
|
*/
|
|
366
|
-
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<
|
|
387
|
+
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<IsoDate | undefined, true> : JsonSchemaAnyBuilder<IsoDate | undefined, true>;
|
|
367
388
|
before(date: string): this;
|
|
368
389
|
sameOrBefore(date: string): this;
|
|
369
390
|
after(date: string): this;
|
|
@@ -376,12 +397,12 @@ export interface JsonSchemaIsoDateOptions {
|
|
|
376
397
|
after?: string;
|
|
377
398
|
sameOrAfter?: string;
|
|
378
399
|
}
|
|
379
|
-
export declare class JsonSchemaIsoMonthBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<
|
|
400
|
+
export declare class JsonSchemaIsoMonthBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<IsoMonth, Opt> {
|
|
380
401
|
constructor();
|
|
381
402
|
}
|
|
382
403
|
export interface JsonSchemaIsoMonthOptions {
|
|
383
404
|
}
|
|
384
|
-
export declare class JsonSchemaNumberBuilder<
|
|
405
|
+
export declare class JsonSchemaNumberBuilder<OUT extends number | undefined = number, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
385
406
|
constructor();
|
|
386
407
|
/**
|
|
387
408
|
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
@@ -394,9 +415,9 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
394
415
|
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
395
416
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
396
417
|
*/
|
|
397
|
-
optional<T extends readonly (number | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<
|
|
418
|
+
optional<T extends readonly (number | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<OUT | undefined, true> : JsonSchemaNumberBuilder<OUT | undefined, true> : JsonSchemaNumberBuilder<OUT | undefined, true>;
|
|
398
419
|
integer(): this;
|
|
399
|
-
branded<B extends number>(): JsonSchemaNumberBuilder<B,
|
|
420
|
+
branded<B extends number>(): JsonSchemaNumberBuilder<B, Opt>;
|
|
400
421
|
multipleOf(multipleOf: number): this;
|
|
401
422
|
min(minimum: number): this;
|
|
402
423
|
exclusiveMin(exclusiveMinimum: number): this;
|
|
@@ -412,10 +433,10 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
412
433
|
int64(): this;
|
|
413
434
|
float(): this;
|
|
414
435
|
double(): this;
|
|
415
|
-
unixTimestamp(): JsonSchemaNumberBuilder<UnixTimestamp,
|
|
416
|
-
unixTimestamp2000(): JsonSchemaNumberBuilder<UnixTimestamp,
|
|
417
|
-
unixTimestampMillis(): JsonSchemaNumberBuilder<UnixTimestampMillis,
|
|
418
|
-
unixTimestamp2000Millis(): JsonSchemaNumberBuilder<UnixTimestampMillis,
|
|
436
|
+
unixTimestamp(): JsonSchemaNumberBuilder<UnixTimestamp, Opt>;
|
|
437
|
+
unixTimestamp2000(): JsonSchemaNumberBuilder<UnixTimestamp, Opt>;
|
|
438
|
+
unixTimestampMillis(): JsonSchemaNumberBuilder<UnixTimestampMillis, Opt>;
|
|
439
|
+
unixTimestamp2000Millis(): JsonSchemaNumberBuilder<UnixTimestampMillis, Opt>;
|
|
419
440
|
utcOffset(): this;
|
|
420
441
|
utcOffsetHour(): this;
|
|
421
442
|
/**
|
|
@@ -425,7 +446,7 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
425
446
|
*/
|
|
426
447
|
precision(numberOfDigits: number): this;
|
|
427
448
|
}
|
|
428
|
-
export declare class JsonSchemaBooleanBuilder<
|
|
449
|
+
export declare class JsonSchemaBooleanBuilder<OUT extends boolean | undefined = boolean, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
429
450
|
constructor();
|
|
430
451
|
/**
|
|
431
452
|
* @param optionalValue One of the two possible boolean values that should be considered/converted as `undefined`.
|
|
@@ -433,9 +454,9 @@ export declare class JsonSchemaBooleanBuilder<IN extends boolean | undefined = b
|
|
|
433
454
|
* This `optionalValue` feature only works when the current schema is nested in an object or array schema,
|
|
434
455
|
* due to how mutability works in Ajv.
|
|
435
456
|
*/
|
|
436
|
-
optional(optionalValue?: boolean): JsonSchemaBooleanBuilder<
|
|
457
|
+
optional(optionalValue?: boolean): JsonSchemaBooleanBuilder<OUT | undefined, true>;
|
|
437
458
|
}
|
|
438
|
-
export declare class JsonSchemaObjectBuilder<
|
|
459
|
+
export declare class JsonSchemaObjectBuilder<OUT extends AnyObject, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
439
460
|
constructor(props?: AnyObject, opt?: JsonSchemaObjectBuilderOpts);
|
|
440
461
|
addProperties(props: AnyObject): this;
|
|
441
462
|
/**
|
|
@@ -447,17 +468,15 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
|
|
|
447
468
|
* When `null` is passed, the return type becomes `JsonSchemaTerminal`
|
|
448
469
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
449
470
|
*/
|
|
450
|
-
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<
|
|
471
|
+
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<OUT | undefined, true> : JsonSchemaAnyBuilder<OUT | undefined, true>;
|
|
451
472
|
/**
|
|
452
473
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
453
474
|
*/
|
|
454
475
|
allowAdditionalProperties(): this;
|
|
455
|
-
extend<P extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
456
|
-
[K in keyof P]
|
|
457
|
-
}>>>, Override<OUT, {
|
|
458
|
-
[K in keyof P as P[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? never : K : never]: P[K] extends JsonSchemaAnyBuilder<any, infer OUT2, any> ? OUT2 : never;
|
|
476
|
+
extend<P extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: P): JsonSchemaObjectBuilder<Override<OUT, {
|
|
477
|
+
[K in keyof P as P[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: P[K] extends JsonSchemaAnyBuilder<infer OUT2, any> ? OUT2 : never;
|
|
459
478
|
} & {
|
|
460
|
-
[K in keyof P as P[K] extends JsonSchemaAnyBuilder<any,
|
|
479
|
+
[K in keyof P as P[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: P[K] extends JsonSchemaAnyBuilder<infer OUT2, any> ? OUT2 : never;
|
|
461
480
|
}>, false>;
|
|
462
481
|
/**
|
|
463
482
|
* Concatenates another schema to the current schema.
|
|
@@ -477,36 +496,28 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
|
|
|
477
496
|
* const shuSchema = fooSchema.concat(barSchema).isOfType<Shu>() // important
|
|
478
497
|
* ```
|
|
479
498
|
*/
|
|
480
|
-
concat<
|
|
499
|
+
concat<OUT2 extends AnyObject>(other: JsonSchemaObjectBuilder<OUT2, any>): JsonSchemaObjectBuilder<OUT & OUT2, false>;
|
|
481
500
|
/**
|
|
482
501
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
483
502
|
*/
|
|
484
|
-
dbEntity(): JsonSchemaObjectBuilder<
|
|
485
|
-
id?: string | undefined;
|
|
486
|
-
created?: any;
|
|
487
|
-
updated?: any;
|
|
488
|
-
}>>>, Override<OUT, {
|
|
503
|
+
dbEntity(): JsonSchemaObjectBuilder<Override<OUT, {
|
|
489
504
|
id: string;
|
|
490
505
|
created: any;
|
|
491
506
|
updated: any;
|
|
492
507
|
} & {}>, false>;
|
|
493
508
|
minProperties(minProperties: number): this;
|
|
494
509
|
maxProperties(maxProperties: number): this;
|
|
495
|
-
exclusiveProperties(propNames: readonly (keyof
|
|
510
|
+
exclusiveProperties(propNames: readonly (keyof OUT & string)[]): this;
|
|
496
511
|
}
|
|
497
512
|
interface JsonSchemaObjectBuilderOpts {
|
|
498
513
|
hasIsOfTypeCheck?: false;
|
|
499
|
-
patternProperties?: StringMap<JsonSchema<any
|
|
514
|
+
patternProperties?: StringMap<JsonSchema<any>>;
|
|
500
515
|
keySchema?: JsonSchema;
|
|
501
516
|
}
|
|
502
|
-
export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
503
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
517
|
+
export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<string, JsonSchemaAnyBuilder<any, any>>, Opt extends boolean = false> extends JsonSchemaAnyBuilder<Expand<{
|
|
518
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
504
519
|
} & {
|
|
505
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
506
|
-
}>, Expand<{
|
|
507
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<any, infer OUT, any> ? OUT : never;
|
|
508
|
-
} & {
|
|
509
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<any, infer OUT, any> ? OUT : never;
|
|
520
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
510
521
|
}>, Opt> {
|
|
511
522
|
constructor(props?: PROPS);
|
|
512
523
|
addProperties(props: PROPS): this;
|
|
@@ -520,40 +531,32 @@ export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<strin
|
|
|
520
531
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
521
532
|
*/
|
|
522
533
|
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<Expand<{
|
|
523
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
524
|
-
} & {
|
|
525
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<infer IN, any, any> ? IN : never;
|
|
526
|
-
}> | undefined, Expand<{
|
|
527
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<any, infer OUT, any> ? OUT : never;
|
|
534
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
528
535
|
} & {
|
|
529
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
536
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
530
537
|
}> | undefined, true> : JsonSchemaAnyBuilder<Expand<{
|
|
531
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
538
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
532
539
|
} & {
|
|
533
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
534
|
-
}> | undefined, Expand<{
|
|
535
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JsonSchemaAnyBuilder<any, infer OUT, any> ? OUT : never;
|
|
536
|
-
} & {
|
|
537
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<any, infer OUT, any> ? OUT : never;
|
|
540
|
+
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
538
541
|
}> | undefined, true>;
|
|
539
542
|
/**
|
|
540
543
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
541
544
|
*/
|
|
542
545
|
allowAdditionalProperties(): this;
|
|
543
|
-
extend<NEW_PROPS extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
546
|
+
extend<NEW_PROPS extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: NEW_PROPS): JsonSchemaObjectInferringBuilder<{
|
|
544
547
|
[K in keyof PROPS | keyof NEW_PROPS]: K extends keyof NEW_PROPS ? NEW_PROPS[K] : K extends keyof PROPS ? PROPS[K] : never;
|
|
545
548
|
}, Opt>;
|
|
546
549
|
/**
|
|
547
550
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
548
551
|
*/
|
|
549
552
|
dbEntity(): JsonSchemaObjectInferringBuilder<{ [K in "created" | "id" | "updated" | keyof PROPS]: K extends "created" | "id" | "updated" ? {
|
|
550
|
-
id: JsonSchemaStringBuilder<string,
|
|
551
|
-
created: JsonSchemaNumberBuilder<UnixTimestamp,
|
|
552
|
-
updated: JsonSchemaNumberBuilder<UnixTimestamp,
|
|
553
|
+
id: JsonSchemaStringBuilder<string, false>;
|
|
554
|
+
created: JsonSchemaNumberBuilder<UnixTimestamp, false>;
|
|
555
|
+
updated: JsonSchemaNumberBuilder<UnixTimestamp, false>;
|
|
553
556
|
}[K] : K extends keyof PROPS ? PROPS[K] : never; }, Opt>;
|
|
554
557
|
}
|
|
555
|
-
export declare class JsonSchemaArrayBuilder<
|
|
556
|
-
constructor(itemsSchema: JsonSchemaAnyBuilder<
|
|
558
|
+
export declare class JsonSchemaArrayBuilder<OUT, Opt> extends JsonSchemaAnyBuilder<OUT[], Opt> {
|
|
559
|
+
constructor(itemsSchema: JsonSchemaAnyBuilder<OUT, Opt>);
|
|
557
560
|
minLength(minItems: number): this;
|
|
558
561
|
maxLength(maxItems: number): this;
|
|
559
562
|
length(exactLength: number): this;
|
|
@@ -561,33 +564,29 @@ export declare class JsonSchemaArrayBuilder<IN, OUT, Opt> extends JsonSchemaAnyB
|
|
|
561
564
|
exactLength(length: number): this;
|
|
562
565
|
unique(): this;
|
|
563
566
|
}
|
|
564
|
-
export declare class JsonSchemaSet2Builder<
|
|
565
|
-
constructor(itemsSchema: JsonSchemaAnyBuilder<
|
|
567
|
+
export declare class JsonSchemaSet2Builder<OUT, Opt> extends JsonSchemaAnyBuilder<Set2<OUT>, Opt> {
|
|
568
|
+
constructor(itemsSchema: JsonSchemaAnyBuilder<OUT, Opt>);
|
|
566
569
|
min(minItems: number): this;
|
|
567
570
|
max(maxItems: number): this;
|
|
568
571
|
}
|
|
569
|
-
export declare class JsonSchemaBufferBuilder extends JsonSchemaAnyBuilder<
|
|
572
|
+
export declare class JsonSchemaBufferBuilder extends JsonSchemaAnyBuilder<Buffer, false> {
|
|
570
573
|
constructor();
|
|
571
574
|
}
|
|
572
|
-
export declare class JsonSchemaEnumBuilder<
|
|
573
|
-
constructor(enumValues: readonly
|
|
574
|
-
branded<B extends
|
|
575
|
+
export declare class JsonSchemaEnumBuilder<OUT extends string | number | boolean | null, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
576
|
+
constructor(enumValues: readonly OUT[], baseType: EnumBaseType, opt?: JsonBuilderRuleOpt);
|
|
577
|
+
branded<B extends OUT>(): JsonSchemaEnumBuilder<B, Opt>;
|
|
575
578
|
}
|
|
576
|
-
export declare class JsonSchemaTupleBuilder<ITEMS extends JsonSchemaAnyBuilder<any, any
|
|
577
|
-
private readonly _items;
|
|
579
|
+
export declare class JsonSchemaTupleBuilder<ITEMS extends JsonSchemaAnyBuilder<any, any>[]> extends JsonSchemaAnyBuilder<TupleOut<ITEMS>, false> {
|
|
578
580
|
constructor(items: ITEMS);
|
|
579
581
|
}
|
|
580
|
-
export declare class JsonSchemaAnyOfByBuilder<
|
|
581
|
-
|
|
582
|
-
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any, any>>);
|
|
582
|
+
export declare class JsonSchemaAnyOfByBuilder<OUT> extends JsonSchemaAnyBuilder<OUT, false> {
|
|
583
|
+
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any>>);
|
|
583
584
|
}
|
|
584
|
-
export declare class JsonSchemaAnyOfTheseBuilder<
|
|
585
|
-
|
|
586
|
-
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any, any>>);
|
|
585
|
+
export declare class JsonSchemaAnyOfTheseBuilder<OUT> extends JsonSchemaAnyBuilder<OUT, false> {
|
|
586
|
+
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any>>);
|
|
587
587
|
}
|
|
588
588
|
type EnumBaseType = 'string' | 'number' | 'other';
|
|
589
|
-
export interface JsonSchema<
|
|
590
|
-
readonly in?: IN;
|
|
589
|
+
export interface JsonSchema<OUT = unknown> {
|
|
591
590
|
readonly out?: OUT;
|
|
592
591
|
$schema?: string;
|
|
593
592
|
$id?: string;
|
|
@@ -600,14 +599,14 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
600
599
|
items?: JsonSchema;
|
|
601
600
|
prefixItems?: JsonSchema[];
|
|
602
601
|
properties?: {
|
|
603
|
-
[K in keyof
|
|
602
|
+
[K in keyof OUT]: JsonSchema<OUT[K]>;
|
|
604
603
|
};
|
|
605
|
-
patternProperties?: StringMap<JsonSchema<any
|
|
604
|
+
patternProperties?: StringMap<JsonSchema<any>>;
|
|
606
605
|
required?: string[];
|
|
607
606
|
additionalProperties?: boolean;
|
|
608
607
|
minProperties?: number;
|
|
609
608
|
maxProperties?: number;
|
|
610
|
-
default?:
|
|
609
|
+
default?: OUT;
|
|
611
610
|
if?: JsonSchema;
|
|
612
611
|
then?: JsonSchema;
|
|
613
612
|
else?: JsonSchema;
|
|
@@ -661,38 +660,35 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
661
660
|
precision?: number;
|
|
662
661
|
customValidations?: CustomValidatorFn[];
|
|
663
662
|
customConversions?: CustomConverterFn<any>[];
|
|
663
|
+
postValidation?: PostValidatonFn<any, OUT>;
|
|
664
664
|
}
|
|
665
665
|
declare function object(props: AnyObject): never;
|
|
666
|
-
declare function object<
|
|
667
|
-
[K in keyof Required<
|
|
668
|
-
}): JsonSchemaObjectBuilder<
|
|
669
|
-
declare function objectInfer<P extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
666
|
+
declare function object<OUT extends AnyObject>(props: {
|
|
667
|
+
[K in keyof Required<OUT>]-?: JsonSchemaTerminal<OUT[K], any>;
|
|
668
|
+
}): JsonSchemaObjectBuilder<OUT, false>;
|
|
669
|
+
declare function objectInfer<P extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: P): JsonSchemaObjectInferringBuilder<P, false>;
|
|
670
670
|
declare function objectDbEntity(props: AnyObject): never;
|
|
671
|
-
declare function objectDbEntity<
|
|
672
|
-
[K in EXTRA_KEYS]-?: BuilderFor<
|
|
673
|
-
} & (ExactMatch<
|
|
671
|
+
declare function objectDbEntity<OUT extends BaseDBEntity, EXTRA_KEYS extends Exclude<keyof OUT, keyof BaseDBEntity> = Exclude<keyof OUT, keyof BaseDBEntity>>(props: {
|
|
672
|
+
[K in EXTRA_KEYS]-?: BuilderFor<OUT[K]>;
|
|
673
|
+
} & (ExactMatch<OUT['id'], BaseDBEntity['id']> extends true ? {
|
|
674
674
|
id?: BuilderFor<BaseDBEntity['id']>;
|
|
675
675
|
} : {
|
|
676
|
-
id: BuilderFor<
|
|
677
|
-
}) & (ExactMatch<
|
|
676
|
+
id: BuilderFor<OUT['id']>;
|
|
677
|
+
}) & (ExactMatch<OUT['created'], BaseDBEntity['created']> extends true ? {
|
|
678
678
|
created?: BuilderFor<BaseDBEntity['created']>;
|
|
679
679
|
} : {
|
|
680
|
-
created: BuilderFor<
|
|
681
|
-
}) & (ExactMatch<
|
|
680
|
+
created: BuilderFor<OUT['created']>;
|
|
681
|
+
}) & (ExactMatch<OUT['updated'], BaseDBEntity['updated']> extends true ? {
|
|
682
682
|
updated?: BuilderFor<BaseDBEntity['updated']>;
|
|
683
683
|
} : {
|
|
684
|
-
updated: BuilderFor<
|
|
685
|
-
})): JsonSchemaObjectBuilder<
|
|
686
|
-
declare function record<KS extends JsonSchemaAnyBuilder<any, any
|
|
687
|
-
declare function withRegexKeys<S extends JsonSchemaAnyBuilder<any, any
|
|
684
|
+
updated: BuilderFor<OUT['updated']>;
|
|
685
|
+
})): JsonSchemaObjectBuilder<OUT, false>;
|
|
686
|
+
declare function record<KS extends JsonSchemaAnyBuilder<any, any>, VS extends JsonSchemaAnyBuilder<any, any>, Opt extends boolean = SchemaOpt<VS>>(keySchema: KS, valueSchema: VS): JsonSchemaObjectBuilder<Opt extends true ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>> : Record<SchemaOut<KS>, SchemaOut<VS>>, false>;
|
|
687
|
+
declare function withRegexKeys<S extends JsonSchemaAnyBuilder<any, any>>(keyRegex: RegExp | string, schema: S): JsonSchemaObjectBuilder<StringMap<SchemaOut<S>>, false>;
|
|
688
688
|
/**
|
|
689
689
|
* Builds the object schema with the indicated `keys` and uses the `schema` for their validation.
|
|
690
690
|
*/
|
|
691
|
-
declare function withEnumKeys<const T extends readonly (string | number)[] | StringEnum | NumberEnum, S extends JsonSchemaAnyBuilder<any, any
|
|
692
|
-
[P in K]?: SchemaIn<S>;
|
|
693
|
-
} : {
|
|
694
|
-
[P in K]: SchemaIn<S>;
|
|
695
|
-
}, Opt extends true ? {
|
|
691
|
+
declare function withEnumKeys<const T extends readonly (string | number)[] | StringEnum | NumberEnum, S extends JsonSchemaAnyBuilder<any, any>, K extends string | number = EnumKeyUnion<T>, Opt extends boolean = SchemaOpt<S>>(keys: T, schema: S): JsonSchemaObjectBuilder<Opt extends true ? {
|
|
696
692
|
[P in K]?: SchemaOut<S>;
|
|
697
693
|
} : {
|
|
698
694
|
[P in K]: SchemaOut<S>;
|
|
@@ -713,28 +709,15 @@ type HasAllowExtraKeys<T> = T extends {
|
|
|
713
709
|
} ? true : false;
|
|
714
710
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
715
711
|
type IsAssignableRelaxed<A, B> = IsAny<RelaxIndexSignature<A>> extends true ? true : [RelaxIndexSignature<A>] extends [B] ? true : false;
|
|
716
|
-
type OptionalDbEntityFields<T> = T extends BaseDBEntity ? Omit<T, keyof BaseDBEntity> & Partial<Pick<T, keyof BaseDBEntity>> : T;
|
|
717
712
|
type ExactMatchBase<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => (T extends B ? 1 : 2) ? (<T>() => T extends B ? 1 : 2) extends <T>() => (T extends A ? 1 : 2) ? true : false : false;
|
|
718
713
|
type ExactMatch<A, B> = HasAllowExtraKeys<B> extends true ? IsAssignableRelaxed<B, A> : ExactMatchBase<Expand<A>, Expand<B>> extends true ? true : ExactMatchBase<Expand<StripIndexSignatureDeep<A>>, Expand<StripIndexSignatureDeep<B>>>;
|
|
719
|
-
type BuilderOutUnion<B extends readonly JsonSchemaAnyBuilder<any, any
|
|
720
|
-
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<
|
|
714
|
+
type BuilderOutUnion<B extends readonly JsonSchemaAnyBuilder<any, any>[]> = {
|
|
715
|
+
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<infer O, any> ? O : never;
|
|
721
716
|
}[number];
|
|
722
|
-
type
|
|
723
|
-
[K in keyof
|
|
724
|
-
}[number];
|
|
725
|
-
type AnyOfByIn<D extends Record<PropertyKey, JsonSchemaTerminal<any, any, any>>> = {
|
|
726
|
-
[K in keyof D]: D[K] extends JsonSchemaTerminal<infer I, any, any> ? I : never;
|
|
727
|
-
}[keyof D];
|
|
728
|
-
type AnyOfByOut<D extends Record<PropertyKey, JsonSchemaTerminal<any, any, any>>> = {
|
|
729
|
-
[K in keyof D]: D[K] extends JsonSchemaTerminal<any, infer O, any> ? O : never;
|
|
717
|
+
type AnyOfByOut<D extends Record<PropertyKey, JsonSchemaTerminal<any, any>>> = {
|
|
718
|
+
[K in keyof D]: D[K] extends JsonSchemaTerminal<infer O, any> ? O : never;
|
|
730
719
|
}[keyof D];
|
|
731
|
-
type
|
|
732
|
-
[K in P]: infer V;
|
|
733
|
-
} ? V : never;
|
|
734
|
-
type AnyOfByInput<IN, P extends string, D = AnyOfByDiscriminant<IN, P>> = IN extends unknown ? Omit<Partial<IN>, P> & {
|
|
735
|
-
[K in P]?: D;
|
|
736
|
-
} : never;
|
|
737
|
-
type BuilderFor<T> = JsonSchemaAnyBuilder<any, T, any>;
|
|
720
|
+
type BuilderFor<T> = JsonSchemaAnyBuilder<T, any>;
|
|
738
721
|
interface JsonBuilderRuleOpt {
|
|
739
722
|
/**
|
|
740
723
|
* Text of error message to return when the validation fails for the given rule:
|
|
@@ -750,15 +733,12 @@ interface JsonBuilderRuleOpt {
|
|
|
750
733
|
name?: string;
|
|
751
734
|
}
|
|
752
735
|
type EnumKeyUnion<T> = T extends readonly (infer U)[] ? U : T extends StringEnum | NumberEnum ? T[keyof T] : never;
|
|
753
|
-
type
|
|
754
|
-
type
|
|
755
|
-
type
|
|
756
|
-
|
|
757
|
-
[K in keyof T]: T[K] extends JsonSchemaAnyBuilder<infer I, any, any> ? I : never;
|
|
758
|
-
};
|
|
759
|
-
type TupleOut<T extends readonly JsonSchemaAnyBuilder<any, any, any>[]> = {
|
|
760
|
-
[K in keyof T]: T[K] extends JsonSchemaAnyBuilder<any, infer O, any> ? O : never;
|
|
736
|
+
type SchemaOut<S> = S extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
737
|
+
type SchemaOpt<S> = S extends JsonSchemaAnyBuilder<any, infer Opt> ? (Opt extends true ? true : false) : false;
|
|
738
|
+
type TupleOut<T extends readonly JsonSchemaAnyBuilder<any, any>[]> = {
|
|
739
|
+
[K in keyof T]: T[K] extends JsonSchemaAnyBuilder<infer O, any> ? O : never;
|
|
761
740
|
};
|
|
741
|
+
export type PostValidatonFn<OUT, OUT2> = (v: OUT) => OUT2;
|
|
762
742
|
export type CustomValidatorFn = (v: any) => string | undefined;
|
|
763
743
|
export type CustomConverterFn<OUT> = (v: any) => OUT;
|
|
764
744
|
export {};
|