@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.
- package/api/types.d.ts +1 -1
- package/authentication/authentication.api.d.ts +21 -22
- package/authentication/authentication.api.js +1 -6
- package/authentication/client/api.client.d.ts +4 -5
- package/authentication/client/api.client.js +1 -2
- package/authentication/client/http-client.middleware.d.ts +1 -1
- package/browser/pdf-options.js +8 -9
- package/errors/custom.error.d.ts +5 -5
- package/examples/api/basic-overview.js +4 -4
- package/http/client/http-client-request.d.ts +1 -2
- package/http/client/module.d.ts +1 -1
- package/image-service/image-service.js +4 -7
- package/mail/mail.client.d.ts +2 -2
- package/mail/mail.client.js +3 -5
- package/orm/decorators.d.ts +1 -0
- package/orm/decorators.js +4 -0
- package/orm/entity.js +3 -3
- package/orm/index.d.ts +4 -0
- package/orm/index.js +4 -0
- package/orm/repository.d.ts +6 -8
- package/orm/repository.js +7 -0
- package/orm/schema-converter.d.ts +83 -0
- package/orm/schema-converter.js +74 -0
- package/orm/schema.d.ts +3 -0
- package/orm/schema.js +1 -0
- package/orm/types.d.ts +8 -0
- package/orm/types.js +6 -0
- package/package.json +6 -4
- package/reflection/registry.d.ts +1 -1
- package/reflection/utils.d.ts +2 -2
- package/schema/decorators/class.d.ts +1 -1
- package/schema/decorators/index.d.ts +0 -2
- package/schema/decorators/index.js +0 -2
- package/schema/decorators/property.d.ts +6 -5
- package/schema/decorators/property.js +10 -14
- package/schema/decorators/types.d.ts +7 -12
- package/schema/decorators/utils.d.ts +2 -15
- package/schema/decorators/utils.js +4 -43
- package/schema/index.d.ts +1 -6
- package/schema/index.js +15 -6
- package/schema/schema.d.ts +89 -14
- package/schema/schema.error.d.ts +4 -6
- package/schema/schema.error.js +6 -10
- package/schema/schema.js +74 -276
- package/schema/schemas/any.d.ts +7 -5
- package/schema/schemas/any.js +10 -6
- package/schema/schemas/array.d.ts +11 -12
- package/schema/schemas/array.js +27 -19
- package/schema/schemas/bigint.d.ts +9 -0
- package/schema/schemas/bigint.js +19 -0
- package/schema/schemas/boolean.d.ts +15 -5
- package/schema/schemas/boolean.js +47 -6
- package/schema/schemas/date.d.ts +9 -7
- package/schema/schemas/date.js +25 -19
- package/schema/schemas/defaulted.d.ts +11 -6
- package/schema/schemas/defaulted.js +23 -8
- package/schema/schemas/enumeration.d.ts +10 -5
- package/schema/schemas/enumeration.js +25 -15
- package/schema/schemas/index.d.ts +4 -6
- package/schema/schemas/index.js +4 -6
- package/schema/schemas/instance.d.ts +11 -3
- package/schema/schemas/instance.js +25 -4
- package/schema/schemas/literal.d.ts +10 -5
- package/schema/schemas/literal.js +25 -15
- package/schema/schemas/never.d.ts +6 -0
- package/schema/schemas/never.js +11 -0
- package/schema/schemas/nullable.d.ts +11 -6
- package/schema/schemas/nullable.js +24 -7
- package/schema/schemas/number.d.ts +13 -7
- package/schema/schemas/number.js +34 -23
- package/schema/schemas/object.d.ts +75 -7
- package/schema/schemas/object.js +171 -6
- package/schema/schemas/one-or-many.d.ts +10 -7
- package/schema/schemas/one-or-many.js +18 -11
- package/schema/schemas/optional.d.ts +11 -7
- package/schema/schemas/optional.js +24 -6
- package/schema/schemas/readable-stream.d.ts +8 -6
- package/schema/schemas/readable-stream.js +11 -6
- package/schema/schemas/regexp.d.ts +8 -6
- package/schema/schemas/regexp.js +25 -7
- package/schema/schemas/simple.d.ts +27 -0
- package/schema/schemas/simple.js +57 -0
- package/schema/schemas/string.d.ts +13 -21
- package/schema/schemas/string.js +26 -34
- package/schema/schemas/symbol.d.ts +12 -0
- package/schema/schemas/symbol.js +25 -0
- package/schema/schemas/transform.d.ts +9 -5
- package/schema/schemas/transform.js +19 -6
- package/schema/schemas/uint8-array.d.ts +9 -5
- package/schema/schemas/uint8-array.js +17 -26
- package/schema/schemas/union.d.ts +14 -7
- package/schema/schemas/union.js +30 -11
- package/schema/schemas/unknown.d.ts +7 -5
- package/schema/schemas/unknown.js +11 -7
- package/schema/testable.d.ts +3 -0
- package/schema/testable.js +30 -0
- package/schema/types.d.ts +31 -0
- package/schema/types.js +1 -0
- package/schema-old/decorators/class.d.ts +3 -0
- package/schema-old/decorators/class.js +5 -0
- package/schema-old/decorators/index.d.ts +6 -0
- package/schema-old/decorators/index.js +6 -0
- package/schema-old/decorators/property.d.ts +6 -0
- package/schema-old/decorators/property.js +17 -0
- package/schema-old/decorators/types.d.ts +19 -0
- package/schema-old/decorators/types.js +1 -0
- package/schema-old/decorators/utils.d.ts +15 -0
- package/schema-old/decorators/utils.js +48 -0
- package/schema-old/index.d.ts +10 -0
- package/schema-old/index.js +10 -0
- package/schema-old/schema.d.ts +15 -0
- package/schema-old/schema.error.d.ts +26 -0
- package/schema-old/schema.error.js +64 -0
- package/schema-old/schema.js +283 -0
- package/schema-old/schemas/any.d.ts +5 -0
- package/schema-old/schemas/any.js +9 -0
- package/schema-old/schemas/array.d.ts +12 -0
- package/schema-old/schemas/array.js +23 -0
- package/schema-old/schemas/boolean.d.ts +5 -0
- package/schema-old/schemas/boolean.js +9 -0
- package/schema-old/schemas/date.d.ts +8 -0
- package/schema-old/schemas/date.js +22 -0
- package/schema-old/schemas/defaulted.d.ts +6 -0
- package/schema-old/schemas/defaulted.js +10 -0
- package/schema-old/schemas/enumeration.d.ts +6 -0
- package/schema-old/schemas/enumeration.js +17 -0
- package/schema-old/schemas/index.d.ts +26 -0
- package/schema-old/schemas/index.js +26 -0
- package/schema-old/schemas/instance.d.ts +3 -0
- package/schema-old/schemas/instance.js +5 -0
- package/schema-old/schemas/literal.d.ts +5 -0
- package/schema-old/schemas/literal.js +17 -0
- package/schema-old/schemas/nullable.d.ts +6 -0
- package/schema-old/schemas/nullable.js +9 -0
- package/schema-old/schemas/number.d.ts +9 -0
- package/schema-old/schemas/number.js +27 -0
- package/schema-old/schemas/object.d.ts +7 -0
- package/schema-old/schemas/object.js +12 -0
- package/schema-old/schemas/one-or-many.d.ts +9 -0
- package/schema-old/schemas/one-or-many.js +15 -0
- package/schema-old/schemas/optional.d.ts +7 -0
- package/schema-old/schemas/optional.js +8 -0
- package/schema-old/schemas/readable-stream.d.ts +6 -0
- package/schema-old/schemas/readable-stream.js +9 -0
- package/schema-old/schemas/regexp.d.ts +6 -0
- package/schema-old/schemas/regexp.js +9 -0
- package/schema-old/schemas/string.d.ts +22 -0
- package/schema-old/schemas/string.js +38 -0
- package/schema-old/schemas/transform.d.ts +5 -0
- package/schema-old/schemas/transform.js +7 -0
- package/schema-old/schemas/uint8-array.d.ts +10 -0
- package/schema-old/schemas/uint8-array.js +29 -0
- package/schema-old/schemas/union.d.ts +7 -0
- package/schema-old/schemas/union.js +13 -0
- package/schema-old/schemas/unknown.d.ts +5 -0
- package/schema-old/schemas/unknown.js +9 -0
- package/templates/resolvers/string.template-resolver.d.ts +0 -1
- package/templates/resolvers/string.template-resolver.js +1 -5
- package/templates/template.model.js +1 -1
- package/types.d.ts +2 -0
- package/utils/type-guards.js +1 -1
- /package/{schema → schema-old}/array-constraints/index.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/index.js +0 -0
- /package/{schema → schema-old}/array-constraints/maximum-length.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/maximum-length.js +0 -0
- /package/{schema → schema-old}/array-constraints/minimum-length.d.ts +0 -0
- /package/{schema → schema-old}/array-constraints/minimum-length.js +0 -0
- /package/{schema → schema-old}/coercers/boolean.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/boolean.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/date.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/date.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/index.d.ts +0 -0
- /package/{schema → schema-old}/coercers/index.js +0 -0
- /package/{schema → schema-old}/coercers/number.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/number.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/regexp.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/regexp.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/string.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/string.coercer.js +0 -0
- /package/{schema → schema-old}/coercers/uint8-array.coercer.d.ts +0 -0
- /package/{schema → schema-old}/coercers/uint8-array.coercer.js +0 -0
- /package/{schema → schema-old}/constraints/enumeration.d.ts +0 -0
- /package/{schema → schema-old}/constraints/enumeration.js +0 -0
- /package/{schema → schema-old}/constraints/generic.d.ts +0 -0
- /package/{schema → schema-old}/constraints/generic.js +0 -0
- /package/{schema → schema-old}/constraints/index.d.ts +0 -0
- /package/{schema → schema-old}/constraints/index.js +0 -0
- /package/{schema → schema-old}/constraints/integer.d.ts +0 -0
- /package/{schema → schema-old}/constraints/integer.js +0 -0
- /package/{schema → schema-old}/constraints/length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/length.js +0 -0
- /package/{schema → schema-old}/constraints/literal.d.ts +0 -0
- /package/{schema → schema-old}/constraints/literal.js +0 -0
- /package/{schema → schema-old}/constraints/maximum-date.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum-date.js +0 -0
- /package/{schema → schema-old}/constraints/maximum-length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum-length.js +0 -0
- /package/{schema → schema-old}/constraints/maximum.d.ts +0 -0
- /package/{schema → schema-old}/constraints/maximum.js +0 -0
- /package/{schema → schema-old}/constraints/minimum-date.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum-date.js +0 -0
- /package/{schema → schema-old}/constraints/minimum-length.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum-length.js +0 -0
- /package/{schema → schema-old}/constraints/minimum.d.ts +0 -0
- /package/{schema → schema-old}/constraints/minimum.js +0 -0
- /package/{schema → schema-old}/constraints/pattern.d.ts +0 -0
- /package/{schema → schema-old}/constraints/pattern.js +0 -0
- /package/{schema → schema-old}/decorators/coerce.d.ts +0 -0
- /package/{schema → schema-old}/decorators/coerce.js +0 -0
- /package/{schema → schema-old}/decorators/constraint.d.ts +0 -0
- /package/{schema → schema-old}/decorators/constraint.js +0 -0
- /package/{schema → schema-old}/schemas/assign.d.ts +0 -0
- /package/{schema → schema-old}/schemas/assign.js +0 -0
- /package/{schema → schema-old}/schemas/constraint.d.ts +0 -0
- /package/{schema → schema-old}/schemas/constraint.js +0 -0
- /package/{schema → schema-old}/schemas/omit.d.ts +0 -0
- /package/{schema → schema-old}/schemas/omit.js +0 -0
- /package/{schema → schema-old}/schemas/partial.d.ts +0 -0
- /package/{schema → schema-old}/schemas/partial.js +0 -0
- /package/{schema → schema-old}/schemas/pick.d.ts +0 -0
- /package/{schema → schema-old}/schemas/pick.js +0 -0
- /package/{schema → schema-old}/schemas/record.d.ts +0 -0
- /package/{schema → schema-old}/schemas/record.js +0 -0
- /package/{schema → schema-old}/transformers/generic.d.ts +0 -0
- /package/{schema → schema-old}/transformers/generic.js +0 -0
- /package/{schema → schema-old}/transformers/index.d.ts +0 -0
- /package/{schema → schema-old}/transformers/index.js +0 -0
- /package/{schema → schema-old}/transformers/lowercase.d.ts +0 -0
- /package/{schema → schema-old}/transformers/lowercase.js +0 -0
- /package/{schema → schema-old}/transformers/trim.d.ts +0 -0
- /package/{schema → schema-old}/transformers/trim.js +0 -0
- /package/{schema → schema-old}/transformers/uppercase.d.ts +0 -0
- /package/{schema → schema-old}/transformers/uppercase.js +0 -0
- /package/{schema → schema-old}/types/index.d.ts +0 -0
- /package/{schema → schema-old}/types/index.js +0 -0
- /package/{schema → schema-old}/types/schema-array-constraint.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-array-constraint.js +0 -0
- /package/{schema → schema-old}/types/schema-value-coercer.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-coercer.js +0 -0
- /package/{schema → schema-old}/types/schema-value-constraint.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-constraint.js +0 -0
- /package/{schema → schema-old}/types/schema-value-transformer.d.ts +0 -0
- /package/{schema → schema-old}/types/schema-value-transformer.js +0 -0
- /package/{schema → schema-old}/types/types.d.ts +0 -0
- /package/{schema → schema-old}/types/types.js +0 -0
- /package/{schema → schema-old}/utils/index.d.ts +0 -0
- /package/{schema → schema-old}/utils/index.js +0 -0
- /package/{schema → schema-old}/utils/schema.d.ts +0 -0
- /package/{schema → schema-old}/utils/schema.js +0 -0
- /package/{schema → schema-old}/utils/value-type.d.ts +0 -0
- /package/{schema → schema-old}/utils/value-type.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { boolean, doublePrecision, integer, pgSchema, text, unique, uuid } from 'drizzle-orm/pg-core';
|
|
11
|
+
import { NotSupportedError } from '../errors/not-supported.error.js';
|
|
12
|
+
import { reflectionRegistry } from '../reflection/registry.js';
|
|
13
|
+
import { Property } from '../schema/index.js';
|
|
14
|
+
import { fromEntries } from '../utils/object/object.js';
|
|
15
|
+
import { assertStringPass, isUndefined } from '../utils/type-guards.js';
|
|
16
|
+
import { Integer } from './types.js';
|
|
17
|
+
export const mySchema = pgSchema('my_schema');
|
|
18
|
+
export const colors = mySchema.enum('colors', ['red', 'green', 'blue']);
|
|
19
|
+
export const mySchemaUsers = mySchema.table('users', {
|
|
20
|
+
id: uuid('id'),
|
|
21
|
+
name: text('name'),
|
|
22
|
+
age: integer(''),
|
|
23
|
+
color: colors('color').default('red'),
|
|
24
|
+
}, (self) => ({
|
|
25
|
+
unq: unique().on(self.age).nullsNotDistinct().nullsNotDistinct()
|
|
26
|
+
}));
|
|
27
|
+
export function getDrizzleSchemaFromType(type) {
|
|
28
|
+
const metadata = reflectionRegistry.getMetadata(type);
|
|
29
|
+
if (isUndefined(metadata)) {
|
|
30
|
+
throw new Error('Type does not have reflection metadata.');
|
|
31
|
+
}
|
|
32
|
+
const entries = [...metadata.properties].map(([property, propertyMetadata]) => [property, getPostgresColumn(assertStringPass(property), propertyMetadata.type)]);
|
|
33
|
+
const schema = mySchema.table(type.entityName, fromEntries(entries));
|
|
34
|
+
return schema;
|
|
35
|
+
}
|
|
36
|
+
function getPostgresColumn(name, type) {
|
|
37
|
+
if (type == String) {
|
|
38
|
+
return text(name);
|
|
39
|
+
}
|
|
40
|
+
if (type == Number) {
|
|
41
|
+
return doublePrecision(name);
|
|
42
|
+
}
|
|
43
|
+
if (type == Boolean) {
|
|
44
|
+
return boolean(name);
|
|
45
|
+
}
|
|
46
|
+
throw new NotSupportedError(`Type ${type.name} not supported`);
|
|
47
|
+
}
|
|
48
|
+
export class Entity2 {
|
|
49
|
+
id;
|
|
50
|
+
}
|
|
51
|
+
__decorate([
|
|
52
|
+
Property(),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], Entity2.prototype, "id", void 0);
|
|
55
|
+
export class User extends Entity2 {
|
|
56
|
+
name;
|
|
57
|
+
age;
|
|
58
|
+
hasAge;
|
|
59
|
+
}
|
|
60
|
+
__decorate([
|
|
61
|
+
Property(),
|
|
62
|
+
__metadata("design:type", String)
|
|
63
|
+
], User.prototype, "name", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
Integer(),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], User.prototype, "age", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
Property(),
|
|
70
|
+
__metadata("design:type", Boolean)
|
|
71
|
+
], User.prototype, "hasAge", void 0);
|
|
72
|
+
const user = getDrizzleSchemaFromType(User);
|
|
73
|
+
const db = null;
|
|
74
|
+
const results = await db.select().from(user);
|
package/orm/schema.d.ts
ADDED
package/orm/schema.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/orm/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Integer } from '../schema/index.js';
|
|
2
|
+
import type { doublePrecision, integer, uuid } from 'drizzle-orm/pg-core';
|
|
3
|
+
import type { Tagged } from 'type-fest';
|
|
4
|
+
export declare function Uuid(): PropertyDecorator & MethodDecorator;
|
|
5
|
+
export type Uuid<ColumnName extends string> = Tagged<string, 'column', ReturnType<typeof uuid<ColumnName>>>;
|
|
6
|
+
export type Integer<ColumnName extends string> = Tagged<number, 'column', ReturnType<typeof integer<ColumnName>>>;
|
|
7
|
+
export type DoublePrecision<ColumnName extends string> = Tagged<number, 'column', ReturnType<typeof doublePrecision<ColumnName>>>;
|
|
8
|
+
export { Integer };
|
package/orm/types.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention */
|
|
2
|
+
import { createSchemaPropertyDecorator, Integer, string } from '../schema/index.js';
|
|
3
|
+
export function Uuid() {
|
|
4
|
+
return createSchemaPropertyDecorator({ schema: string() });
|
|
5
|
+
}
|
|
6
|
+
export { Integer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0-beta2",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -111,11 +111,11 @@
|
|
|
111
111
|
"luxon": "^3.4",
|
|
112
112
|
"reflect-metadata": "^0.2",
|
|
113
113
|
"rxjs": "^7.8",
|
|
114
|
-
"type-fest": "4.
|
|
114
|
+
"type-fest": "4.21"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@mxssfd/typedoc-theme": "1.1",
|
|
118
|
-
"@stylistic/eslint-plugin": "2.
|
|
118
|
+
"@stylistic/eslint-plugin": "2.3",
|
|
119
119
|
"@types/chroma-js": "2.4",
|
|
120
120
|
"@types/koa__router": "12.0",
|
|
121
121
|
"@types/luxon": "3.4",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@types/mjml": "4.7",
|
|
124
124
|
"@types/node": "20",
|
|
125
125
|
"@types/nodemailer": "6.4",
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
126
|
+
"@typescript-eslint/eslint-plugin": "7.16",
|
|
127
127
|
"concurrently": "8.2",
|
|
128
128
|
"eslint": "8.57",
|
|
129
129
|
"eslint-import-resolver-typescript": "3.6",
|
|
@@ -142,12 +142,14 @@
|
|
|
142
142
|
"@zxcvbn-ts/language-de": "^3.0",
|
|
143
143
|
"@zxcvbn-ts/language-en": "^3.0",
|
|
144
144
|
"chroma-js": "^2.4",
|
|
145
|
+
"drizzle-orm": "^0.32",
|
|
145
146
|
"handlebars": "^4.7",
|
|
146
147
|
"koa": "^2.15",
|
|
147
148
|
"minio": "^8.0",
|
|
148
149
|
"mjml": "^4.15",
|
|
149
150
|
"mongodb": "^6.7",
|
|
150
151
|
"nodemailer": "^6.9",
|
|
152
|
+
"pg": "^8.12",
|
|
151
153
|
"playwright": "^1.45",
|
|
152
154
|
"preact": "^10.22",
|
|
153
155
|
"preact-render-to-string": "^6.5",
|
package/reflection/registry.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type MetadataBase<T extends MetadataType> = {
|
|
|
9
9
|
export type TypeMetadata = MetadataBase<'type'> & {
|
|
10
10
|
readonly constructor: AbstractConstructor;
|
|
11
11
|
readonly parent: AbstractConstructor | null;
|
|
12
|
-
/**
|
|
12
|
+
/** Undefined if class has no constructor */
|
|
13
13
|
readonly parameters: ConstructorParameterMetadata[] | undefined;
|
|
14
14
|
readonly properties: ReadonlyMap<string | symbol, PropertyMetadata>;
|
|
15
15
|
readonly staticProperties: ReadonlyMap<string | symbol, PropertyMetadata>;
|
package/reflection/utils.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export type CreateDecoratorTypeOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
export type CreateDecoratorOptions = {
|
|
7
7
|
data?: Record<string | symbol>;
|
|
8
|
-
/**
|
|
8
|
+
/** Merge data values instead of replacing them (requires them to be objects, arrays, maps or sets) */
|
|
9
9
|
mergeData?: boolean;
|
|
10
|
-
/**
|
|
10
|
+
/** Return values of these decorators are not used */
|
|
11
11
|
include?: OneOrMany<DecoratorUnion>;
|
|
12
12
|
};
|
|
13
13
|
export type SpecificCreateDecoratorOptions<T extends DecoratorType> = TypedOmit<CreateDecoratorOptions, 'include'> & {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Decorator } from '../../reflection/index.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
export
|
|
6
|
-
export declare function Property(schema?:
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import type { SchemaTestable } from '../schema.js';
|
|
4
|
+
import type { SchemaPropertyReflectionData } from './types.js';
|
|
5
|
+
export type SchemaPropertyDecoratorOptions = TypedOmit<SchemaPropertyReflectionData, 'schema'>;
|
|
6
|
+
export declare function Property(schema?: SchemaTestable, options?: SchemaPropertyDecoratorOptions): Decorator<'property' | 'accessor'>;
|
|
7
|
+
export declare function Property(options?: SchemaPropertyDecoratorOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { typeSchema } from '../types/index.js';
|
|
2
|
+
import { isDefined } from '../../utils/type-guards.js';
|
|
3
|
+
import { isSchemaTestable } from '../testable.js';
|
|
5
4
|
import { createSchemaPropertyDecorator } from './utils.js';
|
|
6
|
-
export function Property(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
arrayConstraints: isDefined(options.arrayConstraints) ? toArray(options.arrayConstraints) : undefined,
|
|
15
|
-
valueConstraints: isDefined(options.valueConstraints) ? toArray(options.valueConstraints) : undefined
|
|
16
|
-
});
|
|
5
|
+
export function Property(schemaOrOptions, optionsOrNothing) {
|
|
6
|
+
if (isDefined(optionsOrNothing)) {
|
|
7
|
+
return createSchemaPropertyDecorator({ schema: schemaOrOptions, ...optionsOrNothing });
|
|
8
|
+
}
|
|
9
|
+
if (isSchemaTestable(schemaOrOptions)) {
|
|
10
|
+
return createSchemaPropertyDecorator({ schema: schemaOrOptions });
|
|
11
|
+
}
|
|
12
|
+
return createSchemaPropertyDecorator(schemaOrOptions);
|
|
17
13
|
}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Decorator } from '../../reflection/types.js';
|
|
2
2
|
import type { SchemaTestable } from '../schema.js';
|
|
3
|
-
import type {
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { ObjectSchemaFactoryFunction, ObjectSchemaOptions } from '../schemas/object.js';
|
|
4
|
+
export type SchemaPropertyDecorator = Decorator<'property' | 'accessor'>;
|
|
5
|
+
export type SchemaTypeReflectionData = Partial<Pick<ObjectSchemaOptions, 'mask' | 'unknownProperties' | 'unknownPropertiesKey'>> & {
|
|
6
|
+
schema?: SchemaTestable;
|
|
7
|
+
factory?: ObjectSchemaFactoryFunction<any>;
|
|
7
8
|
};
|
|
8
9
|
export type SchemaPropertyReflectionData = {
|
|
9
|
-
schema?:
|
|
10
|
+
schema?: SchemaTestable;
|
|
10
11
|
array?: boolean;
|
|
11
12
|
optional?: boolean;
|
|
12
13
|
nullable?: boolean;
|
|
13
|
-
coerce?: boolean;
|
|
14
|
-
coercers?: readonly SchemaValueCoercer[];
|
|
15
|
-
transformers?: readonly SchemaValueTransformer[];
|
|
16
|
-
arrayConstraints?: readonly SchemaArrayConstraint[];
|
|
17
|
-
valueConstraints?: readonly SchemaValueConstraint[];
|
|
18
14
|
};
|
|
19
|
-
export type PropertyOptions = Partial<ValueSchema<any>>;
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { Schema } from '../schema.js';
|
|
4
|
-
import type { SchemaArrayConstraint } from '../types/schema-array-constraint.js';
|
|
5
|
-
import type { SchemaValueCoercer } from '../types/schema-value-coercer.js';
|
|
6
|
-
import type { SchemaValueConstraint } from '../types/schema-value-constraint.js';
|
|
7
|
-
import type { SchemaValueTransformer } from '../types/schema-value-transformer.js';
|
|
8
|
-
import type { PropertyOptions, SchemaPropertyReflectionData } from './types.js';
|
|
9
|
-
export declare function createSchemaPropertyDecorator(options: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
10
|
-
export declare function createSchemaPropertyDecoratorFromSchema(schema: Schema): Decorator<'property' | 'accessor'>;
|
|
11
|
-
export declare function createSchemaValueCoercerDecorator(coercer: SchemaValueCoercer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
12
|
-
export declare function createSchemaValueTransformerDecorator(transformer: SchemaValueTransformer, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
13
|
-
export declare function createSchemaArrayConstraintDecorator(constraint: SchemaArrayConstraint, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
14
|
-
export declare function createSchemaValueConstraintDecorator(constraints: OneOrMany<SchemaValueConstraint>, options?: PropertyOptions): Decorator<'property' | 'accessor'>;
|
|
15
|
-
export declare function tryGetSchemaPropertyReflectionData(metadata: PropertyMetadata): SchemaPropertyReflectionData | undefined;
|
|
1
|
+
import type { SchemaPropertyDecorator, SchemaPropertyReflectionData } from './types.js';
|
|
2
|
+
export declare function createSchemaPropertyDecorator(data?: SchemaPropertyReflectionData): SchemaPropertyDecorator;
|
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
import { createPropertyOrAccessorDecorator } from '../../reflection/index.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { filterObject } from '../../utils/object/object.js';
|
|
6
|
-
import { isArray, isDefined, isUndefined } from '../../utils/type-guards.js';
|
|
7
|
-
import { isValueSchema, valueSchema } from '../types/types.js';
|
|
8
|
-
export function createSchemaPropertyDecorator(options) {
|
|
3
|
+
import { filterUndefinedObjectProperties } from '../../utils/object/object.js';
|
|
4
|
+
export function createSchemaPropertyDecorator(data = {}) {
|
|
9
5
|
return createPropertyOrAccessorDecorator({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const newSchemaData = {
|
|
13
|
-
...options,
|
|
14
|
-
coercers: (isDefined(options.coercers) && (!isArray(options.coercers) || options.coercers.length > 0)) ? merge(toArray(options.coercers), schemaData.coercers) : undefined,
|
|
15
|
-
transformers: (isDefined(options.transformers) && (!isArray(options.transformers) || options.transformers.length > 0)) ? merge(toArray(options.transformers), schemaData.transformers) : undefined,
|
|
16
|
-
arrayConstraints: (isDefined(options.arrayConstraints) && (!isArray(options.arrayConstraints) || options.arrayConstraints.length > 0)) ? merge(toArray(options.arrayConstraints), schemaData.arrayConstraints) : undefined,
|
|
17
|
-
valueConstraints: (isDefined(options.valueConstraints) && (!isArray(options.valueConstraints) || options.valueConstraints.length > 0)) ? merge(toArray(options.valueConstraints), schemaData.valueConstraints) : undefined
|
|
18
|
-
};
|
|
19
|
-
metadata.data.set('schema', filterObject(newSchemaData, isDefined), true);
|
|
20
|
-
}
|
|
6
|
+
data: { schema: filterUndefinedObjectProperties(data) },
|
|
7
|
+
mergeData: true
|
|
21
8
|
});
|
|
22
9
|
}
|
|
23
|
-
export function createSchemaPropertyDecoratorFromSchema(schema) {
|
|
24
|
-
return createSchemaPropertyDecorator(isValueSchema(schema) ? schema : valueSchema(schema));
|
|
25
|
-
}
|
|
26
|
-
export function createSchemaValueCoercerDecorator(coercer, options) {
|
|
27
|
-
return createSchemaPropertyDecorator({ ...options, coercers: coercer });
|
|
28
|
-
}
|
|
29
|
-
export function createSchemaValueTransformerDecorator(transformer, options) {
|
|
30
|
-
return createSchemaPropertyDecorator({ ...options, transformers: transformer });
|
|
31
|
-
}
|
|
32
|
-
export function createSchemaArrayConstraintDecorator(constraint, options) {
|
|
33
|
-
return createSchemaPropertyDecorator({ ...options, arrayConstraints: constraint });
|
|
34
|
-
}
|
|
35
|
-
export function createSchemaValueConstraintDecorator(constraints, options) {
|
|
36
|
-
return createSchemaPropertyDecorator({ ...options, valueConstraints: constraints });
|
|
37
|
-
}
|
|
38
|
-
export function tryGetSchemaPropertyReflectionData(metadata) {
|
|
39
|
-
return metadata.data.tryGet('schema');
|
|
40
|
-
}
|
|
41
|
-
function getOrCreateSchemaPropertyReflectionData(metadata) {
|
|
42
|
-
let schemaData = tryGetSchemaPropertyReflectionData(metadata);
|
|
43
|
-
if (isUndefined(schemaData)) {
|
|
44
|
-
schemaData = {};
|
|
45
|
-
metadata.data.set('schema', schemaData);
|
|
46
|
-
}
|
|
47
|
-
return schemaData;
|
|
48
|
-
}
|
package/schema/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
export * from './array-constraints/index.js';
|
|
2
|
-
export * from './coercers/index.js';
|
|
3
|
-
export * from './constraints/index.js';
|
|
4
1
|
export * from './decorators/index.js';
|
|
5
2
|
export * from './schema.error.js';
|
|
6
3
|
export * from './schema.js';
|
|
7
4
|
export * from './schemas/index.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './types/index.js';
|
|
10
|
-
export * from './utils/index.js';
|
|
5
|
+
export * from './testable.js';
|
package/schema/index.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from './constraints/index.js';
|
|
1
|
+
import { Schema } from './schema.js';
|
|
2
|
+
import { schemaTestableToSchema } from './testable.js';
|
|
4
3
|
export * from './decorators/index.js';
|
|
5
4
|
export * from './schema.error.js';
|
|
6
5
|
export * from './schema.js';
|
|
7
6
|
export * from './schemas/index.js';
|
|
8
|
-
export * from './
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export * from './testable.js';
|
|
8
|
+
Schema.test = function test(schema, value, options) {
|
|
9
|
+
return schemaTestableToSchema(schema).test(value, options);
|
|
10
|
+
};
|
|
11
|
+
Schema.validate = function validate(schema, value, options) {
|
|
12
|
+
return schemaTestableToSchema(schema).validate(value, options);
|
|
13
|
+
};
|
|
14
|
+
Schema.assert = function assert(schema, value, options) {
|
|
15
|
+
schemaTestableToSchema(schema).assert(value, options);
|
|
16
|
+
};
|
|
17
|
+
Schema.parse = function parse(schema, value, options) {
|
|
18
|
+
return schemaTestableToSchema(schema).parse(value, options);
|
|
19
|
+
};
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,15 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function<T extends readonly SchemaTestable[], R extends SchemaTestable, F extends (...args: TupleSchemaOutput<T>) => SchemaOutput<R>>(argumentSchemas: T, returnSchema: R, handler: F): F;
|
|
12
|
-
asyncFunction<T extends readonly SchemaTestable[], R extends SchemaTestable, F extends (...args: TupleSchemaOutput<T>) => Promise<SchemaOutput<R>>>(argumentSchemas: T, returnSchema: R, handler: F): F;
|
|
1
|
+
import type { IsEqual, Or } from 'type-fest';
|
|
2
|
+
import { JsonPath } from '../json-path/json-path.js';
|
|
3
|
+
import type { AbstractConstructor } from '../types.js';
|
|
4
|
+
import type { SchemaError } from './schema.error.js';
|
|
5
|
+
import type { Coercible, Maskable } from './types.js';
|
|
6
|
+
export type SchemaTestOptions = Coercible & Maskable & {
|
|
7
|
+
/**
|
|
8
|
+
* Use fast errors which can improve performance a lot but misses detailed stack traces.
|
|
9
|
+
*/
|
|
10
|
+
fastErrors?: boolean;
|
|
13
11
|
};
|
|
14
|
-
export
|
|
15
|
-
|
|
12
|
+
export type SchemaTestResult<T> = {
|
|
13
|
+
valid: true;
|
|
14
|
+
value: T;
|
|
15
|
+
error?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
valid: false;
|
|
18
|
+
value?: undefined;
|
|
19
|
+
error: SchemaError;
|
|
20
|
+
};
|
|
21
|
+
type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, String>> extends true ? typeof String : Or<IsEqual<T, number>, IsEqual<T, Number>> extends true ? typeof Number : Or<IsEqual<T, boolean>, IsEqual<T, Boolean>> extends true ? typeof Boolean : Or<IsEqual<T, bigint>, IsEqual<T, BigInt>> extends true ? typeof BigInt : Or<IsEqual<T, symbol>, IsEqual<T, Symbol>> extends true ? typeof Symbol : never;
|
|
22
|
+
type NormalizeConstructorToPrimitve<T> = T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends BigInt ? bigint : T extends Symbol ? symbol : T;
|
|
23
|
+
export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
24
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? NormalizeConstructorToPrimitve<U> : never;
|
|
25
|
+
export declare abstract class Schema<T = unknown> {
|
|
26
|
+
/**
|
|
27
|
+
* Test an unknown value to see whether it corresponds to the schema.
|
|
28
|
+
* @param schema schema to test against
|
|
29
|
+
* @param value value to test
|
|
30
|
+
* @param options validation options
|
|
31
|
+
* @returns test result
|
|
32
|
+
*/
|
|
33
|
+
static readonly test: <T>(schema: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions) => SchemaTestResult<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Validate an unknown value to see whether it corresponds to the schema.
|
|
36
|
+
* @param schema schema to validate against
|
|
37
|
+
* @param value value to validate
|
|
38
|
+
* @param options validation options
|
|
39
|
+
* @returns validation result
|
|
40
|
+
*/
|
|
41
|
+
static readonly validate: <T>(schema: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Asserts an unknown value to be valid according to the schema.
|
|
44
|
+
* @param schema schema to validate against
|
|
45
|
+
* @param value value to validate
|
|
46
|
+
* @param options validation options
|
|
47
|
+
*/
|
|
48
|
+
static readonly assert: <T>(schema: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions) => asserts value is T;
|
|
49
|
+
/**
|
|
50
|
+
* Parse an unknown value to comply with the scheme.
|
|
51
|
+
* @param schema schema to validate against
|
|
52
|
+
* @param value value to validate
|
|
53
|
+
* @param options validation options
|
|
54
|
+
* @returns validation result
|
|
55
|
+
*/
|
|
56
|
+
static readonly parse: <T>(schema: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions) => T;
|
|
57
|
+
/**
|
|
58
|
+
* Test an unknown value to see whether it corresponds to the schema.
|
|
59
|
+
* @param schema schema to test against
|
|
60
|
+
* @param value value to test
|
|
61
|
+
* @param options validation options
|
|
62
|
+
* @returns test result with either the value or validation error
|
|
63
|
+
*/
|
|
64
|
+
test(value: any, options?: SchemaTestOptions): SchemaTestResult<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Validate an unknown value to see whether it corresponds to the schema.
|
|
67
|
+
* @param schema schema to validate against
|
|
68
|
+
* @param value value to validate
|
|
69
|
+
* @param options validation options
|
|
70
|
+
* @returns validation result. Throws if validation fails
|
|
71
|
+
*/
|
|
72
|
+
validate(value: any, options?: SchemaTestOptions): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Asserts an unknown value to be valid according to the schema.
|
|
75
|
+
* @param schema schema to validate against
|
|
76
|
+
* @param value value to validate
|
|
77
|
+
* @param options validation options
|
|
78
|
+
*/
|
|
79
|
+
assert(value: any, options?: SchemaTestOptions): asserts value is T;
|
|
80
|
+
/**
|
|
81
|
+
* Parse an unknown value to comply with the scheme.
|
|
82
|
+
* @param schema schema to parse against
|
|
83
|
+
* @param value value to parse
|
|
84
|
+
* @param options validation options
|
|
85
|
+
* @returns parsed value
|
|
86
|
+
*/
|
|
87
|
+
parse(value: any, options?: SchemaTestOptions): T;
|
|
88
|
+
abstract _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
89
|
+
}
|
|
90
|
+
export {};
|
package/schema/schema.error.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { CustomError } from '../errors/custom.error.js';
|
|
1
|
+
import { CustomError, type CustomErrorOptions } from '../errors/custom.error.js';
|
|
3
2
|
import type { JsonPath } from '../json-path/index.js';
|
|
4
|
-
import type { OneOrMany, TypedOmit, UndefinableJson } from '../types.js';
|
|
3
|
+
import type { AbstractConstructor, OneOrMany, TypedOmit, UndefinableJson } from '../types.js';
|
|
5
4
|
import type { ErrorExtraInfo } from '../utils/format-error.js';
|
|
6
|
-
import type { ValueType } from './types/index.js';
|
|
7
5
|
export type SchemaErrorOptions = Pick<CustomErrorOptions, 'fast'> & {
|
|
8
6
|
path: string | JsonPath;
|
|
9
7
|
details?: UndefinableJson;
|
|
@@ -16,10 +14,10 @@ export declare class SchemaError extends CustomError implements ErrorExtraInfo {
|
|
|
16
14
|
readonly details?: UndefinableJson;
|
|
17
15
|
readonly inner?: OneOrMany<SchemaError>;
|
|
18
16
|
constructor(message: string, options: SchemaErrorOptions, cause?: any);
|
|
19
|
-
static expectedButGot(expected: OneOrMany<string |
|
|
17
|
+
static expectedButGot(expected: OneOrMany<string | AbstractConstructor>, got: string, path: string | JsonPath, options?: TypedOmit<SchemaErrorOptions, 'path'> & {
|
|
20
18
|
customMessage?: string;
|
|
21
19
|
}): SchemaError;
|
|
22
|
-
static couldNotCoerce(expected: OneOrMany<string |
|
|
20
|
+
static couldNotCoerce(expected: OneOrMany<string | AbstractConstructor>, got: string, path: string | JsonPath, options: TypedOmit<SchemaErrorOptions, 'path'> & {
|
|
23
21
|
customMessage?: string;
|
|
24
22
|
}): SchemaError;
|
|
25
23
|
getExtraInfo(includeMessage?: boolean): UndefinableJson | undefined;
|
package/schema/schema.error.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { CustomError } from '../errors/custom.error.js';
|
|
2
2
|
import { toArray } from '../utils/array/array.js';
|
|
3
|
-
import { isArray, isDefined, isNotNullOrUndefined, isString } from '../utils/type-guards.js';
|
|
4
|
-
import { getExpectString } from './schema.js';
|
|
5
|
-
import { getValueTypeName } from './utils/index.js';
|
|
3
|
+
import { isArray, isDefined, isFunction, isNotNullOrUndefined, isString } from '../utils/type-guards.js';
|
|
6
4
|
export class SchemaError extends CustomError {
|
|
7
5
|
static errorName = 'SchemaError';
|
|
8
6
|
path;
|
|
@@ -24,24 +22,22 @@ export class SchemaError extends CustomError {
|
|
|
24
22
|
}
|
|
25
23
|
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
26
24
|
static expectedButGot(expected, got, path, options) {
|
|
27
|
-
const expectedNames = toArray(expected).map((
|
|
28
|
-
const gotName = isString(got) ? got : getValueTypeName(got);
|
|
25
|
+
const expectedNames = toArray(expected).map((e) => isFunction(e) ? e.name : e);
|
|
29
26
|
const expectedString = expectedNames.length == 1
|
|
30
27
|
? expectedNames[0]
|
|
31
28
|
: `(${expectedNames.join(' | ')})`;
|
|
32
|
-
const customMessage = isDefined(options
|
|
33
|
-
const message = `Expected ${expectedString} but got ${
|
|
29
|
+
const customMessage = isDefined(options?.customMessage) ? `: ${options.customMessage}` : '.';
|
|
30
|
+
const message = `Expected ${expectedString} but got ${got}${customMessage}`;
|
|
34
31
|
return new SchemaError(message, { path, ...options });
|
|
35
32
|
}
|
|
36
33
|
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
37
34
|
static couldNotCoerce(expected, got, path, options) {
|
|
38
|
-
const expectedNames = toArray(expected).map((
|
|
39
|
-
const gotText = isString(got) ? got : getValueTypeName(got);
|
|
35
|
+
const expectedNames = toArray(expected).map((e) => isFunction(e) ? e.name : e);
|
|
40
36
|
const expectedString = expectedNames.length == 1
|
|
41
37
|
? expectedNames[0]
|
|
42
38
|
: `[${expectedNames.join(', ')}]`;
|
|
43
39
|
const customMessageString = isDefined(options.customMessage) ? `: ${options.customMessage}` : '.';
|
|
44
|
-
const errorMessage = `Could not coerce ${
|
|
40
|
+
const errorMessage = `Could not coerce ${got} to ${expectedString}${customMessageString}`;
|
|
45
41
|
return new SchemaError(errorMessage, { path, ...options });
|
|
46
42
|
}
|
|
47
43
|
getExtraInfo(includeMessage = false) {
|