@sdflc/backend-helpers 1.0.24 → 1.0.27
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 +175 -0
- package/build/{baseController.d.ts → BaseController.d.ts} +0 -0
- package/build/{baseController.js → BaseController.js} +0 -0
- package/build/{baseCore.d.ts → BaseCore.d.ts} +13 -20
- package/build/{baseCore.js → BaseCore.js} +116 -152
- package/build/{baseGateway.d.ts → BaseGateway.d.ts} +15 -11
- package/build/{baseGateway.js → BaseGateway.js} +138 -97
- package/build/{dataCache.d.ts → DataCache.d.ts} +0 -0
- package/build/{dataCache.js → DataCache.js} +2 -2
- package/build/{database.d.ts → Database.d.ts} +0 -0
- package/build/{database.js → Database.js} +0 -0
- package/build/{dbMigratorAndSeeder.d.ts → DbMigratorAndSeeder.d.ts} +0 -0
- package/build/{dbMigratorAndSeeder.js → DbMigratorAndSeeder.js} +5 -1
- package/build/apiContext.d.ts +3 -3
- package/build/apiContext.js +89 -32
- package/build/constants.d.ts +4 -5
- package/build/constants.js +23 -4
- package/build/dbSeeder.js +5 -1
- package/build/dbTableHelpers.d.ts +2 -0
- package/build/dbTableHelpers.js +48 -27
- package/build/index.d.ts +9 -11
- package/build/index.js +19 -20
- package/build/interfaces/ApiContext.d.ts +23 -0
- package/build/interfaces/{BaseCoreInterface.js → ApiContext.js} +0 -0
- package/build/interfaces/ApiContextInterface.d.ts +5 -1
- package/build/interfaces/BaseCorePropsInterface.d.ts +31 -0
- package/build/interfaces/{BaseGatewayInterface.js → BaseCorePropsInterface.js} +0 -0
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +28 -0
- package/build/interfaces/BaseGatewayPropsInterface.js +2 -0
- package/build/interfaces/CacheInterface.d.ts +3 -3
- package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
- package/build/interfaces/JwtTokenSecretAndSettings.js +2 -0
- package/build/interfaces/index.d.ts +4 -2
- package/build/resolversHelpers.js +11 -10
- package/build/userToken.js +3 -3
- package/package.json +68 -68
- package/build/baseGatewayHelpers.d.ts +0 -20
- package/build/baseGatewayHelpers.js +0 -87
- package/build/interfaces/BaseCoreInterface.d.ts +0 -43
- package/build/interfaces/BaseGatewayInterface.d.ts +0 -26
package/package.json
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
|
|
5
|
-
"main": "build/index.js",
|
|
6
|
-
"types": "build/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"build/**/*"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "rimraf ./build && tsc",
|
|
12
|
-
"lint": "eslint . --ext .ts --fix",
|
|
13
|
-
"test": "echo No Tests Available Yet",
|
|
14
|
-
"testToDo": "jest --config jest.config.ts",
|
|
15
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
|
-
"prepare": "husky install && npm run build",
|
|
17
|
-
"prepare1": "husky install",
|
|
18
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
19
|
-
"preversion": "npm run lint",
|
|
20
|
-
"version": "npm run format && git add -A src",
|
|
21
|
-
"postversion": "git push && git push --tags"
|
|
22
|
-
},
|
|
23
|
-
"author": "Sergey Demidenko",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"peerDependencies": {},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@types/bcrypt": "^5.0.0",
|
|
28
|
-
"@types/bluebird": "^3.5.36",
|
|
29
|
-
"@types/dotenv-safe": "^8.1.2",
|
|
30
|
-
"@types/jest": "^26.0.24",
|
|
31
|
-
"@types/jsonwebtoken": "^8.5.8",
|
|
32
|
-
"@types/lodash": "^4.14.
|
|
33
|
-
"@types/node": "^14.18.12",
|
|
34
|
-
"@types/redis": "^2.8.32",
|
|
35
|
-
"@types/uuid": "^8.3.4",
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
37
|
-
"@typescript-eslint/parser": "^4.33.0",
|
|
38
|
-
"eslint": "^7.32.0",
|
|
39
|
-
"eslint-config-prettier": "^6.15.0",
|
|
40
|
-
"eslint-plugin-jest": "^24.7.0",
|
|
41
|
-
"eslint-plugin-prettier": "^3.4.1",
|
|
42
|
-
"eslint-plugin-react": "^7.
|
|
43
|
-
"husky": "^6.0.0",
|
|
44
|
-
"jest": "^26.6.3",
|
|
45
|
-
"prettier": "^2.5.1",
|
|
46
|
-
"rimraf": "^3.0.2",
|
|
47
|
-
"run-script-os": "^1.1.3",
|
|
48
|
-
"ts-jest": "^26.4.4",
|
|
49
|
-
"ts-node": "^9.0.0",
|
|
50
|
-
"typescript": "^4.5.5"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"@sdflc/api-helpers": "^1.1.
|
|
54
|
-
"@sdflc/utils": "^1.0.
|
|
55
|
-
"bcrypt": "^5.0.1",
|
|
56
|
-
"bluebird": "^3.7.2",
|
|
57
|
-
"dataloader": "^2.0.0",
|
|
58
|
-
"dayjs": "^1.10.7",
|
|
59
|
-
"dotenv-safe": "^8.2.0",
|
|
60
|
-
"jsonwebtoken": "^8.5.1",
|
|
61
|
-
"knex": "^0.95.15",
|
|
62
|
-
"lodash": "^4.17.20",
|
|
63
|
-
"pg": "^8.7.3",
|
|
64
|
-
"redis": "^3.1.2",
|
|
65
|
-
"redis-dataloader": "^1.0.2",
|
|
66
|
-
"uuid": "^8.3.2"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@sdflc/backend-helpers",
|
|
3
|
+
"version": "1.0.27",
|
|
4
|
+
"description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "rimraf ./build && tsc",
|
|
12
|
+
"lint": "eslint . --ext .ts --fix",
|
|
13
|
+
"test": "echo No Tests Available Yet",
|
|
14
|
+
"testToDo": "jest --config jest.config.ts",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
|
+
"prepare": "husky install && npm run build",
|
|
17
|
+
"prepare1": "husky install",
|
|
18
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
19
|
+
"preversion": "npm run lint",
|
|
20
|
+
"version": "npm run format && git add -A src",
|
|
21
|
+
"postversion": "git push && git push --tags"
|
|
22
|
+
},
|
|
23
|
+
"author": "Sergey Demidenko",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"peerDependencies": {},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/bcrypt": "^5.0.0",
|
|
28
|
+
"@types/bluebird": "^3.5.36",
|
|
29
|
+
"@types/dotenv-safe": "^8.1.2",
|
|
30
|
+
"@types/jest": "^26.0.24",
|
|
31
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
32
|
+
"@types/lodash": "^4.14.179",
|
|
33
|
+
"@types/node": "^14.18.12",
|
|
34
|
+
"@types/redis": "^2.8.32",
|
|
35
|
+
"@types/uuid": "^8.3.4",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
37
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
38
|
+
"eslint": "^7.32.0",
|
|
39
|
+
"eslint-config-prettier": "^6.15.0",
|
|
40
|
+
"eslint-plugin-jest": "^24.7.0",
|
|
41
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
42
|
+
"eslint-plugin-react": "^7.29.1",
|
|
43
|
+
"husky": "^6.0.0",
|
|
44
|
+
"jest": "^26.6.3",
|
|
45
|
+
"prettier": "^2.5.1",
|
|
46
|
+
"rimraf": "^3.0.2",
|
|
47
|
+
"run-script-os": "^1.1.3",
|
|
48
|
+
"ts-jest": "^26.4.4",
|
|
49
|
+
"ts-node": "^9.0.0",
|
|
50
|
+
"typescript": "^4.5.5"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@sdflc/api-helpers": "^1.1.8",
|
|
54
|
+
"@sdflc/utils": "^1.0.19",
|
|
55
|
+
"bcrypt": "^5.0.1",
|
|
56
|
+
"bluebird": "^3.7.2",
|
|
57
|
+
"dataloader": "^2.0.0",
|
|
58
|
+
"dayjs": "^1.10.7",
|
|
59
|
+
"dotenv-safe": "^8.2.0",
|
|
60
|
+
"jsonwebtoken": "^8.5.1",
|
|
61
|
+
"knex": "^0.95.15",
|
|
62
|
+
"lodash": "^4.17.20",
|
|
63
|
+
"pg": "^8.7.3",
|
|
64
|
+
"redis": "^3.1.2",
|
|
65
|
+
"redis-dataloader": "^1.0.2",
|
|
66
|
+
"uuid": "^8.3.2"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const buildDefaultGatewayProps: (args: any) => {
|
|
2
|
-
filter: (query: any, params: any) => any;
|
|
3
|
-
keyPrefix: any;
|
|
4
|
-
context: any;
|
|
5
|
-
buildKey: any;
|
|
6
|
-
table: any;
|
|
7
|
-
idField: any;
|
|
8
|
-
setFields: any;
|
|
9
|
-
readAll: boolean;
|
|
10
|
-
redisClient: any;
|
|
11
|
-
cacheTtl: any;
|
|
12
|
-
noCache: boolean;
|
|
13
|
-
idGenerator: () => string;
|
|
14
|
-
insertFormatter: (args?: any) => any;
|
|
15
|
-
updateFormatter: (args?: any) => any;
|
|
16
|
-
updateFilter: (query: any, params: any) => void;
|
|
17
|
-
removeFormatter: () => any;
|
|
18
|
-
removeFilter: (query: any, params: any) => void;
|
|
19
|
-
returnFields: any;
|
|
20
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildDefaultGatewayProps = void 0;
|
|
7
|
-
var uuid_1 = require("uuid");
|
|
8
|
-
var dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
-
var lodash_1 = require("lodash");
|
|
10
|
-
var utils_1 = require("@sdflc/utils");
|
|
11
|
-
var constants_1 = __importDefault(require("./constants"));
|
|
12
|
-
var FIELDS = constants_1.default.FIELDS;
|
|
13
|
-
var buildDefaultGatewayProps = function (args) {
|
|
14
|
-
var config = args.config, tableName = args.tableName, filter = args.filter, updateFilter = args.updateFilter, hasStatus = args.hasStatus, hasRemovedAt = args.hasRemovedAt, hasRemovedAtStr = args.hasRemovedAtStr, setFields = args.setFields, idField = args.idField, activeStatuses = args.activeStatuses, redisClient = args.redisClient, context = args.context, buildKey = args.buildKey, returnFields = args.returnFields;
|
|
15
|
-
return {
|
|
16
|
-
filter: function (query, params) {
|
|
17
|
-
if (hasStatus === undefined || hasStatus === true) {
|
|
18
|
-
query.whereIn(FIELDS.STATUS, activeStatuses);
|
|
19
|
-
}
|
|
20
|
-
else if (hasRemovedAt === undefined || hasRemovedAt === true) {
|
|
21
|
-
query.whereNull(FIELDS.REMOVED_AT);
|
|
22
|
-
}
|
|
23
|
-
if (typeof filter === 'function') {
|
|
24
|
-
filter(query, params);
|
|
25
|
-
}
|
|
26
|
-
return query;
|
|
27
|
-
},
|
|
28
|
-
keyPrefix: tableName,
|
|
29
|
-
context: context,
|
|
30
|
-
buildKey: buildKey,
|
|
31
|
-
table: tableName,
|
|
32
|
-
idField: idField || FIELDS.ID,
|
|
33
|
-
setFields: setFields,
|
|
34
|
-
readAll: false,
|
|
35
|
-
redisClient: redisClient,
|
|
36
|
-
cacheTtl: config.cacheTtl,
|
|
37
|
-
noCache: false,
|
|
38
|
-
idGenerator: function () {
|
|
39
|
-
var id = (0, uuid_1.v4)();
|
|
40
|
-
return id;
|
|
41
|
-
},
|
|
42
|
-
insertFormatter: function (args) {
|
|
43
|
-
return args;
|
|
44
|
-
},
|
|
45
|
-
updateFormatter: function (args) {
|
|
46
|
-
return args;
|
|
47
|
-
},
|
|
48
|
-
updateFilter: function (query, params) {
|
|
49
|
-
var id = (params || {}).id;
|
|
50
|
-
if (id) {
|
|
51
|
-
query.whereIn(FIELDS.ID, (0, lodash_1.castArray)(id));
|
|
52
|
-
}
|
|
53
|
-
if (typeof updateFilter === 'function') {
|
|
54
|
-
updateFilter(query, params);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
removeFormatter: function () {
|
|
58
|
-
var removalTime = (0, dayjs_1.default)();
|
|
59
|
-
var removedAt = removalTime.toDate();
|
|
60
|
-
var obj = {
|
|
61
|
-
removedAt: removedAt,
|
|
62
|
-
};
|
|
63
|
-
if (hasRemovedAtStr === undefined || hasRemovedAtStr === true) {
|
|
64
|
-
obj[FIELDS.REMOVED_AT_STR] = removalTime.format('YYYYMMDDTHHmmssZ');
|
|
65
|
-
}
|
|
66
|
-
if (hasStatus === undefined || hasStatus === true) {
|
|
67
|
-
obj[FIELDS.STATUS] = utils_1.STATUSES.REMOVED;
|
|
68
|
-
}
|
|
69
|
-
return obj;
|
|
70
|
-
},
|
|
71
|
-
removeFilter: function (query, params) {
|
|
72
|
-
var arr = [];
|
|
73
|
-
if (Array.isArray(params)) {
|
|
74
|
-
arr.push.apply(arr, params);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
arr.push(params);
|
|
78
|
-
}
|
|
79
|
-
query = query.whereIn(FIELDS.ID, arr.map(function (item) { return item[FIELDS.ID]; }));
|
|
80
|
-
if (hasStatus === undefined || hasStatus === true) {
|
|
81
|
-
query.where(FIELDS.STATUS, '!=', utils_1.STATUSES.REMOVED);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
returnFields: returnFields || [FIELDS.ID],
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
exports.buildDefaultGatewayProps = buildDefaultGatewayProps;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
|
|
2
|
-
import { LoggerLevels, Logger } from '@sdflc/utils';
|
|
3
|
-
import { Database } from '../database';
|
|
4
|
-
import { BaseGateway } from '../baseGateway';
|
|
5
|
-
import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
|
|
6
|
-
import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
|
|
7
|
-
import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
|
|
8
|
-
export interface BaseCoreInterface {
|
|
9
|
-
db: Database;
|
|
10
|
-
context?: any;
|
|
11
|
-
gateway?: BaseGateway;
|
|
12
|
-
gateways?: any;
|
|
13
|
-
isProduction: boolean;
|
|
14
|
-
logLevel: LoggerLevels;
|
|
15
|
-
logger?: Logger;
|
|
16
|
-
name?: string;
|
|
17
|
-
requestId: string;
|
|
18
|
-
doAuth: boolean;
|
|
19
|
-
doingWhat?: BaseCoreDoingWhatInterface;
|
|
20
|
-
beforeList?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
21
|
-
beforeCreate?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
22
|
-
beforeCreateMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
23
|
-
beforeUpdate?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
24
|
-
beforeUpdateMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
25
|
-
beforeSet?(params: any, opt?: any): BaseCoreActionsInterface;
|
|
26
|
-
beforeRemove?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
27
|
-
beforeRemoveMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
28
|
-
afterList?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
29
|
-
afterCreate?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
30
|
-
afterCreateMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
31
|
-
afterUpdate?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
32
|
-
afterUpdateMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
33
|
-
afterSet?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
34
|
-
afterRemove?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
35
|
-
afterRemoveMany?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
36
|
-
onException?(params: any, opt?: BaseCoreActionsInterface): any;
|
|
37
|
-
validators?: BaseCoreValidatorsInterface;
|
|
38
|
-
authenticate?(params: any, opt?: BaseCoreActionsInterface): Promise<any[]> | any[];
|
|
39
|
-
gwSpace?: BaseGateway;
|
|
40
|
-
interserviceApiKey?: string;
|
|
41
|
-
jwtSecret?: string;
|
|
42
|
-
verifytokenArgs?: VerifyUserTokenArgs;
|
|
43
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { LoggerLevels, Logger } from '@sdflc/utils';
|
|
2
|
-
import { BaseCore } from '../baseCore';
|
|
3
|
-
import { Database } from '../database';
|
|
4
|
-
import { LoaderInterface } from './LoaderInterface';
|
|
5
|
-
import { SortItemInterface } from './SortItemInterface';
|
|
6
|
-
export interface BaseGatewayInterface {
|
|
7
|
-
db: Database;
|
|
8
|
-
core?: BaseCore;
|
|
9
|
-
table?: string;
|
|
10
|
-
idField?: string;
|
|
11
|
-
setFields?: string[] | string;
|
|
12
|
-
selectFields?: any[];
|
|
13
|
-
defaultSorting?: SortItemInterface[];
|
|
14
|
-
filter?(query: any, params: any): any;
|
|
15
|
-
loader?: LoaderInterface;
|
|
16
|
-
noCache?: boolean;
|
|
17
|
-
idGenerator?(args?: any): any;
|
|
18
|
-
insertFormatter?(args?: any): any;
|
|
19
|
-
updateFormatter?(args?: any, where?: any): any;
|
|
20
|
-
updateFilter?(query: any, params: any): any;
|
|
21
|
-
removeFormatter?(args?: any): any;
|
|
22
|
-
removeFilter?(query: any, params: any): any;
|
|
23
|
-
returnFields?: any[];
|
|
24
|
-
logLevel: LoggerLevels;
|
|
25
|
-
logger?: Logger;
|
|
26
|
-
}
|