@naturalcycles/nodejs-lib 15.61.1 → 15.62.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.
|
@@ -235,11 +235,32 @@ export declare class JsonSchemaObjectBuilder<IN extends AnyObject, OUT extends A
|
|
|
235
235
|
* When set, the validation will not strip away properties that are not specified explicitly in the schema.
|
|
236
236
|
*/
|
|
237
237
|
allowAdditionalProperties(): this;
|
|
238
|
-
extend
|
|
238
|
+
extend(props: AnyObject): never;
|
|
239
|
+
extend<IN2 extends AnyObject>(props: {
|
|
240
|
+
[K in keyof Required<IN2>]-?: JsonSchemaAnyBuilder<any, IN2[K], any>;
|
|
241
|
+
}): JsonSchemaObjectBuilder<IN & IN2, OUT & IN2, false>;
|
|
242
|
+
/**
|
|
243
|
+
* Concatenates another schema to the current schema.
|
|
244
|
+
*
|
|
245
|
+
* It expects a type to be passed in as a generic, and this type should be the expected final type.
|
|
246
|
+
*
|
|
247
|
+
* ```ts
|
|
248
|
+
* interface Foo { foo: string }
|
|
249
|
+
* const fooSchema = j.object<Foo>({ foo: j.string() })
|
|
250
|
+
*
|
|
251
|
+
* interface Bar { bar: number }
|
|
252
|
+
* const barSchema = j.object<Bar>({ bar: j.number() })
|
|
253
|
+
*
|
|
254
|
+
* interface Shu { foo: string, bar: number }
|
|
255
|
+
* const shuSchema = fooSchema.concat<Shu>(barSchema)
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
concat(other: any): never;
|
|
259
|
+
concat<FINAL extends AnyObject>(other: JsonSchemaObjectBuilder<any, any, any>): JsonSchemaObjectBuilder<FINAL, FINAL, false>;
|
|
239
260
|
/**
|
|
240
261
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
241
262
|
*/
|
|
242
|
-
dbEntity():
|
|
263
|
+
dbEntity(): never;
|
|
243
264
|
minProperties(minProperties: number): this;
|
|
244
265
|
maxProperties(maxProperties: number): this;
|
|
245
266
|
}
|
|
@@ -589,6 +589,15 @@ export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
589
589
|
const clone = this.clone();
|
|
590
590
|
const incomingSchemaBuilder = new JsonSchemaObjectBuilder(props);
|
|
591
591
|
mergeJsonSchemaObjects(clone.schema, incomingSchemaBuilder.schema);
|
|
592
|
+
// The incoming object is type-safe because `extend<Foo>()` expects a passed in type that matches the passed in props,
|
|
593
|
+
// but maybe the current schema was created differently, so that's what decides the typecheckedness.
|
|
594
|
+
const hasIsOfTypeCheck = this.schema.hasIsOfTypeCheck;
|
|
595
|
+
_objectAssign(clone.schema, { hasIsOfTypeCheck });
|
|
596
|
+
return clone;
|
|
597
|
+
}
|
|
598
|
+
concat(other) {
|
|
599
|
+
const clone = this.clone();
|
|
600
|
+
mergeJsonSchemaObjects(clone.schema, other.schema);
|
|
592
601
|
return clone;
|
|
593
602
|
}
|
|
594
603
|
/**
|
|
@@ -646,6 +655,10 @@ export class JsonSchemaObjectInferringBuilder extends JsonSchemaAnyBuilder {
|
|
|
646
655
|
_objectAssign(newBuilder.schema, _deepCopy(this.schema));
|
|
647
656
|
const incomingSchemaBuilder = new JsonSchemaObjectInferringBuilder(props);
|
|
648
657
|
mergeJsonSchemaObjects(newBuilder.schema, incomingSchemaBuilder.schema);
|
|
658
|
+
// This extend function is not type-safe as it is inferring,
|
|
659
|
+
// so even if the base schema was already type-checked,
|
|
660
|
+
// the new schema loses that quality.
|
|
661
|
+
_objectAssign(newBuilder.schema, { hasIsOfTypeCheck: false });
|
|
649
662
|
return newBuilder;
|
|
650
663
|
}
|
|
651
664
|
/**
|
package/package.json
CHANGED
|
@@ -828,14 +828,49 @@ export class JsonSchemaObjectBuilder<
|
|
|
828
828
|
return this.cloneAndUpdateSchema({ additionalProperties: true })
|
|
829
829
|
}
|
|
830
830
|
|
|
831
|
-
extend
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
831
|
+
extend(props: AnyObject): never
|
|
832
|
+
extend<IN2 extends AnyObject>(props: {
|
|
833
|
+
[K in keyof Required<IN2>]-?: JsonSchemaAnyBuilder<any, IN2[K], any>
|
|
834
|
+
}): JsonSchemaObjectBuilder<IN & IN2, OUT & IN2, false>
|
|
835
|
+
extend<IN2 extends AnyObject>(props: {
|
|
836
|
+
[key in keyof IN2]: JsonSchemaAnyBuilder<any, IN2[key], any>
|
|
837
|
+
}): JsonSchemaObjectBuilder<IN & IN2, OUT & IN2, false> {
|
|
838
|
+
const clone = this.clone()
|
|
835
839
|
|
|
836
840
|
const incomingSchemaBuilder = new JsonSchemaObjectBuilder<IN2, IN2, false>(props)
|
|
837
841
|
mergeJsonSchemaObjects(clone.schema as any, incomingSchemaBuilder.schema as any)
|
|
838
842
|
|
|
843
|
+
// The incoming object is type-safe because `extend<Foo>()` expects a passed in type that matches the passed in props,
|
|
844
|
+
// but maybe the current schema was created differently, so that's what decides the typecheckedness.
|
|
845
|
+
const hasIsOfTypeCheck = this.schema.hasIsOfTypeCheck
|
|
846
|
+
_objectAssign(clone.schema, { hasIsOfTypeCheck })
|
|
847
|
+
|
|
848
|
+
return clone as unknown as JsonSchemaObjectBuilder<IN & IN2, OUT & IN2, false>
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Concatenates another schema to the current schema.
|
|
853
|
+
*
|
|
854
|
+
* It expects a type to be passed in as a generic, and this type should be the expected final type.
|
|
855
|
+
*
|
|
856
|
+
* ```ts
|
|
857
|
+
* interface Foo { foo: string }
|
|
858
|
+
* const fooSchema = j.object<Foo>({ foo: j.string() })
|
|
859
|
+
*
|
|
860
|
+
* interface Bar { bar: number }
|
|
861
|
+
* const barSchema = j.object<Bar>({ bar: j.number() })
|
|
862
|
+
*
|
|
863
|
+
* interface Shu { foo: string, bar: number }
|
|
864
|
+
* const shuSchema = fooSchema.concat<Shu>(barSchema)
|
|
865
|
+
* ```
|
|
866
|
+
*/
|
|
867
|
+
concat(other: any): never
|
|
868
|
+
concat<FINAL extends AnyObject>(
|
|
869
|
+
other: JsonSchemaObjectBuilder<any, any, any>,
|
|
870
|
+
): JsonSchemaObjectBuilder<FINAL, FINAL, false>
|
|
871
|
+
concat(other: any): any {
|
|
872
|
+
const clone = this.clone()
|
|
873
|
+
mergeJsonSchemaObjects(clone.schema as any, other.schema)
|
|
839
874
|
return clone
|
|
840
875
|
}
|
|
841
876
|
|
|
@@ -959,6 +994,11 @@ export class JsonSchemaObjectInferringBuilder<
|
|
|
959
994
|
const incomingSchemaBuilder = new JsonSchemaObjectInferringBuilder<NEW_PROPS, false>(props)
|
|
960
995
|
mergeJsonSchemaObjects(newBuilder.schema as any, incomingSchemaBuilder.schema as any)
|
|
961
996
|
|
|
997
|
+
// This extend function is not type-safe as it is inferring,
|
|
998
|
+
// so even if the base schema was already type-checked,
|
|
999
|
+
// the new schema loses that quality.
|
|
1000
|
+
_objectAssign(newBuilder.schema, { hasIsOfTypeCheck: false })
|
|
1001
|
+
|
|
962
1002
|
return newBuilder as JsonSchemaObjectInferringBuilder<
|
|
963
1003
|
{
|
|
964
1004
|
[K in keyof PROPS | keyof NEW_PROPS]: K extends keyof NEW_PROPS
|