@tstdl/base 0.91.0 → 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.
Files changed (154) hide show
  1. package/authentication/authentication.api.d.ts +1 -1
  2. package/enumerable/async-enumerable.d.ts +5 -1
  3. package/enumerable/async-enumerable.js +8 -8
  4. package/enumerable/enumerable.d.ts +5 -1
  5. package/enumerable/enumerable.js +8 -8
  6. package/package.json +1 -1
  7. package/schema-old/array-constraints/index.d.ts +0 -2
  8. package/schema-old/array-constraints/index.js +0 -2
  9. package/schema-old/array-constraints/maximum-length.d.ts +0 -11
  10. package/schema-old/array-constraints/maximum-length.js +0 -22
  11. package/schema-old/array-constraints/minimum-length.d.ts +0 -11
  12. package/schema-old/array-constraints/minimum-length.js +0 -22
  13. package/schema-old/coercers/boolean.coercer.d.ts +0 -9
  14. package/schema-old/coercers/boolean.coercer.js +0 -27
  15. package/schema-old/coercers/date.coercer.d.ts +0 -9
  16. package/schema-old/coercers/date.coercer.js +0 -16
  17. package/schema-old/coercers/index.d.ts +0 -6
  18. package/schema-old/coercers/index.js +0 -6
  19. package/schema-old/coercers/number.coercer.d.ts +0 -9
  20. package/schema-old/coercers/number.coercer.js +0 -14
  21. package/schema-old/coercers/regexp.coercer.d.ts +0 -11
  22. package/schema-old/coercers/regexp.coercer.js +0 -20
  23. package/schema-old/coercers/string.coercer.d.ts +0 -9
  24. package/schema-old/coercers/string.coercer.js +0 -14
  25. package/schema-old/coercers/uint8-array.coercer.d.ts +0 -11
  26. package/schema-old/coercers/uint8-array.coercer.js +0 -22
  27. package/schema-old/constraints/enumeration.d.ts +0 -13
  28. package/schema-old/constraints/enumeration.js +0 -29
  29. package/schema-old/constraints/generic.d.ts +0 -20
  30. package/schema-old/constraints/generic.js +0 -23
  31. package/schema-old/constraints/index.d.ts +0 -12
  32. package/schema-old/constraints/index.js +0 -12
  33. package/schema-old/constraints/integer.d.ts +0 -12
  34. package/schema-old/constraints/integer.js +0 -23
  35. package/schema-old/constraints/length.d.ts +0 -6
  36. package/schema-old/constraints/length.js +0 -15
  37. package/schema-old/constraints/literal.d.ts +0 -10
  38. package/schema-old/constraints/literal.js +0 -24
  39. package/schema-old/constraints/maximum-date.d.ts +0 -12
  40. package/schema-old/constraints/maximum-date.js +0 -26
  41. package/schema-old/constraints/maximum-length.d.ts +0 -12
  42. package/schema-old/constraints/maximum-length.js +0 -25
  43. package/schema-old/constraints/maximum.d.ts +0 -12
  44. package/schema-old/constraints/maximum.js +0 -24
  45. package/schema-old/constraints/minimum-date.d.ts +0 -12
  46. package/schema-old/constraints/minimum-date.js +0 -26
  47. package/schema-old/constraints/minimum-length.d.ts +0 -12
  48. package/schema-old/constraints/minimum-length.js +0 -25
  49. package/schema-old/constraints/minimum.d.ts +0 -12
  50. package/schema-old/constraints/minimum.js +0 -24
  51. package/schema-old/constraints/pattern.d.ts +0 -13
  52. package/schema-old/constraints/pattern.js +0 -26
  53. package/schema-old/decorators/class.d.ts +0 -3
  54. package/schema-old/decorators/class.js +0 -5
  55. package/schema-old/decorators/coerce.d.ts +0 -2
  56. package/schema-old/decorators/coerce.js +0 -5
  57. package/schema-old/decorators/constraint.d.ts +0 -4
  58. package/schema-old/decorators/constraint.js +0 -7
  59. package/schema-old/decorators/index.d.ts +0 -6
  60. package/schema-old/decorators/index.js +0 -6
  61. package/schema-old/decorators/property.d.ts +0 -6
  62. package/schema-old/decorators/property.js +0 -17
  63. package/schema-old/decorators/types.d.ts +0 -19
  64. package/schema-old/decorators/types.js +0 -1
  65. package/schema-old/decorators/utils.d.ts +0 -15
  66. package/schema-old/decorators/utils.js +0 -48
  67. package/schema-old/index.d.ts +0 -10
  68. package/schema-old/index.js +0 -10
  69. package/schema-old/schema.d.ts +0 -15
  70. package/schema-old/schema.error.d.ts +0 -26
  71. package/schema-old/schema.error.js +0 -64
  72. package/schema-old/schema.js +0 -283
  73. package/schema-old/schemas/any.d.ts +0 -5
  74. package/schema-old/schemas/any.js +0 -9
  75. package/schema-old/schemas/array.d.ts +0 -12
  76. package/schema-old/schemas/array.js +0 -23
  77. package/schema-old/schemas/assign.d.ts +0 -7
  78. package/schema-old/schemas/assign.js +0 -24
  79. package/schema-old/schemas/boolean.d.ts +0 -5
  80. package/schema-old/schemas/boolean.js +0 -9
  81. package/schema-old/schemas/constraint.d.ts +0 -5
  82. package/schema-old/schemas/constraint.js +0 -7
  83. package/schema-old/schemas/date.d.ts +0 -8
  84. package/schema-old/schemas/date.js +0 -22
  85. package/schema-old/schemas/defaulted.d.ts +0 -6
  86. package/schema-old/schemas/defaulted.js +0 -10
  87. package/schema-old/schemas/enumeration.d.ts +0 -6
  88. package/schema-old/schemas/enumeration.js +0 -17
  89. package/schema-old/schemas/index.d.ts +0 -26
  90. package/schema-old/schemas/index.js +0 -26
  91. package/schema-old/schemas/instance.d.ts +0 -3
  92. package/schema-old/schemas/instance.js +0 -5
  93. package/schema-old/schemas/literal.d.ts +0 -5
  94. package/schema-old/schemas/literal.js +0 -17
  95. package/schema-old/schemas/nullable.d.ts +0 -6
  96. package/schema-old/schemas/nullable.js +0 -9
  97. package/schema-old/schemas/number.d.ts +0 -9
  98. package/schema-old/schemas/number.js +0 -27
  99. package/schema-old/schemas/object.d.ts +0 -7
  100. package/schema-old/schemas/object.js +0 -12
  101. package/schema-old/schemas/omit.d.ts +0 -3
  102. package/schema-old/schemas/omit.js +0 -15
  103. package/schema-old/schemas/one-or-many.d.ts +0 -9
  104. package/schema-old/schemas/one-or-many.js +0 -15
  105. package/schema-old/schemas/optional.d.ts +0 -7
  106. package/schema-old/schemas/optional.js +0 -8
  107. package/schema-old/schemas/partial.d.ts +0 -4
  108. package/schema-old/schemas/partial.js +0 -17
  109. package/schema-old/schemas/pick.d.ts +0 -3
  110. package/schema-old/schemas/pick.js +0 -15
  111. package/schema-old/schemas/readable-stream.d.ts +0 -6
  112. package/schema-old/schemas/readable-stream.js +0 -9
  113. package/schema-old/schemas/record.d.ts +0 -5
  114. package/schema-old/schemas/record.js +0 -10
  115. package/schema-old/schemas/regexp.d.ts +0 -6
  116. package/schema-old/schemas/regexp.js +0 -9
  117. package/schema-old/schemas/string.d.ts +0 -22
  118. package/schema-old/schemas/string.js +0 -38
  119. package/schema-old/schemas/transform.d.ts +0 -5
  120. package/schema-old/schemas/transform.js +0 -7
  121. package/schema-old/schemas/uint8-array.d.ts +0 -10
  122. package/schema-old/schemas/uint8-array.js +0 -29
  123. package/schema-old/schemas/union.d.ts +0 -7
  124. package/schema-old/schemas/union.js +0 -13
  125. package/schema-old/schemas/unknown.d.ts +0 -5
  126. package/schema-old/schemas/unknown.js +0 -9
  127. package/schema-old/transformers/generic.d.ts +0 -12
  128. package/schema-old/transformers/generic.js +0 -18
  129. package/schema-old/transformers/index.d.ts +0 -4
  130. package/schema-old/transformers/index.js +0 -4
  131. package/schema-old/transformers/lowercase.d.ts +0 -8
  132. package/schema-old/transformers/lowercase.js +0 -12
  133. package/schema-old/transformers/trim.d.ts +0 -8
  134. package/schema-old/transformers/trim.js +0 -12
  135. package/schema-old/transformers/uppercase.d.ts +0 -8
  136. package/schema-old/transformers/uppercase.js +0 -12
  137. package/schema-old/types/index.d.ts +0 -5
  138. package/schema-old/types/index.js +0 -5
  139. package/schema-old/types/schema-array-constraint.d.ts +0 -5
  140. package/schema-old/types/schema-array-constraint.js +0 -2
  141. package/schema-old/types/schema-value-coercer.d.ts +0 -8
  142. package/schema-old/types/schema-value-coercer.js +0 -2
  143. package/schema-old/types/schema-value-constraint.d.ts +0 -8
  144. package/schema-old/types/schema-value-constraint.js +0 -2
  145. package/schema-old/types/schema-value-transformer.d.ts +0 -7
  146. package/schema-old/types/schema-value-transformer.js +0 -2
  147. package/schema-old/types/types.d.ts +0 -175
  148. package/schema-old/types/types.js +0 -172
  149. package/schema-old/utils/index.d.ts +0 -2
  150. package/schema-old/utils/index.js +0 -2
  151. package/schema-old/utils/schema.d.ts +0 -18
  152. package/schema-old/utils/schema.js +0 -139
  153. package/schema-old/utils/value-type.d.ts +0 -8
  154. package/schema-old/utils/value-type.js +0 -56
