@nextage/nx-frame-be 1.0.34 → 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.
- package/build/common/base/__test__/base.model.test.js +31 -23
- package/build/common/base/base.controller.d.ts +0 -25
- package/build/common/base/base.interfaces.d.ts +0 -25
- package/build/common/base/base.model.d.ts +9 -35
- package/build/common/base/base.model.js +14 -2
- package/build/common/base/mongo-utils.d.ts +0 -25
- package/build/common/base/mongo-utils.js +35 -13
- package/build/common/base/sql-utils.js +2 -2
- package/build/common/constants.d.ts +1 -3
- package/build/common/crypto/crypto.classes.d.ts +0 -2
- package/build/common/crypto/crypto.interfaces.d.ts +0 -1
- package/build/common/crypto/crypto.utils.d.ts +0 -1
- package/build/common/crypto/encryption.plugin.d.ts +10 -0
- package/build/common/crypto/encryption.plugin.js +93 -0
- package/build/common/crypto/index.d.ts +1 -0
- package/build/common/crypto/index.js +1 -0
- package/build/common/express/express.utils.js +3 -4
- package/build/common/graphql/__test__/generator.schema.test.js +39 -39
- package/build/common/graphql/directives.js +3 -3
- package/build/common/graphql/generator copy.js +5 -5
- package/build/common/graphql/generator.js +5 -5
- package/build/common/graphql/loader.js +4 -4
- package/build/common/graphql/utils.js +3 -3
- package/build/common/grid-fs/gridfs-base.model.d.ts +0 -26
- package/build/common/grid-fs/gridfs-base.model.js +1 -1
- package/build/common/grid-fs/gridfs.interfaces.d.ts +0 -25
- package/build/common/manager/bulk-manager.d.ts +0 -25
- package/build/common/manager/crypto-manager.d.ts +0 -1
- package/build/common/manager/socket-io-cli-manager.d.ts +0 -1
- package/build/common/manager/tunnel-manager.d.ts +0 -1
- package/build/common/models/coded-entity.model.js +2 -14
- package/build/common/types.d.ts +0 -25
- package/build/common/utils.d.ts +0 -3
- package/build/common/utils.js +83 -85
- package/build/test/setup.js +3 -2
- package/package.json +12 -12
|
@@ -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
|
|
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 = ((
|
|
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((
|
|
215
|
-
expect((
|
|
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
|
|
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 = ((
|
|
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((
|
|
229
|
-
expect((
|
|
230
|
-
expect((
|
|
231
|
-
expect((
|
|
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 = ((
|
|
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((
|
|
242
|
-
expect((
|
|
243
|
-
expect((
|
|
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 = ((
|
|
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((
|
|
254
|
-
expect((
|
|
255
|
-
expect((
|
|
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
|
|
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 = ((
|
|
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((
|
|
268
|
-
expect((
|
|
269
|
-
(
|
|
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,28 +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/schematypes" />
|
|
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/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { NxContext, NxObject } from '../interfaces';
|
|
28
3
|
import { BaseModel } from './base.model';
|
|
@@ -1,28 +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/schematypes" />
|
|
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/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { ModelCrudEventType } from '../enums';
|
|
28
3
|
import { NxObject } from '../interfaces';
|
|
@@ -1,29 +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/schematypes" />
|
|
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/inferschematype" />
|
|
26
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
27
1
|
import mongoose from 'mongoose';
|
|
28
2
|
import { EventEmitter } from 'events';
|
|
29
3
|
import { NxContext, NxObject } from '../interfaces';
|
|
@@ -42,11 +16,7 @@ export declare class BaseModel<TAttrs, TDoc extends BaseMongoDoc, TMongoModel ex
|
|
|
42
16
|
/**
|
|
43
17
|
*
|
|
44
18
|
*/
|
|
45
|
-
get schema():
|
|
46
|
-
id?: mongoose.SchemaDefinitionProperty<string | undefined, BaseMongoDoc> | undefined;
|
|
47
|
-
_id?: mongoose.SchemaDefinitionProperty<unknown, BaseMongoDoc> | undefined;
|
|
48
|
-
__v?: mongoose.SchemaDefinitionProperty<any, BaseMongoDoc> | undefined;
|
|
49
|
-
};
|
|
19
|
+
get schema(): any;
|
|
50
20
|
/**
|
|
51
21
|
* Get mongodb collection name
|
|
52
22
|
*/
|
|
@@ -95,9 +65,13 @@ export declare class BaseModel<TAttrs, TDoc extends BaseMongoDoc, TMongoModel ex
|
|
|
95
65
|
* @param {*} fields
|
|
96
66
|
* @param {*} options
|
|
97
67
|
*/
|
|
98
|
-
find(params: FilterParams, fields: NxObject, options: mongoose.QueryOptions<TDoc>): Promise<(mongoose.Document<unknown, {}, BaseMongoDoc> & BaseMongoDoc & Required<{
|
|
99
|
-
_id:
|
|
100
|
-
}>
|
|
68
|
+
find(params: FilterParams, fields: NxObject, options: mongoose.QueryOptions<TDoc>): Promise<(mongoose.Document<unknown, {}, BaseMongoDoc, {}, mongoose.DefaultSchemaOptions> & BaseMongoDoc & Required<{
|
|
69
|
+
_id: mongoose.Types.ObjectId;
|
|
70
|
+
}> & {
|
|
71
|
+
__v: number;
|
|
72
|
+
} & {
|
|
73
|
+
id: string;
|
|
74
|
+
})[]>;
|
|
101
75
|
list(params?: FilterParams, fields?: mongoose.ProjectionType<BaseMongoDoc>, pagination?: QueryPagination, context?: NxContext): Promise<TDoc[]>;
|
|
102
76
|
list(params: FilterParams, fields: mongoose.ProjectionType<BaseMongoDoc>, pagination: QueryPagination, queryActions: NxObject, context: NxContext): Promise<TDoc[]>;
|
|
103
77
|
/**
|
|
@@ -106,7 +80,7 @@ export declare class BaseModel<TAttrs, TDoc extends BaseMongoDoc, TMongoModel ex
|
|
|
106
80
|
* @param {*} params
|
|
107
81
|
* @param {*} callback
|
|
108
82
|
*/
|
|
109
|
-
listNative(params?: FilterParams, options?: mongoose.mongo.FindOptions
|
|
83
|
+
listNative(params?: FilterParams, options?: mongoose.mongo.FindOptions): mongoose.mongo.FindCursor<mongoose.mongo.WithId<mongoose.mongo.BSON.Document>>;
|
|
110
84
|
/**
|
|
111
85
|
*
|
|
112
86
|
* @param params
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
exports.BaseModel = void 0;
|
|
13
24
|
const events_1 = require("events");
|
|
@@ -517,8 +528,9 @@ class BaseModel extends events_1.EventEmitter {
|
|
|
517
528
|
return null;
|
|
518
529
|
const fiAttrs = foundItem.toObject();
|
|
519
530
|
delete fiAttrs.id;
|
|
520
|
-
delete fiAttrs._id;
|
|
521
|
-
|
|
531
|
+
// delete fiAttrs._id;
|
|
532
|
+
const { _id } = fiAttrs, cleanAttrs = __rest(fiAttrs, ["_id"]);
|
|
533
|
+
item = Object.assign(cleanAttrs, item);
|
|
522
534
|
item = yield this.beforeCopy(item, context);
|
|
523
535
|
const newItem = this.mgModel.build(item);
|
|
524
536
|
const res = yield (newItem === null || newItem === void 0 ? void 0 : newItem.save());
|
|
@@ -1,28 +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/schematypes" />
|
|
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/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { BaseDBItem } from '../types';
|
|
28
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.
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
type Path = string;
|
|
3
|
+
interface EncryptionPluginOptions {
|
|
4
|
+
fields: Path[];
|
|
5
|
+
getKey: (keyId?: string) => Buffer;
|
|
6
|
+
currentKeyId: string;
|
|
7
|
+
algorithm?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function encryptionPlugin(schema: Schema, options: EncryptionPluginOptions): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encryptionPlugin = encryptionPlugin;
|
|
7
|
+
// encryptionPlugin.ts
|
|
8
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
|
+
function encryptionPlugin(schema, options) {
|
|
10
|
+
const { fields, getKey, currentKeyId, algorithm = 'aes-256-cbc' } = options;
|
|
11
|
+
// --- utils nested ---
|
|
12
|
+
const getNested = (obj, path) => path.split('.').reduce((o, k) => (o ? o[k] : undefined), obj);
|
|
13
|
+
const setNested = (obj, path, value) => {
|
|
14
|
+
const keys = path.split('.');
|
|
15
|
+
const last = keys.pop();
|
|
16
|
+
const target = keys.reduce((o, k) => {
|
|
17
|
+
if (!o[k])
|
|
18
|
+
o[k] = {};
|
|
19
|
+
return o[k];
|
|
20
|
+
}, obj);
|
|
21
|
+
target[last] = value;
|
|
22
|
+
};
|
|
23
|
+
// --- crypto ---
|
|
24
|
+
const encrypt = (data) => {
|
|
25
|
+
const iv = node_crypto_1.default.randomBytes(16);
|
|
26
|
+
const key = getKey(currentKeyId);
|
|
27
|
+
const cipher = node_crypto_1.default.createCipheriv(algorithm, key, iv);
|
|
28
|
+
const json = JSON.stringify(data);
|
|
29
|
+
let encrypted = cipher.update(json);
|
|
30
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
31
|
+
return {
|
|
32
|
+
_enc: true,
|
|
33
|
+
v: encrypted.toString('hex'),
|
|
34
|
+
iv: iv.toString('hex'),
|
|
35
|
+
k: currentKeyId
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const decrypt = (payload) => {
|
|
39
|
+
const key = getKey(payload.k);
|
|
40
|
+
const iv = Buffer.from(payload.iv, 'hex');
|
|
41
|
+
const encryptedText = Buffer.from(payload.v, 'hex');
|
|
42
|
+
const decipher = node_crypto_1.default.createDecipheriv(algorithm, key, iv);
|
|
43
|
+
let decrypted = decipher.update(encryptedText);
|
|
44
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
45
|
+
return JSON.parse(decrypted.toString());
|
|
46
|
+
};
|
|
47
|
+
const isEncrypted = (val) => (val === null || val === void 0 ? void 0 : val._enc) === true;
|
|
48
|
+
// --- encrypt fields ---
|
|
49
|
+
const encryptFields = (obj) => {
|
|
50
|
+
for (const path of fields) {
|
|
51
|
+
const value = getNested(obj, path);
|
|
52
|
+
if (value && !isEncrypted(value))
|
|
53
|
+
setNested(obj, path, encrypt(value));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// --- decrypt fields ---
|
|
57
|
+
const decryptFields = (obj) => {
|
|
58
|
+
for (const path of fields) {
|
|
59
|
+
const value = getNested(obj, path);
|
|
60
|
+
if (isEncrypted(value)) {
|
|
61
|
+
try {
|
|
62
|
+
setNested(obj, path, decrypt(value));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
//console.log(e);
|
|
66
|
+
// fallback safe
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// --- hooks ---
|
|
72
|
+
// schema.pre('save', function (next) {
|
|
73
|
+
// encryptFields(this);
|
|
74
|
+
// next();
|
|
75
|
+
// });
|
|
76
|
+
// schema.post('init', function (doc) {
|
|
77
|
+
// decryptFields(doc);
|
|
78
|
+
// });
|
|
79
|
+
// schema.post('save', function (doc) {
|
|
80
|
+
// decryptFields(doc);
|
|
81
|
+
// });
|
|
82
|
+
// // update hooks
|
|
83
|
+
// schema.pre(['updateOne', 'findOneAndUpdate'], (next: Function) => {
|
|
84
|
+
// const update: any = this.getUpdate();
|
|
85
|
+
// if (!update) return next();
|
|
86
|
+
// // support $set
|
|
87
|
+
// if (update.$set)
|
|
88
|
+
// encryptFields(update.$set);
|
|
89
|
+
// else
|
|
90
|
+
// encryptFields(update);
|
|
91
|
+
// next();
|
|
92
|
+
// });
|
|
93
|
+
}
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./crypto.interfaces"), exports);
|
|
18
18
|
__exportStar(require("./crypto.classes"), exports);
|
|
19
19
|
__exportStar(require("./crypto.utils"), exports);
|
|
20
|
+
__exportStar(require("./encryption.plugin"), exports);
|
|
@@ -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.
|
|
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.
|