@tstdl/base 0.91.0-beta9 → 0.91.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.
- package/enumerable/async-enumerable.d.ts +5 -1
- package/enumerable/async-enumerable.js +8 -8
- package/enumerable/enumerable.d.ts +5 -1
- package/enumerable/enumerable.js +8 -8
- package/intl/number-parser.d.ts +1 -1
- package/object-storage/s3/s3.object-storage-provider.d.ts +6 -6
- package/object-storage/s3/s3.object-storage-provider.js +6 -6
- package/package.json +5 -5
- package/schema/schema.d.ts +3 -2
- package/schema/schemas/array.js +10 -8
- package/schema/schemas/object.d.ts +19 -11
- package/schema/schemas/optional.d.ts +3 -2
- package/utils/async-iterable-helpers/group-single.d.ts +2 -1
- package/utils/async-iterable-helpers/group-single.js +2 -2
- package/utils/async-iterable-helpers/group-to-map.d.ts +2 -1
- package/utils/async-iterable-helpers/group-to-map.js +44 -17
- package/utils/async-iterable-helpers/group-to-single-map.d.ts +2 -1
- package/utils/async-iterable-helpers/group-to-single-map.js +44 -17
- package/utils/async-iterable-helpers/group.d.ts +2 -1
- package/utils/async-iterable-helpers/group.js +2 -2
- package/utils/async-iterable-helpers/types.d.ts +3 -0
- package/utils/iterable-helpers/group-single.d.ts +2 -1
- package/utils/iterable-helpers/group-single.js +2 -2
- package/utils/iterable-helpers/group-to-map.d.ts +2 -1
- package/utils/iterable-helpers/group-to-map.js +21 -7
- package/utils/iterable-helpers/group-to-single-map.d.ts +2 -1
- package/utils/iterable-helpers/group-to-single-map.js +21 -7
- package/utils/iterable-helpers/group.d.ts +2 -1
- package/utils/iterable-helpers/group.js +2 -2
- package/utils/iterable-helpers/types.d.ts +3 -0
- package/schema-old/array-constraints/index.d.ts +0 -2
- package/schema-old/array-constraints/index.js +0 -2
- package/schema-old/array-constraints/maximum-length.d.ts +0 -11
- package/schema-old/array-constraints/maximum-length.js +0 -22
- package/schema-old/array-constraints/minimum-length.d.ts +0 -11
- package/schema-old/array-constraints/minimum-length.js +0 -22
- package/schema-old/coercers/boolean.coercer.d.ts +0 -9
- package/schema-old/coercers/boolean.coercer.js +0 -27
- package/schema-old/coercers/date.coercer.d.ts +0 -9
- package/schema-old/coercers/date.coercer.js +0 -16
- package/schema-old/coercers/index.d.ts +0 -6
- package/schema-old/coercers/index.js +0 -6
- package/schema-old/coercers/number.coercer.d.ts +0 -9
- package/schema-old/coercers/number.coercer.js +0 -14
- package/schema-old/coercers/regexp.coercer.d.ts +0 -11
- package/schema-old/coercers/regexp.coercer.js +0 -20
- package/schema-old/coercers/string.coercer.d.ts +0 -9
- package/schema-old/coercers/string.coercer.js +0 -14
- package/schema-old/coercers/uint8-array.coercer.d.ts +0 -11
- package/schema-old/coercers/uint8-array.coercer.js +0 -22
- package/schema-old/constraints/enumeration.d.ts +0 -13
- package/schema-old/constraints/enumeration.js +0 -29
- package/schema-old/constraints/generic.d.ts +0 -20
- package/schema-old/constraints/generic.js +0 -23
- package/schema-old/constraints/index.d.ts +0 -12
- package/schema-old/constraints/index.js +0 -12
- package/schema-old/constraints/integer.d.ts +0 -12
- package/schema-old/constraints/integer.js +0 -23
- package/schema-old/constraints/length.d.ts +0 -6
- package/schema-old/constraints/length.js +0 -15
- package/schema-old/constraints/literal.d.ts +0 -10
- package/schema-old/constraints/literal.js +0 -24
- package/schema-old/constraints/maximum-date.d.ts +0 -12
- package/schema-old/constraints/maximum-date.js +0 -26
- package/schema-old/constraints/maximum-length.d.ts +0 -12
- package/schema-old/constraints/maximum-length.js +0 -25
- package/schema-old/constraints/maximum.d.ts +0 -12
- package/schema-old/constraints/maximum.js +0 -24
- package/schema-old/constraints/minimum-date.d.ts +0 -12
- package/schema-old/constraints/minimum-date.js +0 -26
- package/schema-old/constraints/minimum-length.d.ts +0 -12
- package/schema-old/constraints/minimum-length.js +0 -25
- package/schema-old/constraints/minimum.d.ts +0 -12
- package/schema-old/constraints/minimum.js +0 -24
- package/schema-old/constraints/pattern.d.ts +0 -13
- package/schema-old/constraints/pattern.js +0 -26
- package/schema-old/decorators/class.d.ts +0 -3
- package/schema-old/decorators/class.js +0 -5
- package/schema-old/decorators/coerce.d.ts +0 -2
- package/schema-old/decorators/coerce.js +0 -5
- package/schema-old/decorators/constraint.d.ts +0 -4
- package/schema-old/decorators/constraint.js +0 -7
- package/schema-old/decorators/index.d.ts +0 -6
- package/schema-old/decorators/index.js +0 -6
- package/schema-old/decorators/property.d.ts +0 -6
- package/schema-old/decorators/property.js +0 -17
- package/schema-old/decorators/types.d.ts +0 -19
- package/schema-old/decorators/types.js +0 -1
- package/schema-old/decorators/utils.d.ts +0 -15
- package/schema-old/decorators/utils.js +0 -48
- package/schema-old/index.d.ts +0 -10
- package/schema-old/index.js +0 -10
- package/schema-old/schema.d.ts +0 -15
- package/schema-old/schema.error.d.ts +0 -26
- package/schema-old/schema.error.js +0 -64
- package/schema-old/schema.js +0 -283
- package/schema-old/schemas/any.d.ts +0 -5
- package/schema-old/schemas/any.js +0 -9
- package/schema-old/schemas/array.d.ts +0 -12
- package/schema-old/schemas/array.js +0 -23
- package/schema-old/schemas/assign.d.ts +0 -7
- package/schema-old/schemas/assign.js +0 -24
- package/schema-old/schemas/boolean.d.ts +0 -5
- package/schema-old/schemas/boolean.js +0 -9
- package/schema-old/schemas/constraint.d.ts +0 -5
- package/schema-old/schemas/constraint.js +0 -7
- package/schema-old/schemas/date.d.ts +0 -8
- package/schema-old/schemas/date.js +0 -22
- package/schema-old/schemas/defaulted.d.ts +0 -6
- package/schema-old/schemas/defaulted.js +0 -10
- package/schema-old/schemas/enumeration.d.ts +0 -6
- package/schema-old/schemas/enumeration.js +0 -17
- package/schema-old/schemas/index.d.ts +0 -26
- package/schema-old/schemas/index.js +0 -26
- package/schema-old/schemas/instance.d.ts +0 -3
- package/schema-old/schemas/instance.js +0 -5
- package/schema-old/schemas/literal.d.ts +0 -5
- package/schema-old/schemas/literal.js +0 -17
- package/schema-old/schemas/nullable.d.ts +0 -6
- package/schema-old/schemas/nullable.js +0 -9
- package/schema-old/schemas/number.d.ts +0 -9
- package/schema-old/schemas/number.js +0 -27
- package/schema-old/schemas/object.d.ts +0 -7
- package/schema-old/schemas/object.js +0 -12
- package/schema-old/schemas/omit.d.ts +0 -3
- package/schema-old/schemas/omit.js +0 -15
- package/schema-old/schemas/one-or-many.d.ts +0 -9
- package/schema-old/schemas/one-or-many.js +0 -15
- package/schema-old/schemas/optional.d.ts +0 -7
- package/schema-old/schemas/optional.js +0 -8
- package/schema-old/schemas/partial.d.ts +0 -4
- package/schema-old/schemas/partial.js +0 -17
- package/schema-old/schemas/pick.d.ts +0 -3
- package/schema-old/schemas/pick.js +0 -15
- package/schema-old/schemas/readable-stream.d.ts +0 -6
- package/schema-old/schemas/readable-stream.js +0 -9
- package/schema-old/schemas/record.d.ts +0 -5
- package/schema-old/schemas/record.js +0 -10
- package/schema-old/schemas/regexp.d.ts +0 -6
- package/schema-old/schemas/regexp.js +0 -9
- package/schema-old/schemas/string.d.ts +0 -22
- package/schema-old/schemas/string.js +0 -38
- package/schema-old/schemas/transform.d.ts +0 -5
- package/schema-old/schemas/transform.js +0 -7
- package/schema-old/schemas/uint8-array.d.ts +0 -10
- package/schema-old/schemas/uint8-array.js +0 -29
- package/schema-old/schemas/union.d.ts +0 -7
- package/schema-old/schemas/union.js +0 -13
- package/schema-old/schemas/unknown.d.ts +0 -5
- package/schema-old/schemas/unknown.js +0 -9
- package/schema-old/transformers/generic.d.ts +0 -12
- package/schema-old/transformers/generic.js +0 -18
- package/schema-old/transformers/index.d.ts +0 -4
- package/schema-old/transformers/index.js +0 -4
- package/schema-old/transformers/lowercase.d.ts +0 -8
- package/schema-old/transformers/lowercase.js +0 -12
- package/schema-old/transformers/trim.d.ts +0 -8
- package/schema-old/transformers/trim.js +0 -12
- package/schema-old/transformers/uppercase.d.ts +0 -8
- package/schema-old/transformers/uppercase.js +0 -12
- package/schema-old/types/index.d.ts +0 -5
- package/schema-old/types/index.js +0 -5
- package/schema-old/types/schema-array-constraint.d.ts +0 -5
- package/schema-old/types/schema-array-constraint.js +0 -2
- package/schema-old/types/schema-value-coercer.d.ts +0 -8
- package/schema-old/types/schema-value-coercer.js +0 -2
- package/schema-old/types/schema-value-constraint.d.ts +0 -8
- package/schema-old/types/schema-value-constraint.js +0 -2
- package/schema-old/types/schema-value-transformer.d.ts +0 -7
- package/schema-old/types/schema-value-transformer.js +0 -2
- package/schema-old/types/types.d.ts +0 -175
- package/schema-old/types/types.js +0 -172
- package/schema-old/utils/index.d.ts +0 -2
- package/schema-old/utils/index.js +0 -2
- package/schema-old/utils/schema.d.ts +0 -18
- package/schema-old/utils/schema.js +0 -139
- package/schema-old/utils/value-type.d.ts +0 -8
- package/schema-old/utils/value-type.js +0 -56
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { IteratorFunction } from './types.js';
|
|
1
|
+
import type { GroupSelectors, IteratorFunction } from './types.js';
|
|
2
2
|
export declare function groupToSingleMap<TIn, TGroup>(iterable: Iterable<TIn>, selector: IteratorFunction<TIn, TGroup>): Map<TGroup, TIn>;
|
|
3
|
+
export declare function groupToSingleMap<TIn, TGroup extends [any, ...any[]]>(iterable: Iterable<TIn>, ...selectors: GroupSelectors<TIn, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn>;
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MultiKeyMap } from '../../data-structures/multi-key-map.js';
|
|
2
|
+
export function groupToSingleMap(iterable, ...selectors) {
|
|
3
3
|
let index = 0;
|
|
4
|
+
if (selectors.length == 1) {
|
|
5
|
+
const selector = selectors[0];
|
|
6
|
+
const map = new Map();
|
|
7
|
+
for (const item of iterable) {
|
|
8
|
+
const groupKey = selector(item, index++);
|
|
9
|
+
if (map.has(groupKey)) {
|
|
10
|
+
throw new Error(`Group ${String(groupKey)} has more than one item.`);
|
|
11
|
+
}
|
|
12
|
+
map.set(groupKey, item);
|
|
13
|
+
}
|
|
14
|
+
return map;
|
|
15
|
+
}
|
|
16
|
+
const map = new MultiKeyMap();
|
|
4
17
|
for (const item of iterable) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
18
|
+
const groupKeys = selectors.map((selector) => selector(item, index)); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
19
|
+
index++;
|
|
20
|
+
if (map.has(groupKeys)) {
|
|
21
|
+
throw new Error(`Group [${groupKeys.map((key) => String(key)).join(', ')}] has more than one item.`);
|
|
8
22
|
}
|
|
9
|
-
map.set(
|
|
23
|
+
map.set(groupKeys, item);
|
|
10
24
|
}
|
|
11
|
-
return map;
|
|
25
|
+
return map.toMap();
|
|
12
26
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { IteratorFunction } from './types.js';
|
|
1
|
+
import type { GroupSelectors, IteratorFunction } from './types.js';
|
|
2
2
|
export declare function group<TIn, TGroup>(iterable: Iterable<TIn>, selector: IteratorFunction<TIn, TGroup>): IterableIterator<[TGroup, TIn[]]>;
|
|
3
|
+
export declare function group<TIn, TGroup extends [any, ...any[]]>(iterable: Iterable<TIn>, ...selectors: GroupSelectors<TIn, TGroup>): IterableIterator<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, TIn[]]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { groupToMap } from './group-to-map.js';
|
|
2
|
-
export function group(iterable,
|
|
3
|
-
return groupToMap(iterable,
|
|
2
|
+
export function group(iterable, ...selectors) {
|
|
3
|
+
return groupToMap(iterable, ...selectors)[Symbol.iterator]();
|
|
4
4
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
3
|
-
import { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class ArrayMaximumLengthConstraint extends SchemaArrayConstraint {
|
|
6
|
-
private readonly maximumLength;
|
|
7
|
-
readonly expects: string;
|
|
8
|
-
constructor(maximumLength: number);
|
|
9
|
-
validate(value: any[], path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
10
|
-
}
|
|
11
|
-
export declare function ArrayMaximumLength(maximumLength: number): Decorator<'property' | 'accessor'>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { createSchemaArrayConstraintDecorator } from '../decorators/index.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
|
|
5
|
-
export class ArrayMaximumLengthConstraint extends SchemaArrayConstraint {
|
|
6
|
-
maximumLength;
|
|
7
|
-
expects;
|
|
8
|
-
constructor(maximumLength) {
|
|
9
|
-
super();
|
|
10
|
-
this.maximumLength = maximumLength;
|
|
11
|
-
this.expects = `a maximum array length of ${this.maximumLength}`;
|
|
12
|
-
}
|
|
13
|
-
validate(value, path, context) {
|
|
14
|
-
if (value.length > this.maximumLength) {
|
|
15
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, `an array length of ${value.length}`, path, { fast: context.options.fastErrors }) };
|
|
16
|
-
}
|
|
17
|
-
return { valid: true };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function ArrayMaximumLength(maximumLength) {
|
|
21
|
-
return createSchemaArrayConstraintDecorator(new ArrayMaximumLengthConstraint(maximumLength));
|
|
22
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
3
|
-
import { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class MinimumArrayLengthConstraint extends SchemaArrayConstraint {
|
|
6
|
-
private readonly minimumLength;
|
|
7
|
-
readonly expects: string;
|
|
8
|
-
constructor(minimumLength: number);
|
|
9
|
-
validate(value: any[], path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
10
|
-
}
|
|
11
|
-
export declare function MinimumArrayLength(minimumLength: number): Decorator<'property' | 'accessor'>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { createSchemaArrayConstraintDecorator } from '../decorators/index.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
|
|
5
|
-
export class MinimumArrayLengthConstraint extends SchemaArrayConstraint {
|
|
6
|
-
minimumLength;
|
|
7
|
-
expects;
|
|
8
|
-
constructor(minimumLength) {
|
|
9
|
-
super();
|
|
10
|
-
this.minimumLength = minimumLength;
|
|
11
|
-
this.expects = `a minimum array length of ${this.minimumLength}`;
|
|
12
|
-
}
|
|
13
|
-
validate(value, path, context) {
|
|
14
|
-
if (value.length < this.minimumLength) {
|
|
15
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, `an array length of ${value.length}`, path, { fast: context.options.fastErrors }) };
|
|
16
|
-
}
|
|
17
|
-
return { valid: true };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function MinimumArrayLength(minimumLength) {
|
|
21
|
-
return createSchemaArrayConstraintDecorator(new MinimumArrayLengthConstraint(minimumLength));
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { CoercerContext, CoerceResult } from '../types/index.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export declare class BooleanCoercer extends SchemaValueCoercer {
|
|
5
|
-
readonly sourceType: (NumberConstructor | StringConstructor | BigIntConstructor)[];
|
|
6
|
-
readonly targetType: BooleanConstructor;
|
|
7
|
-
coerce(value: number | string | bigint, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
8
|
-
}
|
|
9
|
-
export declare const booleanCoercer: BooleanCoercer;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { isString } from '../../utils/type-guards.js';
|
|
2
|
-
import { SchemaError } from '../schema.error.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export class BooleanCoercer extends SchemaValueCoercer {
|
|
5
|
-
sourceType = [Number, String, BigInt];
|
|
6
|
-
targetType = Boolean;
|
|
7
|
-
coerce(value, path, context) {
|
|
8
|
-
const normalizedValue = isString(value) ? value.toLowerCase() : value;
|
|
9
|
-
switch (normalizedValue) {
|
|
10
|
-
case 1:
|
|
11
|
-
case 1n:
|
|
12
|
-
case 'true':
|
|
13
|
-
case '1':
|
|
14
|
-
case 'yes':
|
|
15
|
-
return { success: true, value: true };
|
|
16
|
-
case 0:
|
|
17
|
-
case 0n:
|
|
18
|
-
case 'false':
|
|
19
|
-
case '0':
|
|
20
|
-
case 'no':
|
|
21
|
-
return { success: true, value: false };
|
|
22
|
-
default:
|
|
23
|
-
return { success: false, error: SchemaError.couldNotCoerce(Boolean, value.toString(), path, { fast: context.options.fastErrors }) };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export const booleanCoercer = new BooleanCoercer();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { CoercerContext, CoerceResult } from '../types/index.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export declare class DateCoercer extends SchemaValueCoercer {
|
|
5
|
-
readonly sourceType: (NumberConstructor | StringConstructor | BigIntConstructor)[];
|
|
6
|
-
readonly targetType: DateConstructor;
|
|
7
|
-
coerce(value: number | string | bigint, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
8
|
-
}
|
|
9
|
-
export declare const dateCoercer: DateCoercer;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isBigInt } from '../../utils/type-guards.js';
|
|
2
|
-
import { SchemaError } from '../schema.error.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export class DateCoercer extends SchemaValueCoercer {
|
|
5
|
-
sourceType = [Number, String, BigInt];
|
|
6
|
-
targetType = Date;
|
|
7
|
-
coerce(value, path, context) {
|
|
8
|
-
const parseValue = isBigInt(value) ? Number(value) : value;
|
|
9
|
-
const date = new Date(parseValue);
|
|
10
|
-
if (Number.isNaN(date.getTime())) {
|
|
11
|
-
return { success: false, error: SchemaError.couldNotCoerce(this.targetType, value.toString(), path, { fast: context.options.fastErrors }) };
|
|
12
|
-
}
|
|
13
|
-
return { success: true, value: date };
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export const dateCoercer = new DateCoercer();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { CoercerContext, CoerceResult } from '../types/index.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export declare class NumberCoercer extends SchemaValueCoercer {
|
|
5
|
-
readonly sourceType: (BooleanConstructor | StringConstructor | BigIntConstructor)[];
|
|
6
|
-
readonly targetType: NumberConstructor;
|
|
7
|
-
coerce(value: string | bigint | boolean, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
8
|
-
}
|
|
9
|
-
export declare const numberCoercer: NumberCoercer;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SchemaError } from '../schema.error.js';
|
|
2
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
3
|
-
export class NumberCoercer extends SchemaValueCoercer {
|
|
4
|
-
sourceType = [String, BigInt, Boolean];
|
|
5
|
-
targetType = Number;
|
|
6
|
-
coerce(value, path, context) {
|
|
7
|
-
const result = Number(value);
|
|
8
|
-
if (Number.isNaN(result)) {
|
|
9
|
-
return { success: false, error: SchemaError.couldNotCoerce(this.targetType, value.toString(), path, { fast: context.options.fastErrors, customMessage: 'Value is not a number.' }) };
|
|
10
|
-
}
|
|
11
|
-
return { success: true, value: result };
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export const numberCoercer = new NumberCoercer();
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { CoercerContext, CoerceResult } from '../types/index.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export declare class RegExpCoercer extends SchemaValueCoercer {
|
|
5
|
-
readonly sourceType: StringConstructor;
|
|
6
|
-
readonly targetType: RegExpConstructor;
|
|
7
|
-
readonly flags: string | undefined;
|
|
8
|
-
constructor(flags?: string);
|
|
9
|
-
coerce(value: string, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
10
|
-
}
|
|
11
|
-
export declare const regExpCoercer: RegExpCoercer;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SchemaError } from '../schema.error.js';
|
|
2
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
3
|
-
export class RegExpCoercer extends SchemaValueCoercer {
|
|
4
|
-
sourceType = String;
|
|
5
|
-
targetType = RegExp;
|
|
6
|
-
flags;
|
|
7
|
-
constructor(flags = 'u') {
|
|
8
|
-
super();
|
|
9
|
-
this.flags = flags;
|
|
10
|
-
}
|
|
11
|
-
coerce(value, path, context) {
|
|
12
|
-
try {
|
|
13
|
-
return { success: true, value: RegExp(value, this.flags) };
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
return { success: false, error: SchemaError.couldNotCoerce(this.targetType, 'invalid regexp pattern', path, { fast: context.options.fastErrors, customMessage: error.message }) };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export const regExpCoercer = new RegExpCoercer();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { CoercerContext, CoerceResult } from '../types/index.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export declare class StringCoercer extends SchemaValueCoercer {
|
|
5
|
-
readonly sourceType: (DateConstructor | NumberConstructor | BooleanConstructor | BigIntConstructor)[];
|
|
6
|
-
readonly targetType: StringConstructor;
|
|
7
|
-
coerce(value: number | boolean | bigint | Date, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
8
|
-
}
|
|
9
|
-
export declare const stringCoercer: StringCoercer;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isDate, isValidDate } from '../../utils/type-guards.js';
|
|
2
|
-
import { SchemaError } from '../schema.error.js';
|
|
3
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
4
|
-
export class StringCoercer extends SchemaValueCoercer {
|
|
5
|
-
sourceType = [Number, Boolean, BigInt, Date];
|
|
6
|
-
targetType = String;
|
|
7
|
-
coerce(value, path, context) {
|
|
8
|
-
if (isDate(value) && !isValidDate(value)) {
|
|
9
|
-
return { success: false, error: SchemaError.couldNotCoerce(this.targetType, 'invalid date', path, { fast: context.options.fastErrors }) };
|
|
10
|
-
}
|
|
11
|
-
return { success: true, value: value.toString() };
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export const stringCoercer = new StringCoercer();
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Schema } from '../schema.js';
|
|
3
|
-
import type { CoerceResult, CoercerContext } from '../types/index.js';
|
|
4
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
5
|
-
export declare class Uint8ArrayCoercer extends SchemaValueCoercer {
|
|
6
|
-
static readonly byteNumberArraySchema: Schema<number[]>;
|
|
7
|
-
readonly sourceType: ArrayConstructor;
|
|
8
|
-
readonly targetType: Uint8ArrayConstructor;
|
|
9
|
-
coerce(value: any[], path: JsonPath, { options }: CoercerContext): CoerceResult;
|
|
10
|
-
}
|
|
11
|
-
export declare const uint8ArrayCoercer: Uint8ArrayCoercer;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
|
-
import { SchemaError } from '../schema.error.js';
|
|
3
|
-
import { testSchema } from '../schema.js';
|
|
4
|
-
import { array } from '../schemas/array.js';
|
|
5
|
-
import { number } from '../schemas/number.js';
|
|
6
|
-
import { SchemaValueCoercer } from '../types/index.js';
|
|
7
|
-
export class Uint8ArrayCoercer extends SchemaValueCoercer {
|
|
8
|
-
static byteNumberArraySchema;
|
|
9
|
-
static {
|
|
10
|
-
lazyProperty(this, 'byteNumberArraySchema', () => array(number({ integer: true, minimum: 0, maximum: 255 })));
|
|
11
|
-
}
|
|
12
|
-
sourceType = Array;
|
|
13
|
-
targetType = Uint8Array;
|
|
14
|
-
coerce(value, path, { options }) {
|
|
15
|
-
const testResult = testSchema(Uint8ArrayCoercer.byteNumberArraySchema, value, options, path);
|
|
16
|
-
if (!testResult.valid) {
|
|
17
|
-
return { success: false, error: SchemaError.couldNotCoerce(Uint8Array, Array, path, { inner: testResult.error, fast: options.fastErrors }) };
|
|
18
|
-
}
|
|
19
|
-
return { success: true, value: Uint8Array.from(testResult.value) };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export const uint8ArrayCoercer = new Uint8ArrayCoercer();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Enumeration, EnumerationValue, OneOrMany } from '../../types.js';
|
|
3
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class EnumerationConstraint extends SchemaValueConstraint {
|
|
6
|
-
private readonly allowedValuesString;
|
|
7
|
-
readonly enumeration: Enumeration;
|
|
8
|
-
readonly allowedValuesSet: Set<EnumerationValue>;
|
|
9
|
-
readonly suitableTypes: SchemaValueConstraint['suitableTypes'];
|
|
10
|
-
readonly expects: OneOrMany<string>;
|
|
11
|
-
constructor(enumeration: Enumeration);
|
|
12
|
-
validate(value: number, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
13
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { enumValues } from '../../utils/enum.js';
|
|
3
|
-
import { distinct } from '../../utils/iterable-helpers/distinct.js';
|
|
4
|
-
import { isArray, isString } from '../../utils/type-guards.js';
|
|
5
|
-
import { SchemaError } from '../schema.error.js';
|
|
6
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
7
|
-
import { getValueType } from '../utils/value-type.js';
|
|
8
|
-
export class EnumerationConstraint extends SchemaValueConstraint {
|
|
9
|
-
allowedValuesString;
|
|
10
|
-
enumeration;
|
|
11
|
-
allowedValuesSet;
|
|
12
|
-
suitableTypes;
|
|
13
|
-
expects;
|
|
14
|
-
constructor(enumeration) {
|
|
15
|
-
super();
|
|
16
|
-
this.enumeration = enumeration;
|
|
17
|
-
const allowedValues = isArray(enumeration) ? enumeration : enumValues(enumeration);
|
|
18
|
-
this.allowedValuesSet = new Set(allowedValues);
|
|
19
|
-
this.allowedValuesString = allowedValues.map((value) => (isString(value) ? `"${value}"` : value)).join(', ');
|
|
20
|
-
this.suitableTypes = [...distinct(allowedValues.map((value) => getValueType(value)))];
|
|
21
|
-
this.expects = `one of [${this.allowedValuesString}]`;
|
|
22
|
-
}
|
|
23
|
-
validate(value, path, context) {
|
|
24
|
-
if (!this.allowedValuesSet.has(value)) {
|
|
25
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, value.toString(), path, { fast: context.options.fastErrors }) };
|
|
26
|
-
}
|
|
27
|
-
return { valid: true };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { OneOrMany } from '../../types.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
5
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
6
|
-
export type GenericConstraintResult = {
|
|
7
|
-
success: true;
|
|
8
|
-
error?: undefined;
|
|
9
|
-
} | {
|
|
10
|
-
success: false;
|
|
11
|
-
error: string | SchemaError;
|
|
12
|
-
};
|
|
13
|
-
export type GenericConstraintFunction<T> = (value: T, path: JsonPath) => boolean | ConstraintResult;
|
|
14
|
-
export declare class GenericConstraint<T> extends SchemaValueConstraint {
|
|
15
|
-
readonly suitableTypes: NumberConstructor;
|
|
16
|
-
readonly expects: OneOrMany<string>;
|
|
17
|
-
readonly constraintFunction: GenericConstraintFunction<T>;
|
|
18
|
-
constructor(constraintFunction: GenericConstraintFunction<T>, expects?: OneOrMany<string>);
|
|
19
|
-
validate(value: T, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { isBoolean } from '../../utils/type-guards.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
5
|
-
export class GenericConstraint extends SchemaValueConstraint {
|
|
6
|
-
suitableTypes = Number;
|
|
7
|
-
expects;
|
|
8
|
-
constraintFunction;
|
|
9
|
-
constructor(constraintFunction, expects = 'valid value') {
|
|
10
|
-
super();
|
|
11
|
-
this.constraintFunction = constraintFunction;
|
|
12
|
-
this.expects = expects;
|
|
13
|
-
}
|
|
14
|
-
validate(value, path, context) {
|
|
15
|
-
const result = this.constraintFunction(value, path);
|
|
16
|
-
if (isBoolean(result)) {
|
|
17
|
-
return result
|
|
18
|
-
? { valid: true }
|
|
19
|
-
: { valid: false, error: SchemaError.expectedButGot(this.expects, 'invalid value', path, { fast: context.options.fastErrors }) };
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './enumeration.js';
|
|
2
|
-
export * from './generic.js';
|
|
3
|
-
export * from './integer.js';
|
|
4
|
-
export * from './length.js';
|
|
5
|
-
export * from './literal.js';
|
|
6
|
-
export * from './maximum.js';
|
|
7
|
-
export * from './maximum-date.js';
|
|
8
|
-
export * from './maximum-length.js';
|
|
9
|
-
export * from './minimum.js';
|
|
10
|
-
export * from './minimum-date.js';
|
|
11
|
-
export * from './minimum-length.js';
|
|
12
|
-
export * from './pattern.js';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './enumeration.js';
|
|
2
|
-
export * from './generic.js';
|
|
3
|
-
export * from './integer.js';
|
|
4
|
-
export * from './length.js';
|
|
5
|
-
export * from './literal.js';
|
|
6
|
-
export * from './maximum.js';
|
|
7
|
-
export * from './maximum-date.js';
|
|
8
|
-
export * from './maximum-length.js';
|
|
9
|
-
export * from './minimum.js';
|
|
10
|
-
export * from './minimum-date.js';
|
|
11
|
-
export * from './minimum-length.js';
|
|
12
|
-
export * from './pattern.js';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
3
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class IntegerConstraint extends SchemaValueConstraint {
|
|
6
|
-
readonly suitableTypes: NumberConstructor;
|
|
7
|
-
readonly expects: string;
|
|
8
|
-
constructor();
|
|
9
|
-
validate(value: number, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
10
|
-
}
|
|
11
|
-
export declare const integerConstraint: IntegerConstraint;
|
|
12
|
-
export declare function Integer(): Decorator<'property' | 'accessor'>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { createSchemaValueConstraintDecorator } from '../decorators/utils.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
5
|
-
import { typeSchema } from '../types/types.js';
|
|
6
|
-
export class IntegerConstraint extends SchemaValueConstraint {
|
|
7
|
-
suitableTypes = Number;
|
|
8
|
-
expects;
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
this.expects = 'an integer';
|
|
12
|
-
}
|
|
13
|
-
validate(value, path, context) {
|
|
14
|
-
if (!Number.isInteger(value)) {
|
|
15
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, value.toString(), path, { fast: context.options.fastErrors }) };
|
|
16
|
-
}
|
|
17
|
-
return { valid: true };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export const integerConstraint = new IntegerConstraint();
|
|
21
|
-
export function Integer() {
|
|
22
|
-
return createSchemaValueConstraintDecorator(integerConstraint, { schema: typeSchema(Number) });
|
|
23
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { isDefined } from '../../utils/type-guards.js';
|
|
3
|
-
import { createSchemaValueConstraintDecorator } from '../decorators/utils.js';
|
|
4
|
-
import { MaximumLengthConstraint } from './maximum-length.js';
|
|
5
|
-
import { MinimumLengthConstraint } from './minimum-length.js';
|
|
6
|
-
export function Length(options) {
|
|
7
|
-
const constraints = [];
|
|
8
|
-
if (isDefined(options.minimum)) {
|
|
9
|
-
constraints.push(new MinimumLengthConstraint(options.minimum));
|
|
10
|
-
}
|
|
11
|
-
if (isDefined(options.maximum)) {
|
|
12
|
-
constraints.push(new MaximumLengthConstraint(options.maximum));
|
|
13
|
-
}
|
|
14
|
-
return createSchemaValueConstraintDecorator(constraints);
|
|
15
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
3
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
4
|
-
export declare class LiteralConstraint extends SchemaValueConstraint {
|
|
5
|
-
readonly literal: any;
|
|
6
|
-
readonly suitableTypes: SchemaValueConstraint['suitableTypes'];
|
|
7
|
-
readonly expects: string;
|
|
8
|
-
constructor(literal: any);
|
|
9
|
-
validate(value: any, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
10
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { isPrimitive } from '../../utils/type-guards.js';
|
|
3
|
-
import { SchemaError } from '../schema.error.js';
|
|
4
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
5
|
-
import { getValueType, getValueTypeName } from '../utils/value-type.js';
|
|
6
|
-
export class LiteralConstraint extends SchemaValueConstraint {
|
|
7
|
-
literal;
|
|
8
|
-
suitableTypes;
|
|
9
|
-
expects;
|
|
10
|
-
constructor(literal) {
|
|
11
|
-
super();
|
|
12
|
-
this.literal = literal;
|
|
13
|
-
this.suitableTypes = getValueType(literal);
|
|
14
|
-
const literalName = isPrimitive(literal) ? String(literal) : getValueTypeName(this.suitableTypes);
|
|
15
|
-
this.expects = `literal ${literalName}`;
|
|
16
|
-
}
|
|
17
|
-
validate(value, path, context) {
|
|
18
|
-
if (value !== this.literal) {
|
|
19
|
-
const valueType = getValueType(value);
|
|
20
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, getValueTypeName(valueType), path, { fast: context.options.fastErrors }) };
|
|
21
|
-
}
|
|
22
|
-
return { valid: true };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
3
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class MaximumDateConstraint extends SchemaValueConstraint {
|
|
6
|
-
private readonly maximum;
|
|
7
|
-
readonly suitableTypes: NumberConstructor;
|
|
8
|
-
readonly expects: string;
|
|
9
|
-
constructor(maximum: Date | number);
|
|
10
|
-
validate(value: Date, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
11
|
-
}
|
|
12
|
-
export declare function MaximumDate(maximum: number): Decorator<'property' | 'accessor'>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { assertValidDate, isNumber } from '../../utils/type-guards.js';
|
|
3
|
-
import { createSchemaValueConstraintDecorator } from '../decorators/index.js';
|
|
4
|
-
import { SchemaError } from '../schema.error.js';
|
|
5
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
6
|
-
import { typeSchema } from '../types/types.js';
|
|
7
|
-
export class MaximumDateConstraint extends SchemaValueConstraint {
|
|
8
|
-
maximum;
|
|
9
|
-
suitableTypes = Number;
|
|
10
|
-
expects;
|
|
11
|
-
constructor(maximum) {
|
|
12
|
-
super();
|
|
13
|
-
this.maximum = isNumber(maximum) ? new Date(maximum) : maximum;
|
|
14
|
-
this.expects = `<= ${this.maximum.toISOString()}`;
|
|
15
|
-
assertValidDate(this.maximum);
|
|
16
|
-
}
|
|
17
|
-
validate(value, path, context) {
|
|
18
|
-
if (value > this.maximum) {
|
|
19
|
-
return { valid: false, error: SchemaError.expectedButGot(this.expects, value.toISOString(), path, { fast: context.options.fastErrors }) };
|
|
20
|
-
}
|
|
21
|
-
return { valid: true };
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export function MaximumDate(maximum) {
|
|
25
|
-
return createSchemaValueConstraintDecorator(new MaximumDateConstraint(maximum), { schema: typeSchema(Number) });
|
|
26
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type { Decorator } from '../../reflection/index.js';
|
|
3
|
-
import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
4
|
-
import type { ConstraintContext, ConstraintResult } from '../types/types.js';
|
|
5
|
-
export declare class MaximumLengthConstraint extends SchemaValueConstraint {
|
|
6
|
-
private readonly maximumLength;
|
|
7
|
-
readonly suitableTypes: (ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | ArrayConstructor | StringConstructor)[];
|
|
8
|
-
readonly expects: string;
|
|
9
|
-
constructor(maximumLength: number);
|
|
10
|
-
validate(value: string, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
11
|
-
}
|
|
12
|
-
export declare function MaximumLength(maximumLength: number): Decorator<'property' | 'accessor'>;
|