@sdflc/backend-helpers 1.0.61 → 1.0.63
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/BaseCore.js +14 -4
- package/build/BaseGateway.d.ts +2 -1
- package/build/BaseGateway.js +11 -7
- package/build/DbMigratorAndSeeder.js +1 -1
- package/build/dbSeeder.js +1 -1
- package/build/interfaces/BuildListQueryArgsInterface.d.ts +5 -0
- package/build/interfaces/BuildListQueryArgsInterface.js +2 -0
- package/build/interfaces/ListArgsInterface.d.ts +2 -1
- package/build/interfaces/index.d.ts +1 -0
- package/build/interfaces/index.js +1 -0
- package/package.json +24 -24
package/build/BaseCore.js
CHANGED
|
@@ -19,6 +19,9 @@ const userToken_1 = require("./userToken");
|
|
|
19
19
|
const defaultValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
|
|
20
20
|
return [true, {}];
|
|
21
21
|
};
|
|
22
|
+
const defaultMutationValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
|
|
23
|
+
return [true, {}];
|
|
24
|
+
};
|
|
22
25
|
const defaultValidators = {
|
|
23
26
|
list: defaultValidate,
|
|
24
27
|
get: commonValidators_1.validateGet,
|
|
@@ -263,8 +266,11 @@ class BaseCore {
|
|
|
263
266
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
264
267
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
265
268
|
var _d;
|
|
266
|
-
const
|
|
267
|
-
|
|
269
|
+
const args2use = yield this.beforeGet(args, opt);
|
|
270
|
+
if ((args2use === null || args2use === void 0 ? void 0 : args2use.id) == null) {
|
|
271
|
+
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
272
|
+
}
|
|
273
|
+
const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.get(args2use === null || args2use === void 0 ? void 0 : args2use.id));
|
|
268
274
|
const result = yield this.afterGet(item, opt);
|
|
269
275
|
if (!result) {
|
|
270
276
|
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
@@ -285,8 +291,11 @@ class BaseCore {
|
|
|
285
291
|
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
286
292
|
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
287
293
|
var _d;
|
|
288
|
-
const
|
|
289
|
-
|
|
294
|
+
const args2use = yield this.beforeGetMany(args, opt);
|
|
295
|
+
if (!Array.isArray(args2use === null || args2use === void 0 ? void 0 : args2use.ids)) {
|
|
296
|
+
return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
|
|
297
|
+
}
|
|
298
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.getMany(args2use.ids));
|
|
290
299
|
const result = yield this.afterGetMany(items, opt);
|
|
291
300
|
return this.success(result);
|
|
292
301
|
}),
|
|
@@ -652,6 +661,7 @@ class BaseCore {
|
|
|
652
661
|
context.accountId = tokenData.accountId;
|
|
653
662
|
context.roleId = tokenData.roleId;
|
|
654
663
|
context.userId = tokenData.userId;
|
|
664
|
+
context.isSuperAdmin = context.roleId === 'superadmin';
|
|
655
665
|
context.spaceId = tokenData.spaceId || context.spaceId;
|
|
656
666
|
context.lang = tokenData.lang || context.requestedLang;
|
|
657
667
|
authByToken = true;
|
package/build/BaseGateway.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DateTimeHelpers } from '@sdflc/utils';
|
|
2
|
-
import { ApiContext, BaseGatewayPropsInterface, ListArgsInterface } from './interfaces';
|
|
2
|
+
import { ApiContext, BaseGatewayPropsInterface, BuildListQueryArgsInterface, ListArgsInterface } from './interfaces';
|
|
3
3
|
import { Database } from './Database';
|
|
4
4
|
declare class BaseGateway {
|
|
5
5
|
protected config: BaseGatewayPropsInterface;
|
|
@@ -24,6 +24,7 @@ declare class BaseGateway {
|
|
|
24
24
|
getIdField(): string;
|
|
25
25
|
get(id: any): Promise<any>;
|
|
26
26
|
getMany(ids: any[]): Promise<any>;
|
|
27
|
+
buildListQuery(args?: BuildListQueryArgsInterface): any;
|
|
27
28
|
list(args?: ListArgsInterface): Promise<any>;
|
|
28
29
|
create(args: any): Promise<any[]>;
|
|
29
30
|
update(where: any, params: any): Promise<any>;
|
package/build/BaseGateway.js
CHANGED
|
@@ -269,18 +269,22 @@ class BaseGateway {
|
|
|
269
269
|
return this.loader.loadMany(ids);
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
+
buildListQuery(args) {
|
|
273
|
+
const { fieldsToUse } = args || {};
|
|
274
|
+
const query = this.getBuilder();
|
|
275
|
+
query.select(fieldsToUse);
|
|
276
|
+
return query;
|
|
277
|
+
}
|
|
272
278
|
list(args) {
|
|
273
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
-
const { filter, params } = args || {};
|
|
280
|
+
const { filter, params, useCache } = args || {};
|
|
275
281
|
const { limit, offset, sortBy } = this.getDb().createLimitOffsetSortBy(params, this.config.defaultSorting || []);
|
|
276
282
|
if (!this.config.table) {
|
|
277
283
|
return [];
|
|
278
284
|
}
|
|
279
|
-
const
|
|
280
|
-
const fieldsToUse =
|
|
281
|
-
|
|
282
|
-
: this.getIdField();
|
|
283
|
-
query.select(fieldsToUse);
|
|
285
|
+
const shouldUseCache = useCache != null ? useCache : this.config.noCache;
|
|
286
|
+
const fieldsToUse = shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
287
|
+
const query = this.buildListQuery({ filter, params, fieldsToUse });
|
|
284
288
|
yield this.onListFilter(query, filter);
|
|
285
289
|
if (limit && !isNaN(limit) && limit > 0) {
|
|
286
290
|
query.offset(offset).limit(limit);
|
|
@@ -289,7 +293,7 @@ class BaseGateway {
|
|
|
289
293
|
query.orderBy(sortBy);
|
|
290
294
|
}
|
|
291
295
|
const items = yield query;
|
|
292
|
-
return
|
|
296
|
+
return shouldUseCache ? items : yield this.getMany(items.map((row) => row.id));
|
|
293
297
|
});
|
|
294
298
|
}
|
|
295
299
|
create(args) {
|
|
@@ -183,7 +183,7 @@ class DbMigratorAndSeeder {
|
|
|
183
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
184
|
let seedGroups = [];
|
|
185
185
|
const seedFileNames = (0, lodash_1.flatten)(seedFiles);
|
|
186
|
-
const seedFnExports = yield Promise.all((0, lodash_1.map)(seedFileNames, (filename) =>
|
|
186
|
+
const seedFnExports = yield Promise.all((0, lodash_1.map)(seedFileNames, (filename) => { var _a; return _a = path_1.default.join(dirname, `./objects/${filename}.js`), Promise.resolve().then(() => __importStar(require(_a))); }));
|
|
187
187
|
const seedFns = (0, lodash_1.map)(seedFnExports, 'default');
|
|
188
188
|
const seedFnsMap = {};
|
|
189
189
|
for (let i = 0; i < seedFileNames.length; i++) {
|
package/build/dbSeeder.js
CHANGED
|
@@ -42,7 +42,7 @@ const dbHelpers_1 = require("./dbHelpers");
|
|
|
42
42
|
const generateSeeds = (dirname, seedFiles) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
let seedGroups = [];
|
|
44
44
|
const seedFileNames = (0, lodash_1.flatten)(seedFiles);
|
|
45
|
-
const seedFnExports = yield Promise.all((0, lodash_1.map)(seedFileNames, (filename) =>
|
|
45
|
+
const seedFnExports = yield Promise.all((0, lodash_1.map)(seedFileNames, (filename) => { var _a; return _a = path_1.default.join(dirname, `./objects/${filename}.js`), Promise.resolve().then(() => __importStar(require(_a))); }));
|
|
46
46
|
const seedFns = (0, lodash_1.map)(seedFnExports, 'default');
|
|
47
47
|
const seedFnsMap = {};
|
|
48
48
|
for (let i = 0; i < seedFileNames.length; i++) {
|
|
@@ -39,3 +39,4 @@ __exportStar(require("./CommonValidatorArgs"), exports);
|
|
|
39
39
|
__exportStar(require("./CreateUserTokenResult"), exports);
|
|
40
40
|
__exportStar(require("./ExtractCredentialsArgs"), exports);
|
|
41
41
|
__exportStar(require("./DownloadFileArgs"), exports);
|
|
42
|
+
__exportStar(require("./BuildListQueryArgsInterface"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,43 +29,43 @@
|
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"check-types": "^11.2.2",
|
|
31
31
|
"checkit": "^0.7.0",
|
|
32
|
-
"dataloader": "^2.
|
|
33
|
-
"dayjs": "^1.11.
|
|
32
|
+
"dataloader": "^2.2.2",
|
|
33
|
+
"dayjs": "^1.11.7",
|
|
34
34
|
"dotenv-safe": "^8.2.0",
|
|
35
35
|
"is-uuid": "^1.0.2",
|
|
36
|
-
"json-stable-stringify": "^1.0.
|
|
37
|
-
"jsonwebtoken": "^
|
|
38
|
-
"knex": "^2.
|
|
36
|
+
"json-stable-stringify": "^1.0.2",
|
|
37
|
+
"jsonwebtoken": "^9.0.0",
|
|
38
|
+
"knex": "^2.4.2",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
|
-
"pg": "^8.
|
|
41
|
-
"redis": "^4.
|
|
40
|
+
"pg": "^8.9.0",
|
|
41
|
+
"redis": "^4.6.5",
|
|
42
42
|
"uuid": "^9.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/bcrypt": "^5.0.0",
|
|
46
|
-
"@types/bluebird": "^3.5.
|
|
46
|
+
"@types/bluebird": "^3.5.38",
|
|
47
47
|
"@types/check-types": "^7.3.4",
|
|
48
48
|
"@types/dotenv-safe": "^8.1.2",
|
|
49
49
|
"@types/is-uuid": "^1.0.0",
|
|
50
|
-
"@types/jest": "^29.
|
|
50
|
+
"@types/jest": "^29.4.0",
|
|
51
51
|
"@types/json-stable-stringify": "^1.0.34",
|
|
52
|
-
"@types/jsonwebtoken": "^
|
|
52
|
+
"@types/jsonwebtoken": "^9.0.1",
|
|
53
53
|
"@types/lodash": "^4.14.181",
|
|
54
|
-
"@types/node": "^18.
|
|
55
|
-
"@types/uuid": "^
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
-
"eslint": "^8.
|
|
59
|
-
"eslint-config-prettier": "^8.
|
|
60
|
-
"eslint-plugin-jest": "^27.1
|
|
54
|
+
"@types/node": "^18.14.1",
|
|
55
|
+
"@types/uuid": "^9.0.1",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
58
|
+
"eslint": "^8.34.0",
|
|
59
|
+
"eslint-config-prettier": "^8.6.0",
|
|
60
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
61
61
|
"eslint-plugin-prettier": "^4.2.1",
|
|
62
|
-
"husky": "^8.0.
|
|
63
|
-
"jest": "^29.
|
|
64
|
-
"prettier": "^2.
|
|
65
|
-
"rimraf": "^
|
|
62
|
+
"husky": "^8.0.3",
|
|
63
|
+
"jest": "^29.4.3",
|
|
64
|
+
"prettier": "^2.8.4",
|
|
65
|
+
"rimraf": "^4.1.2",
|
|
66
66
|
"run-script-os": "^1.1.6",
|
|
67
|
-
"ts-jest": "^29.0.
|
|
67
|
+
"ts-jest": "^29.0.5",
|
|
68
68
|
"ts-node": "^10.9.1",
|
|
69
|
-
"typescript": "^4.
|
|
69
|
+
"typescript": "^4.9.5"
|
|
70
70
|
}
|
|
71
71
|
}
|