@@ -1,5 +1,5 @@
1
1
  import { type ApiDefinition } from '../api/types.js';
2
- import { ObjectSchema, type ObjectSchemaOrType } from '../schema/index.js';
2
+ import { type ObjectSchema, type ObjectSchemaOrType } from '../schema/index.js';
3
3
  import type { SchemaTestable } from '../schema/schema.js';
4
4
  import type { Record } from '../types.js';
5
5
  import type { TokenPayload } from './index.js';
@@ -2,7 +2,7 @@ import type { CancellationSignal } from '../cancellation/token.js';
2
2
  import type { AnyIterable } from '../utils/any-iterable-iterator.js';
3
3
  import type { AsyncComparator } from '../utils/sort.js';
4
4
  import type { Observable } from 'rxjs';
5
- import type { AsyncIteratorFunction, AsyncPredicate, AsyncReducer, AsyncRetryPredicate, ParallelizableIteratorFunction, ParallelizablePredicate, ThrottleFunction } from '../utils/async-iterable-helpers/index.js';
5
+ import type { AsyncGroupSelectors, AsyncIteratorFunction, AsyncPredicate, AsyncReducer, AsyncRetryPredicate, ParallelizableIteratorFunction, ParallelizablePredicate, ThrottleFunction } from '../utils/async-iterable-helpers/index.js';
6
6
  import type { IterableItemMetadata, TypePredicate } from '../utils/iterable-helpers/index.js';
