@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/node/annotation/transactional.ts"],"names":[],"mappings":";;;AACA,yCAAsE;AAEtE,wCAAwC;AACxC,gDAAgD;AAEhD,IAAY,WAEX;AAFD,WAAY,WAAW;IACnB,qDAAQ,CAAA;IAAE,2DAAW,CAAA;AACzB,CAAC,EAFW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAEtB;AAQD,IAAiB,mBAAmB,CAInC;AAJD,WAAiB,mBA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IACF,IAAI,MAAM,GAAwB,aAAa,CAAC;IAChD,IAAI,mBAAmB,CAAC,EAAE,CAAC,yBAAyB,CAAC,EAAE;QACnD,MAAM,mCAAQ,aAAa,GAAK,yBAAyB,CAAE,CAAC;KAC/D;SAAM,IAAI,yBAAyB,EAAE;QAClC,MAAM,mCAAQ,aAAa,KAAE,IAAI,EAAE,yBAAyB,GAAE,CAAC;KAClE;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAdD,wDAcC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityManager, ObjectType, EntitySchema, Repository, TreeRepository, MongoRepository, ObjectLiteral } from 'typeorm';
|
|
2
|
+
export declare const CURRENT_ORM_CONTEXT_REQUEST_KEY = "CurrentOrmContextRequest";
|
|
3
|
+
export declare namespace OrmContext {
|
|
4
|
+
function getEntityManager(name?: string): EntityManager;
|
|
5
|
+
function getRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity> | EntitySchema<Entity> | string, name?: string): Repository<Entity>;
|
|
6
|
+
function getTreeRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity> | EntitySchema<Entity> | string, name?: string): TreeRepository<Entity>;
|
|
7
|
+
function getMongoRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity> | EntitySchema<Entity> | string, name?: string): MongoRepository<Entity>;
|
|
8
|
+
function pushEntityManager(name: string, entityManager: EntityManager): void;
|
|
9
|
+
function popEntityManager(name: string): EntityManager | undefined;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=context-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/context/context-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG9H,eAAO,MAAM,+BAA+B,6BAA6B,CAAC;AAE1E,yBAAiB,UAAU,CAAC;IAExB,SAAgB,gBAAgB,CAAC,IAAI,SAA0B,GAAG,aAAa,CAS9E;IAED,SAAgB,aAAa,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GAAC,YAAY,CAAC,MAAM,CAAC,GAAC,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAErJ;IAED,SAAgB,iBAAiB,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GAAC,YAAY,CAAC,MAAM,CAAC,GAAC,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAE7J;IAED,SAAgB,kBAAkB,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GAAC,YAAY,CAAC,MAAM,CAAC,GAAC,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAE/J;IAED,SAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,IAAI,CAUlF;IAED,SAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAQxE;CAEJ"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrmContext = exports.CURRENT_ORM_CONTEXT_REQUEST_KEY = void 0;
|
|
4
|
+
const node_1 = require("@celljs/core/lib/node");
|
|
5
|
+
const common_1 = require("../../common");
|
|
6
|
+
exports.CURRENT_ORM_CONTEXT_REQUEST_KEY = 'CurrentOrmContextRequest';
|
|
7
|
+
var OrmContext;
|
|
8
|
+
(function (OrmContext) {
|
|
9
|
+
function getEntityManager(name = common_1.DEFAULT_CONNECTION_NAME) {
|
|
10
|
+
const entityManagerMap = node_1.Context.getAttr(exports.CURRENT_ORM_CONTEXT_REQUEST_KEY, node_1.AttributeScope.Request);
|
|
11
|
+
if (entityManagerMap) {
|
|
12
|
+
const entityManagers = entityManagerMap.get(name);
|
|
13
|
+
if (entityManagers && entityManagers.length > 0) {
|
|
14
|
+
return entityManagers[entityManagers.length - 1];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
OrmContext.getEntityManager = getEntityManager;
|
|
20
|
+
function getRepository(target, name) {
|
|
21
|
+
return getEntityManager(name).getRepository(target);
|
|
22
|
+
}
|
|
23
|
+
OrmContext.getRepository = getRepository;
|
|
24
|
+
function getTreeRepository(target, name) {
|
|
25
|
+
return getEntityManager(name).getTreeRepository(target);
|
|
26
|
+
}
|
|
27
|
+
OrmContext.getTreeRepository = getTreeRepository;
|
|
28
|
+
function getMongoRepository(target, name) {
|
|
29
|
+
return getEntityManager(name).getMongoRepository(target);
|
|
30
|
+
}
|
|
31
|
+
OrmContext.getMongoRepository = getMongoRepository;
|
|
32
|
+
function pushEntityManager(name, entityManager) {
|
|
33
|
+
let entityManagerMap = node_1.Context.getAttr(exports.CURRENT_ORM_CONTEXT_REQUEST_KEY, node_1.AttributeScope.Request);
|
|
34
|
+
if (!entityManagerMap) {
|
|
35
|
+
entityManagerMap = new Map();
|
|
36
|
+
node_1.Context.setAttr(exports.CURRENT_ORM_CONTEXT_REQUEST_KEY, entityManagerMap);
|
|
37
|
+
}
|
|
38
|
+
if (!entityManagerMap.get(name)) {
|
|
39
|
+
entityManagerMap.set(name, []);
|
|
40
|
+
}
|
|
41
|
+
entityManagerMap.get(name).push(entityManager);
|
|
42
|
+
}
|
|
43
|
+
OrmContext.pushEntityManager = pushEntityManager;
|
|
44
|
+
function popEntityManager(name) {
|
|
45
|
+
const entityManagerMap = node_1.Context.getAttr(exports.CURRENT_ORM_CONTEXT_REQUEST_KEY, node_1.AttributeScope.Request);
|
|
46
|
+
if (entityManagerMap) {
|
|
47
|
+
const entityManagers = entityManagerMap.get(name);
|
|
48
|
+
if (entityManagers && entityManagers.length > 0) {
|
|
49
|
+
return entityManagers.pop();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
OrmContext.popEntityManager = popEntityManager;
|
|
54
|
+
})(OrmContext = exports.OrmContext || (exports.OrmContext = {}));
|
|
55
|
+
//# sourceMappingURL=context-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-protocol.js","sourceRoot":"","sources":["../../../src/node/context/context-protocol.ts"],"names":[],"mappings":";;;AAAA,gDAAgE;AAEhE,yCAAuD;AAE1C,QAAA,+BAA+B,GAAG,0BAA0B,CAAC;AAE1E,IAAiB,UAAU,CA+C1B;AA/CD,WAAiB,UAAU;IAEvB,SAAgB,gBAAgB,CAAC,IAAI,GAAG,gCAAuB;QAC3D,MAAM,gBAAgB,GAAG,cAAO,CAAC,OAAO,CAA+B,uCAA+B,EAAE,qBAAc,CAAC,OAAO,CAAC,CAAC;QAChI,IAAI,gBAAgB,EAAE;YAClB,MAAM,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClD,IAAI,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC7C,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aACpD;SACJ;QACD,OAA+B,SAAS,CAAC;IAC7C,CAAC;IATe,2BAAgB,mBAS/B,CAAA;IAED,SAAgB,aAAa,CAA+B,MAAsD,EAAE,IAAa;QAC7H,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,aAAa,CAAS,MAAM,CAAC,CAAC;IAChE,CAAC;IAFe,wBAAa,gBAE5B,CAAA;IAED,SAAgB,iBAAiB,CAA+B,MAAsD,EAAE,IAAa;QACjI,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,iBAAiB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0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,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("./context-protocol"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./annotation"), exports);
|
|
18
|
+
__exportStar(require("./context"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;;AAE1B,wBAA0B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
const core_1 = require("@celljs/core");
|
|
18
|
+
__exportStar(require("../common"), exports);
|
|
19
|
+
exports.default = (0, core_1.autoBind)();
|
|
20
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAwC;AACxC,4CAA0B;AAE1B,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAE7B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/typeorm",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/common/index.js",
|
|
6
|
+
"typings": "lib/common/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/core": "3.0.0",
|
|
9
|
+
"mysql2": "^2.3.3",
|
|
10
|
+
"typeorm": "^0.3.7"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cell-component"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
27
|
+
"files": [
|
|
28
|
+
"lib",
|
|
29
|
+
"src",
|
|
30
|
+
"cell.yml",
|
|
31
|
+
"cell-fc.yml"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"lint": "cell-component lint",
|
|
35
|
+
"build": "cell-component build",
|
|
36
|
+
"watch": "cell-component watch",
|
|
37
|
+
"clean": "cell-component clean",
|
|
38
|
+
"test": "cell-component test:js"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@celljs/cli-service": "3.0.0",
|
|
42
|
+
"@celljs/component": "3.0.0"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_CONNECTION_NAME = 'default';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Component } from '@celljs/core';
|
|
2
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
|
3
|
+
import { DataSourceNotFoundError, AlreadyHasActiveDataSourceError } from './errors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DataSourceManager is used to store and manage multiple orm dataSources.
|
|
7
|
+
* It also provides useful factory methods to simplify dataSource creation.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
@Component()
|
|
11
|
+
export class DataSourceManager {
|
|
12
|
+
/**
|
|
13
|
+
* List of dataSources registered in this dataSource manager.
|
|
14
|
+
*/
|
|
15
|
+
get dataSources(): DataSource[] {
|
|
16
|
+
return Array.from(this.dataSourceMap.values());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal lookup to quickly get from a dataSource name to the DataSource object.
|
|
21
|
+
*/
|
|
22
|
+
private readonly dataSourceMap: Map<string, DataSource> = new Map();
|
|
23
|
+
|
|
24
|
+
// -------------------------------------------------------------------------
|
|
25
|
+
// Public Methods
|
|
26
|
+
// -------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if dataSource with the given name exist in the manager.
|
|
30
|
+
*/
|
|
31
|
+
has(name: string): boolean {
|
|
32
|
+
return this.dataSourceMap.has(name);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets registered dataSource with the given name.
|
|
37
|
+
* If dataSource name is not given then it will get a default dataSource.
|
|
38
|
+
* Throws error if dataSource with the given name was not found.
|
|
39
|
+
*/
|
|
40
|
+
get(name: string = 'default'): DataSource {
|
|
41
|
+
const dataSource = this.dataSourceMap.get(name);
|
|
42
|
+
if (!dataSource) {
|
|
43
|
+
throw new DataSourceNotFoundError(name);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return dataSource;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new dataSource based on the given dataSource options and registers it in the manager.
|
|
51
|
+
* DataSource won't be established, you'll need to manually call connect method to establish dataSource.
|
|
52
|
+
*/
|
|
53
|
+
create(options: DataSourceOptions & { name?: string }): DataSource {
|
|
54
|
+
|
|
55
|
+
const name = options.name || 'default';
|
|
56
|
+
// check if such dataSource is already registered
|
|
57
|
+
const existDataSource = this.dataSourceMap.get(name);
|
|
58
|
+
if (existDataSource) {
|
|
59
|
+
// if dataSource is registered and its not closed then throw an error
|
|
60
|
+
if (existDataSource.isInitialized) {
|
|
61
|
+
throw new AlreadyHasActiveDataSourceError(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// create a new dataSource
|
|
66
|
+
const dataSource = new DataSource({ ...options, name});
|
|
67
|
+
this.dataSourceMap.set(name, dataSource);
|
|
68
|
+
return dataSource;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { DEFAULT_CONNECTION_NAME } from './constants';
|
|
3
|
+
|
|
4
|
+
const _entitiyMap = new Map<string, Function[]>();
|
|
5
|
+
|
|
6
|
+
export function autoBindEntities(entities: any, name = 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
|
+
}
|
|
17
|
+
const current = _entitiyMap.get(name) || [];
|
|
18
|
+
|
|
19
|
+
_entitiyMap.set(name, [ ...current, ..._entities ]);
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export namespace EntityProvider {
|
|
24
|
+
export function getEntities(name = DEFAULT_CONNECTION_NAME) {
|
|
25
|
+
return _entitiyMap.get(name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TypeORMError } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when consumer tries to get datasource that does not exist.
|
|
5
|
+
*/
|
|
6
|
+
export class DataSourceNotFoundError extends TypeORMError {
|
|
7
|
+
constructor(name: string) {
|
|
8
|
+
super(`DataSource "${name}" was not found.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Thrown when consumer tries to recreate datasource with the same name, but previous datasource was not closed yet.
|
|
14
|
+
*/
|
|
15
|
+
export class AlreadyHasActiveDataSourceError extends TypeORMError {
|
|
16
|
+
constructor(DataSourceName: string) {
|
|
17
|
+
super(
|
|
18
|
+
`Cannot create a new DataSource named "${DataSourceName}", because DataSource with such name ` +
|
|
19
|
+
'already exist and it now has an active DataSource session.',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Component, ApplicationLifecycle, Application, Value, Autowired, Deferred } from '@celljs/core';
|
|
2
|
+
import { DEFAULT_CONNECTION_NAME } from './constants';
|
|
3
|
+
import { DataSourceManager } from './data-source-manager';
|
|
4
|
+
import { EntityProvider } from './entity-provider';
|
|
5
|
+
import { createDataSources } from './utils';
|
|
6
|
+
|
|
7
|
+
@Component(ApplicationLifecycle)
|
|
8
|
+
export class TypeOrmInitializer implements ApplicationLifecycle<Application> {
|
|
9
|
+
|
|
10
|
+
readonly initialized = new Deferred<void>();
|
|
11
|
+
|
|
12
|
+
@Value('cell.typeorm')
|
|
13
|
+
protected readonly options: any;
|
|
14
|
+
|
|
15
|
+
@Autowired(DataSourceManager)
|
|
16
|
+
protected readonly dataSourceManager: DataSourceManager;
|
|
17
|
+
|
|
18
|
+
async onStart(app: Application): Promise<void> {
|
|
19
|
+
const { ormConfig } = this.options;
|
|
20
|
+
let configs: any[];
|
|
21
|
+
if (Array.isArray(ormConfig)) {
|
|
22
|
+
configs = ormConfig;
|
|
23
|
+
} else {
|
|
24
|
+
ormConfig.name = DEFAULT_CONNECTION_NAME;
|
|
25
|
+
configs = [ ormConfig ];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const config of configs) {
|
|
29
|
+
config.entities = EntityProvider.getEntities(config.name) || [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await createDataSources(configs);
|
|
33
|
+
this.initialized.resolve();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
onStop(app: Application): void {
|
|
37
|
+
const dataSources = this.dataSourceManager.dataSources;
|
|
38
|
+
for (const dataSource of dataSources) {
|
|
39
|
+
if (dataSource.isInitialized) {
|
|
40
|
+
dataSource.destroy();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContainerUtil } from '@celljs/core';
|
|
2
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
|
3
|
+
import { DataSourceManager } from '../common';
|
|
4
|
+
|
|
5
|
+
export async function getDataSource(name?: string) {
|
|
6
|
+
const dataSourceManager = ContainerUtil.get(DataSourceManager);
|
|
7
|
+
const dataSource = dataSourceManager.get(name);
|
|
8
|
+
if (!dataSource.isInitialized) {
|
|
9
|
+
await dataSource.initialize();
|
|
10
|
+
}
|
|
11
|
+
return dataSource;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function createDataSources(options: DataSourceOptions[]): Promise<DataSource[]> {
|
|
15
|
+
const dataSourceManager = ContainerUtil.get(DataSourceManager);
|
|
16
|
+
const dataSources = options.map(option => dataSourceManager.create(option));
|
|
17
|
+
// Do not use Promise.all or test 8522 will produce a dangling sqlite connection
|
|
18
|
+
for (const dataSource of dataSources) {
|
|
19
|
+
await dataSource.initialize();
|
|
20
|
+
}
|
|
21
|
+
return dataSources;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './transactional';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { IsolationLevel } from 'typeorm/driver/types/IsolationLevel';
|
|
2
|
+
import { DEFAULT_CONNECTION_NAME, getDataSource } from '../../common';
|
|
3
|
+
import { EntityManager } from 'typeorm';
|
|
4
|
+
import { OrmContext } from '../context';
|
|
5
|
+
import { Context } from '@celljs/core/lib/node';
|
|
6
|
+
|
|
7
|
+
export enum Propagation {
|
|
8
|
+
Required, RequiresNew
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TransactionalOption {
|
|
12
|
+
name?: string;
|
|
13
|
+
isolation?: IsolationLevel;
|
|
14
|
+
propagation?: Propagation;
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export namespace TransactionalOption {
|
|
18
|
+
export function is(option: any): option is TransactionalOption {
|
|
19
|
+
return option && (option.name !== undefined || option.isolation !== undefined || option.readOnly !== undefined);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TransactionalDecorator {
|
|
24
|
+
(nameOrTransactionalOption?: string | TransactionalOption): MethodDecorator;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const Transactional = <TransactionalDecorator>function (nameOrTransactionalOption?: string | TransactionalOption): MethodDecorator {
|
|
28
|
+
const { name, isolation, propagation, readOnly } = getTransactionalOption(nameOrTransactionalOption);
|
|
29
|
+
return (target: Object, methodName: string, descriptor: PropertyDescriptor) => {
|
|
30
|
+
const originalMethod = descriptor.value;
|
|
31
|
+
descriptor.value = async function (...args: any[]) {
|
|
32
|
+
if (propagation === Propagation.Required) {
|
|
33
|
+
const em = OrmContext.getEntityManager(name);
|
|
34
|
+
if (em && em.queryRunner && (em.queryRunner.isTransactionActive || readOnly)) {
|
|
35
|
+
return originalMethod.apply(this, args);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const callback = async (entityManager: EntityManager) => {
|
|
39
|
+
|
|
40
|
+
OrmContext.pushEntityManager(name!, entityManager);
|
|
41
|
+
try {
|
|
42
|
+
return await originalMethod.apply(this, args);
|
|
43
|
+
} finally {
|
|
44
|
+
OrmContext.popEntityManager(name!);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const dataSource = await getDataSource(name);
|
|
48
|
+
const manager = dataSource.manager;
|
|
49
|
+
if (readOnly) {
|
|
50
|
+
return callback(manager);
|
|
51
|
+
} else if (isolation) {
|
|
52
|
+
return manager.transaction(isolation, callback);
|
|
53
|
+
} else {
|
|
54
|
+
return manager.transaction(callback);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const originalMethod2 = descriptor.value;
|
|
59
|
+
|
|
60
|
+
descriptor.value = async function (...args: any[]) {
|
|
61
|
+
if (!Context.getCurrent()) {
|
|
62
|
+
return new Promise<any>((resolve, reject) => {
|
|
63
|
+
Context.run(async () => {
|
|
64
|
+
Context.setCurrent(new Context());
|
|
65
|
+
try {
|
|
66
|
+
resolve(originalMethod2.apply(this, args));
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
return originalMethod2.apply(this, args);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function getTransactionalOption(nameOrTransactionalOption?: string | TransactionalOption) {
|
|
83
|
+
const defaultOption = {
|
|
84
|
+
name: DEFAULT_CONNECTION_NAME,
|
|
85
|
+
propagation: Propagation.Required,
|
|
86
|
+
readOnly: false
|
|
87
|
+
};
|
|
88
|
+
let option: TransactionalOption = defaultOption;
|
|
89
|
+
if (TransactionalOption.is(nameOrTransactionalOption)) {
|
|
90
|
+
option = { ...defaultOption, ...nameOrTransactionalOption };
|
|
91
|
+
} else if (nameOrTransactionalOption) {
|
|
92
|
+
option = { ...defaultOption, name: nameOrTransactionalOption };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return option;
|
|
96
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Context, AttributeScope } from '@celljs/core/lib/node';
|
|
2
|
+
import { EntityManager, ObjectType, EntitySchema, Repository, TreeRepository, MongoRepository, ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { DEFAULT_CONNECTION_NAME } from '../../common';
|
|
4
|
+
|
|
5
|
+
export const CURRENT_ORM_CONTEXT_REQUEST_KEY = 'CurrentOrmContextRequest';
|
|
6
|
+
|
|
7
|
+
export namespace OrmContext {
|
|
8
|
+
|
|
9
|
+
export function getEntityManager(name = DEFAULT_CONNECTION_NAME): EntityManager {
|
|
10
|
+
const entityManagerMap = Context.getAttr<Map<string, EntityManager[]>>(CURRENT_ORM_CONTEXT_REQUEST_KEY, AttributeScope.Request);
|
|
11
|
+
if (entityManagerMap) {
|
|
12
|
+
const entityManagers = entityManagerMap.get(name);
|
|
13
|
+
if (entityManagers && entityManagers.length > 0) {
|
|
14
|
+
return entityManagers[entityManagers.length - 1];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return <EntityManager><unknown>undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): Repository<Entity> {
|
|
21
|
+
return getEntityManager(name).getRepository<Entity>(target);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getTreeRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): TreeRepository<Entity> {
|
|
25
|
+
return getEntityManager(name).getTreeRepository<Entity>(target);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getMongoRepository<Entity extends ObjectLiteral>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): MongoRepository<Entity> {
|
|
29
|
+
return getEntityManager(name).getMongoRepository<Entity>(target);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function pushEntityManager(name: string, entityManager: EntityManager): void {
|
|
33
|
+
let entityManagerMap = Context.getAttr<Map<string, EntityManager[]>>(CURRENT_ORM_CONTEXT_REQUEST_KEY, AttributeScope.Request);
|
|
34
|
+
if (!entityManagerMap) {
|
|
35
|
+
entityManagerMap = new Map<string, EntityManager[]>();
|
|
36
|
+
Context.setAttr(CURRENT_ORM_CONTEXT_REQUEST_KEY, entityManagerMap);
|
|
37
|
+
}
|
|
38
|
+
if (!entityManagerMap.get(name)) {
|
|
39
|
+
entityManagerMap.set(name, []);
|
|
40
|
+
}
|
|
41
|
+
entityManagerMap.get(name)!.push(entityManager);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function popEntityManager(name: string): EntityManager | undefined {
|
|
45
|
+
const entityManagerMap = Context.getAttr<Map<string, EntityManager[]>>(CURRENT_ORM_CONTEXT_REQUEST_KEY, AttributeScope.Request);
|
|
46
|
+
if (entityManagerMap) {
|
|
47
|
+
const entityManagers = entityManagerMap.get(name);
|
|
48
|
+
if (entityManagers && entityManagers.length > 0) {
|
|
49
|
+
return entityManagers.pop();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context-protocol';
|