@almatar/branding 0.1.4 → 0.1.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/lib/index.d.ts +13 -13
- package/lib/index.js +13 -13
- package/lib/lib/AlmatarBranding.d.ts +5 -4
- package/lib/lib/AlmatarBranding.js +14 -12
- package/lib/lib/BrandIdentifier.d.ts +8 -6
- package/lib/lib/BrandIdentifier.js +108 -86
- package/lib/lib/BrandManager.d.ts +17 -7
- package/lib/lib/BrandManager.js +148 -108
- package/lib/lib/Models/BrandModel.d.ts +8 -0
- package/lib/lib/Models/BrandModel.js +10 -0
- package/lib/lib/Models/EmployeeBrandModel.d.ts +6 -6
- package/lib/lib/Models/EmployeeBrandModel.js +10 -10
- package/lib/lib/Storage.d.ts +14 -10
- package/lib/lib/Storage.js +173 -135
- package/lib/lib/TenantModel/Mongoose/MultiTenant.d.ts +8 -8
- package/lib/lib/TenantModel/Mongoose/MultiTenant.js +24 -24
- package/lib/lib/TenantModel/MongooseModel.d.ts +13 -13
- package/lib/lib/TenantModel/MongooseModel.js +90 -84
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.d.ts +9 -9
- package/lib/lib/TenantModel/NestMongoose/TenantMongooseModule.js +45 -45
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.d.ts +10 -10
- package/lib/lib/TenantModel/NestMongoose/mongoose.providers.js +17 -17
- package/lib/lib/request/PromiseRequest.d.ts +3 -3
- package/lib/lib/request/PromiseRequest.js +61 -62
- package/lib/lib/request/TenantRequest.d.ts +4 -4
- package/lib/lib/request/TenantRequest.js +73 -73
- package/package.json +56 -56
- package/readme.md +146 -146
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EmployeeBrandModel = void 0;
|
|
4
|
-
var EmployeeBrandModel = /** @class */ (function () {
|
|
5
|
-
function EmployeeBrandModel(init) {
|
|
6
|
-
Object.assign(this, init);
|
|
7
|
-
}
|
|
8
|
-
return EmployeeBrandModel;
|
|
9
|
-
}());
|
|
10
|
-
exports.EmployeeBrandModel = EmployeeBrandModel;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmployeeBrandModel = void 0;
|
|
4
|
+
var EmployeeBrandModel = /** @class */ (function () {
|
|
5
|
+
function EmployeeBrandModel(init) {
|
|
6
|
+
Object.assign(this, init);
|
|
7
|
+
}
|
|
8
|
+
return EmployeeBrandModel;
|
|
9
|
+
}());
|
|
10
|
+
exports.EmployeeBrandModel = EmployeeBrandModel;
|
package/lib/lib/Storage.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
export default class ContextNamespace {
|
|
2
|
-
static bindENamespace(req: any, res: any, next: any): void;
|
|
3
|
-
static setEBrand(req: any, res: any, next: any): Promise<void>;
|
|
4
|
-
static bindHNamespace(req: any, reply: any): void;
|
|
5
|
-
static setHBrand(req: any, reply: any): Promise<void>;
|
|
6
|
-
static setBrand(
|
|
7
|
-
static getBrand(): any;
|
|
8
|
-
static getEmployeeBrands(): any;
|
|
9
|
-
static getNamespace(): any;
|
|
10
|
-
|
|
1
|
+
export default class ContextNamespace {
|
|
2
|
+
static bindENamespace(req: any, res: any, next: any): void;
|
|
3
|
+
static setEBrand(req: any, res: any, next: any): Promise<void>;
|
|
4
|
+
static bindHNamespace(req: any, reply: any): void;
|
|
5
|
+
static setHBrand(req: any, reply: any): Promise<void>;
|
|
6
|
+
static setBrand(brand: string | string[]): any;
|
|
7
|
+
static getBrand(): any;
|
|
8
|
+
static getEmployeeBrands(): any;
|
|
9
|
+
static getNamespace(): any;
|
|
10
|
+
static setBrands(brands: string[]): any;
|
|
11
|
+
static getBrands(): string[] | null;
|
|
12
|
+
static getDefaultBrand(): string | null;
|
|
13
|
+
static isValidBrand(brand: string): boolean;
|
|
14
|
+
}
|
package/lib/lib/Storage.js
CHANGED
|
@@ -1,135 +1,173 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var BrandIdentifier_1 = require("./BrandIdentifier");
|
|
40
|
-
var createNamespace = require('cls-hooked').createNamespace;
|
|
41
|
-
var namespaceName = 'request';
|
|
42
|
-
var ns = createNamespace(namespaceName);
|
|
43
|
-
var ContextNamespace = /** @class */ (function () {
|
|
44
|
-
function ContextNamespace() {
|
|
45
|
-
}
|
|
46
|
-
/* Express Start */
|
|
47
|
-
ContextNamespace.bindENamespace = function (req, res, next) {
|
|
48
|
-
|
|
49
|
-
ns.bindEmitter(
|
|
50
|
-
ns.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var BrandIdentifier_1 = require("./BrandIdentifier");
|
|
40
|
+
var createNamespace = require('cls-hooked').createNamespace;
|
|
41
|
+
var namespaceName = 'request';
|
|
42
|
+
var ns = createNamespace(namespaceName);
|
|
43
|
+
var ContextNamespace = /** @class */ (function () {
|
|
44
|
+
function ContextNamespace() {
|
|
45
|
+
}
|
|
46
|
+
/* Express Start */
|
|
47
|
+
ContextNamespace.bindENamespace = function (req, res, next) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
ns.bindEmitter(req);
|
|
50
|
+
ns.bindEmitter(res);
|
|
51
|
+
ns.run(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
52
|
+
var brandIdentifier;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
|
|
57
|
+
return [4 /*yield*/, brandIdentifier.getBrands()];
|
|
58
|
+
case 1:
|
|
59
|
+
_a.sent();
|
|
60
|
+
next();
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); });
|
|
65
|
+
};
|
|
66
|
+
ContextNamespace.setEBrand = function (req, res, next) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var brandIdentifier, brand;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0:
|
|
72
|
+
brandIdentifier = new BrandIdentifier_1.BrandIdentifier('express');
|
|
73
|
+
return [4 /*yield*/, brandIdentifier.getBrand(req)];
|
|
74
|
+
case 1:
|
|
75
|
+
brand = _a.sent();
|
|
76
|
+
if (Array.isArray(brand)) {
|
|
77
|
+
ns.set('employeeBrands', brand);
|
|
78
|
+
next();
|
|
79
|
+
}
|
|
80
|
+
else if (typeof brand === 'string') {
|
|
81
|
+
ns.set('brand', brand);
|
|
82
|
+
next();
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
next(brand);
|
|
86
|
+
}
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/* Express End */
|
|
93
|
+
/* Hapi Start */
|
|
94
|
+
ContextNamespace.bindHNamespace = function (req, reply) {
|
|
95
|
+
var _this = this;
|
|
96
|
+
ns.bindEmitter(req.raw.req);
|
|
97
|
+
ns.bindEmitter(req.raw.res);
|
|
98
|
+
ns.run(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
var brandIdentifier;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
|
|
104
|
+
return [4 /*yield*/, brandIdentifier.getBrands()];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
reply();
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); });
|
|
112
|
+
};
|
|
113
|
+
ContextNamespace.setHBrand = function (req, reply) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var brandIdentifier, brand;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
|
|
120
|
+
return [4 /*yield*/, brandIdentifier.getBrand(req)];
|
|
121
|
+
case 1:
|
|
122
|
+
brand = _a.sent();
|
|
123
|
+
if (Array.isArray(brand)) {
|
|
124
|
+
ns.set('employeeBrands', brand);
|
|
125
|
+
reply();
|
|
126
|
+
}
|
|
127
|
+
else if (typeof brand === 'string') {
|
|
128
|
+
ns.set('brand', brand);
|
|
129
|
+
reply();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
reply(brand);
|
|
133
|
+
}
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
/* Hapi End */
|
|
140
|
+
ContextNamespace.setBrand = function (brand) {
|
|
141
|
+
if (Array.isArray(brand)) {
|
|
142
|
+
return ns.set('employeeBrands', brand);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return ns.set('brand', brand);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
ContextNamespace.getBrand = function () {
|
|
149
|
+
return ns.get('brand');
|
|
150
|
+
};
|
|
151
|
+
ContextNamespace.getEmployeeBrands = function () {
|
|
152
|
+
return ns.get('employeeBrands');
|
|
153
|
+
};
|
|
154
|
+
ContextNamespace.getNamespace = function () {
|
|
155
|
+
return ns;
|
|
156
|
+
};
|
|
157
|
+
ContextNamespace.setBrands = function (brands) {
|
|
158
|
+
return ns.set('brands', brands);
|
|
159
|
+
};
|
|
160
|
+
ContextNamespace.getBrands = function () {
|
|
161
|
+
return ns.get('brands');
|
|
162
|
+
};
|
|
163
|
+
ContextNamespace.getDefaultBrand = function () {
|
|
164
|
+
var brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
|
|
165
|
+
return brandIdentifier.getDefaultBrand();
|
|
166
|
+
};
|
|
167
|
+
ContextNamespace.isValidBrand = function (brand) {
|
|
168
|
+
var _a;
|
|
169
|
+
return (_a = ns.get('brands')) === null || _a === void 0 ? void 0 : _a.includes(brand);
|
|
170
|
+
};
|
|
171
|
+
return ContextNamespace;
|
|
172
|
+
}());
|
|
173
|
+
exports.default = ContextNamespace;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare class MultiTenant {
|
|
2
|
-
private mongoose;
|
|
3
|
-
private models;
|
|
4
|
-
constructor(mongoose: any);
|
|
5
|
-
tenantModel(name: string, schema: any, options?: any): (props?: {}) => any;
|
|
6
|
-
tenantlessModel(name: string, schema: any, options?: any): () => any;
|
|
7
|
-
}
|
|
8
|
-
export default MultiTenant;
|
|
1
|
+
declare class MultiTenant {
|
|
2
|
+
private mongoose;
|
|
3
|
+
private models;
|
|
4
|
+
constructor(mongoose: any);
|
|
5
|
+
tenantModel(name: string, schema: any, options?: any): (props?: {}) => any;
|
|
6
|
+
tenantlessModel(name: string, schema: any, options?: any): () => any;
|
|
7
|
+
}
|
|
8
|
+
export default MultiTenant;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var MongooseModel_1 = require("../MongooseModel");
|
|
4
|
-
var MultiTenant = /** @class */ (function () {
|
|
5
|
-
function MultiTenant(mongoose) {
|
|
6
|
-
this.mongoose = mongoose;
|
|
7
|
-
this.models = {};
|
|
8
|
-
}
|
|
9
|
-
MultiTenant.prototype.tenantModel = function (name, schema, options) {
|
|
10
|
-
var _this = this;
|
|
11
|
-
return function (props) {
|
|
12
|
-
if (props === void 0) { props = {}; }
|
|
13
|
-
var skipBrand = props.skipBrand;
|
|
14
|
-
var mongooseModel = new MongooseModel_1.MongooseModel(_this.mongoose);
|
|
15
|
-
return mongooseModel.createModel(name, schema, options, _this.models, skipBrand);
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
MultiTenant.prototype.tenantlessModel = function (name, schema, options) {
|
|
19
|
-
var _this = this;
|
|
20
|
-
return function () { return _this.mongoose.model(name, schema, options); };
|
|
21
|
-
};
|
|
22
|
-
return MultiTenant;
|
|
23
|
-
}());
|
|
24
|
-
exports.default = MultiTenant;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var MongooseModel_1 = require("../MongooseModel");
|
|
4
|
+
var MultiTenant = /** @class */ (function () {
|
|
5
|
+
function MultiTenant(mongoose) {
|
|
6
|
+
this.mongoose = mongoose;
|
|
7
|
+
this.models = {};
|
|
8
|
+
}
|
|
9
|
+
MultiTenant.prototype.tenantModel = function (name, schema, options) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
return function (props) {
|
|
12
|
+
if (props === void 0) { props = {}; }
|
|
13
|
+
var skipBrand = props.skipBrand;
|
|
14
|
+
var mongooseModel = new MongooseModel_1.MongooseModel(_this.mongoose);
|
|
15
|
+
return mongooseModel.createModel(name, schema, options, _this.models, skipBrand);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
MultiTenant.prototype.tenantlessModel = function (name, schema, options) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
return function () { return _this.mongoose.model(name, schema, options); };
|
|
21
|
+
};
|
|
22
|
+
return MultiTenant;
|
|
23
|
+
}());
|
|
24
|
+
exports.default = MultiTenant;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare class MongooseModel {
|
|
2
|
-
private mongoose;
|
|
3
|
-
constructor(mongoose: any);
|
|
4
|
-
createModel(name: string, schema: any, options?: any, existingModels?: any, skipBrand?: boolean): any;
|
|
5
|
-
private addPreCondition;
|
|
6
|
-
private addPreReadQueries;
|
|
7
|
-
private addPreAggregate;
|
|
8
|
-
private addPreAggregateQueries;
|
|
9
|
-
private addPreSave;
|
|
10
|
-
private addPreSaveQueries;
|
|
11
|
-
private addPreInsertMany;
|
|
12
|
-
private addPreInsertManyQueries;
|
|
13
|
-
}
|
|
1
|
+
export declare class MongooseModel {
|
|
2
|
+
private mongoose;
|
|
3
|
+
constructor(mongoose: any);
|
|
4
|
+
createModel(name: string, schema: any, options?: any, existingModels?: any, skipBrand?: boolean): any;
|
|
5
|
+
private addPreCondition;
|
|
6
|
+
private addPreReadQueries;
|
|
7
|
+
private addPreAggregate;
|
|
8
|
+
private addPreAggregateQueries;
|
|
9
|
+
private addPreSave;
|
|
10
|
+
private addPreSaveQueries;
|
|
11
|
+
private addPreInsertMany;
|
|
12
|
+
private addPreInsertManyQueries;
|
|
13
|
+
}
|
|
@@ -1,84 +1,90 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongooseModel = void 0;
|
|
4
|
-
var Storage_1 = require("../Storage");
|
|
5
|
-
var MongooseModel = /** @class */ (function () {
|
|
6
|
-
function MongooseModel(mongoose) {
|
|
7
|
-
this.mongoose = mongoose;
|
|
8
|
-
}
|
|
9
|
-
MongooseModel.prototype.createModel = function (name, schema, options, existingModels, skipBrand) {
|
|
10
|
-
var brands = [];
|
|
11
|
-
if (!skipBrand) {
|
|
12
|
-
brands =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
schema.pre('
|
|
39
|
-
schema.pre('
|
|
40
|
-
schema.pre('
|
|
41
|
-
schema.pre('
|
|
42
|
-
schema.pre('
|
|
43
|
-
schema.pre('
|
|
44
|
-
schema.pre('
|
|
45
|
-
schema.pre('
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongooseModel = void 0;
|
|
4
|
+
var Storage_1 = require("../Storage");
|
|
5
|
+
var MongooseModel = /** @class */ (function () {
|
|
6
|
+
function MongooseModel(mongoose) {
|
|
7
|
+
this.mongoose = mongoose;
|
|
8
|
+
}
|
|
9
|
+
MongooseModel.prototype.createModel = function (name, schema, options, existingModels, skipBrand) {
|
|
10
|
+
var brands = [];
|
|
11
|
+
if (!skipBrand) {
|
|
12
|
+
brands = Storage_1.default.getEmployeeBrands()
|
|
13
|
+
? Storage_1.default.getEmployeeBrands()
|
|
14
|
+
: [Storage_1.default.getBrand()];
|
|
15
|
+
schema.add({ brand: String });
|
|
16
|
+
this.addPreReadQueries(schema);
|
|
17
|
+
this.addPreAggregateQueries(schema);
|
|
18
|
+
this.addPreSaveQueries(schema);
|
|
19
|
+
this.addPreInsertManyQueries(schema);
|
|
20
|
+
}
|
|
21
|
+
var modelName = skipBrand || !Array.isArray(brands) ? name : name + "-" + brands.join('-');
|
|
22
|
+
if (!existingModels[modelName]) {
|
|
23
|
+
existingModels[modelName] = this.mongoose.model(modelName, schema, options);
|
|
24
|
+
}
|
|
25
|
+
return existingModels[modelName];
|
|
26
|
+
};
|
|
27
|
+
MongooseModel.prototype.addPreCondition = function (next) {
|
|
28
|
+
var brands = Storage_1.default.getEmployeeBrands()
|
|
29
|
+
? Storage_1.default.getEmployeeBrands()
|
|
30
|
+
: [Storage_1.default.getBrand()];
|
|
31
|
+
if (Array.isArray(brands)) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
this.where({ brand: { $in: brands } });
|
|
34
|
+
}
|
|
35
|
+
next();
|
|
36
|
+
};
|
|
37
|
+
MongooseModel.prototype.addPreReadQueries = function (schema) {
|
|
38
|
+
schema.pre('count', this.addPreCondition);
|
|
39
|
+
schema.pre('find', this.addPreCondition);
|
|
40
|
+
schema.pre('findOne', this.addPreCondition);
|
|
41
|
+
schema.pre('update', this.addPreCondition);
|
|
42
|
+
schema.pre('findOneAndUpdate', this.addPreCondition);
|
|
43
|
+
schema.pre('updateOne', this.addPreCondition);
|
|
44
|
+
schema.pre('updateMany', this.addPreCondition);
|
|
45
|
+
schema.pre('findOneAndDelete', this.addPreCondition);
|
|
46
|
+
schema.pre('findOneAndRemove', this.addPreCondition);
|
|
47
|
+
schema.pre('deleteMany', this.addPreCondition);
|
|
48
|
+
schema.pre('deleteOne', this.addPreCondition);
|
|
49
|
+
schema.pre('remove', this.addPreCondition);
|
|
50
|
+
};
|
|
51
|
+
MongooseModel.prototype.addPreAggregate = function (next) {
|
|
52
|
+
var brands = Storage_1.default.getEmployeeBrands()
|
|
53
|
+
? Storage_1.default.getEmployeeBrands()
|
|
54
|
+
: [Storage_1.default.getBrand()];
|
|
55
|
+
if (Array.isArray(brands)) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
this.pipeline().unshift({ $match: { brand: { $in: brands } } });
|
|
58
|
+
}
|
|
59
|
+
next();
|
|
60
|
+
};
|
|
61
|
+
MongooseModel.prototype.addPreAggregateQueries = function (schema) {
|
|
62
|
+
schema.pre('aggregate', this.addPreAggregate);
|
|
63
|
+
};
|
|
64
|
+
MongooseModel.prototype.addPreSave = function (next) {
|
|
65
|
+
var brand = Storage_1.default.getBrand();
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
if (!this.brand && brand) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
this.brand = brand;
|
|
70
|
+
}
|
|
71
|
+
next();
|
|
72
|
+
};
|
|
73
|
+
MongooseModel.prototype.addPreSaveQueries = function (schema) {
|
|
74
|
+
schema.pre('save', this.addPreSave);
|
|
75
|
+
};
|
|
76
|
+
MongooseModel.prototype.addPreInsertMany = function (next, dataArray) {
|
|
77
|
+
var brand = Storage_1.default.getBrand();
|
|
78
|
+
dataArray.forEach(function (data) {
|
|
79
|
+
if (!data.tanentId && brand) {
|
|
80
|
+
data.brand = brand;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
next();
|
|
84
|
+
};
|
|
85
|
+
MongooseModel.prototype.addPreInsertManyQueries = function (schema) {
|
|
86
|
+
schema.pre('insertMany', this.addPreInsertMany);
|
|
87
|
+
};
|
|
88
|
+
return MongooseModel;
|
|
89
|
+
}());
|
|
90
|
+
exports.MongooseModel = MongooseModel;
|