@tstdl/base 0.90.92 → 0.91.0-beta2

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 +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 +27 -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 +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 +11 -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 +11 -7
  76. package/schema/schemas/optional.js +24 -6
  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,12 +1,177 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { objectSchema } from '../types/index.js';
1
+ /* eslint-disable max-depth */
2
+ import { reflectionRegistry } from '../../reflection/index.js';
3
+ import { SchemaError } from '../../schema/schema.error.js';
4
+ import { toArray } from '../../utils/array/array.js';
5
+ import { memoizeSingle } from '../../utils/function/memoize.js';
6
+ import { filterObject, mapObjectValues, objectKeys } from '../../utils/object/object.js';
7
+ import { assert, isDefined, isFunction, isLiteralObject, isNotNull, isNotNullOrUndefined, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
8
+ import { typeOf } from '../../utils/type-of.js';
9
+ import { Schema } from '../schema.js';
10
+ import { schemaTestableToSchema } from '../testable.js';
11
+ import { array } from './array.js';
12
+ import { nullable } from './nullable.js';
13
+ import { optional } from './optional.js';
14
+ export const tryGetSchemaFromReflection = memoizeSingle(_tryGetSchemaFromReflection, { weak: true });
15
+ export class ObjectSchema extends Schema {
16
+ propertyKeys;
17
+ allowUnknownProperties;
18
+ properties;
19
+ mask;
20
+ unknownProperties;
21
+ unknownPropertiesKey;
22
+ factory;
23
+ constructor(properties, options = {}) {
24
+ super();
25
+ this.properties = mapObjectValues(properties, (value) => schemaTestableToSchema(value));
26
+ this.mask = options.mask ?? null;
27
+ this.unknownProperties = isNotNullOrUndefined(options.unknownProperties) ? schemaTestableToSchema(options.unknownProperties) : null;
28
+ this.unknownPropertiesKey = isNotNullOrUndefined(options.unknownPropertiesKey) ? schemaTestableToSchema(options.unknownPropertiesKey) : null;
29
+ this.factory = options.factory ?? null;
30
+ this.allowUnknownProperties = isNotNull(this.unknownProperties) || isNotNull(this.unknownPropertiesKey);
31
+ this.propertyKeys = new Set(objectKeys(properties));
32
+ }
33
+ _test(value, path, options) {
34
+ if (!isObject(value)) {
35
+ return { valid: false, error: SchemaError.expectedButGot('object', typeOf(value), path) };
36
+ }
37
+ const mask = this.mask ?? options.mask ?? false;
38
+ const resultValue = isLiteralObject(this.factory) ? new this.factory.type() : {};
39
+ const valueKeys = new Set(objectKeys(value));
40
+ const unknownValuePropertyKeys = valueKeys.difference(this.propertyKeys);
41
+ if ((unknownValuePropertyKeys.size > 0) && !mask && !this.allowUnknownProperties) {
42
+ return { valid: false, error: new SchemaError('Unexpected property', { path: path.add(unknownValuePropertyKeys.values().next().value), fast: options.fastErrors }) };
43
+ }
44
+ for (const key of this.propertyKeys) {
45
+ const propertyResult = this.properties[key]._test(value[key], path.add(key), options);
46
+ if (!propertyResult.valid) {
47
+ return propertyResult;
48
+ }
49
+ resultValue[key] = propertyResult.value;
50
+ }
51
+ if (this.allowUnknownProperties) {
52
+ for (const key of unknownValuePropertyKeys) {
53
+ const propertyPath = path.add(key);
54
+ const keyResult = this.unknownPropertiesKey?._test(key, propertyPath, options) ?? { valid: true };
55
+ if (!keyResult.valid) {
56
+ if (mask) {
57
+ continue;
58
+ }
59
+ return { valid: false, error: new SchemaError('Invalid property key.', { path: propertyPath, inner: keyResult.error, fast: options.fastErrors }) };
60
+ }
61
+ const innerValueResult = this.unknownProperties?._test(value[key], propertyPath, options) ?? { valid: true, value: value[key] };
62
+ if (!innerValueResult.valid) {
63
+ return innerValueResult;
64
+ }
65
+ resultValue[key] = innerValueResult.value;
66
+ }
67
+ }
68
+ const testResultValue = isFunction(this.factory) ? this.factory(resultValue) : resultValue;
69
+ return { valid: true, value: testResultValue };
70
+ }
71
+ }
72
+ export function object(properties, options) {
73
+ return new ObjectSchema(properties, options);
74
+ }
3
75
  export function explicitObject(properties, options) {
4
76
  return object(properties, options);
5
77
  }
6
- export function object(properties, options) {
7
- return objectSchema({
8
- properties,
9
- ...options
78
+ export function record(key, value, options) {
79
+ return object({}, { ...options, unknownPropertiesKey: key, unknownProperties: value });
80
+ }
81
+ export function assign(...schemasOrTypes) {
82
+ const schemas = schemasOrTypes.map((schemaOrType) => {
83
+ if (schemaOrType instanceof ObjectSchema) {
84
+ return schemaOrType;
85
+ }
86
+ const typeSchema = getSchemaFromReflection(schemaOrType);
87
+ assert(typeSchema instanceof ObjectSchema, 'assign() only works with object schemas.');
88
+ return typeSchema;
89
+ });
90
+ return object(schemas.reduce((result, schema) => ({ ...result, ...schema.properties }), {}), {
91
+ mask: schemas.findLast((schema) => isNotNull(schema.mask))?.mask,
92
+ unknownProperties: schemas.findLast((schema) => isNotNull(schema.unknownProperties))?.unknownProperties,
93
+ unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey
94
+ });
95
+ }
96
+ export function partial(schema, keyOrKeys) {
97
+ const keys = isUndefined(keyOrKeys) ? undefined : toArray(keyOrKeys);
98
+ const mapper = isUndefined(keys)
99
+ ? (propertySchema) => optional(propertySchema)
100
+ : (propertySchema, key) => keys.includes(key) ? optional(propertySchema) : propertySchema;
101
+ return object(mapObjectValues(schema.properties, mapper), {
102
+ mask: schema.mask,
103
+ unknownProperties: schema.unknownProperties,
104
+ unknownPropertiesKey: schema.unknownPropertiesKey
10
105
  });
11
106
  }
107
+ export function pick(schema, keys) {
108
+ const keyArray = toArray(keys);
109
+ return object(filterObject(schema.properties, (_, key) => keyArray.includes(key)), {
110
+ mask: schema.mask,
111
+ unknownProperties: schema.unknownProperties,
112
+ unknownPropertiesKey: schema.unknownPropertiesKey
113
+ });
114
+ }
115
+ export function omit(schema, keys) {
116
+ const keysArray = toArray(keys);
117
+ return object(filterObject(schema.properties, (_, key) => !keysArray.includes(key)), {
118
+ mask: schema.mask,
119
+ unknownProperties: schema.unknownProperties,
120
+ unknownPropertiesKey: schema.unknownPropertiesKey
121
+ });
122
+ }
123
+ export function getSchemaFromReflection(type) {
124
+ const schema = tryGetSchemaFromReflection(type);
125
+ if (isNull(schema)) {
126
+ throw new Error(`Could not get schema for ${type.name} from reflection data.`);
127
+ }
128
+ return schema;
129
+ }
130
+ function _tryGetSchemaFromReflection(type) {
131
+ const metadata = reflectionRegistry.getMetadata(type);
132
+ if (isUndefined(metadata)) {
133
+ return null;
134
+ }
135
+ const typeData = metadata.data.tryGet('schema') ?? {};
136
+ if (typeData.schema instanceof Schema) {
137
+ return typeData.schema;
138
+ }
139
+ if (isFunction(typeData.schema)) {
140
+ return schemaTestableToSchema(typeData.schema);
141
+ }
142
+ const schema = object(getObjectSchemaPropertiesFromReflection(metadata, type), {
143
+ factory: isDefined(typeData.factory) ? typeData.factory : { type: type },
144
+ mask: typeData.mask,
145
+ unknownProperties: typeData.unknownProperties,
146
+ unknownPropertiesKey: typeData.unknownPropertiesKey
147
+ });
148
+ const prototype = Reflect.getPrototypeOf(type);
149
+ if (isNotNull(prototype) && reflectionRegistry.hasType(prototype)) {
150
+ const parentSchema = getSchemaFromReflection(prototype);
151
+ assert(parentSchema instanceof ObjectSchema, 'Can not infer an ObjectSchema from reflection when parent class has an explicit non-object schema defined.');
152
+ return assign(parentSchema, schema);
153
+ }
154
+ return schema;
155
+ }
156
+ function getObjectSchemaPropertiesFromReflection(metadata, type) {
157
+ const properties = {};
158
+ for (const [key, propertyMetadata] of metadata.properties) {
159
+ const reflectionData = propertyMetadata.data.tryGet('schema');
160
+ if (isUndefined(reflectionData?.schema) && (propertyMetadata.type == Object)) {
161
+ throw new Error(`Schema of property "${String(key)}" on type ${type.name} is inferred as Object. This is most likely unwanted and happens when the property is defined as partial or the type is an union. Use an explicit @Property(Object) if wanted.`);
162
+ }
163
+ let propertySchema = reflectionData?.schema ?? propertyMetadata.type;
164
+ if (reflectionData?.array == true) {
165
+ propertySchema = array(propertySchema);
166
+ }
167
+ if (reflectionData?.nullable == true) {
168
+ propertySchema = nullable(propertySchema);
169
+ }
170
+ if (reflectionData?.optional == true) {
171
+ propertySchema = optional(propertySchema);
172
+ }
173
+ properties[key] = propertySchema;
174
+ }
175
+ return properties;
176
+ }
12
177
  export const emptyObjectSchema = explicitObject({});
@@ -1,9 +1,12 @@
1
- import type { Decorator } from '../../reflection/index.js';
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { OneOrMany as OneOrManyType } from '../../types.js';
3
- import type { SchemaTestable } from '../schema.js';
4
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
5
- import type { ArrayOptions } from './array.js';
3
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
4
+ import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
6
5
  export type OneOrMany<T> = OneOrManyType<T>;
7
- export type OneOrManyOptions = ValueSchemaOptions & Pick<ArrayOptions, 'minimumLength' | 'maximumLength'>;
8
- export declare function oneOrMany<T>(innerValues: OneOrMany<SchemaTestable<T>>, options?: OneOrManyOptions): ValueSchema<T | T[]>;
9
- export declare function OneOrMany(innerValues: OneOrMany<SchemaTestable>, options?: OneOrManyOptions): Decorator<'property' | 'accessor'>;
6
+ export declare class OneOrManySchema<T> extends Schema<T | T[]> {
7
+ readonly schema: Schema<T | T[]>;
8
+ constructor(schema: SchemaTestable<T>);
9
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | T[]>;
10
+ }
11
+ export declare function oneOrMany<T>(schema: SchemaTestable<T>): OneOrManySchema<T>;
12
+ export declare function OneOrMany(schema: SchemaTestable, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,15 +1,22 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { toArray } from '../../utils/array/array.js';
3
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/utils.js';
1
+ import { Property } from '../decorators/index.js';
2
+ import { Schema } from '../schema.js';
3
+ import { schemaTestableToSchema } from '../testable.js';
4
4
  import { array } from './array.js';
5
5
  import { union } from './union.js';
6
- export function oneOrMany(innerValues, options) {
7
- return union([
8
- array(innerValues, { minimumLength: options?.minimumLength, maximumLength: options?.maximumLength }),
9
- ...toArray(innerValues)
10
- ], options);
6
+ export class OneOrManySchema extends Schema {
7
+ schema;
8
+ constructor(schema) {
9
+ super();
10
+ const oneSchema = schemaTestableToSchema(schema);
11
+ this.schema = union(oneSchema, array(oneSchema));
12
+ }
13
+ _test(value, path, options) {
14
+ return this.schema._test(value, path, options);
15
+ }
11
16
  }
12
- // eslint-disable-next-line @typescript-eslint/no-redeclare
13
- export function OneOrMany(innerValues, options) {
14
- return createSchemaPropertyDecoratorFromSchema(oneOrMany(innerValues, options));
17
+ export function oneOrMany(schema) {
18
+ return new OneOrManySchema(schema);
19
+ }
20
+ export function OneOrMany(schema, options) {
21
+ return Property(oneOrMany(schema), options);
15
22
  }
@@ -1,7 +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, ValueSchemaOptions } from '../types/types.js';
5
- export type OptionalOptions = ValueSchemaOptions;
6
- export declare function optional<T>(schema: OneOrMany<SchemaTestable<T>>, options?: OptionalOptions): ValueSchema<T | undefined>;
7
- export declare function Optional(schema?: OneOrMany<SchemaTestable>): Decorator<'property' | 'accessor'>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import { 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 OptionalSchema<T> extends Schema<T | undefined> {
6
+ readonly schema: Schema<T>;
7
+ constructor(schema: SchemaTestable<T>);
8
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
9
+ }
10
+ export declare function optional<T>(schema: SchemaTestable<T>): OptionalSchema<T>;
11
+ export declare function Optional(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
@@ -1,8 +1,26 @@
1
- import { createSchemaPropertyDecorator } from '../decorators/utils.js';
2
- import { valueSchema } from '../types/index.js';
3
- export function optional(schema, options) {
4
- return valueSchema(schema, { ...options, optional: true });
1
+ import { isUndefined } 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 OptionalSchema extends Schema {
6
+ schema;
7
+ constructor(schema) {
8
+ if ((schema instanceof OptionalSchema) && (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 (isUndefined(value)) {
16
+ return { valid: true, value: undefined };
17
+ }
18
+ return this.schema._test(value, path, options);
19
+ }
5
20
  }
6
- export function Optional(schema) {
7
- return createSchemaPropertyDecorator({ schema, optional: true });
21
+ export function optional(schema) {
22
+ return new OptionalSchema(schema);
23
+ }
24
+ export function Optional(schema, options) {
25
+ return createSchemaPropertyDecorator({ schema, ...options, optional: true });
8
26
  }
@@ -1,6 +1,8 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { Schema } from '../schema.js';
3
- import type { ValueSchemaOptions } from '../types/types.js';
4
- export type ReadableStreamOptions = ValueSchemaOptions;
5
- export declare function readableStream(options?: ReadableStreamOptions): Schema<ReadableStream>;
6
- export declare function ReadableStreamProperty(options?: ReadableStreamOptions): Decorator<'property' | 'accessor'>;
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type ReadableStreamSchemaOptions = SimpleSchemaOptions;
4
+ export declare class ReadableStreamSchema extends SimpleSchema<ReadableStream> {
5
+ constructor(options?: ReadableStreamSchemaOptions);
6
+ }
7
+ export declare function readableStream(options?: ReadableStreamSchemaOptions): ReadableStreamSchema;
8
+ export declare function ReadableStream(options?: SchemaPropertyDecoratorOptions & ReadableStreamSchemaOptions): SchemaPropertyDecorator;
@@ -1,9 +1,14 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/index.js';
3
- import { valueSchema } from '../types/index.js';
1
+ import { isReadableStream } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SimpleSchema } from './simple.js';
4
+ export class ReadableStreamSchema extends SimpleSchema {
5
+ constructor(options) {
6
+ super('ReadableStream', isReadableStream, options);
7
+ }
8
+ }
4
9
  export function readableStream(options) {
5
- return valueSchema(ReadableStream, options);
10
+ return new ReadableStreamSchema(options);
6
11
  }
7
- export function ReadableStreamProperty(options) {
8
- return createSchemaPropertyDecoratorFromSchema(readableStream(options));
12
+ export function ReadableStream(options) {
13
+ return Property(readableStream(options), options);
9
14
  }
@@ -1,6 +1,8 @@
1
- import type { Decorator } from '../../reflection/index.js';
2
- import type { Schema } from '../schema.js';
3
- import type { ValueSchemaOptions } from '../types/types.js';
4
- export type RegExpSchemaOptions = ValueSchemaOptions;
5
- export declare function regexp(options?: RegExpSchemaOptions): Schema<RegExp>;
6
- export declare function RegExpProperty(options?: RegExpSchemaOptions): Decorator<'property' | 'accessor'>;
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type RegExpSchemaOptions = SimpleSchemaOptions;
4
+ export declare class RegExpSchema extends SimpleSchema<RegExp> {
5
+ constructor(options?: RegExpSchemaOptions);
6
+ }
7
+ export declare function regExp(options?: RegExpSchemaOptions): RegExpSchema;
8
+ export declare function RegExp(options?: SchemaPropertyDecoratorOptions & RegExpSchemaOptions): SchemaPropertyDecorator;
@@ -1,9 +1,27 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/index.js';
3
- import { valueSchema } from '../types/index.js';
4
- export function regexp(options) {
5
- return valueSchema(RegExp, options);
1
+ import { isRegExp } 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 RegExpSchema extends SimpleSchema {
6
+ constructor(options) {
7
+ super('RegExp', isRegExp, options, {
8
+ coercers: {
9
+ string: (value, path, options) => {
10
+ try {
11
+ const regex = globalThis.RegExp(value, 'u');
12
+ return ({ success: true, value: regex, valid: true });
13
+ }
14
+ catch (error) {
15
+ return { success: false, error: SchemaError.couldNotCoerce(globalThis.RegExp, 'string', path, { fast: options.fastErrors, customMessage: error.message }) };
16
+ }
17
+ }
18
+ }
19
+ });
20
+ }
6
21
  }
7
- export function RegExpProperty(options) {
8
- return createSchemaPropertyDecoratorFromSchema(regexp(options));
22
+ export function regExp(options) {
23
+ return new RegExpSchema(options);
24
+ }
25
+ export function RegExp(options) {
26
+ return Property(regExp(options), options);
9
27
  }
@@ -0,0 +1,27 @@
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import type { AbstractConstructor, OneOrMany } from '../../types.js';
3
+ import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
+ import type { CoerceResult, Coercible, ConstraintResult } from '../types.js';
5
+ export type SimpleSchemaOptions = Coercible;
6
+ type SimpleSchemaRefinements<T> = {
7
+ coercers?: SimpleSchemaCoercers<T>;
8
+ constraints?: (SimpleSchemaConstraint<T> | null)[];
9
+ gotValueFormatter?: SimpleSchemaGotValueFormatter;
10
+ };
11
+ export type SimpleSchemaCoercers<T> = {
12
+ string?: (value: string, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
13
+ number?: (value: number, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
14
+ boolean?: (value: boolean, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
15
+ bigint?: (value: bigint, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
16
+ undefined?: (value: undefined, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
17
+ null?: (value: null, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
18
+ all?: (value: unknown, path: JsonPath, options: SchemaTestOptions) => CoerceResult<T>;
19
+ };
20
+ export type SimpleSchemaConstraint<T> = (value: T) => ConstraintResult;
21
+ export type SimpleSchemaGotValueFormatter = (value: unknown) => string;
22
+ export declare abstract class SimpleSchema<T> extends Schema<T> {
23
+ #private;
24
+ constructor(expected: OneOrMany<string | AbstractConstructor>, guardFn: (value: any) => value is T, options?: SimpleSchemaOptions, refinements?: SimpleSchemaRefinements<T>);
25
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
26
+ }
27
+ export {};
@@ -0,0 +1,57 @@
1
+ import { isDefined, isError, isNotNull, isNull, isUndefined } from '../../utils/type-guards.js';
2
+ import { typeOf } from '../../utils/type-of.js';
3
+ import { SchemaError } from '../schema.error.js';
4
+ import { Schema } from '../schema.js';
5
+ export class SimpleSchema extends Schema {
6
+ #guardFn;
7
+ #expected;
8
+ #options;
9
+ #coercers;
10
+ #constraints;
11
+ #gotValueFormatter;
12
+ constructor(expected, guardFn, options = {}, refinements = {}) {
13
+ super();
14
+ this.#expected = expected;
15
+ this.#guardFn = guardFn;
16
+ this.#options = options;
17
+ this.#coercers = refinements.coercers ?? {};
18
+ this.#constraints = refinements.constraints?.filter(isNotNull) ?? [];
19
+ this.#gotValueFormatter = refinements.gotValueFormatter ?? typeOf;
20
+ }
21
+ _test(value, path, options) {
22
+ let result;
23
+ if (this.#guardFn(value)) {
24
+ result = { valid: true, value };
25
+ }
26
+ else if ((this.#options.coerce ?? options.coerce) == true) {
27
+ const type = typeof value;
28
+ const coerceType = isNull(value) ? 'null' : type;
29
+ const coerceFn = (this.#coercers[coerceType] ?? this.#coercers.all);
30
+ if (isDefined(coerceFn)) {
31
+ const coerceResult = coerceFn(value, path, options);
32
+ if (coerceResult.success) {
33
+ if (!coerceResult.valid) {
34
+ return this._test(coerceResult.value, path, options);
35
+ }
36
+ result = { valid: true, value: coerceResult.value };
37
+ }
38
+ else if (isDefined(coerceResult.error)) {
39
+ result = { valid: false, error: coerceResult.error };
40
+ }
41
+ }
42
+ }
43
+ if (isUndefined(result)) {
44
+ return { valid: false, error: SchemaError.expectedButGot(this.#expected, this.#gotValueFormatter(value), path, { fast: options.fastErrors }) };
45
+ }
46
+ for (const constraint of this.#constraints) {
47
+ const constraintResult = constraint(result.value);
48
+ if (!constraintResult.success) {
49
+ if (isError(constraintResult.error)) {
50
+ return { valid: false, error: constraintResult.error };
51
+ }
52
+ return { valid: false, error: new SchemaError(`Constraint validation failed: ${constraintResult.error}`, { path, fast: options.fastErrors }) };
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ }
@@ -1,22 +1,14 @@
1
- import type { Decorator } from '../../reflection/types.js';
2
- import type { ValueSchema, ValueSchemaOptions } from '../types/types.js';
3
- export type StringOptions = ValueSchemaOptions & {
4
- /** trim */
5
- trim?: boolean;
6
- /** lowercase */
7
- lowercase?: boolean;
8
- /** uppercase */
9
- uppercase?: boolean;
10
- /** minimum length */
11
- minimumLength?: number;
12
- /** maximum length */
13
- maximumLength?: number;
14
- /** regular expression */
15
- pattern?: string | RegExp;
16
- /** regular expression flags */
17
- patternFlags?: string;
18
- /** name for errors */
19
- patternName?: string;
1
+ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
+ export type StringSchemaOptions = SimpleSchemaOptions & {
4
+ pattern?: RegExp | string;
20
5
  };
21
- export declare function string(options?: StringOptions): ValueSchema<string>;
22
- export declare function StringProperty(options?: StringOptions): Decorator<'property' | 'accessor'>;
6
+ export declare class StringSchema extends SimpleSchema<string> {
7
+ constructor(options?: StringSchemaOptions);
8
+ }
9
+ export declare function string(options?: StringSchemaOptions): StringSchema;
10
+ export declare function String(options?: SchemaPropertyDecoratorOptions & StringSchemaOptions): SchemaPropertyDecorator;
11
+ /**
12
+ * @deprecated use {@link String()} instead
13
+ */
14
+ export declare function StringProperty(options?: SchemaPropertyDecoratorOptions & StringSchemaOptions): SchemaPropertyDecorator;
@@ -1,38 +1,30 @@
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 { MaximumLengthConstraint, MinimumLengthConstraint, PatternConstraint } from '../constraints/index.js';
5
- import { createSchemaPropertyDecoratorFromSchema } from '../decorators/utils.js';
6
- import { LowercaseTransformer, TrimTransformer, UppercaseTransformer } from '../transformers/index.js';
7
- import { valueSchema } from '../types/types.js';
8
- export function string(options = {}) {
9
- const valueConstraints = toArrayCopy(options.valueConstraints ?? []);
10
- const transformers = toArrayCopy(options.transformers ?? []);
11
- if (isDefined(options.minimumLength)) {
12
- valueConstraints.push(new MinimumLengthConstraint(options.minimumLength));
1
+ import { isDefined, isRegExp, isString } from '../../utils/type-guards.js';
2
+ import { Property } from '../decorators/index.js';
3
+ import { SimpleSchema } from './simple.js';
4
+ export class StringSchema extends SimpleSchema {
5
+ constructor(options) {
6
+ const pattern = isDefined(options?.pattern) ? isString(options.pattern) ? RegExp(options.pattern, 'u') : isRegExp(options.pattern) ? options.pattern : undefined : undefined;
7
+ super('string', isString, options, {
8
+ coercers: {
9
+ number: (value) => ({ success: true, value: globalThis.String(value), valid: true }),
10
+ boolean: (value) => ({ success: true, value: globalThis.String(value), valid: true }),
11
+ bigint: (value) => ({ success: true, value: globalThis.String(value), valid: true })
12
+ },
13
+ constraints: [
14
+ isDefined(pattern) ? ((value) => pattern.test(value) ? ({ success: true }) : ({ success: false, error: 'Value did not match pattern.' })) : null
15
+ ]
16
+ });
13
17
  }
14
- if (isDefined(options.maximumLength)) {
15
- valueConstraints.push(new MaximumLengthConstraint(options.maximumLength));
16
- }
17
- if (isDefined(options.pattern)) {
18
- const pattern = RegExp(options.pattern, options.patternFlags);
19
- valueConstraints.push(new PatternConstraint(pattern, options.patternName));
20
- }
21
- if (isDefined(options.trim)) {
22
- transformers.push(new TrimTransformer());
23
- }
24
- if (isDefined(options.lowercase)) {
25
- transformers.push(new LowercaseTransformer());
26
- }
27
- if (isDefined(options.uppercase)) {
28
- transformers.push(new UppercaseTransformer());
29
- }
30
- return valueSchema(String, {
31
- ...options,
32
- valueConstraints,
33
- transformers
34
- });
35
18
  }
19
+ export function string(options) {
20
+ return new StringSchema(options);
21
+ }
22
+ export function String(options) {
23
+ return Property(string(options), options);
24
+ }
25
+ /**
26
+ * @deprecated use {@link String()} instead
27
+ */
36
28
  export function StringProperty(options) {
37
- return createSchemaPropertyDecoratorFromSchema(string(options));
29
+ return String(options);
38
30
  }
@@ -0,0 +1,12 @@
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 SymbolSchema extends Schema<symbol> {
5
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<symbol>;
6
+ }
7
+ export declare function symbol(): SymbolSchema;
8
+ export declare function Symbol(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
9
+ /**
10
+ * @deprecated use {@link Symbol()} instead
11
+ */
12
+ export declare function SymbolProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -0,0 +1,25 @@
1
+ import { SchemaError } from '../../schema/schema.error.js';
2
+ import { isSymbol } from '../../utils/type-guards.js';
3
+ import { typeOf } from '../../utils/type-of.js';
4
+ import { Property } from '../decorators/index.js';
5
+ import { Schema } from '../schema.js';
6
+ export class SymbolSchema extends Schema {
7
+ _test(value, path, options) {
8
+ if (isSymbol(value)) {
9
+ return { valid: true, value };
10
+ }
11
+ return { valid: false, error: SchemaError.expectedButGot('symbol', typeOf(value), path, { fast: options.fastErrors }) };
12
+ }
13
+ }
14
+ export function symbol() {
15
+ return new SymbolSchema();
16
+ }
17
+ export function Symbol(options) {
18
+ return Property(symbol(), options);
19
+ }
20
+ /**
21
+ * @deprecated use {@link Symbol()} instead
22
+ */
23
+ export function SymbolProperty(options) {
24
+ return Symbol(options);
25
+ }
@@ -1,5 +1,9 @@
1
- import type { OneOrMany } from '../../types.js';
2
- import type { SchemaTestable } from '../schema.js';
3
- import type { GenericTransformFunction } from '../transformers/generic.js';
4
- import type { ValueSchema, ValueType } from '../types/index.js';
5
- export declare function transform<T, O>(schema: OneOrMany<SchemaTestable<T>>, transformFunction: GenericTransformFunction<T, O>, sourceType?: OneOrMany<ValueType<T>>): ValueSchema<O>;
1
+ import type { JsonPath } from '../../json-path/json-path.js';
2
+ import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
3
+ export declare class TransformSchema<I, O> extends Schema<O> {
4
+ readonly schema: Schema<I>;
5
+ readonly transformFn: (value: I) => O;
6
+ constructor(schema: Schema<I>, transformFn: (value: I) => O);
7
+ _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<O>;
8
+ }
9
+ export declare function transform<I, O>(schema: Schema<I>, transformFn: (value: I) => O): TransformSchema<I, O>;