@tstdl/base 0.92.62 → 0.92.63
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/orm/server/repository.js +8 -4
- package/package.json +1 -1
package/orm/server/repository.js
CHANGED
|
@@ -32,6 +32,8 @@ export class EntityRepositoryConfig {
|
|
|
32
32
|
schema;
|
|
33
33
|
}
|
|
34
34
|
export const ENTITY_TYPE = injectionToken('EntityType');
|
|
35
|
+
const entityTypeToken = Symbol('EntityType');
|
|
36
|
+
const entityRepositoryConfigToken = Symbol('EntityRepositoryConfig');
|
|
35
37
|
const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
|
|
36
38
|
let EntityRepository = class EntityRepository {
|
|
37
39
|
#repositoryConstructor;
|
|
@@ -46,8 +48,9 @@ let EntityRepository = class EntityRepository {
|
|
|
46
48
|
isInTransaction;
|
|
47
49
|
constructor(type, table, columnDefinitions, columnDefinitionsMap, session) {
|
|
48
50
|
this.#repositoryConstructor = new.target;
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
+
const entityRepositoryConfig = new.target[entityRepositoryConfigToken] ?? inject(EntityRepositoryConfig);
|
|
52
|
+
this.type = type ?? injectArgument(this, { optional: true }) ?? assertDefinedPass(new.target[entityTypeToken], 'Missing entity type.');
|
|
53
|
+
this.table = table ?? getDrizzleTableFromType(this.type, entityRepositoryConfig.schema);
|
|
51
54
|
this.columnDefinitions = columnDefinitions ?? getColumnDefinitions(this.table);
|
|
52
55
|
this.columnDefinitionsMap = columnDefinitionsMap ?? new Map(this.columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
53
56
|
this.session = session ?? inject(Database);
|
|
@@ -464,9 +467,10 @@ export function getRepository(type, config) {
|
|
|
464
467
|
const className = `${type.name}Service`;
|
|
465
468
|
const entityRepositoryClass = {
|
|
466
469
|
[className]: class extends EntityRepository {
|
|
470
|
+
static [entityTypeToken] = type;
|
|
471
|
+
static [entityRepositoryConfigToken] = config;
|
|
467
472
|
}
|
|
468
473
|
}[className];
|
|
469
|
-
|
|
470
|
-
injectorDecorator(entityRepositoryClass);
|
|
474
|
+
Singleton()(entityRepositoryClass);
|
|
471
475
|
return entityRepositoryClass;
|
|
472
476
|
}
|