@tstdl/base 0.90.92 → 0.91.0-beta10
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 +56 -57
- 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 +1 -1
- 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 +99 -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 +7 -5
- 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 +29 -19
- package/schema/schemas/bigint.d.ts +9 -0
- package/schema/schemas/bigint.js +19 -0
- package/schema/schemas/boolean.d.ts +11 -5
- package/schema/schemas/boolean.js +41 -6
- package/schema/schemas/date.d.ts +9 -7
- package/schema/schemas/date.js +24 -18
- 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/function.d.ts +8 -0
- package/schema/schemas/function.js +14 -0
- package/schema/schemas/index.d.ts +5 -6
- package/schema/schemas/index.js +5 -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 +9 -7
- package/schema/schemas/number.js +28 -23
- package/schema/schemas/object.d.ts +84 -7
- package/schema/schemas/object.js +180 -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 +10 -5
- package/schema/schemas/regexp.d.ts +8 -6
- package/schema/schemas/regexp.js +24 -6
- package/schema/schemas/simple.d.ts +27 -0
- package/schema/schemas/simple.js +57 -0
- package/schema/schemas/string.d.ts +9 -21
- package/schema/schemas/string.js +20 -34
- package/schema/schemas/symbol.d.ts +8 -0
- package/schema/schemas/symbol.js +19 -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 +33 -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
package/orm/repository.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export type EntityMetadataUpdate = {
|
|
|
19
19
|
export type EntityUpdate<T extends Entity> = Partial<TypedOmit<T, 'metadata'>> & EntityMetadataUpdate;
|
|
20
20
|
export declare abstract class EntityRepository<T extends Entity = Entity> {
|
|
21
21
|
readonly type: Type<T>;
|
|
22
|
-
|
|
22
|
+
readonly database: import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>>;
|
|
23
|
+
load(_id: string): Promise<T>;
|
|
23
24
|
abstract tryLoad(id: string): Promise<T | undefined>;
|
|
24
25
|
abstract loadByFilter(query: Query<T>, options?: LoadOptions<T>): Promise<T>;
|
|
25
26
|
abstract tryLoadByFilter(query: Query<T>, options?: LoadOptions<T>): Promise<T | undefined>;
|
|
@@ -33,7 +34,6 @@ export declare abstract class EntityRepository<T extends Entity = Entity> {
|
|
|
33
34
|
abstract countByFilter(query: Query<T>): Promise<number>;
|
|
34
35
|
abstract has(id: string): Promise<boolean>;
|
|
35
36
|
abstract hasByFilter(query: Query<T>): Promise<boolean>;
|
|
36
|
-
abstract hasMany(ids: string[]): Promise<string[]>;
|
|
37
37
|
abstract hasAll(ids: string[]): Promise<boolean>;
|
|
38
38
|
abstract insert(entity: NewEntity<T>): Promise<T>;
|
|
39
39
|
abstract insertMany(entities: NewEntity<T>[]): Promise<T[]>;
|
|
@@ -41,10 +41,8 @@ export declare abstract class EntityRepository<T extends Entity = Entity> {
|
|
|
41
41
|
abstract updateByFilter(query: Query<T>, update: EntityUpdate<T>): Promise<void>;
|
|
42
42
|
abstract updateMany(ids: string[], update: EntityUpdate<T>): Promise<void>;
|
|
43
43
|
abstract updateManyByFilter(filter: Query<T>, update: EntityUpdate<T>): Promise<void>;
|
|
44
|
-
abstract delete
|
|
45
|
-
abstract deleteMany
|
|
46
|
-
abstract
|
|
47
|
-
abstract
|
|
48
|
-
abstract deleteByFilter<U extends T = T>(query: Query<U>): Promise<boolean>;
|
|
49
|
-
abstract deleteManyByFilter<U extends T = T>(query: Query<U>): Promise<number>;
|
|
44
|
+
abstract delete(id: string): Promise<boolean>;
|
|
45
|
+
abstract deleteMany(ids: string[]): Promise<number>;
|
|
46
|
+
abstract deleteByFilter(query: Query<T>): Promise<boolean>;
|
|
47
|
+
abstract deleteManyByFilter(query: Query<T>): Promise<number>;
|
|
50
48
|
}
|
package/orm/repository.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { NotImplementedError } from '../errors/not-implemented.error.js';
|
|
2
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
1
3
|
export const repositoryType = Symbol('repositoryType');
|
|
2
4
|
export class EntityRepository {
|
|
3
5
|
type;
|
|
6
|
+
database = drizzle(null);
|
|
7
|
+
async load(_id) {
|
|
8
|
+
// const result = await this.database.select({ name2: mySchemaUsers.name }).from(mySchemaUsers).leftJoin();
|
|
9
|
+
throw new NotImplementedError();
|
|
10
|
+
}
|
|
4
11
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { boolean, doublePrecision, text, type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { GetTagMetadata, SnakeCase, Tagged } from 'type-fest';
|
|
3
|
+
import type { Type } from '../types.js';
|
|
4
|
+
import { BuildColumns, NotNull } from 'drizzle-orm';
|
|
5
|
+
import type { DbSchemaStatic } from './schema.js';
|
|
6
|
+
import { Integer } from './types.js';
|
|
7
|
+
export declare const mySchema: import("drizzle-orm/pg-core").PgSchema<"my_schema">;
|
|
8
|
+
export declare const colors: import("drizzle-orm/pg-core").PgEnum<["red", "green", "blue"]>;
|
|
9
|
+
export declare const mySchemaUsers: PgTableWithColumns<{
|
|
10
|
+
name: "users";
|
|
11
|
+
schema: "my_schema";
|
|
12
|
+
columns: {
|
|
13
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
14
|
+
name: "id";
|
|
15
|
+
tableName: "users";
|
|
16
|
+
dataType: "string";
|
|
17
|
+
columnType: "PgUUID";
|
|
18
|
+
data: string;
|
|
19
|
+
driverParam: string;
|
|
20
|
+
notNull: false;
|
|
21
|
+
hasDefault: false;
|
|
22
|
+
isPrimaryKey: false;
|
|
23
|
+
isAutoincrement: false;
|
|
24
|
+
hasRuntimeDefault: false;
|
|
25
|
+
enumValues: undefined;
|
|
26
|
+
baseColumn: never;
|
|
27
|
+
generated: undefined;
|
|
28
|
+
}, {}, {}>;
|
|
29
|
+
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
30
|
+
name: "name";
|
|
31
|
+
tableName: "users";
|
|
32
|
+
dataType: "string";
|
|
33
|
+
columnType: "PgText";
|
|
34
|
+
data: string;
|
|
35
|
+
driverParam: string;
|
|
36
|
+
notNull: false;
|
|
37
|
+
hasDefault: false;
|
|
38
|
+
isPrimaryKey: false;
|
|
39
|
+
isAutoincrement: false;
|
|
40
|
+
hasRuntimeDefault: false;
|
|
41
|
+
enumValues: [string, ...string[]];
|
|
42
|
+
baseColumn: never;
|
|
43
|
+
generated: undefined;
|
|
44
|
+
}, {}, {}>;
|
|
45
|
+
age: import("drizzle-orm/pg-core").PgColumn<{
|
|
46
|
+
name: "";
|
|
47
|
+
tableName: "users";
|
|
48
|
+
dataType: "number";
|
|
49
|
+
columnType: "PgInteger";
|
|
50
|
+
data: number;
|
|
51
|
+
driverParam: string | number;
|
|
52
|
+
notNull: false;
|
|
53
|
+
hasDefault: false;
|
|
54
|
+
isPrimaryKey: false;
|
|
55
|
+
isAutoincrement: false;
|
|
56
|
+
hasRuntimeDefault: false;
|
|
57
|
+
enumValues: undefined;
|
|
58
|
+
baseColumn: never;
|
|
59
|
+
generated: undefined;
|
|
60
|
+
}, {}, {}>;
|
|
61
|
+
color: import("drizzle-orm/pg-core").PgColumn<{
|
|
62
|
+
name: "color";
|
|
63
|
+
tableName: "users";
|
|
64
|
+
dataType: "string";
|
|
65
|
+
columnType: "PgEnumColumn";
|
|
66
|
+
data: "red" | "green" | "blue";
|
|
67
|
+
driverParam: string;
|
|
68
|
+
notNull: false;
|
|
69
|
+
hasDefault: true;
|
|
70
|
+
isPrimaryKey: false;
|
|
71
|
+
isAutoincrement: false;
|
|
72
|
+
hasRuntimeDefault: false;
|
|
73
|
+
enumValues: ["red", "green", "blue"];
|
|
74
|
+
baseColumn: never;
|
|
75
|
+
generated: undefined;
|
|
76
|
+
}, {}, {}>;
|
|
77
|
+
};
|
|
78
|
+
dialect: "pg";
|
|
79
|
+
}>;
|
|
80
|
+
type ColumnBase<Name extends string, T> = T extends Tagged<T, 'column', any> ? GetTagMetadata<T, 'column'> : T extends string ? ReturnType<typeof text<Name, string, [string, ...string[]]>> : T extends number ? ReturnType<typeof doublePrecision<Name>> : T extends boolean ? ReturnType<typeof boolean<Name>> : never;
|
|
81
|
+
type Column<Name extends string, T> = null extends T ? ColumnBase<Name, T> : NotNull<ColumnBase<Name, T>>;
|
|
82
|
+
export declare function getDrizzleSchemaFromType<T extends Type & DbSchemaStatic>(type: T): PgTableWithColumns<{
|
|
83
|
+
name: SnakeCase<T['entityName']>;
|
|
84
|
+
schema: '';
|
|
85
|
+
columns: BuildColumns<T['entityName'], {
|
|
86
|
+
[P in keyof InstanceType<T>]: Column<Extract<P, string>, InstanceType<T>[P]>;
|
|
87
|
+
}, 'pg'>;
|
|
88
|
+
dialect: '';
|
|
89
|
+
}>;
|
|
90
|
+
export declare class Entity2 {
|
|
91
|
+
id: string;
|
|
92
|
+
}
|
|
93
|
+
export declare class User extends Entity2 {
|
|
94
|
+
static entityName: 'UserData';
|
|
95
|
+
name: string;
|
|
96
|
+
age: Integer<'age'> | null;
|
|
97
|
+
hasAge: boolean;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -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-beta10",
|
|
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.22"
|
|
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
|
-
"mongodb": "^6.
|
|
150
|
+
"mongodb": "^6.8",
|
|
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 {};
|