@sdflc/backend-helpers 1.0.77 → 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 -484
  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,14 +1,14 @@
1
- import { CacheInterface, LoaderInterface } from './interfaces';
2
- declare class DataCache implements LoaderInterface {
3
- private buildKey;
4
- private loader;
5
- private config;
6
- private redisClient;
7
- constructor(props: CacheInterface);
8
- batchLoaderDefault(props: CacheInterface): (ids: any[]) => Promise<any[]>;
9
- init(batchFunction: any, keyPrefix?: string, context?: any): void;
10
- load(key: any): any;
11
- loadMany(keys: any[]): any;
12
- clear(key: any | any[]): void;
13
- }
14
- export { DataCache };
1
+ import { CacheInterface, LoaderInterface } from './interfaces';
2
+ declare class DataCache implements LoaderInterface {
3
+ private buildKey;
4
+ private loader;
5
+ private config;
6
+ private redisClient;
7
+ constructor(props: CacheInterface);
8
+ batchLoaderDefault(props: CacheInterface): (ids: any[]) => Promise<any[]>;
9
+ init(batchFunction: any, keyPrefix?: string, context?: any): void;
10
+ load(key: any): any;
11
+ loadMany(keys: any[]): any;
12
+ clear(key: any | any[]): void;
13
+ }
14
+ export { DataCache };
@@ -1,104 +1,104 @@
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.DataCache = void 0;
16
- const dataloader_1 = __importDefault(require("dataloader"));
17
- const RedisDataLoader_1 = require("./RedisDataLoader");
18
- const utils_1 = require("@sdflc/utils");
19
- const _1 = require(".");
20
- const lodash_1 = require("lodash");
21
- class DataCache {
22
- constructor(props) {
23
- const { loaderFn, keyPrefix, context, buildKey, redisClient, table } = props || {};
24
- if (!(props === null || props === void 0 ? void 0 : props.idField)) {
25
- props.idField = _1.FIELDS.ID;
26
- }
27
- if (!(props === null || props === void 0 ? void 0 : props.idFieldAs)) {
28
- props.idFieldAs = _1.FIELDS.ID;
29
- }
30
- this.config = props;
31
- this.redisClient = redisClient;
32
- this.buildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
33
- this.batchLoaderDefault = this.batchLoaderDefault.bind(this);
34
- const fn = typeof loaderFn === 'function' ? loaderFn : this.batchLoaderDefault(props);
35
- const prefixToUse = (context === null || context === void 0 ? void 0 : context.keyPrefix) || keyPrefix || table;
36
- this.init(fn, prefixToUse, context);
37
- }
38
- batchLoaderDefault(props) {
39
- const { table, idField, idFieldAs, readAll, db } = props;
40
- if (!table) {
41
- throw Error(`DataCache requires 'table' property to be setup`);
42
- }
43
- else if (!idField && readAll == null) {
44
- throw Error(`DataCache requires 'idField' or 'readAll' property to be setup`);
45
- }
46
- else if (!db) {
47
- throw Error(`DataCache requires 'db' property to be setup`);
48
- }
49
- return (ids) => __awaiter(this, void 0, void 0, function* () {
50
- const resultItems = [];
51
- const readCfg = Object.assign(Object.assign({}, props), { buildKey: this.buildKey });
52
- const idsToUse = (0, lodash_1.castArray)(ids);
53
- if (!readAll) {
54
- readCfg.mapBy = idFieldAs || idField;
55
- readCfg.whereIn = {
56
- field: idField,
57
- values: idsToUse.filter((id) => id),
58
- };
59
- }
60
- const dbItems = yield db.read(readCfg);
61
- if (readAll) {
62
- resultItems.push(...dbItems);
63
- }
64
- else {
65
- resultItems.push(...idsToUse.map((id) => dbItems[this.buildKey(id)] || null));
66
- }
67
- return resultItems;
68
- });
69
- }
70
- init(batchFunction, keyPrefix, context) {
71
- if (this.redisClient) {
72
- this.loader = new RedisDataLoader_1.RedisDataLoader(this.redisClient,
73
- // set a prefix for the keys stored in redis. This way you can avoid key
74
- // collisions for different data-sets in your redis instance.
75
- keyPrefix,
76
- // create a regular loader. This should always be set with caching disabled.
77
- {
78
- load: (ids) => batchFunction(ids, context),
79
- }, {
80
- cache: true,
81
- expire: this.config.cacheTtl,
82
- });
83
- }
84
- else {
85
- this.loader = new dataloader_1.default((ids) => batchFunction(ids, context));
86
- }
87
- }
88
- load(key) {
89
- return this.loader.load(this.buildKey(key));
90
- }
91
- loadMany(keys) {
92
- return this.loader.loadMany(keys.map((key) => this.buildKey(key)));
93
- }
94
- clear(key) {
95
- var _a;
96
- if (Array.isArray(key)) {
97
- key.forEach((item) => { var _a; return (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(item)); });
98
- }
99
- else {
100
- (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(key));
101
- }
102
- }
103
- }
104
- exports.DataCache = DataCache;
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.DataCache = void 0;
16
+ const dataloader_1 = __importDefault(require("dataloader"));
17
+ const RedisDataLoader_1 = require("./RedisDataLoader");
18
+ const utils_1 = require("@sdflc/utils");
19
+ const _1 = require(".");
20
+ const lodash_1 = require("lodash");
21
+ class DataCache {
22
+ constructor(props) {
23
+ const { loaderFn, keyPrefix, context, buildKey, redisClient, table } = props || {};
24
+ if (!(props === null || props === void 0 ? void 0 : props.idField)) {
25
+ props.idField = _1.FIELDS.ID;
26
+ }
27
+ if (!(props === null || props === void 0 ? void 0 : props.idFieldAs)) {
28
+ props.idFieldAs = _1.FIELDS.ID;
29
+ }
30
+ this.config = props;
31
+ this.redisClient = redisClient;
32
+ this.buildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
33
+ this.batchLoaderDefault = this.batchLoaderDefault.bind(this);
34
+ const fn = typeof loaderFn === 'function' ? loaderFn : this.batchLoaderDefault(props);
35
+ const prefixToUse = (context === null || context === void 0 ? void 0 : context.keyPrefix) || keyPrefix || table;
36
+ this.init(fn, prefixToUse, context);
37
+ }
38
+ batchLoaderDefault(props) {
39
+ const { table, idField, idFieldAs, readAll, db } = props;
40
+ if (!table) {
41
+ throw Error(`DataCache requires 'table' property to be setup`);
42
+ }
43
+ else if (!idField && readAll == null) {
44
+ throw Error(`DataCache requires 'idField' or 'readAll' property to be setup`);
45
+ }
46
+ else if (!db) {
47
+ throw Error(`DataCache requires 'db' property to be setup`);
48
+ }
49
+ return (ids) => __awaiter(this, void 0, void 0, function* () {
50
+ const resultItems = [];
51
+ const readCfg = Object.assign(Object.assign({}, props), { buildKey: this.buildKey });
52
+ const idsToUse = (0, lodash_1.castArray)(ids);
53
+ if (!readAll) {
54
+ readCfg.mapBy = idFieldAs || idField;
55
+ readCfg.whereIn = {
56
+ field: idField,
57
+ values: idsToUse.filter((id) => id),
58
+ };
59
+ }
60
+ const dbItems = yield db.read(readCfg);
61
+ if (readAll) {
62
+ resultItems.push(...dbItems);
63
+ }
64
+ else {
65
+ resultItems.push(...idsToUse.map((id) => dbItems[this.buildKey(id)] || null));
66
+ }
67
+ return resultItems;
68
+ });
69
+ }
70
+ init(batchFunction, keyPrefix, context) {
71
+ if (this.redisClient) {
72
+ this.loader = new RedisDataLoader_1.RedisDataLoader(this.redisClient,
73
+ // set a prefix for the keys stored in redis. This way you can avoid key
74
+ // collisions for different data-sets in your redis instance.
75
+ keyPrefix,
76
+ // create a regular loader. This should always be set with caching disabled.
77
+ {
78
+ load: (ids) => batchFunction(ids, context),
79
+ }, {
80
+ cache: true,
81
+ expire: this.config.cacheTtl,
82
+ });
83
+ }
84
+ else {
85
+ this.loader = new dataloader_1.default((ids) => batchFunction(ids, context));
86
+ }
87
+ }
88
+ load(key) {
89
+ return this.loader.load(this.buildKey(key));
90
+ }
91
+ loadMany(keys) {
92
+ return this.loader.loadMany(keys.map((key) => this.buildKey(key)));
93
+ }
94
+ clear(key) {
95
+ var _a;
96
+ if (Array.isArray(key)) {
97
+ key.forEach((item) => { var _a; return (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(item)); });
98
+ }
99
+ else {
100
+ (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(key));
101
+ }
102
+ }
103
+ }
104
+ exports.DataCache = DataCache;
@@ -1,32 +1,32 @@
1
- import { DatabaseOptions, DatabaseReadInterface } from './interfaces';
2
- declare class Database {
3
- private trx;
4
- private knexHandle;
5
- private dbSchema;
6
- private logger;
7
- constructor(props: DatabaseOptions);
8
- destroy(): void;
9
- isDbError(ex: any): any[];
10
- createTransaction(trx: any): Promise<unknown>;
11
- getSchema(): string;
12
- getBuilder(arg: any): any;
13
- raw(query: string, bindings?: any): any;
14
- runRawQuery(query: string, bindings: any): Promise<any>;
15
- startTransaction(): Promise<unknown>;
16
- setTransaction(trx: any): void;
17
- commitTransaction(): Promise<void>;
18
- rollbackTransaction(): Promise<void>;
19
- doCalculated(item: any, calculatedFields: any[]): void;
20
- read(args: DatabaseReadInterface): Promise<any>;
21
- createSortBy(sortBy: any[], defaultSortBy?: any): any[] | null;
22
- createLimitOffset(page: number, pageSize: number): {
23
- limit: number | undefined;
24
- offset: number;
25
- };
26
- createLimitOffsetSortBy(pagination: any, defaultSortBy: any): {
27
- limit: number | undefined;
28
- offset: number;
29
- sortBy: any[] | null;
30
- };
31
- }
32
- export { Database };
1
+ import { DatabaseOptions, DatabaseReadInterface } from './interfaces';
2
+ declare class Database {
3
+ private trx;
4
+ private knexHandle;
5
+ private dbSchema;
6
+ private logger;
7
+ constructor(props: DatabaseOptions);
8
+ destroy(): void;
9
+ isDbError(ex: any): any[];
10
+ createTransaction(trx: any): Promise<unknown>;
11
+ getSchema(): string;
12
+ getBuilder(arg: any): any;
13
+ raw(query: string, bindings?: any): any;
14
+ runRawQuery(query: string, bindings: any): Promise<any>;
15
+ startTransaction(): Promise<unknown>;
16
+ setTransaction(trx: any): void;
17
+ commitTransaction(): Promise<void>;
18
+ rollbackTransaction(): Promise<void>;
19
+ doCalculated(item: any, calculatedFields: any[]): void;
20
+ read(args: DatabaseReadInterface): Promise<any>;
21
+ createSortBy(sortBy: any[], defaultSortBy?: any): any[] | null;
22
+ createLimitOffset(page: number, pageSize: number): {
23
+ limit: number | undefined;
24
+ offset: number;
25
+ };
26
+ createLimitOffsetSortBy(pagination: any, defaultSortBy: any): {
27
+ limit: number | undefined;
28
+ offset: number;
29
+ sortBy: any[] | null;
30
+ };
31
+ }
32
+ export { Database };