@tstdl/base 0.90.92 → 0.91.0-beta1

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 (251) hide show
  1. package/api/types.d.ts +1 -1
  2. package/authentication/authentication.api.d.ts +21 -22
  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 +3 -3
  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 +83 -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 +6 -4
  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 +3 -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 +10 -12
  48. package/schema/schemas/array.js +27 -19
  49. package/schema/schemas/bigint.d.ts +8 -0
  50. package/schema/schemas/bigint.js +19 -0
  51. package/schema/schemas/boolean.d.ts +15 -5
  52. package/schema/schemas/boolean.js +47 -6
  53. package/schema/schemas/date.d.ts +9 -7
  54. package/schema/schemas/date.js +25 -19
  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/index.d.ts +4 -6
  60. package/schema/schemas/index.js +4 -6
  61. package/schema/schemas/instance.d.ts +11 -3
  62. package/schema/schemas/instance.js +25 -4
  63. package/schema/schemas/literal.d.ts +10 -5
  64. package/schema/schemas/literal.js +25 -15
  65. package/schema/schemas/never.d.ts +6 -0
  66. package/schema/schemas/never.js +11 -0
  67. package/schema/schemas/nullable.d.ts +10 -6
  68. package/schema/schemas/nullable.js +24 -7
  69. package/schema/schemas/number.d.ts +13 -7
  70. package/schema/schemas/number.js +34 -23
  71. package/schema/schemas/object.d.ts +75 -7
  72. package/schema/schemas/object.js +171 -6
  73. package/schema/schemas/one-or-many.d.ts +10 -7
  74. package/schema/schemas/one-or-many.js +18 -11
  75. package/schema/schemas/optional.d.ts +10 -7
  76. package/schema/schemas/optional.js +21 -3
  77. package/schema/schemas/readable-stream.d.ts +8 -6
  78. package/schema/schemas/readable-stream.js +11 -6
  79. package/schema/schemas/regexp.d.ts +8 -6
  80. package/schema/schemas/regexp.js +25 -7
  81. package/schema/schemas/simple.d.ts +27 -0
  82. package/schema/schemas/simple.js +57 -0
  83. package/schema/schemas/string.d.ts +13 -21
  84. package/schema/schemas/string.js +26 -34
  85. package/schema/schemas/symbol.d.ts +12 -0
  86. package/schema/schemas/symbol.js +25 -0
  87. package/schema/schemas/transform.d.ts +9 -5
  88. package/schema/schemas/transform.js +19 -6
  89. package/schema/schemas/uint8-array.d.ts +9 -5
  90. package/schema/schemas/uint8-array.js +17 -26
  91. package/schema/schemas/union.d.ts +14 -7
  92. package/schema/schemas/union.js +30 -11
  93. package/schema/schemas/unknown.d.ts +7 -5
  94. package/schema/schemas/unknown.js +11 -7
  95. package/schema/testable.d.ts +3 -0
  96. package/schema/testable.js +30 -0
  97. package/schema/types.d.ts +31 -0
  98. package/schema/types.js +1 -0
  99. package/schema-old/decorators/class.d.ts +3 -0
  100. package/schema-old/decorators/class.js +5 -0
  101. package/schema-old/decorators/index.d.ts +6 -0
  102. package/schema-old/decorators/index.js +6 -0
  103. package/schema-old/decorators/property.d.ts +6 -0
  104. package/schema-old/decorators/property.js +17 -0
  105. package/schema-old/decorators/types.d.ts +19 -0
  106. package/schema-old/decorators/types.js +1 -0
  107. package/schema-old/decorators/utils.d.ts +15 -0
  108. package/schema-old/decorators/utils.js +48 -0
  109. package/schema-old/index.d.ts +10 -0
  110. package/schema-old/index.js +10 -0
  111. package/schema-old/schema.d.ts +15 -0
  112. package/schema-old/schema.error.d.ts +26 -0
  113. package/schema-old/schema.error.js +64 -0
  114. package/schema-old/schema.js +283 -0
  115. package/schema-old/schemas/any.d.ts +5 -0
  116. package/schema-old/schemas/any.js +9 -0
  117. package/schema-old/schemas/array.d.ts +12 -0
  118. package/schema-old/schemas/array.js +23 -0
  119. package/schema-old/schemas/boolean.d.ts +5 -0
  120. package/schema-old/schemas/boolean.js +9 -0
  121. package/schema-old/schemas/date.d.ts +8 -0
  122. package/schema-old/schemas/date.js +22 -0
  123. package/schema-old/schemas/defaulted.d.ts +6 -0
  124. package/schema-old/schemas/defaulted.js +10 -0
  125. package/schema-old/schemas/enumeration.d.ts +6 -0
  126. package/schema-old/schemas/enumeration.js +17 -0
  127. package/schema-old/schemas/index.d.ts +26 -0
  128. package/schema-old/schemas/index.js +26 -0
  129. package/schema-old/schemas/instance.d.ts +3 -0
  130. package/schema-old/schemas/instance.js +5 -0
  131. package/schema-old/schemas/literal.d.ts +5 -0
  132. package/schema-old/schemas/literal.js +17 -0
  133. package/schema-old/schemas/nullable.d.ts +6 -0
  134. package/schema-old/schemas/nullable.js +9 -0
  135. package/schema-old/schemas/number.d.ts +9 -0
  136. package/schema-old/schemas/number.js +27 -0
  137. package/schema-old/schemas/object.d.ts +7 -0
  138. package/schema-old/schemas/object.js +12 -0
  139. package/schema-old/schemas/one-or-many.d.ts +9 -0
  140. package/schema-old/schemas/one-or-many.js +15 -0
  141. package/schema-old/schemas/optional.d.ts +7 -0
  142. package/schema-old/schemas/optional.js +8 -0
  143. package/schema-old/schemas/readable-stream.d.ts +6 -0
  144. package/schema-old/schemas/readable-stream.js +9 -0
  145. package/schema-old/schemas/regexp.d.ts +6 -0
  146. package/schema-old/schemas/regexp.js +9 -0
  147. package/schema-old/schemas/string.d.ts +22 -0
  148. package/schema-old/schemas/string.js +38 -0
  149. package/schema-old/schemas/transform.d.ts +5 -0
  150. package/schema-old/schemas/transform.js +7 -0
  151. package/schema-old/schemas/uint8-array.d.ts +10 -0
  152. package/schema-old/schemas/uint8-array.js +29 -0
  153. package/schema-old/schemas/union.d.ts +7 -0
  154. package/schema-old/schemas/union.js +13 -0
  155. package/schema-old/schemas/unknown.d.ts +5 -0
  156. package/schema-old/schemas/unknown.js +9 -0
  157. package/templates/resolvers/string.template-resolver.d.ts +0 -1
  158. package/templates/resolvers/string.template-resolver.js +1 -5
  159. package/templates/template.model.js +1 -1
  160. package/types.d.ts +2 -0
  161. package/utils/type-guards.js +1 -1
  162. /package/{schema → schema-old}/array-constraints/index.d.ts +0 -0
  163. /package/{schema → schema-old}/array-constraints/index.js +0 -0
  164. /package/{schema → schema-old}/array-constraints/maximum-length.d.ts +0 -0
  165. /package/{schema → schema-old}/array-constraints/maximum-length.js +0 -0
  166. /package/{schema → schema-old}/array-constraints/minimum-length.d.ts +0 -0
  167. /package/{schema → schema-old}/array-constraints/minimum-length.js +0 -0
  168. /package/{schema → schema-old}/coercers/boolean.coercer.d.ts +0 -0
  169. /package/{schema → schema-old}/coercers/boolean.coercer.js +0 -0
  170. /package/{schema → schema-old}/coercers/date.coercer.d.ts +0 -0
  171. /package/{schema → schema-old}/coercers/date.coercer.js +0 -0
  172. /package/{schema → schema-old}/coercers/index.d.ts +0 -0
  173. /package/{schema → schema-old}/coercers/index.js +0 -0
  174. /package/{schema → schema-old}/coercers/number.coercer.d.ts +0 -0
  175. /package/{schema → schema-old}/coercers/number.coercer.js +0 -0
  176. /package/{schema → schema-old}/coercers/regexp.coercer.d.ts +0 -0
  177. /package/{schema → schema-old}/coercers/regexp.coercer.js +0 -0
  178. /package/{schema → schema-old}/coercers/string.coercer.d.ts +0 -0
  179. /package/{schema → schema-old}/coercers/string.coercer.js +0 -0
  180. /package/{schema → schema-old}/coercers/uint8-array.coercer.d.ts +0 -0
  181. /package/{schema → schema-old}/coercers/uint8-array.coercer.js +0 -0
  182. /package/{schema → schema-old}/constraints/enumeration.d.ts +0 -0
  183. /package/{schema → schema-old}/constraints/enumeration.js +0 -0
  184. /package/{schema → schema-old}/constraints/generic.d.ts +0 -0
  185. /package/{schema → schema-old}/constraints/generic.js +0 -0
  186. /package/{schema → schema-old}/constraints/index.d.ts +0 -0
  187. /package/{schema → schema-old}/constraints/index.js +0 -0
  188. /package/{schema → schema-old}/constraints/integer.d.ts +0 -0
  189. /package/{schema → schema-old}/constraints/integer.js +0 -0
  190. /package/{schema → schema-old}/constraints/length.d.ts +0 -0
  191. /package/{schema → schema-old}/constraints/length.js +0 -0
  192. /package/{schema → schema-old}/constraints/literal.d.ts +0 -0
  193. /package/{schema → schema-old}/constraints/literal.js +0 -0
  194. /package/{schema → schema-old}/constraints/maximum-date.d.ts +0 -0
  195. /package/{schema → schema-old}/constraints/maximum-date.js +0 -0
  196. /package/{schema → schema-old}/constraints/maximum-length.d.ts +0 -0
  197. /package/{schema → schema-old}/constraints/maximum-length.js +0 -0
  198. /package/{schema → schema-old}/constraints/maximum.d.ts +0 -0
  199. /package/{schema → schema-old}/constraints/maximum.js +0 -0
  200. /package/{schema → schema-old}/constraints/minimum-date.d.ts +0 -0
  201. /package/{schema → schema-old}/constraints/minimum-date.js +0 -0
  202. /package/{schema → schema-old}/constraints/minimum-length.d.ts +0 -0
  203. /package/{schema → schema-old}/constraints/minimum-length.js +0 -0
  204. /package/{schema → schema-old}/constraints/minimum.d.ts +0 -0
  205. /package/{schema → schema-old}/constraints/minimum.js +0 -0
  206. /package/{schema → schema-old}/constraints/pattern.d.ts +0 -0
  207. /package/{schema → schema-old}/constraints/pattern.js +0 -0
  208. /package/{schema → schema-old}/decorators/coerce.d.ts +0 -0
  209. /package/{schema → schema-old}/decorators/coerce.js +0 -0
  210. /package/{schema → schema-old}/decorators/constraint.d.ts +0 -0
  211. /package/{schema → schema-old}/decorators/constraint.js +0 -0
  212. /package/{schema → schema-old}/schemas/assign.d.ts +0 -0
  213. /package/{schema → schema-old}/schemas/assign.js +0 -0
  214. /package/{schema → schema-old}/schemas/constraint.d.ts +0 -0
  215. /package/{schema → schema-old}/schemas/constraint.js +0 -0
  216. /package/{schema → schema-old}/schemas/omit.d.ts +0 -0
  217. /package/{schema → schema-old}/schemas/omit.js +0 -0
  218. /package/{schema → schema-old}/schemas/partial.d.ts +0 -0
  219. /package/{schema → schema-old}/schemas/partial.js +0 -0
  220. /package/{schema → schema-old}/schemas/pick.d.ts +0 -0
  221. /package/{schema → schema-old}/schemas/pick.js +0 -0
  222. /package/{schema → schema-old}/schemas/record.d.ts +0 -0
  223. /package/{schema → schema-old}/schemas/record.js +0 -0
  224. /package/{schema → schema-old}/transformers/generic.d.ts +0 -0
  225. /package/{schema → schema-old}/transformers/generic.js +0 -0
  226. /package/{schema → schema-old}/transformers/index.d.ts +0 -0
  227. /package/{schema → schema-old}/transformers/index.js +0 -0
  228. /package/{schema → schema-old}/transformers/lowercase.d.ts +0 -0
  229. /package/{schema → schema-old}/transformers/lowercase.js +0 -0
  230. /package/{schema → schema-old}/transformers/trim.d.ts +0 -0
  231. /package/{schema → schema-old}/transformers/trim.js +0 -0
  232. /package/{schema → schema-old}/transformers/uppercase.d.ts +0 -0
  233. /package/{schema → schema-old}/transformers/uppercase.js +0 -0
  234. /package/{schema → schema-old}/types/index.d.ts +0 -0
  235. /package/{schema → schema-old}/types/index.js +0 -0
  236. /package/{schema → schema-old}/types/schema-array-constraint.d.ts +0 -0
  237. /package/{schema → schema-old}/types/schema-array-constraint.js +0 -0
  238. /package/{schema → schema-old}/types/schema-value-coercer.d.ts +0 -0
  239. /package/{schema → schema-old}/types/schema-value-coercer.js +0 -0
  240. /package/{schema → schema-old}/types/schema-value-constraint.d.ts +0 -0
  241. /package/{schema → schema-old}/types/schema-value-constraint.js +0 -0
  242. /package/{schema → schema-old}/types/schema-value-transformer.d.ts +0 -0
  243. /package/{schema → schema-old}/types/schema-value-transformer.js +0 -0
  244. /package/{schema → schema-old}/types/types.d.ts +0 -0
  245. /package/{schema → schema-old}/types/types.js +0 -0
  246. /package/{schema → schema-old}/utils/index.d.ts +0 -0
  247. /package/{schema → schema-old}/utils/index.js +0 -0
  248. /package/{schema → schema-old}/utils/schema.d.ts +0 -0
  249. /package/{schema → schema-old}/utils/schema.js +0 -0
  250. /package/{schema → schema-old}/utils/value-type.d.ts +0 -0
  251. /package/{schema → schema-old}/utils/value-type.js +0 -0
