@sdflc/backend-helpers 1.0.79 → 1.0.80

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 (37) hide show
  1. package/build/BaseCore.js +496 -600
  2. package/build/BaseGateway.js +331 -377
  3. package/build/DataCache.js +16 -19
  4. package/build/Database.js +55 -74
  5. package/build/DbMigratorAndSeeder.js +88 -114
  6. package/build/RedisDataLoader.js +153 -184
  7. package/build/apiContext.js +35 -33
  8. package/build/baseController.js +9 -16
  9. package/build/commonValidators.js +22 -31
  10. package/build/configBulder.js +5 -1
  11. package/build/dbHelpers.js +19 -29
  12. package/build/dbSeeder.js +11 -20
  13. package/build/dbTableHelpers.js +10 -10
  14. package/build/downloadHelpers.js +15 -25
  15. package/build/esm/BaseCore.js +496 -600
  16. package/build/esm/BaseGateway.js +331 -377
  17. package/build/esm/DataCache.js +16 -19
  18. package/build/esm/Database.js +55 -74
  19. package/build/esm/DbMigratorAndSeeder.js +88 -114
  20. package/build/esm/RedisDataLoader.js +153 -184
  21. package/build/esm/apiContext.js +35 -33
  22. package/build/esm/baseController.js +9 -16
  23. package/build/esm/commonValidators.js +22 -31
  24. package/build/esm/configBulder.js +5 -1
  25. package/build/esm/dbHelpers.js +19 -29
  26. package/build/esm/dbSeeder.js +11 -20
  27. package/build/esm/dbTableHelpers.js +10 -10
  28. package/build/esm/downloadHelpers.js +15 -25
  29. package/build/esm/knexConfigBuilder.js +17 -7
  30. package/build/esm/passwordHelpers.js +7 -16
  31. package/build/esm/resolversHelpers.js +11 -4
  32. package/build/esm/userToken.js +2 -2
  33. package/build/knexConfigBuilder.js +17 -7
  34. package/build/passwordHelpers.js +7 -16
  35. package/build/resolversHelpers.js +11 -4
  36. package/build/userToken.js +2 -2
  37. package/package.json +2 -3
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { castArray } from 'lodash';
11
2
  import Checkit from 'checkit';
12
3
  import check from 'check-types';
@@ -145,57 +136,57 @@ export const shouldHaveId = (id) => {
145
136
  }
146
137
  return [true];
147
138
  };
