@tstdl/base 0.91.30 → 0.91.32
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/models/authentication-credentials.model.js +10 -10
- package/authentication/models/authentication-session.model.d.ts +2 -2
- package/authentication/models/authentication-session.model.js +16 -16
- package/authentication/models/init-secret-reset-data.model.js +3 -3
- package/authentication/models/token-payload-base.model.d.ts +4 -4
- package/authentication/models/token-payload-base.model.js +12 -12
- package/examples/api/basic-overview.js +2 -2
- package/examples/api/custom-authentication.js +3 -3
- package/examples/orm/user.model.js +3 -3
- package/mail/mail.client.js +5 -6
- package/orm/entity.js +3 -3
- package/package.json +2 -2
- package/schema/decorators/property.d.ts +4 -3
- package/schema/schemas/array.d.ts +6 -3
- package/schema/schemas/array.js +9 -4
- package/schema/schemas/deferred.d.ts +12 -0
- package/schema/schemas/deferred.js +23 -0
- package/schema/schemas/index.d.ts +1 -0
- package/schema/schemas/index.js +1 -0
- package/schema/schemas/number.d.ts +4 -0
- package/schema/schemas/number.js +6 -1
- package/schema/schemas/object.js +4 -1
- package/schema/schemas/string.d.ts +3 -0
- package/schema/schemas/string.js +8 -2
- package/schema/schemas/uint8-array.d.ts +3 -2
- package/schema/schemas/uint8-array.js +8 -5
- package/templates/resolvers/file.template-resolver.d.ts +1 -2
- package/templates/resolvers/file.template-resolver.js +2 -2
- package/templates/resolvers/jsx.template-resolver.d.ts +1 -3
- package/templates/resolvers/jsx.template-resolver.js +3 -7
- package/templates/template.model.d.ts +1 -1
- package/templates/template.model.js +5 -5
|
@@ -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, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
|
|
11
11
|
export class AuthenticationCredentials {
|
|
12
12
|
id;
|
|
13
13
|
subject;
|
|
@@ -16,23 +16,23 @@ export class AuthenticationCredentials {
|
|
|
16
16
|
hash;
|
|
17
17
|
}
|
|
18
18
|
__decorate([
|
|
19
|
-
|
|
19
|
+
StringProperty(),
|
|
20
20
|
__metadata("design:type", String)
|
|
21
21
|
], AuthenticationCredentials.prototype, "id", void 0);
|
|
22
22
|
__decorate([
|
|
23
|
-
|
|
23
|
+
StringProperty(),
|
|
24
24
|
__metadata("design:type", String)
|
|
25
25
|
], AuthenticationCredentials.prototype, "subject", void 0);
|
|
26
26
|
__decorate([
|
|
27
|
-
|
|
27
|
+
NumberProperty(),
|
|
28
28
|
__metadata("design:type", Number)
|
|
29
29
|
], AuthenticationCredentials.prototype, "hashVersion", void 0);
|
|
30
30
|
__decorate([
|
|
31
|
-
|
|
31
|
+
Uint8ArrayProperty(),
|
|
32
32
|
__metadata("design:type", Uint8Array)
|
|
33
33
|
], AuthenticationCredentials.prototype, "salt", void 0);
|
|
34
34
|
__decorate([
|
|
35
|
-
|
|
35
|
+
Uint8ArrayProperty(),
|
|
36
36
|
__metadata("design:type", Uint8Array)
|
|
37
37
|
], AuthenticationCredentials.prototype, "hash", void 0);
|
|
38
38
|
export class NewAuthenticationCredentials {
|
|
@@ -42,18 +42,18 @@ export class NewAuthenticationCredentials {
|
|
|
42
42
|
hash;
|
|
43
43
|
}
|
|
44
44
|
__decorate([
|
|
45
|
-
|
|
45
|
+
StringProperty(),
|
|
46
46
|
__metadata("design:type", String)
|
|
47
47
|
], NewAuthenticationCredentials.prototype, "subject", void 0);
|
|
48
48
|
__decorate([
|
|
49
|
-
|
|
49
|
+
NumberProperty(),
|
|
50
50
|
__metadata("design:type", Number)
|
|
51
51
|
], NewAuthenticationCredentials.prototype, "hashVersion", void 0);
|
|
52
52
|
__decorate([
|
|
53
|
-
|
|
53
|
+
Uint8ArrayProperty(),
|
|
54
54
|
__metadata("design:type", Uint8Array)
|
|
55
55
|
], NewAuthenticationCredentials.prototype, "salt", void 0);
|
|
56
56
|
__decorate([
|
|
57
|
-
|
|
57
|
+
Uint8ArrayProperty(),
|
|
58
58
|
__metadata("design:type", Uint8Array)
|
|
59
59
|
], NewAuthenticationCredentials.prototype, "hash", void 0);
|
|
@@ -7,44 +7,44 @@ 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, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
|
|
11
11
|
export class AuthenticationSession {
|
|
12
12
|
id;
|
|
13
13
|
subject;
|
|
14
|
-
/**
|
|
14
|
+
/** Timestamp */
|
|
15
15
|
begin;
|
|
16
|
-
/**
|
|
16
|
+
/** Timestamp */
|
|
17
17
|
end;
|
|
18
18
|
refreshTokenHashVersion;
|
|
19
19
|
refreshTokenSalt;
|
|
20
20
|
refreshTokenHash;
|
|
21
21
|
}
|
|
22
22
|
__decorate([
|
|
23
|
-
|
|
23
|
+
StringProperty(),
|
|
24
24
|
__metadata("design:type", String)
|
|
25
25
|
], AuthenticationSession.prototype, "id", void 0);
|
|
26
26
|
__decorate([
|
|
27
|
-
|
|
27
|
+
StringProperty(),
|
|
28
28
|
__metadata("design:type", String)
|
|
29
29
|
], AuthenticationSession.prototype, "subject", void 0);
|
|
30
30
|
__decorate([
|
|
31
|
-
|
|
31
|
+
NumberProperty(),
|
|
32
32
|
__metadata("design:type", Number)
|
|
33
33
|
], AuthenticationSession.prototype, "begin", void 0);
|
|
34
34
|
__decorate([
|
|
35
|
-
|
|
35
|
+
NumberProperty(),
|
|
36
36
|
__metadata("design:type", Number)
|
|
37
37
|
], AuthenticationSession.prototype, "end", void 0);
|
|
38
38
|
__decorate([
|
|
39
|
-
|
|
39
|
+
NumberProperty(),
|
|
40
40
|
__metadata("design:type", Number)
|
|
41
41
|
], AuthenticationSession.prototype, "refreshTokenHashVersion", void 0);
|
|
42
42
|
__decorate([
|
|
43
|
-
|
|
43
|
+
Uint8ArrayProperty(),
|
|
44
44
|
__metadata("design:type", Uint8Array)
|
|
45
45
|
], AuthenticationSession.prototype, "refreshTokenSalt", void 0);
|
|
46
46
|
__decorate([
|
|
47
|
-
|
|
47
|
+
Uint8ArrayProperty(),
|
|
48
48
|
__metadata("design:type", Uint8Array)
|
|
49
49
|
], AuthenticationSession.prototype, "refreshTokenHash", void 0);
|
|
50
50
|
export class NewAuthenticationSession {
|
|
@@ -56,26 +56,26 @@ export class NewAuthenticationSession {
|
|
|
56
56
|
refreshTokenHash;
|
|
57
57
|
}
|
|
58
58
|
__decorate([
|
|
59
|
-
|
|
59
|
+
StringProperty(),
|
|
60
60
|
__metadata("design:type", String)
|
|
61
61
|
], NewAuthenticationSession.prototype, "subject", void 0);
|
|
62
62
|
__decorate([
|
|
63
|
-
|
|
63
|
+
NumberProperty(),
|
|
64
64
|
__metadata("design:type", Number)
|
|
65
65
|
], NewAuthenticationSession.prototype, "begin", void 0);
|
|
66
66
|
__decorate([
|
|
67
|
-
|
|
67
|
+
NumberProperty(),
|
|
68
68
|
__metadata("design:type", Number)
|
|
69
69
|
], NewAuthenticationSession.prototype, "end", void 0);
|
|
70
70
|
__decorate([
|
|
71
|
-
|
|
71
|
+
NumberProperty(),
|
|
72
72
|
__metadata("design:type", Number)
|
|
73
73
|
], NewAuthenticationSession.prototype, "refreshTokenHashVersion", void 0);
|
|
74
74
|
__decorate([
|
|
75
|
-
|
|
75
|
+
Uint8ArrayProperty(),
|
|
76
76
|
__metadata("design:type", Uint8Array)
|
|
77
77
|
], NewAuthenticationSession.prototype, "refreshTokenSalt", void 0);
|
|
78
78
|
__decorate([
|
|
79
|
-
|
|
79
|
+
Uint8ArrayProperty(),
|
|
80
80
|
__metadata("design:type", Uint8Array)
|
|
81
81
|
], NewAuthenticationSession.prototype, "refreshTokenHash", void 0);
|
|
@@ -7,17 +7,17 @@ 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 { StringProperty } from '../../schema/index.js';
|
|
11
11
|
export class InitSecretResetData {
|
|
12
12
|
/** Subject is not checked for existence. */
|
|
13
13
|
subject;
|
|
14
14
|
token;
|
|
15
15
|
}
|
|
16
16
|
__decorate([
|
|
17
|
-
|
|
17
|
+
StringProperty(),
|
|
18
18
|
__metadata("design:type", String)
|
|
19
19
|
], InitSecretResetData.prototype, "subject", void 0);
|
|
20
20
|
__decorate([
|
|
21
|
-
|
|
21
|
+
StringProperty(),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], InitSecretResetData.prototype, "token", void 0);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare class TokenPayloadBase {
|
|
2
|
-
/**
|
|
2
|
+
/** Token id */
|
|
3
3
|
jti: string;
|
|
4
|
-
/**
|
|
4
|
+
/** Issue timestamp in seconds */
|
|
5
5
|
iat: number;
|
|
6
|
-
/**
|
|
6
|
+
/** Expiration timestamp in seconds */
|
|
7
7
|
exp: number;
|
|
8
|
-
/**
|
|
8
|
+
/** Refresh token expiration timestamp in seconds */
|
|
9
9
|
refreshTokenExp: number;
|
|
10
10
|
sessionId: string;
|
|
11
11
|
subject: string;
|
|
@@ -7,45 +7,45 @@ 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, StringProperty } from '../../schema/index.js';
|
|
11
11
|
export class TokenPayloadBase {
|
|
12
|
-
/**
|
|
12
|
+
/** Token id */
|
|
13
13
|
jti;
|
|
14
|
-
/**
|
|
14
|
+
/** Issue timestamp in seconds */
|
|
15
15
|
iat;
|
|
16
|
-
/**
|
|
16
|
+
/** Expiration timestamp in seconds */
|
|
17
17
|
exp;
|
|
18
|
-
/**
|
|
18
|
+
/** Refresh token expiration timestamp in seconds */
|
|
19
19
|
refreshTokenExp;
|
|
20
20
|
sessionId;
|
|
21
21
|
subject;
|
|
22
22
|
impersonator;
|
|
23
23
|
}
|
|
24
24
|
__decorate([
|
|
25
|
-
|
|
25
|
+
StringProperty(),
|
|
26
26
|
__metadata("design:type", String)
|
|
27
27
|
], TokenPayloadBase.prototype, "jti", void 0);
|
|
28
28
|
__decorate([
|
|
29
|
-
|
|
29
|
+
NumberProperty(),
|
|
30
30
|
__metadata("design:type", Number)
|
|
31
31
|
], TokenPayloadBase.prototype, "iat", void 0);
|
|
32
32
|
__decorate([
|
|
33
|
-
|
|
33
|
+
NumberProperty(),
|
|
34
34
|
__metadata("design:type", Number)
|
|
35
35
|
], TokenPayloadBase.prototype, "exp", void 0);
|
|
36
36
|
__decorate([
|
|
37
|
-
|
|
37
|
+
NumberProperty(),
|
|
38
38
|
__metadata("design:type", Number)
|
|
39
39
|
], TokenPayloadBase.prototype, "refreshTokenExp", void 0);
|
|
40
40
|
__decorate([
|
|
41
|
-
|
|
41
|
+
StringProperty(),
|
|
42
42
|
__metadata("design:type", String)
|
|
43
43
|
], TokenPayloadBase.prototype, "sessionId", void 0);
|
|
44
44
|
__decorate([
|
|
45
|
-
|
|
45
|
+
StringProperty(),
|
|
46
46
|
__metadata("design:type", String)
|
|
47
47
|
], TokenPayloadBase.prototype, "subject", void 0);
|
|
48
48
|
__decorate([
|
|
49
|
-
|
|
49
|
+
StringProperty({ optional: true }),
|
|
50
50
|
__metadata("design:type", String)
|
|
51
51
|
], TokenPayloadBase.prototype, "impersonator", void 0);
|
|
@@ -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 { NumberProperty,
|
|
21
|
+
import { NumberProperty, StringProperty, 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 {
|
|
@@ -30,7 +30,7 @@ __decorate([
|
|
|
30
30
|
__metadata("design:type", Number)
|
|
31
31
|
], User.prototype, "id", void 0);
|
|
32
32
|
__decorate([
|
|
33
|
-
|
|
33
|
+
StringProperty(),
|
|
34
34
|
__metadata("design:type", String)
|
|
35
35
|
], User.prototype, "name", void 0);
|
|
36
36
|
const users = [
|
|
@@ -26,7 +26,7 @@ import { Singleton } from '../../injector/decorators.js';
|
|
|
26
26
|
import { inject, injectAsync } from '../../injector/inject.js';
|
|
27
27
|
import { configureLocalMessageBus } from '../../message-bus/local/module.js';
|
|
28
28
|
import { WebServerModule } from '../../module/modules/index.js';
|
|
29
|
-
import {
|
|
29
|
+
import { StringProperty, emptyObjectSchema } from '../../schema/index.js';
|
|
30
30
|
import { configureDefaultSignalsImplementation } from '../../signals/implementation/configure.js';
|
|
31
31
|
import { first } from '../../utils/iterable-helpers/first.js';
|
|
32
32
|
import { skip } from '../../utils/iterable-helpers/skip.js';
|
|
@@ -57,14 +57,14 @@ class CustomTokenPaylod {
|
|
|
57
57
|
deviceRegistrationId;
|
|
58
58
|
}
|
|
59
59
|
__decorate([
|
|
60
|
-
|
|
60
|
+
StringProperty(),
|
|
61
61
|
__metadata("design:type", String)
|
|
62
62
|
], CustomTokenPaylod.prototype, "deviceRegistrationId", void 0);
|
|
63
63
|
class AuthenticationData {
|
|
64
64
|
deviceId;
|
|
65
65
|
}
|
|
66
66
|
__decorate([
|
|
67
|
-
|
|
67
|
+
StringProperty(),
|
|
68
68
|
__metadata("design:type", String)
|
|
69
69
|
], AuthenticationData.prototype, "deviceId", void 0);
|
|
70
70
|
const CustomAuthenticationApiClient = getAuthenticationApiClient(CustomTokenPaylod, AuthenticationData, emptyObjectSchema);
|
|
@@ -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 { Entity, Integer, Unique } from '../../orm/index.js';
|
|
11
|
-
import { Array,
|
|
11
|
+
import { Array, BooleanProperty, StringProperty } from '../../schema/index.js';
|
|
12
12
|
export class User extends Entity {
|
|
13
13
|
static entityName = 'User';
|
|
14
14
|
name;
|
|
@@ -18,7 +18,7 @@ export class User extends Entity {
|
|
|
18
18
|
mail;
|
|
19
19
|
}
|
|
20
20
|
__decorate([
|
|
21
|
-
|
|
21
|
+
StringProperty(),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], User.prototype, "name", void 0);
|
|
24
24
|
__decorate([
|
|
@@ -30,7 +30,7 @@ __decorate([
|
|
|
30
30
|
__metadata("design:type", Object)
|
|
31
31
|
], User.prototype, "age", void 0);
|
|
32
32
|
__decorate([
|
|
33
|
-
|
|
33
|
+
BooleanProperty(),
|
|
34
34
|
__metadata("design:type", Boolean)
|
|
35
35
|
], User.prototype, "hasAge", void 0);
|
|
36
36
|
__decorate([
|
package/mail/mail.client.js
CHANGED
|
@@ -7,19 +7,18 @@ 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 {
|
|
11
|
-
import { BooleanProperty } from '../schema/index.js';
|
|
10
|
+
import { BooleanProperty, NumberProperty, StringProperty } from '../schema/index.js';
|
|
12
11
|
import { Optional } from '../schema/schemas/optional.js';
|
|
13
12
|
export class MailClientAuthConfig {
|
|
14
13
|
user;
|
|
15
14
|
password;
|
|
16
15
|
}
|
|
17
16
|
__decorate([
|
|
18
|
-
|
|
17
|
+
StringProperty(),
|
|
19
18
|
__metadata("design:type", String)
|
|
20
19
|
], MailClientAuthConfig.prototype, "user", void 0);
|
|
21
20
|
__decorate([
|
|
22
|
-
|
|
21
|
+
StringProperty(),
|
|
23
22
|
__metadata("design:type", String)
|
|
24
23
|
], MailClientAuthConfig.prototype, "password", void 0);
|
|
25
24
|
export class MailClientConfig {
|
|
@@ -30,11 +29,11 @@ export class MailClientConfig {
|
|
|
30
29
|
auth;
|
|
31
30
|
}
|
|
32
31
|
__decorate([
|
|
33
|
-
|
|
32
|
+
StringProperty(),
|
|
34
33
|
__metadata("design:type", String)
|
|
35
34
|
], MailClientConfig.prototype, "host", void 0);
|
|
36
35
|
__decorate([
|
|
37
|
-
|
|
36
|
+
NumberProperty(),
|
|
38
37
|
__metadata("design:type", Number)
|
|
39
38
|
], MailClientConfig.prototype, "port", void 0);
|
|
40
39
|
__decorate([
|
package/orm/entity.js
CHANGED
|
@@ -18,15 +18,15 @@ export class EntityMetadata {
|
|
|
18
18
|
attributes;
|
|
19
19
|
}
|
|
20
20
|
__decorate([
|
|
21
|
-
|
|
21
|
+
NumberProperty(),
|
|
22
22
|
__metadata("design:type", Number)
|
|
23
23
|
], EntityMetadata.prototype, "revision", void 0);
|
|
24
24
|
__decorate([
|
|
25
|
-
|
|
25
|
+
NumberProperty(),
|
|
26
26
|
__metadata("design:type", Number)
|
|
27
27
|
], EntityMetadata.prototype, "revisionTimestamp", void 0);
|
|
28
28
|
__decorate([
|
|
29
|
-
|
|
29
|
+
NumberProperty(),
|
|
30
30
|
__metadata("design:type", Number)
|
|
31
31
|
], EntityMetadata.prototype, "createTimestamp", void 0);
|
|
32
32
|
__decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.32",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"koa": "^2.15",
|
|
153
153
|
"minio": "^8.0",
|
|
154
154
|
"mjml": "^4.15",
|
|
155
|
-
"mongodb": "^6.
|
|
155
|
+
"mongodb": "^6.10",
|
|
156
156
|
"nodemailer": "^6.9",
|
|
157
157
|
"pg": "8.13",
|
|
158
158
|
"playwright": "^1.48",
|
|
@@ -2,6 +2,7 @@ import type { Decorator } from '../../reflection/index.js';
|
|
|
2
2
|
import type { TypedOmit } from '../../types.js';
|
|
3
3
|
import type { SchemaTestable } from '../schema.js';
|
|
4
4
|
import type { SchemaPropertyReflectionData } from './types.js';
|
|
5
|
-
export type SchemaPropertyDecoratorOptions =
|
|
6
|
-
export
|
|
7
|
-
export declare function Property(options?:
|
|
5
|
+
export type SchemaPropertyDecoratorOptions = SchemaPropertyReflectionData;
|
|
6
|
+
export type SchemaPropertyDecoratorOptionsWithoutSchema = TypedOmit<SchemaPropertyReflectionData, 'schema'>;
|
|
7
|
+
export declare function Property(schema: SchemaTestable, options?: SchemaPropertyDecoratorOptionsWithoutSchema): Decorator<'property' | 'accessor'>;
|
|
8
|
+
export declare function Property(options: SchemaPropertyDecoratorOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -2,11 +2,14 @@ import type { JsonPath } from '../../json-path/json-path.js';
|
|
|
2
2
|
import type { TypedOmit } from '../../types.js';
|
|
3
3
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
import type { Coercible } from '../types.js';
|
|
6
|
+
export type ArraySchemaOptions = Coercible;
|
|
5
7
|
export declare class ArraySchema<T> extends Schema<T[]> {
|
|
8
|
+
#private;
|
|
6
9
|
readonly name: string;
|
|
7
10
|
readonly itemSchema: Schema<T>;
|
|
8
|
-
constructor(itemSchema: SchemaTestable<T
|
|
11
|
+
constructor(itemSchema: SchemaTestable<T>, options?: ArraySchemaOptions);
|
|
9
12
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
|
|
10
13
|
}
|
|
11
|
-
export declare function array<T>(schema: SchemaTestable<T
|
|
12
|
-
export declare function Array(schema: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
|
14
|
+
export declare function array<T>(schema: SchemaTestable<T>, options?: ArraySchemaOptions): ArraySchema<T>;
|
|
15
|
+
export declare function Array(schema: SchemaTestable, options?: ArraySchemaOptions & TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
package/schema/schemas/array.js
CHANGED
|
@@ -5,15 +5,20 @@ import { Property } from '../decorators/index.js';
|
|
|
5
5
|
import { Schema } from '../schema.js';
|
|
6
6
|
import { schemaTestableToSchema } from '../testable.js';
|
|
7
7
|
export class ArraySchema extends Schema {
|
|
8
|
+
#options;
|
|
8
9
|
name;
|
|
9
10
|
itemSchema;
|
|
10
|
-
constructor(itemSchema) {
|
|
11
|
+
constructor(itemSchema, options = {}) {
|
|
11
12
|
super();
|
|
13
|
+
this.#options = options;
|
|
12
14
|
this.itemSchema = schemaTestableToSchema(itemSchema);
|
|
13
15
|
this.name = `Array[${this.itemSchema.name}]`;
|
|
14
16
|
}
|
|
15
17
|
_test(value, path, options) {
|
|
16
18
|
if (!isArray(value)) {
|
|
19
|
+
if ((this.#options.coerce ?? options.coerce) == true) {
|
|
20
|
+
return this._test([value], path, options);
|
|
21
|
+
}
|
|
17
22
|
return { valid: false, error: SchemaError.expectedButGot('array', typeOf(value), path) };
|
|
18
23
|
}
|
|
19
24
|
const values = [];
|
|
@@ -27,9 +32,9 @@ export class ArraySchema extends Schema {
|
|
|
27
32
|
return { valid: true, value: values };
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
export function array(schema) {
|
|
31
|
-
return new ArraySchema(schema);
|
|
35
|
+
export function array(schema, options) {
|
|
36
|
+
return new ArraySchema(schema, options);
|
|
32
37
|
}
|
|
33
38
|
export function Array(schema, options) {
|
|
34
|
-
return Property(schema,
|
|
39
|
+
return Property(array(schema, options), options);
|
|
35
40
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
+
import { Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export declare class DeferredSchema<T extends SchemaTestable> extends Schema<SchemaOutput<T>> {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly testable: T;
|
|
7
|
+
readonly schema: Schema<SchemaOutput<T>>;
|
|
8
|
+
constructor(schema: () => T);
|
|
9
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<SchemaOutput<T>>;
|
|
10
|
+
}
|
|
11
|
+
export declare function deferred<T extends SchemaTestable>(schema: () => T): DeferredSchema<T>;
|
|
12
|
+
export declare function Deferred<T extends SchemaTestable>(schema: () => T, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
import { schemaTestableToSchema } from '../testable.js';
|
|
5
|
+
export class DeferredSchema extends Schema {
|
|
6
|
+
name;
|
|
7
|
+
testable;
|
|
8
|
+
schema;
|
|
9
|
+
constructor(schema) {
|
|
10
|
+
super();
|
|
11
|
+
lazyProperty(this, 'schema', () => schemaTestableToSchema(schema()));
|
|
12
|
+
lazyProperty(this, 'name', () => `Deferred[${this.schema.name}]`);
|
|
13
|
+
}
|
|
14
|
+
_test(value, path, options) {
|
|
15
|
+
return this.schema._test(value, path, options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function deferred(schema) {
|
|
19
|
+
return new DeferredSchema(schema);
|
|
20
|
+
}
|
|
21
|
+
export function Deferred(schema, options) {
|
|
22
|
+
return Property(deferred(schema), options);
|
|
23
|
+
}
|
package/schema/schemas/index.js
CHANGED
|
@@ -2,10 +2,14 @@ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } fro
|
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
3
|
export type NumberSchemaOptions = SimpleSchemaOptions & {
|
|
4
4
|
integer?: boolean;
|
|
5
|
+
minimum?: number;
|
|
6
|
+
maximum?: number;
|
|
5
7
|
};
|
|
6
8
|
export declare class NumberSchema extends SimpleSchema<number> {
|
|
7
9
|
readonly name = "number";
|
|
8
10
|
readonly integer: boolean;
|
|
11
|
+
readonly minimum: number | null;
|
|
12
|
+
readonly maximum: number | null;
|
|
9
13
|
constructor(options?: NumberSchemaOptions);
|
|
10
14
|
}
|
|
11
15
|
export declare function number(options?: NumberSchemaOptions): NumberSchema;
|
package/schema/schemas/number.js
CHANGED
|
@@ -5,6 +5,8 @@ import { SimpleSchema } from './simple.js';
|
|
|
5
5
|
export class NumberSchema extends SimpleSchema {
|
|
6
6
|
name = 'number';
|
|
7
7
|
integer;
|
|
8
|
+
minimum;
|
|
9
|
+
maximum;
|
|
8
10
|
constructor(options) {
|
|
9
11
|
super('number', isNumber, options, {
|
|
10
12
|
coercers: {
|
|
@@ -18,10 +20,13 @@ export class NumberSchema extends SimpleSchema {
|
|
|
18
20
|
bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false })
|
|
19
21
|
},
|
|
20
22
|
constraints: [
|
|
21
|
-
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: '
|
|
23
|
+
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'Value is not an integer.' }) : null,
|
|
24
|
+
isNumber(options?.minimum) ? (value) => (value >= this.minimum) ? ({ success: true }) : ({ success: false, error: `Value must be more than or equal to ${this.minimum}.` }) : null,
|
|
25
|
+
isNumber(options?.maximum) ? (value) => (value >= this.maximum) ? ({ success: true }) : ({ success: false, error: `Value must be less than or equal to ${this.maximum}.` }) : null
|
|
22
26
|
]
|
|
23
27
|
});
|
|
24
28
|
this.integer = options?.integer ?? false;
|
|
29
|
+
this.minimum = options?.minimum ?? null;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
export function number(options) {
|
package/schema/schemas/object.js
CHANGED
|
@@ -159,9 +159,12 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
|
|
|
159
159
|
for (const [key, propertyMetadata] of metadata.properties) {
|
|
160
160
|
const reflectionData = propertyMetadata.data.tryGet('schema');
|
|
161
161
|
if (isUndefined(reflectionData?.schema) && (propertyMetadata.type == Object)) {
|
|
162
|
-
throw new Error(`Schema of property "${String(key)}" on type ${type.name} is inferred as Object. This is most likely unwanted and happens
|
|
162
|
+
throw new Error(`Schema of property "${String(key)}" on type ${type.name} is inferred as Object. This is most likely unwanted and happens if the property is defined as partial or the type is an union. Use an explicit @Property(Object) if this is wanted.`);
|
|
163
163
|
}
|
|
164
164
|
let propertySchema = reflectionData?.schema ?? propertyMetadata.type;
|
|
165
|
+
if (isUndefined(propertySchema)) {
|
|
166
|
+
throw new Error(`Could not infer schema for "${String(key)}" on type ${type.name}. This happens if neither explicit @Property(type) is used nor reflection metadata is available.`);
|
|
167
|
+
}
|
|
165
168
|
if (reflectionData?.array == true) {
|
|
166
169
|
propertySchema = array(propertySchema);
|
|
167
170
|
}
|
|
@@ -2,9 +2,12 @@ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } fro
|
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
3
|
export type StringSchemaOptions = SimpleSchemaOptions & {
|
|
4
4
|
pattern?: RegExp | string;
|
|
5
|
+
lowercase?: boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare class StringSchema extends SimpleSchema<string> {
|
|
7
8
|
readonly name: string;
|
|
9
|
+
readonly pattern: RegExp | null;
|
|
10
|
+
readonly lowercase: boolean;
|
|
8
11
|
constructor(options?: StringSchemaOptions);
|
|
9
12
|
}
|
|
10
13
|
export declare function string(options?: StringSchemaOptions): StringSchema;
|
package/schema/schemas/string.js
CHANGED
|
@@ -3,8 +3,9 @@ import { Property } from '../decorators/index.js';
|
|
|
3
3
|
import { SimpleSchema } from './simple.js';
|
|
4
4
|
export class StringSchema extends SimpleSchema {
|
|
5
5
|
name = 'string';
|
|
6
|
+
pattern;
|
|
7
|
+
lowercase;
|
|
6
8
|
constructor(options) {
|
|
7
|
-
const pattern = isDefined(options?.pattern) ? isString(options.pattern) ? RegExp(options.pattern, 'u') : isRegExp(options.pattern) ? options.pattern : undefined : undefined;
|
|
8
9
|
super('string', isString, options, {
|
|
9
10
|
coercers: {
|
|
10
11
|
number: (value) => ({ success: true, value: globalThis.String(value), valid: true }),
|
|
@@ -12,9 +13,14 @@ export class StringSchema extends SimpleSchema {
|
|
|
12
13
|
bigint: (value) => ({ success: true, value: globalThis.String(value), valid: true })
|
|
13
14
|
},
|
|
14
15
|
constraints: [
|
|
15
|
-
isDefined(pattern) ? ((value) => pattern.test(value) ? ({ success: true }) : ({ success: false, error: 'Value did not match pattern.' })) : null
|
|
16
|
+
isDefined(options?.pattern) ? ((value) => this.pattern.test(value) ? ({ success: true }) : ({ success: false, error: 'Value did not match pattern.' })) : null
|
|
16
17
|
]
|
|
17
18
|
});
|
|
19
|
+
this.pattern = isString(options?.pattern)
|
|
20
|
+
? RegExp(options.pattern, 'u')
|
|
21
|
+
: isRegExp(options?.pattern)
|
|
22
|
+
? options.pattern
|
|
23
|
+
: null;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
export function string(options) {
|
|
@@ -8,8 +8,9 @@ export type Uint8ArraySchemaOptions = SimpleSchemaOptions & {
|
|
|
8
8
|
};
|
|
9
9
|
export declare class Uint8ArraySchema extends SimpleSchema<Uint8Array> {
|
|
10
10
|
readonly name = "Uint8Array";
|
|
11
|
-
readonly
|
|
11
|
+
readonly minimumLength: number | null;
|
|
12
|
+
readonly maximumLength: number | null;
|
|
12
13
|
constructor(options?: Uint8ArraySchemaOptions);
|
|
13
14
|
}
|
|
14
15
|
export declare function uint8Array(options?: Uint8ArraySchemaOptions): Uint8ArraySchema;
|
|
15
|
-
export declare function Uint8ArrayProperty(
|
|
16
|
+
export declare function Uint8ArrayProperty(options?: Uint8ArraySchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -3,19 +3,22 @@ import { Property } from '../decorators/index.js';
|
|
|
3
3
|
import { SimpleSchema } from './simple.js';
|
|
4
4
|
export class Uint8ArraySchema extends SimpleSchema {
|
|
5
5
|
name = 'Uint8Array';
|
|
6
|
-
|
|
6
|
+
minimumLength;
|
|
7
|
+
maximumLength;
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super('Uint8Array', isUint8Array, options, {
|
|
9
10
|
constraints: [
|
|
10
|
-
isDefined(options?.minimumLength) ? (value) => (value.byteLength >=
|
|
11
|
-
isDefined(options?.maximumLength) ? (value) => (value.byteLength <=
|
|
11
|
+
isDefined(options?.minimumLength) ? (value) => (value.byteLength >= this.minimumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at least ${this.minimumLength} bytes.` }) : null,
|
|
12
|
+
isDefined(options?.maximumLength) ? (value) => (value.byteLength <= this.maximumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at most ${this.maximumLength} bytes.` }) : null
|
|
12
13
|
]
|
|
13
14
|
});
|
|
15
|
+
this.minimumLength = options?.minimumLength ?? null;
|
|
16
|
+
this.maximumLength = options?.maximumLength ?? null;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
export function uint8Array(options) {
|
|
17
20
|
return new Uint8ArraySchema(options);
|
|
18
21
|
}
|
|
19
|
-
export function Uint8ArrayProperty(
|
|
20
|
-
return Property(uint8Array(
|
|
22
|
+
export function Uint8ArrayProperty(options) {
|
|
23
|
+
return Property(uint8Array(options), options);
|
|
21
24
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
1
|
+
import { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
3
2
|
import type { TypedOmit } from '../../types.js';
|
|
4
3
|
import { TemplateField } from '../template.model.js';
|
|
5
4
|
import type { TemplateRenderer, TemplateRendererOptions, TemplateRendererString } from '../template.renderer.js';
|
|
@@ -14,7 +14,7 @@ import * as fs from 'node:fs/promises';
|
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
16
16
|
import { InjectArg, Singleton } from '../../injector/decorators.js';
|
|
17
|
-
import {
|
|
17
|
+
import { StringProperty } from '../../schema/index.js';
|
|
18
18
|
import { TemplateField } from '../template.model.js';
|
|
19
19
|
import { TemplateResolver } from '../template.resolver.js';
|
|
20
20
|
export const fileTemplateProviderConfig = {};
|
|
@@ -22,7 +22,7 @@ export class FileTemplateField extends TemplateField {
|
|
|
22
22
|
templateFile;
|
|
23
23
|
}
|
|
24
24
|
__decorate([
|
|
25
|
-
|
|
25
|
+
StringProperty(),
|
|
26
26
|
__metadata("design:type", String)
|
|
27
27
|
], FileTemplateField.prototype, "templateFile", void 0);
|
|
28
28
|
let FileTemplateResolver = class FileTemplateResolver extends TemplateResolver {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PartialProperty, Record, TypedOmit } from '../../types.js';
|
|
2
2
|
import type { ComponentClass, FunctionComponent } from 'preact';
|
|
3
|
-
import
|
|
4
|
-
import { TemplateField } from '../template.model.js';
|
|
3
|
+
import { Template, TemplateField } from '../template.model.js';
|
|
5
4
|
import type { TemplateRenderer, TemplateRendererOptions, TemplateRendererString } from '../template.renderer.js';
|
|
6
5
|
import { TemplateResolver } from '../template.resolver.js';
|
|
7
6
|
export type JsxTemplate<Context extends Record = any> = FunctionComponent<Context> | ComponentClass<Context, any>;
|
|
@@ -9,7 +8,6 @@ export declare class JsxTemplateField<Renderer extends string = string, Options
|
|
|
9
8
|
template: JsxTemplate<Context>;
|
|
10
9
|
}
|
|
11
10
|
export declare class JsxTemplateResolver extends TemplateResolver<JsxTemplateField, JsxTemplate> {
|
|
12
|
-
constructor();
|
|
13
11
|
canHandle(resolver: string): boolean;
|
|
14
12
|
resolve(field: JsxTemplateField): JsxTemplate;
|
|
15
13
|
}
|
|
@@ -8,20 +8,17 @@ 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 { Singleton } from '../../injector/decorators.js';
|
|
11
|
-
import {
|
|
11
|
+
import { FunctionProperty } from '../../schema/index.js';
|
|
12
12
|
import { TemplateField, simpleTemplate } from '../template.model.js';
|
|
13
13
|
import { TemplateResolver } from '../template.resolver.js';
|
|
14
14
|
export class JsxTemplateField extends TemplateField {
|
|
15
15
|
template;
|
|
16
16
|
}
|
|
17
17
|
__decorate([
|
|
18
|
-
|
|
18
|
+
FunctionProperty(),
|
|
19
19
|
__metadata("design:type", Object)
|
|
20
20
|
], JsxTemplateField.prototype, "template", void 0);
|
|
21
21
|
let JsxTemplateResolver = class JsxTemplateResolver extends TemplateResolver {
|
|
22
|
-
constructor() {
|
|
23
|
-
super();
|
|
24
|
-
}
|
|
25
22
|
canHandle(resolver) {
|
|
26
23
|
return (resolver == 'jsx');
|
|
27
24
|
}
|
|
@@ -30,8 +27,7 @@ let JsxTemplateResolver = class JsxTemplateResolver extends TemplateResolver {
|
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
29
|
JsxTemplateResolver = __decorate([
|
|
33
|
-
Singleton()
|
|
34
|
-
__metadata("design:paramtypes", [])
|
|
30
|
+
Singleton()
|
|
35
31
|
], JsxTemplateResolver);
|
|
36
32
|
export { JsxTemplateResolver };
|
|
37
33
|
export function jsxTemplateField(field) {
|
|
@@ -14,7 +14,7 @@ export type TemplateFields<Fields extends Record<string, boolean>, Resolver exte
|
|
|
14
14
|
}>;
|
|
15
15
|
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any, Context extends Record = any> {
|
|
16
16
|
readonly [templateContext]?: (context: Context) => void;
|
|
17
|
-
/**
|
|
17
|
+
/** Name of template */
|
|
18
18
|
name: string;
|
|
19
19
|
fields: TemplateFields<Fields, string, string, any, Context>;
|
|
20
20
|
options?: TemplateOptions;
|
|
@@ -7,18 +7,18 @@ 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 { Any, any, Class, object, Optional, Property } from '../schema/index.js';
|
|
10
|
+
import { Any, any, Class, object, Optional, Property, StringProperty } from '../schema/index.js';
|
|
11
11
|
let TemplateField = class TemplateField {
|
|
12
12
|
resolver;
|
|
13
13
|
renderer;
|
|
14
14
|
options;
|
|
15
15
|
};
|
|
16
16
|
__decorate([
|
|
17
|
-
|
|
17
|
+
StringProperty(),
|
|
18
18
|
__metadata("design:type", String)
|
|
19
19
|
], TemplateField.prototype, "resolver", void 0);
|
|
20
20
|
__decorate([
|
|
21
|
-
|
|
21
|
+
StringProperty(),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], TemplateField.prototype, "renderer", void 0);
|
|
24
24
|
__decorate([
|
|
@@ -31,13 +31,13 @@ TemplateField = __decorate([
|
|
|
31
31
|
], TemplateField);
|
|
32
32
|
export { TemplateField };
|
|
33
33
|
export class Template {
|
|
34
|
-
/**
|
|
34
|
+
/** Name of template */
|
|
35
35
|
name;
|
|
36
36
|
fields;
|
|
37
37
|
options;
|
|
38
38
|
}
|
|
39
39
|
__decorate([
|
|
40
|
-
|
|
40
|
+
StringProperty(),
|
|
41
41
|
__metadata("design:type", String)
|
|
42
42
|
], Template.prototype, "name", void 0);
|
|
43
43
|
__decorate([
|