@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,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'>;
@@ -1,25 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { isArrayBuffer, isArrayBufferView } from '../../utils/type-guards.js';
3
- import { createSchemaValueConstraintDecorator } from '../decorators/utils.js';
4
- import { SchemaError } from '../schema.error.js';
5
- import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
6
- export class MaximumLengthConstraint extends SchemaValueConstraint {
7
- maximumLength;
8
- suitableTypes = [String, Array, ArrayBuffer, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array];
9
- expects;
10
- constructor(maximumLength) {
11
- super();
12
- this.maximumLength = maximumLength;
13
- this.expects = `a maximum length of ${this.maximumLength}`;
14
- }
15
- validate(value, path, context) {
16
- const length = (isArrayBuffer(value) || isArrayBufferView(value)) ? value.byteLength : value.length;
17
- if (length > this.maximumLength) {
18
- return { valid: false, error: SchemaError.expectedButGot(this.expects, `a length of ${length}`, path, { fast: context.options.fastErrors }) };
19
- }
20
- return { valid: true };
21
- }
22
- }
23
- export function MaximumLength(maximumLength) {
24
- return createSchemaValueConstraintDecorator(new MaximumLengthConstraint(maximumLength));
25
- }
@@ -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, type ConstraintResult } from '../types/types.js';
5
- export declare class MaximumConstraint extends SchemaValueConstraint {
6
- private readonly maximum;
7
- readonly suitableTypes: NumberConstructor;
8
- readonly expects: string;
9
- constructor(maximum: number);
10
- validate(value: number, path: JsonPath, context: ConstraintContext): ConstraintResult;
11
- }
12
- export declare function Maximum(maximum: number): Decorator<'property' | 'accessor'>;
@@ -1,24 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createSchemaValueConstraintDecorator } from '../decorators/index.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 MaximumConstraint extends SchemaValueConstraint {
7
- maximum;
8
- suitableTypes = Number;
9
- expects;
10
- constructor(maximum) {
11
- super();
12
- this.maximum = maximum;
13
- this.expects = `<= ${this.maximum}`;
14
- }
15
- validate(value, path, context) {
16
- if (value > this.maximum) {
17
- return { valid: false, error: SchemaError.expectedButGot(this.expects, value.toString(), path, { fast: context.options.fastErrors }) };
18
- }
19
- return { valid: true };
20
- }
21
- }
22
- export function Maximum(maximum) {
23
- return createSchemaValueConstraintDecorator(new MaximumConstraint(maximum), { schema: typeSchema(Number) });
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, type ConstraintResult } from '../types/types.js';
5
- export declare class MinimumDateConstraint extends SchemaValueConstraint {
6
- private readonly minimum;
7
- readonly suitableTypes: NumberConstructor;
8
- readonly expects: string;
9
- constructor(minimum: Date | number);
10
- validate(value: Date, path: JsonPath, context: ConstraintContext): ConstraintResult;
11
- }
12
- export declare function MinimumDate(minimum: 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 MinimumDateConstraint extends SchemaValueConstraint {
8
- minimum;
9
- suitableTypes = Number;
10
- expects;
11
- constructor(minimum) {
12
- super();
13
- this.minimum = isNumber(minimum) ? new Date(minimum) : minimum;
14
- this.expects = `>= ${this.minimum.toISOString()}`;
15
- assertValidDate(this.minimum);
16
- }
17
- validate(value, path, context) {
18
- if (value > this.minimum) {
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 MinimumDate(minimum) {
25
- return createSchemaValueConstraintDecorator(new MinimumDateConstraint(minimum), { 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 MinimumLengthConstraint extends SchemaValueConstraint {
6
- private readonly minimumLength;
7
- readonly suitableTypes: (ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | ArrayConstructor | StringConstructor)[];
8
- readonly expects: string;
9
- constructor(minimumLength: number);
10
- validate(value: string | ArrayLike<any> | ArrayBuffer, path: JsonPath, context: ConstraintContext): ConstraintResult;
11
- }
12
- export declare function MinimumLength(minimumLength: number): Decorator<'property' | 'accessor'>;
@@ -1,25 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { isArrayBuffer, isArrayBufferView } from '../../utils/type-guards.js';
3
- import { createSchemaValueConstraintDecorator } from '../decorators/utils.js';
4
- import { SchemaError } from '../schema.error.js';
5
- import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
6
- export class MinimumLengthConstraint extends SchemaValueConstraint {
7
- minimumLength;
8
- suitableTypes = [String, Array, ArrayBuffer, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array];
9
- expects;
10
- constructor(minimumLength) {
11
- super();
12
- this.minimumLength = minimumLength;
13
- this.expects = `a minimum length of ${this.minimumLength}`;
14
- }
15
- validate(value, path, context) {
16
- const length = (isArrayBuffer(value) || isArrayBufferView(value)) ? value.byteLength : value.length;
17
- if (length < this.minimumLength) {
18
- return { valid: false, error: SchemaError.expectedButGot(this.expects, `a length of ${length}`, path, { fast: context.options.fastErrors }) };
19
- }
20
- return { valid: true };
21
- }
22
- }
23
- export function MinimumLength(minimumLength) {
24
- return createSchemaValueConstraintDecorator(new MinimumLengthConstraint(minimumLength));
25
- }
@@ -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, type ConstraintResult } from '../types/types.js';
5
- export declare class MinimumConstraint extends SchemaValueConstraint {
6
- private readonly minimum;
7
- readonly suitableTypes: NumberConstructor;
8
- readonly expects: string;
9
- constructor(minimum: number);
10
- validate(value: number, path: JsonPath, context: ConstraintContext): ConstraintResult;
11
- }
12
- export declare function Minimum(minimum: number): Decorator<'property' | 'accessor'>;
@@ -1,24 +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 MinimumConstraint extends SchemaValueConstraint {
7
- minimum;
8
- suitableTypes = Number;
9
- expects;
10
- constructor(minimum) {
11
- super();
12
- this.minimum = minimum;
13
- this.expects = `>= ${this.minimum}`;
14
- }
15
- validate(value, path, context) {
16
- if (value < this.minimum) {
17
- return { valid: false, error: SchemaError.expectedButGot(this.expects, value.toString(), path, { fast: context.options.fastErrors }) };
18
- }
19
- return { valid: true };
20
- }
21
- }
22
- export function Minimum(minimum) {
23
- return createSchemaValueConstraintDecorator(new MinimumConstraint(minimum), { schema: typeSchema(Number) });
24
- }
@@ -1,13 +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, type ConstraintResult } from '../types/types.js';
5
- export declare class PatternConstraint extends SchemaValueConstraint {
6
- private readonly pattern;
7
- private readonly patternName;
8
- readonly suitableTypes: StringConstructor;
9
- readonly expects: string;
10
- constructor(pattern: RegExp, patternName?: string);
11
- validate(value: string, path: JsonPath, context: ConstraintContext): ConstraintResult;
12
- }
13
- export declare function Pattern(pattern: RegExp, patternName?: string): Decorator<'property' | 'accessor'>;
@@ -1,26 +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 PatternConstraint extends SchemaValueConstraint {
7
- pattern;
8
- patternName;
9
- suitableTypes = String;
10
- expects;
11
- constructor(pattern, patternName = 'a pattern') {
12
- super();
13
- this.pattern = pattern;
14
- this.patternName = patternName;
15
- this.expects = `matching ${this.patternName}`;
16
- }
17
- validate(value, path, context) {
18
- if (!this.pattern.test(value)) {
19
- return { valid: false, error: SchemaError.expectedButGot(this.expects, `"${value}"`, path, { fast: context.options.fastErrors }) };
20
- }
21
- return { valid: true };
22
- }
23
- }
24
- export function Pattern(pattern, patternName) {
25
- return createSchemaValueConstraintDecorator(new PatternConstraint(pattern, patternName), { schema: typeSchema(String) });
26
- }
@@ -1,3 +0,0 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { SchemaTypeReflectionData } from './types.js';
3
- export declare function Class(options?: SchemaTypeReflectionData): Decorator<'class'>;
@@ -1,5 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createClassDecorator } from '../../reflection/index.js';
3
- export function Class(options = {}) {
4
- return createClassDecorator({ data: { schema: options }, mergeData: true });
5
- }
@@ -1,2 +0,0 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- export declare function Coerce(): Decorator<'property' | 'accessor'>;
@@ -1,5 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createSchemaPropertyDecorator } from './utils.js';
3
- export function Coerce() {
4
- return createSchemaPropertyDecorator({ coerce: true });
5
- }
@@ -1,4 +0,0 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { OneOrMany } from '../../types.js';
3
- import type { GenericConstraintFunction } from '../constraints/generic.js';
4
- export declare function Constraint<T>(constraintFunction: GenericConstraintFunction<T>, expects?: OneOrMany<string>): Decorator<'property' | 'accessor'>;
@@ -1,7 +0,0 @@
1
- import { GenericConstraint } from '../constraints/generic.js';
2
- import { createSchemaValueConstraintDecorator } from './utils.js';
3
- // eslint-disable-next-line @typescript-eslint/naming-convention
4
- export function Constraint(constraintFunction, expects) {
5
- const constraint = new GenericConstraint(constraintFunction, expects);
6
- return createSchemaValueConstraintDecorator(constraint);
7
- }
@@ -1,6 +0,0 @@
1
- export * from './class.js';
2
- export * from './coerce.js';
3
- export * from './constraint.js';
4
- export * from './property.js';
5
- export * from './types.js';
6
- export * from './utils.js';
@@ -1,6 +0,0 @@
1
- export * from './class.js';
2
- export * from './coerce.js';
3
- export * from './constraint.js';
4
- export * from './property.js';
5
- export * from './types.js';
6
- export * from './utils.js';
@@ -1,6 +0,0 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { OneOrMany, TypedOmit } from '../../types.js';
3
- import type { ValueType } from '../types/index.js';
4
- import type { PropertyOptions } from './types.js';
5
- export declare function Property(options?: PropertyOptions): Decorator<'property' | 'accessor'>;
6
- export declare function Property(schema?: OneOrMany<ValueType>, options?: TypedOmit<PropertyOptions, 'schema'>): Decorator<'property' | 'accessor'>;
@@ -1,17 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArray } from '../../utils/array/array.js';
3
- import { isDefined, isFunction, isString, isUndefined } from '../../utils/type-guards.js';
4
- import { typeSchema } from '../types/index.js';
5
- import { createSchemaPropertyDecorator } from './utils.js';
6
- export function Property(optionsOrTypes = {}, optionsOrNothing) {
7
- const schema = (isFunction(optionsOrTypes) || isString(optionsOrTypes)) ? typeSchema(optionsOrTypes) : undefined;
8
- const options = isUndefined(schema) ? optionsOrTypes : optionsOrNothing ?? {};
9
- return createSchemaPropertyDecorator({
10
- schema,
11
- ...options,
12
- coercers: isDefined(options.coercers) ? toArray(options.coercers) : undefined,
13
- transformers: isDefined(options.transformers) ? toArray(options.transformers) : undefined,
14
- arrayConstraints: isDefined(options.arrayConstraints) ? toArray(options.arrayConstraints) : undefined,
15
- valueConstraints: isDefined(options.valueConstraints) ? toArray(options.valueConstraints) : undefined
16
- });
17
- }
@@ -1,19 +0,0 @@
1
- import type { OneOrMany } from '../../types.js';
2
- import type { SchemaTestable } from '../schema.js';
3
- import type { ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, TypeSchema, ValueSchema, ValueType } from '../types/index.js';
4
- export type SchemaTypeReflectionData = Partial<Pick<ObjectSchema, 'mask' | 'unknownProperties' | 'unknownPropertiesKey'>> & {
5
- schema?: ObjectSchema | TypeSchema | ValueType;
6
- factory?: SchemaFactoryFunction<any>;
7
- };
8
- export type SchemaPropertyReflectionData = {
9
- schema?: OneOrMany<SchemaTestable>;
10
- array?: boolean;
11
- optional?: boolean;
12
- nullable?: boolean;
13
- coerce?: boolean;
14
- coercers?: readonly SchemaValueCoercer[];
15
- transformers?: readonly SchemaValueTransformer[];
16
- arrayConstraints?: readonly SchemaArrayConstraint[];
17
- valueConstraints?: readonly SchemaValueConstraint[];
18
- };
19
- export type PropertyOptions = Partial<ValueSchema<any>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import type { Decorator, PropertyMetadata } from '../../reflection/index.js';
2
- import type { OneOrMany } from '../../types.js';
3
- import type { Schema } from '../schema.js';
4
- import type { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
5
- import type { SchemaValueCoercer } from '../types/schema-value-coercer.js';
6
- import type { SchemaValueConstraint } from '../types/schema-value-constraint.js';
7
- import type { SchemaValueTransformer } from '../types/schema-value-transformer.js';
8
- import type { PropertyOptions, SchemaPropertyReflectionData } from './types.js';
9
- export declare function createSchemaPropertyDecorator(options: PropertyOptions): Decorator<'property' | 'accessor'>;
10
- export declare function createSchemaPropertyDecoratorFromSchema(schema: Schema): Decorator<'property' | 'accessor'>;
11
- export declare function createSchemaValueCoercerDecorator(coercer: SchemaValueCoercer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
12
- export declare function createSchemaValueTransformerDecorator(transformer: SchemaValueTransformer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
13
- export declare function createSchemaArrayConstraintDecorator(constraint: SchemaArrayConstraint, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
14
- export declare function createSchemaValueConstraintDecorator(constraints: OneOrMany<SchemaValueConstraint>, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
15
- export declare function tryGetSchemaPropertyReflectionData(metadata: PropertyMetadata): SchemaPropertyReflectionData | undefined;
@@ -1,48 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createPropertyOrAccessorDecorator } from '../../reflection/index.js';
3
- import { toArray } from '../../utils/array/array.js';
4
- import { merge } from '../../utils/merge.js';
5
- import { filterObject } from '../../utils/object/object.js';
6
- import { isArray, isDefined, isUndefined } from '../../utils/type-guards.js';
7
- import { isValueSchema, valueSchema } from '../types/types.js';
8
- export function createSchemaPropertyDecorator(options) {
9
- return createPropertyOrAccessorDecorator({
10
- handler(_, metadata) {
11
- const schemaData = getOrCreateSchemaPropertyReflectionData(metadata);
12
- const newSchemaData = {
13
- ...options,
14
- coercers: (isDefined(options.coercers) && (!isArray(options.coercers) || options.coercers.length > 0)) ? merge(toArray(options.coercers), schemaData.coercers) : undefined,
15
- transformers: (isDefined(options.transformers) && (!isArray(options.transformers) || options.transformers.length > 0)) ? merge(toArray(options.transformers), schemaData.transformers) : undefined,
16
- arrayConstraints: (isDefined(options.arrayConstraints) && (!isArray(options.arrayConstraints) || options.arrayConstraints.length > 0)) ? merge(toArray(options.arrayConstraints), schemaData.arrayConstraints) : undefined,
17
- valueConstraints: (isDefined(options.valueConstraints) && (!isArray(options.valueConstraints) || options.valueConstraints.length > 0)) ? merge(toArray(options.valueConstraints), schemaData.valueConstraints) : undefined
18
- };
19
- metadata.data.set('schema', filterObject(newSchemaData, isDefined), true);
20
- }
21
- });
22
- }
23
- export function createSchemaPropertyDecoratorFromSchema(schema) {
24
- return createSchemaPropertyDecorator(isValueSchema(schema) ? schema : valueSchema(schema));
25
- }
26
- export function createSchemaValueCoercerDecorator(coercer, options) {
27
- return createSchemaPropertyDecorator({ ...options, coercers: coercer });
28
- }
29
- export function createSchemaValueTransformerDecorator(transformer, options) {
30
- return createSchemaPropertyDecorator({ ...options, transformers: transformer });
31
- }
32
- export function createSchemaArrayConstraintDecorator(constraint, options) {
33
- return createSchemaPropertyDecorator({ ...options, arrayConstraints: constraint });
34
- }
35
- export function createSchemaValueConstraintDecorator(constraints, options) {
36
- return createSchemaPropertyDecorator({ ...options, valueConstraints: constraints });
37
- }
38
- export function tryGetSchemaPropertyReflectionData(metadata) {
39
- return metadata.data.tryGet('schema');
40
- }
41
- function getOrCreateSchemaPropertyReflectionData(metadata) {
42
- let schemaData = tryGetSchemaPropertyReflectionData(metadata);
43
- if (isUndefined(schemaData)) {
44
- schemaData = {};
45
- metadata.data.set('schema', schemaData);
46
- }
47
- return schemaData;
48
- }
@@ -1,10 +0,0 @@
1
- export * from './array-constraints/index.js';
2
- export * from './coercers/index.js';
3
- export * from './constraints/index.js';
4
- export * from './decorators/index.js';
5
- export * from './schema.error.js';
6
- export * from './schema.js';
7
- export * from './schemas/index.js';
8
- export * from './transformers/index.js';
9
- export * from './types/index.js';
10
- export * from './utils/index.js';
@@ -1,10 +0,0 @@
1
- export * from './array-constraints/index.js';
2
- export * from './coercers/index.js';
3
- export * from './constraints/index.js';
4
- export * from './decorators/index.js';
5
- export * from './schema.error.js';
6
- export * from './schema.js';
7
- export * from './schemas/index.js';
8
- export * from './transformers/index.js';
9
- export * from './types/index.js';
10
- export * from './utils/index.js';
@@ -1,15 +0,0 @@
1
- import { JsonPath } from '../json-path/index.js';
2
- import type { NormalizedObjectSchema, NormalizedTypeSchema, NormalizedValueSchema, ObjectSchema, SchemaOutput, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, TupleSchemaOutput, TypeSchema, ValueSchema, ValueType } from './types/index.js';
3
- export type Schema<T = any> = ObjectSchema<T> | ValueSchema<T> | TypeSchema<T>;
4
- export type SchemaTestable<T = any> = Schema<T> | ValueType<T>;
5
- export type NormalizedSchema<T = any> = NormalizedObjectSchema<T> | NormalizedValueSchema<T> | NormalizedTypeSchema<T>;
6
- export declare const Schema: {
7
- registerDefaultCoercer(coercer: SchemaValueCoercer): void;
8
- test<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
9
- validate<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions): boolean;
10
- parse<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions): T;
11
- function<T extends readonly SchemaTestable[], R extends SchemaTestable, F extends (...args: TupleSchemaOutput<T>) => SchemaOutput<R>>(argumentSchemas: T, returnSchema: R, handler: F): F;
12
- asyncFunction<T extends readonly SchemaTestable[], R extends SchemaTestable, F extends (...args: TupleSchemaOutput<T>) => Promise<SchemaOutput<R>>>(argumentSchemas: T, returnSchema: R, handler: F): F;
13
- };
14
- export declare function testSchema<T>(schema: Schema<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
15
- export declare function getExpectString(schema: SchemaTestable): string;
@@ -1,26 +0,0 @@
1
- import type { CustomErrorOptions } from '../errors/custom.error.js';
2
- import { CustomError } from '../errors/custom.error.js';
3
- import type { JsonPath } from '../json-path/index.js';
4
- import type { OneOrMany, TypedOmit, UndefinableJson } from '../types.js';
5
- import type { ErrorExtraInfo } from '../utils/format-error.js';
6
- import type { ValueType } from './types/index.js';
7
- export type SchemaErrorOptions = Pick<CustomErrorOptions, 'fast'> & {
8
- path: string | JsonPath;
9
- details?: UndefinableJson;
10
- inner?: OneOrMany<SchemaError>;
11
- cause?: any;
12
- };
13
- export declare class SchemaError extends CustomError implements ErrorExtraInfo {
14
- static readonly errorName = "SchemaError";
15
- readonly path: string;
16
- readonly details?: UndefinableJson;
17
- readonly inner?: OneOrMany<SchemaError>;
18
- constructor(message: string, options: SchemaErrorOptions, cause?: any);
19
- static expectedButGot(expected: OneOrMany<string | ValueType>, got: string | ValueType, path: string | JsonPath, options?: TypedOmit<SchemaErrorOptions, 'path'> & {
20
- customMessage?: string;
21
- }): SchemaError;
22
- static couldNotCoerce(expected: OneOrMany<string | ValueType>, got: string | ValueType, path: string | JsonPath, options: TypedOmit<SchemaErrorOptions, 'path'> & {
23
- customMessage?: string;
24
- }): SchemaError;
25
- getExtraInfo(includeMessage?: boolean): UndefinableJson | undefined;
26
- }
@@ -1,64 +0,0 @@
1
- import { CustomError } from '../errors/custom.error.js';
2
- import { toArray } from '../utils/array/array.js';
3
- import { isArray, isDefined, isNotNullOrUndefined, isString } from '../utils/type-guards.js';
4
- import { getExpectString } from './schema.js';
5
- import { getValueTypeName } from './utils/index.js';
6
- export class SchemaError extends CustomError {
7
- static errorName = 'SchemaError';
8
- path;
9
- details;
10
- inner;
11
- constructor(message, options, cause) {
12
- super({ message, cause: cause ?? options.cause, fast: options.fast });
13
- this.path = isString(options.path) ? options.path : options.path.path;
14
- if (isDefined(options.inner) && (!isArray(options.inner) || (options.inner.length > 0))) {
15
- this.inner = isArray(options.inner)
16
- ? (options.inner.length == 1)
17
- ? options.inner[0]
18
- : options.inner
19
- : options.inner;
20
- }
21
- if (isNotNullOrUndefined(options.details)) {
22
- this.details = options.details;
23
- }
24
- }
25
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
26
- static expectedButGot(expected, got, path, options) {
27
- const expectedNames = toArray(expected).map((exp) => (isString(exp) ? exp : getExpectString(exp)));
28
- const gotName = isString(got) ? got : getValueTypeName(got);
29
- const expectedString = expectedNames.length == 1
30
- ? expectedNames[0]
31
- : `(${expectedNames.join(' | ')})`;
32
- const customMessage = isDefined(options?.customMessage) ? `: ${options.customMessage}` : '.';
33
- const message = `Expected ${expectedString} but got ${gotName}${customMessage}`;
34
- return new SchemaError(message, { path, ...options });
35
- }
36
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
37
- static couldNotCoerce(expected, got, path, options) {
38
- const expectedNames = toArray(expected).map((exp) => (isString(exp) ? exp : getValueTypeName(exp)));
39
- const gotText = isString(got) ? got : getValueTypeName(got);
40
- const expectedString = expectedNames.length == 1
41
- ? expectedNames[0]
42
- : `[${expectedNames.join(', ')}]`;
43
- const customMessageString = isDefined(options.customMessage) ? `: ${options.customMessage}` : '.';
44
- const errorMessage = `Could not coerce ${gotText} to ${expectedString}${customMessageString}`;
45
- return new SchemaError(errorMessage, { path, ...options });
46
- }
47
- getExtraInfo(includeMessage = false) {
48
- const obj = {
49
- path: this.path
50
- };
51
- if (includeMessage) {
52
- obj['message'] = this.message;
53
- }
54
- if (isDefined(this.inner)) {
55
- obj['inner'] = isArray(this.inner)
56
- ? this.inner.map((error) => error.getExtraInfo(true))
57
- : this.inner.getExtraInfo(true);
58
- }
59
- if (isNotNullOrUndefined(this.details)) {
60
- obj['details'] = this.details;
61
- }
62
- return obj;
63
- }
64
- }