@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.
Files changed (253) hide show
  1. package/api/types.d.ts +1 -1
  2. package/authentication/authentication.api.d.ts +56 -57
  3. package/authentication/authentication.api.js +1 -6
  4. package/authentication/client/api.client.d.ts +4 -5
  5. package/authentication/client/api.client.js +1 -2
  6. package/authentication/client/http-client.middleware.d.ts +1 -1
  7. package/browser/pdf-options.js +8 -9
  8. package/errors/custom.error.d.ts +5 -5
  9. package/examples/api/basic-overview.js +4 -4
  10. package/http/client/http-client-request.d.ts +1 -2
  11. package/http/client/module.d.ts +1 -1
  12. package/image-service/image-service.js +4 -7
  13. package/mail/mail.client.d.ts +2 -2
  14. package/mail/mail.client.js +3 -5
  15. package/orm/decorators.d.ts +1 -0
  16. package/orm/decorators.js +4 -0
  17. package/orm/entity.js +1 -1
  18. package/orm/index.d.ts +4 -0
  19. package/orm/index.js +4 -0
  20. package/orm/repository.d.ts +6 -8
  21. package/orm/repository.js +7 -0
  22. package/orm/schema-converter.d.ts +99 -0
  23. package/orm/schema-converter.js +74 -0
  24. package/orm/schema.d.ts +3 -0
  25. package/orm/schema.js +1 -0
  26. package/orm/types.d.ts +8 -0
  27. package/orm/types.js +6 -0
  28. package/package.json +7 -5
  29. package/reflection/registry.d.ts +1 -1
  30. package/reflection/utils.d.ts +2 -2
  31. package/schema/decorators/class.d.ts +1 -1
  32. package/schema/decorators/index.d.ts +0 -2
  33. package/schema/decorators/index.js +0 -2
  34. package/schema/decorators/property.d.ts +6 -5
  35. package/schema/decorators/property.js +10 -14
  36. package/schema/decorators/types.d.ts +7 -12
  37. package/schema/decorators/utils.d.ts +2 -15
  38. package/schema/decorators/utils.js +4 -43
  39. package/schema/index.d.ts +1 -6
  40. package/schema/index.js +15 -6
  41. package/schema/schema.d.ts +89 -14
  42. package/schema/schema.error.d.ts +4 -6
  43. package/schema/schema.error.js +6 -10
  44. package/schema/schema.js +74 -276
  45. package/schema/schemas/any.d.ts +7 -5
  46. package/schema/schemas/any.js +10 -6
  47. package/schema/schemas/array.d.ts +11 -12
  48. package/schema/schemas/array.js +29 -19
  49. package/schema/schemas/bigint.d.ts +9 -0
  50. package/schema/schemas/bigint.js +19 -0
  51. package/schema/schemas/boolean.d.ts +11 -5
  52. package/schema/schemas/boolean.js +41 -6
  53. package/schema/schemas/date.d.ts +9 -7
  54. package/schema/schemas/date.js +24 -18
  55. package/schema/schemas/defaulted.d.ts +11 -6
  56. package/schema/schemas/defaulted.js +23 -8
  57. package/schema/schemas/enumeration.d.ts +10 -5
  58. package/schema/schemas/enumeration.js +25 -15
  59. package/schema/schemas/function.d.ts +8 -0
  60. package/schema/schemas/function.js +14 -0
  61. package/schema/schemas/index.d.ts +5 -6
  62. package/schema/schemas/index.js +5 -6
  63. package/schema/schemas/instance.d.ts +11 -3
  64. package/schema/schemas/instance.js +25 -4
  65. package/schema/schemas/literal.d.ts +10 -5
  66. package/schema/schemas/literal.js +25 -15
  67. package/schema/schemas/never.d.ts +6 -0
  68. package/schema/schemas/never.js +11 -0
  69. package/schema/schemas/nullable.d.ts +11 -6
  70. package/schema/schemas/nullable.js +24 -7
  71. package/schema/schemas/number.d.ts +9 -7
  72. package/schema/schemas/number.js +28 -23
  73. package/schema/schemas/object.d.ts +84 -7
  74. package/schema/schemas/object.js +180 -6
  75. package/schema/schemas/one-or-many.d.ts +10 -7
  76. package/schema/schemas/one-or-many.js +18 -11
  77. package/schema/schemas/optional.d.ts +11 -7
  78. package/schema/schemas/optional.js +24 -6
  79. package/schema/schemas/readable-stream.d.ts +8 -6
  80. package/schema/schemas/readable-stream.js +10 -5
  81. package/schema/schemas/regexp.d.ts +8 -6
  82. package/schema/schemas/regexp.js +24 -6
  83. package/schema/schemas/simple.d.ts +27 -0
  84. package/schema/schemas/simple.js +57 -0
  85. package/schema/schemas/string.d.ts +9 -21
  86. package/schema/schemas/string.js +20 -34
  87. package/schema/schemas/symbol.d.ts +8 -0
  88. package/schema/schemas/symbol.js +19 -0
  89. package/schema/schemas/transform.d.ts +9 -5
  90. package/schema/schemas/transform.js +19 -6
  91. package/schema/schemas/uint8-array.d.ts +9 -5
  92. package/schema/schemas/uint8-array.js +17 -26
  93. package/schema/schemas/union.d.ts +14 -7
  94. package/schema/schemas/union.js +30 -11
  95. package/schema/schemas/unknown.d.ts +7 -5
  96. package/schema/schemas/unknown.js +11 -7
  97. package/schema/testable.d.ts +3 -0
  98. package/schema/testable.js +33 -0
  99. package/schema/types.d.ts +31 -0
  100. package/schema/types.js +1 -0
  101. package/schema-old/decorators/class.d.ts +3 -0
  102. package/schema-old/decorators/class.js +5 -0
  103. package/schema-old/decorators/index.d.ts +6 -0
  104. package/schema-old/decorators/index.js +6 -0
  105. package/schema-old/decorators/property.d.ts +6 -0
  106. package/schema-old/decorators/property.js +17 -0
  107. package/schema-old/decorators/types.d.ts +19 -0
  108. package/schema-old/decorators/types.js +1 -0
  109. package/schema-old/decorators/utils.d.ts +15 -0
  110. package/schema-old/decorators/utils.js +48 -0
  111. package/schema-old/index.d.ts +10 -0
  112. package/schema-old/index.js +10 -0
  113. package/schema-old/schema.d.ts +15 -0
  114. package/schema-old/schema.error.d.ts +26 -0
  115. package/schema-old/schema.error.js +64 -0
  116. package/schema-old/schema.js +283 -0
  117. package/schema-old/schemas/any.d.ts +5 -0
  118. package/schema-old/schemas/any.js +9 -0
  119. package/schema-old/schemas/array.d.ts +12 -0
  120. package/schema-old/schemas/array.js +23 -0
  121. package/schema-old/schemas/boolean.d.ts +5 -0
  122. package/schema-old/schemas/boolean.js +9 -0
  123. package/schema-old/schemas/date.d.ts +8 -0
  124. package/schema-old/schemas/date.js +22 -0
  125. package/schema-old/schemas/defaulted.d.ts +6 -0
  126. package/schema-old/schemas/defaulted.js +10 -0
  127. package/schema-old/schemas/enumeration.d.ts +6 -0
  128. package/schema-old/schemas/enumeration.js +17 -0
  129. package/schema-old/schemas/index.d.ts +26 -0
  130. package/schema-old/schemas/index.js +26 -0
  131. package/schema-old/schemas/instance.d.ts +3 -0
  132. package/schema-old/schemas/instance.js +5 -0
  133. package/schema-old/schemas/literal.d.ts +5 -0
  134. package/schema-old/schemas/literal.js +17 -0
  135. package/schema-old/schemas/nullable.d.ts +6 -0
  136. package/schema-old/schemas/nullable.js +9 -0
  137. package/schema-old/schemas/number.d.ts +9 -0
  138. package/schema-old/schemas/number.js +27 -0
  139. package/schema-old/schemas/object.d.ts +7 -0
  140. package/schema-old/schemas/object.js +12 -0
  141. package/schema-old/schemas/one-or-many.d.ts +9 -0
  142. package/schema-old/schemas/one-or-many.js +15 -0
  143. package/schema-old/schemas/optional.d.ts +7 -0
  144. package/schema-old/schemas/optional.js +8 -0
  145. package/schema-old/schemas/readable-stream.d.ts +6 -0
  146. package/schema-old/schemas/readable-stream.js +9 -0
  147. package/schema-old/schemas/regexp.d.ts +6 -0
  148. package/schema-old/schemas/regexp.js +9 -0
  149. package/schema-old/schemas/string.d.ts +22 -0
  150. package/schema-old/schemas/string.js +38 -0
  151. package/schema-old/schemas/transform.d.ts +5 -0
  152. package/schema-old/schemas/transform.js +7 -0
  153. package/schema-old/schemas/uint8-array.d.ts +10 -0
  154. package/schema-old/schemas/uint8-array.js +29 -0
  155. package/schema-old/schemas/union.d.ts +7 -0
  156. package/schema-old/schemas/union.js +13 -0
  157. package/schema-old/schemas/unknown.d.ts +5 -0
  158. package/schema-old/schemas/unknown.js +9 -0
  159. package/templates/resolvers/string.template-resolver.d.ts +0 -1
  160. package/templates/resolvers/string.template-resolver.js +1 -5
  161. package/templates/template.model.js +1 -1
  162. package/types.d.ts +2 -0
  163. package/utils/type-guards.js +1 -1
  164. /package/{schema → schema-old}/array-constraints/index.d.ts +0 -0
  165. /package/{schema → schema-old}/array-constraints/index.js +0 -0
  166. /package/{schema → schema-old}/array-constraints/maximum-length.d.ts +0 -0
  167. /package/{schema → schema-old}/array-constraints/maximum-length.js +0 -0
  168. /package/{schema → schema-old}/array-constraints/minimum-length.d.ts +0 -0
  169. /package/{schema → schema-old}/array-constraints/minimum-length.js +0 -0
  170. /package/{schema → schema-old}/coercers/boolean.coercer.d.ts +0 -0
  171. /package/{schema → schema-old}/coercers/boolean.coercer.js +0 -0
  172. /package/{schema → schema-old}/coercers/date.coercer.d.ts +0 -0
  173. /package/{schema → schema-old}/coercers/date.coercer.js +0 -0
  174. /package/{schema → schema-old}/coercers/index.d.ts +0 -0
  175. /package/{schema → schema-old}/coercers/index.js +0 -0
  176. /package/{schema → schema-old}/coercers/number.coercer.d.ts +0 -0
  177. /package/{schema → schema-old}/coercers/number.coercer.js +0 -0
  178. /package/{schema → schema-old}/coercers/regexp.coercer.d.ts +0 -0
  179. /package/{schema → schema-old}/coercers/regexp.coercer.js +0 -0
  180. /package/{schema → schema-old}/coercers/string.coercer.d.ts +0 -0
  181. /package/{schema → schema-old}/coercers/string.coercer.js +0 -0
  182. /package/{schema → schema-old}/coercers/uint8-array.coercer.d.ts +0 -0
  183. /package/{schema → schema-old}/coercers/uint8-array.coercer.js +0 -0
  184. /package/{schema → schema-old}/constraints/enumeration.d.ts +0 -0
  185. /package/{schema → schema-old}/constraints/enumeration.js +0 -0
  186. /package/{schema → schema-old}/constraints/generic.d.ts +0 -0
  187. /package/{schema → schema-old}/constraints/generic.js +0 -0
  188. /package/{schema → schema-old}/constraints/index.d.ts +0 -0
  189. /package/{schema → schema-old}/constraints/index.js +0 -0
  190. /package/{schema → schema-old}/constraints/integer.d.ts +0 -0
  191. /package/{schema → schema-old}/constraints/integer.js +0 -0
  192. /package/{schema → schema-old}/constraints/length.d.ts +0 -0
  193. /package/{schema → schema-old}/constraints/length.js +0 -0
  194. /package/{schema → schema-old}/constraints/literal.d.ts +0 -0
  195. /package/{schema → schema-old}/constraints/literal.js +0 -0
  196. /package/{schema → schema-old}/constraints/maximum-date.d.ts +0 -0
  197. /package/{schema → schema-old}/constraints/maximum-date.js +0 -0
  198. /package/{schema → schema-old}/constraints/maximum-length.d.ts +0 -0
  199. /package/{schema → schema-old}/constraints/maximum-length.js +0 -0
  200. /package/{schema → schema-old}/constraints/maximum.d.ts +0 -0
  201. /package/{schema → schema-old}/constraints/maximum.js +0 -0
  202. /package/{schema → schema-old}/constraints/minimum-date.d.ts +0 -0
  203. /package/{schema → schema-old}/constraints/minimum-date.js +0 -0
  204. /package/{schema → schema-old}/constraints/minimum-length.d.ts +0 -0
  205. /package/{schema → schema-old}/constraints/minimum-length.js +0 -0
  206. /package/{schema → schema-old}/constraints/minimum.d.ts +0 -0
  207. /package/{schema → schema-old}/constraints/minimum.js +0 -0
  208. /package/{schema → schema-old}/constraints/pattern.d.ts +0 -0
  209. /package/{schema → schema-old}/constraints/pattern.js +0 -0
  210. /package/{schema → schema-old}/decorators/coerce.d.ts +0 -0
  211. /package/{schema → schema-old}/decorators/coerce.js +0 -0
  212. /package/{schema → schema-old}/decorators/constraint.d.ts +0 -0
  213. /package/{schema → schema-old}/decorators/constraint.js +0 -0
  214. /package/{schema → schema-old}/schemas/assign.d.ts +0 -0
  215. /package/{schema → schema-old}/schemas/assign.js +0 -0
  216. /package/{schema → schema-old}/schemas/constraint.d.ts +0 -0
  217. /package/{schema → schema-old}/schemas/constraint.js +0 -0
  218. /package/{schema → schema-old}/schemas/omit.d.ts +0 -0
  219. /package/{schema → schema-old}/schemas/omit.js +0 -0
  220. /package/{schema → schema-old}/schemas/partial.d.ts +0 -0
  221. /package/{schema → schema-old}/schemas/partial.js +0 -0
  222. /package/{schema → schema-old}/schemas/pick.d.ts +0 -0
  223. /package/{schema → schema-old}/schemas/pick.js +0 -0
  224. /package/{schema → schema-old}/schemas/record.d.ts +0 -0
  225. /package/{schema → schema-old}/schemas/record.js +0 -0
  226. /package/{schema → schema-old}/transformers/generic.d.ts +0 -0
  227. /package/{schema → schema-old}/transformers/generic.js +0 -0
  228. /package/{schema → schema-old}/transformers/index.d.ts +0 -0
  229. /package/{schema → schema-old}/transformers/index.js +0 -0
  230. /package/{schema → schema-old}/transformers/lowercase.d.ts +0 -0
  231. /package/{schema → schema-old}/transformers/lowercase.js +0 -0
  232. /package/{schema → schema-old}/transformers/trim.d.ts +0 -0
  233. /package/{schema → schema-old}/transformers/trim.js +0 -0
  234. /package/{schema → schema-old}/transformers/uppercase.d.ts +0 -0
  235. /package/{schema → schema-old}/transformers/uppercase.js +0 -0
  236. /package/{schema → schema-old}/types/index.d.ts +0 -0
  237. /package/{schema → schema-old}/types/index.js +0 -0
  238. /package/{schema → schema-old}/types/schema-array-constraint.d.ts +0 -0
  239. /package/{schema → schema-old}/types/schema-array-constraint.js +0 -0
  240. /package/{schema → schema-old}/types/schema-value-coercer.d.ts +0 -0
  241. /package/{schema → schema-old}/types/schema-value-coercer.js +0 -0
  242. /package/{schema → schema-old}/types/schema-value-constraint.d.ts +0 -0
  243. /package/{schema → schema-old}/types/schema-value-constraint.js +0 -0
  244. /package/{schema → schema-old}/types/schema-value-transformer.d.ts +0 -0
  245. /package/{schema → schema-old}/types/schema-value-transformer.js +0 -0
  246. /package/{schema → schema-old}/types/types.d.ts +0 -0
  247. /package/{schema → schema-old}/types/types.js +0 -0
  248. /package/{schema → schema-old}/utils/index.d.ts +0 -0
  249. /package/{schema → schema-old}/utils/index.js +0 -0
  250. /package/{schema → schema-old}/utils/schema.d.ts +0 -0
  251. /package/{schema → schema-old}/utils/schema.js +0 -0
  252. /package/{schema → schema-old}/utils/value-type.d.ts +0 -0
  253. /package/{schema → schema-old}/utils/value-type.js +0 -0