@@ -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
  }
@@ -1,25 +1,23 @@
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';
9
8
  export * from './instance.js';
10
9
  export * from './literal.js';
10
+ export * from './never.js';
11
11
  export * from './nullable.js';
12
12
  export * from './number.js';
13
13
  export * from './object.js';
14
- export * from './omit.js';
15
14
  export * from './one-or-many.js';
16
15
  export * from './optional.js';
17
- export * from './partial.js';
18
- export * from './pick.js';
19
16
  export * from './readable-stream.js';
20
- export * from './record.js';
21
17
  export * from './regexp.js';
18
+ export * from './simple.js';
22
19
  export * from './string.js';
20
+ export * from './symbol.js';
23
21
  export * from './transform.js';
24
22
  export * from './uint8-array.js';
25
23
  export * from './union.js';
@@ -1,25 +1,23 @@
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';
9
8
  export * from './instance.js';
10
9
  export * from './literal.js';
10
+ export * from './never.js';
11
11
  export * from './nullable.js';
12
12
  export * from './number.js';
13
13
  export * from './object.js';
14
- export * from './omit.js';
15
14
  export * from './one-or-many.js';
16
15
  export * from './optional.js';
17
- export * from './partial.js';
18
- export * from './pick.js';
19
16
  export * from './readable-stream.js';