148
- export const validateSingleIntId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
139
+ export const validateSingleIntId = async (args, opt) => {
149
140
  const [result] = rulesSingleIntId.validateSync(args);
150
141
  if (result) {
151
142
  return [createErrorOnCheckError(result)];
152
143
  }
153
144
  return [true, {}];
154
- });
155
- export const validateSingleUuidId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
145
+ };
146
+ export const validateSingleUuidId = async (args, opt) => {
156
147
  const [result] = rulesSingleUuidId.validateSync(args);
157
148
  if (result) {
158
149
  return [createErrorOnCheckError(result)];
159
150
  }
160
151
  return [true, {}];
161
- });
162
- export const validateSingleTextId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
152
+ };
153
+ export const validateSingleTextId = async (args, opt) => {
163
154
  const [result] = rulesSingleTextId.validateSync(args);
164
155
  if (result) {
165
156
  return [createErrorOnCheckError(result)];
166
157
  }
167
158
  return [true, {}];
168
- });
169
- export const validateMultipleIntIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
159
+ };
160
+ export const validateMultipleIntIds = async (args, opt) => {
170
161
  const [result] = rulesMultipleIntIds.validateSync(args);
171
162
  if (result) {
172
163
  return [createErrorOnCheckError(result)];
173
164
  }
174
165
  return [true, {}];
175
- });
176
- export const validateMultipleUuidIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
166
+ };
167
+ export const validateMultipleUuidIds = async (args, opt) => {
177
168
  const [result] = rulesMultipleUuidIds.validateSync(args);
178
169
  if (result) {
179
170
  return [createErrorOnCheckError(result)];
180
171
  }
181
172
  return [true, {}];
182
- });
183
- export const validateMultipleTextIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
173
+ };
174
+ export const validateMultipleTextIds = async (args, opt) => {
184
175
  const [result] = rulesMultipleTextIds.validateSync(args);
185
176
  if (result) {
186
177
  return [createErrorOnCheckError(result)];
187
178
  }
188
179
  return [true, {}];
189
- });
190
- export const validateList = ({ rules }) => (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
180
+ };
181
+ export const validateList = ({ rules }) => async (args, opt) => {
191
182
  const { filter } = args || {};
192
183
  const [result] = rules.validateSync(filter);
193
184
  if (result) {
194
185
  return [createErrorOnCheckError(result)];
195
186
  }
196
187
  return [true, {}];
197
- });
198
- export const validateGet = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
188
+ };
189
+ export const validateGet = async (args, opt) => {
199
190
  const idType = opt.core.getIdType();
200
191
  let rules = null;
201
192
  switch (idType) {
@@ -217,9 +208,9 @@ export const validateGet = (args, opt) => __awaiter(void 0, void 0, void 0, func
217
208
  return [createErrorOnCheckError(result)];
218
209
  }
219
210
  return [true, {}];
220
- });
211
+ };
221
212
  export const validateRemove = validateGet;
222
- export const validateGetMany = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
213
+ export const validateGetMany = async (args, opt) => {
223
214
  const idType = opt.core.getIdType();
224
215
  let rules = null;
225
216
  switch (idType) {
@@ -241,9 +232,9 @@ export const validateGetMany = (args, opt) => __awaiter(void 0, void 0, void 0,
241
232
  return [createErrorOnCheckError(result)];
242
233
  }
243
234
  return [true, {}];
244
- });
235
+ };
245
236
  export const validateRemoveMany = validateGetMany;
246
- export const validateCreate = ({ rules }) => (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
237
+ export const validateCreate = ({ rules }) => async (args, opt) => {
247
238
  const { params } = args || {};
248
239
  const [paramsCheck] = shouldHaveParams(params);
249
240
  if (paramsCheck !== true) {
@@ -254,8 +245,8 @@ export const validateCreate = ({ rules }) => (args, opt) => __awaiter(void 0, vo
254
245
  return [createErrorOnCheckError(result), {}];
255
246
  }
256
247
  return [true, {}];
257
- });
258
- export const validateUpdate = ({ rules }) => (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
248
+ };
249
+ export const validateUpdate = ({ rules }) => async (args, opt) => {
259
250
  const { where, params } = args || {};
260
251
  const [idCheck] = shouldHaveParams(where);
261
252
  if (idCheck !== true) {
@@ -270,4 +261,4 @@ export const validateUpdate = ({ rules }) => (args, opt) => __awaiter(void 0, vo
270
261
  return [createErrorOnCheckError(result), {}];
271
262
  }
272
263
  return [true, {}];
273
- });
264
+ };
@@ -24,5 +24,9 @@ export const buildConfig = (dirName, opt) => {
24
24
  acc[camelCase(key)] = value;
25
25
  return acc;
26
26
  }, {});
27
- return Object.assign(Object.assign({}, envVars), { nodeEnv: env.NODE_ENV, isProduction: env.NODE_ENV === 'production' });
27
+ return {
28
+ ...envVars,
29
+ nodeEnv: env.NODE_ENV,
30
+ isProduction: env.NODE_ENV === 'production',
31
+ };
28
32
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import BPromise from 'bluebird';
11
2
  import { reduce } from 'lodash';
