@nextage/nx-frame-be 1.0.35 → 1.0.36

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 (31) hide show
  1. package/build/common/base/__test__/base.model.test.js +31 -23
  2. package/build/common/base/base.controller.d.ts +0 -26
  3. package/build/common/base/base.interfaces.d.ts +0 -26
  4. package/build/common/base/base.model.d.ts +0 -27
  5. package/build/common/base/mongo-utils.d.ts +0 -26
  6. package/build/common/base/mongo-utils.js +35 -13
  7. package/build/common/base/sql-utils.js +2 -2
  8. package/build/common/constants.d.ts +1 -3
  9. package/build/common/crypto/crypto.classes.d.ts +0 -2
  10. package/build/common/crypto/crypto.interfaces.d.ts +0 -1
  11. package/build/common/crypto/crypto.utils.d.ts +0 -1
  12. package/build/common/crypto/encryption.plugin.d.ts +0 -28
  13. package/build/common/crypto/encryption.plugin.js +1 -2
  14. package/build/common/express/express.utils.js +3 -4
  15. package/build/common/graphql/__test__/generator.schema.test.js +39 -39
  16. package/build/common/graphql/directives.js +3 -3
  17. package/build/common/graphql/generator copy.js +5 -5
  18. package/build/common/graphql/generator.js +5 -5
  19. package/build/common/graphql/loader.js +4 -4
  20. package/build/common/graphql/utils.js +3 -3
  21. package/build/common/grid-fs/gridfs-base.model.d.ts +0 -27
  22. package/build/common/grid-fs/gridfs.interfaces.d.ts +0 -26
  23. package/build/common/manager/bulk-manager.d.ts +0 -26
  24. package/build/common/manager/crypto-manager.d.ts +0 -1
  25. package/build/common/manager/socket-io-cli-manager.d.ts +0 -1
  26. package/build/common/manager/tunnel-manager.d.ts +0 -1
  27. package/build/common/models/coded-entity.model.js +2 -14
  28. package/build/common/types.d.ts +0 -26
  29. package/build/common/utils.d.ts +0 -3
  30. package/build/common/utils.js +83 -85
  31. package/package.json +5 -5
@@ -202,33 +202,37 @@ it('updates bulk items', () => __awaiter(void 0, void 0, void 0, function* () {
202
202
  expect(foundtems[2].version).toEqual(ce3.version + 1);
203
203
  }));
