@sdflc/backend-helpers 1.0.110 → 1.0.111

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.
package/build/BaseCore.js CHANGED
@@ -131,6 +131,7 @@ class BaseCore {
131
131
  async checkResult(args) {
132
132
  const { hasTransaction, result, sameRequest, doingWhat, skipCheckResult } = args;
133
133
  if (sameRequest) {
134
+ this.logger.debug(`Skip result check due to same request flag on ${doingWhat}`);
134
135
  return;
135
136
  }
136
137
  if (hasTransaction) {
@@ -696,7 +697,7 @@ class BaseCore {
696
697
  addRemovedModifierToFields(fields) {
697
698
  const obj = {};
698
699
  if (!fields) {
699
- this.logger.log(`The 'addRemovedModifierToFields' method expected its fields parameter to be a field name or an array of table field names but got:`, fields);
700
+ this.logger.warn(`The 'addRemovedModifierToFields' method expected its fields parameter to be a field name or an array of table field names but got:`, fields);
700
701
  return obj;
701
702
  }
702
703
  (0, lodash_1.castArray)(fields).forEach((field) => {
@@ -428,11 +428,12 @@ class BaseGateway {
428
428
  if (hasSpace) {
429
429
  skipFields.push(constants_1.FIELDS.SPACE_ID);
430
430
  }
431
+ const idField = this.getIdFieldUpdateRemove();
431
432
  for (let idx = 0, len = objects.length; idx < len; ++idx) {
432
433
  const object = objects[idx];
433
434
  objects[idx] = await this.transformOnSet(object);
434
- if (objects[idx][this.getIdField()] == null) {
435
- objects[idx][this.getIdField()] = await this.generateId(object);
435
+ if (objects[idx][idField] == null) {
436
+ objects[idx][idField] = await this.generateId(object);
436
437
  }
437
438
  }
438
439
  const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
@@ -442,7 +443,7 @@ class BaseGateway {
442
443
  const items = await this.getBuilder()
443
444
  .insert(chunks[idx])
444
445
  .returning(this.config.returnFields)
445
- .onConflict(this.config.setFields || this.getIdField())
446
+ .onConflict(this.config.setFields || idField)
446
447
  .merge((0, lodash_1.pullAll)(fields, skipFields));
447
448
  result.push(...items);
448
449
  }
@@ -15,3 +15,4 @@ export declare const validateGetMany: (args: any, opt: BaseCoreActionsInterface)
15
15
  export declare const validateRemoveMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
16
16
  export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
17
17
  export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
18
+ export declare const validateSet: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- 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;
6
+ exports.validateSet = 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;
7
7
  const lodash_1 = require("lodash");
8
8
  const checkit_1 = __importDefault(require("checkit"));
9
9
  const check_types_1 = __importDefault(require("check-types"));
@@ -309,3 +309,16 @@ const validateUpdate = ({ rules }) => async (args, opt) => {
309
309
  return [true, {}];
310
310
  };
311
311
  exports.validateUpdate = validateUpdate;
312
+ const validateSet = ({ rules }) => async (args, opt) => {
313
+ const { params } = args || {};
314
+ const [paramsCheck] = (0, exports.shouldHaveParams)(params);
315
+ if (paramsCheck !== true) {
316
+ return [paramsCheck, {}];
317
+ }
318
+ const [result] = rules.validateSync(params);
319
+ if (result) {
320
+ return [(0, checkItHelpers_1.createErrorOnCheckError)(result), {}];
321
+ }
322
+ return [true, {}];
323
+ };
324
+ exports.validateSet = validateSet;
@@ -125,6 +125,7 @@ class BaseCore {
125
125
  async checkResult(args) {
126
126
  const { hasTransaction, result, sameRequest, doingWhat, skipCheckResult } = args;
127
127
  if (sameRequest) {
128
+ this.logger.debug(`Skip result check due to same request flag on ${doingWhat}`);
128
129
  return;
129
130
  }
130
131
  if (hasTransaction) {
@@ -690,7 +691,7 @@ class BaseCore {
690
691
  addRemovedModifierToFields(fields) {
691
692
  const obj = {};
692
693
  if (!fields) {
693
- this.logger.log(`The 'addRemovedModifierToFields' method expected its fields parameter to be a field name or an array of table field names but got:`, fields);
694
+ this.logger.warn(`The 'addRemovedModifierToFields' method expected its fields parameter to be a field name or an array of table field names but got:`, fields);
694
695
  return obj;
695
696
  }
696
697
  castArray(fields).forEach((field) => {
@@ -422,11 +422,12 @@ class BaseGateway {
422
422
  if (hasSpace) {
423
423
  skipFields.push(FIELDS.SPACE_ID);
424
424
  }
425
+ const idField = this.getIdFieldUpdateRemove();
425
426
  for (let idx = 0, len = objects.length; idx < len; ++idx) {
426
427
  const object = objects[idx];
427
428
  objects[idx] = await this.transformOnSet(object);
428
- if (objects[idx][this.getIdField()] == null) {
429
- objects[idx][this.getIdField()] = await this.generateId(object);
429
+ if (objects[idx][idField] == null) {
430
+ objects[idx][idField] = await this.generateId(object);
430
431
  }
431
432
  }
432
433
  const fields = Array.isArray(mergeFields) ? mergeFields : Object.keys(objects[0]);
@@ -436,7 +437,7 @@ class BaseGateway {
436
437
  const items = await this.getBuilder()
437
438
  .insert(chunks[idx])
438
439
  .returning(this.config.returnFields)
439
- .onConflict(this.config.setFields || this.getIdField())
440
+ .onConflict(this.config.setFields || idField)
440
441
  .merge(pullAll(fields, skipFields));
441
442
  result.push(...items);
442
443
  }
@@ -15,3 +15,4 @@ export declare const validateGetMany: (args: any, opt: BaseCoreActionsInterface)
15
15
  export declare const validateRemoveMany: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
16
16
  export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
17
17
  export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
18
+ export declare const validateSet: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
@@ -289,3 +289,15 @@ export const validateUpdate = ({ rules }) => async (args, opt) => {
289
289
  }
290
290
  return [true, {}];
291
291
  };
292
+ export const validateSet = ({ rules }) => async (args, opt) => {
293
+ const { params } = args || {};
294
+ const [paramsCheck] = shouldHaveParams(params);
295
+ if (paramsCheck !== true) {
296
+ return [paramsCheck, {}];
297
+ }
298
+ const [result] = rules.validateSync(params);
299
+ if (result) {
300
+ return [createErrorOnCheckError(result), {}];
301
+ }
302
+ return [true, {}];
303
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.110",
3
+ "version": "1.0.111",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "type": "commonjs",
6
6
  "exports": {