@tstdl/base 0.92.62 → 0.92.64
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 +18 -10
- package/package.json +1 -1
package/orm/server/repository.js
CHANGED
|
@@ -8,10 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
import { count, eq, inArray, sql } from 'drizzle-orm';
|
|
12
15
|
import { PgTransaction as DrizzlePgTransaction } from 'drizzle-orm/pg-core';
|
|
13
16
|
import { NotFoundError } from '../../errors/not-found.error.js';
|
|
14
|
-
import { Singleton } from '../../injector/decorators.js';
|
|
17
|
+
import { Optional, Singleton } from '../../injector/decorators.js';
|
|
15
18
|
import { inject, injectArgument } from '../../injector/inject.js';
|
|
16
19
|
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
17
20
|
import { injectionToken } from '../../injector/token.js';
|
|
@@ -32,6 +35,8 @@ export class EntityRepositoryConfig {
|
|
|
32
35
|
schema;
|
|
33
36
|
}
|
|
34
37
|
export const ENTITY_TYPE = injectionToken('EntityType');
|
|
38
|
+
const entityTypeToken = Symbol('EntityType');
|
|
39
|
+
const entityRepositoryConfigToken = Symbol('EntityRepositoryConfig');
|
|
35
40
|
const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
|
|
36
41
|
let EntityRepository = class EntityRepository {
|
|
37
42
|
#repositoryConstructor;
|
|
@@ -46,8 +51,9 @@ let EntityRepository = class EntityRepository {
|
|
|
46
51
|
isInTransaction;
|
|
47
52
|
constructor(type, table, columnDefinitions, columnDefinitionsMap, session) {
|
|
48
53
|
this.#repositoryConstructor = new.target;
|
|
49
|
-
|
|
50
|
-
this.
|
|
54
|
+
const entityRepositoryConfig = new.target[entityRepositoryConfigToken] ?? inject(EntityRepositoryConfig);
|
|
55
|
+
this.type = type ?? injectArgument(this, { optional: true }) ?? assertDefinedPass(new.target[entityTypeToken], 'Missing entity type.');
|
|
56
|
+
this.table = table ?? getDrizzleTableFromType(this.type, entityRepositoryConfig.schema);
|
|
51
57
|
this.columnDefinitions = columnDefinitions ?? getColumnDefinitions(this.table);
|
|
52
58
|
this.columnDefinitionsMap = columnDefinitionsMap ?? new Map(this.columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
53
59
|
this.session = session ?? inject(Database);
|
|
@@ -449,11 +455,12 @@ let EntityRepository = class EntityRepository {
|
|
|
449
455
|
}
|
|
450
456
|
};
|
|
451
457
|
EntityRepository = __decorate([
|
|
452
|
-
Singleton(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
458
|
+
Singleton(),
|
|
459
|
+
__param(0, Optional()),
|
|
460
|
+
__param(1, Optional()),
|
|
461
|
+
__param(2, Optional()),
|
|
462
|
+
__param(3, Optional()),
|
|
463
|
+
__param(4, Optional()),
|
|
457
464
|
__metadata("design:paramtypes", [Object, Object, Array, Map, Object])
|
|
458
465
|
], EntityRepository);
|
|
459
466
|
export { EntityRepository };
|
|
@@ -464,9 +471,10 @@ export function getRepository(type, config) {
|
|
|
464
471
|
const className = `${type.name}Service`;
|
|
465
472
|
const entityRepositoryClass = {
|
|
466
473
|
[className]: class extends EntityRepository {
|
|
474
|
+
static [entityTypeToken] = type;
|
|
475
|
+
static [entityRepositoryConfigToken] = config;
|
|
467
476
|
}
|
|
468
477
|
}[className];
|
|
469
|
-
|
|
470
|
-
injectorDecorator(entityRepositoryClass);
|
|
478
|
+
Singleton()(entityRepositoryClass);
|
|
471
479
|
return entityRepositoryClass;
|
|
472
480
|
}
|