204
204
  it('adds an array item', () => __awaiter(void 0, void 0, void 0, function* () {
205
- var _g, _h, _j, _k;
205
+ var _a, _b, _c, _d, _e;
206
206
  const { ceItem: ce1 } = yield createItem();
207
+ const initialVersion = (_a = ce1 === null || ce1 === void 0 ? void 0 : ce1.version) !== null && _a !== void 0 ? _a : 0;
207
208
  const updateData = {
208
209
  arrayPath: 'data.items',
209
210
  item: { id: (0, utils_1.uuid)(), value: 100 }
210
211
  };
211
212
  const updatedItem = yield (coded_entity_model_1.ceModel === null || coded_entity_model_1.ceModel === void 0 ? void 0 : coded_entity_model_1.ceModel.addArrayItem(ce1 === null || ce1 === void 0 ? void 0 : ce1.id, updateData, {}, {}));
212
- const itemsLength = ((_h = (_g = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _g === void 0 ? void 0 : _g.items) === null || _h === void 0 ? void 0 : _h.length) || 0;
213
+ const itemsLength = ((_c = (_b = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length) || 0;
213
214
  expect(itemsLength).toEqual(((ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items) || []).length + 1);
214
- expect((_j = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _j === void 0 ? void 0 : _j.items[itemsLength - 1].id).toEqual(updateData.item.id);
215
- expect((_k = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _k === void 0 ? void 0 : _k.items[itemsLength - 1].value).toEqual(updateData.item.value);
215
+ expect((_d = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _d === void 0 ? void 0 : _d.items[itemsLength - 1].id).toEqual(updateData.item.id);
216
+ expect((_e = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _e === void 0 ? void 0 : _e.items[itemsLength - 1].value).toEqual(updateData.item.value);
217
+ expect(updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.version).toEqual(initialVersion + 1);
216
218
  }));
217
219
  it('updates an array item', () => __awaiter(void 0, void 0, void 0, function* () {
218
- var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
220
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
219
221
  const { ceItem: ce1 } = yield createItem();
222
+ const initialVersion = (_a = ce1 === null || ce1 === void 0 ? void 0 : ce1.version) !== null && _a !== void 0 ? _a : 0;
220
223
  const updateData = {
221
224
  arrayPath: 'data.items',
222
225
  arrayFilter: { id: ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id },
223
226
  item: { id: ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id, value: 50, newattr: 'AAA' }
224
227
  };
225
228
  let updatedItem = yield (coded_entity_model_1.ceModel === null || coded_entity_model_1.ceModel === void 0 ? void 0 : coded_entity_model_1.ceModel.updateArrayItem(ce1 === null || ce1 === void 0 ? void 0 : ce1.id, updateData, {}, {}));
226
- let itemsLength = ((_m = (_l = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _l === void 0 ? void 0 : _l.items) === null || _m === void 0 ? void 0 : _m.length) || 0;
229
+ let itemsLength = ((_c = (_b = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length) || 0;
227
230
  expect(itemsLength).toEqual(((ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items) || []).length);
228
- expect((_o = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _o === void 0 ? void 0 : _o.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
229
- expect((_p = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _p === void 0 ? void 0 : _p.items[1].id).toEqual(updateData.item.id);
230
- expect((_q = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _q === void 0 ? void 0 : _q.items[1].value).toEqual(updateData.item.value);
231
- expect((_r = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _r === void 0 ? void 0 : _r.items[1].newattr).toEqual(updateData.item.newattr);
231
+ expect((_d = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _d === void 0 ? void 0 : _d.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
232
+ expect((_e = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _e === void 0 ? void 0 : _e.items[1].id).toEqual(updateData.item.id);
233
+ expect((_f = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _f === void 0 ? void 0 : _f.items[1].value).toEqual(updateData.item.value);
234
+ expect((_g = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _g === void 0 ? void 0 : _g.items[1].newattr).toEqual(updateData.item.newattr);
235
+ expect(updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.version).toEqual(initialVersion + 1);
232
236
  const updateData2 = {
233
237
  arrayPath: 'data.items',
234
238
  partial: true,
@@ -236,11 +240,12 @@ it('updates an array item', () => __awaiter(void 0, void 0, void 0, function* ()
236
240
  item: { value: 51, newattr: 'AAA' }
237
241
  };
238
242
  updatedItem = yield (coded_entity_model_1.ceModel === null || coded_entity_model_1.ceModel === void 0 ? void 0 : coded_entity_model_1.ceModel.updateArrayItem(ce1 === null || ce1 === void 0 ? void 0 : ce1.id, updateData2, {}, {}));
239
- itemsLength = ((_t = (_s = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _s === void 0 ? void 0 : _s.items) === null || _t === void 0 ? void 0 : _t.length) || 0;
243
+ itemsLength = ((_j = (_h = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _h === void 0 ? void 0 : _h.items) === null || _j === void 0 ? void 0 : _j.length) || 0;
240
244
  expect(itemsLength).toEqual(((ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items) || []).length);
241
- expect((_u = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _u === void 0 ? void 0 : _u.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
242
- expect((_v = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _v === void 0 ? void 0 : _v.items[1].value).toEqual(updateData2.item.value);
243
- expect((_w = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _w === void 0 ? void 0 : _w.items[1].newattr).toEqual(updateData2.item.newattr);
245
+ expect((_k = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _k === void 0 ? void 0 : _k.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
246
+ expect((_l = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _l === void 0 ? void 0 : _l.items[1].value).toEqual(updateData2.item.value);
247
+ expect((_m = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _m === void 0 ? void 0 : _m.items[1].newattr).toEqual(updateData2.item.newattr);
248
+ expect(updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.version).toEqual(initialVersion + 2);
244
249
  const updateData3 = {
245
250
  arrayPath: 'data.items',
246
251
  updateAttr: 'newattr',
@@ -248,25 +253,28 @@ it('updates an array item', () => __awaiter(void 0, void 0, void 0, function* ()
248
253
  item: { value: 55, newattr: 'BBB' }
249
254
  };
250
255
  updatedItem = yield (coded_entity_model_1.ceModel === null || coded_entity_model_1.ceModel === void 0 ? void 0 : coded_entity_model_1.ceModel.updateArrayItem(ce1 === null || ce1 === void 0 ? void 0 : ce1.id, updateData3, {}, {}));
251
- itemsLength = ((_y = (_x = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _x === void 0 ? void 0 : _x.items) === null || _y === void 0 ? void 0 : _y.length) || 0;
256
+ itemsLength = ((_p = (_o = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _o === void 0 ? void 0 : _o.items) === null || _p === void 0 ? void 0 : _p.length) || 0;
252
257
  expect(itemsLength).toEqual(((ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items) || []).length);
253
- expect((_z = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _z === void 0 ? void 0 : _z.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
254
- expect((_0 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _0 === void 0 ? void 0 : _0.items[1].value).toEqual(updateData2.item.value);
255
- expect((_1 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _1 === void 0 ? void 0 : _1.items[1].newattr).toEqual(updateData3.item.newattr);
258
+ expect((_q = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _q === void 0 ? void 0 : _q.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
259
+ expect((_r = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _r === void 0 ? void 0 : _r.items[1].value).toEqual(updateData2.item.value);
260
+ expect((_s = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _s === void 0 ? void 0 : _s.items[1].newattr).toEqual(updateData3.item.newattr);
261
+ expect(updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.version).toEqual(initialVersion + 3);
256
262
  }));
257
263
  it('removes an array item', () => __awaiter(void 0, void 0, void 0, function* () {
258
- var _2, _3, _4, _5, _6;
264
+ var _a, _b, _c, _d, _e, _f;
259
265
  const { ceItem: ce1 } = yield createItem();
266
+ const initialVersion = (_a = ce1 === null || ce1 === void 0 ? void 0 : ce1.version) !== null && _a !== void 0 ? _a : 0;
260
267
  const updateData = {
261
268
  arrayPath: 'data.items',
262
269
  item: (0, utils_1.clone)(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1])
263
270
  };
264
271
  let updatedItem = yield (coded_entity_model_1.ceModel === null || coded_entity_model_1.ceModel === void 0 ? void 0 : coded_entity_model_1.ceModel.removeArrayItem(ce1 === null || ce1 === void 0 ? void 0 : ce1.id, updateData, {}, {}));
265
- let itemsLength = ((_3 = (_2 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _2 === void 0 ? void 0 : _2.items) === null || _3 === void 0 ? void 0 : _3.length) || 0;
272
+ let itemsLength = ((_c = (_b = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length) || 0;
266
273
  expect(itemsLength).toEqual(((ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items) || []).length - 1);
267
- expect((_4 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _4 === void 0 ? void 0 : _4.items[1].id).not.toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
268
- expect((_5 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _5 === void 0 ? void 0 : _5.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[2].id);
269
- (_6 = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _6 === void 0 ? void 0 : _6.items.forEach(di => {
274
+ expect((_d = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _d === void 0 ? void 0 : _d.items[1].id).not.toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
275
+ expect((_e = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _e === void 0 ? void 0 : _e.items[1].id).toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[2].id);
276
+ expect(updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.version).toEqual(initialVersion + 1);
277
+ (_f = updatedItem === null || updatedItem === void 0 ? void 0 : updatedItem.data) === null || _f === void 0 ? void 0 : _f.items.forEach(di => {
270
278
  expect(di.id).not.toEqual(ce1 === null || ce1 === void 0 ? void 0 : ce1.data.items[1].id);
271
279
  });
272
280
  }));
@@ -1,29 +1,3 @@
1
- /// <reference types="mongoose/types/aggregate" />
2
- /// <reference types="mongoose/types/callback" />
3
- /// <reference types="mongoose/types/collection" />
4
- /// <reference types="mongoose/types/connection" />
5
- /// <reference types="mongoose/types/cursor" />
6
- /// <reference types="mongoose/types/document" />
7
- /// <reference types="mongoose/types/error" />
8
- /// <reference types="mongoose/types/expressions" />
9
- /// <reference types="mongoose/types/helpers" />
10
- /// <reference types="mongoose/types/middlewares" />
11
- /// <reference types="mongoose/types/indexes" />
12
- /// <reference types="mongoose/types/models" />
13
- /// <reference types="mongoose/types/mongooseoptions" />
14
- /// <reference types="mongoose/types/pipelinestage" />
15
- /// <reference types="mongoose/types/populate" />
16
- /// <reference types="mongoose/types/query" />
17
- /// <reference types="mongoose/types/schemaoptions" />
18
- /// <reference types="mongoose/types/session" />
19
- /// <reference types="mongoose/types/types" />
20
- /// <reference types="mongoose/types/utility" />
21
- /// <reference types="mongoose/types/validation" />
22
- /// <reference types="mongoose/types/virtuals" />
23
- /// <reference types="mongoose/types/schematypes" />
24
- /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose/types/inferhydrateddoctype" />
26
- /// <reference types="mongoose/types/inferrawdoctype" />
27
1
  import mongoose from 'mongoose';
28
2
  import { NxContext, NxObject } from '../interfaces';
29
3
  import { BaseModel } from './base.model';
@@ -1,29 +1,3 @@
1
- /// <reference types="mongoose/types/aggregate" />
2
- /// <reference types="mongoose/types/callback" />
3
- /// <reference types="mongoose/types/collection" />
4
- /// <reference types="mongoose/types/connection" />
5
- /// <reference types="mongoose/types/cursor" />
6
- /// <reference types="mongoose/types/document" />
7
- /// <reference types="mongoose/types/error" />
8
- /// <reference types="mongoose/types/expressions" />
9
- /// <reference types="mongoose/types/helpers" />
10
- /// <reference types="mongoose/types/middlewares" />
11
- /// <reference types="mongoose/types/indexes" />
12
- /// <reference types="mongoose/types/models" />
13
- /// <reference types="mongoose/types/mongooseoptions" />
14
- /// <reference types="mongoose/types/pipelinestage" />
15
- /// <reference types="mongoose/types/populate" />
16
- /// <reference types="mongoose/types/query" />
17
- /// <reference types="mongoose/types/schemaoptions" />
18
- /// <reference types="mongoose/types/session" />
19
- /// <reference types="mongoose/types/types" />
20
- /// <reference types="mongoose/types/utility" />
21
- /// <reference types="mongoose/types/validation" />
22
- /// <reference types="mongoose/types/virtuals" />
23
- /// <reference types="mongoose/types/schematypes" />
24
- /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose/types/inferhydrateddoctype" />
26
- /// <reference types="mongoose/types/inferrawdoctype" />
27
1
  import mongoose from 'mongoose';
28
2
  import { ModelCrudEventType } from '../enums';
29
3
  import { NxObject } from '../interfaces';
@@ -1,30 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="mongoose/types/aggregate" />
3
- /// <reference types="mongoose/types/callback" />
4
- /// <reference types="mongoose/types/collection" />
5
- /// <reference types="mongoose/types/connection" />
6
- /// <reference types="mongoose/types/cursor" />
7
- /// <reference types="mongoose/types/document" />
8
- /// <reference types="mongoose/types/error" />
9
- /// <reference types="mongoose/types/expressions" />
10
- /// <reference types="mongoose/types/helpers" />
11
- /// <reference types="mongoose/types/middlewares" />
12
- /// <reference types="mongoose/types/indexes" />
13
- /// <reference types="mongoose/types/models" />
14
- /// <reference types="mongoose/types/mongooseoptions" />
15
- /// <reference types="mongoose/types/pipelinestage" />
16
- /// <reference types="mongoose/types/populate" />
17
- /// <reference types="mongoose/types/query" />
18
- /// <reference types="mongoose/types/schemaoptions" />
19
- /// <reference types="mongoose/types/session" />
20
- /// <reference types="mongoose/types/types" />
21
- /// <reference types="mongoose/types/utility" />
22
- /// <reference types="mongoose/types/validation" />
23
- /// <reference types="mongoose/types/virtuals" />
24
- /// <reference types="mongoose/types/schematypes" />
25
- /// <reference types="mongoose/types/inferschematype" />
26
- /// <reference types="mongoose/types/inferhydrateddoctype" />
27
- /// <reference types="mongoose/types/inferrawdoctype" />
28
1
  import mongoose from 'mongoose';
29
2
  import { EventEmitter } from 'events';
30
3
  import { NxContext, NxObject } from '../interfaces';
@@ -1,29 +1,3 @@
1
- /// <reference types="mongoose/types/aggregate" />
2
- /// <reference types="mongoose/types/callback" />
3
- /// <reference types="mongoose/types/collection" />
4
- /// <reference types="mongoose/types/connection" />
5
- /// <reference types="mongoose/types/cursor" />
6
- /// <reference types="mongoose/types/document" />
7
- /// <reference types="mongoose/types/error" />
8
- /// <reference types="mongoose/types/expressions" />
9
- /// <reference types="mongoose/types/helpers" />
10
- /// <reference types="mongoose/types/middlewares" />
11
- /// <reference types="mongoose/types/indexes" />
12
- /// <reference types="mongoose/types/models" />
13
- /// <reference types="mongoose/types/mongooseoptions" />
14
- /// <reference types="mongoose/types/pipelinestage" />
15
- /// <reference types="mongoose/types/populate" />
16
- /// <reference types="mongoose/types/query" />
17
- /// <reference types="mongoose/types/schemaoptions" />
18
- /// <reference types="mongoose/types/session" />
19
- /// <reference types="mongoose/types/types" />
20
- /// <reference types="mongoose/types/utility" />
21
- /// <reference types="mongoose/types/validation" />
22
- /// <reference types="mongoose/types/virtuals" />
23
- /// <reference types="mongoose/types/schematypes" />
24
- /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose/types/inferhydrateddoctype" />
26
- /// <reference types="mongoose/types/inferrawdoctype" />
27
1
  import mongoose from 'mongoose';
28
2
  import { BaseDBItem } from '../types';
29
3
  import { ModelDef } from './mongo.types';
@@ -3,9 +3,16 @@ 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.isSameId = exports.isValidObjectId = exports.genObjectId = exports.toObjectIds = exports.toObjectId = exports.loadMongoModel = exports.createModel = exports.loadModel = exports.foldedSchema = exports.codedEntitySchema = void 0;
6
+ exports.foldedSchema = exports.codedEntitySchema = void 0;
7
+ exports.loadModel = loadModel;
8
+ exports.createModel = createModel;
9
+ exports.loadMongoModel = loadMongoModel;
10
+ exports.toObjectId = toObjectId;
11
+ exports.toObjectIds = toObjectIds;
12
+ exports.genObjectId = genObjectId;
13
+ exports.isValidObjectId = isValidObjectId;
14
+ exports.isSameId = isSameId;
7
15
  const mongoose_1 = __importDefault(require("mongoose"));
8
- const mongoose_update_if_current_1 = require("mongoose-update-if-current");
9
16
  const constants_1 = require("../constants");
10
17
  const base_model_1 = require("./base.model");
11
18
  exports.codedEntitySchema = {
@@ -37,7 +44,6 @@ function loadModel(model) {
37
44
  if (model.collectionName)
38
45
  constants_1.APP.mongoModels[model.collectionName] = model;
39
46
  }
40
- exports.loadModel = loadModel;
41
47
  /**
42
48
  * name - name of the Model to be created
43
49
  * classDef - (optional) class to be used to create model
@@ -70,7 +76,29 @@ function createModel({ name, classDef, modelName, modelParams, collection, schem
70
76
  //console.log(`created model ${modelName} (load: ${!!load})`);
71
77
  return model;
72
78
  }
73
- exports.createModel = createModel;
79
+ function enableQueryVersioning(mgSchema, version) {
80
+ if (!version)
81
+ return;
82
+ const versionKey = mgSchema.get('versionKey');
83
+ if (!versionKey || typeof versionKey !== 'string')
84
+ return;
85
+ const addVersionIncrement = function () {
86
+ const update = this.getUpdate();
87
+ if (!update || Array.isArray(update))
88
+ return;
89
+ const nextUpdate = update;
90
+ const versionOperators = [nextUpdate, nextUpdate.$set, nextUpdate.$unset, nextUpdate.$inc];
91
+ const touchesVersion = versionOperators.some(operator => !!operator && Object.keys(operator).includes(versionKey));
92
+ if (touchesVersion)
93
+ return;
94
+ nextUpdate.$inc = nextUpdate.$inc ? Object.assign(Object.assign({}, nextUpdate.$inc), { [versionKey]: 1 }) : { [versionKey]: 1 };
95
+ this.setUpdate(nextUpdate);
96
+ };
97
+ mgSchema.pre('findOneAndUpdate', addVersionIncrement);
98
+ mgSchema.pre('updateOne', addVersionIncrement);
99
+ mgSchema.pre('updateMany', addVersionIncrement);
100
+ }
101
+ ;
74
102
  /**
75
103
  *
76
104
  * @param {*} modelName
@@ -79,6 +107,8 @@ exports.createModel = createModel;
79
107
  */
80
108
  function loadMongoModel(modelName, schema, collection, version = true) {
81
109
  const mgSchema = new mongoose_1.default.Schema(schema, {
110
+ optimisticConcurrency: version,
111
+ versionKey: 'version',
82
112
  minimize: false,
83
113
  toJSON: {
84
114
  // convert _id to a standard id attribute
@@ -90,9 +120,7 @@ function loadMongoModel(modelName, schema, collection, version = true) {
90
120
  });
91
121
  // change documents' version key from __v to version
92
122
  mgSchema.set('versionKey', 'version');
93
- // apply version increment to every document update
94
- if (version)
95
- mgSchema.plugin(mongoose_update_if_current_1.updateIfCurrentPlugin);
123
+ enableQueryVersioning(mgSchema, version);
96
124
  mgSchema.statics.build = (attrs) => {
97
125
  const item = { _id: attrs.id };
98
126
  delete attrs.id;
@@ -112,7 +140,6 @@ function loadMongoModel(modelName, schema, collection, version = true) {
112
140
  const MGModel = (constants_1.APP.mongoose || mongoose_1.default).model(modelName, mgSchema, collection);
113
141
  return MGModel;
114
142
  }
115
- exports.loadMongoModel = loadMongoModel;
116
143
  /**
117
144
  *
118
145
  * @param {*} baseSchema
@@ -135,7 +162,6 @@ function toObjectId(value, generate = false) {
135
162
  return generate ? genObjectId() : value;
136
163
  return (value instanceof mongoose_1.default.Types.ObjectId) ? value : mongoose_1.default.Types.ObjectId.createFromHexString(value);
137
164
  }
138
- exports.toObjectId = toObjectId;
139
165
  /**
140
166
  *
141
167
  * @param values
@@ -145,7 +171,6 @@ exports.toObjectId = toObjectId;
145
171
  function toObjectIds(values, generate = false) {
146
172
  return values.map(v => toObjectId(v));
147
173
  }
148
- exports.toObjectIds = toObjectIds;
149
174
  /**
150
175
  * return a new ObjectId value
151
176
  *
@@ -154,7 +179,6 @@ exports.toObjectIds = toObjectIds;
154
179
  function genObjectId() {
155
180
  return new mongoose_1.default.Types.ObjectId();
156
181
  }
157
- exports.genObjectId = genObjectId;
158
182
  // /**
159
183
  // *
160
184
  // * @param {*} period
@@ -212,7 +236,6 @@ function isValidObjectId(value) {
212
236
  return value.every(v => mongoose_1.default.isValidObjectId(v));
213
237
  return mongoose_1.default.isValidObjectId(value);
214
238
  }
215
- exports.isValidObjectId = isValidObjectId;
216
239
  /**
217
240
  *
218
241
  * @param {*} id1
@@ -222,7 +245,6 @@ exports.isValidObjectId = isValidObjectId;
222
245
  function isSameId(id1, id2) {
223
246
  return (id1 === null || id1 === void 0 ? void 0 : id1.toString()) === (id2 === null || id2 === void 0 ? void 0 : id2.toString());
224
247
  }
225
- exports.isSameId = isSameId;
226
248
  // /**
227
249
  // *
228
250
  // * @param {*} cursor
@@ -3,7 +3,8 @@ 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.loadSQLModel = exports.TABLE_SYNC_PROMISES = exports.codedEntitySQLSchema = void 0;
6
+ exports.TABLE_SYNC_PROMISES = exports.codedEntitySQLSchema = void 0;
7
+ exports.loadSQLModel = loadSQLModel;
7
8
  const sequelize_1 = __importDefault(require("sequelize"));
8
9
  const constants_1 = require("../constants");
9
10
  exports.codedEntitySQLSchema = {
@@ -43,7 +44,6 @@ function loadSQLModel(modelName, modelDef, schema, tableName, schemaName, params
43
44
  }
44
45
  return model;
45
46
  }
46
- exports.loadSQLModel = loadSQLModel;
47
47
  // /**
48
48
  // *
49
49
  // * @param {*} period
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { AppData } from './types';
4
2
  import { CryptoUtils } from './crypto';
5
3
  export declare const APP: AppData;
@@ -20,7 +18,7 @@ export declare const REGEX: {
20
18
  email: RegExp;
21
19
  dataurl: RegExp;
22
20
  };
23
- export declare const BUFFER_NULL: Buffer;
21
+ export declare const BUFFER_NULL: Buffer<ArrayBuffer>;
24
22
  export declare const EVENT_TYPE: {};
25
23
  export declare const MODEL_CRUD_EVENT = "crudEvent";
26
24
  export declare const cryptoUtils: CryptoUtils;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import crypto from 'crypto';
4
2
  import { Stream } from 'stream';
5
3
  import { NxObject } from '../interfaces';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import crypto from 'crypto';
3
2
  import { NxObject } from '../interfaces';
4
3
  import { BaseModel } from '../base/base.model';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Stream } from 'stream';
3
2
  import { NxObject } from '../interfaces';
4
3
  import { BlindIndexOptions } from './crypto.interfaces';
@@ -1,31 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="mongoose/types/aggregate" />
4
- /// <reference types="mongoose/types/callback" />
5
- /// <reference types="mongoose/types/collection" />
6
- /// <reference types="mongoose/types/connection" />
7
- /// <reference types="mongoose/types/cursor" />
8
- /// <reference types="mongoose/types/document" />
9
- /// <reference types="mongoose/types/error" />
10
- /// <reference types="mongoose/types/expressions" />
11
- /// <reference types="mongoose/types/helpers" />
12
- /// <reference types="mongoose/types/middlewares" />
13
- /// <reference types="mongoose/types/indexes" />
14
- /// <reference types="mongoose/types/models" />
15
- /// <reference types="mongoose/types/mongooseoptions" />
16
- /// <reference types="mongoose/types/pipelinestage" />
17
- /// <reference types="mongoose/types/populate" />
18
- /// <reference types="mongoose/types/query" />
19
- /// <reference types="mongoose/types/schemaoptions" />
20
- /// <reference types="mongoose/types/session" />
21
- /// <reference types="mongoose/types/types" />
22
- /// <reference types="mongoose/types/utility" />
23
- /// <reference types="mongoose/types/validation" />
24
- /// <reference types="mongoose/types/virtuals" />
25
- /// <reference types="mongoose/types/schematypes" />
26
- /// <reference types="mongoose/types/inferschematype" />
27
- /// <reference types="mongoose/types/inferhydrateddoctype" />
28
- /// <reference types="mongoose/types/inferrawdoctype" />
29
1
  import { Schema } from 'mongoose';
30
2
  type Path = string;
31
3
  interface EncryptionPluginOptions {
@@ -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.encryptionPlugin = void 0;
6
+ exports.encryptionPlugin = encryptionPlugin;
7
7
  // encryptionPlugin.ts
8
8
  const node_crypto_1 = __importDefault(require("node:crypto"));
9
9
  function encryptionPlugin(schema, options) {
@@ -91,4 +91,3 @@ function encryptionPlugin(schema, options) {
91
91
  // next();
92
92
  // });
93
93
  }
94
- exports.encryptionPlugin = encryptionPlugin;
@@ -12,7 +12,9 @@ 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.allowMethods = exports.sendJSONResponse = exports.validateSchema = void 0;
15
+ exports.validateSchema = validateSchema;
16
+ exports.sendJSONResponse = sendJSONResponse;
17
+ exports.allowMethods = allowMethods;
16
18
  const http_errors_1 = __importDefault(require("http-errors"));
17
19
  const express_validator_1 = require("express-validator");
18
20
  /**
@@ -30,7 +32,6 @@ function validateSchema(schema, errorFormatter = (err, req) => err) {
30
32
  res.status(400).json(errorFormatter(errors, req));
31
33
  });
32
34
  }
33
- exports.validateSchema = validateSchema;
34
35
  /**
35
36
  *
36
37
  * @param {*} res
@@ -44,7 +45,6 @@ function sendJSONResponse(res, status = 200, content = {}) {
44
45
  res.status(status);
45
46
  res.json(content);
46
47
  }
47
- exports.sendJSONResponse = sendJSONResponse;
48
48
  /**
49
49
  * Create an Express middleware function which errors if an HTTP method is not allowed.
50
50
  *
@@ -66,7 +66,6 @@ function allowMethods(methods = [], message = 'Method Not Allowed') {
66
66
  next();
67
67
  };
68
68
  }
69
- exports.allowMethods = allowMethods;
70
69
  ;
71
70
  /**
72
71
  * Normalise an array of HTTP methods.