@tstdl/base 0.90.92 → 0.91.0-beta10

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 (253) hide show
  1. package/api/types.d.ts +1 -1
  2. package/authentication/authentication.api.d.ts +56 -57
  3. package/authentication/authentication.api.js +1 -6
  4. package/authentication/client/api.client.d.ts +4 -5
  5. package/authentication/client/api.client.js +1 -2
  6. package/authentication/client/http-client.middleware.d.ts +1 -1
  7. package/browser/pdf-options.js +8 -9
  8. package/errors/custom.error.d.ts +5 -5
  9. package/examples/api/basic-overview.js +4 -4
  10. package/http/client/http-client-request.d.ts +1 -2
  11. package/http/client/module.d.ts +1 -1
  12. package/image-service/image-service.js +4 -7
  13. package/mail/mail.client.d.ts +2 -2
  14. package/mail/mail.client.js +3 -5
  15. package/orm/decorators.d.ts +1 -0
  16. package/orm/decorators.js +4 -0
  17. package/orm/entity.js +1 -1
  18. package/orm/index.d.ts +4 -0
  19. package/orm/index.js +4 -0
  20. package/orm/repository.d.ts +6 -8
  21. package/orm/repository.js +7 -0
  22. package/orm/schema-converter.d.ts +99 -0
  23. package/orm/schema-converter.js +74 -0
  24. package/orm/schema.d.ts +3 -0
  25. package/orm/schema.js +1 -0
  26. package/orm/types.d.ts +8 -0
  27. package/orm/types.js +6 -0
  28. package/package.json +7 -5
  29. package/reflection/registry.d.ts +1 -1
  30. package/reflection/utils.d.ts +2 -2
  31. package/schema/decorators/class.d.ts +1 -1
  32. package/schema/decorators/index.d.ts +0 -2
  33. package/schema/decorators/index.js +0 -2
  34. package/schema/decorators/property.d.ts +6 -5
  35. package/schema/decorators/property.js +10 -14
  36. package/schema/decorators/types.d.ts +7 -12
  37. package/schema/decorators/utils.d.ts +2 -15
  38. package/schema/decorators/utils.js +4 -43
  39. package/schema/index.d.ts +1 -6
  40. package/schema/index.js +15 -6
  41. package/schema/schema.d.ts +89 -14
  42. package/schema/schema.error.d.ts +4 -6
  43. package/schema/schema.error.js +6 -10
  44. package/schema/schema.js +74 -276
  45. package/schema/schemas/any.d.ts +7 -5
  46. package/schema/schemas/any.js +10 -6
  47. package/schema/schemas/array.d.ts +11 -12
  48. package/schema/schemas/array.js +29 -19
  49. package/schema/schemas/bigint.d.ts +9 -0
  50. package/schema/schemas/bigint.js +19 -0
  51. package/schema/schemas/boolean.d.ts +11 -5
  52. package/schema/schemas/boolean.js +41 -6
  53. package/schema/schemas/date.d.ts +9 -7
  54. package/schema/schemas/date.js +24 -18
  55. package/schema/schemas/defaulted.d.ts +11 -6
  56. package/schema/schemas/defaulted.js +23 -8
  57. package/schema/schemas/enumeration.d.ts +10 -5
  58. package/schema/schemas/enumeration.js +25 -15
  59. package/schema/schemas/function.d.ts +8 -0
  60. package/schema/schemas/function.js +14 -0
  61. package/schema/schemas/index.d.ts +5 -6
  62. package/schema/schemas/index.js +5 -6
  63. package/schema/schemas/instance.d.ts +11 -3
  64. package/schema/schemas/instance.js +25 -4
  65. package/schema/schemas/literal.d.ts +10 -5
  66. package/schema/schemas/literal.js +25 -15
  67. package/schema/schemas/never.d.ts +6 -0
  68. package/schema/schemas/never.js +11 -0
  69. package/schema/schemas/nullable.d.ts +11 -6
  70. package/schema/schemas/nullable.js +24 -7
  71. package/schema/schemas/number.d.ts +9 -7
  72. package/schema/schemas/number.js +28 -23
  73. package/schema/schemas/object.d.ts +84 -7
  74. package/schema/schemas/object.js +180 -6
  75. package/schema/schemas/one-or-many.d.ts +10 -7
  76. package/schema/schemas/one-or-many.js +18 -11
  77. package/schema/schemas/optional.d.ts +11 -7
  78. package/schema/schemas/optional.js +24 -6
  79. package/schema/schemas/readable-stream.d.ts +8 -6
  80. package/schema/schemas/readable-stream.js +10 -5
  81. package/schema/schemas/regexp.d.ts +8 -6
  82. package/schema/schemas/regexp.js +24 -6
  83. package/schema/schemas/simple.d.ts +27 -0
  84. package/schema/schemas/simple.js +57 -0
  85. package/schema/schemas/string.d.ts +9 -21
  86. package/schema/schemas/string.js +20 -34
  87. package/schema/schemas/symbol.d.ts +8 -0
  88. package/schema/schemas/symbol.js +19 -0
  89. package/schema/schemas/transform.d.ts +9 -5
  90. package/schema/schemas/transform.js +19 -6
  91. package/schema/schemas/uint8-array.d.ts +9 -5
  92. package/schema/schemas/uint8-array.js +17 -26
  93. package/schema/schemas/union.d.ts +14 -7
  94. package/schema/schemas/union.js +30 -11
  95. package/schema/schemas/unknown.d.ts +7 -5
  96. package/schema/schemas/unknown.js +11 -7
  97. package/schema/testable.d.ts +3 -0
  98. package/schema/testable.js +33 -0
  99. package/schema/types.d.ts +31 -0
  100. package/schema/types.js +1 -0
  101. package/schema-old/decorators/class.d.ts +3 -0
  102. package/schema-old/decorators/class.js +5 -0
  103. package/schema-old/decorators/index.d.ts +6 -0
  104. package/schema-old/decorators/index.js +6 -0
  105. package/schema-old/decorators/property.d.ts +6 -0
  106. package/schema-old/decorators/property.js +17 -0
  107. package/schema-old/decorators/types.d.ts +19 -0
  108. package/schema-old/decorators/types.js +1 -0
  109. package/schema-old/decorators/utils.d.ts +15 -0
  110. package/schema-old/decorators/utils.js +48 -0
  111. package/schema-old/index.d.ts +10 -0
  112. package/schema-old/index.js +10 -0
  113. package/schema-old/schema.d.ts +15 -0
  114. package/schema-old/schema.error.d.ts +26 -0
  115. package/schema-old/schema.error.js +64 -0
  116. package/schema-old/schema.js +283 -0
  117. package/schema-old/schemas/any.d.ts +5 -0
  118. package/schema-old/schemas/any.js +9 -0
  119. package/schema-old/schemas/array.d.ts +12 -0
  120. package/schema-old/schemas/array.js +23 -0
  121. package/schema-old/schemas/boolean.d.ts +5 -0
  122. package/schema-old/schemas/boolean.js +9 -0
  123. package/schema-old/schemas/date.d.ts +8 -0
  124. package/schema-old/schemas/date.js +22 -0
  125. package/schema-old/schemas/defaulted.d.ts +6 -0
  126. package/schema-old/schemas/defaulted.js +10 -0
  127. package/schema-old/schemas/enumeration.d.ts +6 -0
  128. package/schema-old/schemas/enumeration.js +17 -0
  129. package/schema-old/schemas/index.d.ts +26 -0
  130. package/schema-old/schemas/index.js +26 -0
  131. package/schema-old/schemas/instance.d.ts +3 -0
  132. package/schema-old/schemas/instance.js +5 -0
  133. package/schema-old/schemas/literal.d.ts +5 -0
  134. package/schema-old/schemas/literal.js +17 -0
  135. package/schema-old/schemas/nullable.d.ts +6 -0
  136. package/schema-old/schemas/nullable.js +9 -0
  137. package/schema-old/schemas/number.d.ts +9 -0
  138. package/schema-old/schemas/number.js +27 -0
  139. package/schema-old/schemas/object.d.ts +7 -0
  140. package/schema-old/schemas/object.js +12 -0
  141. package/schema-old/schemas/one-or-many.d.ts +9 -0
  142. package/schema-old/schemas/one-or-many.js +15 -0
  143. package/schema-old/schemas/optional.d.ts +7 -0
  144. package/schema-old/schemas/optional.js +8 -0
  145. package/schema-old/schemas/readable-stream.d.ts +6 -0
  146. package/schema-old/schemas/readable-stream.js +9 -0
  147. package/schema-old/schemas/regexp.d.ts +6 -0
  148. package/schema-old/schemas/regexp.js +9 -0
  149. package/schema-old/schemas/string.d.ts +22 -0
  150. package/schema-old/schemas/string.js +38 -0
  151. package/schema-old/schemas/transform.d.ts +5 -0
  152. package/schema-old/schemas/transform.js +7 -0
  153. package/schema-old/schemas/uint8-array.d.ts +10 -0
  154. package/schema-old/schemas/uint8-array.js +29 -0
  155. package/schema-old/schemas/union.d.ts +7 -0
  156. package/schema-old/schemas/union.js +13 -0
  157. package/schema-old/schemas/unknown.d.ts +5 -0
  158. package/schema-old/schemas/unknown.js +9 -0
  159. package/templates/resolvers/string.template-resolver.d.ts +0 -1
  160. package/templates/resolvers/string.template-resolver.js +1 -5
  161. package/templates/template.model.js +1 -1
  162. package/types.d.ts +2 -0
  163. package/utils/type-guards.js +1 -1
  164. /package/{schema → schema-old}/array-constraints/index.d.ts +0 -0
  165. /package/{schema → schema-old}/array-constraints/index.js +0 -0
  166. /package/{schema → schema-old}/array-constraints/maximum-length.d.ts +0 -0
  167. /package/{schema → schema-old}/array-constraints/maximum-length.js +0 -0
  168. /package/{schema → schema-old}/array-constraints/minimum-length.d.ts +0 -0
  169. /package/{schema → schema-old}/array-constraints/minimum-length.js +0 -0
  170. /package/{schema → schema-old}/coercers/boolean.coercer.d.ts +0 -0
  171. /package/{schema → schema-old}/coercers/boolean.coercer.js +0 -0
  172. /package/{schema → schema-old}/coercers/date.coercer.d.ts +0 -0
  173. /package/{schema → schema-old}/coercers/date.coercer.js +0 -0
  174. /package/{schema → schema-old}/coercers/index.d.ts +0 -0
  175. /package/{schema → schema-old}/coercers/index.js +0 -0
  176. /package/{schema → schema-old}/coercers/number.coercer.d.ts +0 -0
  177. /package/{schema → schema-old}/coercers/number.coercer.js +0 -0
  178. /package/{schema → schema-old}/coercers/regexp.coercer.d.ts +0 -0
  179. /package/{schema → schema-old}/coercers/regexp.coercer.js +0 -0
  180. /package/{schema → schema-old}/coercers/string.coercer.d.ts +0 -0
  181. /package/{schema → schema-old}/coercers/string.coercer.js +0 -0
  182. /package/{schema → schema-old}/coercers/uint8-array.coercer.d.ts +0 -0
  183. /package/{schema → schema-old}/coercers/uint8-array.coercer.js +0 -0
  184. /package/{schema → schema-old}/constraints/enumeration.d.ts +0 -0
  185. /package/{schema → schema-old}/constraints/enumeration.js +0 -0
  186. /package/{schema → schema-old}/constraints/generic.d.ts +0 -0
  187. /package/{schema → schema-old}/constraints/generic.js +0 -0
  188. /package/{schema → schema-old}/constraints/index.d.ts +0 -0
  189. /package/{schema → schema-old}/constraints/index.js +0 -0
  190. /package/{schema → schema-old}/constraints/integer.d.ts +0 -0
  191. /package/{schema → schema-old}/constraints/integer.js +0 -0
  192. /package/{schema → schema-old}/constraints/length.d.ts +0 -0
  193. /package/{schema → schema-old}/constraints/length.js +0 -0
  194. /package/{schema → schema-old}/constraints/literal.d.ts +0 -0
  195. /package/{schema → schema-old}/constraints/literal.js +0 -0
  196. /package/{schema → schema-old}/constraints/maximum-date.d.ts +0 -0
  197. /package/{schema → schema-old}/constraints/maximum-date.js +0 -0
  198. /package/{schema → schema-old}/constraints/maximum-length.d.ts +0 -0
  199. /package/{schema → schema-old}/constraints/maximum-length.js +0 -0
  200. /package/{schema → schema-old}/constraints/maximum.d.ts +0 -0
  201. /package/{schema → schema-old}/constraints/maximum.js +0 -0
  202. /package/{schema → schema-old}/constraints/minimum-date.d.ts +0 -0
  203. /package/{schema → schema-old}/constraints/minimum-date.js +0 -0
  204. /package/{schema → schema-old}/constraints/minimum-length.d.ts +0 -0
  205. /package/{schema → schema-old}/constraints/minimum-length.js +0 -0
  206. /package/{schema → schema-old}/constraints/minimum.d.ts +0 -0
  207. /package/{schema → schema-old}/constraints/minimum.js +0 -0
  208. /package/{schema → schema-old}/constraints/pattern.d.ts +0 -0
  209. /package/{schema → schema-old}/constraints/pattern.js +0 -0
  210. /package/{schema → schema-old}/decorators/coerce.d.ts +0 -0
  211. /package/{schema → schema-old}/decorators/coerce.js +0 -0
  212. /package/{schema → schema-old}/decorators/constraint.d.ts +0 -0
  213. /package/{schema → schema-old}/decorators/constraint.js +0 -0
  214. /package/{schema → schema-old}/schemas/assign.d.ts +0 -0
  215. /package/{schema → schema-old}/schemas/assign.js +0 -0
  216. /package/{schema → schema-old}/schemas/constraint.d.ts +0 -0
  217. /package/{schema → schema-old}/schemas/constraint.js +0 -0
  218. /package/{schema → schema-old}/schemas/omit.d.ts +0 -0
  219. /package/{schema → schema-old}/schemas/omit.js +0 -0
  220. /package/{schema → schema-old}/schemas/partial.d.ts +0 -0
  221. /package/{schema → schema-old}/schemas/partial.js +0 -0
  222. /package/{schema → schema-old}/schemas/pick.d.ts +0 -0
  223. /package/{schema → schema-old}/schemas/pick.js +0 -0
  224. /package/{schema → schema-old}/schemas/record.d.ts +0 -0
  225. /package/{schema → schema-old}/schemas/record.js +0 -0
  226. /package/{schema → schema-old}/transformers/generic.d.ts +0 -0
  227. /package/{schema → schema-old}/transformers/generic.js +0 -0
  228. /package/{schema → schema-old}/transformers/index.d.ts +0 -0
  229. /package/{schema → schema-old}/transformers/index.js +0 -0
  230. /package/{schema → schema-old}/transformers/lowercase.d.ts +0 -0
  231. /package/{schema → schema-old}/transformers/lowercase.js +0 -0
  232. /package/{schema → schema-old}/transformers/trim.d.ts +0 -0
  233. /package/{schema → schema-old}/transformers/trim.js +0 -0
  234. /package/{schema → schema-old}/transformers/uppercase.d.ts +0 -0
  235. /package/{schema → schema-old}/transformers/uppercase.js +0 -0
  236. /package/{schema → schema-old}/types/index.d.ts +0 -0
  237. /package/{schema → schema-old}/types/index.js +0 -0
  238. /package/{schema → schema-old}/types/schema-array-constraint.d.ts +0 -0
  239. /package/{schema → schema-old}/types/schema-array-constraint.js +0 -0
  240. /package/{schema → schema-old}/types/schema-value-coercer.d.ts +0 -0
  241. /package/{schema → schema-old}/types/schema-value-coercer.js +0 -0
  242. /package/{schema → schema-old}/types/schema-value-constraint.d.ts +0 -0
  243. /package/{schema → schema-old}/types/schema-value-constraint.js +0 -0
  244. /package/{schema → schema-old}/types/schema-value-transformer.d.ts +0 -0
  245. /package/{schema → schema-old}/types/schema-value-transformer.js +0 -0
  246. /package/{schema → schema-old}/types/types.d.ts +0 -0
  247. /package/{schema → schema-old}/types/types.js +0 -0
  248. /package/{schema → schema-old}/utils/index.d.ts +0 -0
  249. /package/{schema → schema-old}/utils/index.js +0 -0
  250. /package/{schema → schema-old}/utils/schema.d.ts +0 -0
  251. /package/{schema → schema-old}/utils/schema.js +0 -0
  252. /package/{schema → schema-old}/utils/value-type.d.ts +0 -0
  253. /package/{schema → schema-old}/utils/value-type.js +0 -0
