@sdflc/backend-helpers 1.0.76 → 1.0.78

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.
Files changed (106) hide show
  1. package/README.md +178 -178
  2. package/build/BaseCore.d.ts +88 -88
  3. package/build/BaseCore.js +819 -819
  4. package/build/BaseGateway.d.ts +49 -49
  5. package/build/BaseGateway.js +484 -483
  6. package/build/DataCache.d.ts +14 -14
  7. package/build/DataCache.js +104 -104
  8. package/build/Database.d.ts +32 -32
  9. package/build/Database.js +198 -198
  10. package/build/DbMigratorAndSeeder.d.ts +49 -49
  11. package/build/DbMigratorAndSeeder.js +238 -228
  12. package/build/RedisDataLoader.d.ts +41 -41
  13. package/build/RedisDataLoader.js +248 -248
  14. package/build/apiContext.d.ts +11 -11
  15. package/build/apiContext.js +143 -143
  16. package/build/{BaseController.d.ts → baseController.d.ts} +17 -17
  17. package/build/{BaseController.js → baseController.js} +66 -66
  18. package/build/checkItHelpers.d.ts +3 -3
  19. package/build/checkItHelpers.js +28 -28
  20. package/build/commonValidators.d.ts +17 -17
  21. package/build/commonValidators.js +298 -298
  22. package/build/configBulder.d.ts +2 -2
  23. package/build/configBulder.js +32 -32
  24. package/build/constants.d.ts +30 -30
  25. package/build/constants.js +80 -81
  26. package/build/dbHelpers.d.ts +43 -43
  27. package/build/dbHelpers.js +166 -166
  28. package/build/dbSeeder.d.ts +2 -2
  29. package/build/dbSeeder.js +92 -82
  30. package/build/dbTableHelpers.d.ts +11 -11
  31. package/build/dbTableHelpers.js +110 -110
  32. package/build/downloadHelpers.d.ts +2 -2
  33. package/build/downloadHelpers.js +83 -83
  34. package/build/index.d.ts +21 -21
  35. package/build/index.js +37 -37
  36. package/build/interfaces/ApiContext.d.ts +24 -24
  37. package/build/interfaces/ApiContext.js +2 -2
  38. package/build/interfaces/ApiContextInterface.d.ts +12 -12
  39. package/build/interfaces/ApiContextInterface.js +2 -2
  40. package/build/interfaces/BaseCoreActionsInterface.d.ts +38 -38
  41. package/build/interfaces/BaseCoreActionsInterface.js +2 -2
  42. package/build/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -12
  43. package/build/interfaces/BaseCoreDoAuthOnActionInterface.js +2 -2
  44. package/build/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -13
  45. package/build/interfaces/BaseCoreDoingWhatInterface.js +2 -2
  46. package/build/interfaces/BaseCorePropsInterface.d.ts +36 -36
  47. package/build/interfaces/BaseCorePropsInterface.js +2 -2
  48. package/build/interfaces/BaseCoreValidatorsInterface.d.ts +13 -13
  49. package/build/interfaces/BaseCoreValidatorsInterface.js +2 -2
  50. package/build/interfaces/BaseGatewayPropsInterface.d.ts +39 -39
  51. package/build/interfaces/BaseGatewayPropsInterface.js +2 -2
  52. package/build/interfaces/BuildConfigOptions.d.ts +6 -6
  53. package/build/interfaces/BuildConfigOptions.js +2 -2
  54. package/build/interfaces/BuildDefaultResolversOptions.d.ts +17 -17
  55. package/build/interfaces/BuildDefaultResolversOptions.js +2 -2
  56. package/build/interfaces/BuildListQueryArgsInterface.d.ts +6 -6
  57. package/build/interfaces/BuildListQueryArgsInterface.js +2 -2
  58. package/build/interfaces/CacheInterface.d.ts +15 -15
  59. package/build/interfaces/CacheInterface.js +2 -2
  60. package/build/interfaces/CommonValidatorArgs.d.ts +3 -3
  61. package/build/interfaces/CommonValidatorArgs.js +2 -2
  62. package/build/interfaces/CoreActionInterface.d.ts +14 -14
  63. package/build/interfaces/CoreActionInterface.js +2 -2
  64. package/build/interfaces/CreateUserTokenArgs.d.ts +11 -11
  65. package/build/interfaces/CreateUserTokenArgs.js +2 -2
  66. package/build/interfaces/CreateUserTokenResult.d.ts +4 -4
  67. package/build/interfaces/CreateUserTokenResult.js +2 -2
  68. package/build/interfaces/DatabaseOptions.d.ts +22 -22
  69. package/build/interfaces/DatabaseOptions.js +2 -2
  70. package/build/interfaces/DatabaseReadInterface.d.ts +14 -14
  71. package/build/interfaces/DatabaseReadInterface.js +2 -2
  72. package/build/interfaces/DbFieldAddDefaultInterface.d.ts +9 -9
  73. package/build/interfaces/DbFieldAddDefaultInterface.js +2 -2
  74. package/build/interfaces/DownloadFileArgs.d.ts +6 -6
  75. package/build/interfaces/DownloadFileArgs.js +2 -2
  76. package/build/interfaces/ExtractCredentialsArgs.d.ts +19 -19
  77. package/build/interfaces/ExtractCredentialsArgs.js +2 -2
  78. package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -5
  79. package/build/interfaces/JwtTokenSecretAndSettings.js +2 -2
  80. package/build/interfaces/ListArgsInterface.d.ts +5 -5
  81. package/build/interfaces/ListArgsInterface.js +2 -2
  82. package/build/interfaces/LoaderInterface.d.ts +4 -4
  83. package/build/interfaces/LoaderInterface.js +2 -2
  84. package/build/interfaces/PaginationInterface.d.ts +7 -7
  85. package/build/interfaces/PaginationInterface.js +2 -2
  86. package/build/interfaces/SortItemInterface.d.ts +4 -4
  87. package/build/interfaces/SortItemInterface.js +2 -2
  88. package/build/interfaces/UserTokenParams.d.ts +8 -8
  89. package/build/interfaces/UserTokenParams.js +2 -2
  90. package/build/interfaces/VerifyUserTokenArgs.d.ts +13 -13
  91. package/build/interfaces/VerifyUserTokenArgs.js +2 -2
  92. package/build/interfaces/index.d.ts +28 -28
  93. package/build/interfaces/index.js +43 -43
  94. package/build/knexConfigBuilder.d.ts +1 -1
  95. package/build/knexConfigBuilder.js +80 -80
  96. package/build/passwordHelpers.d.ts +5 -5
  97. package/build/passwordHelpers.js +30 -30
  98. package/build/redisClient.d.ts +17 -17
  99. package/build/redisClient.js +97 -97
  100. package/build/resolversHelpers.d.ts +3 -3
  101. package/build/resolversHelpers.js +62 -62
  102. package/build/userToken.d.ts +8 -8
  103. package/build/userToken.js +86 -86
  104. package/build/utils.d.ts +2 -2
  105. package/build/utils.js +21 -21
  106. package/package.json +71 -71
