@sdflc/backend-helpers 1.0.77 → 1.0.79

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 (210) hide show
  1. package/README.md +178 -178
  2. package/build/BaseCore.d.ts +88 -88
  3. package/build/BaseCore.js +816 -819
  4. package/build/BaseGateway.d.ts +49 -49
  5. package/build/BaseGateway.js +482 -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 +243 -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 +292 -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/esm/BaseCore.d.ts +88 -0
  35. package/build/esm/BaseCore.js +810 -0
  36. package/build/esm/BaseGateway.d.ts +49 -0
  37. package/build/esm/BaseGateway.js +476 -0
  38. package/build/esm/DataCache.d.ts +14 -0
  39. package/build/esm/DataCache.js +98 -0
  40. package/build/esm/Database.d.ts +32 -0
  41. package/build/esm/Database.js +192 -0
  42. package/build/esm/DbMigratorAndSeeder.d.ts +49 -0
  43. package/build/esm/DbMigratorAndSeeder.js +199 -0
  44. package/build/esm/RedisDataLoader.d.ts +41 -0
  45. package/build/esm/RedisDataLoader.js +237 -0
  46. package/build/esm/apiContext.d.ts +11 -0
  47. package/build/esm/apiContext.js +135 -0
  48. package/build/esm/baseController.d.ts +17 -0
  49. package/build/esm/baseController.js +60 -0
  50. package/build/esm/checkItHelpers.d.ts +3 -0
  51. package/build/esm/checkItHelpers.js +23 -0
  52. package/build/esm/commonValidators.d.ts +17 -0
  53. package/build/esm/commonValidators.js +273 -0
  54. package/build/esm/configBulder.d.ts +2 -0
  55. package/build/esm/configBulder.js +28 -0
  56. package/build/esm/constants.d.ts +30 -0
  57. package/build/esm/constants.js +69 -0
  58. package/build/esm/dbHelpers.d.ts +43 -0
  59. package/build/esm/dbHelpers.js +154 -0
  60. package/build/esm/dbSeeder.d.ts +2 -0
  61. package/build/esm/dbSeeder.js +53 -0
  62. package/build/esm/dbTableHelpers.d.ts +11 -0
  63. package/build/esm/dbTableHelpers.js +99 -0
  64. package/build/esm/downloadHelpers.d.ts +2 -0
  65. package/build/esm/downloadHelpers.js +76 -0
  66. package/build/esm/index.d.ts +21 -0
  67. package/build/esm/index.js +21 -0
  68. package/build/esm/interfaces/ApiContext.d.ts +24 -0
  69. package/build/esm/interfaces/ApiContext.js +1 -0
  70. package/build/esm/interfaces/ApiContextInterface.d.ts +12 -0
  71. package/build/esm/interfaces/ApiContextInterface.js +1 -0
  72. package/build/esm/interfaces/BaseCoreActionsInterface.d.ts +38 -0
  73. package/build/esm/interfaces/BaseCoreActionsInterface.js +1 -0
  74. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -0
  75. package/build/esm/interfaces/BaseCoreDoAuthOnActionInterface.js +1 -0
  76. package/build/esm/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -0
  77. package/build/esm/interfaces/BaseCoreDoingWhatInterface.js +1 -0
  78. package/build/esm/interfaces/BaseCorePropsInterface.d.ts +36 -0
  79. package/build/esm/interfaces/BaseCorePropsInterface.js +1 -0
  80. package/build/esm/interfaces/BaseCoreValidatorsInterface.d.ts +13 -0
  81. package/build/esm/interfaces/BaseCoreValidatorsInterface.js +1 -0
  82. package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +39 -0
  83. package/build/esm/interfaces/BaseGatewayPropsInterface.js +1 -0
  84. package/build/esm/interfaces/BuildConfigOptions.d.ts +6 -0
  85. package/build/esm/interfaces/BuildConfigOptions.js +1 -0
  86. package/build/esm/interfaces/BuildDefaultResolversOptions.d.ts +17 -0
  87. package/build/esm/interfaces/BuildDefaultResolversOptions.js +1 -0
  88. package/build/esm/interfaces/BuildListQueryArgsInterface.d.ts +6 -0
  89. package/build/esm/interfaces/BuildListQueryArgsInterface.js +1 -0
  90. package/build/esm/interfaces/CacheInterface.d.ts +15 -0
  91. package/build/esm/interfaces/CacheInterface.js +1 -0
  92. package/build/esm/interfaces/CommonValidatorArgs.d.ts +3 -0
  93. package/build/esm/interfaces/CommonValidatorArgs.js +1 -0
  94. package/build/esm/interfaces/CoreActionInterface.d.ts +14 -0
  95. package/build/esm/interfaces/CoreActionInterface.js +1 -0
  96. package/build/esm/interfaces/CreateUserTokenArgs.d.ts +11 -0
  97. package/build/esm/interfaces/CreateUserTokenArgs.js +1 -0
  98. package/build/esm/interfaces/CreateUserTokenResult.d.ts +4 -0
  99. package/build/esm/interfaces/CreateUserTokenResult.js +1 -0
  100. package/build/esm/interfaces/DatabaseOptions.d.ts +22 -0
  101. package/build/esm/interfaces/DatabaseOptions.js +1 -0
  102. package/build/esm/interfaces/DatabaseReadInterface.d.ts +14 -0
  103. package/build/esm/interfaces/DatabaseReadInterface.js +1 -0
  104. package/build/esm/interfaces/DbFieldAddDefaultInterface.d.ts +9 -0
  105. package/build/esm/interfaces/DbFieldAddDefaultInterface.js +1 -0
  106. package/build/esm/interfaces/DownloadFileArgs.d.ts +6 -0
  107. package/build/esm/interfaces/DownloadFileArgs.js +1 -0
  108. package/build/esm/interfaces/ExtractCredentialsArgs.d.ts +19 -0
  109. package/build/esm/interfaces/ExtractCredentialsArgs.js +1 -0
  110. package/build/esm/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
  111. package/build/esm/interfaces/JwtTokenSecretAndSettings.js +1 -0
  112. package/build/esm/interfaces/ListArgsInterface.d.ts +5 -0
  113. package/build/esm/interfaces/ListArgsInterface.js +1 -0
  114. package/build/esm/interfaces/LoaderInterface.d.ts +4 -0
  115. package/build/esm/interfaces/LoaderInterface.js +1 -0
  116. package/build/esm/interfaces/PaginationInterface.d.ts +7 -0
  117. package/build/esm/interfaces/PaginationInterface.js +1 -0
  118. package/build/esm/interfaces/SortItemInterface.d.ts +4 -0
  119. package/build/esm/interfaces/SortItemInterface.js +1 -0
  120. package/build/esm/interfaces/UserTokenParams.d.ts +8 -0
  121. package/build/esm/interfaces/UserTokenParams.js +1 -0
  122. package/build/esm/interfaces/VerifyUserTokenArgs.d.ts +13 -0
  123. package/build/esm/interfaces/VerifyUserTokenArgs.js +1 -0
  124. package/build/esm/interfaces/index.d.ts +28 -0
  125. package/build/esm/interfaces/index.js +27 -0
  126. package/build/esm/knexConfigBuilder.d.ts +1 -0
  127. package/build/esm/knexConfigBuilder.js +73 -0
  128. package/build/esm/passwordHelpers.d.ts +5 -0
  129. package/build/esm/passwordHelpers.js +22 -0
  130. package/build/esm/redisClient.d.ts +17 -0
  131. package/build/esm/redisClient.js +94 -0
  132. package/build/esm/resolversHelpers.d.ts +3 -0
  133. package/build/esm/resolversHelpers.js +59 -0
  134. package/build/esm/userToken.d.ts +8 -0
  135. package/build/esm/userToken.js +74 -0
  136. package/build/esm/utils.d.ts +2 -0
  137. package/build/esm/utils.js +13 -0
  138. package/build/index.d.ts +21 -21
  139. package/build/index.js +37 -37
  140. package/build/interfaces/ApiContext.d.ts +24 -24
  141. package/build/interfaces/ApiContext.js +2 -2
  142. package/build/interfaces/ApiContextInterface.d.ts +12 -12
  143. package/build/interfaces/ApiContextInterface.js +2 -2
  144. package/build/interfaces/BaseCoreActionsInterface.d.ts +38 -38
  145. package/build/interfaces/BaseCoreActionsInterface.js +2 -2
  146. package/build/interfaces/BaseCoreDoAuthOnActionInterface.d.ts +12 -12
  147. package/build/interfaces/BaseCoreDoAuthOnActionInterface.js +2 -2
  148. package/build/interfaces/BaseCoreDoingWhatInterface.d.ts +13 -13
  149. package/build/interfaces/BaseCoreDoingWhatInterface.js +2 -2
  150. package/build/interfaces/BaseCorePropsInterface.d.ts +36 -36
  151. package/build/interfaces/BaseCorePropsInterface.js +2 -2
  152. package/build/interfaces/BaseCoreValidatorsInterface.d.ts +13 -13
  153. package/build/interfaces/BaseCoreValidatorsInterface.js +2 -2
  154. package/build/interfaces/BaseGatewayPropsInterface.d.ts +39 -39
  155. package/build/interfaces/BaseGatewayPropsInterface.js +2 -2
  156. package/build/interfaces/BuildConfigOptions.d.ts +6 -6
  157. package/build/interfaces/BuildConfigOptions.js +2 -2
  158. package/build/interfaces/BuildDefaultResolversOptions.d.ts +17 -17
  159. package/build/interfaces/BuildDefaultResolversOptions.js +2 -2
  160. package/build/interfaces/BuildListQueryArgsInterface.d.ts +6 -6
  161. package/build/interfaces/BuildListQueryArgsInterface.js +2 -2
  162. package/build/interfaces/CacheInterface.d.ts +15 -15
  163. package/build/interfaces/CacheInterface.js +2 -2
  164. package/build/interfaces/CommonValidatorArgs.d.ts +3 -3
  165. package/build/interfaces/CommonValidatorArgs.js +2 -2
  166. package/build/interfaces/CoreActionInterface.d.ts +14 -14
  167. package/build/interfaces/CoreActionInterface.js +2 -2
  168. package/build/interfaces/CreateUserTokenArgs.d.ts +11 -11
  169. package/build/interfaces/CreateUserTokenArgs.js +2 -2
  170. package/build/interfaces/CreateUserTokenResult.d.ts +4 -4
  171. package/build/interfaces/CreateUserTokenResult.js +2 -2
  172. package/build/interfaces/DatabaseOptions.d.ts +22 -22
  173. package/build/interfaces/DatabaseOptions.js +2 -2
  174. package/build/interfaces/DatabaseReadInterface.d.ts +14 -14
  175. package/build/interfaces/DatabaseReadInterface.js +2 -2
  176. package/build/interfaces/DbFieldAddDefaultInterface.d.ts +9 -9
  177. package/build/interfaces/DbFieldAddDefaultInterface.js +2 -2
  178. package/build/interfaces/DownloadFileArgs.d.ts +6 -6
  179. package/build/interfaces/DownloadFileArgs.js +2 -2
  180. package/build/interfaces/ExtractCredentialsArgs.d.ts +19 -19
  181. package/build/interfaces/ExtractCredentialsArgs.js +2 -2
  182. package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -5
  183. package/build/interfaces/JwtTokenSecretAndSettings.js +2 -2
  184. package/build/interfaces/ListArgsInterface.d.ts +5 -5
  185. package/build/interfaces/ListArgsInterface.js +2 -2
  186. package/build/interfaces/LoaderInterface.d.ts +4 -4
  187. package/build/interfaces/LoaderInterface.js +2 -2
  188. package/build/interfaces/PaginationInterface.d.ts +7 -7
  189. package/build/interfaces/PaginationInterface.js +2 -2
  190. package/build/interfaces/SortItemInterface.d.ts +4 -4
  191. package/build/interfaces/SortItemInterface.js +2 -2
  192. package/build/interfaces/UserTokenParams.d.ts +8 -8
  193. package/build/interfaces/UserTokenParams.js +2 -2
  194. package/build/interfaces/VerifyUserTokenArgs.d.ts +13 -13
  195. package/build/interfaces/VerifyUserTokenArgs.js +2 -2
  196. package/build/interfaces/index.d.ts +28 -28
  197. package/build/interfaces/index.js +43 -43
  198. package/build/knexConfigBuilder.d.ts +1 -1
  199. package/build/knexConfigBuilder.js +80 -80
  200. package/build/passwordHelpers.d.ts +5 -5
  201. package/build/passwordHelpers.js +30 -30
  202. package/build/redisClient.d.ts +17 -17
  203. package/build/redisClient.js +97 -97
  204. package/build/resolversHelpers.d.ts +3 -3
  205. package/build/resolversHelpers.js +62 -62
  206. package/build/userToken.d.ts +8 -8
  207. package/build/userToken.js +86 -86
  208. package/build/utils.d.ts +2 -2
  209. package/build/utils.js +21 -21
  210. package/package.json +79 -71