@@ -1,8 +1,10 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
3
- export type DateOptions = ValueSchemaOptions & {
4
- minimum?: Date | number;
5
- maximum?: Date | number;
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type DateSchemaOptions = SimpleSchemaOptions & {
4
+ integer?: boolean;
6
5
  };
7
- export declare function date(options?: DateOptions): ValueSchema<Date>;
8
- export declare function DateProperty(options?: DateOptions): Decorator<'property' | 'accessor'>;
6
+ export declare class DateSchema extends SimpleSchema<globalThis.Date> {
7
+ constructor(options?: DateSchemaOptions);
8
+ }
9
+ export declare function date(options?: DateSchemaOptions): DateSchema;
10
+ export declare function DateProperty(options?: SchemaPropertyDecoratorOptions & DateSchemaOptions): SchemaPropertyDecorator;
@@ -1,22 +1,28 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArrayCopy } from '../../utils/array/array.js';
3
- import { isDefined } from '../../utils/type-guards.js';
4
- import { MaximumDateConstraint, MinimumDateConstraint } from '../constraints/index.js';
5
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/index.js';
6
- import { valueSchema } from '../types/types.js';
7
- export function date(options = {}) {
8
- const constraints = toArrayCopy(options.valueConstraints ?? []);
9
- if (isDefined(options.minimum)) {
10
- constraints.push(new MinimumDateConstraint(options.minimum));
1
+ import { isValidDate } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SchemaError } from '../schema.error.js';
4
+ import { SimpleSchema } from './simple.js';
5
+ export class DateSchema extends SimpleSchema {
6
+ constructor(options) {
7
+ super('date', isValidDate, options, {
8
+ coercers: {
9
+ string: (value, path, options) => {
10
+ const result = new globalThis.Date(value);
11
+ return globalThis.Number.isNaN(result.getTime())
12
+ ? { success: false, error: SchemaError.couldNotCoerce('date', 'string', path, { fast: options.fastErrors }) }
13
+ : { success: true, value: result, valid: true };
14
+ },
15
+ number: (value) => ({ success: true, value: new globalThis.Date(value), valid: false })
16
+ },
17
+ constraints: [
18
+ (options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'value is not an integer.' }) : null
19
+ ]
20
+ });
11
21
  }
12
- if (isDefined(options.maximum)) {
13
- constraints.push(new MaximumDateConstraint(options.maximum));
14
- }
15
- return valueSchema(Date, {
16
- ...options,
17
- valueConstraints: constraints
18
- });
22
+ }
23
+ export function date(options) {
24
+ return new DateSchema(options);
19
25
  }