@@ -1,80 +1,80 @@
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.buildKnexConfig = void 0;
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) => {
15
- if (!result || result.rows) {
16
- return result;
17
- }
18
- return (0, utils_1.camelKeys)(result);
19
- };
20
- const buildKnexConfig = (dirName, appConfig) => {
21
- const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, dbPoolMin, dbPoolMax, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, wrapIdentifierOverrideMap, dbPool, } = appConfig;
22
- const sharedConfig = {
23
- client: dbType || 'pg',
24
- postProcessResponse: camelResponse,
25
- wrapIdentifier: (value, origImpl) => {
26
- if (value === '*') {
27
- return origImpl(value);
28
- }
29
- const value2use = (wrapIdentifierOverrideMap === null || wrapIdentifierOverrideMap === void 0 ? void 0 : wrapIdentifierOverrideMap[value]) || origImpl((0, lodash_1.snakeCase)(value));
30
- return value2use;
31
- },
32
- connection: {
33
- host: dbHost,
34
- port: dbPort,
35
- user: dbUser,
36
- password: dbPassword,
37
- database: dbName,
38
- //ssl: database.ssl,
39
- },
40
- };
41
- if (typeof dbPool === 'object') {
42
- sharedConfig.pool = dbPool;
43
- }
44
- else {
45
- sharedConfig.pool = {
46
- min: dbPoolMin != null && !isNaN(dbPoolMin) ? dbPoolMin : 0,
47
- max: dbPoolMax != null && !isNaN(dbPoolMax) ? dbPoolMax : 50,
48
- acquireTimeoutMillis: 30000,
49
- createTimeoutMillis: 30000,
50
- destroyTimeoutMillis: 5000,
51
- idleTimeoutMillis: 30000,
52
- reapIntervalMillis: 1000,
53
- createRetryIntervalMillis: 200,
54
- propagateCreateError: false,
55
- };
56
- }
57
- const config = {
58
- development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
59
- stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
60
- directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
61
- tableName: migrationsTable ||
62
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
63
- }, seeds: {
64
- directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
65
- } }),
66
- production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
67
- directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
68
- tableName: migrationsTable ||
69
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
70
- }, seeds: {
71
- directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
72
- } }),
73
- };
74
- let config2use = (0, lodash_1.get)(config, nodeEnv);
75
- if (!config2use) {
76
- config2use = config.development;
77
- }
78
- return config2use;
79
- };
80
- exports.buildKnexConfig = buildKnexConfig;
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.buildKnexConfig = void 0;
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) => {
15
+ if (!result || result.rows) {
16
+ return result;
17
+ }
18
+ return (0, utils_1.camelKeys)(result);
19
+ };
20
+ const buildKnexConfig = (dirName, appConfig) => {
21
+ const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, dbPoolMin, dbPoolMax, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, wrapIdentifierOverrideMap, dbPool, } = appConfig;
22
+ const sharedConfig = {
23
+ client: dbType || 'pg',
24
+ postProcessResponse: camelResponse,
25
+ wrapIdentifier: (value, origImpl) => {
26
+ if (value === '*') {
27
+ return origImpl(value);
28
+ }
29
+ const value2use = (wrapIdentifierOverrideMap === null || wrapIdentifierOverrideMap === void 0 ? void 0 : wrapIdentifierOverrideMap[value]) || origImpl((0, lodash_1.snakeCase)(value));
30
+ return value2use;
31
+ },
32
+ connection: {
33
+ host: dbHost,
34
+ port: dbPort,
35
+ user: dbUser,
36
+ password: dbPassword,
37
+ database: dbName,
38
+ //ssl: database.ssl,
39
+ },
40
+ };
41
+ if (typeof dbPool === 'object') {
42
+ sharedConfig.pool = dbPool;
43
+ }
44
+ else {
45
+ sharedConfig.pool = {
46
+ min: dbPoolMin != null && !isNaN(dbPoolMin) ? dbPoolMin : 0,
47
+ max: dbPoolMax != null && !isNaN(dbPoolMax) ? dbPoolMax : 50,
48
+ acquireTimeoutMillis: 30000,
49
+ createTimeoutMillis: 30000,
50
+ destroyTimeoutMillis: 5000,
51
+ idleTimeoutMillis: 30000,
52
+ reapIntervalMillis: 1000,
53
+ createRetryIntervalMillis: 200,
54
+ propagateCreateError: false,
55
+ };
56
+ }
57
+ const config = {
58
+ development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
59
+ stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
60
+ directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
61
+ tableName: migrationsTable ||
62
+ `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
63
+ }, seeds: {
64
+ directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
65
+ } }),
66
+ production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
67
+ directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
68
+ tableName: migrationsTable ||
69
+ `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
70
+ }, seeds: {
71
+ directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
72
+ } }),
73
+ };
74
+ let config2use = (0, lodash_1.get)(config, nodeEnv);
75
+ if (!config2use) {
76
+ config2use = config.development;
77
+ }
78
+ return config2use;
79
+ };
80
+ exports.buildKnexConfig = buildKnexConfig;
@@ -1,5 +1,5 @@
1
- export declare const getSaltAndHash: (password: string, saltRounds?: number) => Promise<{
2
- salt: string;
3
- hash: string;
4
- }>;
5
- export declare const checkPassword: (password: string, hashedPassword: string) => Promise<boolean>;
1
+ export declare const getSaltAndHash: (password: string, saltRounds?: number) => Promise<{
2
+ salt: string;
3
+ hash: string;
4
+ }>;
5
+ export declare const checkPassword: (password: string, hashedPassword: string) => Promise<boolean>;
@@ -1,30 +1,30 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.checkPassword = exports.getSaltAndHash = void 0;
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
- });
25
- exports.getSaltAndHash = getSaltAndHash;
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
- });
30
- exports.checkPassword = checkPassword;
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkPassword = exports.getSaltAndHash = void 0;
16
+ const bcrypt_1 = __importDefault(require("bcrypt"));
17
+ const getSaltAndHash = (password_1, ...args_1) => __awaiter(void 0, [password_1, ...args_1], void 0, function* (password, saltRounds = 10) {
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
+ });
25
+ exports.getSaltAndHash = getSaltAndHash;
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
+ });
30
+ exports.checkPassword = checkPassword;
@@ -1,17 +1,17 @@
1
- interface CreateRedisClientInterface {
2
- redisHost: string;
3
- redisPort: string | number;
4
- redisPassword: string;
5
- redisSsl: boolean;
6
- retryAttempts?: number;
7
- firstTimeout?: number;
8
- pingInterval?: number;
9
- connectionTimeout?: number;
10
- onConnecting?(): void;
11
- onConnected?(): void;
12
- onDisconnected?(): void;
13
- onReconnecting?(): void;
14
- onError?(err: any): void;
15
- }
16
- declare const createRedisClient: (args: CreateRedisClientInterface) => any;
17
- export { createRedisClient };
1
+ interface CreateRedisClientInterface {
2
+ redisHost: string;
3
+ redisPort: string | number;
4
+ redisPassword: string;
5
+ redisSsl: boolean;
6
+ retryAttempts?: number;
7
+ firstTimeout?: number;
8
+ pingInterval?: number;
9
+ connectionTimeout?: number;
10
+ onConnecting?(): void;
11
+ onConnected?(): void;
12
+ onDisconnected?(): void;
13
+ onReconnecting?(): void;
14
+ onError?(err: any): void;
15
+ }
16
+ declare const createRedisClient: (args: CreateRedisClientInterface) => any;
17
+ export { createRedisClient };
@@ -1,97 +1,97 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRedisClient = void 0;
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 || {};
12
- if (!redisHost) {
13
- return null;
14
- }
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),
26
- },
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
- }
34
- });
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;
96
- };
97
- exports.createRedisClient = createRedisClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRedisClient = void 0;
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 || {};
12
+ if (!redisHost) {
13
+ return null;
14
+ }
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),
26
+ },
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
+ }
34
+ });
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;
96
+ };
97
+ exports.createRedisClient = createRedisClient;
@@ -1,3 +1,3 @@
1
- import { BuildDefaultResolvers } from './interfaces';
2
- declare const buildDefaultResolvers: (args: BuildDefaultResolvers) => any;
3
- export { buildDefaultResolvers };
1
+ import { BuildDefaultResolvers } from './interfaces';
2
+ declare const buildDefaultResolvers: (args: BuildDefaultResolvers) => any;
3
+ export { buildDefaultResolvers };
@@ -1,62 +1,62 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildDefaultResolvers = void 0;
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`;
9
- if (disableList !== true) {
10
- Query[`${prefix}List`] = (parent, args, context) => {
11
- return context.cores[coreToUse].list(args);
12
- };
13
- }
14
- if (disableGet !== true) {
15
- Query[`${prefix}Get`] = (parent, args, context) => {
16
- return context.cores[coreToUse].get(args);
17
- };
18
- }
19
- if (disableGetMany !== true) {
20
- Query[`${prefix}GetMany`] = (parent, args, context) => {
21
- return context.cores[coreToUse].getMany(args);
22
- };
23
- }
24
- if (disableCreate !== true) {
25
- Mutation[`${prefix}Create`] = (parent, args, context) => {
26
- return context.cores[coreToUse].create(args);
27
- };
28
- }
29
- if (disableCreateMany !== true) {
30
- Mutation[`${prefix}CreateMany`] = (parent, args, context) => {
31
- return context.cores[coreToUse].createMany(args);
32
- };
33
- }
34
- if (disableUpdate !== true) {
35
- Mutation[`${prefix}Update`] = (parent, args, context) => {
36
- return context.cores[coreToUse].update(args);
37
- };
38
- }
39
- if (disableUpdateMany !== true) {
40
- Mutation[`${prefix}UpdateMany`] = (parent, args, context) => {
41
- return context.cores[coreToUse].updateMany(args);
42
- };
43
- }
44
- if (disableSet !== true) {
45
- Mutation[`${prefix}Set`] = (parent, args, context) => {
46
- return context.cores[coreToUse].set(args);
47
- };
48
- }
49
- if (disableRemove !== true) {
50
- Mutation[`${prefix}Remove`] = (parent, args, context) => {
51
- return context.cores[coreToUse].remove(args);
52
- };
53
- }
54
- if (disableRemoveMany !== true) {
55
- Mutation[`${prefix}RemoveMany`] = (parent, args, context) => {
56
- return context.cores[coreToUse].removeMany(args);
57
- };
58
- }
59
- return Object.assign({ Query,
60
- Mutation }, (types || {}));
61
- };
62
- exports.buildDefaultResolvers = buildDefaultResolvers;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildDefaultResolvers = void 0;
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`;
9
+ if (disableList !== true) {
10
+ Query[`${prefix}List`] = (parent, args, context) => {
11
+ return context.cores[coreToUse].list(args);
12
+ };
13
+ }
14
+ if (disableGet !== true) {
15
+ Query[`${prefix}Get`] = (parent, args, context) => {
16
+ return context.cores[coreToUse].get(args);
17
+ };
18
+ }
19
+ if (disableGetMany !== true) {
20
+ Query[`${prefix}GetMany`] = (parent, args, context) => {
21
+ return context.cores[coreToUse].getMany(args);
22
+ };
23
+ }
24
+ if (disableCreate !== true) {
25
+ Mutation[`${prefix}Create`] = (parent, args, context) => {
26
+ return context.cores[coreToUse].create(args);
27
+ };
28
+ }
29
+ if (disableCreateMany !== true) {
30
+ Mutation[`${prefix}CreateMany`] = (parent, args, context) => {
31
+ return context.cores[coreToUse].createMany(args);
32
+ };
33
+ }
34
+ if (disableUpdate !== true) {
35
+ Mutation[`${prefix}Update`] = (parent, args, context) => {
36
+ return context.cores[coreToUse].update(args);
37
+ };
38
+ }
39
+ if (disableUpdateMany !== true) {
40
+ Mutation[`${prefix}UpdateMany`] = (parent, args, context) => {
41
+ return context.cores[coreToUse].updateMany(args);
42
+ };
43
+ }
44
+ if (disableSet !== true) {
45
+ Mutation[`${prefix}Set`] = (parent, args, context) => {
46
+ return context.cores[coreToUse].set(args);
47
+ };
48
+ }
49
+ if (disableRemove !== true) {
50
+ Mutation[`${prefix}Remove`] = (parent, args, context) => {
51
+ return context.cores[coreToUse].remove(args);
52
+ };
53
+ }
54
+ if (disableRemoveMany !== true) {
55
+ Mutation[`${prefix}RemoveMany`] = (parent, args, context) => {
56
+ return context.cores[coreToUse].removeMany(args);
57
+ };
58
+ }
59
+ return Object.assign({ Query,
60
+ Mutation }, (types || {}));
61
+ };
62
+ exports.buildDefaultResolvers = buildDefaultResolvers;
@@ -1,8 +1,8 @@
1
- import { OpResult } from '@sdflc/api-helpers';
2
- import { UserTokenParams, CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
3
- export declare const setDefaultJwtAlgorithm: (algorithm: string) => void;
4
- export declare const getDefaultJwtAlgorithm: () => string;
5
- export declare const setDefaultJwtIssuer: (issuer: string) => void;
6
- export declare const getDefaultJwtIssuer: () => string;
7
- export declare const createUserToken: (params: UserTokenParams, secret: string, opt: CreateUserTokenArgs) => any;
8
- export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs) => OpResult;
1
+ import { OpResult } from '@sdflc/api-helpers';
2
+ import { UserTokenParams, CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
3
+ export declare const setDefaultJwtAlgorithm: (algorithm: string) => void;
4
+ export declare const getDefaultJwtAlgorithm: () => string;
5
+ export declare const setDefaultJwtIssuer: (issuer: string) => void;
6
+ export declare const getDefaultJwtIssuer: () => string;
7
+ export declare const createUserToken: (params: UserTokenParams, secret: string, opt: CreateUserTokenArgs) => any;
8
+ export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs) => OpResult;