@sdflc/backend-helpers 1.0.48 → 1.0.51
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/BaseController.js +21 -62
- package/build/BaseCore.d.ts +2 -2
- package/build/BaseCore.js +425 -690
- package/build/BaseGateway.js +358 -554
- package/build/DataCache.d.ts +1 -1
- package/build/DataCache.js +55 -104
- package/build/Database.js +104 -177
- package/build/DbMigratorAndSeeder.js +131 -238
- package/build/RedisDataLoader.d.ts +41 -0
- package/build/RedisDataLoader.js +248 -0
- package/build/apiContext.js +103 -191
- package/build/checkItHelpers.js +10 -10
- package/build/commonValidators.js +49 -91
- package/build/configBulder.js +8 -19
- package/build/constants.js +3 -3
- package/build/dbHelpers.js +72 -126
- package/build/dbSeeder.js +38 -90
- package/build/dbTableHelpers.js +25 -26
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +1 -0
- package/build/interfaces/CoreActionInterface.d.ts +2 -1
- package/build/knexConfigBuilder.js +17 -28
- package/build/passwordHelpers.js +13 -59
- package/build/redisClient.d.ts +6 -0
- package/build/redisClient.js +87 -88
- package/build/resolversHelpers.js +17 -27
- package/build/userToken.js +24 -24
- package/build/utils.js +4 -5
- package/package.json +33 -34
package/build/dbTableHelpers.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const utils_1 = require("@sdflc/utils");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const dbFieldAddDefaults = (table, opt) => {
|
|
7
|
+
const { addUserInfo, addVersion, addStatus, skipTimestamps, skipRemovedAtStr } = opt || {};
|
|
8
8
|
if (addStatus) {
|
|
9
9
|
table
|
|
10
10
|
.integer(constants_1.FIELDS.STATUS)
|
|
@@ -38,30 +38,30 @@ var dbFieldAddDefaults = function (table, opt) {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
exports.dbFieldAddDefaults = dbFieldAddDefaults;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const addOrderNo = (table, opt) => {
|
|
42
|
+
const chain = table.text(constants_1.FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
|
|
43
43
|
if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
|
|
44
44
|
table.index([constants_1.FIELDS.ORDER_NO]);
|
|
45
45
|
}
|
|
46
46
|
return chain;
|
|
47
47
|
};
|
|
48
48
|
exports.addOrderNo = addOrderNo;
|
|
49
|
-
|
|
49
|
+
const addAmount = (table, fieldName) => {
|
|
50
50
|
return table.decimal(fieldName, 19, 4);
|
|
51
51
|
};
|
|
52
52
|
exports.addAmount = addAmount;
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const addSpaceId = (table, opt) => {
|
|
54
|
+
const chain = table.text(constants_1.FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
|
|
55
55
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
56
|
-
table.foreign(constants_1.FIELDS.SPACE_ID).references(
|
|
56
|
+
table.foreign(constants_1.FIELDS.SPACE_ID).references(`space.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
57
57
|
}
|
|
58
58
|
return chain;
|
|
59
59
|
};
|
|
60
60
|
exports.addSpaceId = addSpaceId;
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const addUserId = (table, opt) => {
|
|
62
|
+
const chain = table.uuid(constants_1.FIELDS.USER_ID).notNullable().comment('Reference to the user table');
|
|
63
63
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
64
|
-
table.foreign(constants_1.FIELDS.USER_ID).references(
|
|
64
|
+
table.foreign(constants_1.FIELDS.USER_ID).references(`user.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
65
65
|
}
|
|
66
66
|
if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
|
|
67
67
|
table.index([constants_1.FIELDS.USER_ID]);
|
|
@@ -69,10 +69,10 @@ var addUserId = function (table, opt) {
|
|
|
69
69
|
return chain;
|
|
70
70
|
};
|
|
71
71
|
exports.addUserId = addUserId;
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const addAccountId = (table, opt) => {
|
|
73
|
+
const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
|
|
74
74
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
75
|
-
table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(
|
|
75
|
+
table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(`account.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
76
76
|
}
|
|
77
77
|
if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
|
|
78
78
|
table.index([constants_1.FIELDS.ACCOUNT_ID]);
|
|
@@ -80,10 +80,10 @@ var addAccountId = function (table, opt) {
|
|
|
80
80
|
return chain;
|
|
81
81
|
};
|
|
82
82
|
exports.addAccountId = addAccountId;
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const addLang = (table, opt) => {
|
|
84
|
+
const chain = table.text(constants_1.FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
|
|
85
85
|
if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
|
|
86
|
-
table.foreign(constants_1.FIELDS.LANG).references(
|
|
86
|
+
table.foreign(constants_1.FIELDS.LANG).references(`language.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
87
87
|
}
|
|
88
88
|
if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
|
|
89
89
|
table.index([constants_1.FIELDS.LANG]);
|
|
@@ -91,13 +91,12 @@ var addLang = function (table, opt) {
|
|
|
91
91
|
return chain;
|
|
92
92
|
};
|
|
93
93
|
exports.addLang = addLang;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
_a);
|
|
94
|
+
const defaultFields = (opt) => {
|
|
95
|
+
const { addUserInfo } = opt || {};
|
|
96
|
+
const obj = {
|
|
97
|
+
[constants_1.FIELDS.CREATED_AT]: '2021-01-01T00:00:00Z',
|
|
98
|
+
[constants_1.FIELDS.UPDATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
|
|
99
|
+
};
|
|
101
100
|
if (addUserInfo === true) {
|
|
102
101
|
obj[constants_1.FIELDS.CREATED_BY] = utils_1.UUID_EMPTY;
|
|
103
102
|
obj[constants_1.FIELDS.UPDATED_BY] = utils_1.UUID_EMPTY;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
|
|
1
2
|
export interface CoreActionInterface {
|
|
2
3
|
args: any;
|
|
3
4
|
doAuth?: boolean;
|
|
4
5
|
accessRights?: any[];
|
|
5
|
-
validate?(args
|
|
6
|
+
validate?(args: any, opt: BaseCoreActionsInterface): Promise<any[]> | any[];
|
|
6
7
|
action(args?: any, opt?: any): any;
|
|
7
8
|
hasTransaction: boolean;
|
|
8
9
|
doingWhat?: string;
|
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.buildKnexConfig = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const utils_1 = require("@sdflc/utils");
|
|
10
|
+
const defaultMigrationsTable = 'migrations';
|
|
11
|
+
const defaultMigrationsFolder = 'migrations';
|
|
12
|
+
const defaultMigrationsTemplateFileName = 'migrations-template.js';
|
|
13
|
+
const defaultSeedsFolder = 'seeds';
|
|
14
|
+
const camelResponse = (result) => {
|
|
26
15
|
if (!result || result.rows) {
|
|
27
16
|
return result;
|
|
28
17
|
}
|
|
29
18
|
return (0, utils_1.camelKeys)(result);
|
|
30
19
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
const buildKnexConfig = (dirName, appConfig) => {
|
|
21
|
+
const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, } = appConfig;
|
|
22
|
+
const sharedConfig = {
|
|
34
23
|
client: dbType || 'pg',
|
|
35
24
|
postProcessResponse: camelResponse,
|
|
36
|
-
wrapIdentifier:
|
|
25
|
+
wrapIdentifier: (value, origImpl) => (value === '*' ? origImpl(value) : origImpl((0, lodash_1.snakeCase)(value))),
|
|
37
26
|
connection: {
|
|
38
27
|
host: dbHost,
|
|
39
28
|
port: dbPort,
|
|
@@ -43,19 +32,19 @@ var buildKnexConfig = function (dirName, appConfig) {
|
|
|
43
32
|
//ssl: database.ssl,
|
|
44
33
|
},
|
|
45
34
|
};
|
|
46
|
-
|
|
47
|
-
development:
|
|
35
|
+
const config = {
|
|
36
|
+
development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
|
|
48
37
|
stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
|
|
49
38
|
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
50
39
|
tableName: migrationsTable ||
|
|
51
|
-
|
|
40
|
+
`${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
|
|
52
41
|
}, seeds: {
|
|
53
42
|
directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
|
|
54
43
|
} }),
|
|
55
|
-
production:
|
|
44
|
+
production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
|
|
56
45
|
directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
|
|
57
46
|
tableName: migrationsTable ||
|
|
58
|
-
|
|
47
|
+
`${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
|
|
59
48
|
}, seeds: {
|
|
60
49
|
directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
|
|
61
50
|
} }),
|
package/build/passwordHelpers.js
CHANGED
|
@@ -8,69 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
15
|
exports.checkPassword = exports.getSaltAndHash = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
salt = _a.sent();
|
|
53
|
-
return [4 /*yield*/, bcrypt_1.default.hash(password, salt)];
|
|
54
|
-
case 2:
|
|
55
|
-
hash = _a.sent();
|
|
56
|
-
return [2 /*return*/, {
|
|
57
|
-
salt: salt,
|
|
58
|
-
hash: hash,
|
|
59
|
-
}];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
};
|
|
16
|
+
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
17
|
+
const getSaltAndHash = (password, saltRounds = 10) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const salt = yield bcrypt_1.default.genSalt(saltRounds);
|
|
19
|
+
const hash = yield bcrypt_1.default.hash(password, salt);
|
|
20
|
+
return {
|
|
21
|
+
salt,
|
|
22
|
+
hash,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
64
25
|
exports.getSaltAndHash = getSaltAndHash;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
case 0: return [4 /*yield*/, bcrypt_1.default.compare(password, hashedPassword)];
|
|
70
|
-
case 1:
|
|
71
|
-
isCorrect = _a.sent();
|
|
72
|
-
return [2 /*return*/, isCorrect];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}); };
|
|
26
|
+
const checkPassword = (password, hashedPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const isCorrect = yield bcrypt_1.default.compare(password, hashedPassword);
|
|
28
|
+
return isCorrect;
|
|
29
|
+
});
|
|
76
30
|
exports.checkPassword = checkPassword;
|
package/build/redisClient.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ interface CreateRedisClientInterface {
|
|
|
6
6
|
retryAttempts?: number;
|
|
7
7
|
firstTimeout?: number;
|
|
8
8
|
pingInterval?: number;
|
|
9
|
+
connectionTimeout?: number;
|
|
10
|
+
onConnecting?(): void;
|
|
11
|
+
onConnected?(): void;
|
|
12
|
+
onDisconnected?(): void;
|
|
13
|
+
onReconnecting?(): void;
|
|
14
|
+
onError?(err: any): void;
|
|
9
15
|
}
|
|
10
16
|
declare const createRedisClient: (args: CreateRedisClientInterface) => any;
|
|
11
17
|
export { createRedisClient };
|
package/build/redisClient.js
CHANGED
|
@@ -1,98 +1,97 @@
|
|
|
1
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.createRedisClient = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var _a = args || {}, redisHost = _a.redisHost, redisPort = _a.redisPort, redisPassword = _a.redisPassword, redisSsl = _a.redisSsl, retryAttempts = _a.retryAttempts, firstTimeout = _a.firstTimeout, pingInterval = _a.pingInterval;
|
|
4
|
+
const redis_1 = require("redis");
|
|
5
|
+
// const DEFAULT_RETRY_ATTEMPTS = 10;
|
|
6
|
+
// const DEFAULT_FIRST_TIMEOUT = 3000;
|
|
7
|
+
const createRedisClient = (args) => {
|
|
8
|
+
const { redisHost, redisPort, redisPassword, redisSsl,
|
|
9
|
+
//retryAttempts,
|
|
10
|
+
//firstTimeout,
|
|
11
|
+
pingInterval, connectionTimeout, onConnecting, onConnected, onDisconnected, onReconnecting, onError, } = args || {};
|
|
52
12
|
if (!redisHost) {
|
|
53
13
|
return null;
|
|
54
14
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (options.total_retry_time > 1000 * 60 * 60) {
|
|
67
|
-
// End reconnecting after a specific timeout and flush all commands
|
|
68
|
-
// with a individual error
|
|
69
|
-
return new Error('Retry time exhausted');
|
|
70
|
-
}
|
|
71
|
-
var attempts = !retryAttempts || retryAttempts == null || isNaN(retryAttempts)
|
|
72
|
-
? DEFAULT_RETRY_ATTEMPTS
|
|
73
|
-
: Number(retryAttempts);
|
|
74
|
-
if (options.attempt > attempts) {
|
|
75
|
-
// End reconnecting with built in error
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
var timeout = !firstTimeout || firstTimeout == null || isNaN(firstTimeout) ? DEFAULT_FIRST_TIMEOUT : Number(firstTimeout);
|
|
79
|
-
// reconnect after
|
|
80
|
-
return Math.min(options.attempt * 100, timeout);
|
|
15
|
+
const cfg = {
|
|
16
|
+
socket: {
|
|
17
|
+
host: redisHost,
|
|
18
|
+
port: Number(redisPort),
|
|
19
|
+
family: 0,
|
|
20
|
+
connectTimeout: connectionTimeout != undefined ? connectionTimeout : 5000,
|
|
21
|
+
noDelay: true,
|
|
22
|
+
keepAlive: pingInterval != undefined ? pingInterval : 5000,
|
|
23
|
+
tls: redisSsl,
|
|
24
|
+
rejectUnauthorized: false,
|
|
25
|
+
reconnectStrategy: (retries) => Math.min(retries * 50, 500),
|
|
81
26
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
27
|
+
password: redisPassword || undefined,
|
|
28
|
+
};
|
|
29
|
+
const redisClient = (0, redis_1.createClient)(cfg);
|
|
30
|
+
redisClient.on('connect', () => {
|
|
31
|
+
if (typeof onConnecting === 'function') {
|
|
32
|
+
onConnecting();
|
|
33
|
+
}
|
|
87
34
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
35
|
+
redisClient.on('ready', () => {
|
|
36
|
+
if (typeof onConnected === 'function') {
|
|
37
|
+
onConnected();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
redisClient.on('end', () => {
|
|
41
|
+
if (typeof onDisconnected === 'function') {
|
|
42
|
+
onDisconnected();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
redisClient.on('reconnecting', () => {
|
|
46
|
+
if (typeof onReconnecting === 'function') {
|
|
47
|
+
onReconnecting();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
redisClient.on('error', (err) => {
|
|
51
|
+
if (typeof onError === 'function') {
|
|
52
|
+
onError(err);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// const redisClientOld = redis.createClient({
|
|
56
|
+
// host: redisHost,
|
|
57
|
+
// port: Number(redisPort),
|
|
58
|
+
// password: redisPassword || undefined,
|
|
59
|
+
// no_ready_check: true,
|
|
60
|
+
// retry_strategy: function (options) {
|
|
61
|
+
// if (options.error && options.error.code === 'ECONNREFUSED') {
|
|
62
|
+
// // End reconnecting on a specific error and flush all commands with
|
|
63
|
+
// // a individual error
|
|
64
|
+
// return new Error('The server refused the connection');
|
|
65
|
+
// }
|
|
66
|
+
// if (options.total_retry_time > 1000 * 60 * 60) {
|
|
67
|
+
// // End reconnecting after a specific timeout and flush all commands
|
|
68
|
+
// // with a individual error
|
|
69
|
+
// return new Error('Retry time exhausted');
|
|
70
|
+
// }
|
|
71
|
+
// const attempts =
|
|
72
|
+
// !retryAttempts || retryAttempts == null || isNaN(retryAttempts)
|
|
73
|
+
// ? DEFAULT_RETRY_ATTEMPTS
|
|
74
|
+
// : Number(retryAttempts);
|
|
75
|
+
// if (options.attempt > attempts) {
|
|
76
|
+
// // End reconnecting with built in error
|
|
77
|
+
// return undefined;
|
|
78
|
+
// }
|
|
79
|
+
// const timeout =
|
|
80
|
+
// !firstTimeout || firstTimeout == null || isNaN(firstTimeout) ? DEFAULT_FIRST_TIMEOUT : Number(firstTimeout);
|
|
81
|
+
// // reconnect after
|
|
82
|
+
// return Math.min(options.attempt * 100, timeout);
|
|
83
|
+
// },
|
|
84
|
+
// tls: redisSsl
|
|
85
|
+
// ? {
|
|
86
|
+
// servername: redisHost,
|
|
87
|
+
// }
|
|
88
|
+
// : undefined,
|
|
89
|
+
// });
|
|
90
|
+
// if (pingInterval && !isNaN(pingInterval) && pingInterval > 1000) {
|
|
91
|
+
// setInterval(async () => {
|
|
92
|
+
// redisClient.ping();
|
|
93
|
+
// }, pingInterval);
|
|
94
|
+
// }
|
|
95
|
+
return redisClient;
|
|
97
96
|
};
|
|
98
97
|
exports.createRedisClient = createRedisClient;
|
|
@@ -1,72 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.buildDefaultResolvers = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const buildDefaultResolvers = (args) => {
|
|
5
|
+
const { prefix, core, query, mutation, types, disableList, disableGet, disableGetMany, disableCreate, disableCreateMany, disableUpdate, disableUpdateMany, disableSet, disableRemove, disableRemoveMany, } = args || {};
|
|
6
|
+
const Query = Object.assign({}, (query || {}));
|
|
7
|
+
const Mutation = Object.assign({}, (mutation || {}));
|
|
8
|
+
const coreToUse = core || `${prefix}Core`;
|
|
20
9
|
if (disableList !== true) {
|
|
21
|
-
Query[
|
|
10
|
+
Query[`${prefix}List`] = (parent, args, context) => {
|
|
22
11
|
return context.cores[coreToUse].list(args);
|
|
23
12
|
};
|
|
24
13
|
}
|
|
25
14
|
if (disableGet !== true) {
|
|
26
|
-
Query[
|
|
15
|
+
Query[`${prefix}Get`] = (parent, args, context) => {
|
|
27
16
|
return context.cores[coreToUse].get(args);
|
|
28
17
|
};
|
|
29
18
|
}
|
|
30
19
|
if (disableGetMany !== true) {
|
|
31
|
-
Query[
|
|
20
|
+
Query[`${prefix}GetMany`] = (parent, args, context) => {
|
|
32
21
|
return context.cores[coreToUse].getMany(args);
|
|
33
22
|
};
|
|
34
23
|
}
|
|
35
24
|
if (disableCreate !== true) {
|
|
36
|
-
Mutation[
|
|
25
|
+
Mutation[`${prefix}Create`] = (parent, args, context) => {
|
|
37
26
|
return context.cores[coreToUse].create(args);
|
|
38
27
|
};
|
|
39
28
|
}
|
|
40
29
|
if (disableCreateMany !== true) {
|
|
41
|
-
Mutation[
|
|
30
|
+
Mutation[`${prefix}CreateMany`] = (parent, args, context) => {
|
|
42
31
|
return context.cores[coreToUse].createMany(args);
|
|
43
32
|
};
|
|
44
33
|
}
|
|
45
34
|
if (disableUpdate !== true) {
|
|
46
|
-
Mutation[
|
|
35
|
+
Mutation[`${prefix}Update`] = (parent, args, context) => {
|
|
47
36
|
return context.cores[coreToUse].update(args);
|
|
48
37
|
};
|
|
49
38
|
}
|
|
50
39
|
if (disableUpdateMany !== true) {
|
|
51
|
-
Mutation[
|
|
40
|
+
Mutation[`${prefix}UpdateMany`] = (parent, args, context) => {
|
|
52
41
|
return context.cores[coreToUse].updateMany(args);
|
|
53
42
|
};
|
|
54
43
|
}
|
|
55
44
|
if (disableSet !== true) {
|
|
56
|
-
Mutation[
|
|
45
|
+
Mutation[`${prefix}Set`] = (parent, args, context) => {
|
|
57
46
|
return context.cores[coreToUse].set(args);
|
|
58
47
|
};
|
|
59
48
|
}
|
|
60
49
|
if (disableRemove !== true) {
|
|
61
|
-
Mutation[
|
|
50
|
+
Mutation[`${prefix}Remove`] = (parent, args, context) => {
|
|
62
51
|
return context.cores[coreToUse].remove(args);
|
|
63
52
|
};
|
|
64
53
|
}
|
|
65
54
|
if (disableRemoveMany !== true) {
|
|
66
|
-
Mutation[
|
|
55
|
+
Mutation[`${prefix}RemoveMany`] = (parent, args, context) => {
|
|
67
56
|
return context.cores[coreToUse].removeMany(args);
|
|
68
57
|
};
|
|
69
58
|
}
|
|
70
|
-
return
|
|
59
|
+
return Object.assign({ Query,
|
|
60
|
+
Mutation }, (types || {}));
|
|
71
61
|
};
|
|
72
62
|
exports.buildDefaultResolvers = buildDefaultResolvers;
|