20
26
  export function DateProperty(options) {
21
- return createSchemaPropertyDecoratorFromSchema(date(options));
27
+ return Property(date(options), options);
22
28
  }
@@ -1,6 +1,11 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { OneOrMany } from '../../types.js';
3
- import type { SchemaTestable } from '../schema.js';
4
- import type { ValueSchema } from '../types/index.js';
5
- export declare function defaulted<T, Default>(type: OneOrMany<SchemaTestable<T>>, defaultValue: Default): ValueSchema<NonNullable<T> | Default>;
6
- export declare function Defaulted(type: OneOrMany<SchemaTestable>, defaultValue: any): Decorator<'property' | 'accessor'>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
+ export declare class DefaultSchema<T, D> extends Schema<T | D> {
5
+ readonly schema: Schema<T>;
6
+ readonly defaultValue: D;
7
+ constructor(schema: SchemaTestable<T>, defaultValue: D);
8
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | D>;
9
+ }
10
+ export declare function defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D): DefaultSchema<T, D>;
11
+ export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,10 +1,25 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/utils.js';
3
- import { valueSchema } from '../types/index.js';
4
- import { transform } from './transform.js';
5
- export function defaulted(type, defaultValue) {
6
- return transform(valueSchema(type, { optional: true, nullable: true }), (value) => value ?? defaultValue); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
1
+ import { isNullOrUndefined } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { Schema } from '../schema.js';
4
+ import { schemaTestableToSchema } from '../testable.js';
5
+ export class DefaultSchema extends Schema {
6
+ schema;
7
+ defaultValue;
8
+ constructor(schema, defaultValue) {
9
+ super();
10
+ this.schema = schemaTestableToSchema(schema);
11
+ this.defaultValue = defaultValue;
12
+ }
13
+ _test(value, path, options) {
14
+ if (isNullOrUndefined(value)) {
15
+ return { valid: true, value: this.defaultValue };
16
+ }
17
+ return this.schema._test(value, path, options);
18
+ }
7
19
  }
8
- export function Defaulted(type, defaultValue) {
9
- return createSchemaPropertyDecoratorFromSchema(defaulted(type, defaultValue));
20
+ export function defaulted(schema, defaultValue) {
21
+ return new DefaultSchema(schema, defaultValue);
22
+ }
23
+ export function Defaulted(schema, defaultValue, options) {
24
+ return Property(defaulted(schema, defaultValue), options);
10
25
  }
@@ -1,6 +1,11 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
1
  import type { Enumeration as EnumerationType, EnumerationValue } from '../../types.js';
3
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
4
- export type EnumerationOptions = ValueSchemaOptions;
5
- export declare function enumeration<T extends EnumerationType>(enumerationValue: T, options?: EnumerationOptions): ValueSchema<EnumerationValue<T>>;
6
- export declare function Enumeration(enumerationValue: EnumerationType, options?: EnumerationOptions): Decorator<'property' | 'accessor'>;
2
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
4
+ export type EnumerationSchemaOptions = SimpleSchemaOptions;
5
+ export declare class EnumerationSchema<T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
6
+ #private;
7
+ readonly enumeration: EnumerationType;
8
+ constructor(enumeration: T, options?: EnumerationSchemaOptions);
9
+ }
10
+ export declare function enumeration<T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions): EnumerationSchema<T>;
11
+ export declare function Enumeration(enumeration: EnumerationType, options?: EnumerationSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,17 +1,27 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArrayCopy } from '../../utils/array/array.js';
3
- import { EnumerationConstraint } from '../constraints/index.js';
4
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/index.js';
5
- import { valueSchema } from '../types/types.js';
6
- export function enumeration(enumerationValue, options) {
7
- const valueConstraints = toArrayCopy(options?.valueConstraints ?? []);
8
- const enumerationConstraint = new EnumerationConstraint(enumerationValue);
9
- valueConstraints.push(enumerationConstraint);
10
- return valueSchema(enumerationConstraint.suitableTypes, {
11
- ...options,
12
- valueConstraints
13
- });
1
+ import { enumValues } from '../../utils/enum.js';
2
+ import { isArray, isString } from '../../utils/type-guards.js';
3
+ import { Property } from '../decorators/index.js';
4
+ import { SimpleSchema } from './simple.js';
5
+ export class EnumerationSchema extends SimpleSchema {
6
+ #allowedValuesSet;
7
+ enumeration;
8
+ constructor(enumeration, options) {
9
+ const allowedValues = isArray(enumeration) ? enumeration : enumValues(enumeration);
10
+ const allowedValuesString = allowedValues.map((value) => (isString(value) ? `"${value}"` : String(value))).join(', ');
11
+ super(`one of [${allowedValuesString}]`, (value) => this.#allowedValuesSet.has(value), options, {
12
+ coercers: {
13
+ string: (value) => ({ success: true, value: Number(value), valid: false }),
14
+ number: (value) => ({ success: true, value: String(value), valid: false })
15
+ },
16
+ gotValueFormatter: (value) => isString(value) ? `"${value}"` : String(value)
17
+ });
18
+ this.enumeration = enumeration;
19
+ this.#allowedValuesSet = new Set(allowedValues);
20
+ }
14
21
  }