20
- export * from './record.js';
21
17
  export * from './regexp.js';
18
+ export * from './simple.js';
22
19
  export * from './string.js';
20
+ export * from './symbol.js';
23
21
  export * from './transform.js';
24
22
  export * from './uint8-array.js';
25
23
  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,10 @@
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 SchemaPropertyDecorator } from '../decorators/index.js';
3
+ import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
+ export declare class NullableSchema<T> extends Schema<T | null> {
5
+ readonly schema: Schema<T>;
6
+ constructor(schema: SchemaTestable<T>);
7
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
8
+ }
9
+ export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
10
+ export declare function 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() {
25
+ return createSchemaPropertyDecorator({ nullable: true });
9
26
  }
@@ -1,9 +1,15 @@
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 Number(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
11
+ export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
12
+ /**
13
+ * @deprecated use {@link Number()} instead
14
+ */
15
+ export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
@@ -1,27 +1,38 @@
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
- });
24
23
  }
24
+ export function number(options) {
25
+ return new NumberSchema(options);
26
+ }
27
+ export function Number(options) {
28
+ return Property(number(options), options);
29
+ }
30
+ export function Integer(options) {
31
+ return Property(number({ ...options, integer: true }), options);
32
+ }
33
+ /**
34
+ * @deprecated use {@link Number()} instead
35
+ */
25
36
  export function NumberProperty(options) {
26
- return createSchemaPropertyDecoratorFromSchema(number(options));
37
+ return Number(options);
27
38
  }
