@sdflc/backend-helpers 1.0.13 → 1.0.14

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
@@ -524,7 +524,7 @@ var BaseCore = /** @class */ (function () {
524
524
  return [2 /*return*/, this.runAction({
525
525
  args: args,
526
526
  validate: this.validators.set,
527
- accessRights: [ACCESS_RIGHTS.UPDATE, ACCESS_RIGHTS.UPDATE],
527
+ accessRights: [ACCESS_RIGHTS.CREATE, ACCESS_RIGHTS.UPDATE],
528
528
  action: function (args) { return __awaiter(_this, void 0, void 0, function () {
529
529
  var params, object, items, result;
530
530
  var _a;
@@ -53,6 +53,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
53
53
  exports.BaseGateway = void 0;
54
54
  var dataCache_1 = require("./dataCache");
55
55
  var constants_1 = __importDefault(require("./constants"));
56
+ var lodash_1 = require("lodash");
56
57
  var ID_FIELD = constants_1.default.ID_FIELD;
57
58
  var defaultIdGenerator = function () {
58
59
  return undefined;
@@ -299,38 +300,21 @@ var BaseGateway = /** @class */ (function () {
299
300
  */
300
301
  BaseGateway.prototype.set = function (params) {
301
302
  return __awaiter(this, void 0, void 0, function () {
302
- var results, idField, idx, len, item, items, items;
303
- var _a;
304
- return __generator(this, function (_b) {
305
- switch (_b.label) {
303
+ var results, idField, items;
304
+ return __generator(this, function (_a) {
305
+ switch (_a.label) {
306
306
  case 0:
307
- if (!Array.isArray(params)) {
308
- params = [params];
309
- }
310
307
  results = [];
311
308
  idField = this.getIdField();
312
- idx = 0, len = params.length;
313
- _b.label = 1;
309
+ return [4 /*yield*/, this.getBuilder()
310
+ .insert(lodash_1.castArray(params))
311
+ .returning(this.returnFields)
312
+ .onConflict(this.config.setFields || idField)
313
+ .merge()];
314
314
  case 1:
315
- if (!(idx < len)) return [3 /*break*/, 6];
316
- item = params[idx];
317
- if (!(item === null || item === void 0 ? void 0 : item[idField])) return [3 /*break*/, 3];
318
- return [4 /*yield*/, this.update((_a = {},
319
- _a[idField] = item === null || item === void 0 ? void 0 : item[idField],
320
- _a), item)];
321
- case 2:
322
- items = _b.sent();
323
- results.push.apply(results, items);
324
- return [3 /*break*/, 5];
325
- case 3: return [4 /*yield*/, this.create(item)];
326
- case 4:
327
- items = _b.sent();
315
+ items = _a.sent();
328
316
  results.push.apply(results, items);
329
- _b.label = 5;
330
- case 5:
331
- ++idx;
332
- return [3 /*break*/, 1];
333
- case 6: return [2 /*return*/, results];
317
+ return [2 /*return*/, results];
334
318
  }
335
319
  });
336
320
  });
@@ -6,6 +6,7 @@ export interface BaseGatewayInterface {
6
6
  db: Database;
7
7
  table?: string;
8
8
  idField?: string;
9
+ setFields?: string[] | string;
9
10
  selectFields?: any[];
10
11
  defaultSorting?: SortItemInterface[];
11
12
  filter?(query: any, params: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
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",