12
3
  const SQLS = {
@@ -14,16 +5,16 @@ const SQLS = {
14
5
  listTablesSchema: (appSettings) => `
15
6
  SELECT TABLE_NAME as table_name
16
7
  FROM INFORMATION_SCHEMA.TABLES
17
- WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
8
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
18
9
  `,
19
10
  listTables: () => `
20
11
  SELECT TABLE_NAME as table_name
21
12
  FROM INFORMATION_SCHEMA.TABLES
22
13
  `,
23
14
  dropTablesSchema: (appSettings) => `
24
- SELECT 'DROP TABLE IF EXISTS ${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}.' || TABLE_NAME || ';' as cmd
15
+ SELECT 'DROP TABLE IF EXISTS ${appSettings?.dbSchema}.' || TABLE_NAME || ';' as cmd
25
16
  FROM INFORMATION_SCHEMA.TABLES
26
- WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
17
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
27
18
  `,
28
19
  dropTables: () => `
29
20
  SELECT 'DROP TABLE IF EXISTS ' || TABLE_NAME || ';' as cmd
@@ -34,16 +25,16 @@ const SQLS = {
34
25
  listTablesSchema: (appSettings) => `
35
26
  SELECT TABLE_NAME as table_name
36
27
  FROM INFORMATION_SCHEMA.TABLES
37
- WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
28
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
38
29
  `,
39
30
  listTables: () => `
40
31
  SELECT TABLE_NAME as table_name
41
32
  FROM INFORMATION_SCHEMA.TABLES
42
33
  `,
43
34
  dropTablesSchema: (appSettings) => `
44
- SELECT 'DROP TABLE IF EXISTS [${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}].[' + TABLE_NAME + '];' as cmd
35
+ SELECT 'DROP TABLE IF EXISTS [${appSettings?.dbSchema}].[' + TABLE_NAME + '];' as cmd
45
36
  FROM INFORMATION_SCHEMA.TABLES
46
- WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
37
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
47
38
  `,
48
39
  dropTables: () => `
49
40
  SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
@@ -59,10 +50,9 @@ const SQLS = {
59
50
  * @param knexHandle Knex handle object with configured connection to DB
60
51
  * @param appSettings settings with db related information
61
52
  */
62
- const dbCleanTable = (table, knexHandle, appSettings) => __awaiter(void 0, void 0, void 0, function* () {
63
- var _a;
53
+ const dbCleanTable = async (table, knexHandle, appSettings) => {
64
54
  const query = knexHandle(table).withSchema(appSettings.dbSchema).delete();
65
- const cleanTableFilters = (_a = appSettings === null || appSettings === void 0 ? void 0 : appSettings.cleanTableFilters) === null || _a === void 0 ? void 0 : _a[table];
55
+ const cleanTableFilters = appSettings?.cleanTableFilters?.[table];
66
56
  if (cleanTableFilters != undefined) {
67
57
  if (Array.isArray(cleanTableFilters.where)) {
68
58
  cleanTableFilters.where.forEach((whereItem) => {
@@ -70,25 +60,25 @@ const dbCleanTable = (table, knexHandle, appSettings) => __awaiter(void 0, void
70
60
  });
71
61
  }
72
62
  }
73
- yield query;
74
- });
63
+ await query;
64
+ };
75
65
  /**
76
66
  * Returns a list of tables in db schedm specified in settings
77
67
  * @param knexHandle Knex handle object with configured connection to DB
78
68
  * @param appSettings settings with db related information
79
69
  * @returns arrays of table names in the provided db schema
80
70
  */
81
- const dbListTables = (knexHandle, appSettings) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const dbListTables = async (knexHandle, appSettings) => {
82
72
  const skipTables = (appSettings || {}).skipTables || [];
83
73
  let query = SQLS[appSettings.dbType].listTablesSchema(appSettings);
84
74
  if (!appSettings.dbSchema) {
85
75
  query = SQLS[appSettings.dbType].listTables(appSettings);
86
76
  }
87
- const tables = yield knexHandle.raw(query);
77
+ const tables = await knexHandle.raw(query);
88
78
  return (tables.rows || [])
89
79
  .map((row) => row.table_name)
90
80
  .filter((table) => skipTables.indexOf(table) === -1);
91
- });
81
+ };
92
82
  /**
93
83
  * Removes all the records from provided list of tables
94
84
  * @param tablesToClean array of table names
@@ -96,14 +86,14 @@ const dbListTables = (knexHandle, appSettings) => __awaiter(void 0, void 0, void
96
86
  * @param appSettings settings with db related information
97
87
  * @returns promise
98
88
  */
99
- const dbClean = (tablesToClean, knexHandle, appSettings) => __awaiter(void 0, void 0, void 0, function* () {
89
+ const dbClean = async (tablesToClean, knexHandle, appSettings) => {
100
90
  for (let idx = 0, len = tablesToClean.length; idx < len; ++idx) {
101
- yield dbCleanTable(tablesToClean[idx], knexHandle, appSettings);
91
+ await dbCleanTable(tablesToClean[idx], knexHandle, appSettings);
102
92
  }
103
93
  return new BPromise((resolve) => {
104
94
  resolve(tablesToClean);
105
95
  });
106
- });
96
+ };
107
97
  /**
108
98
  * Selects all the tables in the schema and drops them.
109
99
  * This approach does not work in case we have constraints.
@@ -142,13 +132,13 @@ const dbTransformSeedsToObject = (generatedSeedArrays) => reduce(generatedSeedAr
142
132
  const dbRunMigrations = (knexHandle, appSettings) => {
143
133
  return knexHandle.migrate
144
134
  .latest()
145
- .then((result) => __awaiter(void 0, void 0, void 0, function* () {
135
+ .then(async (result) => {
146
136
  if (appSettings && appSettings.runDbSeed && result[1].length > 0) {
147
- yield knexHandle.seed.run();
137
+ await knexHandle.seed.run();
148
138
  }
149
139
  console.log('Ran', result[1].length, 'migration(s)');
150
140
  return knexHandle.migrate.currentVersion();
151
- }))
141
+ })
152
142
  .then((version) => console.log('Current version of database: ', version));
153
143
  };
154
144
  export { dbCleanTable, dbListTables, dbClean, dbWipe, dbReset, dbTransformSeedsToObject, dbRunMigrations };
@@ -1,19 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import path from 'path';
11
2
  import { camelCase, flatten, map } from 'lodash';
12
3
  import { dbClean } from './dbHelpers';
13
- const generateSeeds = (dirname, seedFiles) => __awaiter(void 0, void 0, void 0, function* () {
4
+ const generateSeeds = async (dirname, seedFiles) => {
14
5
  let seedGroups = [];
15
6
  const seedFileNames = flatten(seedFiles);
16
- const seedFnExports = yield Promise.all(map(seedFileNames, (filename) => import(path.join(dirname, `./objects/${filename}.js`))));
7
+ const seedFnExports = await Promise.all(map(seedFileNames, (filename) => import(path.join(dirname, `./objects/${filename}.js`))));
17
8
  const seedFns = map(seedFnExports, 'default');
18
9
  const seedFnsMap = {};
19
10
  for (let i = 0; i < seedFileNames.length; i++) {
@@ -31,7 +22,7 @@ const generateSeeds = (dirname, seedFiles) => __awaiter(void 0, void 0, void 0,
31
22
  return seeds;
32
23
  }, {});
33
24
  return seedGroups;
34
- });
25
+ };
35
26
  const removeSeedsFromDb = (seedFiles, knexHandle, config) => {
36
27
  const tablesToReset = flatten(seedFiles).reverse();
37
28
  console.log('Deleting records from tables: ', tablesToReset);
@@ -40,14 +31,14 @@ const removeSeedsFromDb = (seedFiles, knexHandle, config) => {
40
31
  const insertRecords = (seedGroups, knexHandle, config) => {
41
32
  const { dbSchema } = config || {};
42
33
  console.log('Inserting seeds records tables tables...');
43
- return seedGroups.reduce((previousGroup, group) => __awaiter(void 0, void 0, void 0, function* () {
44
- yield previousGroup;
34
+ return seedGroups.reduce(async (previousGroup, group) => {
35
+ await previousGroup;
45
36
  return Promise.all(Object.keys(group).map((table) => knexHandle(table).withSchema(dbSchema).insert(group[table])));
46
- }), Promise.resolve());
37
+ }, Promise.resolve());
38
+ };
39
+ const dbSeed = async (dirname, seedFiles, knexHandle, config) => {
40
+ const groups = await generateSeeds(dirname, seedFiles);
41
+ await removeSeedsFromDb(seedFiles, knexHandle, config);
42
+ return await insertRecords(groups, knexHandle, config);
47
43
  };
48
- const dbSeed = (dirname, seedFiles, knexHandle, config) => __awaiter(void 0, void 0, void 0, function* () {
49
- const groups = yield generateSeeds(dirname, seedFiles);
50
- yield removeSeedsFromDb(seedFiles, knexHandle, config);
51
- return yield insertRecords(groups, knexHandle, config);
52
- });
53
44
  export { dbSeed };
@@ -6,14 +6,14 @@ export const dbFieldAddDefaults = (table, opt) => {
6
6
  table
7
7
  .integer(FIELDS.STATUS)
8
8
  .defaultTo(STATUSES.ACTIVE)
9
- .comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
9
+ .comment(opt?.statusComment ||
10
10
  'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
11
11
  }
12
12
  if (addVersion) {
13
13
  table
14
14
  .integer(FIELDS.VERSION)
15
15
  .defaultTo(0)
16
- .comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
16
+ .comment(opt?.versionComment || 'The field is used to control versioning');
17
17
  }
18
18
  if (addUserInfo) {
19
19
  table.uuid(FIELDS.CREATED_BY).comment('ID of user who created the record');
@@ -40,7 +40,7 @@ export const dbFieldAddDefaults = (table, opt) => {
40
40
  };
41
41
  export const addOrderNo = (table, opt) => {
42
42
  const chain = table.text(FIELDS.ORDER_NO).notNullable().defaultTo('10000000');
43
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
43
+ if (opt?.addIndex === true) {
44
44
  table.index([FIELDS.ORDER_NO]);
45
45
  }
46
46
  return chain;
@@ -50,37 +50,37 @@ export const addAmount = (table, fieldName) => {
50
50
  };
51
51
  export const addSpaceId = (table, opt) => {
52
52
  const chain = table.text(FIELDS.SPACE_ID).notNullable().comment('Reference to the space table');
53
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
53
+ if (opt?.addForeignKey === true) {
54
54
  table.foreign(FIELDS.SPACE_ID).references(`space.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
55
55
  }
56
56
  return chain;
57
57
  };
58
58
  export const addUserId = (table, opt) => {
59
59
  const chain = table.uuid(FIELDS.USER_ID).notNullable().comment('Reference to the user table');
60
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
60
+ if (opt?.addForeignKey === true) {
61
61
  table.foreign(FIELDS.USER_ID).references(`user.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
62
62
  }
63
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
63
+ if (opt?.addIndex === true) {
64
64
  table.index([FIELDS.USER_ID]);
65
65
  }
66
66
  return chain;
67
67
  };
68
68
  export const addAccountId = (table, opt) => {
69
69
  const chain = table.uuid(FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the user table');
70
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
70
+ if (opt?.addForeignKey === true) {
71
71
  table.foreign(FIELDS.ACCOUNT_ID).references(`account.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
72
72
  }
73
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
73
+ if (opt?.addIndex === true) {
74
74
  table.index([FIELDS.ACCOUNT_ID]);
75
75
  }
76
76
  return chain;
77
77
  };
78
78
  export const addLang = (table, opt) => {
79
79
  const chain = table.text(FIELDS.LANG).defaultTo('en').notNullable().comment('Language, example: en, ru, en_CA, etc');
80
- if ((opt === null || opt === void 0 ? void 0 : opt.addForeignKey) === true) {
80
+ if (opt?.addForeignKey === true) {
81
81
  table.foreign(FIELDS.LANG).references(`language.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
82
82
  }
83
- if ((opt === null || opt === void 0 ? void 0 : opt.addIndex) === true) {
83
+ if (opt?.addIndex === true) {
84
84
  table.index([FIELDS.LANG]);
85
85
  }
86
86
  return chain;
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import util from 'util';
11
2
  import fs from 'fs';
12
3
  import stream from 'stream';
@@ -22,33 +13,32 @@ const MESSAGES = {
22
13
  NO_FILENAME: 'Failed to download file as "fileName" prop was not provided and no file name was in the "url"',
23
14
  };
24
15
  const CHARSET = 'charset=';
25
- export const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function* () {
16
+ export const downloadFile = async (args) => {
26
17
  const measureTool = new MeasureTool();
27
- const { durationMs, result } = yield measureTool.measureExecTime('', () => __awaiter(void 0, void 0, void 0, function* () {
28
- var _a, _b, _c;
29
- if (!(args === null || args === void 0 ? void 0 : args.url)) {
18
+ const { durationMs, result } = await measureTool.measureExecTime('', async () => {
19
+ if (!args?.url) {
30
20
  return OpResult.fail(OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_URL);
31
21
  }
32
- const url = new URL(args === null || args === void 0 ? void 0 : args.url);
33
- 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) || '';
22
+ const url = new URL(args?.url);
23
+ const fileName = !args?.fileName ? url.pathname.split('/').pop() || `${url.hostname}.html` : args?.fileName || '';
34
24
  if (!fileName) {
35
25
  return OpResult.fail(OP_RESULT_CODES.VALIDATION_FAILED, {}, MESSAGES.NO_FILENAME);
36
26
  }
37
- const fullPathName = path.resolve((args === null || args === void 0 ? void 0 : args.folder) || '', fileName);
27
+ const fullPathName = path.resolve(args?.folder || '', fileName);
38
28
  try {
39
- const response = yield axios.get(url.toString(), {
29
+ const response = await axios.get(url.toString(), {
40
30
  responseType: 'stream',
41
31
  });
42
- const strease2use = (args === null || args === void 0 ? void 0 : args.stream) || fs.createWriteStream(fullPathName);
43
- yield pipeline(response.data, strease2use);
44
- const contentType = ((_a = response === null || response === void 0 ? void 0 : response.headers) === null || _a === void 0 ? void 0 : _a[HEADERS.CONTENT_TYPE]) || '';
32
+ const strease2use = args?.stream || fs.createWriteStream(fullPathName);
33
+ await pipeline(response.data, strease2use);
34
+ const contentType = response?.headers?.[HEADERS.CONTENT_TYPE] || '';
45
35
  const [mimeType, charset] = contentType.split('; ');
46
- const encoding = (charset === null || charset === void 0 ? void 0 : charset.startsWith(CHARSET)) ? charset.slice(CHARSET.length) : '';
36
+ const encoding = charset?.startsWith(CHARSET) ? charset.slice(CHARSET.length) : '';
47
37
  return OpResult.ok({
48
38
  url: url.toString(),
49
39
  fileName,
50
40
  fullPathName,
51
- size: Number((_c = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[HEADERS.CONTENT_LENGTH]) !== null && _c !== void 0 ? _c : 0),
41
+ size: Number(response.headers?.[HEADERS.CONTENT_LENGTH] ?? 0),
52
42
  mimeType,
53
43
  encoding,
54
44
  });
@@ -56,11 +46,11 @@ export const downloadFile = (args) => __awaiter(void 0, void 0, void 0, function
56
46
  catch (ex) {
57
47
  return OpResult.fail(OP_RESULT_CODES.FAILED, { url: url.toString(), fileName, fullPathName, size: 0, mimeType: '' }, ex.message);
58
48
  }
59
- }));
49
+ });
60
50
  const data = result.getDataFirst();
61
- result.setData(Object.assign(Object.assign({}, data), { speed: (data.size * 1000) / durationMs, durationMs }));
51
+ result.setData({ ...data, speed: (data.size * 1000) / durationMs, durationMs });
62
52
  return result;
63
- });
53
+ };
64
54
  // const run = async () => {
65
55
  // // const result = await downloadFile({
66
56
  // // url: 'https://sushitei.com/wp-content/uploads/2022/08/2022-Sushi-Tei-Autumn-Menu.pdf',
@@ -20,7 +20,7 @@ export const buildKnexConfig = (dirName, appConfig) => {
20
20
  if (value === '*') {
21
21
  return origImpl(value);
22
22
  }
23
- const value2use = (wrapIdentifierOverrideMap === null || wrapIdentifierOverrideMap === void 0 ? void 0 : wrapIdentifierOverrideMap[value]) || origImpl(snakeCase(value));
23
+ const value2use = wrapIdentifierOverrideMap?.[value] || origImpl(snakeCase(value));
24
24
  return value2use;
25
25
  },
26
26
  connection: {
@@ -49,21 +49,31 @@ export const buildKnexConfig = (dirName, appConfig) => {
49
49
  };
50
50
  }
51
51
  const config = {
52
- development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
52
+ development: {
53
+ ...sharedConfig,
54
+ debug,
55
+ migrations: {
53
56
  stub: path.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
54
57
  directory: path.join(dirName, migrationsFolder || defaultMigrationsFolder),
55
58
  tableName: migrationsTable ||
56
59
  `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
57
- }, seeds: {
60
+ },
61
+ seeds: {
58
62
  directory: path.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
59
- } }),
60
- production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
63
+ },
64
+ },
65
+ production: {
66
+ ...sharedConfig,
67
+ debug,
68
+ migrations: {
61
69
  directory: path.join(dirName, migrationsFolder || defaultMigrationsFolder),
62
70
  tableName: migrationsTable ||
63
71
  `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
64
- }, seeds: {
72
+ },
73
+ seeds: {
65
74
  directory: path.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
66
- } }),
75
+ },
76
+ },
67
77
  };
68
78
  let config2use = get(config, nodeEnv);
69
79
  if (!config2use) {
@@ -1,22 +1,13 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import bcrypt from 'bcrypt';
11
- export const getSaltAndHash = (password_1, ...args_1) => __awaiter(void 0, [password_1, ...args_1], void 0, function* (password, saltRounds = 10) {
12
- const salt = yield bcrypt.genSalt(saltRounds);
13
- const hash = yield bcrypt.hash(password, salt);
2
+ export const getSaltAndHash = async (password, saltRounds = 10) => {
3
+ const salt = await bcrypt.genSalt(saltRounds);
4
+ const hash = await bcrypt.hash(password, salt);
14
5
  return {
15
6
  salt,
16
7
  hash,
17
8
  };
18
- });
19
- export const checkPassword = (password, hashedPassword) => __awaiter(void 0, void 0, void 0, function* () {
20
- const isCorrect = yield bcrypt.compare(password, hashedPassword);
9
+ };
10
+ export const checkPassword = async (password, hashedPassword) => {
11
+ const isCorrect = await bcrypt.compare(password, hashedPassword);
21
12
  return isCorrect;
22
- });
13
+ };
@@ -1,7 +1,11 @@
1
1
  const buildDefaultResolvers = (args) => {
2
2
  const { prefix, core, query, mutation, types, disableList, disableGet, disableGetMany, disableCreate, disableCreateMany, disableUpdate, disableUpdateMany, disableSet, disableRemove, disableRemoveMany, } = args || {};
3
- const Query = Object.assign({}, (query || {}));
4
- const Mutation = Object.assign({}, (mutation || {}));
3
+ const Query = {
4
+ ...(query || {}),
5
+ };
6
+ const Mutation = {
7
+ ...(mutation || {}),
8
+ };
5
9
  const coreToUse = core || `${prefix}Core`;
6
10
  if (disableList !== true) {
7
11
  Query[`${prefix}List`] = (parent, args, context) => {
@@ -53,7 +57,10 @@ const buildDefaultResolvers = (args) => {
53
57
  return context.cores[coreToUse].removeMany(args);
54
58
  };
55
59
  }
56
- return Object.assign({ Query,
57
- Mutation }, (types || {}));
60
+ return {
61
+ Query,
62
+ Mutation,
63
+ ...(types || {}),
64
+ };
58
65
  };
59
66
  export { buildDefaultResolvers };
@@ -32,7 +32,7 @@ export const createUserToken = (params, secret, opt) => {
32
32
  issuer: issuer || defaultIssuer,
33
33
  jwtid: jwtid || uuid(),
34
34
  subject: params.userId,
35
- noTimestamp: noTimestamp !== null && noTimestamp !== void 0 ? noTimestamp : false,
35
+ noTimestamp: noTimestamp ?? false,
36
36
  header,
37
37
  keyid,
38
38
  expiresIn: expiresIn && !isNaN(expiresIn) ? expiresIn : undefined,
@@ -57,7 +57,7 @@ export const verifyUserToken = (token, secret, args) => {
57
57
  clockTimestamp,
58
58
  nonce,
59
59
  });
60
- if ((obj === null || obj === void 0 ? void 0 : obj.fingerprint) && obj.fingerprint != fingerprint) {
60
+ if (obj?.fingerprint && obj.fingerprint != fingerprint) {
61
61
  return OpResult.fail(OP_RESULT_CODES.UNAUTHORIZED, null, 'User unauthenticated');
62
62
  }
63
63
  return OpResult.ok(obj);
@@ -26,7 +26,7 @@ const buildKnexConfig = (dirName, appConfig) => {
26
26
  if (value === '*') {
27
27
  return origImpl(value);
28
28
  }
29
- const value2use = (wrapIdentifierOverrideMap === null || wrapIdentifierOverrideMap === void 0 ? void 0 : wrapIdentifierOverrideMap[value]) || origImpl((0, lodash_1.snakeCase)(value));
29
+ const value2use = wrapIdentifierOverrideMap?.[value] || origImpl((0, lodash_1.snakeCase)(value));
30
30
  return value2use;
31
31
  },
32
32
  connection: {
@@ -55,21 +55,31 @@ const buildKnexConfig = (dirName, appConfig) => {
55
55
  };
56
56
  }
57
57
  const config = {
58
- development: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
58
+ development: {
59
+ ...sharedConfig,
60
+ debug,
61
+ migrations: {
59
62
  stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
60
63
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
61
64
  tableName: migrationsTable ||
62
65
  `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
63
- }, seeds: {
66
+ },
67
+ seeds: {
64
68
  directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
65
- } }),
66
- production: Object.assign(Object.assign({}, sharedConfig), { debug, migrations: {
69
+ },
70
+ },
71
+ production: {
72
+ ...sharedConfig,
73
+ debug,
74
+ migrations: {
67
75
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
68
76
  tableName: migrationsTable ||
69
77
  `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
70
- }, seeds: {
78
+ },
79
+ seeds: {
71
80
  directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
72
- } }),
81
+ },
82
+ },
73
83
  };
74
84
  let config2use = (0, lodash_1.get)(config, nodeEnv);
75
85
  if (!config2use) {