@naturalcycles/nodejs-lib 15.91.0 → 15.92.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.
|
@@ -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,13 +34,13 @@ 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;
|
|
@@ -51,10 +51,10 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
51
51
|
private getObjectPropertySchema;
|
|
52
52
|
}
|
|
53
53
|
export declare const HIDDEN_AJV_SCHEMA: unique symbol;
|
|
54
|
-
export type WithCachedAjvSchema<Base,
|
|
55
|
-
[HIDDEN_AJV_SCHEMA]: AjvSchema<
|
|
54
|
+
export type WithCachedAjvSchema<Base, OUT> = Base & {
|
|
55
|
+
[HIDDEN_AJV_SCHEMA]: AjvSchema<OUT>;
|
|
56
56
|
};
|
|
57
|
-
export interface AjvValidationOptions
|
|
57
|
+
export interface AjvValidationOptions {
|
|
58
58
|
/**
|
|
59
59
|
* Defaults to true,
|
|
60
60
|
* because that's how AJV works by default,
|
|
@@ -82,7 +82,7 @@ export interface AjvValidationOptions<IN> {
|
|
|
82
82
|
* can include it "how it was" in an error message. So, for that reason we'll use
|
|
83
83
|
* `getOriginalInput()`, if it's provided.
|
|
84
84
|
*/
|
|
85
|
-
getOriginalInput?: () =>
|
|
85
|
+
getOriginalInput?: () => unknown;
|
|
86
86
|
}
|
|
87
87
|
export interface AjvSchemaCfg {
|
|
88
88
|
/**
|
|
@@ -104,21 +104,21 @@ export interface AjvSchemaCfg {
|
|
|
104
104
|
*/
|
|
105
105
|
lazy?: boolean;
|
|
106
106
|
}
|
|
107
|
-
export type SchemaHandledByAjv<
|
|
107
|
+
export type SchemaHandledByAjv<OUT> = JsonSchemaTerminal<OUT, any> | JsonSchema<OUT> | AjvSchema<OUT>;
|
|
108
108
|
export declare const j: {
|
|
109
109
|
/**
|
|
110
110
|
* Matches literally any value - equivalent to TypeScript's `any` type.
|
|
111
111
|
* Use sparingly, as it bypasses type validation entirely.
|
|
112
112
|
*/
|
|
113
|
-
any(): JsonSchemaAnyBuilder<any,
|
|
114
|
-
string(): JsonSchemaStringBuilder<string,
|
|
115
|
-
number(): JsonSchemaNumberBuilder<number,
|
|
116
|
-
boolean(): JsonSchemaBooleanBuilder<boolean,
|
|
113
|
+
any(): JsonSchemaAnyBuilder<any, false>;
|
|
114
|
+
string(): JsonSchemaStringBuilder<string, false>;
|
|
115
|
+
number(): JsonSchemaNumberBuilder<number, false>;
|
|
116
|
+
boolean(): JsonSchemaBooleanBuilder<boolean, false>;
|
|
117
117
|
object: typeof object & {
|
|
118
118
|
dbEntity: typeof objectDbEntity;
|
|
119
119
|
infer: typeof objectInfer;
|
|
120
|
-
any(): JsonSchemaObjectBuilder<AnyObject,
|
|
121
|
-
stringMap<S extends JsonSchemaTerminal<any, any
|
|
120
|
+
any(): JsonSchemaObjectBuilder<AnyObject, false>;
|
|
121
|
+
stringMap<S extends JsonSchemaTerminal<any, any>>(schema: S): JsonSchemaObjectBuilder<StringMap<SchemaOut<S>>, false>;
|
|
122
122
|
/**
|
|
123
123
|
* @experimental Look around, maybe you find a rule that is better for your use-case.
|
|
124
124
|
*
|
|
@@ -154,11 +154,11 @@ export declare const j: {
|
|
|
154
154
|
withEnumKeys: typeof withEnumKeys;
|
|
155
155
|
withRegexKeys: typeof withRegexKeys;
|
|
156
156
|
};
|
|
157
|
-
array<
|
|
158
|
-
tuple<const S extends JsonSchemaAnyBuilder<any, any
|
|
159
|
-
set<
|
|
157
|
+
array<OUT, Opt>(itemSchema: JsonSchemaAnyBuilder<OUT, Opt>): JsonSchemaArrayBuilder<OUT, Opt>;
|
|
158
|
+
tuple<const S extends JsonSchemaAnyBuilder<any, any>[]>(items: S): JsonSchemaTupleBuilder<S>;
|
|
159
|
+
set<OUT, Opt>(itemSchema: JsonSchemaAnyBuilder<OUT, Opt>): JsonSchemaSet2Builder<OUT, Opt>;
|
|
160
160
|
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,
|
|
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, false>;
|
|
162
162
|
/**
|
|
163
163
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
164
164
|
* To validate objects, use `anyOfBy`.
|
|
@@ -170,7 +170,7 @@ export declare const j: {
|
|
|
170
170
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
171
171
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
172
172
|
*/
|
|
173
|
-
oneOf<B extends readonly JsonSchemaAnyBuilder<any,
|
|
173
|
+
oneOf<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
174
174
|
/**
|
|
175
175
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
176
176
|
* To validate objects, use `anyOfBy` or `anyOfThese`.
|
|
@@ -182,7 +182,7 @@ export declare const j: {
|
|
|
182
182
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
183
183
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
184
184
|
*/
|
|
185
|
-
anyOf<B extends readonly JsonSchemaAnyBuilder<any,
|
|
185
|
+
anyOf<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
186
186
|
/**
|
|
187
187
|
* Pick validation schema for an object based on the value of a specific property.
|
|
188
188
|
*
|
|
@@ -195,7 +195,7 @@ export declare const j: {
|
|
|
195
195
|
* const schema = j.anyOfBy('success', schemaMap)
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
|
-
anyOfBy<
|
|
198
|
+
anyOfBy<D extends Record<PropertyKey, JsonSchemaTerminal<any, any>>, OUT = AnyOfByOut<D>>(propertyName: string, schemaDictionary: D): JsonSchemaAnyOfByBuilder<OUT>;
|
|
199
199
|
/**
|
|
200
200
|
* Custom version of `anyOf` which - in contrast to the original function - does not mutate the input.
|
|
201
201
|
* This comes with a performance penalty, so do not use it where performance matters.
|
|
@@ -204,37 +204,46 @@ export declare const j: {
|
|
|
204
204
|
* const schema = j.anyOfThese([successSchema, errorSchema])
|
|
205
205
|
* ```
|
|
206
206
|
*/
|
|
207
|
-
anyOfThese<B extends readonly JsonSchemaAnyBuilder<any,
|
|
207
|
+
anyOfThese<B extends readonly JsonSchemaAnyBuilder<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JsonSchemaAnyBuilder<OUT, false>;
|
|
208
208
|
and(): {
|
|
209
209
|
silentBob: () => never;
|
|
210
210
|
};
|
|
211
|
-
literal<const V extends string | number | boolean | null>(v: V): JsonSchemaEnumBuilder<V,
|
|
211
|
+
literal<const V extends string | number | boolean | null>(v: V): JsonSchemaEnumBuilder<V, false>;
|
|
212
212
|
};
|
|
213
|
-
export declare class JsonSchemaTerminal<
|
|
214
|
-
protected [HIDDEN_AJV_SCHEMA]: AjvSchema<any
|
|
213
|
+
export declare class JsonSchemaTerminal<OUT, Opt> {
|
|
214
|
+
protected [HIDDEN_AJV_SCHEMA]: AjvSchema<any> | undefined;
|
|
215
215
|
protected schema: JsonSchema;
|
|
216
216
|
constructor(schema: JsonSchema);
|
|
217
|
-
get ajvSchema(): AjvSchema<any
|
|
217
|
+
get ajvSchema(): AjvSchema<any>;
|
|
218
218
|
getSchema(): JsonSchema;
|
|
219
219
|
/**
|
|
220
220
|
* Produces a "clean schema object" without methods.
|
|
221
221
|
* Same as if it would be JSON.stringified.
|
|
222
222
|
*/
|
|
223
|
-
build(): JsonSchema<
|
|
223
|
+
build(): JsonSchema<OUT>;
|
|
224
224
|
clone(): this;
|
|
225
225
|
cloneAndUpdateSchema(schema: Partial<JsonSchema>): this;
|
|
226
|
-
validate(input:
|
|
227
|
-
isValid(input:
|
|
228
|
-
getValidationResult(input:
|
|
229
|
-
getValidationFunction(): ValidationFunction<
|
|
226
|
+
validate(input: unknown, opt?: AjvValidationOptions): OUT;
|
|
227
|
+
isValid(input: unknown, opt?: AjvValidationOptions): boolean;
|
|
228
|
+
getValidationResult(input: unknown, opt?: AjvValidationOptions): ValidationFunctionResult<OUT, AjvValidationError>;
|
|
229
|
+
getValidationFunction(): ValidationFunction<OUT, AjvValidationError>;
|
|
230
|
+
/**
|
|
231
|
+
* Specify a function to be called after the normal validation is finished.
|
|
232
|
+
*
|
|
233
|
+
* This function will receive the validated, type-safe data, and you can use it
|
|
234
|
+
* to do further validations, e.g. conditional validations based on certain property values,
|
|
235
|
+
* or to do data modifications either by mutating the input or returning a new value.
|
|
236
|
+
*
|
|
237
|
+
* If you throw an error from this function, it will show up as an error in the validation.
|
|
238
|
+
*/
|
|
239
|
+
postValidation<OUT2 = OUT>(fn: PostValidatonFn<OUT, OUT2>): JsonSchemaTerminal<OUT2, Opt>;
|
|
230
240
|
/**
|
|
231
241
|
* @experimental
|
|
232
242
|
*/
|
|
233
|
-
in: IN;
|
|
234
243
|
out: OUT;
|
|
235
244
|
opt: Opt;
|
|
236
245
|
}
|
|
237
|
-
export declare class JsonSchemaAnyBuilder<
|
|
246
|
+
export declare class JsonSchemaAnyBuilder<OUT, Opt> extends JsonSchemaTerminal<OUT, Opt> {
|
|
238
247
|
protected setErrorMessage(ruleName: string, errorMessage: string | undefined): void;
|
|
239
248
|
/**
|
|
240
249
|
* A helper function that takes a type parameter and compares it with the type inferred from the schema.
|
|
@@ -261,24 +270,24 @@ export declare class JsonSchemaAnyBuilder<IN, OUT, Opt> extends JsonSchemaTermin
|
|
|
261
270
|
type(type: string): this;
|
|
262
271
|
default(v: any): this;
|
|
263
272
|
instanceof(of: string): this;
|
|
264
|
-
optional(): JsonSchemaAnyBuilder<
|
|
265
|
-
nullable(): JsonSchemaAnyBuilder<
|
|
273
|
+
optional(): JsonSchemaAnyBuilder<OUT | undefined, true>;
|
|
274
|
+
nullable(): JsonSchemaAnyBuilder<OUT | null, Opt>;
|
|
266
275
|
/**
|
|
267
276
|
* @deprecated
|
|
268
277
|
* The usage of this function is discouraged as it defeats the purpose of having type-safe validation.
|
|
269
278
|
*/
|
|
270
|
-
castAs<T>(): JsonSchemaAnyBuilder<T,
|
|
279
|
+
castAs<T>(): JsonSchemaAnyBuilder<T, Opt>;
|
|
271
280
|
/**
|
|
272
281
|
* Locks the given schema chain and no other modification can be done to it.
|
|
273
282
|
*/
|
|
274
|
-
final(): JsonSchemaTerminal<
|
|
283
|
+
final(): JsonSchemaTerminal<OUT, Opt>;
|
|
275
284
|
/**
|
|
276
285
|
*
|
|
277
286
|
* @param validator A validator function that returns an error message or undefined.
|
|
278
287
|
*
|
|
279
288
|
* You may add multiple custom validators and they will be executed in the order you added them.
|
|
280
289
|
*/
|
|
281
|
-
custom<OUT2 = OUT>(validator: CustomValidatorFn): JsonSchemaAnyBuilder<
|
|
290
|
+
custom<OUT2 = OUT>(validator: CustomValidatorFn): JsonSchemaAnyBuilder<OUT2, Opt>;
|
|
282
291
|
/**
|
|
283
292
|
*
|
|
284
293
|
* @param converter A converter function that returns a new value.
|
|
@@ -289,9 +298,9 @@ export declare class JsonSchemaAnyBuilder<IN, OUT, Opt> extends JsonSchemaTermin
|
|
|
289
298
|
* This feature only works when the current schema is nested in an object or array schema,
|
|
290
299
|
* due to how mutability works in Ajv.
|
|
291
300
|
*/
|
|
292
|
-
convert<OUT2>(converter: CustomConverterFn<OUT2>): JsonSchemaAnyBuilder<
|
|
301
|
+
convert<OUT2>(converter: CustomConverterFn<OUT2>): JsonSchemaAnyBuilder<OUT2, Opt>;
|
|
293
302
|
}
|
|
294
|
-
export declare class JsonSchemaStringBuilder<
|
|
303
|
+
export declare class JsonSchemaStringBuilder<OUT extends string | undefined = string, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
295
304
|
constructor();
|
|
296
305
|
/**
|
|
297
306
|
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
@@ -304,7 +313,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
304
313
|
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
305
314
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
306
315
|
*/
|
|
307
|
-
optional<T extends readonly (string | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<
|
|
316
|
+
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
317
|
regex(pattern: RegExp, opt?: JsonBuilderRuleOpt): this;
|
|
309
318
|
pattern(pattern: string, opt?: JsonBuilderRuleOpt): this;
|
|
310
319
|
minLength(minLength: number): this;
|
|
@@ -316,7 +325,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
316
325
|
toLowerCase(): this;
|
|
317
326
|
toUpperCase(): this;
|
|
318
327
|
truncate(toLength: number): this;
|
|
319
|
-
branded<B extends string>(): JsonSchemaStringBuilder<B,
|
|
328
|
+
branded<B extends string>(): JsonSchemaStringBuilder<B, Opt>;
|
|
320
329
|
/**
|
|
321
330
|
* Validates that the input is a fully-specified YYYY-MM-DD formatted valid IsoDate value.
|
|
322
331
|
*
|
|
@@ -324,7 +333,7 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
324
333
|
* because this call effectively starts a new schema chain.
|
|
325
334
|
*/
|
|
326
335
|
isoDate(): JsonSchemaIsoDateBuilder;
|
|
327
|
-
isoDateTime(): JsonSchemaStringBuilder<IsoDateTime
|
|
336
|
+
isoDateTime(): JsonSchemaStringBuilder<IsoDateTime, Opt>;
|
|
328
337
|
isoMonth(): JsonSchemaIsoMonthBuilder;
|
|
329
338
|
/**
|
|
330
339
|
* Validates the string format to be JWT.
|
|
@@ -345,14 +354,14 @@ export declare class JsonSchemaStringBuilder<IN extends string | undefined = str
|
|
|
345
354
|
* All previous expectations in the schema chain are dropped - including `.optional()` -
|
|
346
355
|
* because this call effectively starts a new schema chain as an `enum` validation.
|
|
347
356
|
*/
|
|
348
|
-
ianaTimezone(): JsonSchemaEnumBuilder<
|
|
357
|
+
ianaTimezone(): JsonSchemaEnumBuilder<IANATimezone, false>;
|
|
349
358
|
base64Url(): this;
|
|
350
359
|
uuid(): this;
|
|
351
360
|
}
|
|
352
361
|
export interface JsonSchemaStringEmailOptions {
|
|
353
362
|
checkTLD: boolean;
|
|
354
363
|
}
|
|
355
|
-
export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<
|
|
364
|
+
export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<IsoDate, Opt> {
|
|
356
365
|
constructor();
|
|
357
366
|
/**
|
|
358
367
|
* @param nullValue Pass `null` to have `null` values be considered/converted as `undefined`.
|
|
@@ -363,7 +372,7 @@ export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> exten
|
|
|
363
372
|
* When `null` is passed, the return type becomes `JsonSchemaTerminal`
|
|
364
373
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
365
374
|
*/
|
|
366
|
-
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<
|
|
375
|
+
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<IsoDate | undefined, true> : JsonSchemaAnyBuilder<IsoDate | undefined, true>;
|
|
367
376
|
before(date: string): this;
|
|
368
377
|
sameOrBefore(date: string): this;
|
|
369
378
|
after(date: string): this;
|
|
@@ -376,12 +385,12 @@ export interface JsonSchemaIsoDateOptions {
|
|
|
376
385
|
after?: string;
|
|
377
386
|
sameOrAfter?: string;
|
|
378
387
|
}
|
|
379
|
-
export declare class JsonSchemaIsoMonthBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<
|
|
388
|
+
export declare class JsonSchemaIsoMonthBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<IsoMonth, Opt> {
|
|
380
389
|
constructor();
|
|
381
390
|
}
|
|
382
391
|
export interface JsonSchemaIsoMonthOptions {
|
|
383
392
|
}
|
|
384
|
-
export declare class JsonSchemaNumberBuilder<
|
|
393
|
+
export declare class JsonSchemaNumberBuilder<OUT extends number | undefined = number, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
385
394
|
constructor();
|
|
386
395
|
/**
|
|
387
396
|
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
@@ -394,9 +403,9 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
394
403
|
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
395
404
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
396
405
|
*/
|
|
397
|
-
optional<T extends readonly (number | null)[] | undefined = undefined>(optionalValues?: T): T extends readonly (infer U)[] ? null extends U ? JsonSchemaTerminal<
|
|
406
|
+
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
407
|
integer(): this;
|
|
399
|
-
branded<B extends number>(): JsonSchemaNumberBuilder<B,
|
|
408
|
+
branded<B extends number>(): JsonSchemaNumberBuilder<B, Opt>;
|
|
400
409
|
multipleOf(multipleOf: number): this;
|
|
401
410
|
min(minimum: number): this;
|
|
402
411
|
exclusiveMin(exclusiveMinimum: number): this;
|
|
@@ -412,10 +421,10 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
412
421
|
int64(): this;
|
|
413
422
|
float(): this;
|
|
414
423
|
double(): this;
|
|
415
|
-
unixTimestamp(): JsonSchemaNumberBuilder<UnixTimestamp,
|
|
416
|
-
unixTimestamp2000(): JsonSchemaNumberBuilder<UnixTimestamp,
|
|
417
|
-
unixTimestampMillis(): JsonSchemaNumberBuilder<UnixTimestampMillis,
|
|
418
|
-
unixTimestamp2000Millis(): JsonSchemaNumberBuilder<UnixTimestampMillis,
|
|
424
|
+
unixTimestamp(): JsonSchemaNumberBuilder<UnixTimestamp, Opt>;
|
|
425
|
+
unixTimestamp2000(): JsonSchemaNumberBuilder<UnixTimestamp, Opt>;
|
|
426
|
+
unixTimestampMillis(): JsonSchemaNumberBuilder<UnixTimestampMillis, Opt>;
|
|
427
|
+
unixTimestamp2000Millis(): JsonSchemaNumberBuilder<UnixTimestampMillis, Opt>;
|
|
419
428
|
utcOffset(): this;
|
|
420
429
|
utcOffsetHour(): this;
|
|
421
430
|
/**
|
|
@@ -425,7 +434,7 @@ export declare class JsonSchemaNumberBuilder<IN extends number | undefined = num
|
|
|
425
434
|
*/
|
|
426
435
|
precision(numberOfDigits: number): this;
|
|
427
436
|
}
|
|
428
|
-
export declare class JsonSchemaBooleanBuilder<
|
|
437
|
+
export declare class JsonSchemaBooleanBuilder<OUT extends boolean | undefined = boolean, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
429
438
|
constructor();
|
|
430
439
|
/**
|
|
431
440
|
* @param optionalValue One of the two possible boolean values that should be considered/converted as `undefined`.
|
|
@@ -433,9 +442,9 @@ export declare class JsonSchemaBooleanBuilder<IN extends boolean | undefined = b
|
|
|
433
442
|
* This `optionalValue` feature only works when the current schema is nested in an object or array schema,
|
|
434
443
|
* due to how mutability works in Ajv.
|
|
435
444
|
*/
|
|
436
|
-
optional(optionalValue?: boolean): JsonSchemaBooleanBuilder<
|
|
445
|
+
optional(optionalValue?: boolean): JsonSchemaBooleanBuilder<OUT | undefined, true>;
|
|
437
446
|
}
|
|
438
|
-
export declare class JsonSchemaObjectBuilder<
|
|
447
|
+
export declare class JsonSchemaObjectBuilder<OUT extends AnyObject, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
439
448
|
constructor(props?: AnyObject, opt?: JsonSchemaObjectBuilderOpts);
|
|
440
449
|
addProperties(props: AnyObject): this;
|
|
441
450
|
/**
|
|
@@ -447,17 +456,15 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
|
|
|
447
456
|
* When `null` is passed, the return type becomes `JsonSchemaTerminal`
|
|
448
457
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
449
458
|
*/
|
|
450
|
-
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<
|
|
459
|
+
optional<N extends null | undefined = undefined>(nullValue?: N): N extends null ? JsonSchemaTerminal<OUT | undefined, true> : JsonSchemaAnyBuilder<OUT | undefined, true>;
|
|
451
460
|
/**
|
|
452
461
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
453
462
|
*/
|
|
454
463
|
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;
|
|
464
|
+
extend<P extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: P): JsonSchemaObjectBuilder<Override<OUT, {
|
|
465
|
+
[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
466
|
} & {
|
|
460
|
-
[K in keyof P as P[K] extends JsonSchemaAnyBuilder<any,
|
|
467
|
+
[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
468
|
}>, false>;
|
|
462
469
|
/**
|
|
463
470
|
* Concatenates another schema to the current schema.
|
|
@@ -477,36 +484,28 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
|
|
|
477
484
|
* const shuSchema = fooSchema.concat(barSchema).isOfType<Shu>() // important
|
|
478
485
|
* ```
|
|
479
486
|
*/
|
|
480
|
-
concat<
|
|
487
|
+
concat<OUT2 extends AnyObject>(other: JsonSchemaObjectBuilder<OUT2, any>): JsonSchemaObjectBuilder<OUT & OUT2, false>;
|
|
481
488
|
/**
|
|
482
489
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
483
490
|
*/
|
|
484
|
-
dbEntity(): JsonSchemaObjectBuilder<
|
|
485
|
-
id?: string | undefined;
|
|
486
|
-
created?: any;
|
|
487
|
-
updated?: any;
|
|
488
|
-
}>>>, Override<OUT, {
|
|
491
|
+
dbEntity(): JsonSchemaObjectBuilder<Override<OUT, {
|
|
489
492
|
id: string;
|
|
490
493
|
created: any;
|
|
491
494
|
updated: any;
|
|
492
495
|
} & {}>, false>;
|
|
493
496
|
minProperties(minProperties: number): this;
|
|
494
497
|
maxProperties(maxProperties: number): this;
|
|
495
|
-
exclusiveProperties(propNames: readonly (keyof
|
|
498
|
+
exclusiveProperties(propNames: readonly (keyof OUT & string)[]): this;
|
|
496
499
|
}
|
|
497
500
|
interface JsonSchemaObjectBuilderOpts {
|
|
498
501
|
hasIsOfTypeCheck?: false;
|
|
499
|
-
patternProperties?: StringMap<JsonSchema<any
|
|
502
|
+
patternProperties?: StringMap<JsonSchema<any>>;
|
|
500
503
|
keySchema?: JsonSchema;
|
|
501
504
|
}
|
|
502
|
-
export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
503
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
504
|
-
} & {
|
|
505
|
-
[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;
|
|
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;
|
|
505
|
+
export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<string, JsonSchemaAnyBuilder<any, any>>, Opt extends boolean = false> extends JsonSchemaAnyBuilder<Expand<{
|
|
506
|
+
[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;
|
|
508
507
|
} & {
|
|
509
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
508
|
+
[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
509
|
}>, Opt> {
|
|
511
510
|
constructor(props?: PROPS);
|
|
512
511
|
addProperties(props: PROPS): this;
|
|
@@ -520,40 +519,32 @@ export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<strin
|
|
|
520
519
|
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
521
520
|
*/
|
|
522
521
|
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;
|
|
522
|
+
[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
523
|
} & {
|
|
529
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
524
|
+
[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
525
|
}> | undefined, true> : JsonSchemaAnyBuilder<Expand<{
|
|
531
|
-
[K in keyof PROPS as PROPS[K] extends JsonSchemaAnyBuilder<any,
|
|
526
|
+
[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
527
|
} & {
|
|
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;
|
|
528
|
+
[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
529
|
}> | undefined, true>;
|
|
539
530
|
/**
|
|
540
531
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
541
532
|
*/
|
|
542
533
|
allowAdditionalProperties(): this;
|
|
543
|
-
extend<NEW_PROPS extends Record<string, JsonSchemaAnyBuilder<any, any
|
|
534
|
+
extend<NEW_PROPS extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: NEW_PROPS): JsonSchemaObjectInferringBuilder<{
|
|
544
535
|
[K in keyof PROPS | keyof NEW_PROPS]: K extends keyof NEW_PROPS ? NEW_PROPS[K] : K extends keyof PROPS ? PROPS[K] : never;
|
|
545
536
|
}, Opt>;
|
|
546
537
|
/**
|
|
547
538
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
548
539
|
*/
|
|
549
540
|
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,
|
|
541
|
+
id: JsonSchemaStringBuilder<string, false>;
|
|
542
|
+
created: JsonSchemaNumberBuilder<UnixTimestamp, false>;
|
|
543
|
+
updated: JsonSchemaNumberBuilder<UnixTimestamp, false>;
|
|
553
544
|
}[K] : K extends keyof PROPS ? PROPS[K] : never; }, Opt>;
|
|
554
545
|
}
|
|
555
|
-
export declare class JsonSchemaArrayBuilder<
|
|
556
|
-
constructor(itemsSchema: JsonSchemaAnyBuilder<
|
|
546
|
+
export declare class JsonSchemaArrayBuilder<OUT, Opt> extends JsonSchemaAnyBuilder<OUT[], Opt> {
|
|
547
|
+
constructor(itemsSchema: JsonSchemaAnyBuilder<OUT, Opt>);
|
|
557
548
|
minLength(minItems: number): this;
|
|
558
549
|
maxLength(maxItems: number): this;
|
|
559
550
|
length(exactLength: number): this;
|
|
@@ -561,33 +552,29 @@ export declare class JsonSchemaArrayBuilder<IN, OUT, Opt> extends JsonSchemaAnyB
|
|
|
561
552
|
exactLength(length: number): this;
|
|
562
553
|
unique(): this;
|
|
563
554
|
}
|
|
564
|
-
export declare class JsonSchemaSet2Builder<
|
|
565
|
-
constructor(itemsSchema: JsonSchemaAnyBuilder<
|
|
555
|
+
export declare class JsonSchemaSet2Builder<OUT, Opt> extends JsonSchemaAnyBuilder<Set2<OUT>, Opt> {
|
|
556
|
+
constructor(itemsSchema: JsonSchemaAnyBuilder<OUT, Opt>);
|
|
566
557
|
min(minItems: number): this;
|
|
567
558
|
max(maxItems: number): this;
|
|
568
559
|
}
|
|
569
|
-
export declare class JsonSchemaBufferBuilder extends JsonSchemaAnyBuilder<
|
|
560
|
+
export declare class JsonSchemaBufferBuilder extends JsonSchemaAnyBuilder<Buffer, false> {
|
|
570
561
|
constructor();
|
|
571
562
|
}
|
|
572
|
-
export declare class JsonSchemaEnumBuilder<
|
|
573
|
-
constructor(enumValues: readonly
|
|
574
|
-
branded<B extends
|
|
563
|
+
export declare class JsonSchemaEnumBuilder<OUT extends string | number | boolean | null, Opt extends boolean = false> extends JsonSchemaAnyBuilder<OUT, Opt> {
|
|
564
|
+
constructor(enumValues: readonly OUT[], baseType: EnumBaseType, opt?: JsonBuilderRuleOpt);
|
|
565
|
+
branded<B extends OUT>(): JsonSchemaEnumBuilder<B, Opt>;
|
|
575
566
|
}
|
|
576
|
-
export declare class JsonSchemaTupleBuilder<ITEMS extends JsonSchemaAnyBuilder<any, any
|
|
577
|
-
private readonly _items;
|
|
567
|
+
export declare class JsonSchemaTupleBuilder<ITEMS extends JsonSchemaAnyBuilder<any, any>[]> extends JsonSchemaAnyBuilder<TupleOut<ITEMS>, false> {
|
|
578
568
|
constructor(items: ITEMS);
|
|
579
569
|
}
|
|
580
|
-
export declare class JsonSchemaAnyOfByBuilder<
|
|
581
|
-
|
|
582
|
-
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any, any>>);
|
|
570
|
+
export declare class JsonSchemaAnyOfByBuilder<OUT> extends JsonSchemaAnyBuilder<OUT, false> {
|
|
571
|
+
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any>>);
|
|
583
572
|
}
|
|
584
|
-
export declare class JsonSchemaAnyOfTheseBuilder<
|
|
585
|
-
|
|
586
|
-
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any, any>>);
|
|
573
|
+
export declare class JsonSchemaAnyOfTheseBuilder<OUT> extends JsonSchemaAnyBuilder<OUT, false> {
|
|
574
|
+
constructor(propertyName: string, schemaDictionary: Record<PropertyKey, JsonSchemaTerminal<any, any>>);
|
|
587
575
|
}
|
|
588
576
|
type EnumBaseType = 'string' | 'number' | 'other';
|
|
589
|
-
export interface JsonSchema<
|
|
590
|
-
readonly in?: IN;
|
|
577
|
+
export interface JsonSchema<OUT = unknown> {
|
|
591
578
|
readonly out?: OUT;
|
|
592
579
|
$schema?: string;
|
|
593
580
|
$id?: string;
|
|
@@ -600,14 +587,14 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
600
587
|
items?: JsonSchema;
|
|
601
588
|
prefixItems?: JsonSchema[];
|
|
602
589
|
properties?: {
|
|
603
|
-
[K in keyof
|
|
590
|
+
[K in keyof OUT]: JsonSchema<OUT[K]>;
|
|
604
591
|
};
|
|
605
|
-
patternProperties?: StringMap<JsonSchema<any
|
|
592
|
+
patternProperties?: StringMap<JsonSchema<any>>;
|
|
606
593
|
required?: string[];
|
|
607
594
|
additionalProperties?: boolean;
|
|
608
595
|
minProperties?: number;
|
|
609
596
|
maxProperties?: number;
|
|
610
|
-
default?:
|
|
597
|
+
default?: OUT;
|
|
611
598
|
if?: JsonSchema;
|
|
612
599
|
then?: JsonSchema;
|
|
613
600
|
else?: JsonSchema;
|
|
@@ -661,38 +648,35 @@ export interface JsonSchema<IN = unknown, OUT = IN> {
|
|
|
661
648
|
precision?: number;
|
|
662
649
|
customValidations?: CustomValidatorFn[];
|
|
663
650
|
customConversions?: CustomConverterFn<any>[];
|
|
651
|
+
postValidation?: PostValidatonFn<any, OUT>;
|
|
664
652
|
}
|
|
665
653
|
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
|
|
654
|
+
declare function object<OUT extends AnyObject>(props: {
|
|
655
|
+
[K in keyof Required<OUT>]-?: JsonSchemaTerminal<OUT[K], any>;
|
|
656
|
+
}): JsonSchemaObjectBuilder<OUT, false>;
|
|
657
|
+
declare function objectInfer<P extends Record<string, JsonSchemaAnyBuilder<any, any>>>(props: P): JsonSchemaObjectInferringBuilder<P, false>;
|
|
670
658
|
declare function objectDbEntity(props: AnyObject): never;
|
|
671
|
-
declare function objectDbEntity<
|
|
672
|
-
[K in EXTRA_KEYS]-?: BuilderFor<
|
|
673
|
-
} & (ExactMatch<
|
|
659
|
+
declare function objectDbEntity<OUT extends BaseDBEntity, EXTRA_KEYS extends Exclude<keyof OUT, keyof BaseDBEntity> = Exclude<keyof OUT, keyof BaseDBEntity>>(props: {
|
|
660
|
+
[K in EXTRA_KEYS]-?: BuilderFor<OUT[K]>;
|
|
661
|
+
} & (ExactMatch<OUT['id'], BaseDBEntity['id']> extends true ? {
|
|
674
662
|
id?: BuilderFor<BaseDBEntity['id']>;
|
|
675
663
|
} : {
|
|
676
|
-
id: BuilderFor<
|
|
677
|
-
}) & (ExactMatch<
|
|
664
|
+
id: BuilderFor<OUT['id']>;
|
|
665
|
+
}) & (ExactMatch<OUT['created'], BaseDBEntity['created']> extends true ? {
|
|
678
666
|
created?: BuilderFor<BaseDBEntity['created']>;
|
|
679
667
|
} : {
|
|
680
|
-
created: BuilderFor<
|
|
681
|
-
}) & (ExactMatch<
|
|
668
|
+
created: BuilderFor<OUT['created']>;
|
|
669
|
+
}) & (ExactMatch<OUT['updated'], BaseDBEntity['updated']> extends true ? {
|
|
682
670
|
updated?: BuilderFor<BaseDBEntity['updated']>;
|
|
683
671
|
} : {
|
|
684
|
-
updated: BuilderFor<
|
|
685
|
-
})): JsonSchemaObjectBuilder<
|
|
686
|
-
declare function record<KS extends JsonSchemaAnyBuilder<any, any
|
|
687
|
-
declare function withRegexKeys<S extends JsonSchemaAnyBuilder<any, any
|
|
672
|
+
updated: BuilderFor<OUT['updated']>;
|
|
673
|
+
})): JsonSchemaObjectBuilder<OUT, false>;
|
|
674
|
+
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>;
|
|
675
|
+
declare function withRegexKeys<S extends JsonSchemaAnyBuilder<any, any>>(keyRegex: RegExp | string, schema: S): JsonSchemaObjectBuilder<StringMap<SchemaOut<S>>, false>;
|
|
688
676
|
/**
|
|
689
677
|
* Builds the object schema with the indicated `keys` and uses the `schema` for their validation.
|
|
690
678
|
*/
|
|
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 ? {
|
|
679
|
+
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
680
|
[P in K]?: SchemaOut<S>;
|
|
697
681
|
} : {
|
|
698
682
|
[P in K]: SchemaOut<S>;
|
|
@@ -713,28 +697,15 @@ type HasAllowExtraKeys<T> = T extends {
|
|
|
713
697
|
} ? true : false;
|
|
714
698
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
715
699
|
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
700
|
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
701
|
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<
|
|
721
|
-
}[number];
|
|
722
|
-
type BuilderInUnion<B extends readonly JsonSchemaAnyBuilder<any, any, any>[]> = {
|
|
723
|
-
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<infer I, any, any> ? I : never;
|
|
702
|
+
type BuilderOutUnion<B extends readonly JsonSchemaAnyBuilder<any, any>[]> = {
|
|
703
|
+
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<infer O, any> ? O : never;
|
|
724
704
|
}[number];
|
|
725
|
-
type
|
|
726
|
-
[K in keyof D]: D[K] extends JsonSchemaTerminal<infer
|
|
705
|
+
type AnyOfByOut<D extends Record<PropertyKey, JsonSchemaTerminal<any, any>>> = {
|
|
706
|
+
[K in keyof D]: D[K] extends JsonSchemaTerminal<infer O, any> ? O : never;
|
|
727
707
|
}[keyof D];
|
|
728
|
-
type
|
|
729
|
-
[K in keyof D]: D[K] extends JsonSchemaTerminal<any, infer O, any> ? O : never;
|
|
730
|
-
}[keyof D];
|
|
731
|
-
type AnyOfByDiscriminant<IN, P extends string> = IN extends {
|
|
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>;
|
|
708
|
+
type BuilderFor<T> = JsonSchemaAnyBuilder<T, any>;
|
|
738
709
|
interface JsonBuilderRuleOpt {
|
|
739
710
|
/**
|
|
740
711
|
* Text of error message to return when the validation fails for the given rule:
|
|
@@ -750,15 +721,12 @@ interface JsonBuilderRuleOpt {
|
|
|
750
721
|
name?: string;
|
|
751
722
|
}
|
|
752
723
|
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;
|
|
724
|
+
type SchemaOut<S> = S extends JsonSchemaAnyBuilder<infer OUT, any> ? OUT : never;
|
|
725
|
+
type SchemaOpt<S> = S extends JsonSchemaAnyBuilder<any, infer Opt> ? (Opt extends true ? true : false) : false;
|
|
726
|
+
type TupleOut<T extends readonly JsonSchemaAnyBuilder<any, any>[]> = {
|
|
727
|
+
[K in keyof T]: T[K] extends JsonSchemaAnyBuilder<infer O, any> ? O : never;
|
|
761
728
|
};
|
|
729
|
+
export type PostValidatonFn<OUT, OUT2> = (v: OUT) => OUT2;
|
|
762
730
|
export type CustomValidatorFn = (v: any) => string | undefined;
|
|
763
731
|
export type CustomConverterFn<OUT> = (v: any) => OUT;
|
|
764
732
|
export {};
|