@rsdk/db.typeorm 4.0.0-next.7 → 4.0.0-next.8
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 +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/internal/exceptions.d.ts +8 -8
- package/dist/internal/exceptions.js +10 -10
- package/dist/internal/strategy.d.ts +1 -1
- package/dist/internal/strategy.js +3 -3
- package/dist/internal/test/strategy.test.e2e.js +1 -1
- package/dist/metadata/typeorm-entity.decorator.d.ts +3 -3
- package/dist/metadata/typeorm-entity.decorator.js +5 -5
- package/dist/providers/typeorm-logger.adapter.d.ts +1 -1
- package/dist/providers/typeorm-logger.adapter.js +5 -5
- package/dist/providers/typeorm-override-entities.data-source-factory.d.ts +3 -3
- package/dist/providers/typeorm-override-entities.data-source-factory.js +8 -8
- package/dist/typeorm.errors-transformer.d.ts +1 -1
- package/dist/typeorm.errors-transformer.js +3 -3
- package/dist/typeorm.plugin.js +5 -5
- package/package.json +5 -5
- package/src/index.ts +3 -3
- package/src/internal/exceptions.ts +8 -8
- package/src/internal/strategy.ts +1 -1
- package/src/internal/test/strategy.test.e2e.ts +2 -2
- package/src/metadata/typeorm-entity.decorator.ts +5 -5
- package/src/providers/typeorm-logger.adapter.ts +1 -1
- package/src/providers/typeorm-override-entities.data-source-factory.ts +12 -12
- package/src/typeorm.errors-transformer.ts +1 -1
- package/src/typeorm.plugin.ts +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.0-next.8](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.7...v4.0.0-next.8) (2023-11-29)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Kafka batch producer ([#150](https://github.com/R-Vision/rsdk/issues/150)) ([2faa2f4](https://github.com/R-Vision/rsdk/commit/2faa2f41ca0dbb6d8a92cbf0ab20cf5cefeaf4e9))
|
|
11
|
+
|
|
6
12
|
## [4.0.0-next.7](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.6...v4.0.0-next.7) (2023-11-21)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @rsdk/db.typeorm
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { TransactionRunner } from '@rsdk/db';
|
|
|
2
2
|
export { TypeOrmPlugin } from './typeorm.plugin';
|
|
3
3
|
export { IsolationLevel } from './types';
|
|
4
4
|
export { OverrideEntity } from './metadata/override-entity.decorator';
|
|
5
|
-
export {
|
|
5
|
+
export { TypeOrmEntity } from './metadata/typeorm-entity.decorator';
|
|
6
6
|
export declare const Runner: TransactionRunner<import("./types").IsolationLevel, import("./internal/context").TypeOrmContext>;
|
|
7
7
|
export declare const Transactional: (payload?: {
|
|
8
8
|
isolation?: import("./types").IsolationLevel;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transactional = exports.Runner = exports.
|
|
3
|
+
exports.Transactional = exports.Runner = exports.TypeOrmEntity = exports.OverrideEntity = exports.IsolationLevel = exports.TypeOrmPlugin = void 0;
|
|
4
4
|
const db_1 = require("@rsdk/db");
|
|
5
5
|
const strategy_1 = require("./internal/strategy");
|
|
6
6
|
var typeorm_plugin_1 = require("./typeorm.plugin");
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "IsolationLevel", { enumerable: true, get: functi
|
|
|
10
10
|
var override_entity_decorator_1 = require("./metadata/override-entity.decorator");
|
|
11
11
|
Object.defineProperty(exports, "OverrideEntity", { enumerable: true, get: function () { return override_entity_decorator_1.OverrideEntity; } });
|
|
12
12
|
var typeorm_entity_decorator_1 = require("./metadata/typeorm-entity.decorator");
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
exports.Runner = new db_1.TransactionRunner(new strategy_1.
|
|
13
|
+
Object.defineProperty(exports, "TypeOrmEntity", { enumerable: true, get: function () { return typeorm_entity_decorator_1.TypeOrmEntity; } });
|
|
14
|
+
exports.Runner = new db_1.TransactionRunner(new strategy_1.TypeOrmTransactionalStrategy());
|
|
15
15
|
exports.Transactional = exports.Runner.Transactional.bind(exports.Runner);
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { InternalException } from '@rsdk/core';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class TypeOrmdbException extends InternalException {
|
|
3
3
|
}
|
|
4
|
-
export declare class ProxiedMethodIsNotFunction extends
|
|
4
|
+
export declare class ProxiedMethodIsNotFunction extends TypeOrmdbException {
|
|
5
5
|
constructor();
|
|
6
6
|
}
|
|
7
|
-
export declare class AlreadyAttached extends
|
|
7
|
+
export declare class AlreadyAttached extends TypeOrmdbException {
|
|
8
8
|
constructor();
|
|
9
9
|
}
|
|
10
|
-
export declare class QueryRunnerMustBeAttached extends
|
|
10
|
+
export declare class QueryRunnerMustBeAttached extends TypeOrmdbException {
|
|
11
11
|
constructor();
|
|
12
12
|
}
|
|
13
|
-
export declare class ContextMustBeProvided extends
|
|
13
|
+
export declare class ContextMustBeProvided extends TypeOrmdbException {
|
|
14
14
|
constructor();
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Неожиданный релиз (закрытие/возвращение в пул) соединения
|
|
18
18
|
*/
|
|
19
|
-
export declare class UnexpectedRelease extends
|
|
19
|
+
export declare class UnexpectedRelease extends TypeOrmdbException {
|
|
20
20
|
constructor();
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Ожидалось завершение работы с транзакцией, но не удовлетворены условия завершения (например транзакция не может быть закрыта из-за наличия незакрытых `savepoint`)
|
|
24
24
|
*/
|
|
25
|
-
export declare class MustReleased extends
|
|
25
|
+
export declare class MustReleased extends TypeOrmdbException {
|
|
26
26
|
constructor();
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -65,6 +65,6 @@ export declare class QueryRunnerIsReleased extends InternalException {
|
|
|
65
65
|
export declare class QueryRunnerIsTransactionActive extends InternalException {
|
|
66
66
|
constructor();
|
|
67
67
|
}
|
|
68
|
-
export declare class DatasourceOptionsNotSet extends
|
|
68
|
+
export declare class DatasourceOptionsNotSet extends TypeOrmdbException {
|
|
69
69
|
constructor();
|
|
70
70
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatasourceOptionsNotSet = exports.QueryRunnerIsTransactionActive = exports.QueryRunnerIsReleased = exports.ContextIsReleased = exports.MustReleased = exports.UnexpectedRelease = exports.ContextMustBeProvided = exports.QueryRunnerMustBeAttached = exports.AlreadyAttached = exports.ProxiedMethodIsNotFunction = exports.
|
|
3
|
+
exports.DatasourceOptionsNotSet = exports.QueryRunnerIsTransactionActive = exports.QueryRunnerIsReleased = exports.ContextIsReleased = exports.MustReleased = exports.UnexpectedRelease = exports.ContextMustBeProvided = exports.QueryRunnerMustBeAttached = exports.AlreadyAttached = exports.ProxiedMethodIsNotFunction = exports.TypeOrmdbException = void 0;
|
|
4
4
|
const core_1 = require("@rsdk/core");
|
|
5
|
-
class
|
|
5
|
+
class TypeOrmdbException extends core_1.InternalException {
|
|
6
6
|
}
|
|
7
|
-
exports.
|
|
8
|
-
class ProxiedMethodIsNotFunction extends
|
|
7
|
+
exports.TypeOrmdbException = TypeOrmdbException;
|
|
8
|
+
class ProxiedMethodIsNotFunction extends TypeOrmdbException {
|
|
9
9
|
constructor() {
|
|
10
10
|
super('Proxied method non function value');
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ProxiedMethodIsNotFunction = ProxiedMethodIsNotFunction;
|
|
14
|
-
class AlreadyAttached extends
|
|
14
|
+
class AlreadyAttached extends TypeOrmdbException {
|
|
15
15
|
constructor() {
|
|
16
16
|
super('Already attached');
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.AlreadyAttached = AlreadyAttached;
|
|
20
|
-
class QueryRunnerMustBeAttached extends
|
|
20
|
+
class QueryRunnerMustBeAttached extends TypeOrmdbException {
|
|
21
21
|
constructor() {
|
|
22
22
|
super('QueryRunner must be attached');
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.QueryRunnerMustBeAttached = QueryRunnerMustBeAttached;
|
|
26
|
-
class ContextMustBeProvided extends
|
|
26
|
+
class ContextMustBeProvided extends TypeOrmdbException {
|
|
27
27
|
constructor() {
|
|
28
28
|
super('Incorrect call, context must be provided');
|
|
29
29
|
}
|
|
@@ -32,7 +32,7 @@ exports.ContextMustBeProvided = ContextMustBeProvided;
|
|
|
32
32
|
/**
|
|
33
33
|
* Неожиданный релиз (закрытие/возвращение в пул) соединения
|
|
34
34
|
*/
|
|
35
|
-
class UnexpectedRelease extends
|
|
35
|
+
class UnexpectedRelease extends TypeOrmdbException {
|
|
36
36
|
constructor() {
|
|
37
37
|
super('Unexpected release connection');
|
|
38
38
|
}
|
|
@@ -41,7 +41,7 @@ exports.UnexpectedRelease = UnexpectedRelease;
|
|
|
41
41
|
/**
|
|
42
42
|
* Ожидалось завершение работы с транзакцией, но не удовлетворены условия завершения (например транзакция не может быть закрыта из-за наличия незакрытых `savepoint`)
|
|
43
43
|
*/
|
|
44
|
-
class MustReleased extends
|
|
44
|
+
class MustReleased extends TypeOrmdbException {
|
|
45
45
|
constructor() {
|
|
46
46
|
super('Must released but conditions not satisfied');
|
|
47
47
|
}
|
|
@@ -96,7 +96,7 @@ class QueryRunnerIsTransactionActive extends core_1.InternalException {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
exports.QueryRunnerIsTransactionActive = QueryRunnerIsTransactionActive;
|
|
99
|
-
class DatasourceOptionsNotSet extends
|
|
99
|
+
class DatasourceOptionsNotSet extends TypeOrmdbException {
|
|
100
100
|
constructor() {
|
|
101
101
|
super('Datasource options not set');
|
|
102
102
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CallBack, TransactionalStrategy } from '@rsdk/db';
|
|
2
2
|
import type { IsolationLevel } from '../types';
|
|
3
3
|
import { TypeOrmContext } from './context';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class TypeOrmTransactionalStrategy implements TransactionalStrategy<IsolationLevel, TypeOrmContext> {
|
|
5
5
|
/**
|
|
6
6
|
* Возвращает текущий контекст если вызвано внутри него
|
|
7
7
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TypeOrmTransactionalStrategy = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const context_1 = require("./context");
|
|
6
6
|
const exceptions_1 = require("./exceptions");
|
|
7
7
|
const initializer_1 = require("./initializer");
|
|
8
|
-
class
|
|
8
|
+
class TypeOrmTransactionalStrategy {
|
|
9
9
|
/**
|
|
10
10
|
* Возвращает текущий контекст если вызвано внутри него
|
|
11
11
|
*/
|
|
@@ -104,5 +104,5 @@ class TypeormTransactionalStrategy {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
exports.
|
|
107
|
+
exports.TypeOrmTransactionalStrategy = TypeOrmTransactionalStrategy;
|
|
108
108
|
//# sourceMappingURL=strategy.js.map
|
|
@@ -42,7 +42,7 @@ const createSecondCat = async () => {
|
|
|
42
42
|
return await catRepo.save(catRepo.create(util_1.secondCat));
|
|
43
43
|
};
|
|
44
44
|
exports.createSecondCat = createSecondCat;
|
|
45
|
-
const runner = new db_1.TransactionRunner(new strategy_1.
|
|
45
|
+
const runner = new db_1.TransactionRunner(new strategy_1.TypeOrmTransactionalStrategy());
|
|
46
46
|
let dataSource;
|
|
47
47
|
const pingDatabase = async () => await dataSource.query('select 1 + 1');
|
|
48
48
|
exports.pingDatabase = pingDatabase;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Type } from '@nestjs/common';
|
|
2
2
|
import type { EntitySchema } from 'typeorm';
|
|
3
|
-
export type
|
|
3
|
+
export type TypeOrmEntityOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Table name
|
|
6
6
|
*/
|
|
@@ -9,5 +9,5 @@ export type TypeormEntityOptions = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Decorator for set our options
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
13
|
-
export declare function
|
|
12
|
+
export declare const TypeOrmEntity: (typeormEntityOptions: TypeOrmEntityOptions) => ClassDecorator;
|
|
13
|
+
export declare function getTypeOrmEntityMetadata(entity: string | Function | EntitySchema | Type): TypeOrmEntityOptions | undefined;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.getTypeOrmEntityMetadata = exports.TypeOrmEntity = void 0;
|
|
5
5
|
const TYPEORM_ENTITY_METADATA = 'metadata:typeorm-entity';
|
|
6
6
|
/**
|
|
7
7
|
* Decorator for set our options
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const TypeOrmEntity = (typeormEntityOptions) => (target) => {
|
|
10
10
|
Reflect.defineMetadata(TYPEORM_ENTITY_METADATA, typeormEntityOptions, target);
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
13
|
-
function
|
|
12
|
+
exports.TypeOrmEntity = TypeOrmEntity;
|
|
13
|
+
function getTypeOrmEntityMetadata(entity) {
|
|
14
14
|
return Reflect.getMetadata(TYPEORM_ENTITY_METADATA, entity);
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.getTypeOrmEntityMetadata = getTypeOrmEntityMetadata;
|
|
17
17
|
//# sourceMappingURL=typeorm-entity.decorator.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ILogger } from '@rsdk/logging';
|
|
2
2
|
import type { Logger } from 'typeorm';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class TypeOrmLoggerAdapter implements Logger {
|
|
4
4
|
private platformLogger;
|
|
5
5
|
constructor(platformLogger: ILogger);
|
|
6
6
|
logQuery(query: string, parameters?: any[]): any;
|
|
@@ -12,11 +12,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.TypeOrmLoggerAdapter = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const core_1 = require("@rsdk/core");
|
|
18
18
|
const db_1 = require("@rsdk/db");
|
|
19
|
-
let
|
|
19
|
+
let TypeOrmLoggerAdapter = class TypeOrmLoggerAdapter {
|
|
20
20
|
platformLogger;
|
|
21
21
|
constructor(platformLogger) {
|
|
22
22
|
this.platformLogger = platformLogger;
|
|
@@ -59,10 +59,10 @@ let TypeormLoggerAdapter = class TypeormLoggerAdapter {
|
|
|
59
59
|
return this.platformLogger[level](message);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
exports.
|
|
63
|
-
exports.
|
|
62
|
+
exports.TypeOrmLoggerAdapter = TypeOrmLoggerAdapter;
|
|
63
|
+
exports.TypeOrmLoggerAdapter = TypeOrmLoggerAdapter = __decorate([
|
|
64
64
|
(0, common_1.Injectable)(),
|
|
65
65
|
__param(0, (0, core_1.InjectLogger)('TypeOrm')),
|
|
66
66
|
__metadata("design:paramtypes", [Object])
|
|
67
|
-
],
|
|
67
|
+
], TypeOrmLoggerAdapter);
|
|
68
68
|
//# sourceMappingURL=typeorm-logger.adapter.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DataSourceOptions } from 'typeorm';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class TypeOrmOverrideEntitiesDataSourceFactory {
|
|
4
4
|
static create(dataSourceOptions: DataSourceOptions): DataSource;
|
|
5
5
|
private static getOverrideEntitiesMetadataByObjectMapOfEntities;
|
|
6
6
|
private static getOverrideEntitiesMetadataByArrayOfEntities;
|
|
7
|
-
private static
|
|
8
|
-
private static
|
|
7
|
+
private static isTypeOrmEntityOverrided;
|
|
8
|
+
private static getTypeOrmMetadataByEntity;
|
|
9
9
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.TypeOrmOverrideEntitiesDataSourceFactory = void 0;
|
|
5
5
|
const typeorm_1 = require("typeorm");
|
|
6
6
|
const override_entity_decorator_1 = require("../metadata/override-entity.decorator");
|
|
7
7
|
const typeorm_entity_decorator_1 = require("../metadata/typeorm-entity.decorator");
|
|
8
|
-
class
|
|
8
|
+
class TypeOrmOverrideEntitiesDataSourceFactory {
|
|
9
9
|
static create(dataSourceOptions) {
|
|
10
10
|
// if we dont have any eitities, we dont start any proccess with override logics
|
|
11
11
|
if (!dataSourceOptions.entities) {
|
|
@@ -16,7 +16,7 @@ class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
16
16
|
// List of T-s passed as an array
|
|
17
17
|
if (Array.isArray(dataSourceOptions.entities)) {
|
|
18
18
|
const overrideEntitiesMetadata = this.getOverrideEntitiesMetadataByArrayOfEntities(dataSourceOptions.entities);
|
|
19
|
-
const overridedEntities = dataSourceOptions.entities.filter((entity) => !this.
|
|
19
|
+
const overridedEntities = dataSourceOptions.entities.filter((entity) => !this.isTypeOrmEntityOverrided(this.getTypeOrmMetadataByEntity(entity), overrideEntitiesMetadata));
|
|
20
20
|
return new typeorm_1.DataSource({
|
|
21
21
|
...dataSourceOptions,
|
|
22
22
|
entities: overridedEntities,
|
|
@@ -24,7 +24,7 @@ class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
24
24
|
}
|
|
25
25
|
// List of T-s passed as object map.
|
|
26
26
|
const overrideEntitiesMetadata = this.getOverrideEntitiesMetadataByObjectMapOfEntities(dataSourceOptions);
|
|
27
|
-
const overridedEntities = Object.fromEntries(Object.entries(dataSourceOptions.entities).filter(([_key, entity]) => !this.
|
|
27
|
+
const overridedEntities = Object.fromEntries(Object.entries(dataSourceOptions.entities).filter(([_key, entity]) => !this.isTypeOrmEntityOverrided(this.getTypeOrmMetadataByEntity(entity), overrideEntitiesMetadata)));
|
|
28
28
|
return new typeorm_1.DataSource({
|
|
29
29
|
...dataSourceOptions,
|
|
30
30
|
entities: overridedEntities,
|
|
@@ -50,13 +50,13 @@ class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
50
50
|
}
|
|
51
51
|
return overrideEntitiesMetadata;
|
|
52
52
|
}
|
|
53
|
-
static
|
|
53
|
+
static isTypeOrmEntityOverrided(typeormEntityMetadata, overrideEntitiesMetadata) {
|
|
54
54
|
return (typeormEntityMetadata?.name &&
|
|
55
55
|
overrideEntitiesMetadata[typeormEntityMetadata.name]);
|
|
56
56
|
}
|
|
57
|
-
static
|
|
58
|
-
return (0, typeorm_entity_decorator_1.
|
|
57
|
+
static getTypeOrmMetadataByEntity(entity) {
|
|
58
|
+
return (0, typeorm_entity_decorator_1.getTypeOrmEntityMetadata)(entity);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
exports.
|
|
61
|
+
exports.TypeOrmOverrideEntitiesDataSourceFactory = TypeOrmOverrideEntitiesDataSourceFactory;
|
|
62
62
|
//# sourceMappingURL=typeorm-override-entities.data-source-factory.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IErrorsTransformer, PipelineException } from '@rsdk/core';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class TypeOrmErrorTransformer implements IErrorsTransformer {
|
|
3
3
|
match(ex: unknown): boolean;
|
|
4
4
|
transform(ex: any): PipelineException;
|
|
5
5
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TypeOrmErrorTransformer = void 0;
|
|
4
4
|
const core_1 = require("@rsdk/core");
|
|
5
5
|
const typeorm_1 = require("typeorm");
|
|
6
|
-
class
|
|
6
|
+
class TypeOrmErrorTransformer {
|
|
7
7
|
match(ex) {
|
|
8
8
|
return ex instanceof typeorm_1.TypeORMError;
|
|
9
9
|
}
|
|
@@ -21,5 +21,5 @@ class TypeormErrorTransformer {
|
|
|
21
21
|
throw new Error('unknown exception');
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
exports.
|
|
24
|
+
exports.TypeOrmErrorTransformer = TypeOrmErrorTransformer;
|
|
25
25
|
//# sourceMappingURL=typeorm.errors-transformer.js.map
|
package/dist/typeorm.plugin.js
CHANGED
|
@@ -38,11 +38,11 @@ class TypeOrmPlugin {
|
|
|
38
38
|
imports: [
|
|
39
39
|
{
|
|
40
40
|
module: typeorm_1.TypeOrmModule,
|
|
41
|
-
providers: [providers_1.TypeOrmHealthIndicator, providers_1.
|
|
42
|
-
exports: [providers_1.
|
|
41
|
+
providers: [providers_1.TypeOrmHealthIndicator, providers_1.TypeOrmLoggerAdapter],
|
|
42
|
+
exports: [providers_1.TypeOrmLoggerAdapter],
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
|
-
inject: [providers_1.TypeOrmPluginConfig, providers_1.
|
|
45
|
+
inject: [providers_1.TypeOrmPluginConfig, providers_1.TypeOrmLoggerAdapter, core_1.APP_NAME],
|
|
46
46
|
useFactory: (config, logger, appName) => ({
|
|
47
47
|
/**
|
|
48
48
|
* Так как typeorm поддерживает целый зоопарк не совместимых друг с другом СУБД, для всего нужны разные опции
|
|
@@ -72,14 +72,14 @@ class TypeOrmPlugin {
|
|
|
72
72
|
if (!options) {
|
|
73
73
|
throw new exceptions_1.DatasourceOptionsNotSet();
|
|
74
74
|
}
|
|
75
|
-
return typeorm_override_entities_data_source_factory_1.
|
|
75
|
+
return typeorm_override_entities_data_source_factory_1.TypeOrmOverrideEntitiesDataSourceFactory.create(options).initialize();
|
|
76
76
|
},
|
|
77
77
|
}),
|
|
78
78
|
migration_checker_module_1.MigrationCheckerModule,
|
|
79
79
|
];
|
|
80
80
|
}
|
|
81
81
|
errorTransformers() {
|
|
82
|
-
return [new typeorm_errors_transformer_1.
|
|
82
|
+
return [new typeorm_errors_transformer_1.TypeOrmErrorTransformer()];
|
|
83
83
|
}
|
|
84
84
|
getMigrationsOption() {
|
|
85
85
|
return [(0, node_path_1.resolve)(process.cwd(), 'dist/typeorm/migrations/**.js')];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/db.typeorm",
|
|
3
|
-
"version": "4.0.0-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.0.0-next.8",
|
|
4
|
+
"description": "TypeOrm module for platform",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"@nestjs/typeorm": "^10.0.0",
|
|
20
20
|
"@rsdk/common": "^4.0.0-next.6",
|
|
21
21
|
"@rsdk/common.nestjs": "^4.0.0-next.6",
|
|
22
|
-
"@rsdk/core": "^4.0.0-next.
|
|
23
|
-
"@rsdk/db": "^4.0.0-next.
|
|
22
|
+
"@rsdk/core": "^4.0.0-next.8",
|
|
23
|
+
"@rsdk/db": "^4.0.0-next.8",
|
|
24
24
|
"@rsdk/logging": "^4.0.0-next.6",
|
|
25
25
|
"@rsdk/nest-tools": "^4.0.0-next.4",
|
|
26
26
|
"reflect-metadata": "^0.1.13",
|
|
27
27
|
"rxjs": "^7.0.0",
|
|
28
28
|
"typeorm": "^0.3.12"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "bae7c74fc8be068b8bd66b403d19e2b32cf092ec"
|
|
31
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TransactionRunner } from '@rsdk/db';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { TypeOrmTransactionalStrategy } from './internal/strategy';
|
|
4
4
|
|
|
5
5
|
export { TypeOrmPlugin } from './typeorm.plugin';
|
|
6
6
|
export { IsolationLevel } from './types';
|
|
7
7
|
export { OverrideEntity } from './metadata/override-entity.decorator';
|
|
8
|
-
export {
|
|
8
|
+
export { TypeOrmEntity } from './metadata/typeorm-entity.decorator';
|
|
9
9
|
|
|
10
|
-
export const Runner = new TransactionRunner(new
|
|
10
|
+
export const Runner = new TransactionRunner(new TypeOrmTransactionalStrategy());
|
|
11
11
|
export const Transactional = Runner.Transactional.bind(Runner);
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { InternalException } from '@rsdk/core';
|
|
2
2
|
|
|
3
|
-
export class
|
|
3
|
+
export class TypeOrmdbException extends InternalException {}
|
|
4
4
|
|
|
5
|
-
export class ProxiedMethodIsNotFunction extends
|
|
5
|
+
export class ProxiedMethodIsNotFunction extends TypeOrmdbException {
|
|
6
6
|
constructor() {
|
|
7
7
|
super('Proxied method non function value');
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export class AlreadyAttached extends
|
|
11
|
+
export class AlreadyAttached extends TypeOrmdbException {
|
|
12
12
|
constructor() {
|
|
13
13
|
super('Already attached');
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export class QueryRunnerMustBeAttached extends
|
|
17
|
+
export class QueryRunnerMustBeAttached extends TypeOrmdbException {
|
|
18
18
|
constructor() {
|
|
19
19
|
super('QueryRunner must be attached');
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export class ContextMustBeProvided extends
|
|
23
|
+
export class ContextMustBeProvided extends TypeOrmdbException {
|
|
24
24
|
constructor() {
|
|
25
25
|
super('Incorrect call, context must be provided');
|
|
26
26
|
}
|
|
@@ -29,7 +29,7 @@ export class ContextMustBeProvided extends TypeormdbException {
|
|
|
29
29
|
/**
|
|
30
30
|
* Неожиданный релиз (закрытие/возвращение в пул) соединения
|
|
31
31
|
*/
|
|
32
|
-
export class UnexpectedRelease extends
|
|
32
|
+
export class UnexpectedRelease extends TypeOrmdbException {
|
|
33
33
|
constructor() {
|
|
34
34
|
super('Unexpected release connection');
|
|
35
35
|
}
|
|
@@ -38,7 +38,7 @@ export class UnexpectedRelease extends TypeormdbException {
|
|
|
38
38
|
/**
|
|
39
39
|
* Ожидалось завершение работы с транзакцией, но не удовлетворены условия завершения (например транзакция не может быть закрыта из-за наличия незакрытых `savepoint`)
|
|
40
40
|
*/
|
|
41
|
-
export class MustReleased extends
|
|
41
|
+
export class MustReleased extends TypeOrmdbException {
|
|
42
42
|
constructor() {
|
|
43
43
|
super('Must released but conditions not satisfied');
|
|
44
44
|
}
|
|
@@ -95,7 +95,7 @@ export class QueryRunnerIsTransactionActive extends InternalException {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
export class DatasourceOptionsNotSet extends
|
|
98
|
+
export class DatasourceOptionsNotSet extends TypeOrmdbException {
|
|
99
99
|
constructor() {
|
|
100
100
|
super('Datasource options not set');
|
|
101
101
|
}
|
package/src/internal/strategy.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { TypeOrmContext } from './context';
|
|
|
7
7
|
import { ContextMustBeProvided } from './exceptions';
|
|
8
8
|
import { Initializer } from './initializer';
|
|
9
9
|
|
|
10
|
-
export class
|
|
10
|
+
export class TypeOrmTransactionalStrategy
|
|
11
11
|
implements TransactionalStrategy<IsolationLevel, TypeOrmContext>
|
|
12
12
|
{
|
|
13
13
|
/**
|
|
@@ -13,7 +13,7 @@ import { DataSource } from 'typeorm';
|
|
|
13
13
|
|
|
14
14
|
import { DEFAULT_ISOLATION_LEVEL, IsolationLevel } from '../../types';
|
|
15
15
|
import { Initializer } from '../initializer';
|
|
16
|
-
import {
|
|
16
|
+
import { TypeOrmTransactionalStrategy } from '../strategy';
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
Account,
|
|
@@ -35,7 +35,7 @@ export const createSecondCat = async (): Promise<Cat> => {
|
|
|
35
35
|
return await catRepo.save(catRepo.create(secondCat));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const runner = new TransactionRunner(new
|
|
38
|
+
const runner = new TransactionRunner(new TypeOrmTransactionalStrategy());
|
|
39
39
|
let dataSource: DataSource;
|
|
40
40
|
|
|
41
41
|
export const pingDatabase = async (): Promise<void> =>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { Type } from '@nestjs/common';
|
|
4
4
|
import type { EntitySchema } from 'typeorm';
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type TypeOrmEntityOptions = {
|
|
7
7
|
/**
|
|
8
8
|
* Table name
|
|
9
9
|
*/
|
|
@@ -15,8 +15,8 @@ const TYPEORM_ENTITY_METADATA = 'metadata:typeorm-entity';
|
|
|
15
15
|
/**
|
|
16
16
|
* Decorator for set our options
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
19
|
-
(typeormEntityOptions:
|
|
18
|
+
export const TypeOrmEntity =
|
|
19
|
+
(typeormEntityOptions: TypeOrmEntityOptions): ClassDecorator =>
|
|
20
20
|
(target: Function | EntitySchema | Type) => {
|
|
21
21
|
Reflect.defineMetadata(
|
|
22
22
|
TYPEORM_ENTITY_METADATA,
|
|
@@ -25,8 +25,8 @@ export const TypeormEntity =
|
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export function
|
|
28
|
+
export function getTypeOrmEntityMetadata(
|
|
29
29
|
entity: string | Function | EntitySchema | Type,
|
|
30
|
-
):
|
|
30
|
+
): TypeOrmEntityOptions | undefined {
|
|
31
31
|
return Reflect.getMetadata(TYPEORM_ENTITY_METADATA, entity);
|
|
32
32
|
}
|
|
@@ -5,7 +5,7 @@ import { ILogger } from '@rsdk/logging';
|
|
|
5
5
|
import type { Logger } from 'typeorm';
|
|
6
6
|
|
|
7
7
|
@Injectable()
|
|
8
|
-
export class
|
|
8
|
+
export class TypeOrmLoggerAdapter implements Logger {
|
|
9
9
|
constructor(@InjectLogger('TypeOrm') private platformLogger: ILogger) {}
|
|
10
10
|
|
|
11
11
|
logQuery(query: string, parameters?: any[]): any {
|
|
@@ -5,10 +5,10 @@ import type { DataSourceOptions, EntitySchema } from 'typeorm';
|
|
|
5
5
|
import { DataSource } from 'typeorm';
|
|
6
6
|
|
|
7
7
|
import { getOverrideEntityMetadata } from '../metadata/override-entity.decorator';
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
8
|
+
import type { TypeOrmEntityOptions } from '../metadata/typeorm-entity.decorator';
|
|
9
|
+
import { getTypeOrmEntityMetadata } from '../metadata/typeorm-entity.decorator';
|
|
10
10
|
|
|
11
|
-
export class
|
|
11
|
+
export class TypeOrmOverrideEntitiesDataSourceFactory {
|
|
12
12
|
static create(dataSourceOptions: DataSourceOptions): DataSource {
|
|
13
13
|
// if we dont have any eitities, we dont start any proccess with override logics
|
|
14
14
|
if (!dataSourceOptions.entities) {
|
|
@@ -27,8 +27,8 @@ export class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
27
27
|
|
|
28
28
|
const overridedEntities = dataSourceOptions.entities.filter(
|
|
29
29
|
(entity) =>
|
|
30
|
-
!this.
|
|
31
|
-
this.
|
|
30
|
+
!this.isTypeOrmEntityOverrided(
|
|
31
|
+
this.getTypeOrmMetadataByEntity(entity),
|
|
32
32
|
overrideEntitiesMetadata,
|
|
33
33
|
),
|
|
34
34
|
);
|
|
@@ -45,8 +45,8 @@ export class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
45
45
|
const overridedEntities = Object.fromEntries(
|
|
46
46
|
Object.entries(dataSourceOptions.entities).filter(
|
|
47
47
|
([_key, entity]) =>
|
|
48
|
-
!this.
|
|
49
|
-
this.
|
|
48
|
+
!this.isTypeOrmEntityOverrided(
|
|
49
|
+
this.getTypeOrmMetadataByEntity(entity),
|
|
50
50
|
overrideEntitiesMetadata,
|
|
51
51
|
),
|
|
52
52
|
),
|
|
@@ -92,8 +92,8 @@ export class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
92
92
|
return overrideEntitiesMetadata;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
private static
|
|
96
|
-
typeormEntityMetadata:
|
|
95
|
+
private static isTypeOrmEntityOverrided(
|
|
96
|
+
typeormEntityMetadata: TypeOrmEntityOptions | undefined,
|
|
97
97
|
overrideEntitiesMetadata: Record<
|
|
98
98
|
string,
|
|
99
99
|
string | Function | EntitySchema | Type
|
|
@@ -105,9 +105,9 @@ export class TypeormOverrideEntitiesDataSourceFactory {
|
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
private static
|
|
108
|
+
private static getTypeOrmMetadataByEntity(
|
|
109
109
|
entity: string | Function | EntitySchema,
|
|
110
|
-
):
|
|
111
|
-
return
|
|
110
|
+
): TypeOrmEntityOptions | undefined {
|
|
111
|
+
return getTypeOrmEntityMetadata(entity);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -2,7 +2,7 @@ import type { IErrorsTransformer, PipelineException } from '@rsdk/core';
|
|
|
2
2
|
import { InternalException, NotFoundException } from '@rsdk/core';
|
|
3
3
|
import { EntityNotFoundError, TypeORMError } from 'typeorm';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class TypeOrmErrorTransformer implements IErrorsTransformer {
|
|
6
6
|
match(ex: unknown): boolean {
|
|
7
7
|
return ex instanceof TypeORMError;
|
|
8
8
|
}
|
package/src/typeorm.plugin.ts
CHANGED
|
@@ -17,13 +17,13 @@ import type { DataSourceOptions } from 'typeorm';
|
|
|
17
17
|
import { DatasourceOptionsNotSet } from './internal/exceptions';
|
|
18
18
|
import { Initializer } from './internal/initializer';
|
|
19
19
|
import { MigrationCheckerModule } from './modules/migration-checker.module';
|
|
20
|
-
import {
|
|
20
|
+
import { TypeOrmOverrideEntitiesDataSourceFactory } from './providers/typeorm-override-entities.data-source-factory';
|
|
21
21
|
import {
|
|
22
22
|
TypeOrmHealthIndicator,
|
|
23
|
-
|
|
23
|
+
TypeOrmLoggerAdapter,
|
|
24
24
|
TypeOrmPluginConfig,
|
|
25
25
|
} from './providers';
|
|
26
|
-
import {
|
|
26
|
+
import { TypeOrmErrorTransformer } from './typeorm.errors-transformer';
|
|
27
27
|
import type { TypeOrmPluginOptions } from './types';
|
|
28
28
|
|
|
29
29
|
export class TypeOrmPlugin implements PlatformAppPlugin {
|
|
@@ -55,14 +55,14 @@ export class TypeOrmPlugin implements PlatformAppPlugin {
|
|
|
55
55
|
imports: [
|
|
56
56
|
{
|
|
57
57
|
module: TypeOrmModule,
|
|
58
|
-
providers: [TypeOrmHealthIndicator,
|
|
59
|
-
exports: [
|
|
58
|
+
providers: [TypeOrmHealthIndicator, TypeOrmLoggerAdapter],
|
|
59
|
+
exports: [TypeOrmLoggerAdapter],
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
|
-
inject: [TypeOrmPluginConfig,
|
|
62
|
+
inject: [TypeOrmPluginConfig, TypeOrmLoggerAdapter, APP_NAME],
|
|
63
63
|
useFactory: (
|
|
64
64
|
config: TypeOrmPluginConfig,
|
|
65
|
-
logger:
|
|
65
|
+
logger: TypeOrmLoggerAdapter,
|
|
66
66
|
appName: string,
|
|
67
67
|
): TypeOrmModuleOptions => ({
|
|
68
68
|
/**
|
|
@@ -93,7 +93,7 @@ export class TypeOrmPlugin implements PlatformAppPlugin {
|
|
|
93
93
|
if (!options) {
|
|
94
94
|
throw new DatasourceOptionsNotSet();
|
|
95
95
|
}
|
|
96
|
-
return
|
|
96
|
+
return TypeOrmOverrideEntitiesDataSourceFactory.create(
|
|
97
97
|
options,
|
|
98
98
|
).initialize();
|
|
99
99
|
},
|
|
@@ -103,7 +103,7 @@ export class TypeOrmPlugin implements PlatformAppPlugin {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
errorTransformers(): IErrorsTransformer[] {
|
|
106
|
-
return [new
|
|
106
|
+
return [new TypeOrmErrorTransformer()];
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
private getMigrationsOption(): string[] {
|