7
7
  import type { EnumerableMethods } from './enumerable-methods.js';
8
8
  import { Enumerable } from './enumerable.js';
@@ -33,9 +33,13 @@ export declare class AsyncEnumerable<T> implements EnumerableMethods, AsyncItera
33
33
  forceCast<TNew>(): AsyncEnumerable<TNew>;
34
34
  forEach(func: AsyncIteratorFunction<T, any>): Promise<void>;
35
35
  group<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): AsyncEnumerable<[TGroup, T[]]>;
36
+ group<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): AsyncEnumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]]>;
36
37
  groupSingle<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): AsyncEnumerable<[TGroup, T]>;
38
+ groupSingle<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): AsyncEnumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T]>;
37
39
  groupToMap<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): Promise<Map<TGroup, T[]>>;
40
+ groupToMap<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]>>;
38
41
  groupToSingleMap<TGroup>(selector: AsyncIteratorFunction<T, TGroup>): Promise<Map<TGroup, T>>;
42
+ groupToSingleMap<TGroup extends [any, ...any[]]>(...selectors: AsyncGroupSelectors<T, TGroup>): Promise<Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T>>;
39
43
  tap(tapper: AsyncIteratorFunction<T, any>): AsyncEnumerable<T>;
40
44
  interruptEvery(value: number): AsyncEnumerable<T>;
41
45
  interruptPerSecond(value: number): AsyncEnumerable<T>;