15
- export function Enumeration(enumerationValue, options) {
16
- return createSchemaPropertyDecoratorFromSchema(enumeration(enumerationValue, options));
22
+ export function enumeration(enumeration, options) {
23
+ return new EnumerationSchema(enumeration, options);
24
+ }
25
+ export function Enumeration(enums, options) {
26
+ return Property(enumeration(enums, options), options);
17
27
  }
@@ -0,0 +1,8 @@
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type FunctionSchemaOptions = SimpleSchemaOptions;
4
+ export declare class FunctionSchema extends SimpleSchema<Function> {
5
+ constructor(options?: FunctionSchemaOptions);
6
+ }
7
+ export declare function func(): FunctionSchema;
8
+ export declare function FunctionProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -0,0 +1,14 @@
1
+ import { isFunction } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SimpleSchema } from './simple.js';
4
+ export class FunctionSchema extends SimpleSchema {
5
+ constructor(options) {
6
+ super('function', isFunction, options);
7
+ }
8
+ }
9
+ export function func() {
10
+ return new FunctionSchema();
11
+ }
12
+ export function FunctionProperty(options) {
13
+ return Property(func(), options);
14
+ }
@@ -1,25 +1,24 @@
1
1
  export * from './any.js';
2
2
  export * from './array.js';