@@ -1,7 +1,75 @@
1
- import type { ObjectLiteral, Optionalize, Record, SimplifyObject, TypedOmit } from '../../types.js';
2
- import type { IfNever } from 'type-fest';
3
- import { type ObjectSchema, type ObjectSchemaProperties, type TypedObjectSchemaUnknownProperties } from '../types/index.js';
4
- export type ObjectOptions<T extends Record = Record> = TypedOmit<ObjectSchema<T>, 'properties' | 'unknownProperties' | 'unknownPropertiesKey'>;
5
- export declare function explicitObject<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T>): ObjectSchema<T>;
6
- export declare function object<T extends Record = Record<never>, K extends PropertyKey = any, V = never>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T> & TypedObjectSchemaUnknownProperties<K, V>): ObjectSchema<SimplifyObject<Optionalize<T> & IfNever<V, ObjectLiteral, Record<K, V>>>>;
7
- export declare const emptyObjectSchema: ObjectSchema<ObjectLiteral>;
1
+ import type { EmptyObject, Merge } from 'type-fest';
2
+ import type { JsonPath } from '../../json-path/json-path.js';
3
+ import type { AbstractConstructor, OneOrMany, PartialProperty, Record, SimplifyObject, Type, TypedOmit } from '../../types.js';
4
+ import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
+ export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
6
+ export type ObjectSchemaFactory<T> = {
7
+ type: Type<T>;
8
+ } | ObjectSchemaFactoryFunction<T>;
9
+ export type ObjectSchemaProperties<T extends Record = Record> = {
10
+ [P in keyof T]-?: SchemaTestable<T[P]>;
11
+ };
12
+ export type NormalizedObjectSchemaProperties<T extends Record> = {
13
+ [P in keyof T]-?: Schema<T[P]>;
14
+ };
15
+ export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey = PropertyKey, V = unknown> = {
16
+ mask?: boolean | null;
17
+ unknownProperties?: SchemaTestable<V> | null;
18
+ unknownPropertiesKey?: SchemaTestable<K> | null;
19
+ factory?: ObjectSchemaFactory<T> | null;
20
+ };
21
+ export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
22
+ export declare const tryGetSchemaFromReflection: typeof _tryGetSchemaFromReflection;
23
+ export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
24
+ private readonly propertyKeys;
25
+ private readonly allowUnknownProperties;
26
+ readonly properties: NormalizedObjectSchemaProperties<T>;
27
+ readonly mask: boolean | null;
28
+ readonly unknownProperties: Schema | null;
29
+ readonly unknownPropertiesKey: Schema<PropertyKey> | null;
30
+ readonly factory: ObjectSchemaFactory<T> | null;
31
+ constructor(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>);
32
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
33
+ }
34
+ export declare function object<K extends PropertyKey, V>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, V>> & {
35
+ unknownProperties: SchemaTestable<V>;
36
+ unknownPropertiesKey: SchemaTestable<K>;
37
+ }): ObjectSchema<Record<K, V>>;
38
+ export declare function object<K extends PropertyKey>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, unknown>> & {
39
+ unknownProperties?: undefined;
40
+ unknownPropertiesKey: SchemaTestable<K>;
41
+ }): ObjectSchema<Record<K, unknown>>;
42
+ export declare function object<V>(properties: Record<never>, options: ObjectSchemaOptions<Record<PropertyKey, V>> & {
43
+ unknownProperties: SchemaTestable<V>;
44
+ unknownPropertiesKey?: undefined;
45
+ }): ObjectSchema<Record<PropertyKey, V>>;
46
+ export declare function object<T extends Record, K extends PropertyKey, V>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<K, V>> & {
47
+ unknownProperties: SchemaTestable<V>;
48
+ unknownPropertiesKey: SchemaTestable<K>;
49
+ }): ObjectSchema<SimplifyObject<T & Record<K, V>>>;
50
+ export declare function object<T extends Record, K extends PropertyKey>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<K, unknown>> & {
51
+ unknownPropertiesKey: SchemaTestable<K>;
52
+ }): ObjectSchema<SimplifyObject<T & Record<K, unknown>>>;
53
+ export declare function object<T extends Record, V>(properties: ObjectSchemaProperties<T>, options: ObjectSchemaOptions<T & Record<PropertyKey, V>> & {
54
+ unknownProperties: SchemaTestable<V>;
55
+ }): ObjectSchema<SimplifyObject<T & Record<PropertyKey, V>>>;
56
+ export declare function object<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T> & {
57
+ unknownProperties?: undefined;
58
+ unknownPropertiesKey?: undefined;
59
+ }): ObjectSchema<T>;
60
+ export declare function object<T extends Record, K extends PropertyKey, V>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T, K, V>): ObjectSchema<SimplifyObject<T & Record<K, V>>>;
61
+ export declare function explicitObject<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>): ObjectSchema<T>;
62
+ export declare function record<K extends PropertyKey, V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
63
+ export declare function assign<T1 extends Record, T2 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>): ObjectSchema<Merge<T1, T2>>;
64
+ export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>): ObjectSchema<Merge<Merge<T1, T2>, T3>>;
65
+ export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>>;
66
+ export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>): ObjectSchema<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>>;
67
+ export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record, T6 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>, f: ObjectSchemaOrType<T6>): ObjectSchema<Merge<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>, T6>>;
68
+ export declare function partial<T extends Record>(schema: ObjectSchema<T>): ObjectSchema<Partial<T>>;
69
+ export declare function partial<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<PartialProperty<T, K>>;
70
+ export declare function pick<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
71
+ export declare function omit<T extends Record, K extends keyof T>(schema: ObjectSchema<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
72
+ export declare function getSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T>;
73
+ declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | null;
74
+ export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
75
+ export {};