@uql/core 3.1.0 → 3.1.2
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/CHANGELOG.md +134 -176
- package/README.md +413 -0
- package/package.json +31 -26
- package/dist/package.json +0 -131
- package/src/@types/index.d.ts +0 -1
- package/src/@types/jest.d.ts +0 -6
- package/src/browser/http/bus.spec.ts +0 -22
- package/src/browser/http/bus.ts +0 -17
- package/src/browser/http/http.spec.ts +0 -70
- package/src/browser/http/http.ts +0 -55
- package/src/browser/http/index.ts +0 -2
- package/src/browser/index.ts +0 -4
- package/src/browser/options.spec.ts +0 -37
- package/src/browser/options.ts +0 -18
- package/src/browser/querier/genericClientRepository.spec.ts +0 -105
- package/src/browser/querier/genericClientRepository.ts +0 -49
- package/src/browser/querier/httpQuerier.ts +0 -82
- package/src/browser/querier/index.ts +0 -3
- package/src/browser/querier/querier.util.spec.ts +0 -35
- package/src/browser/querier/querier.util.ts +0 -18
- package/src/browser/type/clientQuerier.ts +0 -45
- package/src/browser/type/clientQuerierPool.ts +0 -5
- package/src/browser/type/clientRepository.ts +0 -22
- package/src/browser/type/index.ts +0 -4
- package/src/browser/type/request.ts +0 -25
- package/src/dialect/abstractDialect.ts +0 -28
- package/src/dialect/abstractSqlDialect-spec.ts +0 -1309
- package/src/dialect/abstractSqlDialect.ts +0 -805
- package/src/dialect/index.ts +0 -3
- package/src/dialect/namingStrategy.spec.ts +0 -52
- package/src/dialect/queryContext.ts +0 -69
- package/src/entity/decorator/definition.spec.ts +0 -736
- package/src/entity/decorator/definition.ts +0 -265
- package/src/entity/decorator/entity.ts +0 -8
- package/src/entity/decorator/field.ts +0 -9
- package/src/entity/decorator/id.ts +0 -9
- package/src/entity/decorator/index.ts +0 -5
- package/src/entity/decorator/relation.spec.ts +0 -41
- package/src/entity/decorator/relation.ts +0 -34
- package/src/entity/index.ts +0 -1
- package/src/express/@types/express.d.ts +0 -8
- package/src/express/@types/index.d.ts +0 -1
- package/src/express/index.ts +0 -2
- package/src/express/querierMiddleware.ts +0 -217
- package/src/express/query.util.spec.ts +0 -40
- package/src/express/query.util.ts +0 -21
- package/src/index.ts +0 -9
- package/src/maria/index.ts +0 -3
- package/src/maria/mariaDialect.spec.ts +0 -207
- package/src/maria/mariaDialect.ts +0 -42
- package/src/maria/mariaQuerierPool.test.ts +0 -23
- package/src/maria/mariadbQuerier.test.ts +0 -23
- package/src/maria/mariadbQuerier.ts +0 -45
- package/src/maria/mariadbQuerierPool.ts +0 -21
- package/src/migrate/cli.ts +0 -301
- package/src/migrate/generator/index.ts +0 -4
- package/src/migrate/generator/mongoSchemaGenerator.spec.ts +0 -112
- package/src/migrate/generator/mongoSchemaGenerator.ts +0 -115
- package/src/migrate/generator/mysqlSchemaGenerator.spec.ts +0 -34
- package/src/migrate/generator/mysqlSchemaGenerator.ts +0 -92
- package/src/migrate/generator/postgresSchemaGenerator.spec.ts +0 -44
- package/src/migrate/generator/postgresSchemaGenerator.ts +0 -127
- package/src/migrate/generator/sqliteSchemaGenerator.spec.ts +0 -33
- package/src/migrate/generator/sqliteSchemaGenerator.ts +0 -81
- package/src/migrate/index.ts +0 -41
- package/src/migrate/introspection/index.ts +0 -4
- package/src/migrate/introspection/mongoIntrospector.spec.ts +0 -75
- package/src/migrate/introspection/mongoIntrospector.ts +0 -47
- package/src/migrate/introspection/mysqlIntrospector.spec.ts +0 -113
- package/src/migrate/introspection/mysqlIntrospector.ts +0 -278
- package/src/migrate/introspection/postgresIntrospector.spec.ts +0 -112
- package/src/migrate/introspection/postgresIntrospector.ts +0 -329
- package/src/migrate/introspection/sqliteIntrospector.spec.ts +0 -112
- package/src/migrate/introspection/sqliteIntrospector.ts +0 -296
- package/src/migrate/migrator-mongo.test.ts +0 -54
- package/src/migrate/migrator.spec.ts +0 -255
- package/src/migrate/migrator.test.ts +0 -94
- package/src/migrate/migrator.ts +0 -719
- package/src/migrate/namingStrategy.spec.ts +0 -22
- package/src/migrate/schemaGenerator-advanced.spec.ts +0 -138
- package/src/migrate/schemaGenerator.spec.ts +0 -190
- package/src/migrate/schemaGenerator.ts +0 -478
- package/src/migrate/storage/databaseStorage.spec.ts +0 -69
- package/src/migrate/storage/databaseStorage.ts +0 -100
- package/src/migrate/storage/index.ts +0 -2
- package/src/migrate/storage/jsonStorage.ts +0 -58
- package/src/migrate/type.ts +0 -1
- package/src/mongo/index.ts +0 -3
- package/src/mongo/mongoDialect.spec.ts +0 -251
- package/src/mongo/mongoDialect.ts +0 -238
- package/src/mongo/mongodbQuerier.test.ts +0 -45
- package/src/mongo/mongodbQuerier.ts +0 -256
- package/src/mongo/mongodbQuerierPool.test.ts +0 -25
- package/src/mongo/mongodbQuerierPool.ts +0 -24
- package/src/mysql/index.ts +0 -3
- package/src/mysql/mysql2Querier.test.ts +0 -20
- package/src/mysql/mysql2Querier.ts +0 -49
- package/src/mysql/mysql2QuerierPool.test.ts +0 -20
- package/src/mysql/mysql2QuerierPool.ts +0 -21
- package/src/mysql/mysqlDialect.spec.ts +0 -20
- package/src/mysql/mysqlDialect.ts +0 -16
- package/src/namingStrategy/defaultNamingStrategy.ts +0 -18
- package/src/namingStrategy/index.spec.ts +0 -36
- package/src/namingStrategy/index.ts +0 -2
- package/src/namingStrategy/snakeCaseNamingStrategy.ts +0 -15
- package/src/options.spec.ts +0 -41
- package/src/options.ts +0 -18
- package/src/postgres/index.ts +0 -3
- package/src/postgres/manual-types.d.ts +0 -4
- package/src/postgres/pgQuerier.test.ts +0 -25
- package/src/postgres/pgQuerier.ts +0 -45
- package/src/postgres/pgQuerierPool.test.ts +0 -28
- package/src/postgres/pgQuerierPool.ts +0 -21
- package/src/postgres/postgresDialect.spec.ts +0 -428
- package/src/postgres/postgresDialect.ts +0 -144
- package/src/querier/abstractQuerier-test.ts +0 -584
- package/src/querier/abstractQuerier.ts +0 -353
- package/src/querier/abstractQuerierPool-test.ts +0 -20
- package/src/querier/abstractQuerierPool.ts +0 -18
- package/src/querier/abstractSqlQuerier-spec.ts +0 -979
- package/src/querier/abstractSqlQuerier-test.ts +0 -21
- package/src/querier/abstractSqlQuerier.ts +0 -138
- package/src/querier/decorator/index.ts +0 -3
- package/src/querier/decorator/injectQuerier.spec.ts +0 -74
- package/src/querier/decorator/injectQuerier.ts +0 -45
- package/src/querier/decorator/serialized.spec.ts +0 -98
- package/src/querier/decorator/serialized.ts +0 -13
- package/src/querier/decorator/transactional.spec.ts +0 -240
- package/src/querier/decorator/transactional.ts +0 -56
- package/src/querier/index.ts +0 -4
- package/src/repository/genericRepository.spec.ts +0 -111
- package/src/repository/genericRepository.ts +0 -74
- package/src/repository/index.ts +0 -1
- package/src/sqlite/index.ts +0 -3
- package/src/sqlite/manual-types.d.ts +0 -4
- package/src/sqlite/sqliteDialect.spec.ts +0 -155
- package/src/sqlite/sqliteDialect.ts +0 -76
- package/src/sqlite/sqliteQuerier.spec.ts +0 -36
- package/src/sqlite/sqliteQuerier.test.ts +0 -21
- package/src/sqlite/sqliteQuerier.ts +0 -37
- package/src/sqlite/sqliteQuerierPool.test.ts +0 -12
- package/src/sqlite/sqliteQuerierPool.ts +0 -38
- package/src/test/entityMock.ts +0 -375
- package/src/test/index.ts +0 -3
- package/src/test/it.util.ts +0 -69
- package/src/test/spec.util.ts +0 -57
- package/src/type/entity.ts +0 -218
- package/src/type/index.ts +0 -9
- package/src/type/migration.ts +0 -241
- package/src/type/namingStrategy.ts +0 -17
- package/src/type/querier.ts +0 -143
- package/src/type/querierPool.ts +0 -26
- package/src/type/query.ts +0 -506
- package/src/type/repository.ts +0 -142
- package/src/type/universalQuerier.ts +0 -133
- package/src/type/utility.ts +0 -21
- package/src/util/dialect.util-extra.spec.ts +0 -96
- package/src/util/dialect.util.spec.ts +0 -23
- package/src/util/dialect.util.ts +0 -134
- package/src/util/index.ts +0 -5
- package/src/util/object.util.spec.ts +0 -29
- package/src/util/object.util.ts +0 -27
- package/src/util/raw.ts +0 -11
- package/src/util/sql.util-extra.spec.ts +0 -17
- package/src/util/sql.util.spec.ts +0 -208
- package/src/util/sql.util.ts +0 -104
- package/src/util/string.util.spec.ts +0 -46
- package/src/util/string.util.ts +0 -35
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -8
package/src/test/entityMock.ts
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { Entity, Field, Id, ManyToMany, ManyToOne, OneToMany, OneToOne } from '../entity/index.js';
|
|
3
|
-
import { idKey, type Relation } from '../type/index.js';
|
|
4
|
-
import { raw } from '../util/index.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* an `abstract` class can (optionally) be used as the base "template" for the entities
|
|
8
|
-
* (so common fields' declaration is easily reused).
|
|
9
|
-
*/
|
|
10
|
-
export abstract class BaseEntity {
|
|
11
|
-
/**
|
|
12
|
-
* auto-generated primary-key (when the `onInsert` property is omitted).
|
|
13
|
-
*/
|
|
14
|
-
@Id()
|
|
15
|
-
id?: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* foreign-keys are really simple to specify with the `reference` property.
|
|
19
|
-
*/
|
|
20
|
-
@Field({ reference: () => Company })
|
|
21
|
-
companyId?: number;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The `Relation` wrapper type can be used in ESM projects for the relations to
|
|
25
|
-
* avoid circular dependency issues.
|
|
26
|
-
*/
|
|
27
|
-
@ManyToOne({ entity: () => Company })
|
|
28
|
-
company?: Relation<Company>;
|
|
29
|
-
|
|
30
|
-
@Field({ reference: () => User })
|
|
31
|
-
creatorId?: number;
|
|
32
|
-
|
|
33
|
-
@ManyToOne({ entity: () => User })
|
|
34
|
-
creator?: Relation<User>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 'onInsert' property can be used to specify a custom mechanism for
|
|
38
|
-
* obtaining the value of a field when inserting:
|
|
39
|
-
*/
|
|
40
|
-
@Field({ onInsert: Date.now })
|
|
41
|
-
createdAt?: number;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 'onUpdate' property can be used to specify a custom mechanism for
|
|
45
|
-
* obtaining the value of a field when updating:
|
|
46
|
-
*/
|
|
47
|
-
@Field({ onUpdate: Date.now })
|
|
48
|
-
updatedAt?: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type CompanyKindKey = 'public' | 'private';
|
|
52
|
-
|
|
53
|
-
export type CompanyKind = { [k in CompanyKindKey]?: 0 | 1 };
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* `Company` will inherit all the fields (including the `Id`) declared in `BaseEntity`.
|
|
57
|
-
*/
|
|
58
|
-
@Entity()
|
|
59
|
-
export class Company extends BaseEntity {
|
|
60
|
-
@Field()
|
|
61
|
-
name?: string;
|
|
62
|
-
|
|
63
|
-
@Field()
|
|
64
|
-
description?: string;
|
|
65
|
-
|
|
66
|
-
@Field({ type: 'jsonb' })
|
|
67
|
-
kind?: CompanyKind;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* and entity can specify the table name.
|
|
72
|
-
*/
|
|
73
|
-
@Entity({ name: 'user_profile' })
|
|
74
|
-
export class Profile extends BaseEntity {
|
|
75
|
-
/**
|
|
76
|
-
* an entity can specify its own ID Field and still inherit the others
|
|
77
|
-
* columns/relations from its parent entity.
|
|
78
|
-
*/
|
|
79
|
-
@Id()
|
|
80
|
-
pk?: number;
|
|
81
|
-
|
|
82
|
-
@Field({ name: 'image' })
|
|
83
|
-
picture?: string;
|
|
84
|
-
|
|
85
|
-
@OneToOne({ entity: () => User })
|
|
86
|
-
declare creator?: Relation<User>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@Entity()
|
|
90
|
-
export class User extends BaseEntity {
|
|
91
|
-
@Field()
|
|
92
|
-
name?: string;
|
|
93
|
-
|
|
94
|
-
@Field({ updatable: false })
|
|
95
|
-
email?: string;
|
|
96
|
-
|
|
97
|
-
@Field({ eager: false })
|
|
98
|
-
password?: string;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* `mappedBy` property can be a callback or a string (callback is useful for auto-refactoring).
|
|
102
|
-
*/
|
|
103
|
-
@OneToOne({ entity: () => Profile, mappedBy: (profile) => profile.creator, cascade: true })
|
|
104
|
-
profile?: Profile;
|
|
105
|
-
|
|
106
|
-
@OneToMany({ entity: () => User, mappedBy: 'creator' })
|
|
107
|
-
users?: User[];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@Entity()
|
|
111
|
-
export class UserWithNonUpdatableId {
|
|
112
|
-
@Id({ updatable: false })
|
|
113
|
-
id: number;
|
|
114
|
-
|
|
115
|
-
@Field()
|
|
116
|
-
name: string;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Entity()
|
|
120
|
-
export class LedgerAccount extends BaseEntity {
|
|
121
|
-
@Field()
|
|
122
|
-
name?: string;
|
|
123
|
-
|
|
124
|
-
@Field()
|
|
125
|
-
description?: string;
|
|
126
|
-
|
|
127
|
-
@Field({ reference: () => LedgerAccount })
|
|
128
|
-
parentLedgerId?: number;
|
|
129
|
-
|
|
130
|
-
@ManyToOne()
|
|
131
|
-
parentLedger?: LedgerAccount;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@Entity()
|
|
135
|
-
export class TaxCategory extends BaseEntity {
|
|
136
|
-
/**
|
|
137
|
-
* `idKey` symbol can be used to specify the name of the identifier property,
|
|
138
|
-
* so the type of the identifier can always be type-safe
|
|
139
|
-
* (the identifiers named as `id` or `_id` are auto-inferred).
|
|
140
|
-
*/
|
|
141
|
-
[idKey]?: 'pk';
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* an entity can override the ID Field and still inherit the others
|
|
145
|
-
* columns/relations from its parent entity.
|
|
146
|
-
* 'onInsert' property can be used to specify a custom mechanism for
|
|
147
|
-
* auto-generating the primary-key's value when inserting.
|
|
148
|
-
*/
|
|
149
|
-
@Id({ onInsert: randomUUID })
|
|
150
|
-
pk?: string;
|
|
151
|
-
|
|
152
|
-
@Field()
|
|
153
|
-
name?: string;
|
|
154
|
-
|
|
155
|
-
@Field()
|
|
156
|
-
description?: string;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@Entity()
|
|
160
|
-
export class Tax extends BaseEntity {
|
|
161
|
-
@Field()
|
|
162
|
-
name?: string;
|
|
163
|
-
|
|
164
|
-
@Field()
|
|
165
|
-
percentage?: number;
|
|
166
|
-
|
|
167
|
-
@Field({ reference: () => TaxCategory })
|
|
168
|
-
categoryId?: string;
|
|
169
|
-
|
|
170
|
-
@ManyToOne()
|
|
171
|
-
category?: TaxCategory;
|
|
172
|
-
|
|
173
|
-
@Field()
|
|
174
|
-
description?: string;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* `softDelete` will make the entity "soft deletable".
|
|
179
|
-
*/
|
|
180
|
-
@Entity({ softDelete: true })
|
|
181
|
-
export class MeasureUnitCategory extends BaseEntity {
|
|
182
|
-
@Field()
|
|
183
|
-
name?: string;
|
|
184
|
-
|
|
185
|
-
@OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.categoryId })
|
|
186
|
-
measureUnits?: MeasureUnit[];
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* `onDelete` callback allows to specify which field will be used when deleting/querying this entity.
|
|
190
|
-
*/
|
|
191
|
-
@Field({ onDelete: Date.now })
|
|
192
|
-
deletedAt?: number;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
@Entity({ softDelete: true })
|
|
196
|
-
export class MeasureUnit extends BaseEntity {
|
|
197
|
-
@Field()
|
|
198
|
-
name?: string;
|
|
199
|
-
|
|
200
|
-
@Field({ reference: () => MeasureUnitCategory })
|
|
201
|
-
categoryId?: number;
|
|
202
|
-
|
|
203
|
-
@ManyToOne({ cascade: 'persist' })
|
|
204
|
-
category?: MeasureUnitCategory;
|
|
205
|
-
|
|
206
|
-
@Field({ onDelete: Date.now })
|
|
207
|
-
deletedAt?: number;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
@Entity()
|
|
211
|
-
export class Storehouse extends BaseEntity {
|
|
212
|
-
@Field()
|
|
213
|
-
name?: string;
|
|
214
|
-
|
|
215
|
-
@Field()
|
|
216
|
-
address?: string;
|
|
217
|
-
|
|
218
|
-
@Field()
|
|
219
|
-
description?: string;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
@Entity()
|
|
223
|
-
export class Item extends BaseEntity {
|
|
224
|
-
@Field()
|
|
225
|
-
name?: string;
|
|
226
|
-
|
|
227
|
-
@Field()
|
|
228
|
-
description?: string;
|
|
229
|
-
|
|
230
|
-
@Field()
|
|
231
|
-
code?: string;
|
|
232
|
-
|
|
233
|
-
@Field({ reference: () => LedgerAccount })
|
|
234
|
-
buyLedgerAccountId?: number;
|
|
235
|
-
|
|
236
|
-
@ManyToOne()
|
|
237
|
-
buyLedgerAccount?: LedgerAccount;
|
|
238
|
-
|
|
239
|
-
@Field({ reference: () => LedgerAccount })
|
|
240
|
-
saleLedgerAccountId?: number;
|
|
241
|
-
|
|
242
|
-
@ManyToOne()
|
|
243
|
-
saleLedgerAccount?: LedgerAccount;
|
|
244
|
-
|
|
245
|
-
@Field({ reference: () => Tax })
|
|
246
|
-
taxId?: number;
|
|
247
|
-
|
|
248
|
-
@ManyToOne()
|
|
249
|
-
tax?: Tax;
|
|
250
|
-
|
|
251
|
-
@Field({ reference: () => MeasureUnit })
|
|
252
|
-
measureUnitId?: number;
|
|
253
|
-
|
|
254
|
-
@ManyToOne()
|
|
255
|
-
measureUnit?: MeasureUnit;
|
|
256
|
-
|
|
257
|
-
@Field()
|
|
258
|
-
salePrice?: number;
|
|
259
|
-
|
|
260
|
-
@Field()
|
|
261
|
-
inventoryable?: boolean;
|
|
262
|
-
|
|
263
|
-
@ManyToMany({ entity: () => Tag, through: () => ItemTag, cascade: true })
|
|
264
|
-
tags?: Tag[];
|
|
265
|
-
|
|
266
|
-
@Field({
|
|
267
|
-
/**
|
|
268
|
-
* `virtual` property allows defining the value for a non-persistent field,
|
|
269
|
-
* such value might be a scalar or a (`raw`) function. Virtual-fields can
|
|
270
|
-
* be used in `$select` and `$where` as a common field whose value is
|
|
271
|
-
* replaced is replaced at runtime.
|
|
272
|
-
*/
|
|
273
|
-
virtual: raw(({ ctx, escapedPrefix, dialect }) => {
|
|
274
|
-
ctx.append('(');
|
|
275
|
-
dialect.count(
|
|
276
|
-
ctx,
|
|
277
|
-
ItemTag,
|
|
278
|
-
{
|
|
279
|
-
$where: {
|
|
280
|
-
itemId: raw(({ ctx }) => {
|
|
281
|
-
ctx.append(escapedPrefix + dialect.escapeId('id'));
|
|
282
|
-
}),
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
{ autoPrefix: true },
|
|
286
|
-
);
|
|
287
|
-
ctx.append(')');
|
|
288
|
-
}),
|
|
289
|
-
})
|
|
290
|
-
tagsCount?: number;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
@Entity()
|
|
294
|
-
export class Tag extends BaseEntity {
|
|
295
|
-
@Field()
|
|
296
|
-
name?: string;
|
|
297
|
-
|
|
298
|
-
@ManyToMany({ entity: () => Item, mappedBy: (item) => item.tags })
|
|
299
|
-
items?: Item[];
|
|
300
|
-
|
|
301
|
-
@Field({
|
|
302
|
-
virtual: raw(({ ctx, escapedPrefix, dialect }) => {
|
|
303
|
-
ctx.append('(');
|
|
304
|
-
dialect.count(
|
|
305
|
-
ctx,
|
|
306
|
-
ItemTag,
|
|
307
|
-
{
|
|
308
|
-
$where: {
|
|
309
|
-
tagId: raw(({ ctx }) => {
|
|
310
|
-
ctx.append(escapedPrefix + dialect.escapeId('id'));
|
|
311
|
-
}),
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
{ autoPrefix: true },
|
|
315
|
-
);
|
|
316
|
-
ctx.append(')');
|
|
317
|
-
}),
|
|
318
|
-
})
|
|
319
|
-
itemsCount?: number;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
@Entity()
|
|
323
|
-
export class ItemTag {
|
|
324
|
-
@Id()
|
|
325
|
-
id?: number;
|
|
326
|
-
|
|
327
|
-
@Field({ reference: () => Item })
|
|
328
|
-
itemId?: number;
|
|
329
|
-
|
|
330
|
-
@Field({ reference: () => Tag })
|
|
331
|
-
tagId?: number;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
@Entity()
|
|
335
|
-
export class InventoryAdjustment extends BaseEntity {
|
|
336
|
-
@OneToMany({
|
|
337
|
-
entity: () => ItemAdjustment,
|
|
338
|
-
mappedBy: (rel) => rel.inventoryAdjustment,
|
|
339
|
-
cascade: true,
|
|
340
|
-
})
|
|
341
|
-
itemAdjustments?: ItemAdjustment[];
|
|
342
|
-
|
|
343
|
-
@Field()
|
|
344
|
-
date?: Date;
|
|
345
|
-
|
|
346
|
-
@Field()
|
|
347
|
-
description?: string;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
@Entity()
|
|
351
|
-
export class ItemAdjustment extends BaseEntity {
|
|
352
|
-
@Field({ reference: () => Item })
|
|
353
|
-
itemId?: number;
|
|
354
|
-
|
|
355
|
-
@ManyToOne()
|
|
356
|
-
item?: Item;
|
|
357
|
-
|
|
358
|
-
@Field()
|
|
359
|
-
number?: number;
|
|
360
|
-
|
|
361
|
-
@Field()
|
|
362
|
-
buyPrice?: number;
|
|
363
|
-
|
|
364
|
-
@Field({ reference: () => Storehouse })
|
|
365
|
-
storehouseId?: number;
|
|
366
|
-
|
|
367
|
-
@ManyToOne()
|
|
368
|
-
storehouse?: Storehouse;
|
|
369
|
-
|
|
370
|
-
@Field({ reference: () => InventoryAdjustment })
|
|
371
|
-
inventoryAdjustmentId?: number;
|
|
372
|
-
|
|
373
|
-
@ManyToOne()
|
|
374
|
-
inventoryAdjustment?: InventoryAdjustment;
|
|
375
|
-
}
|
package/src/test/index.ts
DELETED
package/src/test/it.util.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { getEntities, getMeta } from '../entity/decorator/index.js';
|
|
2
|
-
import type { AbstractSqlQuerier } from '../querier/index.js';
|
|
3
|
-
import type { Type } from '../type/index.js';
|
|
4
|
-
import { getKeys } from '../util/index.js';
|
|
5
|
-
|
|
6
|
-
export async function createTables(querier: AbstractSqlQuerier, primaryKeyType: string) {
|
|
7
|
-
const entities = getEntities();
|
|
8
|
-
await Promise.all(
|
|
9
|
-
entities.map((entity) => {
|
|
10
|
-
const sql = getDdlForTable(entity, querier, primaryKeyType);
|
|
11
|
-
return querier.run(sql);
|
|
12
|
-
}),
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function dropTables(querier: AbstractSqlQuerier) {
|
|
17
|
-
const entities = getEntities();
|
|
18
|
-
await Promise.all(
|
|
19
|
-
entities.map((entity) => {
|
|
20
|
-
const meta = getMeta(entity);
|
|
21
|
-
const sql = `DROP TABLE IF EXISTS ${querier.dialect.escapeId(meta.name)}`;
|
|
22
|
-
return querier.run(sql);
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function clearTables(querier: AbstractSqlQuerier) {
|
|
28
|
-
const entities = getEntities();
|
|
29
|
-
await Promise.all(
|
|
30
|
-
entities.map((entity) => {
|
|
31
|
-
const ctx = querier.dialect.createContext();
|
|
32
|
-
querier.dialect.delete(ctx, entity, {});
|
|
33
|
-
return querier.run(ctx.sql, ctx.values);
|
|
34
|
-
}),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getDdlForTable<E>(entity: Type<E>, querier: AbstractSqlQuerier, primaryKeyType: string) {
|
|
39
|
-
const meta = getMeta(entity);
|
|
40
|
-
|
|
41
|
-
let sql = `CREATE TABLE ${querier.dialect.escapeId(meta.name)} (\n\t`;
|
|
42
|
-
|
|
43
|
-
const insertableIdType = 'VARCHAR(36)';
|
|
44
|
-
const defaultType = 'VARCHAR(255)';
|
|
45
|
-
|
|
46
|
-
const columns = getKeys(meta.fields).map((key) => {
|
|
47
|
-
const field = meta.fields[key];
|
|
48
|
-
let propSql = querier.dialect.escapeId(field.name) + ' ';
|
|
49
|
-
if (field.isId) {
|
|
50
|
-
propSql += field.onInsert ? `${insertableIdType} PRIMARY KEY` : primaryKeyType;
|
|
51
|
-
} else {
|
|
52
|
-
if (field.type === Number) {
|
|
53
|
-
propSql += 'BIGINT';
|
|
54
|
-
} else if (field.type === Date) {
|
|
55
|
-
propSql += 'TIMESTAMP';
|
|
56
|
-
} else {
|
|
57
|
-
propSql += defaultType;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return propSql;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
sql += columns.join(',\n\t');
|
|
64
|
-
sql += `\n);`;
|
|
65
|
-
|
|
66
|
-
// log('sql', sql);
|
|
67
|
-
|
|
68
|
-
return sql;
|
|
69
|
-
}
|
package/src/test/spec.util.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, it } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
export function createSpec<T extends Spec>(spec: T) {
|
|
4
|
-
const proto: FunctionConstructor = Object.getPrototypeOf(spec);
|
|
5
|
-
let describeFn: typeof describe;
|
|
6
|
-
const specName = proto.constructor.name;
|
|
7
|
-
|
|
8
|
-
if (specName.startsWith('fff')) {
|
|
9
|
-
describeFn = describe.only;
|
|
10
|
-
} else if (specName.startsWith('xxx')) {
|
|
11
|
-
describeFn = describe.skip;
|
|
12
|
-
} else {
|
|
13
|
-
describeFn = describe;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describeFn(specName, () => createTestCases(spec));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function createTestCases(spec: object) {
|
|
20
|
-
let proto: FunctionConstructor = Object.getPrototypeOf(spec);
|
|
21
|
-
|
|
22
|
-
const processedMethodsMap: { [k: string]: true } = {};
|
|
23
|
-
|
|
24
|
-
while (proto.constructor !== Object) {
|
|
25
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
26
|
-
const isProcessed = processedMethodsMap[key];
|
|
27
|
-
processedMethodsMap[key] = true;
|
|
28
|
-
if (isProcessed || key === 'constructor' || typeof spec[key] !== 'function') {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const callback: () => void | Promise<void> = spec[key].bind(spec);
|
|
32
|
-
if (hooks[key]) {
|
|
33
|
-
hooks[key](callback);
|
|
34
|
-
} else if (key.startsWith('should')) {
|
|
35
|
-
it(key, callback);
|
|
36
|
-
} else if (key.startsWith('fffShould')) {
|
|
37
|
-
it.only(key, callback);
|
|
38
|
-
} else if (key.startsWith('xxxShould')) {
|
|
39
|
-
it.skip(key, callback);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
proto = Object.getPrototypeOf(proto);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const hooks = {
|
|
47
|
-
beforeAll,
|
|
48
|
-
beforeEach,
|
|
49
|
-
afterEach,
|
|
50
|
-
afterAll,
|
|
51
|
-
} as const;
|
|
52
|
-
|
|
53
|
-
type SpecHooks = Partial<typeof hooks>;
|
|
54
|
-
|
|
55
|
-
export type Spec = SpecHooks & {
|
|
56
|
-
readonly [k: string]: (() => void | Promise<void>) | any;
|
|
57
|
-
};
|
package/src/type/entity.ts
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import type { QueryRaw } from './query.js';
|
|
2
|
-
import type { Scalar, Type } from './utility.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Allow to customize the name of the property that identifies an entity
|
|
6
|
-
*/
|
|
7
|
-
export const idKey = Symbol('idKey');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Infers the key names of an entity
|
|
11
|
-
*/
|
|
12
|
-
export type Key<E> = keyof E & string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Infers the field names of an entity
|
|
16
|
-
*/
|
|
17
|
-
export type FieldKey<E> = {
|
|
18
|
-
readonly [K in keyof E]: E[K] extends Scalar ? K : never;
|
|
19
|
-
}[Key<E>];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Infers the relation names of an entity
|
|
23
|
-
*/
|
|
24
|
-
export type RelationKey<E> = {
|
|
25
|
-
readonly [K in keyof E]: E[K] extends Scalar ? never : K;
|
|
26
|
-
}[Key<E>];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Infers the field values of an entity
|
|
30
|
-
*/
|
|
31
|
-
export type FieldValue<E> = E[FieldKey<E>];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Infers the name of the key identifier on an entity
|
|
35
|
-
*/
|
|
36
|
-
export type IdKey<E> = E extends { [idKey]?: infer K }
|
|
37
|
-
? K & FieldKey<E>
|
|
38
|
-
: E extends { _id?: unknown }
|
|
39
|
-
? '_id' & FieldKey<E>
|
|
40
|
-
: E extends { id?: unknown }
|
|
41
|
-
? 'id' & FieldKey<E>
|
|
42
|
-
: E extends { uuid?: unknown }
|
|
43
|
-
? 'uuid' & FieldKey<E>
|
|
44
|
-
: FieldKey<E>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Infers the value of the key identifier on an entity
|
|
48
|
-
*/
|
|
49
|
-
export type IdValue<E> = E[IdKey<E>];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Infers the values of the relations on an entity
|
|
53
|
-
*/
|
|
54
|
-
export type RelationValue<E> = E[RelationKey<E>];
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configurable options for an entity
|
|
58
|
-
*/
|
|
59
|
-
export type EntityOptions = {
|
|
60
|
-
readonly name?: string;
|
|
61
|
-
readonly softDelete?: boolean;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* SQL column types supported by uql migrations
|
|
66
|
-
*/
|
|
67
|
-
export type ColumnType =
|
|
68
|
-
| 'int'
|
|
69
|
-
| 'smallint'
|
|
70
|
-
| 'bigint'
|
|
71
|
-
| 'float'
|
|
72
|
-
| 'double'
|
|
73
|
-
| 'decimal'
|
|
74
|
-
| 'numeric'
|
|
75
|
-
| 'real'
|
|
76
|
-
| 'boolean'
|
|
77
|
-
| 'char'
|
|
78
|
-
| 'varchar'
|
|
79
|
-
| 'text'
|
|
80
|
-
| 'uuid'
|
|
81
|
-
| 'date'
|
|
82
|
-
| 'time'
|
|
83
|
-
| 'timestamp'
|
|
84
|
-
| 'timestamptz'
|
|
85
|
-
| 'json'
|
|
86
|
-
| 'jsonb'
|
|
87
|
-
| 'blob'
|
|
88
|
-
| 'bytea'
|
|
89
|
-
| 'vector'
|
|
90
|
-
| 'serial'
|
|
91
|
-
| 'bigserial';
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Configurable options for a field
|
|
95
|
-
*/
|
|
96
|
-
export type FieldOptions = {
|
|
97
|
-
readonly name?: string;
|
|
98
|
-
readonly isId?: true;
|
|
99
|
-
readonly type?: any;
|
|
100
|
-
readonly reference?: EntityGetter;
|
|
101
|
-
readonly virtual?: QueryRaw;
|
|
102
|
-
readonly updatable?: boolean;
|
|
103
|
-
readonly eager?: boolean;
|
|
104
|
-
readonly onInsert?: OnFieldCallback;
|
|
105
|
-
readonly onUpdate?: OnFieldCallback;
|
|
106
|
-
readonly onDelete?: OnFieldCallback;
|
|
107
|
-
|
|
108
|
-
// Schema/migration properties
|
|
109
|
-
/**
|
|
110
|
-
* SQL column type for migrations. If not specified, inferred from TypeScript type.
|
|
111
|
-
*/
|
|
112
|
-
readonly columnType?: ColumnType;
|
|
113
|
-
/**
|
|
114
|
-
* Column length (e.g., VARCHAR(100)). Defaults to 255 for varchar.
|
|
115
|
-
*/
|
|
116
|
-
readonly length?: number;
|
|
117
|
-
/**
|
|
118
|
-
* Precision for decimal/numeric types.
|
|
119
|
-
*/
|
|
120
|
-
readonly precision?: number;
|
|
121
|
-
/**
|
|
122
|
-
* Scale for decimal/numeric types.
|
|
123
|
-
*/
|
|
124
|
-
readonly scale?: number;
|
|
125
|
-
/**
|
|
126
|
-
* Whether the column allows NULL values. Defaults to true except for ID fields.
|
|
127
|
-
*/
|
|
128
|
-
readonly nullable?: boolean;
|
|
129
|
-
/**
|
|
130
|
-
* Whether the column has a UNIQUE constraint.
|
|
131
|
-
*/
|
|
132
|
-
readonly unique?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Default value for the column.
|
|
135
|
-
*/
|
|
136
|
-
readonly defaultValue?: Scalar | null;
|
|
137
|
-
/**
|
|
138
|
-
* Whether the column is auto-incrementing (for integer IDs).
|
|
139
|
-
*/
|
|
140
|
-
readonly autoIncrement?: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Index configuration. true for simple index, string for named index.
|
|
143
|
-
*/
|
|
144
|
-
readonly index?: boolean | string;
|
|
145
|
-
/**
|
|
146
|
-
* Column comment/description for database documentation.
|
|
147
|
-
*/
|
|
148
|
-
readonly comment?: string;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export type OnFieldCallback = Scalar | QueryRaw | (() => Scalar | QueryRaw);
|
|
152
|
-
|
|
153
|
-
export type EntityGetter<E = any> = () => Type<E>;
|
|
154
|
-
|
|
155
|
-
export type CascadeType = 'persist' | 'delete';
|
|
156
|
-
|
|
157
|
-
export type RelationOptions<E = any> = {
|
|
158
|
-
entity?: EntityGetter<E>;
|
|
159
|
-
cardinality: RelationCardinality;
|
|
160
|
-
readonly cascade?: boolean | CascadeType;
|
|
161
|
-
mappedBy?: RelationMappedBy<E>;
|
|
162
|
-
through?: EntityGetter<RelationValue<E>>;
|
|
163
|
-
references?: RelationReferences;
|
|
164
|
-
};
|
|
165
|
-
type RelationOptionsOwner<E> = Pick<RelationOptions<E>, 'entity' | 'references' | 'cascade'>;
|
|
166
|
-
type RelationOptionsInverseSide<E> = Required<Pick<RelationOptions<E>, 'entity' | 'mappedBy'>> &
|
|
167
|
-
Pick<RelationOptions<E>, 'cascade'>;
|
|
168
|
-
type RelationOptionsThroughOwner<E> = Required<Pick<RelationOptions<E>, 'entity'>> &
|
|
169
|
-
Pick<RelationOptions<E>, 'through' | 'references' | 'cascade'>;
|
|
170
|
-
|
|
171
|
-
export type RelationKeyMap<E> = { readonly [K in keyof E]: K };
|
|
172
|
-
|
|
173
|
-
export type RelationKeyMapper<E> = (keyMap: RelationKeyMap<E>) => Key<E>;
|
|
174
|
-
|
|
175
|
-
export type RelationReferences = { readonly local: string; readonly foreign: string }[];
|
|
176
|
-
|
|
177
|
-
export type RelationMappedBy<E> = Key<E> | RelationKeyMapper<E>;
|
|
178
|
-
|
|
179
|
-
export type RelationCardinality = '11' | 'm1' | '1m' | 'mm';
|
|
180
|
-
|
|
181
|
-
export type RelationOneToOneOptions<E> = RelationOptionsOwner<E> | RelationOptionsInverseSide<E>;
|
|
182
|
-
|
|
183
|
-
export type RelationOneToManyOptions<E> = RelationOptionsInverseSide<E> | RelationOptionsThroughOwner<E>;
|
|
184
|
-
|
|
185
|
-
export type RelationManyToOneOptions<E> = RelationOptionsOwner<E>;
|
|
186
|
-
|
|
187
|
-
export type RelationManyToManyOptions<E> = RelationOptionsThroughOwner<E> | RelationOptionsInverseSide<E>;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Wrapper type for relation type definitions in entities.
|
|
191
|
-
* Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
|
|
192
|
-
*
|
|
193
|
-
* Usage example:
|
|
194
|
-
* @Entity()
|
|
195
|
-
* export default class User {
|
|
196
|
-
*
|
|
197
|
-
* @OneToOne(() => Profile, profile => profile.user)
|
|
198
|
-
* profile: Relation<Profile>;
|
|
199
|
-
*
|
|
200
|
-
* }
|
|
201
|
-
*/
|
|
202
|
-
export type Relation<T> = T;
|
|
203
|
-
|
|
204
|
-
export type EntityMeta<E> = {
|
|
205
|
-
readonly entity: Type<E>;
|
|
206
|
-
name?: string;
|
|
207
|
-
id?: IdKey<E>;
|
|
208
|
-
softDelete?: FieldKey<E>;
|
|
209
|
-
fields: {
|
|
210
|
-
[K in FieldKey<E>]?: FieldOptions;
|
|
211
|
-
};
|
|
212
|
-
relations: {
|
|
213
|
-
[K in RelationKey<E>]?: RelationOptions;
|
|
214
|
-
};
|
|
215
|
-
processed?: boolean;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export type Primitive = string | number | symbol;
|