@tstdl/base 0.91.0-beta1 → 0.91.0-beta11
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/authentication/authentication.api.d.ts +37 -37
- package/examples/api/basic-overview.js +2 -2
- package/image-service/image-service.js +4 -4
- package/mail/mail.client.js +2 -2
- package/orm/entity.js +2 -2
- package/orm/schema-converter.d.ts +16 -0
- package/package.json +4 -4
- package/schema/decorators/utils.js +3 -2
- package/schema/schema.d.ts +3 -2
- package/schema/schemas/array.d.ts +3 -2
- package/schema/schemas/array.js +12 -10
- package/schema/schemas/bigint.d.ts +2 -1
- package/schema/schemas/bigint.js +2 -2
- package/schema/schemas/boolean.d.ts +2 -6
- package/schema/schemas/boolean.js +3 -9
- package/schema/schemas/date.d.ts +1 -1
- package/schema/schemas/date.js +1 -1
- package/schema/schemas/function.d.ts +8 -0
- package/schema/schemas/function.js +14 -0
- package/schema/schemas/index.d.ts +1 -0
- package/schema/schemas/index.js +1 -0
- package/schema/schemas/nullable.d.ts +3 -2
- package/schema/schemas/nullable.js +2 -2
- package/schema/schemas/number.d.ts +1 -5
- package/schema/schemas/number.js +1 -7
- package/schema/schemas/object.d.ts +39 -26
- package/schema/schemas/object.js +21 -12
- package/schema/schemas/optional.d.ts +5 -3
- package/schema/schemas/optional.js +3 -3
- package/schema/schemas/readable-stream.d.ts +1 -1
- package/schema/schemas/readable-stream.js +1 -1
- package/schema/schemas/regexp.d.ts +1 -1
- package/schema/schemas/regexp.js +1 -1
- package/schema/schemas/string.d.ts +0 -4
- package/schema/schemas/string.js +1 -7
- package/schema/schemas/symbol.d.ts +2 -6
- package/schema/schemas/symbol.js +2 -8
- package/schema/schemas/uint8-array.d.ts +1 -1
- package/schema/schemas/uint8-array.js +3 -3
- package/schema/testable.js +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApiDefinition } from '../api/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ObjectSchema, type ObjectSchemaOrType } from '../schema/index.js';
|
|
3
3
|
import type { SchemaTestable } from '../schema/schema.js';
|
|
4
4
|
import type { Record } from '../types.js';
|
|
5
5
|
import type { TokenPayload } from './index.js';
|
|
@@ -15,9 +15,9 @@ export declare const authenticationApiDefinition: {
|
|
|
15
15
|
resource: string;
|
|
16
16
|
method: "POST";
|
|
17
17
|
parameters: ObjectSchema<{
|
|
18
|
-
subject: string;
|
|
19
|
-
secret: string;
|
|
20
|
-
data: unknown;
|
|
18
|
+
readonly subject: string;
|
|
19
|
+
readonly secret: string;
|
|
20
|
+
readonly data: unknown;
|
|
21
21
|
}>;
|
|
22
22
|
result: ObjectSchema<TokenPayload<import("type-fest").EmptyObject>>;
|
|
23
23
|
credentials: true;
|
|
@@ -29,7 +29,7 @@ export declare const authenticationApiDefinition: {
|
|
|
29
29
|
resource: string;
|
|
30
30
|
method: "POST";
|
|
31
31
|
parameters: ObjectSchema<{
|
|
32
|
-
data: unknown;
|
|
32
|
+
readonly data: unknown;
|
|
33
33
|
}>;
|
|
34
34
|
result: ObjectSchema<TokenPayload<import("type-fest").EmptyObject>>;
|
|
35
35
|
credentials: true;
|
|
@@ -41,8 +41,8 @@ export declare const authenticationApiDefinition: {
|
|
|
41
41
|
resource: string;
|
|
42
42
|
method: "POST";
|
|
43
43
|
parameters: ObjectSchema<{
|
|
44
|
-
subject: string;
|
|
45
|
-
data: unknown;
|
|
44
|
+
readonly subject: string;
|
|
45
|
+
readonly data: unknown;
|
|
46
46
|
}>;
|
|
47
47
|
result: ObjectSchema<TokenPayload<import("type-fest").EmptyObject>>;
|
|
48
48
|
credentials: true;
|
|
@@ -54,7 +54,7 @@ export declare const authenticationApiDefinition: {
|
|
|
54
54
|
resource: string;
|
|
55
55
|
method: "POST";
|
|
56
56
|
parameters: ObjectSchema<{
|
|
57
|
-
data: unknown;
|
|
57
|
+
readonly data: unknown;
|
|
58
58
|
}>;
|
|
59
59
|
result: ObjectSchema<TokenPayload<import("type-fest").EmptyObject>>;
|
|
60
60
|
credentials: true;
|
|
@@ -75,8 +75,8 @@ export declare const authenticationApiDefinition: {
|
|
|
75
75
|
resource: string;
|
|
76
76
|
method: "POST";
|
|
77
77
|
parameters: ObjectSchema<{
|
|
78
|
-
subject: string;
|
|
79
|
-
data: import("type-fest").EmptyObject;
|
|
78
|
+
readonly subject: string;
|
|
79
|
+
readonly data: import("type-fest").EmptyObject;
|
|
80
80
|
}>;
|
|
81
81
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
82
82
|
};
|
|
@@ -84,8 +84,8 @@ export declare const authenticationApiDefinition: {
|
|
|
84
84
|
resource: string;
|
|
85
85
|
method: "POST";
|
|
86
86
|
parameters: ObjectSchema<{
|
|
87
|
-
token: string;
|
|
88
|
-
newSecret: string;
|
|
87
|
+
readonly token: string;
|
|
88
|
+
readonly newSecret: string;
|
|
89
89
|
}>;
|
|
90
90
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
91
91
|
};
|
|
@@ -93,7 +93,7 @@ export declare const authenticationApiDefinition: {
|
|
|
93
93
|
resource: string;
|
|
94
94
|
method: "POST";
|
|
95
95
|
parameters: ObjectSchema<{
|
|
96
|
-
secret: string;
|
|
96
|
+
readonly secret: string;
|
|
97
97
|
}>;
|
|
98
98
|
result: typeof SecretCheckResult;
|
|
99
99
|
};
|
|
@@ -110,9 +110,9 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
110
110
|
resource: string;
|
|
111
111
|
method: "POST";
|
|
112
112
|
parameters: ObjectSchema<{
|
|
113
|
-
subject: string;
|
|
114
|
-
secret: string;
|
|
115
|
-
data: AuthenticationData;
|
|
113
|
+
readonly subject: string;
|
|
114
|
+
readonly secret: string;
|
|
115
|
+
readonly data: AuthenticationData;
|
|
116
116
|
}>;
|
|
117
117
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
118
118
|
credentials: true;
|
|
@@ -124,7 +124,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
124
124
|
resource: string;
|
|
125
125
|
method: "POST";
|
|
126
126
|
parameters: ObjectSchema<{
|
|
127
|
-
data: AuthenticationData;
|
|
127
|
+
readonly data: AuthenticationData;
|
|
128
128
|
}>;
|
|
129
129
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
130
130
|
credentials: true;
|
|
@@ -136,8 +136,8 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
136
136
|
resource: string;
|
|
137
137
|
method: "POST";
|
|
138
138
|
parameters: ObjectSchema<{
|
|
139
|
-
subject: string;
|
|
140
|
-
data: AuthenticationData;
|
|
139
|
+
readonly subject: string;
|
|
140
|
+
readonly data: AuthenticationData;
|
|
141
141
|
}>;
|
|
142
142
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
143
143
|
credentials: true;
|
|
@@ -149,7 +149,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
149
149
|
resource: string;
|
|
150
150
|
method: "POST";
|
|
151
151
|
parameters: ObjectSchema<{
|
|
152
|
-
data: AuthenticationData;
|
|
152
|
+
readonly data: AuthenticationData;
|
|
153
153
|
}>;
|
|
154
154
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
155
155
|
credentials: true;
|
|
@@ -170,8 +170,8 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
170
170
|
resource: string;
|
|
171
171
|
method: "POST";
|
|
172
172
|
parameters: ObjectSchema<{
|
|
173
|
-
subject: string;
|
|
174
|
-
data: AdditionalInitSecretResetData;
|
|
173
|
+
readonly subject: string;
|
|
174
|
+
readonly data: AdditionalInitSecretResetData;
|
|
175
175
|
}>;
|
|
176
176
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
177
177
|
};
|
|
@@ -179,8 +179,8 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
179
179
|
resource: string;
|
|
180
180
|
method: "POST";
|
|
181
181
|
parameters: ObjectSchema<{
|
|
182
|
-
token: string;
|
|
183
|
-
newSecret: string;
|
|
182
|
+
readonly token: string;
|
|
183
|
+
readonly newSecret: string;
|
|
184
184
|
}>;
|
|
185
185
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
186
186
|
};
|
|
@@ -188,7 +188,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
188
188
|
resource: string;
|
|
189
189
|
method: "POST";
|
|
190
190
|
parameters: ObjectSchema<{
|
|
191
|
-
secret: string;
|
|
191
|
+
readonly secret: string;
|
|
192
192
|
}>;
|
|
193
193
|
result: typeof SecretCheckResult;
|
|
194
194
|
};
|
|
@@ -203,9 +203,9 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
203
203
|
resource: string;
|
|
204
204
|
method: "POST";
|
|
205
205
|
parameters: ObjectSchema<{
|
|
206
|
-
subject: string;
|
|
207
|
-
secret: string;
|
|
208
|
-
data: AuthenticationData;
|
|
206
|
+
readonly subject: string;
|
|
207
|
+
readonly secret: string;
|
|
208
|
+
readonly data: AuthenticationData;
|
|
209
209
|
}>;
|
|
210
210
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
211
211
|
credentials: true;
|
|
@@ -217,7 +217,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
217
217
|
resource: string;
|
|
218
218
|
method: "POST";
|
|
219
219
|
parameters: ObjectSchema<{
|
|
220
|
-
data: AuthenticationData;
|
|
220
|
+
readonly data: AuthenticationData;
|
|
221
221
|
}>;
|
|
222
222
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
223
223
|
credentials: true;
|
|
@@ -229,8 +229,8 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
229
229
|
resource: string;
|
|
230
230
|
method: "POST";
|
|
231
231
|
parameters: ObjectSchema<{
|
|
232
|
-
subject: string;
|
|
233
|
-
data: AuthenticationData;
|
|
232
|
+
readonly subject: string;
|
|
233
|
+
readonly data: AuthenticationData;
|
|
234
234
|
}>;
|
|
235
235
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
236
236
|
credentials: true;
|
|
@@ -242,7 +242,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
242
242
|
resource: string;
|
|
243
243
|
method: "POST";
|
|
244
244
|
parameters: ObjectSchema<{
|
|
245
|
-
data: AuthenticationData;
|
|
245
|
+
readonly data: AuthenticationData;
|
|
246
246
|
}>;
|
|
247
247
|
result: ObjectSchema<TokenPayload<AdditionalTokenPayload>>;
|
|
248
248
|
credentials: true;
|
|
@@ -263,8 +263,8 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
263
263
|
resource: string;
|
|
264
264
|
method: "POST";
|
|
265
265
|
parameters: ObjectSchema<{
|
|
266
|
-
subject: string;
|
|
267
|
-
data: AdditionalInitSecretResetData;
|
|
266
|
+
readonly subject: string;
|
|
267
|
+
readonly data: AdditionalInitSecretResetData;
|
|
268
268
|
}>;
|
|
269
269
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
270
270
|
};
|
|
@@ -272,8 +272,8 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
272
272
|
resource: string;
|
|
273
273
|
method: "POST";
|
|
274
274
|
parameters: ObjectSchema<{
|
|
275
|
-
token: string;
|
|
276
|
-
newSecret: string;
|
|
275
|
+
readonly token: string;
|
|
276
|
+
readonly newSecret: string;
|
|
277
277
|
}>;
|
|
278
278
|
result: import("../schema/index.js").LiteralSchema<"ok">;
|
|
279
279
|
};
|
|
@@ -281,7 +281,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
281
281
|
resource: string;
|
|
282
282
|
method: "POST";
|
|
283
283
|
parameters: ObjectSchema<{
|
|
284
|
-
secret: string;
|
|
284
|
+
readonly secret: string;
|
|
285
285
|
}>;
|
|
286
286
|
result: typeof SecretCheckResult;
|
|
287
287
|
};
|
|
@@ -18,7 +18,7 @@ import { configureHttpClient } from '../../http/client/module.js';
|
|
|
18
18
|
import { configureNodeHttpServer } from '../../http/server/node/module.js';
|
|
19
19
|
import { inject } from '../../injector/inject.js';
|
|
20
20
|
import { WebServerModule } from '../../module/modules/web-server.module.js';
|
|
21
|
-
import {
|
|
21
|
+
import { NumberProperty, Property, array, boolean, number, object } from '../../schema/index.js';
|
|
22
22
|
import { timeout } from '../../utils/timing.js';
|
|
23
23
|
import { Agent } from 'undici';
|
|
24
24
|
class User {
|
|
@@ -26,7 +26,7 @@ class User {
|
|
|
26
26
|
name;
|
|
27
27
|
}
|
|
28
28
|
__decorate([
|
|
29
|
-
|
|
29
|
+
NumberProperty({ coerce: true }),
|
|
30
30
|
__metadata("design:type", Number)
|
|
31
31
|
], User.prototype, "id", void 0);
|
|
32
32
|
__decorate([
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Enumeration,
|
|
10
|
+
import { Enumeration, NumberProperty, Optional } from '../schema/index.js';
|
|
11
11
|
export var ImageResizeMode;
|
|
12
12
|
(function (ImageResizeMode) {
|
|
13
13
|
ImageResizeMode["Fit"] = "fit";
|
|
@@ -49,11 +49,11 @@ __decorate([
|
|
|
49
49
|
__metadata("design:type", String)
|
|
50
50
|
], ImageOptions.prototype, "resizeMode", void 0);
|
|
51
51
|
__decorate([
|
|
52
|
-
|
|
52
|
+
NumberProperty({ optional: true, coerce: true }),
|
|
53
53
|
__metadata("design:type", Number)
|
|
54
54
|
], ImageOptions.prototype, "width", void 0);
|
|
55
55
|
__decorate([
|
|
56
|
-
|
|
56
|
+
NumberProperty({ optional: true, coerce: true }),
|
|
57
57
|
__metadata("design:type", Number)
|
|
58
58
|
], ImageOptions.prototype, "height", void 0);
|
|
59
59
|
__decorate([
|
|
@@ -62,7 +62,7 @@ __decorate([
|
|
|
62
62
|
__metadata("design:type", String)
|
|
63
63
|
], ImageOptions.prototype, "origin", void 0);
|
|
64
64
|
__decorate([
|
|
65
|
-
|
|
65
|
+
NumberProperty({ optional: true, coerce: true }),
|
|
66
66
|
__metadata("design:type", Number)
|
|
67
67
|
], ImageOptions.prototype, "quality", void 0);
|
|
68
68
|
__decorate([
|
package/mail/mail.client.js
CHANGED
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Property } from '../schema/decorators/property.js';
|
|
11
|
-
import {
|
|
11
|
+
import { BooleanProperty } from '../schema/index.js';
|
|
12
12
|
import { Optional } from '../schema/schemas/optional.js';
|
|
13
13
|
export class MailClientAuthConfig {
|
|
14
14
|
user;
|
|
@@ -38,7 +38,7 @@ __decorate([
|
|
|
38
38
|
__metadata("design:type", Number)
|
|
39
39
|
], MailClientConfig.prototype, "port", void 0);
|
|
40
40
|
__decorate([
|
|
41
|
-
|
|
41
|
+
BooleanProperty({ optional: true }),
|
|
42
42
|
__metadata("design:type", Boolean)
|
|
43
43
|
], MailClientConfig.prototype, "secure", void 0);
|
|
44
44
|
__decorate([
|
package/orm/entity.js
CHANGED
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { NumberProperty, Property, any, record } from '../schema/index.js';
|
|
11
11
|
export class EntityMetadata {
|
|
12
12
|
revision;
|
|
13
13
|
revisionTimestamp;
|
|
@@ -28,7 +28,7 @@ __decorate([
|
|
|
28
28
|
__metadata("design:type", Number)
|
|
29
29
|
], EntityMetadata.prototype, "createTimestamp", void 0);
|
|
30
30
|
__decorate([
|
|
31
|
-
|
|
31
|
+
NumberProperty({ nullable: true }),
|
|
32
32
|
__metadata("design:type", Object)
|
|
33
33
|
], EntityMetadata.prototype, "deleteTimestamp", void 0);
|
|
34
34
|
__decorate([
|
|
@@ -19,8 +19,12 @@ export declare const mySchemaUsers: PgTableWithColumns<{
|
|
|
19
19
|
driverParam: string;
|
|
20
20
|
notNull: false;
|
|
21
21
|
hasDefault: false;
|
|
22
|
+
isPrimaryKey: false;
|
|
23
|
+
isAutoincrement: false;
|
|
24
|
+
hasRuntimeDefault: false;
|
|
22
25
|
enumValues: undefined;
|
|
23
26
|
baseColumn: never;
|
|
27
|
+
generated: undefined;
|
|
24
28
|
}, {}, {}>;
|
|
25
29
|
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
26
30
|
name: "name";
|
|
@@ -31,8 +35,12 @@ export declare const mySchemaUsers: PgTableWithColumns<{
|
|
|
31
35
|
driverParam: string;
|
|
32
36
|
notNull: false;
|
|
33
37
|
hasDefault: false;
|
|
38
|
+
isPrimaryKey: false;
|
|
39
|
+
isAutoincrement: false;
|
|
40
|
+
hasRuntimeDefault: false;
|
|
34
41
|
enumValues: [string, ...string[]];
|
|
35
42
|
baseColumn: never;
|
|
43
|
+
generated: undefined;
|
|
36
44
|
}, {}, {}>;
|
|
37
45
|
age: import("drizzle-orm/pg-core").PgColumn<{
|
|
38
46
|
name: "";
|
|
@@ -43,8 +51,12 @@ export declare const mySchemaUsers: PgTableWithColumns<{
|
|
|
43
51
|
driverParam: string | number;
|
|
44
52
|
notNull: false;
|
|
45
53
|
hasDefault: false;
|
|
54
|
+
isPrimaryKey: false;
|
|
55
|
+
isAutoincrement: false;
|
|
56
|
+
hasRuntimeDefault: false;
|
|
46
57
|
enumValues: undefined;
|
|
47
58
|
baseColumn: never;
|
|
59
|
+
generated: undefined;
|
|
48
60
|
}, {}, {}>;
|
|
49
61
|
color: import("drizzle-orm/pg-core").PgColumn<{
|
|
50
62
|
name: "color";
|
|
@@ -55,8 +67,12 @@ export declare const mySchemaUsers: PgTableWithColumns<{
|
|
|
55
67
|
driverParam: string;
|
|
56
68
|
notNull: false;
|
|
57
69
|
hasDefault: true;
|
|
70
|
+
isPrimaryKey: false;
|
|
71
|
+
isAutoincrement: false;
|
|
72
|
+
hasRuntimeDefault: false;
|
|
58
73
|
enumValues: ["red", "green", "blue"];
|
|
59
74
|
baseColumn: never;
|
|
75
|
+
generated: undefined;
|
|
60
76
|
}, {}, {}>;
|
|
61
77
|
};
|
|
62
78
|
dialect: "pg";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.91.0-
|
|
3
|
+
"version": "0.91.0-beta11",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"luxon": "^3.4",
|
|
112
112
|
"reflect-metadata": "^0.2",
|
|
113
113
|
"rxjs": "^7.8",
|
|
114
|
-
"type-fest": "4.
|
|
114
|
+
"type-fest": "4.22"
|
|
115
115
|
},
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@mxssfd/typedoc-theme": "1.1",
|
|
@@ -142,12 +142,12 @@
|
|
|
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.
|
|
145
|
+
"drizzle-orm": "^0.32",
|
|
146
146
|
"handlebars": "^4.7",
|
|
147
147
|
"koa": "^2.15",
|
|
148
148
|
"minio": "^8.0",
|
|
149
149
|
"mjml": "^4.15",
|
|
150
|
-
"mongodb": "^6.
|
|
150
|
+
"mongodb": "^6.8",
|
|
151
151
|
"nodemailer": "^6.9",
|
|
152
152
|
"pg": "^8.12",
|
|
153
153
|
"playwright": "^1.45",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
import { createPropertyOrAccessorDecorator } from '../../reflection/index.js';
|
|
3
|
-
|
|
3
|
+
import { filterUndefinedObjectProperties } from '../../utils/object/object.js';
|
|
4
|
+
export function createSchemaPropertyDecorator(data = {}) {
|
|
4
5
|
return createPropertyOrAccessorDecorator({
|
|
5
|
-
data: { schema: data },
|
|
6
|
+
data: { schema: filterUndefinedObjectProperties(data) },
|
|
6
7
|
mergeData: true
|
|
7
8
|
});
|
|
8
9
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -19,10 +19,11 @@ export type SchemaTestResult<T> = {
|
|
|
19
19
|
error: SchemaError;
|
|
20
20
|
};
|
|
21
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
22
|
export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
24
|
-
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ?
|
|
23
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
24
|
+
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export declare abstract class Schema<T = unknown> {
|
|
26
|
+
readonly [OPTIONAL]: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
28
29
|
* @param schema schema to test against
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class ArraySchema<T> extends Schema<T[]> {
|
|
5
6
|
readonly itemSchema: Schema<T>;
|
|
@@ -7,4 +8,4 @@ export declare class ArraySchema<T> extends Schema<T[]> {
|
|
|
7
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
|
|
8
9
|
}
|
|
9
10
|
export declare function array<T>(schema: SchemaTestable<T>): ArraySchema<T>;
|
|
10
|
-
export declare function Array(schema: SchemaTestable): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Array(schema: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
package/schema/schemas/array.js
CHANGED
|
@@ -11,21 +11,23 @@ export class ArraySchema extends Schema {
|
|
|
11
11
|
this.itemSchema = schemaTestableToSchema(itemSchema);
|
|
12
12
|
}
|
|
13
13
|
_test(value, path, options) {
|
|
14
|
-
if (isArray(value)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (!isArray(value)) {
|
|
15
|
+
return { valid: false, error: SchemaError.expectedButGot('array', typeOf(value), path) };
|
|
16
|
+
}
|
|
17
|
+
const values = [];
|
|
18
|
+
for (let i = 0; i < value.length; i++) {
|
|
19
|
+
const result = this.itemSchema._test(value[i], path.add(i), options);
|
|
20
|
+
if (!result.valid) {
|
|
21
|
+
return result;
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
values.push(result.value);
|
|
22
24
|
}
|
|
23
|
-
return { valid:
|
|
25
|
+
return { valid: true, value: values };
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
export function array(schema) {
|
|
27
29
|
return new ArraySchema(schema);
|
|
28
30
|
}
|
|
29
|
-
export function Array(schema) {
|
|
30
|
-
return Property(schema, { array: true });
|
|
31
|
+
export function Array(schema, options) {
|
|
32
|
+
return Property(schema, { ...options, array: true });
|
|
31
33
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
3
|
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
3
4
|
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class BigIntSchema extends Schema<bigint> {
|
|
5
6
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<bigint>;
|
|
6
7
|
}
|
|
7
8
|
export declare function bigint(): BigIntSchema;
|
|
8
|
-
export declare function
|
|
9
|
+
export declare function BigIntProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/bigint.js
CHANGED
|
@@ -7,9 +7,5 @@ export declare class BooleanSchema extends SimpleSchema<boolean> {
|
|
|
7
7
|
constructor(options?: BooleanSchemaOptions);
|
|
8
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<boolean>;
|
|
9
9
|
}
|
|
10
|
-
export declare function boolean(): BooleanSchema;
|
|
11
|
-
export declare function
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated use {@link Boolean()} instead
|
|
14
|
-
*/
|
|
15
|
-
export declare function BooleanProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
10
|
+
export declare function boolean(options?: BooleanSchemaOptions): BooleanSchema;
|
|
11
|
+
export declare function BooleanProperty(options?: BooleanSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -36,15 +36,9 @@ export class BooleanSchema extends SimpleSchema {
|
|
|
36
36
|
return { valid: false, error: SchemaError.expectedButGot('boolean', typeOf(value), path, { fast: options.fastErrors }) };
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
export function boolean() {
|
|
40
|
-
return new BooleanSchema();
|
|
39
|
+
export function boolean(options) {
|
|
40
|
+
return new BooleanSchema(options);
|
|
41
41
|
}
|
|
42
|
-
export function Boolean(options) {
|
|
43
|
-
return Property(boolean(), options);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated use {@link Boolean()} instead
|
|
47
|
-
*/
|
|
48
42
|
export function BooleanProperty(options) {
|
|
49
|
-
return
|
|
43
|
+
return Property(boolean(options), options);
|
|
50
44
|
}
|
package/schema/schemas/date.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare class DateSchema extends SimpleSchema<globalThis.Date> {
|
|
|
7
7
|
constructor(options?: DateSchemaOptions);
|
|
8
8
|
}
|
|
9
9
|
export declare function date(options?: DateSchemaOptions): DateSchema;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function DateProperty(options?: SchemaPropertyDecoratorOptions & DateSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/date.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
+
export type FunctionSchemaOptions = SimpleSchemaOptions;
|
|
4
|
+
export declare class FunctionSchema extends SimpleSchema<Function> {
|
|
5
|
+
constructor(options?: FunctionSchemaOptions);
|
|
6
|
+
}
|
|
7
|
+
export declare function func(): FunctionSchema;
|
|
8
|
+
export declare function FunctionProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isFunction } from '../../utils/type-guards.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { SimpleSchema } from './simple.js';
|
|
4
|
+
export class FunctionSchema extends SimpleSchema {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super('function', isFunction, options);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function func() {
|
|
10
|
+
return new FunctionSchema();
|
|
11
|
+
}
|
|
12
|
+
export function FunctionProperty(options) {
|
|
13
|
+
return Property(func(), options);
|
|
14
|
+
}
|
package/schema/schemas/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class NullableSchema<T> extends Schema<T | null> {
|
|
5
6
|
readonly schema: Schema<T>;
|
|
@@ -7,4 +8,4 @@ export declare class NullableSchema<T> extends Schema<T | null> {
|
|
|
7
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
|
|
8
9
|
}
|
|
9
10
|
export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
|
|
10
|
-
export declare function Nullable(): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Nullable(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
|
|
@@ -21,6 +21,6 @@ export class NullableSchema extends Schema {
|
|
|
21
21
|
export function nullable(schema) {
|
|
22
22
|
return new NullableSchema(schema);
|
|
23
23
|
}
|
|
24
|
-
export function Nullable() {
|
|
25
|
-
return createSchemaPropertyDecorator({ nullable: true });
|
|
24
|
+
export function Nullable(schema, options) {
|
|
25
|
+
return createSchemaPropertyDecorator({ schema, ...options, nullable: true });
|
|
26
26
|
}
|
|
@@ -7,9 +7,5 @@ export declare class NumberSchema extends SimpleSchema<number> {
|
|
|
7
7
|
constructor(options?: NumberSchemaOptions);
|
|
8
8
|
}
|
|
9
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
10
|
export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/number.js
CHANGED
|
@@ -24,15 +24,9 @@ export class NumberSchema extends SimpleSchema {
|
|
|
24
24
|
export function number(options) {
|
|
25
25
|
return new NumberSchema(options);
|
|
26
26
|
}
|
|
27
|
-
export function
|
|
27
|
+
export function NumberProperty(options) {
|
|
28
28
|
return Property(number(options), options);
|
|
29
29
|
}
|
|
30
30
|
export function Integer(options) {
|
|
31
31
|
return Property(number({ ...options, integer: true }), options);
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated use {@link Number()} instead
|
|
35
|
-
*/
|
|
36
|
-
export function NumberProperty(options) {
|
|
37
|
-
return Number(options);
|
|
38
|
-
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { EmptyObject, Merge } from 'type-fest';
|
|
2
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 {
|
|
3
|
+
import type { AbstractConstructor, OneOrMany, PartialProperty, Record as RecordType, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
4
|
+
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
5
|
+
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
6
|
+
import { type OPTIONAL, Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
7
|
+
export type Record<K extends PropertyKey = PropertyKey, V = any> = RecordType<K, V>;
|
|
5
8
|
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
6
9
|
export type ObjectSchemaFactory<T> = {
|
|
7
10
|
type: Type<T>;
|
|
@@ -19,6 +22,14 @@ export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey
|
|
|
19
22
|
factory?: ObjectSchemaFactory<T> | null;
|
|
20
23
|
};
|
|
21
24
|
export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
|
|
25
|
+
export type OptionalProperties<T> = {
|
|
26
|
+
[P in keyof T]: T[P] extends {
|
|
27
|
+
[OPTIONAL]: true;
|
|
28
|
+
} ? P : never;
|
|
29
|
+
}[keyof T];
|
|
30
|
+
export type ObjectSchemaPropertiesType<TP extends ObjectSchemaProperties> = SimplifyObject<{
|
|
31
|
+
[P in keyof PartialProperty<TP, OptionalProperties<TP>>]: SchemaOutput<TP[P]>;
|
|
32
|
+
}>;
|
|
22
33
|
export declare const tryGetSchemaFromReflection: typeof _tryGetSchemaFromReflection;
|
|
23
34
|
export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
|
|
24
35
|
private readonly propertyKeys;
|
|
@@ -31,45 +42,47 @@ export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
|
|
|
31
42
|
constructor(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>);
|
|
32
43
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
33
44
|
}
|
|
34
|
-
export declare function object<K extends PropertyKey, V>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, V>> & {
|
|
45
|
+
export declare function object<const K extends PropertyKey, const V>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, V>> & {
|
|
35
46
|
unknownProperties: SchemaTestable<V>;
|
|
36
47
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
37
48
|
}): ObjectSchema<Record<K, V>>;
|
|
38
|
-
export declare function object<K extends PropertyKey>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, unknown>> & {
|
|
49
|
+
export declare function object<const K extends PropertyKey>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, unknown>> & {
|
|
39
50
|
unknownProperties?: undefined;
|
|
40
51
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
41
52
|
}): ObjectSchema<Record<K, unknown>>;
|
|
42
|
-
export declare function object<V>(properties: Record<never>, options: ObjectSchemaOptions<Record<PropertyKey, V>> & {
|
|
53
|
+
export declare function object<const V>(properties: Record<never>, options: ObjectSchemaOptions<Record<PropertyKey, V>> & {
|
|
43
54
|
unknownProperties: SchemaTestable<V>;
|
|
44
55
|
unknownPropertiesKey?: undefined;
|
|
45
56
|
}): ObjectSchema<Record<PropertyKey, V>>;
|
|
46
|
-
export declare function object<
|
|
57
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, V>> & {
|
|
47
58
|
unknownProperties: SchemaTestable<V>;
|
|
48
59
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
49
|
-
}): ObjectSchema<
|
|
50
|
-
export declare function object<
|
|
60
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
|
|
61
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, unknown>> & {
|
|
51
62
|
unknownPropertiesKey: SchemaTestable<K>;
|
|
52
|
-
}): ObjectSchema<
|
|
53
|
-
export declare function object<
|
|
63
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, unknown>>;
|
|
64
|
+
export declare function object<const TP extends ObjectSchemaProperties, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>> & {
|
|
54
65
|
unknownProperties: SchemaTestable<V>;
|
|
55
|
-
}): ObjectSchema<
|
|
56
|
-
export declare function object<
|
|
66
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>>;
|
|
67
|
+
export declare function object<const TP extends ObjectSchemaProperties>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>> & {
|
|
57
68
|
unknownProperties?: undefined;
|
|
58
69
|
unknownPropertiesKey?: undefined;
|
|
59
|
-
}): ObjectSchema<
|
|
60
|
-
export declare function object<
|
|
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:
|
|
69
|
-
export declare function partial<T extends Record, K extends keyof T>(schema:
|
|
70
|
-
export declare function pick<T extends Record, K extends keyof T>(
|
|
71
|
-
export declare function omit<T extends Record, K extends keyof T>(
|
|
70
|
+
}): ObjectSchema<ObjectSchemaPropertiesType<TP>>;
|
|
71
|
+
export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>, K, V>): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
|
|
72
|
+
export declare function explicitObject<const T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>): ObjectSchema<T>;
|
|
73
|
+
export declare function record<const K extends PropertyKey, const V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
|
|
74
|
+
export declare function assign<const T1 extends Record, const T2 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>): ObjectSchema<Merge<T1, T2>>;
|
|
75
|
+
export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>): ObjectSchema<Merge<Merge<T1, T2>, T3>>;
|
|
76
|
+
export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record, const T4 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>>;
|
|
77
|
+
export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record, const T4 extends Record, const 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>>;
|
|
78
|
+
export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record, const T4 extends Record, const T5 extends Record, const 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>>;
|
|
79
|
+
export declare function partial<const T extends Record>(schema: ObjectSchemaOrType<T>): ObjectSchema<Partial<T>>;
|
|
80
|
+
export declare function partial<const T extends Record, const K extends keyof T>(schema: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<PartialProperty<T, K>>;
|
|
81
|
+
export declare function pick<const T extends Record, const K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Pick<T, K>>>;
|
|
82
|
+
export declare function omit<const T extends Record, const K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
72
83
|
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;
|
|
84
|
+
declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | ObjectSchema<T> | null;
|
|
85
|
+
export declare function getObjectSchema<T extends Record>(schemaOrType: SchemaTestable<T>): ObjectSchema<T>;
|
|
86
|
+
export declare function Record<K extends PropertyKey, V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
74
87
|
export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
|
|
75
88
|
export {};
|
package/schema/schemas/object.js
CHANGED
|
@@ -6,6 +6,7 @@ import { memoizeSingle } from '../../utils/function/memoize.js';
|
|
|
6
6
|
import { filterObject, mapObjectValues, objectKeys } from '../../utils/object/object.js';
|
|
7
7
|
import { assert, isDefined, isFunction, isLiteralObject, isNotNull, isNotNullOrUndefined, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
|
|
8
8
|
import { typeOf } from '../../utils/type-of.js';
|
|
9
|
+
import { Property } from '../decorators/index.js';
|
|
9
10
|
import { Schema } from '../schema.js';
|
|
10
11
|
import { schemaTestableToSchema } from '../testable.js';
|
|
11
12
|
import { array } from './array.js';
|
|
@@ -79,21 +80,15 @@ export function record(key, value, options) {
|
|
|
79
80
|
return object({}, { ...options, unknownPropertiesKey: key, unknownProperties: value });
|
|
80
81
|
}
|
|
81
82
|
export function assign(...schemasOrTypes) {
|
|
82
|
-
const schemas = schemasOrTypes.map(
|
|
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
|
-
});
|
|
83
|
+
const schemas = schemasOrTypes.map(getObjectSchema);
|
|
90
84
|
return object(schemas.reduce((result, schema) => ({ ...result, ...schema.properties }), {}), {
|
|
91
85
|
mask: schemas.findLast((schema) => isNotNull(schema.mask))?.mask,
|
|
92
86
|
unknownProperties: schemas.findLast((schema) => isNotNull(schema.unknownProperties))?.unknownProperties,
|
|
93
87
|
unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey
|
|
94
88
|
});
|
|
95
89
|
}
|
|
96
|
-
export function partial(
|
|
90
|
+
export function partial(schemaOrType, keyOrKeys) {
|
|
91
|
+
const schema = getObjectSchema(schemaOrType);
|
|
97
92
|
const keys = isUndefined(keyOrKeys) ? undefined : toArray(keyOrKeys);
|
|
98
93
|
const mapper = isUndefined(keys)
|
|
99
94
|
? (propertySchema) => optional(propertySchema)
|
|
@@ -104,7 +99,8 @@ export function partial(schema, keyOrKeys) {
|
|
|
104
99
|
unknownPropertiesKey: schema.unknownPropertiesKey
|
|
105
100
|
});
|
|
106
101
|
}
|
|
107
|
-
export function pick(
|
|
102
|
+
export function pick(schemaOrType, keys) {
|
|
103
|
+
const schema = getObjectSchema(schemaOrType);
|
|
108
104
|
const keyArray = toArray(keys);
|
|
109
105
|
return object(filterObject(schema.properties, (_, key) => keyArray.includes(key)), {
|
|
110
106
|
mask: schema.mask,
|
|
@@ -112,7 +108,8 @@ export function pick(schema, keys) {
|
|
|
112
108
|
unknownPropertiesKey: schema.unknownPropertiesKey
|
|
113
109
|
});
|
|
114
110
|
}
|
|
115
|
-
export function omit(
|
|
111
|
+
export function omit(schemaOrType, keys) {
|
|
112
|
+
const schema = getObjectSchema(schemaOrType);
|
|
116
113
|
const keysArray = toArray(keys);
|
|
117
114
|
return object(filterObject(schema.properties, (_, key) => !keysArray.includes(key)), {
|
|
118
115
|
mask: schema.mask,
|
|
@@ -158,7 +155,7 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
|
|
|
158
155
|
for (const [key, propertyMetadata] of metadata.properties) {
|
|
159
156
|
const reflectionData = propertyMetadata.data.tryGet('schema');
|
|
160
157
|
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.`);
|
|
158
|
+
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 this is wanted.`);
|
|
162
159
|
}
|
|
163
160
|
let propertySchema = reflectionData?.schema ?? propertyMetadata.type;
|
|
164
161
|
if (reflectionData?.array == true) {
|
|
@@ -174,4 +171,16 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
|
|
|
174
171
|
}
|
|
175
172
|
return properties;
|
|
176
173
|
}
|
|
174
|
+
export function getObjectSchema(schemaOrType) {
|
|
175
|
+
if (schemaOrType instanceof ObjectSchema) {
|
|
176
|
+
return schemaOrType;
|
|
177
|
+
}
|
|
178
|
+
if (isFunction(schemaOrType)) {
|
|
179
|
+
return getObjectSchema(getSchemaFromReflection(schemaOrType));
|
|
180
|
+
}
|
|
181
|
+
throw new Error('Could not infer ObjectSchema.');
|
|
182
|
+
}
|
|
183
|
+
export function Record(key, value, options) {
|
|
184
|
+
return Property(record(key, value, options), options);
|
|
185
|
+
}
|
|
177
186
|
export const emptyObjectSchema = explicitObject({});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
+
import { type OPTIONAL, Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
6
|
+
readonly [OPTIONAL]: true;
|
|
5
7
|
readonly schema: Schema<T>;
|
|
6
8
|
constructor(schema: SchemaTestable<T>);
|
|
7
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
|
|
8
10
|
}
|
|
9
11
|
export declare function optional<T>(schema: SchemaTestable<T>): OptionalSchema<T>;
|
|
10
|
-
export declare function Optional(schema?: SchemaTestable): SchemaPropertyDecorator;
|
|
12
|
+
export declare function Optional(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
2
|
-
import { createSchemaPropertyDecorator } from '../decorators/
|
|
2
|
+
import { createSchemaPropertyDecorator } from '../decorators/index.js';
|
|
3
3
|
import { Schema } from '../schema.js';
|
|
4
4
|
import { schemaTestableToSchema } from '../testable.js';
|
|
5
5
|
export class OptionalSchema extends Schema {
|
|
@@ -21,6 +21,6 @@ export class OptionalSchema extends Schema {
|
|
|
21
21
|
export function optional(schema) {
|
|
22
22
|
return new OptionalSchema(schema);
|
|
23
23
|
}
|
|
24
|
-
export function Optional(schema) {
|
|
25
|
-
return createSchemaPropertyDecorator({ schema, optional: true });
|
|
24
|
+
export function Optional(schema, options) {
|
|
25
|
+
return createSchemaPropertyDecorator({ schema, ...options, optional: true });
|
|
26
26
|
}
|
|
@@ -5,4 +5,4 @@ export declare class ReadableStreamSchema extends SimpleSchema<ReadableStream> {
|
|
|
5
5
|
constructor(options?: ReadableStreamSchemaOptions);
|
|
6
6
|
}
|
|
7
7
|
export declare function readableStream(options?: ReadableStreamSchemaOptions): ReadableStreamSchema;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function ReadableStreamProperty(options?: SchemaPropertyDecoratorOptions & ReadableStreamSchemaOptions): SchemaPropertyDecorator;
|
|
@@ -9,6 +9,6 @@ export class ReadableStreamSchema extends SimpleSchema {
|
|
|
9
9
|
export function readableStream(options) {
|
|
10
10
|
return new ReadableStreamSchema(options);
|
|
11
11
|
}
|
|
12
|
-
export function
|
|
12
|
+
export function ReadableStreamProperty(options) {
|
|
13
13
|
return Property(readableStream(options), options);
|
|
14
14
|
}
|
|
@@ -5,4 +5,4 @@ export declare class RegExpSchema extends SimpleSchema<RegExp> {
|
|
|
5
5
|
constructor(options?: RegExpSchemaOptions);
|
|
6
6
|
}
|
|
7
7
|
export declare function regExp(options?: RegExpSchemaOptions): RegExpSchema;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function RegExpProperty(options?: SchemaPropertyDecoratorOptions & RegExpSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/regexp.js
CHANGED
|
@@ -7,8 +7,4 @@ export declare class StringSchema extends SimpleSchema<string> {
|
|
|
7
7
|
constructor(options?: StringSchemaOptions);
|
|
8
8
|
}
|
|
9
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
10
|
export declare function StringProperty(options?: SchemaPropertyDecoratorOptions & StringSchemaOptions): SchemaPropertyDecorator;
|
package/schema/schemas/string.js
CHANGED
|
@@ -19,12 +19,6 @@ export class StringSchema extends SimpleSchema {
|
|
|
19
19
|
export function string(options) {
|
|
20
20
|
return new StringSchema(options);
|
|
21
21
|
}
|
|
22
|
-
export function String(options) {
|
|
23
|
-
return Property(string(options), options);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use {@link String()} instead
|
|
27
|
-
*/
|
|
28
22
|
export function StringProperty(options) {
|
|
29
|
-
return
|
|
23
|
+
return Property(string(options), options);
|
|
30
24
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import { type SchemaPropertyDecorator } from '../decorators/index.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
3
|
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
4
|
export declare class SymbolSchema extends Schema<symbol> {
|
|
5
5
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<symbol>;
|
|
6
6
|
}
|
|
7
7
|
export declare function symbol(): SymbolSchema;
|
|
8
|
-
export declare function
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated use {@link Symbol()} instead
|
|
11
|
-
*/
|
|
12
|
-
export declare function SymbolProperty(): SchemaPropertyDecorator;
|
|
8
|
+
export declare function SymbolProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/symbol.js
CHANGED
|
@@ -14,12 +14,6 @@ export class SymbolSchema extends Schema {
|
|
|
14
14
|
export function symbol() {
|
|
15
15
|
return new SymbolSchema();
|
|
16
16
|
}
|
|
17
|
-
export function
|
|
18
|
-
return Property(symbol());
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated use {@link Symbol()} instead
|
|
22
|
-
*/
|
|
23
|
-
export function SymbolProperty() {
|
|
24
|
-
return Symbol();
|
|
17
|
+
export function SymbolProperty(options) {
|
|
18
|
+
return Property(symbol(), options);
|
|
25
19
|
}
|
|
@@ -11,4 +11,4 @@ export declare class Uint8ArraySchema extends SimpleSchema<Uint8Array> {
|
|
|
11
11
|
constructor(options?: Uint8ArraySchemaOptions);
|
|
12
12
|
}
|
|
13
13
|
export declare function uint8Array(options?: Uint8ArraySchemaOptions): Uint8ArraySchema;
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function Uint8ArrayProperty(schemaOptions?: Uint8ArraySchemaOptions, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -6,8 +6,8 @@ export class Uint8ArraySchema extends SimpleSchema {
|
|
|
6
6
|
constructor(options) {
|
|
7
7
|
super('Uint8Array', isUint8Array, options, {
|
|
8
8
|
constraints: [
|
|
9
|
-
isDefined(options?.minimumLength) ? (value) => (value.byteLength >= options.minimumLength) ? ({ success: true }) : ({ success: false, error: `
|
|
10
|
-
isDefined(options?.maximumLength) ? (value) => (value.byteLength <= options.maximumLength) ? ({ success: true }) : ({ success: false, error: `
|
|
9
|
+
isDefined(options?.minimumLength) ? (value) => (value.byteLength >= options.minimumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at least ${options.minimumLength} bytes.` }) : null,
|
|
10
|
+
isDefined(options?.maximumLength) ? (value) => (value.byteLength <= options.maximumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at most ${options.maximumLength} bytes.` }) : null
|
|
11
11
|
]
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -15,6 +15,6 @@ export class Uint8ArraySchema extends SimpleSchema {
|
|
|
15
15
|
export function uint8Array(options) {
|
|
16
16
|
return new Uint8ArraySchema(options);
|
|
17
17
|
}
|
|
18
|
-
export function
|
|
18
|
+
export function Uint8ArrayProperty(schemaOptions, options) {
|
|
19
19
|
return Property(uint8Array(schemaOptions), options);
|
|
20
20
|
}
|
package/schema/testable.js
CHANGED
|
@@ -2,6 +2,7 @@ import { isFunction } from '../utils/type-guards.js';
|
|
|
2
2
|
import { Schema } from './schema.js';
|
|
3
3
|
import { bigint } from './schemas/bigint.js';
|
|
4
4
|
import { boolean } from './schemas/boolean.js';
|
|
5
|
+
import { func } from './schemas/function.js';
|
|
5
6
|
import { number } from './schemas/number.js';
|
|
6
7
|
import { getSchemaFromReflection } from './schemas/object.js';
|
|
7
8
|
import { string } from './schemas/string.js';
|
|
@@ -21,6 +22,8 @@ export function schemaTestableToSchema(testable) {
|
|
|
21
22
|
return bigint();
|
|
22
23
|
case Symbol:
|
|
23
24
|
return symbol();
|
|
25
|
+
case Function:
|
|
26
|
+
return func();
|
|
24
27
|
default:
|
|
25
28
|
return getSchemaFromReflection(testable);
|
|
26
29
|
}
|