@@ -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
- abstract load(id: string): Promise<T>;
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<U extends T>(entity: U): Promise<boolean>;
45
- abstract deleteMany<U extends T>(entities: U[]): Promise<number>;
46
- abstract deleteById(id: string): Promise<boolean>;
47
- abstract deleteManyById(ids: string[]): Promise<number>;
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);
@@ -0,0 +1,3 @@
1
+ export interface DbSchemaStatic {
2
+ readonly entityName: string;
3
+ }
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.90.92",
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.20"
114
+ "type-fest": "4.22"
115
115
  },
116
116
  "devDependencies": {
117
117
  "@mxssfd/typedoc-theme": "1.1",
118
- "@stylistic/eslint-plugin": "2.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.14",
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.7",
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",
@@ -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
- /** undefined if class has no constructor */
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>;
@@ -5,9 +5,9 @@ export type CreateDecoratorTypeOptions = {
5
5
  };
6
6
  export type CreateDecoratorOptions = {
7
7
  data?: Record<string | symbol>;
8
- /** merge data values instead of replacing them (requires them to be objects, arrays, maps or sets) */
8
+ /** Merge data values instead of replacing them (requires them to be objects, arrays, maps or sets) */
9
9
  mergeData?: boolean;
10
- /** return values of these decorators are not used */
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,3 +1,3 @@
1
- import type { Decorator } from '../../reflection/index.js';
1
+ import { type Decorator } from '../../reflection/index.js';
2
2
  import type { SchemaTypeReflectionData } from './types.js';
3
3
  export declare function Class(options?: SchemaTypeReflectionData): Decorator<'class'>;
@@ -1,6 +1,4 @@
1
1
  export * from './class.js';
2
- export * from './coerce.js';
3
- export * from './constraint.js';
4
2
  export * from './property.js';
5
3
  export * from './types.js';
6
4
  export * from './utils.js';
@@ -1,6 +1,4 @@
1
1
  export * from './class.js';
2
- export * from './coerce.js';
3
- export * from './constraint.js';
4
2
  export * from './property.js';
5
3
  export * from './types.js';
6
4
  export * from './utils.js';
@@ -1,6 +1,7 @@
1
1
  import type { Decorator } from '../../reflection/index.js';
2
- import type { OneOrMany, TypedOmit } from '../../types.js';
3
- import type { ValueType } from '../types/index.js';
4
- import type { PropertyOptions } from './types.js';
5
- export declare function Property(options?: PropertyOptions): Decorator<'property' | 'accessor'>;
6
- export declare function Property(schema?: OneOrMany<ValueType>, options?: TypedOmit<PropertyOptions, 'schema'>): Decorator<'property' | 'accessor'>;
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 { toArray } from '../../utils/array/array.js';
3
- import { isDefined, isFunction, isString, isUndefined } from '../../utils/type-guards.js';
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(optionsOrTypes = {}, optionsOrNothing) {
7
- const schema = (isFunction(optionsOrTypes) || isString(optionsOrTypes)) ? typeSchema(optionsOrTypes) : undefined;
8
- const options = isUndefined(schema) ? optionsOrTypes : optionsOrNothing ?? {};
9
- return createSchemaPropertyDecorator({
10
- schema,
11
- ...options,
12
- coercers: isDefined(options.coercers) ? toArray(options.coercers) : undefined,
13
- transformers: isDefined(options.transformers) ? toArray(options.transformers) : undefined,
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 { OneOrMany } from '../../types.js';
1
+ import type { Decorator } from '../../reflection/types.js';
2
2
  import type { SchemaTestable } from '../schema.js';
3
- import type { ObjectSchema, SchemaArrayConstraint, SchemaFactoryFunction, SchemaValueCoercer, SchemaValueConstraint, SchemaValueTransformer, TypeSchema, ValueSchema, ValueType } from '../types/index.js';
4
- export type SchemaTypeReflectionData = Partial<Pick<ObjectSchema, 'mask' | 'unknownProperties' | 'unknownPropertiesKey'>> & {
5
- schema?: ObjectSchema | TypeSchema | ValueType;
6
- factory?: SchemaFactoryFunction<any>;
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?: OneOrMany<SchemaTestable>;
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 { Decorator, PropertyMetadata } from '../../reflection/index.js';
2
- import type { OneOrMany } from '../../types.js';
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 { toArray } from '../../utils/array/array.js';
4
- import { merge } from '../../utils/merge.js';
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
- handler(_, metadata) {
11
- const schemaData = getOrCreateSchemaPropertyReflectionData(metadata);
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 './transformers/index.js';
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
- export * from './array-constraints/index.js';
2
- export * from './coercers/index.js';
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 './transformers/index.js';
9
- export * from './types/index.js';
10
- export * from './utils/index.js';
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
+ };
@@ -1,15 +1,90 @@
1
- import { JsonPath } from '../json-path/index.js';
2
- import type { NormalizedObjectSchema, NormalizedTypeSchema, NormalizedValueSchema, ObjectSchema, SchemaOutput, SchemaTestOptions, SchemaTestResult, SchemaValueCoercer, TupleSchemaOutput, TypeSchema, ValueSchema, ValueType } from './types/index.js';
3
- export type Schema<T = any> = ObjectSchema<T> | ValueSchema<T> | TypeSchema<T>;
4
- export type SchemaTestable<T = any> = Schema<T> | ValueType<T>;
5
- export type NormalizedSchema<T = any> = NormalizedObjectSchema<T> | NormalizedValueSchema<T> | NormalizedTypeSchema<T>;
6
- export declare const Schema: {
7
- registerDefaultCoercer(coercer: SchemaValueCoercer): void;
8
- test<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
9
- validate<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions): boolean;
10
- parse<T>(schemaOrValueType: SchemaTestable<T>, value: unknown, options?: SchemaTestOptions): T;
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 declare function testSchema<T>(schema: Schema<T>, value: unknown, options?: SchemaTestOptions, path?: JsonPath): SchemaTestResult<T>;
15
- export declare function getExpectString(schema: SchemaTestable): string;
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 {};