@midwayjs/tenant 3.15.6

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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # midwayjs tenant module
2
+
3
+ [![Package Quality](http://npm.packagequality.com/shield/midway-core.svg)](http://packagequality.com/#?package=midway-core)
4
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
+
6
+ this is a sub package for midway.
7
+
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
+
10
+ ## License
11
+
12
+ [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -0,0 +1,5 @@
1
+ import { IMidwayContainer } from '@midwayjs/core';
2
+ export declare class TenantConfiguration {
3
+ onReady(container: IMidwayContainer): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,32 @@
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.TenantConfiguration = void 0;
10
+ const core_1 = require("@midwayjs/core");
11
+ const tenantManager_1 = require("./tenantManager");
12
+ let TenantConfiguration = class TenantConfiguration {
13
+ async onReady(container) {
14
+ await container.getAsync(tenantManager_1.TenantManager);
15
+ }
16
+ };
17
+ TenantConfiguration = __decorate([
18
+ (0, core_1.Configuration)({
19
+ namespace: 'tenant',
20
+ importConfigs: [
21
+ {
22
+ default: {
23
+ asyncContextManager: {
24
+ enable: true,
25
+ },
26
+ },
27
+ },
28
+ ],
29
+ })
30
+ ], TenantConfiguration);
31
+ exports.TenantConfiguration = TenantConfiguration;
32
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,3 @@
1
+ export { TenantConfiguration } from './configuration';
2
+ export * from './tenantManager';
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
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
+ exports.TenantConfiguration = void 0;
18
+ var configuration_1 = require("./configuration");
19
+ Object.defineProperty(exports, "TenantConfiguration", { enumerable: true, get: function () { return configuration_1.TenantConfiguration; } });
20
+ __exportStar(require("./tenantManager"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import { IMidwayContainer } from '@midwayjs/core';
2
+ export declare class TenantManager {
3
+ applicationContext: IMidwayContainer;
4
+ getCurrentTenant<T = any>(): Promise<T>;
5
+ setCurrentTenant<T = any>(currentTenant: T): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=tenantManager.d.ts.map
@@ -0,0 +1,45 @@
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.TenantManager = void 0;
13
+ const core_1 = require("@midwayjs/core");
14
+ const CURRENT_TENANT_MANAGER_KEY = 'tenant:current_manager_tenant_key';
15
+ let TenantManager = class TenantManager {
16
+ async getCurrentTenant() {
17
+ const contextManager = this.applicationContext.get(core_1.ASYNC_CONTEXT_MANAGER_KEY);
18
+ const ctx = contextManager
19
+ .active()
20
+ .getValue(core_1.ASYNC_CONTEXT_KEY);
21
+ if (ctx) {
22
+ return ctx.getAttr(CURRENT_TENANT_MANAGER_KEY);
23
+ }
24
+ }
25
+ async setCurrentTenant(currentTenant) {
26
+ const contextManager = this.applicationContext.get(core_1.ASYNC_CONTEXT_MANAGER_KEY);
27
+ const activeContext = contextManager.active();
28
+ const requestContext = activeContext.getValue(core_1.ASYNC_CONTEXT_KEY);
29
+ if (requestContext) {
30
+ requestContext.setAttr(CURRENT_TENANT_MANAGER_KEY, currentTenant);
31
+ }
32
+ else {
33
+ throw new core_1.MidwayEmptyValueError('Current Async Context is Empty');
34
+ }
35
+ }
36
+ };
37
+ __decorate([
38
+ (0, core_1.ApplicationContext)(),
39
+ __metadata("design:type", Object)
40
+ ], TenantManager.prototype, "applicationContext", void 0);
41
+ TenantManager = __decorate([
42
+ (0, core_1.Singleton)()
43
+ ], TenantManager);
44
+ exports.TenantManager = TenantManager;
45
+ //# sourceMappingURL=tenantManager.js.map
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './dist/index';
2
+
3
+ declare module '@midwayjs/core/dist/interface' {
4
+ interface MidwayConfig {
5
+ tenant?: Record<string, any>;
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@midwayjs/tenant",
3
+ "description": "midway tenant component",
4
+ "version": "3.15.6",
5
+ "main": "dist/index.js",
6
+ "typings": "index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts",
10
+ "index.d.ts"
11
+ ],
12
+ "devDependencies": {
13
+ "@midwayjs/core": "^3.15.6",
14
+ "@midwayjs/mock": "^3.15.6"
15
+ },
16
+ "dependencies": {},
17
+ "keywords": [
18
+ "midway",
19
+ "tenant"
20
+ ],
21
+ "author": "czy88840616 <czy88840616@gmail.com>",
22
+ "license": "MIT",
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
26
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
27
+ "ci": "npm run test",
28
+ "lint": "mwts check"
29
+ },
30
+ "engines": {
31
+ "node": ">=12"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/midwayjs/midway.git"
36
+ }
37
+ }