3
- export * from './assign.js';
3
+ export * from './bigint.js';
4
4
  export * from './boolean.js';
5
- export * from './constraint.js';
6
5
  export * from './date.js';
7
6
  export * from './defaulted.js';
8
7
  export * from './enumeration.js';
8
+ export * from './function.js';
9
9
  export * from './instance.js';
10
10
  export * from './literal.js';
11
+ export * from './never.js';
11
12
  export * from './nullable.js';
12
13
  export * from './number.js';
13
14
  export * from './object.js';
14
- export * from './omit.js';
15
15
  export * from './one-or-many.js';
16
16
  export * from './optional.js';
17
- export * from './partial.js';
18
- export * from './pick.js';
19
17
  export * from './readable-stream.js';
20
- export * from './record.js';
21
18
  export * from './regexp.js';
19
+ export * from './simple.js';
22
20
  export * from './string.js';
21
+ export * from './symbol.js';
23
22
  export * from './transform.js';
24
23
  export * from './uint8-array.js';
25
24
  export * from './union.js';
@@ -1,25 +1,24 @@
1
1
  export * from './any.js';
2
2
  export * from './array.js';
3
- export * from './assign.js';
3
+ export * from './bigint.js';
4
4
  export * from './boolean.js';
5
- export * from './constraint.js';
6
5
  export * from './date.js';
