@nocobase/database 0.7.0-alpha.34 → 0.7.0-alpha.57
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/lib/collection-importer.js +101 -67
- package/lib/collection.js +339 -210
- package/lib/database.js +488 -304
- package/lib/fields/array-field.js +45 -25
- package/lib/fields/belongs-to-field.js +101 -54
- package/lib/fields/belongs-to-many-field.js +98 -53
- package/lib/fields/boolean-field.js +24 -9
- package/lib/fields/context-field.js +77 -45
- package/lib/fields/date-field.js +24 -9
- package/lib/fields/field.js +114 -75
- package/lib/fields/has-inverse-field.js +4 -2
- package/lib/fields/has-many-field.js +105 -56
- package/lib/fields/has-one-field.js +105 -54
- package/lib/fields/index.js +277 -33
- package/lib/fields/json-field.js +36 -16
- package/lib/fields/number-field.js +53 -26
- package/lib/fields/password-field.js +118 -73
- package/lib/fields/radio-field.js +75 -47
- package/lib/fields/relation-field.js +41 -28
- package/lib/fields/sort-field.js +165 -89
- package/lib/fields/string-field.js +24 -9
- package/lib/fields/text-field.js +24 -9
- package/lib/fields/time-field.js +24 -9
- package/lib/fields/uid-field.js +57 -28
- package/lib/fields/uuid-field.js +36 -12
- package/lib/fields/virtual-field.js +24 -9
- package/lib/filter-parser.js +288 -179
- package/lib/index.js +210 -29
- package/lib/magic-attribute-model.js +123 -71
- package/lib/mock-database.js +68 -34
- package/lib/model-hook.js +101 -59
- package/lib/model.js +116 -81
- package/lib/operators/array.js +136 -96
- package/lib/operators/association.js +30 -14
- package/lib/operators/date.js +78 -34
- package/lib/operators/empty.js +113 -75
- package/lib/operators/index.js +15 -3
- package/lib/operators/ne.js +27 -12
- package/lib/operators/notIn.js +27 -12
- package/lib/operators/string.js +56 -35
- package/lib/operators/utils.js +18 -10
- package/lib/options-parser.js +323 -215
- package/lib/playground.js +66 -53
- package/lib/relation-repository/belongs-to-many-repository.js +281 -198
- package/lib/relation-repository/belongs-to-repository.js +10 -6
- package/lib/relation-repository/hasmany-repository.js +168 -121
- package/lib/relation-repository/hasone-repository.js +10 -6
- package/lib/relation-repository/multiple-relation-repository.js +263 -148
- package/lib/relation-repository/relation-repository.js +155 -97
- package/lib/relation-repository/single-relation-repository.js +138 -99
- package/lib/relation-repository/types.js +4 -2
- package/lib/repository.js +465 -291
- package/lib/transaction-decorator.js +80 -67
- package/lib/update-associations.js +525 -321
- package/lib/update-guard.js +160 -117
- package/package.json +3 -8
- package/src/database.ts +9 -3
- package/src/mock-database.ts +1 -1
- package/esm/collection-importer.d.ts +0 -7
- package/esm/collection-importer.js +0 -49
- package/esm/collection-importer.js.map +0 -1
- package/esm/collection.d.ts +0 -73
- package/esm/collection.js +0 -224
- package/esm/collection.js.map +0 -1
- package/esm/database.d.ts +0 -104
- package/esm/database.js +0 -305
- package/esm/database.js.map +0 -1
- package/esm/fields/array-field.d.ts +0 -11
- package/esm/fields/array-field.js +0 -26
- package/esm/fields/array-field.js.map +0 -1
- package/esm/fields/belongs-to-field.d.ts +0 -12
- package/esm/fields/belongs-to-field.js +0 -57
- package/esm/fields/belongs-to-field.js.map +0 -1
- package/esm/fields/belongs-to-many-field.d.ts +0 -11
- package/esm/fields/belongs-to-many-field.js +0 -55
- package/esm/fields/belongs-to-many-field.js.map +0 -1
- package/esm/fields/boolean-field.d.ts +0 -8
- package/esm/fields/boolean-field.js +0 -8
- package/esm/fields/boolean-field.js.map +0 -1
- package/esm/fields/context-field.d.ts +0 -13
- package/esm/fields/context-field.js +0 -43
- package/esm/fields/context-field.js.map +0 -1
- package/esm/fields/date-field.d.ts +0 -8
- package/esm/fields/date-field.js +0 -8
- package/esm/fields/date-field.js.map +0 -1
- package/esm/fields/field.d.ts +0 -37
- package/esm/fields/field.js +0 -74
- package/esm/fields/field.js.map +0 -1
- package/esm/fields/has-inverse-field.d.ts +0 -4
- package/esm/fields/has-inverse-field.js +0 -2
- package/esm/fields/has-inverse-field.js.map +0 -1
- package/esm/fields/has-many-field.d.ts +0 -64
- package/esm/fields/has-many-field.js +0 -58
- package/esm/fields/has-many-field.js.map +0 -1
- package/esm/fields/has-one-field.d.ts +0 -64
- package/esm/fields/has-one-field.js +0 -57
- package/esm/fields/has-one-field.js.map +0 -1
- package/esm/fields/index.d.ts +0 -42
- package/esm/fields/index.js +0 -22
- package/esm/fields/index.js.map +0 -1
- package/esm/fields/json-field.d.ts +0 -14
- package/esm/fields/json-field.js +0 -17
- package/esm/fields/json-field.js.map +0 -1
- package/esm/fields/number-field.d.ts +0 -32
- package/esm/fields/number-field.js +0 -28
- package/esm/fields/number-field.js.map +0 -1
- package/esm/fields/password-field.d.ts +0 -21
- package/esm/fields/password-field.js +0 -71
- package/esm/fields/password-field.js.map +0 -1
- package/esm/fields/radio-field.d.ts +0 -14
- package/esm/fields/radio-field.js +0 -49
- package/esm/fields/radio-field.js.map +0 -1
- package/esm/fields/relation-field.d.ts +0 -20
- package/esm/fields/relation-field.js +0 -27
- package/esm/fields/relation-field.js.map +0 -1
- package/esm/fields/sort-field.d.ts +0 -16
- package/esm/fields/sort-field.js +0 -90
- package/esm/fields/sort-field.js.map +0 -1
- package/esm/fields/string-field.d.ts +0 -8
- package/esm/fields/string-field.js +0 -8
- package/esm/fields/string-field.js.map +0 -1
- package/esm/fields/text-field.d.ts +0 -8
- package/esm/fields/text-field.js +0 -8
- package/esm/fields/text-field.js.map +0 -1
- package/esm/fields/time-field.d.ts +0 -8
- package/esm/fields/time-field.js +0 -8
- package/esm/fields/time-field.js.map +0 -1
- package/esm/fields/uid-field.d.ts +0 -10
- package/esm/fields/uid-field.js +0 -27
- package/esm/fields/uid-field.js.map +0 -1
- package/esm/fields/uuid-field.d.ts +0 -9
- package/esm/fields/uuid-field.js +0 -11
- package/esm/fields/uuid-field.js.map +0 -1
- package/esm/fields/virtual-field.d.ts +0 -8
- package/esm/fields/virtual-field.js +0 -8
- package/esm/fields/virtual-field.js.map +0 -1
- package/esm/filter-parser.d.ts +0 -27
- package/esm/filter-parser.js +0 -185
- package/esm/filter-parser.js.map +0 -1
- package/esm/index.d.ts +0 -15
- package/esm/index.js +0 -16
- package/esm/index.js.map +0 -1
- package/esm/magic-attribute-model.d.ts +0 -7
- package/esm/magic-attribute-model.js +0 -70
- package/esm/magic-attribute-model.js.map +0 -1
- package/esm/mock-database.d.ts +0 -22
- package/esm/mock-database.js +0 -34
- package/esm/mock-database.js.map +0 -1
- package/esm/model-hook.d.ts +0 -12
- package/esm/model-hook.js +0 -60
- package/esm/model-hook.js.map +0 -1
- package/esm/model.d.ts +0 -15
- package/esm/model.js +0 -80
- package/esm/model.js.map +0 -1
- package/esm/operators/array.d.ts +0 -26
- package/esm/operators/array.js +0 -105
- package/esm/operators/array.js.map +0 -1
- package/esm/operators/association.d.ts +0 -10
- package/esm/operators/association.js +0 -14
- package/esm/operators/association.js.map +0 -1
- package/esm/operators/date.d.ts +0 -34
- package/esm/operators/date.js +0 -35
- package/esm/operators/date.js.map +0 -1
- package/esm/operators/empty.d.ts +0 -28
- package/esm/operators/empty.js +0 -58
- package/esm/operators/empty.js.map +0 -1
- package/esm/operators/index.d.ts +0 -2
- package/esm/operators/index.js +0 -2
- package/esm/operators/index.js.map +0 -1
- package/esm/operators/ne.d.ts +0 -10
- package/esm/operators/ne.js +0 -12
- package/esm/operators/ne.js.map +0 -1
- package/esm/operators/notIn.d.ts +0 -10
- package/esm/operators/notIn.js +0 -12
- package/esm/operators/notIn.js.map +0 -1
- package/esm/operators/string.d.ts +0 -21
- package/esm/operators/string.js +0 -35
- package/esm/operators/string.js.map +0 -1
- package/esm/operators/utils.d.ts +0 -4
- package/esm/operators/utils.js +0 -11
- package/esm/operators/utils.js.map +0 -1
- package/esm/options-parser.d.ts +0 -31
- package/esm/options-parser.js +0 -225
- package/esm/options-parser.js.map +0 -1
- package/esm/playground.d.ts +0 -1
- package/esm/playground.js +0 -53
- package/esm/playground.js.map +0 -1
- package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
- package/esm/relation-repository/belongs-to-many-repository.js +0 -199
- package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
- package/esm/relation-repository/belongs-to-repository.js +0 -4
- package/esm/relation-repository/belongs-to-repository.js.map +0 -1
- package/esm/relation-repository/hasmany-repository.d.ts +0 -23
- package/esm/relation-repository/hasmany-repository.js +0 -125
- package/esm/relation-repository/hasmany-repository.js.map +0 -1
- package/esm/relation-repository/hasone-repository.d.ts +0 -17
- package/esm/relation-repository/hasone-repository.js +0 -4
- package/esm/relation-repository/hasone-repository.js.map +0 -1
- package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
- package/esm/relation-repository/multiple-relation-repository.js +0 -149
- package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
- package/esm/relation-repository/relation-repository.d.ts +0 -32
- package/esm/relation-repository/relation-repository.js +0 -95
- package/esm/relation-repository/relation-repository.js.map +0 -1
- package/esm/relation-repository/single-relation-repository.d.ts +0 -23
- package/esm/relation-repository/single-relation-repository.js +0 -96
- package/esm/relation-repository/single-relation-repository.js.map +0 -1
- package/esm/relation-repository/types.d.ts +0 -7
- package/esm/relation-repository/types.js +0 -2
- package/esm/relation-repository/types.js.map +0 -1
- package/esm/repository.d.ts +0 -165
- package/esm/repository.js +0 -276
- package/esm/repository.js.map +0 -1
- package/esm/transaction-decorator.d.ts +0 -1
- package/esm/transaction-decorator.js +0 -63
- package/esm/transaction-decorator.js.map +0 -1
- package/esm/update-associations.d.ts +0 -60
- package/esm/update-associations.js +0 -362
- package/esm/update-associations.js.map +0 -1
- package/esm/update-guard.d.ts +0 -26
- package/esm/update-guard.js +0 -122
- package/esm/update-guard.js.map +0 -1
- package/lib/collection-importer.js.map +0 -1
- package/lib/collection.js.map +0 -1
- package/lib/database.js.map +0 -1
- package/lib/fields/array-field.js.map +0 -1
- package/lib/fields/belongs-to-field.js.map +0 -1
- package/lib/fields/belongs-to-many-field.js.map +0 -1
- package/lib/fields/boolean-field.js.map +0 -1
- package/lib/fields/context-field.js.map +0 -1
- package/lib/fields/date-field.js.map +0 -1
- package/lib/fields/field.js.map +0 -1
- package/lib/fields/has-inverse-field.js.map +0 -1
- package/lib/fields/has-many-field.js.map +0 -1
- package/lib/fields/has-one-field.js.map +0 -1
- package/lib/fields/index.js.map +0 -1
- package/lib/fields/json-field.js.map +0 -1
- package/lib/fields/number-field.js.map +0 -1
- package/lib/fields/password-field.js.map +0 -1
- package/lib/fields/radio-field.js.map +0 -1
- package/lib/fields/relation-field.js.map +0 -1
- package/lib/fields/sort-field.js.map +0 -1
- package/lib/fields/string-field.js.map +0 -1
- package/lib/fields/text-field.js.map +0 -1
- package/lib/fields/time-field.js.map +0 -1
- package/lib/fields/uid-field.js.map +0 -1
- package/lib/fields/uuid-field.js.map +0 -1
- package/lib/fields/virtual-field.js.map +0 -1
- package/lib/filter-parser.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/magic-attribute-model.js.map +0 -1
- package/lib/mock-database.js.map +0 -1
- package/lib/model-hook.js.map +0 -1
- package/lib/model.js.map +0 -1
- package/lib/operators/array.js.map +0 -1
- package/lib/operators/association.js.map +0 -1
- package/lib/operators/date.js.map +0 -1
- package/lib/operators/empty.js.map +0 -1
- package/lib/operators/index.js.map +0 -1
- package/lib/operators/ne.js.map +0 -1
- package/lib/operators/notIn.js.map +0 -1
- package/lib/operators/string.js.map +0 -1
- package/lib/operators/utils.js.map +0 -1
- package/lib/options-parser.js.map +0 -1
- package/lib/playground.js.map +0 -1
- package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/lib/relation-repository/belongs-to-repository.js.map +0 -1
- package/lib/relation-repository/hasmany-repository.js.map +0 -1
- package/lib/relation-repository/hasone-repository.js.map +0 -1
- package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
- package/lib/relation-repository/relation-repository.js.map +0 -1
- package/lib/relation-repository/single-relation-repository.js.map +0 -1
- package/lib/relation-repository/types.js.map +0 -1
- package/lib/repository.js.map +0 -1
- package/lib/transaction-decorator.js.map +0 -1
- package/lib/update-associations.js.map +0 -1
- package/lib/update-guard.js.map +0 -1
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
|
@@ -1,153 +1,268 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
18
6
|
exports.MultipleRelationRepository = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const guard = update_guard_1.UpdateGuard.fromOptions(this.targetModel, options);
|
|
101
|
-
const values = guard.sanitize(options.values);
|
|
102
|
-
const queryOptions = this.buildQueryOptions(options);
|
|
103
|
-
const instances = yield this.find(Object.assign(Object.assign({}, queryOptions), { transaction }));
|
|
104
|
-
for (const instance of instances) {
|
|
105
|
-
yield (0, update_associations_1.updateModelByValues)(instance, values, Object.assign(Object.assign({}, options), { sanitized: true, sourceModel: this.sourceInstance, transaction }));
|
|
106
|
-
}
|
|
107
|
-
for (const instance of instances) {
|
|
108
|
-
if (options.hooks !== false) {
|
|
109
|
-
yield this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, Object.assign(Object.assign({}, options), { transaction }));
|
|
110
|
-
yield this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, Object.assign(Object.assign({}, options), { transaction }));
|
|
111
|
-
}
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = require("lodash");
|
|
10
|
+
|
|
11
|
+
_lodash = function _lodash() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _sequelize() {
|
|
19
|
+
const data = require("sequelize");
|
|
20
|
+
|
|
21
|
+
_sequelize = function _sequelize() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _updateAssociations = require("../update-associations");
|
|
29
|
+
|
|
30
|
+
var _updateGuard = require("../update-guard");
|
|
31
|
+
|
|
32
|
+
var _relationRepository = require("./relation-repository");
|
|
33
|
+
|
|
34
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
35
|
+
|
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
+
|
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
39
|
+
|
|
40
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
41
|
+
|
|
42
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
43
|
+
|
|
44
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
45
|
+
|
|
46
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
47
|
+
|
|
48
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
49
|
+
|
|
50
|
+
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
51
|
+
var c = arguments.length,
|
|
52
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
53
|
+
d;
|
|
54
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
55
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
class MultipleRelationRepository extends _relationRepository.RelationRepository {
|
|
59
|
+
extendFindOptions(findOptions) {
|
|
60
|
+
return findOptions;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
find(options) {
|
|
64
|
+
var _this = this;
|
|
65
|
+
|
|
66
|
+
return _asyncToGenerator(function* () {
|
|
67
|
+
const transaction = yield _this.getTransaction(options);
|
|
68
|
+
|
|
69
|
+
const findOptions = _objectSpread(_objectSpread({}, _this.extendFindOptions(_this.buildQueryOptions(_objectSpread({}, options)))), {}, {
|
|
70
|
+
subQuery: false
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const getAccessor = _this.accessors().get;
|
|
74
|
+
|
|
75
|
+
const sourceModel = yield _this.getSourceModel(transaction);
|
|
76
|
+
|
|
77
|
+
if (findOptions.include && findOptions.include.length > 0) {
|
|
78
|
+
const ids = (yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
79
|
+
includeIgnoreAttributes: false,
|
|
80
|
+
attributes: [_this.targetKey()],
|
|
81
|
+
group: `${_this.targetModel.name}.${_this.targetKey()}`,
|
|
82
|
+
transaction
|
|
83
|
+
}))).map(row => row.get(_this.targetKey()));
|
|
84
|
+
return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, (0, _lodash().omit)(findOptions, ['limit', 'offset'])), {}, {
|
|
85
|
+
where: {
|
|
86
|
+
[_this.targetKey()]: {
|
|
87
|
+
[_sequelize().Op.in]: ids
|
|
112
88
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
89
|
+
},
|
|
90
|
+
transaction
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
95
|
+
transaction
|
|
96
|
+
}));
|
|
97
|
+
})();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
findAndCount(options) {
|
|
101
|
+
var _this2 = this;
|
|
102
|
+
|
|
103
|
+
return _asyncToGenerator(function* () {
|
|
104
|
+
const transaction = yield _this2.getTransaction(options, false);
|
|
105
|
+
return [yield _this2.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
106
|
+
transaction
|
|
107
|
+
})), yield _this2.count(_objectSpread(_objectSpread({}, options), {}, {
|
|
108
|
+
transaction
|
|
109
|
+
}))];
|
|
110
|
+
})();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
count(options) {
|
|
114
|
+
var _this3 = this;
|
|
115
|
+
|
|
116
|
+
return _asyncToGenerator(function* () {
|
|
117
|
+
const transaction = yield _this3.getTransaction(options);
|
|
118
|
+
const sourceModel = yield _this3.getSourceModel(transaction);
|
|
119
|
+
|
|
120
|
+
const queryOptions = _this3.buildQueryOptions(options);
|
|
121
|
+
|
|
122
|
+
const count = yield sourceModel[_this3.accessors().get]({
|
|
123
|
+
where: queryOptions.where,
|
|
124
|
+
include: queryOptions.include,
|
|
125
|
+
includeIgnoreAttributes: false,
|
|
126
|
+
attributes: [[_sequelize().Sequelize.fn('COUNT', _sequelize().Sequelize.fn('DISTINCT', _sequelize().Sequelize.col(`${_this3.targetModel.name}.${_this3.targetKey()}`))), 'count']],
|
|
127
|
+
raw: true,
|
|
128
|
+
plain: true,
|
|
129
|
+
transaction
|
|
130
|
+
});
|
|
131
|
+
return parseInt(count.count);
|
|
132
|
+
})();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
findOne(options) {
|
|
136
|
+
var _this4 = this;
|
|
137
|
+
|
|
138
|
+
return _asyncToGenerator(function* () {
|
|
139
|
+
const transaction = yield _this4.getTransaction(options, false);
|
|
140
|
+
const rows = yield _this4.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
141
|
+
limit: 1,
|
|
142
|
+
transaction
|
|
143
|
+
}));
|
|
144
|
+
return rows.length == 1 ? rows[0] : null;
|
|
145
|
+
})();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
remove(options) {
|
|
149
|
+
var _this5 = this;
|
|
150
|
+
|
|
151
|
+
return _asyncToGenerator(function* () {
|
|
152
|
+
const transaction = yield _this5.getTransaction(options);
|
|
153
|
+
let handleKeys = options['tk'];
|
|
154
|
+
|
|
155
|
+
if (!Array.isArray(handleKeys)) {
|
|
156
|
+
handleKeys = [handleKeys];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const sourceModel = yield _this5.getSourceModel(transaction);
|
|
160
|
+
yield sourceModel[_this5.accessors().removeMultiple](handleKeys, {
|
|
161
|
+
transaction
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
})();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
update(options) {
|
|
168
|
+
var _this6 = this;
|
|
169
|
+
|
|
170
|
+
return _asyncToGenerator(function* () {
|
|
171
|
+
const transaction = yield _this6.getTransaction(options);
|
|
172
|
+
|
|
173
|
+
const guard = _updateGuard.UpdateGuard.fromOptions(_this6.targetModel, options);
|
|
174
|
+
|
|
175
|
+
const values = guard.sanitize(options.values);
|
|
176
|
+
|
|
177
|
+
const queryOptions = _this6.buildQueryOptions(options);
|
|
178
|
+
|
|
179
|
+
const instances = yield _this6.find(_objectSpread(_objectSpread({}, queryOptions), {}, {
|
|
180
|
+
transaction
|
|
181
|
+
}));
|
|
182
|
+
|
|
183
|
+
var _iterator = _createForOfIteratorHelper(instances),
|
|
184
|
+
_step;
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
188
|
+
const instance = _step.value;
|
|
189
|
+
yield (0, _updateAssociations.updateModelByValues)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
|
|
190
|
+
sanitized: true,
|
|
191
|
+
sourceModel: _this6.sourceInstance,
|
|
192
|
+
transaction
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
} catch (err) {
|
|
196
|
+
_iterator.e(err);
|
|
197
|
+
} finally {
|
|
198
|
+
_iterator.f();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var _iterator2 = _createForOfIteratorHelper(instances),
|
|
202
|
+
_step2;
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
206
|
+
const instance = _step2.value;
|
|
207
|
+
|
|
208
|
+
if (options.hooks !== false) {
|
|
209
|
+
yield _this6.db.emitAsync(`${_this6.targetCollection.name}.afterUpdateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
210
|
+
transaction
|
|
211
|
+
}));
|
|
212
|
+
yield _this6.db.emitAsync(`${_this6.targetCollection.name}.afterSaveWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
213
|
+
transaction
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
_iterator2.e(err);
|
|
219
|
+
} finally {
|
|
220
|
+
_iterator2.f();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return instances;
|
|
224
|
+
})();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
destroy(options) {
|
|
228
|
+
return _asyncToGenerator(function* () {
|
|
229
|
+
return false;
|
|
230
|
+
})();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
destroyByFilter(filter, transaction) {
|
|
234
|
+
var _this7 = this;
|
|
235
|
+
|
|
236
|
+
return _asyncToGenerator(function* () {
|
|
237
|
+
const instances = yield _this7.find({
|
|
238
|
+
filter: filter,
|
|
239
|
+
transaction
|
|
240
|
+
});
|
|
241
|
+
return yield _this7.destroy({
|
|
242
|
+
filterByTk: instances.map(instance => instance.get(_this7.targetCollection.filterTargetKey)),
|
|
243
|
+
transaction
|
|
244
|
+
});
|
|
245
|
+
})();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
filterHasInclude(filter, options) {
|
|
249
|
+
const filterResult = this.parseFilter(filter, options);
|
|
250
|
+
return filterResult.include && filterResult.include.length > 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
accessors() {
|
|
254
|
+
return super.accessors();
|
|
255
|
+
}
|
|
256
|
+
|
|
140
257
|
}
|
|
141
|
-
|
|
142
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
143
|
-
return {
|
|
144
|
-
tk: args[0],
|
|
145
|
-
transaction,
|
|
146
|
-
};
|
|
147
|
-
})
|
|
148
|
-
], MultipleRelationRepository.prototype, "remove", null);
|
|
149
|
-
__decorate([
|
|
150
|
-
(0, relation_repository_1.transaction)()
|
|
151
|
-
], MultipleRelationRepository.prototype, "update", null);
|
|
258
|
+
|
|
152
259
|
exports.MultipleRelationRepository = MultipleRelationRepository;
|
|
153
|
-
|
|
260
|
+
|
|
261
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
262
|
+
return {
|
|
263
|
+
tk: args[0],
|
|
264
|
+
transaction
|
|
265
|
+
};
|
|
266
|
+
})], MultipleRelationRepository.prototype, "remove", null);
|
|
267
|
+
|
|
268
|
+
__decorate([(0, _relationRepository.transaction)()], MultipleRelationRepository.prototype, "update", null);
|