@@ -1,110 +1,110 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
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
- if (addStatus) {
9
- table
10
- .integer(constants_1.FIELDS.STATUS)
11
- .defaultTo(utils_1.STATUSES.ACTIVE)
12
- .comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
13
- 'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
14
- }
15
- if (addVersion) {
16
- table
17
- .integer(constants_1.FIELDS.VERSION)
18
- .defaultTo(0)
19
- .comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
20
- }
21
- if (addUserInfo) {
22
- table.uuid(constants_1.FIELDS.CREATED_BY).comment('ID of user who created the record');
23
- table.uuid(constants_1.FIELDS.UPDATED_BY).comment('ID of the last user who update the record');
24
- table.uuid(constants_1.FIELDS.REMOVED_BY).comment('ID of user who removed the record');
25
- }
26
- if (skipTimestamps !== true) {
27
- table.timestamps(true, true);
28
- table
29
- .dateTime(constants_1.FIELDS.REMOVED_AT)
30
- .comment('Date and time of removal. As it is nullable it cannot be used in any unique index');
31
- if (skipRemovedAtStr !== true) {
32
- table.text(constants_1.FIELDS.REMOVED_AT_STR).defaultTo('').comment('Used to create unique indexes.');
33
- }
34
- table.index([constants_1.FIELDS.CREATED_AT]);
35
- table.index([constants_1.FIELDS.UPDATED_AT]);
36
- }
37
- if (addStatus) {
38
- table.index([constants_1.FIELDS.STATUS]);
39
- }
40
- if (skipRemovedAtStr !== true) {
41
- table.index([constants_1.FIELDS.REMOVED_AT_STR]);
42
- }
43
- };
44
- exports.dbFieldAddDefaults = dbFieldAddDefaults;
45
- const addOrderNo = (table, opt) => {
46
- const chain = table.text(constants_1.FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
47
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
48
- table.index([constants_1.FIELDS.ORDER_NO]);
49
- }
50
- return chain;
51
- };
52
- exports.addOrderNo = addOrderNo;
53
- const addAmount = (table, fieldName) => {
54
- return table.decimal(fieldName, 19, 4);
55
- };
56
- exports.addAmount = addAmount;
57
- const addSpaceId = (table, opt) => {
58
- const chain = table.text(constants_1.FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
59
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
60
- table.foreign(constants_1.FIELDS.SPACE_ID).references(`space.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
61
- }
62
- return chain;
63
- };
64
- exports.addSpaceId = addSpaceId;
65
- const addUserId = (table, opt) => {
66
- const chain = table.uuid(constants_1.FIELDS.USER_ID).notNullable().comment('Reference to the user table');
67
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
68
- table.foreign(constants_1.FIELDS.USER_ID).references(`user.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
69
- }
70
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
71
- table.index([constants_1.FIELDS.USER_ID]);
72
- }
73
- return chain;
74
- };
75
- exports.addUserId = addUserId;
76
- const addAccountId = (table, opt) => {
77
- const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
78
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
79
- table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(`account.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
80
- }
81
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
82
- table.index([constants_1.FIELDS.ACCOUNT_ID]);
83
- }
84
- return chain;
85
- };
86
- exports.addAccountId = addAccountId;
87
- const addLang = (table, opt) => {
88
- const chain = table.text(constants_1.FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
89
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
90
- table.foreign(constants_1.FIELDS.LANG).references(`language.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
91
- }
92
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
93
- table.index([constants_1.FIELDS.LANG]);
94
- }
95
- return chain;
96
- };
97
- exports.addLang = addLang;
98
- const defaultFields = (opt) => {
99
- const { addUserInfo } = opt || {};
100
- const obj = {
101
- [constants_1.FIELDS.CREATED_AT]: '2021-01-01T00:00:00Z',
102
- [constants_1.FIELDS.UPDATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
103
- };
104
- if (addUserInfo === true) {
105
- obj[constants_1.FIELDS.CREATED_BY] = utils_1.UUID_EMPTY;
106
- obj[constants_1.FIELDS.UPDATED_BY] = utils_1.UUID_EMPTY;
107
- }
108
- return obj;
109
- };
110
- exports.defaultFields = defaultFields;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
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
+ if (addStatus) {
9
+ table
10
+ .integer(constants_1.FIELDS.STATUS)
11
+ .defaultTo(utils_1.STATUSES.ACTIVE)
12
+ .comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
13
+ 'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
14
+ }
15
+ if (addVersion) {
16
+ table
17
+ .integer(constants_1.FIELDS.VERSION)
18
+ .defaultTo(0)
19
+ .comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
20
+ }
21
+ if (addUserInfo) {
22
+ table.uuid(constants_1.FIELDS.CREATED_BY).comment('ID of user who created the record');
23
+ table.uuid(constants_1.FIELDS.UPDATED_BY).comment('ID of the last user who update the record');
24
+ table.uuid(constants_1.FIELDS.REMOVED_BY).comment('ID of user who removed the record');
25
+ }
26
+ if (skipTimestamps !== true) {
27
+ table.timestamps(true, true);
28
+ table
29
+ .dateTime(constants_1.FIELDS.REMOVED_AT)
30
+ .comment('Date and time of removal. As it is nullable it cannot be used in any unique index');
31
+ if (skipRemovedAtStr !== true) {
32
+ table.text(constants_1.FIELDS.REMOVED_AT_STR).defaultTo('').comment('Used to create unique indexes.');
33
+ }
34
+ table.index([constants_1.FIELDS.CREATED_AT]);
35
+ table.index([constants_1.FIELDS.UPDATED_AT]);
36
+ }
37
+ if (addStatus) {
38
+ table.index([constants_1.FIELDS.STATUS]);
39
+ }
40
+ if (skipRemovedAtStr !== true) {
41
+ table.index([constants_1.FIELDS.REMOVED_AT_STR]);
42
+ }
43
+ };
44
+ exports.dbFieldAddDefaults = dbFieldAddDefaults;
45
+ const addOrderNo = (table, opt) => {
46
+ const chain = table.text(constants_1.FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
47
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
48
+ table.index([constants_1.FIELDS.ORDER_NO]);
49
+ }
50
+ return chain;
51
+ };
52
+ exports.addOrderNo = addOrderNo;
53
+ const addAmount = (table, fieldName) => {
54
+ return table.decimal(fieldName, 19, 4);
55
+ };
56
+ exports.addAmount = addAmount;
57
+ const addSpaceId = (table, opt) => {
58
+ const chain = table.text(constants_1.FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
59
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
60
+ table.foreign(constants_1.FIELDS.SPACE_ID).references(`space.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
61
+ }
62
+ return chain;
63
+ };
64
+ exports.addSpaceId = addSpaceId;
65
+ const addUserId = (table, opt) => {
66
+ const chain = table.uuid(constants_1.FIELDS.USER_ID).notNullable().comment('Reference to the user table');
67
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
68
+ table.foreign(constants_1.FIELDS.USER_ID).references(`user.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
69
+ }
70
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
71
+ table.index([constants_1.FIELDS.USER_ID]);
72
+ }
73
+ return chain;
74
+ };
75
+ exports.addUserId = addUserId;
76
+ const addAccountId = (table, opt) => {
77
+ const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
78
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
79
+ table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(`account.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
80
+ }
81
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
82
+ table.index([constants_1.FIELDS.ACCOUNT_ID]);
83
+ }
84
+ return chain;
85
+ };
86
+ exports.addAccountId = addAccountId;
87
+ const addLang = (table, opt) => {
88
+ const chain = table.text(constants_1.FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
89
+ if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
90
+ table.foreign(constants_1.FIELDS.LANG).references(`language.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
91
+ }
92
+ if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
93
+ table.index([constants_1.FIELDS.LANG]);
94
+ }
95
+ return chain;
96
+ };
97
+ exports.addLang = addLang;
98
+ const defaultFields = (opt) => {
99
+ const { addUserInfo } = opt || {};
100
+ const obj = {
101
+ [constants_1.FIELDS.CREATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
102
+ [constants_1.FIELDS.UPDATED_AT]: '2021-01-01T00:00:00Z', // dh.dbUtcNow(),
103
+ };
104
+ if (addUserInfo === true) {
105
+ obj[constants_1.FIELDS.CREATED_BY] = utils_1.UUID_EMPTY;
106
+ obj[constants_1.FIELDS.UPDATED_BY] = utils_1.UUID_EMPTY;
107
+ }
108
+ return obj;
109
+ };
110
+ exports.defaultFields = defaultFields;
@@ -1,2 +1,2 @@
1
- import { DownloadFileArgs } from './interfaces';
2
- export declare const downloadFile: (args: DownloadFileArgs) => Promise<any>;
1
+ import { DownloadFileArgs } from './interfaces';
2
+ export declare const downloadFile: (args: DownloadFileArgs) => Promise<any>;
@@ -1,83 +1,83 @@
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.downloadFile = void 0;
16
- const util_1 = __importDefault(require("util"));
17
- const fs_1 = __importDefault(require("fs"));
18
- const stream_1 = __importDefault(require("stream"));
19
- const path_1 = __importDefault(require("path"));
20
- const url_1 = require("url");
21
- const axios_1 = __importDefault(require("axios"));
22
- const api_helpers_1 = require("@sdflc/api-helpers");
23
- const utils_1 = require("@sdflc/utils");
24
- const constants_1 = require("./constants");
25
- const pipeline = util_1.default.promisify(stream_1.default.pipeline);
26
- const MESSAGES = {
27
- NO_URL: 'Failed to download file as "url" prop was not provided',
28
- NO_FILENAME: 'Failed to download file as "fileName" prop was not provided and no file name was in the "url"',
29
- };
30
- const CHARSET = 'charset=';
31
- const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function* () {
32
- const measureTool = new utils_1.MeasureTool();
33
- const { durationMs, result } = yield measureTool.measureExecTime('', () => __awaiter(void 0, void 0, void 0, function* () {
34
- var _a, _b, _c;
35
- if (!(args === null || args === void 0 ? void 0 : args.url)) {
36
- return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_URL);
37
- }
38
- const url = new url_1.URL(args === null || args === void 0 ? void 0 : args.url);
39
- const fileName = !(args === null || args === void 0 ? void 0 : args.fileName) ? url.pathname.split('/').pop() || `${url.hostname}.html` : (args === null || args === void 0 ? void 0 : args.fileName) || '';
40
- if (!fileName) {
41
- return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_FILENAME);
42
- }
43
- const fullPathName = path_1.default.resolve((args === null || args === void 0 ? void 0 : args.folder) || '', fileName);
44
- try {
45
- const response = yield axios_1.default.get(url.toString(), {
46
- responseType: 'stream',
47
- });
48
- const strease2use = (args === null || args === void 0 ? void 0 : args.stream) || fs_1.default.createWriteStream(fullPathName);
49
- yield pipeline(response.data, strease2use);
50
- const contentType = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[constants_1.HEADERS.CONTENT_TYPE]) || '';
51
- const [mimeType, charset] = contentType.split('; ');
52
- const encoding = (charset === null || charset === void 0 ? void 0 : charset.startsWith(CHARSET)) ? charset.slice(CHARSET.length) : '';
53
- return api_helpers_1.OpResult.ok({
54
- url: url.toString(),
55
- fileName,
56
- fullPathName,
57
- size: Number((_c = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[constants_1.HEADERS.CONTENT_LENGTH]) !== null && _c !== void 0 ? _c : 0),
58
- mimeType,
59
- encoding,
60
- });
61
- }
62
- catch (ex) {
63
- return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.FAILED, { url: url.toString(), fileName, fullPathName, size: 0, mimeType: '' }, ex.message);
64
- }
65
- }));
66
- const data = result.getDataFirst();
67
- result.setData(Object.assign(Object.assign({}, data), { speed: (data.size * 1000) / durationMs, durationMs }));
68
- return result;
69
- });
70
- exports.downloadFile = downloadFile;
71
- // const run = async () => {
72
- // // const result = await downloadFile({
73
- // // url: 'https://sushitei.com/wp-content/uploads/2022/08/2022-Sushi-Tei-Autumn-Menu.pdf',
74
- // // fileName: '',
75
- // // });
76
- // const result = await downloadFile({
77
- // url: 'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/windows/pgadmin4-6.15-x64.exe',
78
- // fileName: '',
79
- // folder: path.resolve('d:\\Users\\dcerge\\Downloads'),
80
- // });
81
- // console.log('result', JSON.stringify(result, null, 2));
82
- // };
83
- // run();
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.downloadFile = void 0;
16
+ const util_1 = __importDefault(require("util"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const stream_1 = __importDefault(require("stream"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const url_1 = require("url");
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const api_helpers_1 = require("@sdflc/api-helpers");
23
+ const utils_1 = require("@sdflc/utils");
24
+ const constants_1 = require("./constants");
25
+ const pipeline = util_1.default.promisify(stream_1.default.pipeline);
26
+ const MESSAGES = {
27
+ NO_URL: 'Failed to download file as "url" prop was not provided',
28
+ NO_FILENAME: 'Failed to download file as "fileName" prop was not provided and no file name was in the "url"',
29
+ };
30
+ const CHARSET = 'charset=';
31
+ const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const measureTool = new utils_1.MeasureTool();
33
+ const { durationMs, result } = yield measureTool.measureExecTime('', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ var _a, _b, _c;
35
+ if (!(args === null || args === void 0 ? void 0 : args.url)) {
36
+ return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_URL);
37
+ }
38
+ const url = new url_1.URL(args === null || args === void 0 ? void 0 : args.url);
39
+ const fileName = !(args === null || args === void 0 ? void 0 : args.fileName) ? url.pathname.split('/').pop() || `${url.hostname}.html` : (args === null || args === void 0 ? void 0 : args.fileName) || '';
40
+ if (!fileName) {
41
+ return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_FILENAME);
42
+ }
43
+ const fullPathName = path_1.default.resolve((args === null || args === void 0 ? void 0 : args.folder) || '', fileName);
44
+ try {
45
+ const response = yield axios_1.default.get(url.toString(), {
46
+ responseType: 'stream',
47
+ });
48
+ const strease2use = (args === null || args === void 0 ? void 0 : args.stream) || fs_1.default.createWriteStream(fullPathName);
49
+ yield pipeline(response.data, strease2use);
50
+ const contentType = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[constants_1.HEADERS.CONTENT_TYPE]) || '';
51
+ const [mimeType, charset] = contentType.split('; ');
52
+ const encoding = (charset === null || charset === void 0 ? void 0 : charset.startsWith(CHARSET)) ? charset.slice(CHARSET.length) : '';
53
+ return api_helpers_1.OpResult.ok({
54
+ url: url.toString(),
55
+ fileName,
56
+ fullPathName,
57
+ size: Number((_c = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[constants_1.HEADERS.CONTENT_LENGTH]) !== null && _c !== void 0 ? _c : 0),
58
+ mimeType,
59
+ encoding,
60
+ });
61
+ }
62
+ catch (ex) {
63
+ return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.FAILED, { url: url.toString(), fileName, fullPathName, size: 0, mimeType: '' }, ex.message);
64
+ }
65
+ }));
66
+ const data = result.getDataFirst();
67
+ result.setData(Object.assign(Object.assign({}, data), { speed: (data.size * 1000) / durationMs, durationMs }));
68
+ return result;
69
+ });
70
+ exports.downloadFile = downloadFile;
71
+ // const run = async () => {
72
+ // // const result = await downloadFile({
73
+ // // url: 'https://sushitei.com/wp-content/uploads/2022/08/2022-Sushi-Tei-Autumn-Menu.pdf',
74
+ // // fileName: '',
75
+ // // });
76
+ // const result = await downloadFile({
77
+ // url: 'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.15/windows/pgadmin4-6.15-x64.exe',
78
+ // fileName: '',
79
+ // folder: path.resolve('d:\\Users\\dcerge\\Downloads'),
80
+ // });
81
+ // console.log('result', JSON.stringify(result, null, 2));
82
+ // };
83
+ // run();
@@ -0,0 +1,88 @@
1
+ import { OpResult } from '@sdflc/api-helpers';
2
+ import { Logger, MeasureTool } from '@sdflc/utils';
3
+ import { ID_TYPES } from './constants';
4
+ import { Database } from './Database';
5
+ import { BaseCorePropsInterface, BaseCoreActionsInterface, CoreActionInterface, JwtTokenSecretAndSettings, ApiContext, ExtractCredentialsArgs } from './interfaces';
6
+ declare class BaseCore {
7
+ protected measureTool: MeasureTool;
8
+ protected config: BaseCorePropsInterface;
9
+ protected logger: Logger;
10
+ constructor(props: BaseCorePropsInterface);
11
+ getIdType(): ID_TYPES;
12
+ getDb(): Database;
13
+ getRequestId(): string;
14
+ getContext(): ApiContext;
15
+ getGateways(): any;
16
+ getGateway(name?: string): any;
17
+ getValidators(): any;
18
+ success(data: any, code?: number): any;
19
+ failure(code: number, errorMsg: string, data?: any): any;
20
+ validationFailure(ex: OpResult | any): any;
21
+ exceptionFailure(ex: any, doingWhat: string, data?: any): any;
22
+ checkResult(args: any): Promise<void>;
23
+ runAction(opt: CoreActionInterface): Promise<any>;
24
+ list(args: any): Promise<any>;
25
+ get(args: any): Promise<any>;
26
+ getMany(args: any): Promise<any>;
27
+ getGatewayToSetOrerNo(): any;
28
+ getFilterToSetOrderNo(args: any): {};
29
+ create(args: any): Promise<any>;
30
+ createMany(args: any): Promise<any>;
31
+ update(args: any): Promise<any>;
32
+ updateMany(args: any): Promise<any>;
33
+ set(args: any): Promise<any>;
34
+ remove(args: any): Promise<any>;
35
+ removeMany(args: any): Promise<any>;
36
+ defaultAfterAndBefore(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
37
+ /**
38
+ * Used to transform an object before sending it in the response
39
+ * @param {any} item An object coming from the database
40
+ * @param {BaseCoreActionsInterface} opt Options
41
+ * @returns {any} transformed object
42
+ */
43
+ processItemOnOut(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
44
+ /**
45
+ * Used to transform an object before processing it on the request
46
+ * @param {any} item An object coming from the outside
47
+ * @param {BaseCoreActionsInterface} opt Options
48
+ * @returns {any} transformed object
49
+ */
50
+ processItemOnIn(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
51
+ beforeGet(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
52
+ beforeGetMany(items: any[], opt?: BaseCoreActionsInterface): Promise<any>;
53
+ beforeList(filter: any, opt?: BaseCoreActionsInterface): Promise<any>;
54
+ afterGet(item: any, opt?: BaseCoreActionsInterface): Promise<any>;
55
+ afterGetMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
56
+ afterList(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
57
+ beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
58
+ afterCreate(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
59
+ beforeCreateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
60
+ afterCreateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
61
+ beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
62
+ afterUpdate(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
63
+ beforeUpdateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
64
+ afterUpdateMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
65
+ beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
66
+ afterSet(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
67
+ beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
68
+ afterRemove(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
69
+ beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
70
+ afterRemoveMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
71
+ onException(params: any, opt?: BaseCoreActionsInterface): Promise<string | null | undefined>;
72
+ /**
73
+ * Returns JWT secret and its settings to verify received JWT token
74
+ * @param params Object of parameters passed to the authenticate method
75
+ * @returns Object with the jwtSecret and verifyTokenArgs
76
+ */
77
+ getJwtTokenSecretAndSettings(params: any): Promise<JwtTokenSecretAndSettings>;
78
+ findSpace(): Promise<any[]>;
79
+ extractCredentials(args: ExtractCredentialsArgs): Promise<{
80
+ token: any;
81
+ fingerprint: any;
82
+ }>;
83
+ authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<any[]>;
84
+ processRemovedRecord(record: any): any;
85
+ addRemovedModifierToFields(fields: string | string[]): any;
86
+ setOrderNo(args: any): Promise<void>;
87
+ }
88
+ export { BaseCore };