@@ -91,19 +91,19 @@ export class AsyncEnumerable {
91
91
  async forEach(func) {
92
92
  await forEachAsync(this.source, func);
93
93
  }
94
- group(selector) {
95
- const grouped = groupAsync(this.source, selector);
94
+ group(...selectors) {
95
+ const grouped = groupAsync(this.source, ...selectors);
96
96
  return new AsyncEnumerable(grouped);
97
97
  }
98
- groupSingle(selector) {
99
- const grouped = groupSingleAsync(this.source, selector);
98
+ groupSingle(...selectors) {
99
+ const grouped = groupSingleAsync(this.source, ...selectors);
100
100
  return new AsyncEnumerable(grouped);
101
101
  }
102
- async groupToMap(selector) {
103
- return groupToMapAsync(this.source, selector);
102
+ async groupToMap(...selectors) {
103
+ return groupToMapAsync(this.source, ...selectors);
104
104
  }
105
- async groupToSingleMap(selector) {
106
- return groupToSingleMapAsync(this.source, selector);
105
+ async groupToSingleMap(...selectors) {
106
+ return groupToSingleMapAsync(this.source, ...selectors);
107
107
  }
108
108
  tap(tapper) {
109
109
  const iterator = tapAsync(this.source, tapper);
@@ -1,6 +1,6 @@
1
1
  import type { CancellationSignal } from '../cancellation/token.js';
2
2
  import type { Comparator } from '../utils/sort.js';
3
- import type { IterableItemMetadata, IteratorFunction, Predicate, Reducer, TypePredicate } from '../utils/iterable-helpers/index.js';
3
+ import type { GroupSelectors, IterableItemMetadata, IteratorFunction, Predicate, Reducer, TypePredicate } from '../utils/iterable-helpers/index.js';
4
4
  import { AsyncEnumerable } from './async-enumerable.js';
5
5
  import type { EnumerableMethods } from './enumerable-methods.js';
6
6
  export declare class Enumerable<T> implements EnumerableMethods, Iterable<T> {
@@ -28,9 +28,13 @@ export declare class Enumerable<T> implements EnumerableMethods, Iterable<T> {
28
28
  forEach(func: IteratorFunction<T, void>): void;
29
29
  forceCast<TNew>(): Enumerable<TNew>;
30
30
  group<TGroup>(selector: IteratorFunction<T, TGroup>): Enumerable<[TGroup, T[]]>;
31
+ group<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Enumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]]>;
31
32
  groupSingle<TGroup>(selector: IteratorFunction<T, TGroup>): Enumerable<[TGroup, T]>;
33
+ groupSingle<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Enumerable<[TGroup['length'] extends 1 ? TGroup[0] : TGroup, T]>;
32
34
  groupToMap<TGroup>(selector: IteratorFunction<T, TGroup>): Map<TGroup, T[]>;
35
+ groupToMap<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T[]>;
33
36
  groupToSingleMap<TGroup>(selector: IteratorFunction<T, TGroup>): Map<TGroup, T>;
37
+ groupToSingleMap<TGroup extends [any, ...any[]]>(...selectors: GroupSelectors<T, TGroup>): Map<TGroup['length'] extends 1 ? TGroup[0] : TGroup, T>;
34
38
  tap(tapper: IteratorFunction<T, any>): Enumerable<T>;
35
39
  last<TPredicate extends T = T>(predicate?: Predicate<T> | TypePredicate<T, TPredicate>): TPredicate;
36
40
  lastOrDefault<D, TPredicate extends T = T>(defaultValue: D, predicate?: Predicate<T> | TypePredicate<T, TPredicate>): TPredicate | D;
@@ -79,19 +79,19 @@ export class Enumerable {
79
79
  forceCast() {
80
80
  return this;
81
81
  }
82
- group(selector) {
83
- const grouped = group(this.source, selector);
82
+ group(...selectors) {
83
+ const grouped = group(this.source, ...selectors);
84
84
  return new Enumerable(grouped);
85
85
  }
86
- groupSingle(selector) {
87
- const grouped = groupSingle(this.source, selector);
86
+ groupSingle(...selectors) {
87
+ const grouped = groupSingle(this.source, ...selectors);
88
88
  return new Enumerable(grouped);
89
89
  }
90
- groupToMap(selector) {
91
- return groupToMap(this.source, selector);
90
+ groupToMap(...selectors) {
91
+ return groupToMap(this.source, ...selectors);
92
92
  }
93
- groupToSingleMap(selector) {
94
- return groupToSingleMap(this.source, selector);
93
+ groupToSingleMap(...selectors) {
94
+ return groupToSingleMap(this.source, ...selectors);
95
95
  }
96
96
  tap(tapper) {
97
97
  const iterator = tap(this.source, tapper);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.91.0",
3
+ "version": "0.91.1",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,2 +0,0 @@
1
- export * from './maximum-length.js';
2
- export * from './minimum-length.js';
@@ -1,2 +0,0 @@
1
- export * from './maximum-length.js';
2
- export * from './minimum-length.js';
@@ -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,6 +0,0 @@
1
- export * from './boolean.coercer.js';
2
- export * from './date.coercer.js';
3
- export * from './number.coercer.js';
4
- export * from './regexp.coercer.js';
5
- export * from './string.coercer.js';
6
- export * from './uint8-array.coercer.js';
@@ -1,6 +0,0 @@
1
- export * from './boolean.coercer.js';
2
- export * from './date.coercer.js';
3
- export * from './number.coercer.js';
4
- export * from './regexp.coercer.js';
5
- export * from './string.coercer.js';
6
- export * from './uint8-array.coercer.js';
@@ -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,6 +0,0 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- export type LengthConstraintOptions = {
3
- minimum?: number;
4
- maximum?: number;
5
- };
6
- export declare function Length(options: LengthConstraintOptions): Decorator<'property' | 'accessor'>;
@@ -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
- }