@naturalcycles/nodejs-lib 15.45.0 → 15.46.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.
|
@@ -66,8 +66,8 @@ export declare class JsonSchemaStringBuilder<IN extends string = string, OUT = I
|
|
|
66
66
|
constructor();
|
|
67
67
|
regex(pattern: RegExp, opt?: JsonBuilderRuleOpt): this;
|
|
68
68
|
pattern(pattern: string, opt?: JsonBuilderRuleOpt): this;
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
minLength(minLength: number): this;
|
|
70
|
+
maxLength(maxLength: number): this;
|
|
71
71
|
length(minLength: number, maxLength: number): this;
|
|
72
72
|
email(opt?: Partial<JsonSchemaStringEmailOptions>): this;
|
|
73
73
|
trim(): this;
|
|
@@ -115,6 +115,7 @@ export declare class JsonSchemaNumberBuilder<IN extends number = number, OUT = I
|
|
|
115
115
|
lessThanOrEqual(value: number): this;
|
|
116
116
|
moreThan(value: number): this;
|
|
117
117
|
moreThanOrEqual(value: number): this;
|
|
118
|
+
equal(value: number): this;
|
|
118
119
|
range(minimum: number, maximum: number, incl: Inclusiveness): this;
|
|
119
120
|
int32(): this;
|
|
120
121
|
int64(): this;
|
|
@@ -172,8 +173,10 @@ export declare class JsonSchemaObjectInferringBuilder<PROPS extends Record<strin
|
|
|
172
173
|
}
|
|
173
174
|
export declare class JsonSchemaArrayBuilder<IN, OUT, Opt> extends JsonSchemaAnyBuilder<IN[], OUT[], Opt> {
|
|
174
175
|
constructor(itemsSchema: JsonSchemaAnyBuilder<IN, OUT, Opt>);
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
minLength(minItems: number): this;
|
|
177
|
+
maxLength(maxItems: number): this;
|
|
178
|
+
length(minItems: number, maxItems: number): this;
|
|
179
|
+
exactLength(length: number): this;
|
|
177
180
|
unique(uniqueItems: number): this;
|
|
178
181
|
}
|
|
179
182
|
export declare class JsonSchemaSet2Builder<IN, OUT, Opt> extends JsonSchemaAnyBuilder<Iterable<IN>, Set2<OUT>, Opt> {
|
|
@@ -249,15 +252,14 @@ declare function object<IN extends AnyObject>(props: {
|
|
|
249
252
|
[key in keyof IN]: JsonSchemaAnyBuilder<any, IN[key], any>;
|
|
250
253
|
}): JsonSchemaObjectBuilder<IN, IN, false>;
|
|
251
254
|
declare function objectInfer<P extends Record<string, JsonSchemaAnyBuilder<any, any, any>>>(props: P): JsonSchemaObjectInferringBuilder<P, false>;
|
|
252
|
-
declare function objectDbEntity(props
|
|
253
|
-
declare function objectDbEntity<IN extends AnyObject>(props
|
|
254
|
-
[
|
|
255
|
+
declare function objectDbEntity(props: AnyObject): never;
|
|
256
|
+
declare function objectDbEntity<IN extends AnyObject, EXTRA_KEYS extends Exclude<keyof IN, 'id' | 'created' | 'updated'> = Exclude<keyof IN, 'id' | 'created' | 'updated'>>(props: {
|
|
257
|
+
[K in EXTRA_KEYS]: JsonSchemaAnyBuilder<any, IN[K], any>;
|
|
255
258
|
}): JsonSchemaObjectBuilder<IN, IN, false>;
|
|
256
259
|
type Expand<T> = T extends infer O ? {
|
|
257
260
|
[K in keyof O]: O[K];
|
|
258
261
|
} : never;
|
|
259
262
|
type ExactMatch<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
260
|
-
type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
261
263
|
type BuilderOutUnion<B extends readonly JsonSchemaAnyBuilder<any, any, any>[]> = {
|
|
262
264
|
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<any, infer O, any> ? O : never;
|
|
263
265
|
}[number];
|
|
@@ -185,11 +185,11 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
|
185
185
|
Object.assign(this.schema, { pattern });
|
|
186
186
|
return this;
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
minLength(minLength) {
|
|
189
189
|
Object.assign(this.schema, { minLength });
|
|
190
190
|
return this;
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
maxLength(maxLength) {
|
|
193
193
|
Object.assign(this.schema, { maxLength });
|
|
194
194
|
return this;
|
|
195
195
|
}
|
|
@@ -334,6 +334,9 @@ export class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
|
|
|
334
334
|
moreThanOrEqual(value) {
|
|
335
335
|
return this.min(value);
|
|
336
336
|
}
|
|
337
|
+
equal(value) {
|
|
338
|
+
return this.min(value).max(value);
|
|
339
|
+
}
|
|
337
340
|
range(minimum, maximum, incl) {
|
|
338
341
|
if (incl === '[)') {
|
|
339
342
|
return this.moreThanOrEqual(minimum).lessThan(maximum);
|
|
@@ -507,14 +510,20 @@ export class JsonSchemaArrayBuilder extends JsonSchemaAnyBuilder {
|
|
|
507
510
|
items: itemsSchema.build(),
|
|
508
511
|
});
|
|
509
512
|
}
|
|
510
|
-
|
|
513
|
+
minLength(minItems) {
|
|
511
514
|
Object.assign(this.schema, { minItems });
|
|
512
515
|
return this;
|
|
513
516
|
}
|
|
514
|
-
|
|
517
|
+
maxLength(maxItems) {
|
|
515
518
|
Object.assign(this.schema, { maxItems });
|
|
516
519
|
return this;
|
|
517
520
|
}
|
|
521
|
+
length(minItems, maxItems) {
|
|
522
|
+
return this.minLength(minItems).maxLength(maxItems);
|
|
523
|
+
}
|
|
524
|
+
exactLength(length) {
|
|
525
|
+
return this.minLength(length).maxLength(length);
|
|
526
|
+
}
|
|
518
527
|
unique(uniqueItems) {
|
|
519
528
|
Object.assign(this.schema, { uniqueItems });
|
|
520
529
|
return this;
|
package/package.json
CHANGED
|
@@ -256,12 +256,12 @@ export class JsonSchemaStringBuilder<
|
|
|
256
256
|
return this
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
minLength(minLength: number): this {
|
|
260
260
|
Object.assign(this.schema, { minLength })
|
|
261
261
|
return this
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
maxLength(maxLength: number): this {
|
|
265
265
|
Object.assign(this.schema, { maxLength })
|
|
266
266
|
return this
|
|
267
267
|
}
|
|
@@ -452,6 +452,10 @@ export class JsonSchemaNumberBuilder<
|
|
|
452
452
|
return this.min(value)
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
+
equal(value: number): this {
|
|
456
|
+
return this.min(value).max(value)
|
|
457
|
+
}
|
|
458
|
+
|
|
455
459
|
range(minimum: number, maximum: number, incl: Inclusiveness): this {
|
|
456
460
|
if (incl === '[)') {
|
|
457
461
|
return this.moreThanOrEqual(minimum).lessThan(maximum)
|
|
@@ -725,16 +729,24 @@ export class JsonSchemaArrayBuilder<IN, OUT, Opt> extends JsonSchemaAnyBuilder<I
|
|
|
725
729
|
})
|
|
726
730
|
}
|
|
727
731
|
|
|
728
|
-
|
|
732
|
+
minLength(minItems: number): this {
|
|
729
733
|
Object.assign(this.schema, { minItems })
|
|
730
734
|
return this
|
|
731
735
|
}
|
|
732
736
|
|
|
733
|
-
|
|
737
|
+
maxLength(maxItems: number): this {
|
|
734
738
|
Object.assign(this.schema, { maxItems })
|
|
735
739
|
return this
|
|
736
740
|
}
|
|
737
741
|
|
|
742
|
+
length(minItems: number, maxItems: number): this {
|
|
743
|
+
return this.minLength(minItems).maxLength(maxItems)
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
exactLength(length: number): this {
|
|
747
|
+
return this.minLength(length).maxLength(length)
|
|
748
|
+
}
|
|
749
|
+
|
|
738
750
|
unique(uniqueItems: number): this {
|
|
739
751
|
Object.assign(this.schema, { uniqueItems })
|
|
740
752
|
return this
|
|
@@ -876,21 +888,25 @@ function objectInfer<P extends Record<string, JsonSchemaAnyBuilder<any, any, any
|
|
|
876
888
|
return new JsonSchemaObjectInferringBuilder<P, false>(props)
|
|
877
889
|
}
|
|
878
890
|
|
|
879
|
-
function objectDbEntity(props
|
|
880
|
-
function objectDbEntity<
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
IN
|
|
884
|
-
|
|
885
|
-
|
|
891
|
+
function objectDbEntity(props: AnyObject): never
|
|
892
|
+
function objectDbEntity<
|
|
893
|
+
IN extends AnyObject,
|
|
894
|
+
EXTRA_KEYS extends Exclude<keyof IN, 'id' | 'created' | 'updated'> = Exclude<
|
|
895
|
+
keyof IN,
|
|
896
|
+
'id' | 'created' | 'updated'
|
|
897
|
+
>,
|
|
898
|
+
>(props: {
|
|
899
|
+
[K in EXTRA_KEYS]: JsonSchemaAnyBuilder<any, IN[K], any>
|
|
886
900
|
}): JsonSchemaObjectBuilder<IN, IN, false>
|
|
887
901
|
|
|
888
|
-
function objectDbEntity<
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
IN
|
|
892
|
-
|
|
893
|
-
|
|
902
|
+
function objectDbEntity<
|
|
903
|
+
IN extends AnyObject,
|
|
904
|
+
EXTRA_KEYS extends Exclude<keyof IN, 'id' | 'created' | 'updated'> = Exclude<
|
|
905
|
+
keyof IN,
|
|
906
|
+
'id' | 'created' | 'updated'
|
|
907
|
+
>,
|
|
908
|
+
>(props: {
|
|
909
|
+
[K in EXTRA_KEYS]: JsonSchemaAnyBuilder<any, IN[K], any>
|
|
894
910
|
}): JsonSchemaObjectBuilder<IN, IN, false> {
|
|
895
911
|
return j.object({
|
|
896
912
|
id: j.string(),
|
|
@@ -905,8 +921,6 @@ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never
|
|
|
905
921
|
type ExactMatch<A, B> =
|
|
906
922
|
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false
|
|
907
923
|
|
|
908
|
-
type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
909
|
-
|
|
910
924
|
type BuilderOutUnion<B extends readonly JsonSchemaAnyBuilder<any, any, any>[]> = {
|
|
911
925
|
[K in keyof B]: B[K] extends JsonSchemaAnyBuilder<any, infer O, any> ? O : never
|
|
912
926
|
}[number]
|