@celljs/typeorm 3.0.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell-fc.yml +10 -0
- package/cell.yml +34 -0
- package/lib/browser/module.d.ts +3 -0
- package/lib/browser/module.d.ts.map +1 -0
- package/lib/browser/module.js +5 -0
- package/lib/browser/module.js.map +1 -0
- package/lib/common/constants.d.ts +2 -0
- package/lib/common/constants.d.ts.map +1 -0
- package/lib/common/constants.js +5 -0
- package/lib/common/constants.js.map +1 -0
- package/lib/common/data-source-manager.d.ts +34 -0
- package/lib/common/data-source-manager.d.ts.map +1 -0
- package/lib/common/data-source-manager.js +76 -0
- package/lib/common/data-source-manager.js.map +1 -0
- package/lib/common/entity-provider.d.ts +5 -0
- package/lib/common/entity-provider.d.ts.map +1 -0
- package/lib/common/entity-provider.js +27 -0
- package/lib/common/entity-provider.js.map +1 -0
- package/lib/common/errors.d.ts +14 -0
- package/lib/common/errors.d.ts.map +1 -0
- package/lib/common/errors.js +24 -0
- package/lib/common/errors.js.map +1 -0
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +23 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/typeorm-initializer.d.ts +10 -0
- package/lib/common/typeorm-initializer.d.ts.map +1 -0
- package/lib/common/typeorm-initializer.js +59 -0
- package/lib/common/typeorm-initializer.js.map +1 -0
- package/lib/common/utils.d.ts +4 -0
- package/lib/common/utils.d.ts.map +1 -0
- package/lib/common/utils.js +25 -0
- package/lib/common/utils.js.map +1 -0
- package/lib/node/annotation/index.d.ts +2 -0
- package/lib/node/annotation/index.d.ts.map +1 -0
- package/lib/node/annotation/index.js +18 -0
- package/lib/node/annotation/index.js.map +1 -0
- package/lib/node/annotation/transactional.d.ts +20 -0
- package/lib/node/annotation/transactional.d.ts.map +1 -0
- package/lib/node/annotation/transactional.js +89 -0
- package/lib/node/annotation/transactional.js.map +1 -0
- package/lib/node/context/context-protocol.d.ts +11 -0
- package/lib/node/context/context-protocol.d.ts.map +1 -0
- package/lib/node/context/context-protocol.js +55 -0
- package/lib/node/context/context-protocol.js.map +1 -0
- package/lib/node/context/index.d.ts +2 -0
- package/lib/node/context/index.d.ts.map +1 -0
- package/lib/node/context/index.js +18 -0
- package/lib/node/context/index.js.map +1 -0
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +19 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +20 -0
- package/lib/node/module.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +45 -0
- package/src/browser/module.ts +3 -0
- package/src/common/constants.ts +1 -0
- package/src/common/data-source-manager.ts +70 -0
- package/src/common/entity-provider.ts +27 -0
- package/src/common/errors.ts +22 -0
- package/src/common/index.ts +6 -0
- package/src/common/typeorm-initializer.ts +45 -0
- package/src/common/utils.ts +22 -0
- package/src/node/annotation/index.ts +1 -0
- package/src/node/annotation/transactional.ts +96 -0
- package/src/node/context/context-protocol.ts +54 -0
- package/src/node/context/index.ts +1 -0
- package/src/node/index.ts +2 -0
- package/src/node/module.ts +4 -0
- package/src/package.spec.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Cellbang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Cell - typeorm Component
|
package/cell-fc.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cell:
|
|
2
|
+
cloud:
|
|
3
|
+
layer:
|
|
4
|
+
name: "${cell.cloud.function.runtime == 'custom' ? 'node-v16-14-2-linux-x64' : ''}"
|
|
5
|
+
compatibleRuntime:
|
|
6
|
+
- custom
|
|
7
|
+
codeUri: https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.gz
|
|
8
|
+
function:
|
|
9
|
+
env: "${cell.cloud.function.runtime == 'custom' ? { PATH: '/opt/node-v16.14.2-linux-x64/bin:$PATH' } : {}}"
|
|
10
|
+
layers: "${cell.cloud.function.runtime == 'custom' ? [ 'node-v16-14-2-linux-x64'] : []}"
|
package/cell.yml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
cell:
|
|
2
|
+
webpack:
|
|
3
|
+
filterWarningsPlugin:
|
|
4
|
+
typeorm:
|
|
5
|
+
- typeorm-aurora-data-api-driver
|
|
6
|
+
- mongodb
|
|
7
|
+
- mssql
|
|
8
|
+
- mysql
|
|
9
|
+
- mysql2
|
|
10
|
+
- oracledb
|
|
11
|
+
- pg
|
|
12
|
+
- pg-native
|
|
13
|
+
- pg-query-stream
|
|
14
|
+
- sql.js
|
|
15
|
+
- redis
|
|
16
|
+
- sqlite3
|
|
17
|
+
- react-native-sqlite-storage
|
|
18
|
+
- cli-highlight
|
|
19
|
+
- Critical dependency
|
|
20
|
+
- '@sap/hdbext'
|
|
21
|
+
- '@sap/hana-client'
|
|
22
|
+
- hdb-pool
|
|
23
|
+
- ioredis
|
|
24
|
+
- better-sqlite3
|
|
25
|
+
- '@google-cloud/spanner'
|
|
26
|
+
typeorm:
|
|
27
|
+
ormConfig:
|
|
28
|
+
- type: "${ env.DE_TYPE ?: 'mysql'}"
|
|
29
|
+
host: "${ env.DB_HOST ?: 'localhost'}"
|
|
30
|
+
port: "${ env.DB_PORT ?: 3306}"
|
|
31
|
+
synchronize: "${ env.DB_SYNC ?: true}"
|
|
32
|
+
# username: "${ env.DB_USERNAME ?: 'root'}"
|
|
33
|
+
# password: "${ env.DB_PASSWORD ?: 'root'}"
|
|
34
|
+
database: "${ env.DB_DATABASE ?: 'test'}"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/browser/module.ts"],"names":[],"mappings":";AAEA,wBAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/browser/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AAExC,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* DataSourceManager is used to store and manage multiple orm dataSources.
|
|
4
|
+
* It also provides useful factory methods to simplify dataSource creation.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare class DataSourceManager {
|
|
8
|
+
/**
|
|
9
|
+
* List of dataSources registered in this dataSource manager.
|
|
10
|
+
*/
|
|
11
|
+
get dataSources(): DataSource[];
|
|
12
|
+
/**
|
|
13
|
+
* Internal lookup to quickly get from a dataSource name to the DataSource object.
|
|
14
|
+
*/
|
|
15
|
+
private readonly dataSourceMap;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if dataSource with the given name exist in the manager.
|
|
18
|
+
*/
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Gets registered dataSource with the given name.
|
|
22
|
+
* If dataSource name is not given then it will get a default dataSource.
|
|
23
|
+
* Throws error if dataSource with the given name was not found.
|
|
24
|
+
*/
|
|
25
|
+
get(name?: string): DataSource;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new dataSource based on the given dataSource options and registers it in the manager.
|
|
28
|
+
* DataSource won't be established, you'll need to manually call connect method to establish dataSource.
|
|
29
|
+
*/
|
|
30
|
+
create(options: DataSourceOptions & {
|
|
31
|
+
name?: string;
|
|
32
|
+
}): DataSource;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=data-source-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source-manager.d.ts","sourceRoot":"","sources":["../../src/common/data-source-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGxD;;;;GAIG;AACH,qBACa,iBAAiB;IAC1B;;OAEG;IACH,IAAI,WAAW,IAAI,UAAU,EAAE,CAE9B;IAED;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsC;IAMpE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;;;OAIG;IACH,GAAG,CAAC,IAAI,GAAE,MAAkB,GAAG,UAAU;IASzC;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;CAiBrE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DataSourceManager = void 0;
|
|
10
|
+
const core_1 = require("@celljs/core");
|
|
11
|
+
const typeorm_1 = require("typeorm");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
/**
|
|
14
|
+
* DataSourceManager is used to store and manage multiple orm dataSources.
|
|
15
|
+
* It also provides useful factory methods to simplify dataSource creation.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
let DataSourceManager = class DataSourceManager {
|
|
19
|
+
constructor() {
|
|
20
|
+
/**
|
|
21
|
+
* Internal lookup to quickly get from a dataSource name to the DataSource object.
|
|
22
|
+
*/
|
|
23
|
+
this.dataSourceMap = new Map();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* List of dataSources registered in this dataSource manager.
|
|
27
|
+
*/
|
|
28
|
+
get dataSources() {
|
|
29
|
+
return Array.from(this.dataSourceMap.values());
|
|
30
|
+
}
|
|
31
|
+
// -------------------------------------------------------------------------
|
|
32
|
+
// Public Methods
|
|
33
|
+
// -------------------------------------------------------------------------
|
|
34
|
+
/**
|
|
35
|
+
* Checks if dataSource with the given name exist in the manager.
|
|
36
|
+
*/
|
|
37
|
+
has(name) {
|
|
38
|
+
return this.dataSourceMap.has(name);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets registered dataSource with the given name.
|
|
42
|
+
* If dataSource name is not given then it will get a default dataSource.
|
|
43
|
+
* Throws error if dataSource with the given name was not found.
|
|
44
|
+
*/
|
|
45
|
+
get(name = 'default') {
|
|
46
|
+
const dataSource = this.dataSourceMap.get(name);
|
|
47
|
+
if (!dataSource) {
|
|
48
|
+
throw new errors_1.DataSourceNotFoundError(name);
|
|
49
|
+
}
|
|
50
|
+
return dataSource;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new dataSource based on the given dataSource options and registers it in the manager.
|
|
54
|
+
* DataSource won't be established, you'll need to manually call connect method to establish dataSource.
|
|
55
|
+
*/
|
|
56
|
+
create(options) {
|
|
57
|
+
const name = options.name || 'default';
|
|
58
|
+
// check if such dataSource is already registered
|
|
59
|
+
const existDataSource = this.dataSourceMap.get(name);
|
|
60
|
+
if (existDataSource) {
|
|
61
|
+
// if dataSource is registered and its not closed then throw an error
|
|
62
|
+
if (existDataSource.isInitialized) {
|
|
63
|
+
throw new errors_1.AlreadyHasActiveDataSourceError(name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// create a new dataSource
|
|
67
|
+
const dataSource = new typeorm_1.DataSource(Object.assign(Object.assign({}, options), { name }));
|
|
68
|
+
this.dataSourceMap.set(name, dataSource);
|
|
69
|
+
return dataSource;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
DataSourceManager = __decorate([
|
|
73
|
+
(0, core_1.Component)()
|
|
74
|
+
], DataSourceManager);
|
|
75
|
+
exports.DataSourceManager = DataSourceManager;
|
|
76
|
+
//# sourceMappingURL=data-source-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source-manager.js","sourceRoot":"","sources":["../../src/common/data-source-manager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyC;AACzC,qCAAwD;AACxD,qCAAoF;AAEpF;;;;GAIG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAAvB;QAQH;;WAEG;QACc,kBAAa,GAA4B,IAAI,GAAG,EAAE,CAAC;IAgDxE,CAAC;IA1DG;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;IAOD,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAe,SAAS;QACxB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,UAAU,EAAE;YACb,MAAM,IAAI,gCAAuB,CAAC,IAAI,CAAC,CAAC;SAC3C;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAA8C;QAEjD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;QACvC,iDAAiD;QACjD,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,eAAe,EAAE;YACjB,qEAAqE;YACrE,IAAI,eAAe,CAAC,aAAa,EAAE;gBAC/B,MAAM,IAAI,wCAA+B,CAAC,IAAI,CAAC,CAAC;aACnD;SACJ;QAED,0BAA0B;QAC1B,MAAM,UAAU,GAAG,IAAI,oBAAU,iCAAM,OAAO,KAAE,IAAI,IAAE,CAAC;QACvD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ,CAAA;AA3DY,iBAAiB;IAD7B,IAAA,gBAAS,GAAE;GACC,iBAAiB,CA2D7B;AA3DY,8CAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-provider.d.ts","sourceRoot":"","sources":["../../src/common/entity-provider.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,SAA0B,QAe7E;AAED,yBAAiB,cAAc,CAAC;IAC5B,SAAgB,WAAW,CAAC,IAAI,SAA0B,0BAEzD;CACJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityProvider = exports.autoBindEntities = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const _entitiyMap = new Map();
|
|
6
|
+
function autoBindEntities(entities, name = constants_1.DEFAULT_CONNECTION_NAME) {
|
|
7
|
+
let _entities = entities;
|
|
8
|
+
if (!Array.isArray(entities)) {
|
|
9
|
+
_entities = [];
|
|
10
|
+
for (const key of Object.keys(entities)) {
|
|
11
|
+
_entities.push(entities[key]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (!_entitiyMap.get(name)) {
|
|
15
|
+
}
|
|
16
|
+
const current = _entitiyMap.get(name) || [];
|
|
17
|
+
_entitiyMap.set(name, [...current, ..._entities]);
|
|
18
|
+
}
|
|
19
|
+
exports.autoBindEntities = autoBindEntities;
|
|
20
|
+
var EntityProvider;
|
|
21
|
+
(function (EntityProvider) {
|
|
22
|
+
function getEntities(name = constants_1.DEFAULT_CONNECTION_NAME) {
|
|
23
|
+
return _entitiyMap.get(name);
|
|
24
|
+
}
|
|
25
|
+
EntityProvider.getEntities = getEntities;
|
|
26
|
+
})(EntityProvider = exports.EntityProvider || (exports.EntityProvider = {}));
|
|
27
|
+
//# sourceMappingURL=entity-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-provider.js","sourceRoot":"","sources":["../../src/common/entity-provider.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AAEtD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;AAElD,SAAgB,gBAAgB,CAAC,QAAa,EAAE,IAAI,GAAG,mCAAuB;IAC1E,IAAI,SAAS,GAAG,QAAQ,CAAC;IACzB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC1B,SAAS,GAAG,EAAE,CAAC;QACf,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACrC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;SACjC;KACJ;IACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;KAE3B;IACD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5C,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,CAAE,GAAG,OAAO,EAAE,GAAG,SAAS,CAAE,CAAC,CAAC;AAExD,CAAC;AAfD,4CAeC;AAED,IAAiB,cAAc,CAI9B;AAJD,WAAiB,cAAc;IAC3B,SAAgB,WAAW,CAAC,IAAI,GAAG,mCAAuB;QACtD,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAFe,0BAAW,cAE1B,CAAA;AACL,CAAC,EAJgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAI9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypeORMError } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when consumer tries to get datasource that does not exist.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DataSourceNotFoundError extends TypeORMError {
|
|
6
|
+
constructor(name: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when consumer tries to recreate datasource with the same name, but previous datasource was not closed yet.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AlreadyHasActiveDataSourceError extends TypeORMError {
|
|
12
|
+
constructor(DataSourceName: string);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/common/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;gBACzC,IAAI,EAAE,MAAM;CAG3B;AAED;;GAEG;AACH,qBAAa,+BAAgC,SAAQ,YAAY;gBACjD,cAAc,EAAE,MAAM;CAMrC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlreadyHasActiveDataSourceError = exports.DataSourceNotFoundError = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when consumer tries to get datasource that does not exist.
|
|
7
|
+
*/
|
|
8
|
+
class DataSourceNotFoundError extends typeorm_1.TypeORMError {
|
|
9
|
+
constructor(name) {
|
|
10
|
+
super(`DataSource "${name}" was not found.`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.DataSourceNotFoundError = DataSourceNotFoundError;
|
|
14
|
+
/**
|
|
15
|
+
* Thrown when consumer tries to recreate datasource with the same name, but previous datasource was not closed yet.
|
|
16
|
+
*/
|
|
17
|
+
class AlreadyHasActiveDataSourceError extends typeorm_1.TypeORMError {
|
|
18
|
+
constructor(DataSourceName) {
|
|
19
|
+
super(`Cannot create a new DataSource named "${DataSourceName}", because DataSource with such name ` +
|
|
20
|
+
'already exist and it now has an active DataSource session.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AlreadyHasActiveDataSourceError = AlreadyHasActiveDataSourceError;
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/common/errors.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAEvC;;GAEG;AACH,MAAa,uBAAwB,SAAQ,sBAAY;IACrD,YAAY,IAAY;QACpB,KAAK,CAAC,eAAe,IAAI,kBAAkB,CAAC,CAAC;IACjD,CAAC;CACJ;AAJD,0DAIC;AAED;;GAEG;AACH,MAAa,+BAAgC,SAAQ,sBAAY;IAC7D,YAAY,cAAsB;QAC9B,KAAK,CACD,yCAAyC,cAAc,uCAAuC;YAC1F,4DAA4D,CACnE,CAAC;IACN,CAAC;CACJ;AAPD,0EAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./entity-provider"), exports);
|
|
19
|
+
__exportStar(require("./typeorm-initializer"), exports);
|
|
20
|
+
__exportStar(require("./data-source-manager"), exports);
|
|
21
|
+
__exportStar(require("./errors"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,oDAAkC;AAClC,wDAAsC;AACtC,wDAAsC;AACtC,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApplicationLifecycle, Application, Deferred } from '@celljs/core';
|
|
2
|
+
import { DataSourceManager } from './data-source-manager';
|
|
3
|
+
export declare class TypeOrmInitializer implements ApplicationLifecycle<Application> {
|
|
4
|
+
readonly initialized: Deferred<void>;
|
|
5
|
+
protected readonly options: any;
|
|
6
|
+
protected readonly dataSourceManager: DataSourceManager;
|
|
7
|
+
onStart(app: Application): Promise<void>;
|
|
8
|
+
onStop(app: Application): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=typeorm-initializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-initializer.d.ts","sourceRoot":"","sources":["../../src/common/typeorm-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,oBAAoB,EAAE,WAAW,EAAoB,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D,qBACa,kBAAmB,YAAW,oBAAoB,CAAC,WAAW,CAAC;IAExE,QAAQ,CAAC,WAAW,iBAAwB;IAG5C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IAGhC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAElD,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB9C,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;CASjC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TypeOrmInitializer = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const data_source_manager_1 = require("./data-source-manager");
|
|
16
|
+
const entity_provider_1 = require("./entity-provider");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
let TypeOrmInitializer = class TypeOrmInitializer {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.initialized = new core_1.Deferred();
|
|
21
|
+
}
|
|
22
|
+
async onStart(app) {
|
|
23
|
+
const { ormConfig } = this.options;
|
|
24
|
+
let configs;
|
|
25
|
+
if (Array.isArray(ormConfig)) {
|
|
26
|
+
configs = ormConfig;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
ormConfig.name = constants_1.DEFAULT_CONNECTION_NAME;
|
|
30
|
+
configs = [ormConfig];
|
|
31
|
+
}
|
|
32
|
+
for (const config of configs) {
|
|
33
|
+
config.entities = entity_provider_1.EntityProvider.getEntities(config.name) || [];
|
|
34
|
+
}
|
|
35
|
+
await (0, utils_1.createDataSources)(configs);
|
|
36
|
+
this.initialized.resolve();
|
|
37
|
+
}
|
|
38
|
+
onStop(app) {
|
|
39
|
+
const dataSources = this.dataSourceManager.dataSources;
|
|
40
|
+
for (const dataSource of dataSources) {
|
|
41
|
+
if (dataSource.isInitialized) {
|
|
42
|
+
dataSource.destroy();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, core_1.Value)('cell.typeorm'),
|
|
49
|
+
__metadata("design:type", Object)
|
|
50
|
+
], TypeOrmInitializer.prototype, "options", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, core_1.Autowired)(data_source_manager_1.DataSourceManager),
|
|
53
|
+
__metadata("design:type", data_source_manager_1.DataSourceManager)
|
|
54
|
+
], TypeOrmInitializer.prototype, "dataSourceManager", void 0);
|
|
55
|
+
TypeOrmInitializer = __decorate([
|
|
56
|
+
(0, core_1.Component)(core_1.ApplicationLifecycle)
|
|
57
|
+
], TypeOrmInitializer);
|
|
58
|
+
exports.TypeOrmInitializer = TypeOrmInitializer;
|
|
59
|
+
//# sourceMappingURL=typeorm-initializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-initializer.js","sourceRoot":"","sources":["../../src/common/typeorm-initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAwG;AACxG,2CAAsD;AACtD,+DAA0D;AAC1D,uDAAmD;AACnD,mCAA4C;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QAEM,gBAAW,GAAG,IAAI,eAAQ,EAAQ,CAAC;IAmChD,CAAC;IA3BG,KAAK,CAAC,OAAO,CAAC,GAAgB;QAC1B,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACnC,IAAI,OAAc,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC1B,OAAO,GAAG,SAAS,CAAC;SACvB;aAAM;YACH,SAAS,CAAC,IAAI,GAAG,mCAAuB,CAAC;YACzC,OAAO,GAAG,CAAE,SAAS,CAAE,CAAC;SAC3B;QAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC1B,MAAM,CAAC,QAAQ,GAAG,gCAAc,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SACnE;QAED,MAAM,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,GAAgB;QACnB,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC;QACvD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YAClC,IAAI,UAAU,CAAC,aAAa,EAAE;gBAC1B,UAAU,CAAC,OAAO,EAAE,CAAC;aACxB;SACJ;IACL,CAAC;CAEJ,CAAA;AAjCG;IAAC,IAAA,YAAK,EAAC,cAAc,CAAC;;mDACU;AAEhC;IAAC,IAAA,gBAAS,EAAC,uCAAiB,CAAC;8BACS,uCAAiB;6DAAC;AAR/C,kBAAkB;IAD9B,IAAA,gBAAS,EAAC,2BAAoB,CAAC;GACnB,kBAAkB,CAqC9B;AArCY,gDAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGxD,wBAAsB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,uBAOhD;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAQ3F"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDataSources = exports.getDataSource = void 0;
|
|
4
|
+
const core_1 = require("@celljs/core");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
async function getDataSource(name) {
|
|
7
|
+
const dataSourceManager = core_1.ContainerUtil.get(common_1.DataSourceManager);
|
|
8
|
+
const dataSource = dataSourceManager.get(name);
|
|
9
|
+
if (!dataSource.isInitialized) {
|
|
10
|
+
await dataSource.initialize();
|
|
11
|
+
}
|
|
12
|
+
return dataSource;
|
|
13
|
+
}
|
|
14
|
+
exports.getDataSource = getDataSource;
|
|
15
|
+
async function createDataSources(options) {
|
|
16
|
+
const dataSourceManager = core_1.ContainerUtil.get(common_1.DataSourceManager);
|
|
17
|
+
const dataSources = options.map(option => dataSourceManager.create(option));
|
|
18
|
+
// Do not use Promise.all or test 8522 will produce a dangling sqlite connection
|
|
19
|
+
for (const dataSource of dataSources) {
|
|
20
|
+
await dataSource.initialize();
|
|
21
|
+
}
|
|
22
|
+
return dataSources;
|
|
23
|
+
}
|
|
24
|
+
exports.createDataSources = createDataSources;
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;AAAA,uCAA6C;AAE7C,sCAA8C;AAEvC,KAAK,UAAU,aAAa,CAAC,IAAa;IAC7C,MAAM,iBAAiB,GAAG,oBAAa,CAAC,GAAG,CAAC,0BAAiB,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE;QAC3B,MAAM,UAAU,CAAC,UAAU,EAAE,CAAC;KACjC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAPD,sCAOC;AAEM,KAAK,UAAU,iBAAiB,CAAC,OAA4B;IAChE,MAAM,iBAAiB,GAAG,oBAAa,CAAC,GAAG,CAAC,0BAAiB,CAAC,CAAC;IAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5E,gFAAgF;IAChF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QAClC,MAAM,UAAU,CAAC,UAAU,EAAE,CAAC;KACjC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC;AARD,8CAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/annotation/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./transactional"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/annotation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IsolationLevel } from 'typeorm/driver/types/IsolationLevel';
|
|
2
|
+
export declare enum Propagation {
|
|
3
|
+
Required = 0,
|
|
4
|
+
RequiresNew = 1
|
|
5
|
+
}
|
|
6
|
+
export interface TransactionalOption {
|
|
7
|
+
name?: string;
|
|
8
|
+
isolation?: IsolationLevel;
|
|
9
|
+
propagation?: Propagation;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace TransactionalOption {
|
|
13
|
+
function is(option: any): option is TransactionalOption;
|
|
14
|
+
}
|
|
15
|
+
export interface TransactionalDecorator {
|
|
16
|
+
(nameOrTransactionalOption?: string | TransactionalOption): MethodDecorator;
|
|
17
|
+
}
|
|
18
|
+
export declare const Transactional: TransactionalDecorator;
|
|
19
|
+
export declare function getTransactionalOption(nameOrTransactionalOption?: string | TransactionalOption): TransactionalOption;
|
|
20
|
+
//# sourceMappingURL=transactional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional.d.ts","sourceRoot":"","sources":["../../../src/node/annotation/transactional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAMrE,oBAAY,WAAW;IACnB,QAAQ,IAAA;IAAE,WAAW,IAAA;CACxB;AAED,MAAM,WAAW,mBAAmB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,yBAAiB,mBAAmB,CAAC;IACjC,SAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,mBAAmB,CAE7D;CACJ;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,yBAAyB,CAAC,EAAE,MAAM,GAAG,mBAAmB,GAAG,eAAe,CAAC;CAC/E;AAED,eAAO,MAAM,aAAa,wBAqDzB,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,yBAAyB,CAAC,EAAE,MAAM,GAAG,mBAAmB,uBAc9F"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTransactionalOption = exports.Transactional = exports.TransactionalOption = exports.Propagation = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
const node_1 = require("@celljs/core/lib/node");
|
|
7
|
+
var Propagation;
|
|
8
|
+
(function (Propagation) {
|
|
9
|
+
Propagation[Propagation["Required"] = 0] = "Required";
|
|
10
|
+
Propagation[Propagation["RequiresNew"] = 1] = "RequiresNew";
|
|
11
|
+
})(Propagation = exports.Propagation || (exports.Propagation = {}));
|
|
12
|
+
var TransactionalOption;
|
|
13
|
+
(function (TransactionalOption) {
|
|
14
|
+
function is(option) {
|
|
15
|
+
return option && (option.name !== undefined || option.isolation !== undefined || option.readOnly !== undefined);
|
|
16
|
+
}
|
|
17
|
+
TransactionalOption.is = is;
|
|
18
|
+
})(TransactionalOption = exports.TransactionalOption || (exports.TransactionalOption = {}));
|
|
19
|
+
exports.Transactional = function (nameOrTransactionalOption) {
|
|
20
|
+
const { name, isolation, propagation, readOnly } = getTransactionalOption(nameOrTransactionalOption);
|
|
21
|
+
return (target, methodName, descriptor) => {
|
|
22
|
+
const originalMethod = descriptor.value;
|
|
23
|
+
descriptor.value = async function (...args) {
|
|
24
|
+
if (propagation === Propagation.Required) {
|
|
25
|
+
const em = context_1.OrmContext.getEntityManager(name);
|
|
26
|
+
if (em && em.queryRunner && (em.queryRunner.isTransactionActive || readOnly)) {
|
|
27
|
+
return originalMethod.apply(this, args);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const callback = async (entityManager) => {
|
|
31
|
+
context_1.OrmContext.pushEntityManager(name, entityManager);
|
|
32
|
+
try {
|
|
33
|
+
return await originalMethod.apply(this, args);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
context_1.OrmContext.popEntityManager(name);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const dataSource = await (0, common_1.getDataSource)(name);
|
|
40
|
+
const manager = dataSource.manager;
|
|
41
|
+
if (readOnly) {
|
|
42
|
+
return callback(manager);
|
|
43
|
+
}
|
|
44
|
+
else if (isolation) {
|
|
45
|
+
return manager.transaction(isolation, callback);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return manager.transaction(callback);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const originalMethod2 = descriptor.value;
|
|
52
|
+
descriptor.value = async function (...args) {
|
|
53
|
+
if (!node_1.Context.getCurrent()) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
node_1.Context.run(async () => {
|
|
56
|
+
node_1.Context.setCurrent(new node_1.Context());
|
|
57
|
+
try {
|
|
58
|
+
resolve(originalMethod2.apply(this, args));
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return originalMethod2.apply(this, args);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
function getTransactionalOption(nameOrTransactionalOption) {
|
|
74
|
+
const defaultOption = {
|
|
75
|
+
name: common_1.DEFAULT_CONNECTION_NAME,
|
|
76
|
+
propagation: Propagation.Required,
|
|
77
|
+
readOnly: false
|
|
78
|
+
};
|
|
79
|
+
let option = defaultOption;
|
|
80
|
+
if (TransactionalOption.is(nameOrTransactionalOption)) {
|
|
81
|
+
option = Object.assign(Object.assign({}, defaultOption), nameOrTransactionalOption);
|
|
82
|
+
}
|
|
83
|
+
else if (nameOrTransactionalOption) {
|
|
84
|
+
option = Object.assign(Object.assign({}, defaultOption), { name: nameOrTransactionalOption });
|
|
85
|
+
}
|
|
86
|
+
return option;
|
|
87
|
+
}
|
|
88
|
+
exports.getTransactionalOption = getTransactionalOption;
|
|
89
|
+
//# sourceMappingURL=transactional.js.map
|