7
6
  export * from './defaulted.js';
8
7
  export * from './enumeration.js';
8
+ export * from './function.js';
9
9
  export * from './instance.js';
10
10
  export * from './literal.js';
11
+ export * from './never.js';
11
12
  export * from './nullable.js';
12
13
  export * from './number.js';
13
14
  export * from './object.js';
14
- export * from './omit.js';
15
15
  export * from './one-or-many.js';
16
16
  export * from './optional.js';
17
- export * from './partial.js';
18
- export * from './pick.js';
19
17
  export * from './readable-stream.js';
20
- export * from './record.js';
21
18
  export * from './regexp.js';
19
+ export * from './simple.js';
22
20
  export * from './string.js';
21
+ export * from './symbol.js';
23
22
  export * from './transform.js';
24
23
  export * from './uint8-array.js';
25
24
  export * from './union.js';
@@ -1,3 +1,11 @@
1
- import type { ValueSchema, ValueSchemaOptions, ValueType } from '../types/index.js';
2
- export type InstanceOptions = ValueSchemaOptions;
3
- export declare function instance<T>(type: ValueType<T>, options?: InstanceOptions): ValueSchema<T>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import type { AbstractConstructor } from '../../types.js';
3
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
4
+ import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
+ export declare class InstanceSchema<T extends AbstractConstructor> extends Schema<InstanceType<T>> {
6
+ readonly type: T;
7
+ constructor(type: T);
8
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<InstanceType<T>>;
9
+ }
10
+ export declare function instance<T extends AbstractConstructor>(type: T): InstanceSchema<T>;
11
+ export declare function Instance(type: AbstractConstructor, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,26 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- import { valueSchema } from '../types/index.js';
3
- export function instance(type, options) {
4
- return valueSchema(type, options);
1
+ import { typeOf } from '../../utils/type-of.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SchemaError } from '../schema.error.js';
4
+ import { Schema } from '../schema.js';
5
+ export class InstanceSchema extends Schema {
6
+ type;
7
+ constructor(type) {
8
+ super();
9
+ this.type = type;
10
+ }
11
+ _test(value, path, options) {
12
+ if (value instanceof this.type) {
13
+ return { valid: true, value };
14
+ }
15
+ return {
16
+ valid: false,
17
+ error: SchemaError.expectedButGot(typeOf(this.type), typeOf(value), path, { fast: options.fastErrors })
18
+ };
19
+ }
20
+ }
21
+ export function instance(type) {
22
+ return new InstanceSchema(type);
23
+ }
24
+ export function Instance(type, options) {
25
+ return Property(instance(type), options);
5
26
  }
@@ -1,5 +1,10 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
3
- export type LiteralOptions = ValueSchemaOptions;
4
- export declare function literal<const T>(value: T, options?: LiteralOptions): ValueSchema<T>;
5
- export declare function Literal(value: any): Decorator<'property' | 'accessor'>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
+ export declare class LiteralSchema<const T> extends Schema<T> {
5
+ readonly value: T;
6
+ constructor(value: T);
7
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
8
+ }
9
+ export declare function literal<const T>(value: T): LiteralSchema<T>;
10
+ export declare function Literal(value: any, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,17 +1,27 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArrayCopy } from '../../utils/array/array.js';
3
- import { LiteralConstraint } from '../constraints/index.js';
4
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/index.js';
5
- import { valueSchema } from '../types/types.js';
6
- import { getValueType } from '../utils/value-type.js';
7
- export function literal(value, options) {
8
- const valueConstraints = toArrayCopy(options?.valueConstraints ?? []);
9
- valueConstraints.push(new LiteralConstraint(value));
10
- return valueSchema(getValueType(value), {
11
- ...options,
12
- valueConstraints
13
- });
1
+ import { isPrimitive } from '../../utils/type-guards.js';
2
+ import { typeOf } from '../../utils/type-of.js';
3
+ import { Property } from '../decorators/index.js';
4
+ import { SchemaError } from '../schema.error.js';
5
+ import { Schema } from '../schema.js';
6
+ export class LiteralSchema extends Schema {
7
+ value;
8
+ constructor(value) {
9
+ super();
10
+ this.value = value;
11
+ }
12
+ _test(value, path, options) {
13
+ if (value === this.value) {
14
+ return { valid: true, value };
15
+ }
16
+ return {
17
+ valid: false,
18
+ error: SchemaError.expectedButGot(isPrimitive(this.value) ? String(this.value) : typeOf(this.value), isPrimitive(value) ? String(value) : typeOf(value), path, { fast: options.fastErrors })
19
+ };
20
+ }
14
21
  }
15
- export function Literal(value) {
16
- return createSchemaPropertyDecoratorFromSchema(literal(value));
22
+ export function literal(value) {
23
+ return new LiteralSchema(value);
24
+ }
25
+ export function Literal(value, options) {
26
+ return Property(literal(value), options);
17
27
  }
@@ -0,0 +1,6 @@
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
3
+ export declare class NeverSchema extends Schema<never> {
4
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<never>;
5
+ }
6
+ export declare function never(): NeverSchema;
@@ -0,0 +1,11 @@
1
+ import { SchemaError } from '../../schema/schema.error.js';
2
+ import { typeOf } from '../../utils/type-of.js';
3
+ import { Schema } from '../schema.js';
4
+ export class NeverSchema extends Schema {
5
+ _test(value, path, options) {
6
+ return { valid: false, error: SchemaError.expectedButGot('never', typeOf(value), path, { fast: options.fastErrors }) };
7
+ }
8
+ }
9
+ export function never() {
10
+ return new NeverSchema();
11
+ }
@@ -1,6 +1,11 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { SchemaTestable } from '../schema.js';
3
- import type { ValueSchema, ValueSchemaOptions } from '../types/index.js';
4
- export type NullableOptions = ValueSchemaOptions;
5
- export declare function nullable<T>(schema: SchemaTestable<T>, options?: NullableOptions): ValueSchema<T | null>;
6
- export declare function Nullable(options?: NullableOptions): Decorator<'property' | 'accessor'>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import type { TypedOmit } from '../../types.js';
3
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
4
+ import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
+ export declare class NullableSchema<T> extends Schema<T | null> {
6
+ readonly schema: Schema<T>;
7
+ constructor(schema: SchemaTestable<T>);
8
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
9
+ }
10
+ export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
11
+ export declare function Nullable(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
@@ -1,9 +1,26 @@
1
- import { createSchemaPropertyDecorator } from '../decorators/utils.js';
2
- import { valueSchema } from '../types/index.js';
3
- export function nullable(schema, options) {
4
- return valueSchema(schema, { ...options, nullable: true });
1
+ import { isNull } from '../../utils/type-guards.js';
2
+ import { createSchemaPropertyDecorator } from '../decorators/index.js';
3
+ import { Schema } from '../schema.js';
4
+ import { schemaTestableToSchema } from '../testable.js';
5
+ export class NullableSchema extends Schema {
6
+ schema;
7
+ constructor(schema) {
8
+ if ((schema instanceof NullableSchema) && (schema == schema.schema)) {
9
+ return schema; // eslint-disable-line no-constructor-return
10
+ }
11
+ super();
12
+ this.schema = schemaTestableToSchema(schema);
13
+ }
14
+ _test(value, path, options) {
15
+ if (isNull(value)) {
16
+ return { valid: true, value };
17
+ }
18
+ return this.schema._test(value, path, options);
19
+ }
5
20
  }
6
- // eslint-disable-next-line @typescript-eslint/naming-convention
7
- export function Nullable(options) {
8
- return createSchemaPropertyDecorator({ ...options, nullable: true });
21
+ export function nullable(schema) {
22
+ return new NullableSchema(schema);
23
+ }
24
+ export function Nullable(schema, options) {
25
+ return createSchemaPropertyDecorator({ schema, ...options, nullable: true });
9
26
  }
@@ -1,9 +1,11 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
3
- export type NumberOptions = ValueSchemaOptions & {
4
- minimum?: number;
5
- maximum?: number;
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type NumberSchemaOptions = SimpleSchemaOptions & {
6
4
  integer?: boolean;
7
5
  };
8
- export declare function number(options?: NumberOptions): ValueSchema<number>;
9
- export declare function NumberProperty(options?: NumberOptions): Decorator<'property' | 'accessor'>;
6
+ export declare class NumberSchema extends SimpleSchema<number> {
7
+ constructor(options?: NumberSchemaOptions);
8
+ }
9
+ export declare function number(options?: NumberSchemaOptions): NumberSchema;
10
+ export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
11
+ export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
@@ -1,27 +1,32 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArrayCopy } from '../../utils/array/array.js';
3
- import { isDefined } from '../../utils/type-guards.js';
4
- import { integerConstraint } from '../constraints/integer.js';
5
- import { MaximumConstraint } from '../constraints/maximum.js';
6
- import { MinimumConstraint } from '../constraints/minimum.js';
7
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/utils.js';
8
- import { valueSchema } from '../types/types.js';
9
- export function number(options = {}) {
10
- const valueConstraints = toArrayCopy(options.valueConstraints ?? []);
11
- if (isDefined(options.minimum)) {
12
- valueConstraints.push(new MinimumConstraint(options.minimum));
1
+ import { isNumber } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SchemaError } from '../schema.error.js';
4
+ import { SimpleSchema } from './simple.js';
5
+ export class NumberSchema extends SimpleSchema {
6
+ constructor(options) {
7
+ super('number', isNumber, options, {
8
+ coercers: {
9
+ string: (value, path, options) => {
10
+ const result = globalThis.Number(value);
11
+ return globalThis.Number.isNaN(result)
12
+ ? { success: false, error: SchemaError.couldNotCoerce('number', 'string', path, { fast: options.fastErrors }) }
13
+ : { success: true, value: result, valid: true };
14
+ },
15
+ boolean: (value) => ({ success: true, value: globalThis.Number(value), valid: true }),
16
+ bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false })
17
+ },
18
+ constraints: [
19
+ (options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'value is not an integer.' }) : null
20
+ ]
21
+ });
13
22
  }
14
- if (isDefined(options.maximum)) {
15
- valueConstraints.push(new MaximumConstraint(options.maximum));
16
- }
17
- if (options.integer == true) {
18
- valueConstraints.push(integerConstraint);
19
- }
20
- return valueSchema(Number, {
21
- ...options,
22
- valueConstraints
23
- });
23
+ }
24
+ export function number(options) {
25
+ return new NumberSchema(options);
24
26
  }
25
27
  export function NumberProperty(options) {
26
- return createSchemaPropertyDecoratorFromSchema(number(options));
28
+ return Property(number(options), options);
29
+ }
30
+ export function Integer(options) {
31
+ return Property(number({ ...options, integer: true }), options);
27
32
  }