@sdflc/backend-helpers 1.0.20 → 1.0.23
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/build/apiContext.js +5 -5
- package/build/appBaseCore.d.ts +9 -0
- package/build/appBaseCore.js +91 -0
- package/build/baseCore.d.ts +21 -20
- package/build/baseCore.js +190 -53
- package/build/baseGateway.d.ts +8 -7
- package/build/baseGateway.js +141 -62
- package/build/baseGatewayHelpers.js +7 -6
- package/build/checkItHelpers.js +1 -1
- package/build/configBulder.js +4 -4
- package/build/constants.d.ts +5 -2
- package/build/constants.js +22 -35
- package/build/dataCache.js +1 -1
- package/build/database.js +2 -2
- package/build/dbHelpers.js +3 -3
- package/build/dbMigratorAndSeeder.js +10 -10
- package/build/dbSeeder.js +6 -6
- package/build/dbTableHelpers.d.ts +7 -0
- package/build/dbTableHelpers.js +58 -12
- package/build/index.d.ts +2 -0
- package/build/index.js +6 -1
- package/build/interfaces/AppBaseCoreInterface.d.ts +6 -0
- package/build/interfaces/AppBaseCoreInterface.js +2 -0
- package/build/interfaces/BaseGatewayInterface.d.ts +1 -1
- package/build/interfaces/index.d.ts +1 -0
- package/build/knexConfigBuilder.js +5 -5
- package/build/passwordHelpers.d.ts +5 -0
- package/build/passwordHelpers.js +76 -0
- package/build/resolversHelpers.js +11 -12
- package/package.json +21 -19
package/build/apiContext.js
CHANGED
|
@@ -23,10 +23,10 @@ var database_1 = require("./database");
|
|
|
23
23
|
var createApiContext = function (args) {
|
|
24
24
|
var _a = args || {}, cores = _a.cores, req = _a.req, getCoreContext = _a.getCoreContext, extendContext = _a.extendContext, inRequestId = _a.requestId;
|
|
25
25
|
var keys = Object.keys(cores || {});
|
|
26
|
-
var requestId = inRequestId || uuid_1.v4();
|
|
26
|
+
var requestId = inRequestId || (0, uuid_1.v4)();
|
|
27
27
|
var coreContext = typeof getCoreContext === 'function' ? getCoreContext({ req: req }) : {};
|
|
28
28
|
var context = keys.reduce(function (acc, key) {
|
|
29
|
-
acc[lodash_1.camelCase(key)] = new cores[key](__assign(__assign({}, coreContext), { requestId: requestId }));
|
|
29
|
+
acc[(0, lodash_1.camelCase)(key)] = new cores[key](__assign(__assign({}, coreContext), { requestId: requestId }));
|
|
30
30
|
return acc;
|
|
31
31
|
}, {});
|
|
32
32
|
context.requestId = requestId;
|
|
@@ -53,14 +53,14 @@ var createContextDefault = function (args) {
|
|
|
53
53
|
var referer = req.headers['referer'];
|
|
54
54
|
var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
|
55
55
|
var acceptLanguage = req.headers['accept-language'];
|
|
56
|
-
var languages = utils_1.extractLanguages(acceptLanguage);
|
|
56
|
+
var languages = (0, utils_1.extractLanguages)(acceptLanguage);
|
|
57
57
|
var requestedLang = req.query['lang'];
|
|
58
|
-
var requestId = uuid_1.v4();
|
|
58
|
+
var requestId = (0, uuid_1.v4)();
|
|
59
59
|
var db = new database_1.Database({
|
|
60
60
|
knexConfig: knexConfig,
|
|
61
61
|
dbSchema: dbSchema,
|
|
62
62
|
});
|
|
63
|
-
return exports.createApiContext({
|
|
63
|
+
return (0, exports.createApiContext)({
|
|
64
64
|
cores: cores,
|
|
65
65
|
req: req,
|
|
66
66
|
requestId: requestId,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AppBaseCoreInterface, BaseCoreActionsInterface } from './interfaces';
|
|
2
|
+
import { BaseCore } from './baseCore';
|
|
3
|
+
declare class AppBaseCore extends BaseCore {
|
|
4
|
+
private gwSpace;
|
|
5
|
+
private interserviceApiKey?;
|
|
6
|
+
constructor(props: AppBaseCoreInterface);
|
|
7
|
+
authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<(string | boolean)[]>;
|
|
8
|
+
}
|
|
9
|
+
export { AppBaseCore };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.AppBaseCore = void 0;
|
|
55
|
+
var baseCore_1 = require("./baseCore");
|
|
56
|
+
var AppBaseCore = /** @class */ (function (_super) {
|
|
57
|
+
__extends(AppBaseCore, _super);
|
|
58
|
+
function AppBaseCore(props) {
|
|
59
|
+
var _this = _super.call(this, props) || this;
|
|
60
|
+
_this.gwSpace = props.gwSpace;
|
|
61
|
+
_this.interserviceApiKey = props.interserviceApiKey;
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
AppBaseCore.prototype.authenticate = function (params, opt) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var context, space;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
context = this.context;
|
|
71
|
+
return [4 /*yield*/, this.gwSpace.get(context.spaceId || '')];
|
|
72
|
+
case 1:
|
|
73
|
+
space = _a.sent();
|
|
74
|
+
if (!space) {
|
|
75
|
+
return [2 /*return*/, [false, 'Space Not Found']];
|
|
76
|
+
}
|
|
77
|
+
context.space = space;
|
|
78
|
+
if (this.interserviceApiKey && context.apiKey === this.interserviceApiKey) {
|
|
79
|
+
return [2 /*return*/, [true, '']];
|
|
80
|
+
}
|
|
81
|
+
else if (space.apiKey && space.apiKey !== context.apiKey) {
|
|
82
|
+
return [2 /*return*/, [false, 'API Key is invalid']];
|
|
83
|
+
}
|
|
84
|
+
return [2 /*return*/, [true, '']];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
return AppBaseCore;
|
|
90
|
+
}(baseCore_1.BaseCore));
|
|
91
|
+
exports.AppBaseCore = AppBaseCore;
|
package/build/baseCore.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Logger } from '@sdflc/utils';
|
|
2
|
-
import { BaseCoreInterface, BaseCoreDoingWhatInterface, CoreActionInterface, BaseCoreValidatorsInterface } from './interfaces';
|
|
2
|
+
import { BaseCoreInterface, BaseCoreDoingWhatInterface, BaseCoreActionsInterface, CoreActionInterface, BaseCoreValidatorsInterface } from './interfaces';
|
|
3
3
|
import { BaseGateway } from './baseGateway';
|
|
4
4
|
import { Database } from './database';
|
|
5
5
|
declare class BaseCore {
|
|
6
|
+
protected props: BaseCoreInterface;
|
|
6
7
|
protected db: Database;
|
|
7
8
|
protected context: any;
|
|
8
9
|
protected gateway?: BaseGateway;
|
|
@@ -10,26 +11,8 @@ declare class BaseCore {
|
|
|
10
11
|
protected logger: Logger;
|
|
11
12
|
protected name?: string;
|
|
12
13
|
protected gateways?: any;
|
|
13
|
-
protected beforeList: any;
|
|
14
|
-
protected beforeCreate: any;
|
|
15
|
-
protected beforeCreateMany: any;
|
|
16
|
-
protected beforeUpdate: any;
|
|
17
|
-
protected beforeUpdateMany: any;
|
|
18
|
-
protected beforeSet: any;
|
|
19
|
-
protected beforeRemove: any;
|
|
20
|
-
protected beforeRemoveMany: any;
|
|
21
|
-
protected afterList: any;
|
|
22
|
-
protected afterCreate: any;
|
|
23
|
-
protected afterCreateMany: any;
|
|
24
|
-
protected afterUpdate: any;
|
|
25
|
-
protected afterUpdateMany: any;
|
|
26
|
-
protected afterSet: any;
|
|
27
|
-
protected afterRemove: any;
|
|
28
|
-
protected afterRemoveMany: any;
|
|
29
|
-
protected onException: any;
|
|
30
14
|
protected requestId: string;
|
|
31
15
|
protected validators: BaseCoreValidatorsInterface;
|
|
32
|
-
protected authenticate: any;
|
|
33
16
|
protected doAuth: boolean;
|
|
34
17
|
constructor(props: BaseCoreInterface);
|
|
35
18
|
getDb(): Database;
|
|
@@ -37,7 +20,7 @@ declare class BaseCore {
|
|
|
37
20
|
getContext(key?: string): any;
|
|
38
21
|
getGateways(): any;
|
|
39
22
|
success(data: any, code?: number): any;
|
|
40
|
-
|
|
23
|
+
failure(code: number, errorMsg: string, data?: any): any;
|
|
41
24
|
validationFailure(ex: any): any;
|
|
42
25
|
exceptionFailure(ex: any, doingWhat: string | any, data?: any): any;
|
|
43
26
|
checkResult(args: any): Promise<void>;
|
|
@@ -52,5 +35,23 @@ declare class BaseCore {
|
|
|
52
35
|
set(args: any): Promise<any>;
|
|
53
36
|
remove(args: any): Promise<any>;
|
|
54
37
|
removeMany(args: any): Promise<any>;
|
|
38
|
+
beforeList(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
39
|
+
afterList(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
40
|
+
beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
41
|
+
afterCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
42
|
+
beforeCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
43
|
+
afterCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
44
|
+
beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
45
|
+
afterUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
46
|
+
beforeUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
47
|
+
afterUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
48
|
+
beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
49
|
+
afterSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
50
|
+
beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
51
|
+
afterRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
52
|
+
beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
53
|
+
afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
54
|
+
onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
55
|
+
authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
|
|
55
56
|
}
|
|
56
57
|
export { BaseCore };
|
package/build/baseCore.js
CHANGED
|
@@ -46,17 +46,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
50
|
exports.BaseCore = void 0;
|
|
54
51
|
var api_helpers_1 = require("@sdflc/api-helpers");
|
|
55
52
|
var utils_1 = require("@sdflc/utils");
|
|
56
53
|
var utils_2 = require("./utils");
|
|
57
|
-
var
|
|
58
|
-
var ACCESS_RIGHTS = constants_1.default.ACCESS_RIGHTS;
|
|
59
|
-
var defaultAfterAndBefore = function (params) {
|
|
54
|
+
var defaultAfterAndBefore = function (params, opt) {
|
|
60
55
|
return params;
|
|
61
56
|
};
|
|
62
57
|
var defaultValidate = function (params, opt) {
|
|
@@ -80,35 +75,15 @@ var defaultAuth = function (params) {
|
|
|
80
75
|
var BaseCore = /** @class */ (function () {
|
|
81
76
|
function BaseCore(props) {
|
|
82
77
|
this.validators = defaultValidators;
|
|
83
|
-
this.
|
|
78
|
+
this.props = props || {};
|
|
79
|
+
this.db = props.db;
|
|
84
80
|
this.name = props.name || '';
|
|
85
81
|
this.context = props.context || {};
|
|
86
82
|
this.gateway = props.gateway;
|
|
87
83
|
this.doingWhat = props.doingWhat;
|
|
88
84
|
this.logger = props.logger || new utils_1.Logger({ level: props.logLevel });
|
|
89
85
|
this.gateways = __assign({ gateway: this.gateway }, (props.gateways || {}));
|
|
90
|
-
this.
|
|
91
|
-
this.beforeCreate = typeof props.beforeCreate === 'function' ? props.beforeCreate : defaultAfterAndBefore;
|
|
92
|
-
this.beforeCreateMany =
|
|
93
|
-
typeof props.beforeCreateMany === 'function' ? props.beforeCreateMany : defaultAfterAndBefore;
|
|
94
|
-
this.beforeUpdate = typeof props.beforeUpdate === 'function' ? props.beforeUpdate : defaultAfterAndBefore;
|
|
95
|
-
this.beforeUpdateMany =
|
|
96
|
-
typeof props.beforeUpdateMany === 'function' ? props.beforeUpdateMany : defaultAfterAndBefore;
|
|
97
|
-
this.beforeSet = typeof props.beforeSet === 'function' ? props.beforeSet : defaultAfterAndBefore;
|
|
98
|
-
this.beforeRemove = typeof props.beforeRemove === 'function' ? props.beforeRemove : defaultAfterAndBefore;
|
|
99
|
-
this.beforeRemoveMany =
|
|
100
|
-
typeof props.beforeRemoveMany === 'function' ? props.beforeRemoveMany : defaultAfterAndBefore;
|
|
101
|
-
this.afterList = typeof props.afterList === 'function' ? props.afterList : defaultAfterAndBefore;
|
|
102
|
-
this.afterCreate = typeof props.afterCreate === 'function' ? props.afterCreate : defaultAfterAndBefore;
|
|
103
|
-
this.afterCreateMany = typeof props.afterCreateMany === 'function' ? props.afterCreateMany : defaultAfterAndBefore;
|
|
104
|
-
this.afterUpdate = typeof props.afterUpdate === 'function' ? props.afterUpdate : defaultAfterAndBefore;
|
|
105
|
-
this.afterUpdateMany = typeof props.afterUpdateMany === 'function' ? props.afterUpdateMany : defaultAfterAndBefore;
|
|
106
|
-
this.afterSet = typeof props.afterSet === 'function' ? props.afterSet : defaultAfterAndBefore;
|
|
107
|
-
this.afterRemove = typeof props.afterRemove === 'function' ? props.afterRemove : defaultAfterAndBefore;
|
|
108
|
-
this.afterRemoveMany = typeof props.afterRemoveMany === 'function' ? props.afterRemoveMany : defaultAfterAndBefore;
|
|
109
|
-
this.onException = typeof props.onException === 'function' ? props.onException : defaultAfterAndBefore;
|
|
110
|
-
this.validators = utils_2.setFunctions((props === null || props === void 0 ? void 0 : props.validators) || {}, this.validators);
|
|
111
|
-
this.authenticate = typeof props.authenticate === 'function' ? props.authenticate : defaultAuth;
|
|
86
|
+
this.validators = (0, utils_2.setFunctions)((props === null || props === void 0 ? void 0 : props.validators) || {}, this.validators);
|
|
112
87
|
this.doAuth = props.doAuth === true;
|
|
113
88
|
this.requestId = props.requestId || '';
|
|
114
89
|
}
|
|
@@ -141,7 +116,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
141
116
|
errors: [],
|
|
142
117
|
}).toJS();
|
|
143
118
|
};
|
|
144
|
-
BaseCore.prototype.
|
|
119
|
+
BaseCore.prototype.failure = function (code, errorMsg, data) {
|
|
145
120
|
var result = new api_helpers_1.OpResult({ data: data });
|
|
146
121
|
result.addError('', errorMsg, code);
|
|
147
122
|
return result.toJS();
|
|
@@ -157,7 +132,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
157
132
|
var _a = this.getDb().isDbError(ex), isDbError = _a[0], dbErrorMsg = _a[1];
|
|
158
133
|
var isOpResult = typeof ex.getErrorSummary === 'function';
|
|
159
134
|
var message = isOpResult ? ex.getErrorSummary() : ex.message;
|
|
160
|
-
var sysMsg = "An exception has occurred on "
|
|
135
|
+
var sysMsg = "An exception has occurred on ".concat(doingWhat, " with message ").concat(message, ":");
|
|
161
136
|
var msg = '';
|
|
162
137
|
if (isDbError) {
|
|
163
138
|
msg = dbErrorMsg;
|
|
@@ -167,7 +142,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
167
142
|
msg = doingWhat['message'];
|
|
168
143
|
}
|
|
169
144
|
else {
|
|
170
|
-
msg = "Sorry, something went wrong on "
|
|
145
|
+
msg = "Sorry, something went wrong on ".concat(doingWhat, ".").concat(isOpResult ? " Reason: ".concat(ex.getErrorSummary()) : '');
|
|
171
146
|
}
|
|
172
147
|
this.logger.error(sysMsg, ex);
|
|
173
148
|
}
|
|
@@ -276,7 +251,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
276
251
|
what = doingWhat;
|
|
277
252
|
if (doingWhat !== step) {
|
|
278
253
|
what = {
|
|
279
|
-
message: step
|
|
254
|
+
message: "".concat(step, " failed on ").concat(doingWhat),
|
|
280
255
|
};
|
|
281
256
|
}
|
|
282
257
|
return [2 /*return*/, this.exceptionFailure(ex_1, what)];
|
|
@@ -293,14 +268,14 @@ var BaseCore = /** @class */ (function () {
|
|
|
293
268
|
return [2 /*return*/, this.runAction({
|
|
294
269
|
args: args,
|
|
295
270
|
validate: this.validators.list,
|
|
296
|
-
accessRights: [ACCESS_RIGHTS.LIST],
|
|
271
|
+
accessRights: [utils_1.ACCESS_RIGHTS.LIST],
|
|
297
272
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
298
273
|
var object, items, result;
|
|
299
274
|
var _a;
|
|
300
275
|
return __generator(this, function (_b) {
|
|
301
276
|
switch (_b.label) {
|
|
302
277
|
case 0:
|
|
303
|
-
this.logger.log("Requesting a list for "
|
|
278
|
+
this.logger.log("Requesting a list for ".concat(this.name, ":"), args);
|
|
304
279
|
return [4 /*yield*/, this.beforeList(args, opt)];
|
|
305
280
|
case 1:
|
|
306
281
|
object = _b.sent();
|
|
@@ -329,7 +304,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
329
304
|
return [2 /*return*/, this.runAction({
|
|
330
305
|
args: args,
|
|
331
306
|
validate: this.validators.get,
|
|
332
|
-
accessRights: [ACCESS_RIGHTS.GET],
|
|
307
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
333
308
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
334
309
|
var id, item;
|
|
335
310
|
var _a;
|
|
@@ -337,7 +312,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
337
312
|
switch (_b.label) {
|
|
338
313
|
case 0:
|
|
339
314
|
id = (args || {}).id;
|
|
340
|
-
this.logger.log("Requesting an item for "
|
|
315
|
+
this.logger.log("Requesting an item for ".concat(this.name, ":"), args);
|
|
341
316
|
return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.get(id))];
|
|
342
317
|
case 1:
|
|
343
318
|
item = _b.sent();
|
|
@@ -359,7 +334,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
359
334
|
return [2 /*return*/, this.runAction({
|
|
360
335
|
args: args,
|
|
361
336
|
validate: this.validators.getMany,
|
|
362
|
-
accessRights: [ACCESS_RIGHTS.GET],
|
|
337
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
363
338
|
action: function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
364
339
|
var ids, items;
|
|
365
340
|
var _a;
|
|
@@ -367,7 +342,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
367
342
|
switch (_b.label) {
|
|
368
343
|
case 0:
|
|
369
344
|
ids = (args || {}).ids;
|
|
370
|
-
this.logger.log("Requesting multiple items for "
|
|
345
|
+
this.logger.log("Requesting multiple items for ".concat(this.name, ":"), args);
|
|
371
346
|
return [4 /*yield*/, ((_a = this.gateway) === null || _a === void 0 ? void 0 : _a.getMany(ids))];
|
|
372
347
|
case 1:
|
|
373
348
|
items = _b.sent();
|
|
@@ -389,7 +364,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
389
364
|
return [2 /*return*/, this.runAction({
|
|
390
365
|
args: args,
|
|
391
366
|
validate: this.validators.create,
|
|
392
|
-
accessRights: [ACCESS_RIGHTS.CREATE],
|
|
367
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
393
368
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
394
369
|
var params, object, item, result;
|
|
395
370
|
var _a;
|
|
@@ -397,7 +372,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
397
372
|
switch (_b.label) {
|
|
398
373
|
case 0:
|
|
399
374
|
params = (args || {}).params;
|
|
400
|
-
this.logger.log("Requesting creation of an item for "
|
|
375
|
+
this.logger.log("Requesting creation of an item for ".concat(this.name, ":"), args);
|
|
401
376
|
return [4 /*yield*/, this.beforeCreate(params, opt)];
|
|
402
377
|
case 1:
|
|
403
378
|
object = _b.sent();
|
|
@@ -425,7 +400,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
425
400
|
return [2 /*return*/, this.runAction({
|
|
426
401
|
args: args,
|
|
427
402
|
validate: this.validators.createMany,
|
|
428
|
-
accessRights: [ACCESS_RIGHTS.CREATE],
|
|
403
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
429
404
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
430
405
|
var params, objects, items, result;
|
|
431
406
|
var _a;
|
|
@@ -433,7 +408,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
433
408
|
switch (_b.label) {
|
|
434
409
|
case 0:
|
|
435
410
|
params = (args || {}).params;
|
|
436
|
-
this.logger.log("Requesting creation of multiple items for "
|
|
411
|
+
this.logger.log("Requesting creation of multiple items for ".concat(this.name, ":"), args);
|
|
437
412
|
return [4 /*yield*/, this.beforeCreateMany(params, opt)];
|
|
438
413
|
case 1:
|
|
439
414
|
objects = _b.sent();
|
|
@@ -461,7 +436,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
461
436
|
return [2 /*return*/, this.runAction({
|
|
462
437
|
args: args,
|
|
463
438
|
validate: this.validators.update,
|
|
464
|
-
accessRights: [ACCESS_RIGHTS.UPDATE],
|
|
439
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
465
440
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
466
441
|
var _a, where, params, object, item, result;
|
|
467
442
|
var _b;
|
|
@@ -469,7 +444,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
469
444
|
switch (_c.label) {
|
|
470
445
|
case 0:
|
|
471
446
|
_a = args || {}, where = _a.where, params = _a.params;
|
|
472
|
-
this.logger.log("Requesting update of an item for "
|
|
447
|
+
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
473
448
|
return [4 /*yield*/, this.beforeUpdate(params, opt)];
|
|
474
449
|
case 1:
|
|
475
450
|
object = _c.sent();
|
|
@@ -497,7 +472,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
497
472
|
return [2 /*return*/, this.runAction({
|
|
498
473
|
args: args,
|
|
499
474
|
validate: this.validators.updateMany,
|
|
500
|
-
accessRights: [ACCESS_RIGHTS.UPDATE],
|
|
475
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
501
476
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
502
477
|
var params, object, items, result;
|
|
503
478
|
var _a;
|
|
@@ -505,7 +480,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
505
480
|
switch (_b.label) {
|
|
506
481
|
case 0:
|
|
507
482
|
params = (args || {}).params;
|
|
508
|
-
this.logger.log("Requesting update of an item for "
|
|
483
|
+
this.logger.log("Requesting update of an item for ".concat(this.name, ":"), args);
|
|
509
484
|
return [4 /*yield*/, this.beforeUpdateMany(params, opt)];
|
|
510
485
|
case 1:
|
|
511
486
|
object = _b.sent();
|
|
@@ -533,7 +508,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
533
508
|
return [2 /*return*/, this.runAction({
|
|
534
509
|
args: args,
|
|
535
510
|
validate: this.validators.set,
|
|
536
|
-
accessRights: [ACCESS_RIGHTS.CREATE, ACCESS_RIGHTS.UPDATE],
|
|
511
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE, utils_1.ACCESS_RIGHTS.UPDATE],
|
|
537
512
|
action: function (args, opt /* { setStep, validatedItems, sameRequest } */) { return __awaiter(_this, void 0, void 0, function () {
|
|
538
513
|
var params, object, items, result;
|
|
539
514
|
var _a;
|
|
@@ -541,7 +516,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
541
516
|
switch (_b.label) {
|
|
542
517
|
case 0:
|
|
543
518
|
params = (args || {}).params;
|
|
544
|
-
this.logger.log("Requesting setting of item(s) for "
|
|
519
|
+
this.logger.log("Requesting setting of item(s) for ".concat(this.name, ":"), args);
|
|
545
520
|
return [4 /*yield*/, this.beforeSet(params, opt)];
|
|
546
521
|
case 1:
|
|
547
522
|
object = _b.sent();
|
|
@@ -569,7 +544,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
569
544
|
return [2 /*return*/, this.runAction({
|
|
570
545
|
args: args,
|
|
571
546
|
validate: this.validators.remove,
|
|
572
|
-
accessRights: [ACCESS_RIGHTS.REMOVE],
|
|
547
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
573
548
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
574
549
|
var where, object, items, result;
|
|
575
550
|
var _a;
|
|
@@ -577,7 +552,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
577
552
|
switch (_b.label) {
|
|
578
553
|
case 0:
|
|
579
554
|
where = (args || {}).where;
|
|
580
|
-
this.logger.log("Requesting removal of an item for "
|
|
555
|
+
this.logger.log("Requesting removal of an item for ".concat(this.name, ":"), args);
|
|
581
556
|
return [4 /*yield*/, this.beforeRemove(where, opt)];
|
|
582
557
|
case 1:
|
|
583
558
|
object = _b.sent();
|
|
@@ -605,7 +580,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
605
580
|
return [2 /*return*/, this.runAction({
|
|
606
581
|
args: args,
|
|
607
582
|
validate: this.validators.removeMany,
|
|
608
|
-
accessRights: [ACCESS_RIGHTS.REMOVE],
|
|
583
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
609
584
|
action: function (args, opt) { return __awaiter(_this, void 0, void 0, function () {
|
|
610
585
|
var where, object, items, result;
|
|
611
586
|
var _a;
|
|
@@ -613,7 +588,7 @@ var BaseCore = /** @class */ (function () {
|
|
|
613
588
|
switch (_b.label) {
|
|
614
589
|
case 0:
|
|
615
590
|
where = (args || {}).where;
|
|
616
|
-
this.logger.log("Requesting removal of multiple items for "
|
|
591
|
+
this.logger.log("Requesting removal of multiple items for ".concat(this.name, ":"), args);
|
|
617
592
|
return [4 /*yield*/, this.beforeRemoveMany(where, opt)];
|
|
618
593
|
case 1:
|
|
619
594
|
object = _b.sent();
|
|
@@ -633,6 +608,168 @@ var BaseCore = /** @class */ (function () {
|
|
|
633
608
|
});
|
|
634
609
|
});
|
|
635
610
|
};
|
|
611
|
+
BaseCore.prototype.beforeList = function (params, opt) {
|
|
612
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
613
|
+
var fn;
|
|
614
|
+
return __generator(this, function (_a) {
|
|
615
|
+
fn = typeof this.props.beforeList === 'function' ? this.props.beforeList : defaultAfterAndBefore;
|
|
616
|
+
return [2 /*return*/, fn(params, opt)];
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
BaseCore.prototype.afterList = function (params, opt) {
|
|
621
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
622
|
+
var fn;
|
|
623
|
+
return __generator(this, function (_a) {
|
|
624
|
+
fn = typeof this.props.afterList === 'function' ? this.props.afterList : defaultAfterAndBefore;
|
|
625
|
+
return [2 /*return*/, fn(params, opt)];
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
BaseCore.prototype.beforeCreate = function (params, opt) {
|
|
630
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
631
|
+
var fn;
|
|
632
|
+
return __generator(this, function (_a) {
|
|
633
|
+
fn = typeof this.props.beforeCreate === 'function' ? this.props.beforeCreate : defaultAfterAndBefore;
|
|
634
|
+
return [2 /*return*/, fn(params, opt)];
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
BaseCore.prototype.afterCreate = function (params, opt) {
|
|
639
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
640
|
+
var fn;
|
|
641
|
+
return __generator(this, function (_a) {
|
|
642
|
+
fn = typeof this.props.afterCreate === 'function' ? this.props.afterCreate : defaultAfterAndBefore;
|
|
643
|
+
return [2 /*return*/, fn(params, opt)];
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
BaseCore.prototype.beforeCreateMany = function (params, opt) {
|
|
648
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
649
|
+
var fn;
|
|
650
|
+
return __generator(this, function (_a) {
|
|
651
|
+
fn = typeof this.props.beforeCreateMany === 'function' ? this.props.beforeCreateMany : defaultAfterAndBefore;
|
|
652
|
+
return [2 /*return*/, fn(params, opt)];
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
BaseCore.prototype.afterCreateMany = function (params, opt) {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
658
|
+
var fn;
|
|
659
|
+
return __generator(this, function (_a) {
|
|
660
|
+
fn = typeof this.props.afterCreateMany === 'function' ? this.props.afterCreateMany : defaultAfterAndBefore;
|
|
661
|
+
return [2 /*return*/, fn(params, opt)];
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
};
|
|
665
|
+
BaseCore.prototype.beforeUpdate = function (params, opt) {
|
|
666
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
667
|
+
var fn;
|
|
668
|
+
return __generator(this, function (_a) {
|
|
669
|
+
fn = typeof this.props.beforeUpdate === 'function' ? this.props.beforeUpdate : defaultAfterAndBefore;
|
|
670
|
+
return [2 /*return*/, fn(params, opt)];
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
BaseCore.prototype.afterUpdate = function (params, opt) {
|
|
675
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
676
|
+
var fn;
|
|
677
|
+
return __generator(this, function (_a) {
|
|
678
|
+
fn = typeof this.props.afterUpdate === 'function' ? this.props.afterUpdate : defaultAfterAndBefore;
|
|
679
|
+
return [2 /*return*/, fn(params, opt)];
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
};
|
|
683
|
+
BaseCore.prototype.beforeUpdateMany = function (params, opt) {
|
|
684
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
685
|
+
var fn;
|
|
686
|
+
return __generator(this, function (_a) {
|
|
687
|
+
fn = typeof this.props.beforeUpdateMany === 'function' ? this.props.beforeUpdateMany : defaultAfterAndBefore;
|
|
688
|
+
return [2 /*return*/, fn(params, opt)];
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
BaseCore.prototype.afterUpdateMany = function (params, opt) {
|
|
693
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
694
|
+
var fn;
|
|
695
|
+
return __generator(this, function (_a) {
|
|
696
|
+
fn = typeof this.props.afterUpdateMany === 'function' ? this.props.afterUpdateMany : defaultAfterAndBefore;
|
|
697
|
+
return [2 /*return*/, fn(params, opt)];
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
BaseCore.prototype.beforeSet = function (params, opt) {
|
|
702
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
703
|
+
var fn;
|
|
704
|
+
return __generator(this, function (_a) {
|
|
705
|
+
fn = typeof this.props.beforeSet === 'function' ? this.props.beforeSet : defaultAfterAndBefore;
|
|
706
|
+
return [2 /*return*/, fn(params, opt)];
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
BaseCore.prototype.afterSet = function (params, opt) {
|
|
711
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
712
|
+
var fn;
|
|
713
|
+
return __generator(this, function (_a) {
|
|
714
|
+
fn = typeof this.props.afterSet === 'function' ? this.props.afterSet : defaultAfterAndBefore;
|
|
715
|
+
return [2 /*return*/, fn(params, opt)];
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
BaseCore.prototype.beforeRemove = function (params, opt) {
|
|
720
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
721
|
+
var fn;
|
|
722
|
+
return __generator(this, function (_a) {
|
|
723
|
+
fn = typeof this.props.beforeRemove === 'function' ? this.props.beforeRemove : defaultAfterAndBefore;
|
|
724
|
+
return [2 /*return*/, fn(params, opt)];
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
BaseCore.prototype.afterRemove = function (params, opt) {
|
|
729
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
730
|
+
var fn;
|
|
731
|
+
return __generator(this, function (_a) {
|
|
732
|
+
fn = typeof this.props.afterRemove === 'function' ? this.props.afterRemove : defaultAfterAndBefore;
|
|
733
|
+
return [2 /*return*/, fn(params, opt)];
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
BaseCore.prototype.beforeRemoveMany = function (params, opt) {
|
|
738
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
739
|
+
var fn;
|
|
740
|
+
return __generator(this, function (_a) {
|
|
741
|
+
fn = typeof this.props.beforeRemoveMany === 'function' ? this.props.beforeRemoveMany : defaultAfterAndBefore;
|
|
742
|
+
return [2 /*return*/, fn(params, opt)];
|
|
743
|
+
});
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
BaseCore.prototype.afterRemoveMany = function (params, opt) {
|
|
747
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
748
|
+
var fn;
|
|
749
|
+
return __generator(this, function (_a) {
|
|
750
|
+
fn = typeof this.props.afterRemoveMany === 'function' ? this.props.afterRemoveMany : defaultAfterAndBefore;
|
|
751
|
+
return [2 /*return*/, fn(params, opt)];
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
BaseCore.prototype.onException = function (params, opt) {
|
|
756
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
757
|
+
var fn;
|
|
758
|
+
return __generator(this, function (_a) {
|
|
759
|
+
fn = typeof this.props.onException === 'function' ? this.props.onException : defaultAfterAndBefore;
|
|
760
|
+
return [2 /*return*/, fn(params, opt)];
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
};
|
|
764
|
+
BaseCore.prototype.authenticate = function (params, opt) {
|
|
765
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
766
|
+
var fn;
|
|
767
|
+
return __generator(this, function (_a) {
|
|
768
|
+
fn = typeof this.props.authenticate === 'function' ? this.props.authenticate : defaultAuth;
|
|
769
|
+
return [2 /*return*/, fn(params, opt)];
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
};
|
|
636
773
|
return BaseCore;
|
|
637
774
|
}());
|
|
638
775
|
exports.BaseCore = BaseCore;
|