@naturalcycles/nodejs-lib 15.97.0 → 15.97.2
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.
|
@@ -53,9 +53,9 @@ export declare const j: {
|
|
|
53
53
|
withEnumKeys: typeof withEnumKeys;
|
|
54
54
|
withRegexKeys: typeof withRegexKeys;
|
|
55
55
|
};
|
|
56
|
-
array<OUT, Opt>(itemSchema:
|
|
57
|
-
tuple<const S extends
|
|
58
|
-
set<OUT, Opt>(itemSchema:
|
|
56
|
+
array<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JArray<OUT, Opt>;
|
|
57
|
+
tuple<const S extends JSchema<any, any>[]>(items: S): JTuple<S>;
|
|
58
|
+
set<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JSet2Builder<OUT, Opt>;
|
|
59
59
|
buffer(): JBuilder<Buffer<ArrayBufferLike>, false>;
|
|
60
60
|
enum<const T extends any>(input: T, opt?: JsonBuilderRuleOpt | undefined): JEnum<T extends readonly (infer U)[] ? U : T extends StringEnum ? T[keyof T] : T extends NumberEnum ? T[keyof T] : never, false>;
|
|
61
61
|
/**
|
|
@@ -69,7 +69,7 @@ export declare const j: {
|
|
|
69
69
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
70
70
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
71
71
|
*/
|
|
72
|
-
oneOf<B extends readonly
|
|
72
|
+
oneOf<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JBuilder<OUT, false>;
|
|
73
73
|
/**
|
|
74
74
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
75
75
|
* To validate objects, use `anyOfBy` or `anyOfThese`.
|
|
@@ -81,7 +81,7 @@ export declare const j: {
|
|
|
81
81
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
82
82
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
83
83
|
*/
|
|
84
|
-
anyOf<B extends readonly
|
|
84
|
+
anyOf<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JBuilder<OUT, false>;
|
|
85
85
|
/**
|
|
86
86
|
* Pick validation schema for an object based on the value of a specific property.
|
|
87
87
|
*
|
|
@@ -103,7 +103,7 @@ export declare const j: {
|
|
|
103
103
|
* const schema = j.anyOfThese([successSchema, errorSchema])
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
|
-
anyOfThese<B extends readonly
|
|
106
|
+
anyOfThese<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(items: [...B]): JBuilder<OUT, false>;
|
|
107
107
|
and(): {
|
|
108
108
|
silentBob: () => never;
|
|
109
109
|
};
|
|
@@ -331,10 +331,10 @@ export declare class JObject<OUT extends AnyObject, Opt extends boolean = false>
|
|
|
331
331
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
332
332
|
*/
|
|
333
333
|
allowAdditionalProperties(): this;
|
|
334
|
-
extend<P extends Record<string,
|
|
335
|
-
[K in keyof P as P[K] extends
|
|
334
|
+
extend<P extends Record<string, JSchema<any, any>>>(props: P): JObject<Override<OUT, {
|
|
335
|
+
[K in keyof P as P[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never;
|
|
336
336
|
} & {
|
|
337
|
-
[K in keyof P as P[K] extends
|
|
337
|
+
[K in keyof P as P[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never;
|
|
338
338
|
}>, false>;
|
|
339
339
|
/**
|
|
340
340
|
* Concatenates another schema to the current schema.
|
|
@@ -349,8 +349,8 @@ export declare class JObject<OUT extends AnyObject, Opt extends boolean = false>
|
|
|
349
349
|
*/
|
|
350
350
|
dbEntity(): JObject<Override<OUT, {
|
|
351
351
|
id: string;
|
|
352
|
-
created:
|
|
353
|
-
updated:
|
|
352
|
+
created: UnixTimestamp;
|
|
353
|
+
updated: UnixTimestamp;
|
|
354
354
|
} & {}>, false>;
|
|
355
355
|
minProperties(minProperties: number): this;
|
|
356
356
|
maxProperties(maxProperties: number): this;
|
|
@@ -361,17 +361,17 @@ interface JObjectOpts {
|
|
|
361
361
|
patternProperties?: StringMap<JsonSchema<any>>;
|
|
362
362
|
keySchema?: JsonSchema;
|
|
363
363
|
}
|
|
364
|
-
export declare class JObjectInfer<PROPS extends Record<string,
|
|
365
|
-
[K in keyof PROPS as PROPS[K] extends
|
|
364
|
+
export declare class JObjectInfer<PROPS extends Record<string, JSchema<any, any>>, Opt extends boolean = false> extends JBuilder<Expand<{
|
|
365
|
+
[K in keyof PROPS as PROPS[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: PROPS[K] extends JSchema<infer OUT, any> ? OUT : never;
|
|
366
366
|
} & {
|
|
367
|
-
[K in keyof PROPS as PROPS[K] extends
|
|
367
|
+
[K in keyof PROPS as PROPS[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: PROPS[K] extends JSchema<infer OUT, any> ? OUT : never;
|
|
368
368
|
}>, Opt> {
|
|
369
369
|
constructor(props?: PROPS);
|
|
370
370
|
/**
|
|
371
371
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
372
372
|
*/
|
|
373
373
|
allowAdditionalProperties(): this;
|
|
374
|
-
extend<NEW_PROPS extends Record<string,
|
|
374
|
+
extend<NEW_PROPS extends Record<string, JSchema<any, any>>>(props: NEW_PROPS): JObjectInfer<{
|
|
375
375
|
[K in keyof PROPS | keyof NEW_PROPS]: K extends keyof NEW_PROPS ? NEW_PROPS[K] : K extends keyof PROPS ? PROPS[K] : never;
|
|
376
376
|
}, Opt>;
|
|
377
377
|
/**
|
|
@@ -384,7 +384,7 @@ export declare class JObjectInfer<PROPS extends Record<string, JBuilder<any, any
|
|
|
384
384
|
}[K] : K extends keyof PROPS ? PROPS[K] : never; }, Opt>;
|
|
385
385
|
}
|
|
386
386
|
export declare class JArray<OUT, Opt> extends JBuilder<OUT[], Opt> {
|
|
387
|
-
constructor(itemsSchema:
|
|
387
|
+
constructor(itemsSchema: JSchema<OUT, Opt>);
|
|
388
388
|
minLength(minItems: number): this;
|
|
389
389
|
maxLength(maxItems: number): this;
|
|
390
390
|
length(exactLength: number): this;
|
|
@@ -393,7 +393,7 @@ export declare class JArray<OUT, Opt> extends JBuilder<OUT[], Opt> {
|
|
|
393
393
|
unique(): this;
|
|
394
394
|
}
|
|
395
395
|
declare class JSet2Builder<OUT, Opt> extends JBuilder<Set2<OUT>, Opt> {
|
|
396
|
-
constructor(itemsSchema:
|
|
396
|
+
constructor(itemsSchema: JSchema<OUT, Opt>);
|
|
397
397
|
min(minItems: number): this;
|
|
398
398
|
max(maxItems: number): this;
|
|
399
399
|
}
|
|
@@ -401,14 +401,14 @@ export declare class JEnum<OUT extends string | number | boolean | null, Opt ext
|
|
|
401
401
|
constructor(enumValues: readonly OUT[], baseType: EnumBaseType, opt?: JsonBuilderRuleOpt);
|
|
402
402
|
branded<B extends OUT>(): JEnum<B, Opt>;
|
|
403
403
|
}
|
|
404
|
-
export declare class JTuple<ITEMS extends
|
|
404
|
+
export declare class JTuple<ITEMS extends JSchema<any, any>[]> extends JBuilder<TupleOut<ITEMS>, false> {
|
|
405
405
|
constructor(items: ITEMS);
|
|
406
406
|
}
|
|
407
407
|
declare function object(props: AnyObject): never;
|
|
408
408
|
declare function object<OUT extends AnyObject>(props: {
|
|
409
409
|
[K in keyof Required<OUT>]-?: JSchema<OUT[K], any>;
|
|
410
410
|
}): JObject<OUT, false>;
|
|
411
|
-
declare function objectInfer<P extends Record<string,
|
|
411
|
+
declare function objectInfer<P extends Record<string, JSchema<any, any>>>(props: P): JObjectInfer<P, false>;
|
|
412
412
|
declare function objectDbEntity(props: AnyObject): never;
|
|
413
413
|
declare function objectDbEntity<OUT extends BaseDBEntity, EXTRA_KEYS extends Exclude<keyof OUT, keyof BaseDBEntity> = Exclude<keyof OUT, keyof BaseDBEntity>>(props: {
|
|
414
414
|
[K in EXTRA_KEYS]-?: BuilderFor<OUT[K]>;
|
|
@@ -425,12 +425,12 @@ declare function objectDbEntity<OUT extends BaseDBEntity, EXTRA_KEYS extends Exc
|
|
|
425
425
|
} : {
|
|
426
426
|
updated: BuilderFor<OUT['updated']>;
|
|
427
427
|
})): JObject<OUT, false>;
|
|
428
|
-
declare function record<KS extends
|
|
429
|
-
declare function withRegexKeys<S extends
|
|
428
|
+
declare function record<KS extends JSchema<any, any>, VS extends JSchema<any, any>, Opt extends boolean = SchemaOpt<VS>>(keySchema: KS, valueSchema: VS): JObject<Opt extends true ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>> : Record<SchemaOut<KS>, SchemaOut<VS>>, false>;
|
|
429
|
+
declare function withRegexKeys<S extends JSchema<any, any>>(keyRegex: RegExp | string, schema: S): JObject<StringMap<SchemaOut<S>>, false>;
|
|
430
430
|
/**
|
|
431
431
|
* Builds the object schema with the indicated `keys` and uses the `schema` for their validation.
|
|
432
432
|
*/
|
|
433
|
-
declare function withEnumKeys<const T extends readonly (string | number)[] | StringEnum | NumberEnum, S extends
|
|
433
|
+
declare function withEnumKeys<const T extends readonly (string | number)[] | StringEnum | NumberEnum, S extends JSchema<any, any>, K extends string | number = EnumKeyUnion<T>, Opt extends boolean = SchemaOpt<S>>(keys: T, schema: S): JObject<Opt extends true ? {
|
|
434
434
|
[P in K]?: SchemaOut<S>;
|
|
435
435
|
} : {
|
|
436
436
|
[P in K]: SchemaOut<S>;
|
|
@@ -621,13 +621,13 @@ type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
|
621
621
|
type IsAssignableRelaxed<A, B> = IsAny<RelaxIndexSignature<A>> extends true ? true : [RelaxIndexSignature<A>] extends [B] ? true : false;
|
|
622
622
|
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;
|
|
623
623
|
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>>>;
|
|
624
|
-
type BuilderOutUnion<B extends readonly
|
|
625
|
-
[K in keyof B]: B[K] extends
|
|
624
|
+
type BuilderOutUnion<B extends readonly JSchema<any, any>[]> = {
|
|
625
|
+
[K in keyof B]: B[K] extends JSchema<infer O, any> ? O : never;
|
|
626
626
|
}[number];
|
|
627
627
|
type AnyOfByOut<D extends Record<PropertyKey, JSchema<any, any>>> = {
|
|
628
628
|
[K in keyof D]: D[K] extends JSchema<infer O, any> ? O : never;
|
|
629
629
|
}[keyof D];
|
|
630
|
-
type BuilderFor<T> =
|
|
630
|
+
type BuilderFor<T> = JSchema<T, any>;
|
|
631
631
|
export interface JsonBuilderRuleOpt {
|
|
632
632
|
/**
|
|
633
633
|
* Text of error message to return when the validation fails for the given rule:
|
|
@@ -643,9 +643,9 @@ export interface JsonBuilderRuleOpt {
|
|
|
643
643
|
name?: string;
|
|
644
644
|
}
|
|
645
645
|
type EnumKeyUnion<T> = T extends readonly (infer U)[] ? U : T extends StringEnum | NumberEnum ? T[keyof T] : never;
|
|
646
|
-
type SchemaOut<S> = S extends
|
|
647
|
-
type SchemaOpt<S> = S extends
|
|
648
|
-
type TupleOut<T extends readonly
|
|
649
|
-
[K in keyof T]: T[K] extends
|
|
646
|
+
type SchemaOut<S> = S extends JSchema<infer OUT, any> ? OUT : never;
|
|
647
|
+
type SchemaOpt<S> = S extends JSchema<any, infer Opt> ? (Opt extends true ? true : false) : false;
|
|
648
|
+
type TupleOut<T extends readonly JSchema<any, any>[]> = {
|
|
649
|
+
[K in keyof T]: T[K] extends JSchema<infer O, any> ? O : never;
|
|
650
650
|
};
|
|
651
651
|
export {};
|
package/package.json
CHANGED
|
@@ -140,15 +140,15 @@ export const j = {
|
|
|
140
140
|
withRegexKeys,
|
|
141
141
|
}),
|
|
142
142
|
|
|
143
|
-
array<OUT, Opt>(itemSchema:
|
|
143
|
+
array<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JArray<OUT, Opt> {
|
|
144
144
|
return new JArray(itemSchema)
|
|
145
145
|
},
|
|
146
146
|
|
|
147
|
-
tuple<const S extends
|
|
147
|
+
tuple<const S extends JSchema<any, any>[]>(items: S): JTuple<S> {
|
|
148
148
|
return new JTuple<S>(items)
|
|
149
149
|
},
|
|
150
150
|
|
|
151
|
-
set<OUT, Opt>(itemSchema:
|
|
151
|
+
set<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JSet2Builder<OUT, Opt> {
|
|
152
152
|
return new JSet2Builder(itemSchema)
|
|
153
153
|
},
|
|
154
154
|
|
|
@@ -206,7 +206,7 @@ export const j = {
|
|
|
206
206
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
207
207
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
208
208
|
*/
|
|
209
|
-
oneOf<B extends readonly
|
|
209
|
+
oneOf<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(
|
|
210
210
|
items: [...B],
|
|
211
211
|
): JBuilder<OUT, false> {
|
|
212
212
|
const schemas = items.map(b => b.build())
|
|
@@ -231,7 +231,7 @@ export const j = {
|
|
|
231
231
|
* Use `anyOf` when schemas may overlap (e.g., AccountId | PartnerId with same format).
|
|
232
232
|
* Use `oneOf` when schemas are mutually exclusive.
|
|
233
233
|
*/
|
|
234
|
-
anyOf<B extends readonly
|
|
234
|
+
anyOf<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(
|
|
235
235
|
items: [...B],
|
|
236
236
|
): JBuilder<OUT, false> {
|
|
237
237
|
const schemas = items.map(b => b.build())
|
|
@@ -284,7 +284,7 @@ export const j = {
|
|
|
284
284
|
* const schema = j.anyOfThese([successSchema, errorSchema])
|
|
285
285
|
* ```
|
|
286
286
|
*/
|
|
287
|
-
anyOfThese<B extends readonly
|
|
287
|
+
anyOfThese<B extends readonly JSchema<any, boolean>[], OUT = BuilderOutUnion<B>>(
|
|
288
288
|
items: [...B],
|
|
289
289
|
): JBuilder<OUT, false> {
|
|
290
290
|
return new JBuilder<OUT, false>({
|
|
@@ -1063,25 +1063,25 @@ export class JObject<OUT extends AnyObject, Opt extends boolean = false> extends
|
|
|
1063
1063
|
return this.cloneAndUpdateSchema({ additionalProperties: true })
|
|
1064
1064
|
}
|
|
1065
1065
|
|
|
1066
|
-
extend<P extends Record<string,
|
|
1066
|
+
extend<P extends Record<string, JSchema<any, any>>>(
|
|
1067
1067
|
props: P,
|
|
1068
1068
|
): JObject<
|
|
1069
1069
|
Override<
|
|
1070
1070
|
OUT,
|
|
1071
1071
|
{
|
|
1072
1072
|
// required keys
|
|
1073
|
-
[K in keyof P as P[K] extends
|
|
1073
|
+
[K in keyof P as P[K] extends JSchema<any, infer IsOpt>
|
|
1074
1074
|
? IsOpt extends true
|
|
1075
1075
|
? never
|
|
1076
1076
|
: K
|
|
1077
|
-
: never]: P[K] extends
|
|
1077
|
+
: never]: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
|
|
1078
1078
|
} & {
|
|
1079
1079
|
// optional keys
|
|
1080
|
-
[K in keyof P as P[K] extends
|
|
1080
|
+
[K in keyof P as P[K] extends JSchema<any, infer IsOpt>
|
|
1081
1081
|
? IsOpt extends true
|
|
1082
1082
|
? K
|
|
1083
1083
|
: never
|
|
1084
|
-
: never]?: P[K] extends
|
|
1084
|
+
: never]?: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
|
|
1085
1085
|
}
|
|
1086
1086
|
>,
|
|
1087
1087
|
false
|
|
@@ -1144,22 +1144,22 @@ interface JObjectOpts {
|
|
|
1144
1144
|
}
|
|
1145
1145
|
|
|
1146
1146
|
export class JObjectInfer<
|
|
1147
|
-
PROPS extends Record<string,
|
|
1147
|
+
PROPS extends Record<string, JSchema<any, any>>,
|
|
1148
1148
|
Opt extends boolean = false,
|
|
1149
1149
|
> extends JBuilder<
|
|
1150
1150
|
Expand<
|
|
1151
1151
|
{
|
|
1152
|
-
[K in keyof PROPS as PROPS[K] extends
|
|
1152
|
+
[K in keyof PROPS as PROPS[K] extends JSchema<any, infer IsOpt>
|
|
1153
1153
|
? IsOpt extends true
|
|
1154
1154
|
? never
|
|
1155
1155
|
: K
|
|
1156
|
-
: never]: PROPS[K] extends
|
|
1156
|
+
: never]: PROPS[K] extends JSchema<infer OUT, any> ? OUT : never
|
|
1157
1157
|
} & {
|
|
1158
|
-
[K in keyof PROPS as PROPS[K] extends
|
|
1158
|
+
[K in keyof PROPS as PROPS[K] extends JSchema<any, infer IsOpt>
|
|
1159
1159
|
? IsOpt extends true
|
|
1160
1160
|
? K
|
|
1161
1161
|
: never
|
|
1162
|
-
: never]?: PROPS[K] extends
|
|
1162
|
+
: never]?: PROPS[K] extends JSchema<infer OUT, any> ? OUT : never
|
|
1163
1163
|
}
|
|
1164
1164
|
>,
|
|
1165
1165
|
Opt
|
|
@@ -1183,7 +1183,7 @@ export class JObjectInfer<
|
|
|
1183
1183
|
return this.cloneAndUpdateSchema({ additionalProperties: true })
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
|
-
extend<NEW_PROPS extends Record<string,
|
|
1186
|
+
extend<NEW_PROPS extends Record<string, JSchema<any, any>>>(
|
|
1187
1187
|
props: NEW_PROPS,
|
|
1188
1188
|
): JObjectInfer<
|
|
1189
1189
|
{
|
|
@@ -1232,7 +1232,7 @@ export class JObjectInfer<
|
|
|
1232
1232
|
}
|
|
1233
1233
|
|
|
1234
1234
|
export class JArray<OUT, Opt> extends JBuilder<OUT[], Opt> {
|
|
1235
|
-
constructor(itemsSchema:
|
|
1235
|
+
constructor(itemsSchema: JSchema<OUT, Opt>) {
|
|
1236
1236
|
super({
|
|
1237
1237
|
type: 'array',
|
|
1238
1238
|
items: itemsSchema.build(),
|
|
@@ -1264,7 +1264,7 @@ export class JArray<OUT, Opt> extends JBuilder<OUT[], Opt> {
|
|
|
1264
1264
|
}
|
|
1265
1265
|
|
|
1266
1266
|
class JSet2Builder<OUT, Opt> extends JBuilder<Set2<OUT>, Opt> {
|
|
1267
|
-
constructor(itemsSchema:
|
|
1267
|
+
constructor(itemsSchema: JSchema<OUT, Opt>) {
|
|
1268
1268
|
super({
|
|
1269
1269
|
type: ['array', 'object'],
|
|
1270
1270
|
Set2: itemsSchema.build(),
|
|
@@ -1302,7 +1302,7 @@ export class JEnum<
|
|
|
1302
1302
|
}
|
|
1303
1303
|
}
|
|
1304
1304
|
|
|
1305
|
-
export class JTuple<ITEMS extends
|
|
1305
|
+
export class JTuple<ITEMS extends JSchema<any, any>[]> extends JBuilder<TupleOut<ITEMS>, false> {
|
|
1306
1306
|
constructor(items: ITEMS) {
|
|
1307
1307
|
super({
|
|
1308
1308
|
type: 'array',
|
|
@@ -1326,7 +1326,7 @@ function object<OUT extends AnyObject>(props: {
|
|
|
1326
1326
|
return new JObject<OUT, false>(props)
|
|
1327
1327
|
}
|
|
1328
1328
|
|
|
1329
|
-
function objectInfer<P extends Record<string,
|
|
1329
|
+
function objectInfer<P extends Record<string, JSchema<any, any>>>(
|
|
1330
1330
|
props: P,
|
|
1331
1331
|
): JObjectInfer<P, false> {
|
|
1332
1332
|
return new JObjectInfer<P, false>(props)
|
|
@@ -1366,8 +1366,8 @@ function objectDbEntity(props: AnyObject): any {
|
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
1368
|
function record<
|
|
1369
|
-
KS extends
|
|
1370
|
-
VS extends
|
|
1369
|
+
KS extends JSchema<any, any>,
|
|
1370
|
+
VS extends JSchema<any, any>,
|
|
1371
1371
|
Opt extends boolean = SchemaOpt<VS>,
|
|
1372
1372
|
>(
|
|
1373
1373
|
keySchema: KS,
|
|
@@ -1402,7 +1402,7 @@ function record<
|
|
|
1402
1402
|
})
|
|
1403
1403
|
}
|
|
1404
1404
|
|
|
1405
|
-
function withRegexKeys<S extends
|
|
1405
|
+
function withRegexKeys<S extends JSchema<any, any>>(
|
|
1406
1406
|
keyRegex: RegExp | string,
|
|
1407
1407
|
schema: S,
|
|
1408
1408
|
): JObject<StringMap<SchemaOut<S>>, false> {
|
|
@@ -1428,7 +1428,7 @@ function withRegexKeys<S extends JBuilder<any, any>>(
|
|
|
1428
1428
|
*/
|
|
1429
1429
|
function withEnumKeys<
|
|
1430
1430
|
const T extends readonly (string | number)[] | StringEnum | NumberEnum,
|
|
1431
|
-
S extends
|
|
1431
|
+
S extends JSchema<any, any>,
|
|
1432
1432
|
K extends string | number = EnumKeyUnion<T>,
|
|
1433
1433
|
Opt extends boolean = SchemaOpt<S>,
|
|
1434
1434
|
>(
|
|
@@ -2117,15 +2117,15 @@ type ExactMatch<A, B> =
|
|
|
2117
2117
|
? true
|
|
2118
2118
|
: ExactMatchBase<Expand<StripIndexSignatureDeep<A>>, Expand<StripIndexSignatureDeep<B>>>
|
|
2119
2119
|
|
|
2120
|
-
type BuilderOutUnion<B extends readonly
|
|
2121
|
-
[K in keyof B]: B[K] extends
|
|
2120
|
+
type BuilderOutUnion<B extends readonly JSchema<any, any>[]> = {
|
|
2121
|
+
[K in keyof B]: B[K] extends JSchema<infer O, any> ? O : never
|
|
2122
2122
|
}[number]
|
|
2123
2123
|
|
|
2124
2124
|
type AnyOfByOut<D extends Record<PropertyKey, JSchema<any, any>>> = {
|
|
2125
2125
|
[K in keyof D]: D[K] extends JSchema<infer O, any> ? O : never
|
|
2126
2126
|
}[keyof D]
|
|
2127
2127
|
|
|
2128
|
-
type BuilderFor<T> =
|
|
2128
|
+
type BuilderFor<T> = JSchema<T, any>
|
|
2129
2129
|
|
|
2130
2130
|
export interface JsonBuilderRuleOpt {
|
|
2131
2131
|
/**
|
|
@@ -2151,9 +2151,9 @@ type EnumKeyUnion<T> =
|
|
|
2151
2151
|
? T[keyof T]
|
|
2152
2152
|
: never
|
|
2153
2153
|
|
|
2154
|
-
type SchemaOut<S> = S extends
|
|
2155
|
-
type SchemaOpt<S> = S extends
|
|
2154
|
+
type SchemaOut<S> = S extends JSchema<infer OUT, any> ? OUT : never
|
|
2155
|
+
type SchemaOpt<S> = S extends JSchema<any, infer Opt> ? (Opt extends true ? true : false) : false
|
|
2156
2156
|
|
|
2157
|
-
type TupleOut<T extends readonly
|
|
2158
|
-
[K in keyof T]: T[K] extends
|
|
2157
|
+
type TupleOut<T extends readonly JSchema<any, any>[]> = {
|
|
2158
|
+
[K in keyof T]: T[K] extends JSchema<infer O, any> ? O : never
|
|
2159
2159
|
}
|