@sdflc/backend-helpers 1.0.60 → 1.0.61

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.
@@ -1,5 +1,6 @@
1
1
  import { OpResult } from '@sdflc/api-helpers';
2
2
  import { Logger, MeasureTool } from '@sdflc/utils';
3
+ import { ID_TYPES } from './constants';
3
4
  import { Database } from './Database';
4
5
  import { BaseCorePropsInterface, BaseCoreActionsInterface, CoreActionInterface, JwtTokenSecretAndSettings, ApiContext, ExtractCredentialsArgs } from './interfaces';
5
6
  declare class BaseCore {
@@ -7,10 +8,12 @@ declare class BaseCore {
7
8
  protected config: BaseCorePropsInterface;
8
9
  protected logger: Logger;
9
10
  constructor(props: BaseCorePropsInterface);
11
+ getIdType(): ID_TYPES;
10
12
  getDb(): Database;
11
13
  getRequestId(): string;
12
14
  getContext(): ApiContext;
13
15
  getGateways(): any;
16
+ getGateway(name?: string): any;
14
17
  getValidators(): any;
15
18
  success(data: any, code?: number): any;
16
19
  failure(code: number, errorMsg: string, data?: any): any;
@@ -21,6 +24,8 @@ declare class BaseCore {
21
24
  list(args: any): Promise<any>;
22
25
  get(args: any): Promise<any>;
23
26
  getMany(args: any): Promise<any>;
27
+ getGatewayToSetOrerNo(): any;
28
+ getFilterToSetOrderNo(args: any): {};
24
29
  create(args: any): Promise<any>;
25
30
  createMany(args: any): Promise<any>;
26
31
  update(args: any): Promise<any>;
@@ -29,22 +34,40 @@ declare class BaseCore {
29
34
  remove(args: any): Promise<any>;
30
35
  removeMany(args: any): Promise<any>;
31
36
  defaultAfterAndBefore(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
32
- beforeList(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
33
- afterList(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>;
34
57
  beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
35
- afterCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
36
- beforeCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
37
- afterCreateMany(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>;
38
61
  beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
39
- afterUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
40
- beforeUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
41
- afterUpdateMany(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>;
42
65
  beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
43
- afterSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
66
+ afterSet(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
44
67
  beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
45
- afterRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
68
+ afterRemove(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
46
69
  beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
47
- afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
70
+ afterRemoveMany(items: any, opt?: BaseCoreActionsInterface): Promise<any>;
48
71
  onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
49
72
  /**
50
73
  * Returns JWT secret and its settings to verify received JWT token
package/build/BaseCore.js CHANGED
@@ -13,22 +13,23 @@ exports.BaseCore = void 0;
13
13
  const api_helpers_1 = require("@sdflc/api-helpers");
14
14
  const utils_1 = require("@sdflc/utils");
15
15
  const lodash_1 = require("lodash");
16
+ const commonValidators_1 = require("./commonValidators");
16
17
  const constants_1 = require("./constants");
17
18
  const userToken_1 = require("./userToken");
18
- const defaultValidate = ( /*params: any, opt?: BaseCoreActionsInterface*/) => {
19
+ const defaultValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
19
20
  return [true, {}];
20
21
  };
21
22
  const defaultValidators = {
22
23
  list: defaultValidate,
23
- get: defaultValidate,
24
- getMany: defaultValidate,
24
+ get: commonValidators_1.validateGet,
25
+ getMany: commonValidators_1.validateGetMany,
25
26
  create: defaultValidate,
26
27
  createMany: defaultValidate,
27
28
  update: defaultValidate,
28
29
  updateMany: defaultValidate,
29
30
  set: defaultValidate,
30
- remove: defaultValidate,
31
- removeMany: defaultValidate,
31
+ remove: commonValidators_1.validateRemove,
32
+ removeMany: commonValidators_1.validateRemoveMany,
32
33
  };
33
34
  class BaseCore {
34
35
  constructor(props) {
@@ -36,6 +37,10 @@ class BaseCore {
36
37
  this.config = props;
37
38
  this.logger = props.logger;
38
39
  }
40
+ getIdType() {
41
+ var _a;
42
+ return (_a = this.config.idType) !== null && _a !== void 0 ? _a : constants_1.ID_TYPES.UNKNOWN;
43
+ }
39
44
  getDb() {
40
45
  return this.config.db;
41
46
  }
@@ -48,6 +53,10 @@ class BaseCore {
48
53
  getGateways() {
49
54
  return this.config.context.gateways || {};
50
55
  }
56
+ getGateway(name) {
57
+ var _a;
58
+ return (_a = this.getGateways()) === null || _a === void 0 ? void 0 : _a[name || this.config.gatewayName];
59
+ }
51
60
  getValidators() {
52
61
  return defaultValidators;
53
62
  }
@@ -238,7 +247,7 @@ class BaseCore {
238
247
  const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.list(object));
239
248
  const result = yield this.afterList(items, opt);
240
249
  // ON NO DATA RETURN EMPTY CODE
241
- return this.success(result /*, result.length > 0 OP_RESULT_CODES.OK : OP_RESULT_CODES.*/);
250
+ return this.success(result);
242
251
  }),
243
252
  hasTransaction: false,
244
253
  doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'listing',
@@ -252,11 +261,15 @@ class BaseCore {
252
261
  args,
253
262
  validate: this.getValidators().get,
254
263
  accessRights: [utils_1.ACCESS_RIGHTS.GET],
255
- action: (args) => __awaiter(this, void 0, void 0, function* () {
264
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
256
265
  var _d;
257
- const { id } = args || {};
258
- const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.get(id));
259
- return this.success([item], item ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
266
+ const id2use = this.beforeGet(args, opt);
267
+ const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.get(id2use));
268
+ const result = yield this.afterGet(item, opt);
269
+ if (!result) {
270
+ return this.failure(api_helpers_1.OP_RESULT_CODES.NOT_FOUND, '', []);
271
+ }
272
+ return this.success([result]);
260
273
  }),
261
274
  hasTransaction: false,
262
275
  doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'getting an item',
@@ -270,17 +283,24 @@ class BaseCore {
270
283
  args,
271
284
  validate: this.getValidators().getMany,
272
285
  accessRights: [utils_1.ACCESS_RIGHTS.GET],
273
- action: (args) => __awaiter(this, void 0, void 0, function* () {
286
+ action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
274
287
  var _d;
275
- const { ids } = args || {};
276
- const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.getMany(ids));
277
- return this.success(items, items.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
288
+ const ids2use = this.beforeGetMany(args, opt);
289
+ const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.getMany(ids2use));
290
+ const result = yield this.afterGetMany(items, opt);
291
+ return this.success(result);
278
292
  }),
279
293
  hasTransaction: false,
280
294
  doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.getMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'geting multiple items',
281
295
  });
282
296
  });
283
297
  }
298
+ getGatewayToSetOrerNo() {
299
+ return this.getContext().gateways[this.config.gatewayName];
300
+ }
301
+ getFilterToSetOrderNo(args) {
302
+ return {};
303
+ }
284
304
  create(args) {
285
305
  var _a, _b, _c;
286
306
  return __awaiter(this, void 0, void 0, function* () {
@@ -291,9 +311,16 @@ class BaseCore {
291
311
  action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
292
312
  var _d;
293
313
  const { params } = args || {};
314
+ if (this.config.hasOrderNo === true) {
315
+ this.setOrderNo({
316
+ params,
317
+ filter: this.getFilterToSetOrderNo({ params, opt }),
318
+ gateway: this.getGatewayToSetOrerNo(),
319
+ });
320
+ }
294
321
  const object = yield this.beforeCreate(params, opt);
295
- const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.create(object));
296
- const result = yield this.afterCreate(item, opt);
322
+ const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.create(object));
323
+ const result = yield this.afterCreate(items, opt);
297
324
  return this.success(result);
298
325
  }),
299
326
  hasTransaction: true,
@@ -332,8 +359,8 @@ class BaseCore {
332
359
  var _d;
333
360
  const { where, params } = args || {};
334
361
  const object = yield this.beforeUpdate(params, opt);
335
- const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.update(where, object));
336
- const result = yield this.afterUpdate(item, opt);
362
+ const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.update(where, object));
363
+ const result = yield this.afterUpdate(items, opt);
337
364
  return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
338
365
  }),
339
366
  hasTransaction: true,
@@ -427,64 +454,107 @@ class BaseCore {
427
454
  return params;
428
455
  });
429
456
  }
430
- beforeList(params, opt) {
457
+ /**
458
+ * Used to transform an object before sending it in the response
459
+ * @param {any} item An object coming from the database
460
+ * @param {BaseCoreActionsInterface} opt Options
461
+ * @returns {any} transformed object
462
+ */
463
+ processItemOnOut(item, opt) {
464
+ return this.defaultAfterAndBefore(item, opt);
465
+ }
466
+ /**
467
+ * Used to transform an object before processing it on the request
468
+ * @param {any} item An object coming from the outside
469
+ * @param {BaseCoreActionsInterface} opt Options
470
+ * @returns {any} transformed object
471
+ */
472
+ processItemOnIn(item, opt) {
473
+ return this.defaultAfterAndBefore(item, opt);
474
+ }
475
+ beforeGet(item, opt) {
431
476
  return __awaiter(this, void 0, void 0, function* () {
432
- return this.defaultAfterAndBefore(params, opt);
477
+ return this.defaultAfterAndBefore(item, opt);
433
478
  });
434
479
  }
435
- afterList(params, opt) {
480
+ beforeGetMany(items, opt) {
436
481
  return __awaiter(this, void 0, void 0, function* () {
437
- return this.defaultAfterAndBefore(params, opt);
482
+ return this.defaultAfterAndBefore(items, opt);
483
+ });
484
+ }
485
+ beforeList(filter, opt) {
486
+ return __awaiter(this, void 0, void 0, function* () {
487
+ return this.defaultAfterAndBefore(filter, opt);
488
+ });
489
+ }
490
+ afterGet(item, opt) {
491
+ return __awaiter(this, void 0, void 0, function* () {
492
+ return this.processItemOnOut(item, opt);
493
+ });
494
+ }
495
+ afterGetMany(items, opt) {
496
+ return __awaiter(this, void 0, void 0, function* () {
497
+ return items.map((item) => this.processItemOnOut(item, opt));
498
+ });
499
+ }
500
+ afterList(items, opt) {
501
+ return __awaiter(this, void 0, void 0, function* () {
502
+ return items.map((item) => this.processItemOnOut(item, opt));
438
503
  });
439
504
  }
440
505
  beforeCreate(params, opt) {
441
506
  return __awaiter(this, void 0, void 0, function* () {
442
- return this.defaultAfterAndBefore(params, opt);
507
+ return this.processItemOnIn(params, opt);
443
508
  });
444
509
  }
445
- afterCreate(params, opt) {
510
+ afterCreate(items, opt) {
446
511
  return __awaiter(this, void 0, void 0, function* () {
447
- return this.defaultAfterAndBefore(params, opt);
512
+ return items.map((item) => this.processItemOnOut(item, opt));
448
513
  });
449
514
  }
450
- beforeCreateMany(params, opt) {
515
+ beforeCreateMany(items, opt) {
451
516
  return __awaiter(this, void 0, void 0, function* () {
452
- return this.defaultAfterAndBefore(params, opt);
517
+ return items.map((item) => this.processItemOnIn(item, opt));
453
518
  });
454
519
  }
455
- afterCreateMany(params, opt) {
520
+ afterCreateMany(items, opt) {
456
521
  return __awaiter(this, void 0, void 0, function* () {
457
- return this.defaultAfterAndBefore(params, opt);
522
+ return items.map((item) => this.processItemOnOut(item, opt));
458
523
  });
459
524
  }
460
525
  beforeUpdate(params, opt) {
461
526
  return __awaiter(this, void 0, void 0, function* () {
462
- return this.defaultAfterAndBefore(params, opt);
527
+ return this.processItemOnIn(params, opt);
463
528
  });
464
529
  }
465
- afterUpdate(params, opt) {
530
+ afterUpdate(items, opt) {
466
531
  return __awaiter(this, void 0, void 0, function* () {
467
- return this.defaultAfterAndBefore(params, opt);
532
+ return items.map((item) => this.processItemOnOut(item, opt));
468
533
  });
469
534
  }
470
- beforeUpdateMany(params, opt) {
535
+ beforeUpdateMany(items, opt) {
471
536
  return __awaiter(this, void 0, void 0, function* () {
472
- return this.defaultAfterAndBefore(params, opt);
537
+ return items.map((item) => {
538
+ return {
539
+ params: this.processItemOnIn(item.params, opt),
540
+ where: item.where,
541
+ };
542
+ });
473
543
  });
474
544
  }
475
- afterUpdateMany(params, opt) {
545
+ afterUpdateMany(items, opt) {
476
546
  return __awaiter(this, void 0, void 0, function* () {
477
- return this.defaultAfterAndBefore(params, opt);
547
+ return items.map((item) => this.processItemOnOut(item, opt));
478
548
  });
479
549
  }
480
550
  beforeSet(params, opt) {
481
551
  return __awaiter(this, void 0, void 0, function* () {
482
- return this.defaultAfterAndBefore(params, opt);
552
+ return (0, lodash_1.castArray)(params).map((item) => this.processItemOnIn(item, opt));
483
553
  });
484
554
  }
485
- afterSet(params, opt) {
555
+ afterSet(items, opt) {
486
556
  return __awaiter(this, void 0, void 0, function* () {
487
- return this.defaultAfterAndBefore(params, opt);
557
+ return items.map((item) => this.processItemOnOut(item, opt));
488
558
  });
489
559
  }
490
560
  beforeRemove(params, opt) {
@@ -492,9 +562,9 @@ class BaseCore {
492
562
  return this.defaultAfterAndBefore(params, opt);
493
563
  });
494
564
  }
495
- afterRemove(params, opt) {
565
+ afterRemove(items, opt) {
496
566
  return __awaiter(this, void 0, void 0, function* () {
497
- return this.defaultAfterAndBefore(params, opt);
567
+ return items.map((item) => this.processItemOnOut(item, opt));
498
568
  });
499
569
  }
500
570
  beforeRemoveMany(params, opt) {
@@ -502,9 +572,9 @@ class BaseCore {
502
572
  return this.defaultAfterAndBefore(params, opt);
503
573
  });
504
574
  }
505
- afterRemoveMany(params, opt) {
575
+ afterRemoveMany(items, opt) {
506
576
  return __awaiter(this, void 0, void 0, function* () {
507
- return this.defaultAfterAndBefore(params, opt);
577
+ return items.map((item) => this.processItemOnOut(item, opt));
508
578
  });
509
579
  }
510
580
  onException(params, opt) {
@@ -51,23 +51,23 @@ exports.createApiContext = createApiContext;
51
51
  * @returns {object} A context object with all available cores
52
52
  */
53
53
  const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, function* () {
54
- const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, res, extendContext, getCoreContext, getGatewayContext, } = args || {};
55
- const authorization = (req.headers[constants_1.HEADERS.AUTHORIZATION] || '').replace('Bearer ', '');
56
- const fingerprint = req.headers[constants_1.HEADERS.FINGERPRINT] || '';
57
- const spaceId = req.headers[constants_1.HEADERS.SPACE_ID];
58
- const apiKey = req.headers[constants_1.HEADERS.API_KEY];
59
- const managementApiKey = req.headers[constants_1.HEADERS.MANAGEMENT_API_KEY];
60
- const accountId = req.headers[constants_1.HEADERS.ACCOUNT_ID];
61
- const roleId = req.headers[constants_1.HEADERS.ROLE_ID];
62
- const userId = req.headers[constants_1.HEADERS.USER_ID];
63
- const userAgent = req.headers[constants_1.HEADERS.USER_AGENT];
64
- const referer = req.headers[constants_1.HEADERS.REFERER];
65
- const ipAddress = req.headers[constants_1.HEADERS.IP_ADDRESS] || req.connection.remoteAddress;
66
- const acceptLanguage = req.headers[constants_1.HEADERS.ACCEPT_LANGUAGE];
67
- const languages = (0, utils_1.extractLanguages)(acceptLanguage);
68
- const requestedLang = req.headers[constants_1.HEADERS.REQUESTED_LANGUAGE] || (languages === null || languages === void 0 ? void 0 : languages[0]) || 'en';
54
+ const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, res, extendContext, getCoreContext, getGatewayContext, authorizationToken, } = args || {};
69
55
  const headers = req.headers || { noHeadersSetup: true };
70
56
  const cookies = req.cookies || { noCookiesSetup: true };
57
+ const authorization = (headers[constants_1.HEADERS.AUTHORIZATION] || authorizationToken || '').replace('Bearer ', '');
58
+ const fingerprint = headers[constants_1.HEADERS.FINGERPRINT] || '';
59
+ const spaceId = headers[constants_1.HEADERS.SPACE_ID];
60
+ const apiKey = headers[constants_1.HEADERS.API_KEY];
61
+ const managementApiKey = headers[constants_1.HEADERS.MANAGEMENT_API_KEY];
62
+ const userAgent = headers[constants_1.HEADERS.USER_AGENT];
63
+ const referer = headers[constants_1.HEADERS.REFERER];
64
+ const ipAddress = headers[constants_1.HEADERS.IP_ADDRESS] || req.connection.remoteAddress;
65
+ const acceptLanguage = headers[constants_1.HEADERS.ACCEPT_LANGUAGE];
66
+ const languages = (0, utils_1.extractLanguages)(acceptLanguage);
67
+ const requestedLang = headers[constants_1.HEADERS.REQUESTED_LANGUAGE] || (languages === null || languages === void 0 ? void 0 : languages[0]) || 'en';
68
+ // const accountId = headers[HEADERS.ACCOUNT_ID];
69
+ // const roleId = headers[HEADERS.ROLE_ID];
70
+ // const userId = headers[HEADERS.USER_ID];
71
71
  const requestId = (0, uuid_1.v4)();
72
72
  const db = new Database_1.Database({
73
73
  knexConfig,
@@ -85,13 +85,14 @@ const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, functio
85
85
  requestedLang,
86
86
  authorization,
87
87
  fingerprint,
88
- accountId,
89
- roleId,
90
- userId,
88
+ // accountId,
89
+ // roleId,
90
+ // userId,
91
91
  req,
92
92
  res,
93
93
  headers,
94
94
  cookies,
95
+ authorizationToken,
95
96
  };
96
97
  return yield (0, exports.createApiContext)({
97
98
  cores,
@@ -9,5 +9,9 @@ export declare const validateMultipleIntIds: (args: any, opt: BaseCoreActionsInt
9
9
  export declare const validateMultipleUuidIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
10
10
  export declare const validateMultipleTextIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
11
11
  export declare const validateList: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
12
+ export declare const validateGet: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
13
+ export declare const validateRemove: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
14
+ export declare const validateGetMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
15
+ export declare const validateRemoveMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
12
16
  export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
13
17
  export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
@@ -12,10 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.validateUpdate = exports.validateCreate = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
15
+ exports.validateUpdate = exports.validateCreate = exports.validateRemoveMany = exports.validateGetMany = exports.validateRemove = exports.validateGet = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
16
+ const lodash_1 = require("lodash");
17
+ const checkit_1 = __importDefault(require("checkit"));
18
+ const check_types_1 = __importDefault(require("check-types"));
19
+ const is_uuid_1 = __importDefault(require("is-uuid"));
16
20
  const api_helpers_1 = require("@sdflc/api-helpers");
17
21
  const checkItHelpers_1 = require("./checkItHelpers");
18
- const checkit_1 = __importDefault(require("checkit"));
22
+ const constants_1 = require("./constants");
19
23
  const rulesSingleIntId = new checkit_1.default({
20
24
  id: [
21
25
  {
@@ -62,6 +66,20 @@ const rulesMultipleIntIds = new checkit_1.default({
62
66
  rule: 'array',
63
67
  message: 'IDs should be an array of integer',
64
68
  },
69
+ {
70
+ rule: (values) => {
71
+ const opResult = new api_helpers_1.OpResult();
72
+ (0, lodash_1.castArray)(values).forEach((value, idx) => {
73
+ if (!check_types_1.default.integer(value)) {
74
+ opResult.addError('ids', `The ids[${idx}] should be an integer`);
75
+ }
76
+ });
77
+ if (opResult.hasErrors()) {
78
+ opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
79
+ throw opResult;
80
+ }
81
+ },
82
+ },
65
83
  ],
66
84
  });
67
85
  const rulesMultipleUuidIds = new checkit_1.default({
@@ -74,6 +92,20 @@ const rulesMultipleUuidIds = new checkit_1.default({
74
92
  rule: 'array',
75
93
  message: 'IDs should be an array of UUIDs',
76
94
  },
95
+ {
96
+ rule: (values) => {
97
+ const opResult = new api_helpers_1.OpResult();
98
+ (0, lodash_1.castArray)(values).forEach((value, idx) => {
99
+ if (!is_uuid_1.default.v4(value)) {
100
+ opResult.addError('ids', `The ids[${idx}] should be a UUID of version 4`);
101
+ }
102
+ });
103
+ if (opResult.hasErrors()) {
104
+ opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
105
+ throw opResult;
106
+ }
107
+ },
108
+ },
77
109
  ],
78
110
  });
79
111
  const rulesMultipleTextIds = new checkit_1.default({
@@ -86,6 +118,20 @@ const rulesMultipleTextIds = new checkit_1.default({
86
118
  rule: 'array',
87
119
  message: 'IDs should be an array of strings',
88
120
  },
121
+ {
122
+ rule: (values) => {
123
+ const opResult = new api_helpers_1.OpResult();
124
+ (0, lodash_1.castArray)(values).forEach((value, idx) => {
125
+ if (!check_types_1.default.string(value)) {
126
+ opResult.addError('ids', `The ids[${idx}] should be a string`);
127
+ }
128
+ });
129
+ if (opResult.hasErrors()) {
130
+ opResult.setCode(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED);
131
+ throw opResult;
132
+ }
133
+ },
134
+ },
89
135
  ],
90
136
  });
91
137
  const shouldHaveParams = (args) => {
@@ -166,6 +212,56 @@ const validateList = ({ rules }) =>
166
212
  return [true, {}];
167
213
  });
168
214
  exports.validateList = validateList;
215
+ const validateGet = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
216
+ const idType = opt.core.getIdType();
217
+ let rules = null;
218
+ switch (idType) {
219
+ case constants_1.ID_TYPES.INT:
220
+ rules = rulesSingleIntId;
221
+ break;
222
+ case constants_1.ID_TYPES.UUID:
223
+ rules = rulesSingleUuidId;
224
+ break;
225
+ case constants_1.ID_TYPES.TEXT:
226
+ rules = rulesSingleTextId;
227
+ break;
228
+ }
229
+ if (!rules) {
230
+ return [true, {}];
231
+ }
232
+ const [result] = rules.validateSync(args);
233
+ if (result) {
234
+ return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
235
+ }
236
+ return [true, {}];
237
+ });
238
+ exports.validateGet = validateGet;
239
+ exports.validateRemove = exports.validateGet;
240
+ const validateGetMany = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
241
+ const idType = opt.core.getIdType();
242
+ let rules = null;
243
+ switch (idType) {
244
+ case constants_1.ID_TYPES.INT:
245
+ rules = rulesMultipleIntIds;
246
+ break;
247
+ case constants_1.ID_TYPES.UUID:
248
+ rules = rulesMultipleUuidIds;
249
+ break;
250
+ case constants_1.ID_TYPES.TEXT:
251
+ rules = rulesMultipleTextIds;
252
+ break;
253
+ }
254
+ if (!rules) {
255
+ return [true, {}];
256
+ }
257
+ const [result] = rules.validateSync(args);
258
+ if (result) {
259
+ return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
260
+ }
261
+ return [true, {}];
262
+ });
263
+ exports.validateGetMany = validateGetMany;
264
+ exports.validateRemoveMany = exports.validateGetMany;
169
265
  const validateCreate = ({ rules }) =>
170
266
  // eslint-disable-next-line
171
267
  (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
@@ -4,7 +4,13 @@ declare const ORDER_BYS: {
4
4
  DESC: string;
5
5
  };
6
6
  declare const HEADERS: any;
7
+ declare enum ID_TYPES {
8
+ UNKNOWN = 0,
9
+ INT = 1,
10
+ UUID = 2,
11
+ TEXT = 3
12
+ }
7
13
  declare const ID_FIELD: any;
8
14
  declare const DEFAULT_ORDER_NO = "10000000";
9
15
  declare const DEFAULT_ORDER_NO_STEP = "1000";
10
- export { ID_FIELD, FIELDS, ORDER_BYS, HEADERS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP };
16
+ export { ID_FIELD, FIELDS, ORDER_BYS, HEADERS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, ID_TYPES };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_ORDER_NO_STEP = exports.DEFAULT_ORDER_NO = exports.HEADERS = exports.ORDER_BYS = exports.FIELDS = exports.ID_FIELD = void 0;
3
+ exports.ID_TYPES = exports.DEFAULT_ORDER_NO_STEP = exports.DEFAULT_ORDER_NO = exports.HEADERS = exports.ORDER_BYS = exports.FIELDS = exports.ID_FIELD = void 0;
4
4
  const FIELDS = {
5
5
  ID: 'id',
6
6
  STATUS: 'status',
@@ -44,8 +44,18 @@ const HEADERS = {
44
44
  IP_ADDRESS: 'x-forwarded-for',
45
45
  ACCEPT_LANGUAGE: 'accept-language',
46
46
  REQUESTED_LANGUAGE: 'x-lang',
47
+ CONTENT_TYPE: 'content-type',
48
+ CONTENT_LENGTH: 'content-length',
47
49
  };
48
50
  exports.HEADERS = HEADERS;
51
+ var ID_TYPES;
52
+ (function (ID_TYPES) {
53
+ ID_TYPES[ID_TYPES["UNKNOWN"] = 0] = "UNKNOWN";
54
+ ID_TYPES[ID_TYPES["INT"] = 1] = "INT";
55
+ ID_TYPES[ID_TYPES["UUID"] = 2] = "UUID";
56
+ ID_TYPES[ID_TYPES["TEXT"] = 3] = "TEXT";
57
+ })(ID_TYPES || (ID_TYPES = {}));
58
+ exports.ID_TYPES = ID_TYPES;
49
59
  const ID_FIELD = FIELDS.ID;
50
60
  exports.ID_FIELD = ID_FIELD;
51
61
  const DEFAULT_ORDER_NO = '10000000';
@@ -0,0 +1,2 @@
1
+ import { DownloadFileArgs } from './interfaces';
2
+ export declare const downloadFile: (args: DownloadFileArgs) => Promise<any>;
@@ -0,0 +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();
package/build/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export * from './resolversHelpers';
18
18
  export * from './userToken';
19
19
  export * from './passwordHelpers';
20
20
  export * from './commonValidators';
21
+ export * from './downloadHelpers';
package/build/index.js CHANGED
@@ -34,3 +34,4 @@ __exportStar(require("./resolversHelpers"), exports);
34
34
  __exportStar(require("./userToken"), exports);
35
35
  __exportStar(require("./passwordHelpers"), exports);
36
36
  __exportStar(require("./commonValidators"), exports);
37
+ __exportStar(require("./downloadHelpers"), exports);
@@ -5,6 +5,7 @@ import { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
5
5
  import { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
6
6
  import { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
7
7
  import { ApiContext } from './ApiContext';
8
+ import { ID_TYPES } from '../constants';
8
9
  export interface BaseCorePropsInterface {
9
10
  /**
10
11
  * Application API context with all necessary information about request
@@ -28,4 +29,6 @@ export interface BaseCorePropsInterface {
28
29
  interserviceApiKey?: string;
29
30
  jwtSecret?: string;
30
31
  verifyTokenArgs?: VerifyUserTokenArgs;
32
+ hasOrderNo?: boolean;
33
+ idType?: ID_TYPES;
31
34
  }
@@ -0,0 +1,6 @@
1
+ export interface DownloadFileArgs {
2
+ url: string;
3
+ fileName: string;
4
+ folder?: string;
5
+ stream?: any;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,25 +1,26 @@
1
1
  export { CacheInterface } from './CacheInterface';
2
- export { LoaderInterface } from './LoaderInterface';
3
- export { BaseGatewayPropsInterface } from './BaseGatewayPropsInterface';
4
- export { ListArgsInterface } from './ListArgsInterface';
5
- export { SortItemInterface } from './SortItemInterface';
6
- export { PaginationInterface } from './PaginationInterface';
7
- export { BaseCorePropsInterface } from './BaseCorePropsInterface';
8
- export { CoreActionInterface } from './CoreActionInterface';
9
- export { ApiContextInterface } from './ApiContextInterface';
10
- export { ApiContext } from './ApiContext';
11
- export { DbFieldAddDefaultInterface } from './DbFieldAddDefaultInterface';
12
- export { BuildConfigOptions } from './BuildConfigOptions';
13
- export { DatabaseOptions } from './DatabaseOptions';
14
- export { DatabaseReadInterface } from './DatabaseReadInterface';
15
- export { BuildDefaultResolvers } from './BuildDefaultResolversOptions';
16
- export { BaseCoreValidatorsInterface } from './BaseCoreValidatorsInterface';
17
- export { UserTokenParams } from './UserTokenParams';
18
- export { CreateUserTokenArgs } from './CreateUserTokenArgs';
19
- export { VerifyUserTokenArgs } from './VerifyUserTokenArgs';
20
- export { BaseCoreActionsInterface } from './BaseCoreActionsInterface';
21
- export { BaseCoreDoingWhatInterface } from './BaseCoreDoingWhatInterface';
22
- export { JwtTokenSecretAndSettings } from './JwtTokenSecretAndSettings';
23
- export { CommonValidatorArgs } from './CommonValidatorArgs';
24
- export { CreateUserTokenResult } from './CreateUserTokenResult';
25
- export { ExtractCredentialsArgs } from './ExtractCredentialsArgs';
2
+ export * from './LoaderInterface';
3
+ export * from './BaseGatewayPropsInterface';
4
+ export * from './ListArgsInterface';
5
+ export * from './SortItemInterface';
6
+ export * from './PaginationInterface';
7
+ export * from './BaseCorePropsInterface';
8
+ export * from './CoreActionInterface';
9
+ export * from './ApiContextInterface';
10
+ export * from './ApiContext';
11
+ export * from './DbFieldAddDefaultInterface';
12
+ export * from './BuildConfigOptions';
13
+ export * from './DatabaseOptions';
14
+ export * from './DatabaseReadInterface';
15
+ export * from './BuildDefaultResolversOptions';
16
+ export * from './BaseCoreValidatorsInterface';
17
+ export * from './UserTokenParams';
18
+ export * from './CreateUserTokenArgs';
19
+ export * from './VerifyUserTokenArgs';
20
+ export * from './BaseCoreActionsInterface';
21
+ export * from './BaseCoreDoingWhatInterface';
22
+ export * from './JwtTokenSecretAndSettings';
23
+ export * from './CommonValidatorArgs';
24
+ export * from './CreateUserTokenResult';
25
+ export * from './ExtractCredentialsArgs';
26
+ export * from './DownloadFileArgs';
@@ -1,2 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./LoaderInterface"), exports);
18
+ __exportStar(require("./BaseGatewayPropsInterface"), exports);
19
+ __exportStar(require("./ListArgsInterface"), exports);
20
+ __exportStar(require("./SortItemInterface"), exports);
21
+ __exportStar(require("./PaginationInterface"), exports);
22
+ __exportStar(require("./BaseCorePropsInterface"), exports);
23
+ __exportStar(require("./CoreActionInterface"), exports);
24
+ __exportStar(require("./ApiContextInterface"), exports);
25
+ __exportStar(require("./ApiContext"), exports);
26
+ __exportStar(require("./DbFieldAddDefaultInterface"), exports);
27
+ __exportStar(require("./BuildConfigOptions"), exports);
28
+ __exportStar(require("./DatabaseOptions"), exports);
29
+ __exportStar(require("./DatabaseReadInterface"), exports);
30
+ __exportStar(require("./BuildDefaultResolversOptions"), exports);
31
+ __exportStar(require("./BaseCoreValidatorsInterface"), exports);
32
+ __exportStar(require("./UserTokenParams"), exports);
33
+ __exportStar(require("./CreateUserTokenArgs"), exports);
34
+ __exportStar(require("./VerifyUserTokenArgs"), exports);
35
+ __exportStar(require("./BaseCoreActionsInterface"), exports);
36
+ __exportStar(require("./BaseCoreDoingWhatInterface"), exports);
37
+ __exportStar(require("./JwtTokenSecretAndSettings"), exports);
38
+ __exportStar(require("./CommonValidatorArgs"), exports);
39
+ __exportStar(require("./CreateUserTokenResult"), exports);
40
+ __exportStar(require("./ExtractCredentialsArgs"), exports);
41
+ __exportStar(require("./DownloadFileArgs"), exports);
@@ -18,11 +18,17 @@ const camelResponse = (result) => {
18
18
  return (0, utils_1.camelKeys)(result);
19
19
  };
20
20
  const buildKnexConfig = (dirName, appConfig) => {
21
- const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, } = appConfig;
21
+ const { dbType, dbHost, dbPort, dbName, dbSchema, dbUser, dbPassword, debug, nodeEnv, migrationsTemplateFileName, migrationsFolder, migrationsTable, useSchemaForMigrationsTable, seedsFolder, seedsFolderDev, seedsFolderProd, wrapIdentifierOverrideMap, } = appConfig;
22
22
  const sharedConfig = {
23
23
  client: dbType || 'pg',
24
24
  postProcessResponse: camelResponse,
25
- wrapIdentifier: (value, origImpl) => (value === '*' ? origImpl(value) : origImpl((0, lodash_1.snakeCase)(value))),
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
+ },
26
32
  connection: {
27
33
  host: dbHost,
28
34
  port: dbPort,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.60",
3
+ "version": "1.0.61",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -27,10 +27,12 @@
27
27
  "@sdflc/utils": "^1.0.22",
28
28
  "bcrypt": "^5.1.0",
29
29
  "bluebird": "^3.7.2",
30
+ "check-types": "^11.2.2",
30
31
  "checkit": "^0.7.0",
31
32
  "dataloader": "^2.1.0",
32
33
  "dayjs": "^1.11.6",
33
34
  "dotenv-safe": "^8.2.0",
35
+ "is-uuid": "^1.0.2",
34
36
  "json-stable-stringify": "^1.0.1",
35
37
  "jsonwebtoken": "^8.5.1",
36
38
  "knex": "^2.3.0",
@@ -42,7 +44,9 @@
42
44
  "devDependencies": {
43
45
  "@types/bcrypt": "^5.0.0",
44
46
  "@types/bluebird": "^3.5.37",
47
+ "@types/check-types": "^7.3.4",
45
48
  "@types/dotenv-safe": "^8.1.2",
49
+ "@types/is-uuid": "^1.0.0",
46
50
  "@types/jest": "^29.2.0",
47
51
  "@types/json-stable-stringify": "^1.0.34",
48
52
  "@types/jsonwebtoken": "^8.5.9",