@naturalcycles/nodejs-lib 15.88.0 → 15.89.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.
|
@@ -243,6 +243,18 @@ export interface JsonSchemaStringEmailOptions {
|
|
|
243
243
|
}
|
|
244
244
|
export declare class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonSchemaAnyBuilder<string | IsoDate, IsoDate, Opt> {
|
|
245
245
|
constructor();
|
|
246
|
+
/**
|
|
247
|
+
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
248
|
+
*
|
|
249
|
+
* This `optionalValues` feature only works when the current schema is nested in an object or array schema,
|
|
250
|
+
* due to how mutability works in Ajv.
|
|
251
|
+
*
|
|
252
|
+
* Make sure this `optional()` call is at the end of your call chain.
|
|
253
|
+
*
|
|
254
|
+
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
255
|
+
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
256
|
+
*/
|
|
257
|
+
optional<T extends readonly null[] | undefined = undefined>(optionalValues?: T): T extends readonly null[] ? JsonSchemaTerminal<string | IsoDate | undefined, IsoDate | undefined, true> : JsonSchemaAnyBuilder<string | IsoDate | undefined, IsoDate | undefined, true>;
|
|
246
258
|
before(date: string): this;
|
|
247
259
|
sameOrBefore(date: string): this;
|
|
248
260
|
after(date: string): this;
|
|
@@ -508,6 +508,29 @@ export class JsonSchemaIsoDateBuilder extends JsonSchemaAnyBuilder {
|
|
|
508
508
|
IsoDate: {},
|
|
509
509
|
});
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
513
|
+
*
|
|
514
|
+
* This `optionalValues` feature only works when the current schema is nested in an object or array schema,
|
|
515
|
+
* due to how mutability works in Ajv.
|
|
516
|
+
*
|
|
517
|
+
* Make sure this `optional()` call is at the end of your call chain.
|
|
518
|
+
*
|
|
519
|
+
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
520
|
+
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
521
|
+
*/
|
|
522
|
+
optional(optionalValues) {
|
|
523
|
+
if (!optionalValues) {
|
|
524
|
+
return super.optional();
|
|
525
|
+
}
|
|
526
|
+
_typeCast(optionalValues);
|
|
527
|
+
const optionalBuilder = this.cloneAndUpdateSchema({ optionalField: true });
|
|
528
|
+
const newBuilder = new JsonSchemaTerminal({
|
|
529
|
+
anyOf: [{ type: 'null', optionalValues }, optionalBuilder.build()],
|
|
530
|
+
optionalField: true,
|
|
531
|
+
});
|
|
532
|
+
return newBuilder;
|
|
533
|
+
}
|
|
511
534
|
before(date) {
|
|
512
535
|
return this.cloneAndUpdateSchema({ IsoDate: { before: date } });
|
|
513
536
|
}
|
package/package.json
CHANGED
|
@@ -703,6 +703,42 @@ export class JsonSchemaIsoDateBuilder<Opt extends boolean = false> extends JsonS
|
|
|
703
703
|
})
|
|
704
704
|
}
|
|
705
705
|
|
|
706
|
+
/**
|
|
707
|
+
* @param optionalValues List of values that should be considered/converted as `undefined`.
|
|
708
|
+
*
|
|
709
|
+
* This `optionalValues` feature only works when the current schema is nested in an object or array schema,
|
|
710
|
+
* due to how mutability works in Ajv.
|
|
711
|
+
*
|
|
712
|
+
* Make sure this `optional()` call is at the end of your call chain.
|
|
713
|
+
*
|
|
714
|
+
* When `null` is included in optionalValues, the return type becomes `JsonSchemaTerminal`
|
|
715
|
+
* (no further chaining allowed) because the schema is wrapped in an anyOf structure.
|
|
716
|
+
*/
|
|
717
|
+
override optional<T extends readonly null[] | undefined = undefined>(
|
|
718
|
+
optionalValues?: T,
|
|
719
|
+
): T extends readonly null[]
|
|
720
|
+
? JsonSchemaTerminal<string | IsoDate | undefined, IsoDate | undefined, true>
|
|
721
|
+
: JsonSchemaAnyBuilder<string | IsoDate | undefined, IsoDate | undefined, true> {
|
|
722
|
+
if (!optionalValues) {
|
|
723
|
+
return super.optional() as any
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
_typeCast<null[]>(optionalValues)
|
|
727
|
+
|
|
728
|
+
const optionalBuilder = this.cloneAndUpdateSchema({ optionalField: true })
|
|
729
|
+
|
|
730
|
+
const newBuilder = new JsonSchemaTerminal<
|
|
731
|
+
string | IsoDate | undefined,
|
|
732
|
+
IsoDate | undefined,
|
|
733
|
+
true
|
|
734
|
+
>({
|
|
735
|
+
anyOf: [{ type: 'null', optionalValues }, optionalBuilder.build()],
|
|
736
|
+
optionalField: true,
|
|
737
|
+
})
|
|
738
|
+
|
|
739
|
+
return newBuilder as any
|
|
740
|
+
}
|
|
741
|
+
|
|
706
742
|
before(date: string): this {
|
|
707
743
|
return this.cloneAndUpdateSchema({ IsoDate: { before: date } })
|
|
708
744
|
}
|