@nocobase/database 0.9.1-alpha.1 → 0.9.2-alpha.1
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-group-manager.d.ts +13 -0
- package/lib/collection-group-manager.js +91 -0
- package/lib/collection-importer.js +0 -24
- package/lib/collection.d.ts +26 -4
- package/lib/collection.js +190 -234
- package/lib/database-utils/index.js +3 -15
- package/lib/database.d.ts +9 -0
- package/lib/database.js +171 -299
- package/lib/decorators/must-have-filter-decorator.js +0 -7
- package/lib/decorators/transaction-decorator.js +5 -18
- package/lib/errors/identifier-error.js +0 -3
- package/lib/features/ReferencesMap.js +1 -14
- package/lib/features/referential-integrity-check.js +7 -21
- package/lib/field-repository/array-field-repository.js +5 -45
- package/lib/fields/array-field.js +0 -13
- package/lib/fields/belongs-to-field.js +24 -50
- package/lib/fields/belongs-to-many-field.js +29 -47
- package/lib/fields/boolean-field.js +0 -7
- package/lib/fields/context-field.js +2 -23
- package/lib/fields/date-field.d.ts +4 -0
- package/lib/fields/date-field.js +15 -7
- package/lib/fields/field.js +32 -85
- package/lib/fields/has-many-field.js +16 -49
- package/lib/fields/has-one-field.js +18 -52
- package/lib/fields/index.js +0 -44
- package/lib/fields/json-field.js +0 -12
- package/lib/fields/number-field.js +0 -23
- package/lib/fields/password-field.js +8 -35
- package/lib/fields/radio-field.js +0 -18
- package/lib/fields/relation-field.js +4 -16
- package/lib/fields/set-field.js +0 -8
- package/lib/fields/sort-field.js +84 -73
- package/lib/fields/string-field.js +0 -7
- package/lib/fields/text-field.js +0 -7
- package/lib/fields/time-field.js +0 -7
- package/lib/fields/uid-field.js +4 -22
- package/lib/fields/uuid-field.js +3 -12
- package/lib/fields/virtual-field.js +0 -7
- package/lib/filter-match.js +7 -22
- package/lib/filter-parser.js +38 -102
- package/lib/index.d.ts +3 -0
- package/lib/index.js +36 -42
- package/lib/inherited-collection.js +15 -62
- package/lib/inherited-map.js +7 -48
- package/lib/listeners/adjacency-list.d.ts +3 -0
- package/lib/listeners/adjacency-list.js +91 -0
- package/lib/listeners/index.d.ts +2 -0
- package/lib/listeners/index.js +12 -0
- package/lib/magic-attribute-model.js +58 -114
- package/lib/migration.js +7 -28
- package/lib/mock-database.d.ts +4 -4
- package/lib/mock-database.js +15 -18
- package/lib/model-hook.js +4 -35
- package/lib/model.js +12 -54
- package/lib/operators/array.js +2 -32
- package/lib/operators/association.js +0 -6
- package/lib/operators/boolean.js +0 -6
- package/lib/operators/child-collection.d.ts +2 -0
- package/lib/operators/child-collection.js +32 -0
- package/lib/operators/date.js +123 -60
- package/lib/operators/empty.js +3 -32
- package/lib/operators/eq.d.ts +2 -0
- package/lib/operators/eq.js +26 -0
- package/lib/operators/index.js +4 -7
- package/lib/operators/ne.js +5 -5
- package/lib/operators/notIn.js +0 -5
- package/lib/operators/string.js +0 -11
- package/lib/operators/utils.js +0 -6
- package/lib/options-parser.d.ts +1 -1
- package/lib/options-parser.js +47 -107
- package/lib/playground.js +0 -4
- package/lib/query-interface/mysql-query-interface.d.ts +18 -0
- package/lib/query-interface/mysql-query-interface.js +88 -0
- package/lib/query-interface/postgres-query-interface.d.ts +14 -0
- package/lib/query-interface/postgres-query-interface.js +99 -0
- package/lib/query-interface/query-interface-builder.d.ts +2 -0
- package/lib/query-interface/query-interface-builder.js +18 -0
- package/lib/query-interface/query-interface.d.ts +21 -0
- package/lib/query-interface/query-interface.js +48 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +17 -0
- package/lib/query-interface/sqlite-query-interface.js +89 -0
- package/lib/relation-repository/belongs-to-many-repository.js +21 -78
- package/lib/relation-repository/belongs-to-repository.js +0 -3
- package/lib/relation-repository/hasmany-repository.js +8 -44
- package/lib/relation-repository/hasone-repository.js +0 -3
- package/lib/relation-repository/multiple-relation-repository.js +16 -68
- package/lib/relation-repository/relation-repository.js +5 -42
- package/lib/relation-repository/single-relation-repository.js +6 -43
- package/lib/repository.d.ts +1 -0
- package/lib/repository.js +36 -182
- package/lib/sql-parser/index.js +10527 -0
- package/lib/sql-parser/sql.pegjs +1297 -0
- package/lib/sync-runner.d.ts +1 -1
- package/lib/sync-runner.js +26 -64
- package/lib/update-associations.js +58 -157
- package/lib/update-guard.js +10 -49
- package/lib/utils.js +16 -54
- package/lib/value-parsers/array-value-parser.js +3 -21
- package/lib/value-parsers/base-value-parser.js +0 -13
- package/lib/value-parsers/boolean-value-parser.js +4 -10
- package/lib/value-parsers/date-value-parser.js +0 -23
- package/lib/value-parsers/index.js +0 -10
- package/lib/value-parsers/json-value-parser.js +0 -7
- package/lib/value-parsers/number-value-parser.js +0 -9
- package/lib/value-parsers/string-value-parser.js +3 -20
- package/lib/value-parsers/to-many-value-parser.js +1 -42
- package/lib/value-parsers/to-one-value-parser.js +0 -14
- package/lib/view/field-type-map.d.ts +47 -0
- package/lib/view/field-type-map.js +56 -0
- package/lib/view/view-inference.d.ts +31 -0
- package/lib/view/view-inference.js +92 -0
- package/lib/view-collection.d.ts +6 -0
- package/lib/view-collection.js +24 -0
- package/package.json +4 -3
- package/src/__tests__/collection.test.ts +44 -0
- package/src/__tests__/fields/date.test.ts +75 -0
- package/src/__tests__/fields/sort-field.test.ts +100 -0
- package/src/__tests__/filter.test.ts +60 -0
- package/src/__tests__/group.test.ts +50 -0
- package/src/__tests__/inhertits/collection-inherits.test.ts +114 -0
- package/src/__tests__/operator/date-operator.test.ts +244 -98
- package/src/__tests__/operator/eq.test.ts +76 -0
- package/src/__tests__/operator/ne.test.ts +19 -1
- package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +82 -0
- package/src/__tests__/repository/find.test.ts +33 -0
- package/src/__tests__/repository.test.ts +88 -0
- package/src/__tests__/sql-parser.test.ts +13 -0
- package/src/__tests__/tree.test.ts +217 -0
- package/src/__tests__/view/list-view.test.ts +34 -0
- package/src/__tests__/view/view-collection.test.ts +199 -0
- package/src/__tests__/view/view-inference.test.ts +145 -0
- package/src/__tests__/view/view-repository.test.ts +67 -0
- package/src/collection-group-manager.ts +94 -0
- package/src/collection.ts +126 -16
- package/src/database-utils/index.ts +1 -0
- package/src/database.ts +98 -17
- package/src/features/ReferencesMap.ts +3 -2
- package/src/fields/belongs-to-many-field.ts +23 -4
- package/src/fields/date-field.ts +18 -0
- package/src/fields/field.ts +17 -7
- package/src/fields/json-field.ts +1 -0
- package/src/fields/sort-field.ts +90 -29
- package/src/filter-parser.ts +2 -1
- package/src/index.ts +3 -1
- package/src/listeners/adjacency-list.ts +60 -0
- package/src/listeners/index.ts +7 -0
- package/src/mock-database.ts +14 -2
- package/src/model.ts +4 -0
- package/src/operators/child-collection.ts +24 -0
- package/src/operators/date.ts +108 -24
- package/src/operators/eq.ts +14 -0
- package/src/operators/index.ts +2 -0
- package/src/operators/ne.ts +12 -7
- package/src/options-parser.ts +25 -11
- package/src/query-interface/mysql-query-interface.ts +72 -0
- package/src/query-interface/postgres-query-interface.ts +103 -0
- package/src/query-interface/query-interface-builder.ts +14 -0
- package/src/query-interface/query-interface.ts +43 -0
- package/src/query-interface/sqlite-query-interface.ts +79 -0
- package/src/relation-repository/belongs-to-many-repository.ts +20 -1
- package/src/relation-repository/hasmany-repository.ts +5 -3
- package/src/relation-repository/multiple-relation-repository.ts +13 -1
- package/src/relation-repository/single-relation-repository.ts +2 -0
- package/src/repository.ts +6 -13
- package/src/sql-parser/index.js +10698 -0
- package/src/sql-parser/readme.md +2 -0
- package/src/sql-parser/sql.pegjs +1297 -0
- package/src/sync-runner.ts +27 -32
- package/src/update-associations.ts +26 -22
- package/src/utils.ts +4 -3
- package/src/view/field-type-map.ts +56 -0
- package/src/view/view-inference.ts +106 -0
- package/src/view-collection.ts +21 -0
|
@@ -4,78 +4,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.MultipleRelationRepository = void 0;
|
|
7
|
-
|
|
8
7
|
function _lodash() {
|
|
9
8
|
const data = require("lodash");
|
|
10
|
-
|
|
11
9
|
_lodash = function _lodash() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _sequelize() {
|
|
19
15
|
const data = require("sequelize");
|
|
20
|
-
|
|
21
16
|
_sequelize = function _sequelize() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
var _updateAssociations = require("../update-associations");
|
|
29
|
-
|
|
30
22
|
var _updateGuard = require("../update-guard");
|
|
31
|
-
|
|
32
23
|
var _relationRepository = require("./relation-repository");
|
|
33
|
-
|
|
34
24
|
var _utils = require("../utils");
|
|
35
|
-
|
|
36
25
|
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; } } }; }
|
|
37
|
-
|
|
38
26
|
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); }
|
|
39
|
-
|
|
40
27
|
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; }
|
|
41
|
-
|
|
42
28
|
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; }
|
|
43
|
-
|
|
44
29
|
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; }
|
|
45
|
-
|
|
46
|
-
function
|
|
47
|
-
|
|
30
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
31
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
32
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
48
33
|
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); } }
|
|
49
|
-
|
|
50
34
|
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); }); }; }
|
|
51
|
-
|
|
52
35
|
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
53
36
|
var c = arguments.length,
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
38
|
+
d;
|
|
56
39
|
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;
|
|
57
40
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
58
41
|
};
|
|
59
|
-
|
|
60
42
|
class MultipleRelationRepository extends _relationRepository.RelationRepository {
|
|
61
43
|
extendFindOptions(findOptions) {
|
|
62
44
|
return findOptions;
|
|
63
45
|
}
|
|
64
|
-
|
|
65
46
|
find(options) {
|
|
66
47
|
var _this = this;
|
|
67
|
-
|
|
68
48
|
return _asyncToGenerator(function* () {
|
|
69
49
|
const transaction = yield _this.getTransaction(options);
|
|
70
|
-
|
|
71
50
|
const findOptions = _objectSpread(_objectSpread({}, _this.extendFindOptions(_this.buildQueryOptions(_objectSpread({}, options)))), {}, {
|
|
72
51
|
subQuery: false
|
|
73
52
|
});
|
|
74
|
-
|
|
75
53
|
const getAccessor = _this.accessors().get;
|
|
76
|
-
|
|
77
54
|
const sourceModel = yield _this.getSourceModel(transaction);
|
|
78
|
-
|
|
55
|
+
if (!sourceModel) return [];
|
|
79
56
|
if (findOptions.include && findOptions.include.length > 0) {
|
|
80
57
|
const ids = (yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
81
58
|
includeIgnoreAttributes: false,
|
|
@@ -88,11 +65,9 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
88
65
|
pk: row.get(_this.targetKey())
|
|
89
66
|
};
|
|
90
67
|
});
|
|
91
|
-
|
|
92
68
|
if (ids.length == 0) {
|
|
93
69
|
return [];
|
|
94
70
|
}
|
|
95
|
-
|
|
96
71
|
return yield (0, _utils.handleAppendsQuery)({
|
|
97
72
|
templateModel: ids[0].row,
|
|
98
73
|
queryPromises: findOptions.include.map(include => {
|
|
@@ -113,16 +88,19 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
113
88
|
})
|
|
114
89
|
});
|
|
115
90
|
}
|
|
116
|
-
|
|
117
|
-
return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
91
|
+
const data = yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
118
92
|
transaction
|
|
119
93
|
}));
|
|
94
|
+
yield _this.collection.db.emitAsync('afterRepositoryFind', {
|
|
95
|
+
findOptions: options,
|
|
96
|
+
dataCollection: _this.collection,
|
|
97
|
+
data
|
|
98
|
+
});
|
|
99
|
+
return data;
|
|
120
100
|
})();
|
|
121
101
|
}
|
|
122
|
-
|
|
123
102
|
findAndCount(options) {
|
|
124
103
|
var _this2 = this;
|
|
125
|
-
|
|
126
104
|
return _asyncToGenerator(function* () {
|
|
127
105
|
const transaction = yield _this2.getTransaction(options, false);
|
|
128
106
|
return [yield _this2.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
@@ -132,16 +110,13 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
132
110
|
}))];
|
|
133
111
|
})();
|
|
134
112
|
}
|
|
135
|
-
|
|
136
113
|
count(options) {
|
|
137
114
|
var _this3 = this;
|
|
138
|
-
|
|
139
115
|
return _asyncToGenerator(function* () {
|
|
140
116
|
const transaction = yield _this3.getTransaction(options);
|
|
141
117
|
const sourceModel = yield _this3.getSourceModel(transaction);
|
|
142
|
-
|
|
118
|
+
if (!sourceModel) return 0;
|
|
143
119
|
const queryOptions = _this3.buildQueryOptions(options);
|
|
144
|
-
|
|
145
120
|
const count = yield sourceModel[_this3.accessors().get]({
|
|
146
121
|
where: queryOptions.where,
|
|
147
122
|
include: queryOptions.include,
|
|
@@ -154,10 +129,8 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
154
129
|
return parseInt(count.count);
|
|
155
130
|
})();
|
|
156
131
|
}
|
|
157
|
-
|
|
158
132
|
findOne(options) {
|
|
159
133
|
var _this4 = this;
|
|
160
|
-
|
|
161
134
|
return _asyncToGenerator(function* () {
|
|
162
135
|
const transaction = yield _this4.getTransaction(options, false);
|
|
163
136
|
const rows = yield _this4.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
@@ -167,18 +140,14 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
167
140
|
return rows.length == 1 ? rows[0] : null;
|
|
168
141
|
})();
|
|
169
142
|
}
|
|
170
|
-
|
|
171
143
|
remove(options) {
|
|
172
144
|
var _this5 = this;
|
|
173
|
-
|
|
174
145
|
return _asyncToGenerator(function* () {
|
|
175
146
|
const transaction = yield _this5.getTransaction(options);
|
|
176
147
|
let handleKeys = options['tk'];
|
|
177
|
-
|
|
178
148
|
if (!Array.isArray(handleKeys)) {
|
|
179
149
|
handleKeys = [handleKeys];
|
|
180
150
|
}
|
|
181
|
-
|
|
182
151
|
const sourceModel = yield _this5.getSourceModel(transaction);
|
|
183
152
|
yield sourceModel[_this5.accessors().removeMultiple](handleKeys, {
|
|
184
153
|
transaction
|
|
@@ -186,26 +155,18 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
186
155
|
return;
|
|
187
156
|
})();
|
|
188
157
|
}
|
|
189
|
-
|
|
190
158
|
update(options) {
|
|
191
159
|
var _this6 = this;
|
|
192
|
-
|
|
193
160
|
return _asyncToGenerator(function* () {
|
|
194
161
|
const transaction = yield _this6.getTransaction(options);
|
|
195
|
-
|
|
196
162
|
const guard = _updateGuard.UpdateGuard.fromOptions(_this6.targetModel, options);
|
|
197
|
-
|
|
198
163
|
const values = guard.sanitize(options.values);
|
|
199
|
-
|
|
200
164
|
const queryOptions = _this6.buildQueryOptions(options);
|
|
201
|
-
|
|
202
165
|
const instances = yield _this6.find(_objectSpread(_objectSpread({}, queryOptions), {}, {
|
|
203
166
|
transaction
|
|
204
167
|
}));
|
|
205
|
-
|
|
206
168
|
var _iterator = _createForOfIteratorHelper(instances),
|
|
207
|
-
|
|
208
|
-
|
|
169
|
+
_step;
|
|
209
170
|
try {
|
|
210
171
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
211
172
|
const instance = _step.value;
|
|
@@ -220,14 +181,11 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
220
181
|
} finally {
|
|
221
182
|
_iterator.f();
|
|
222
183
|
}
|
|
223
|
-
|
|
224
184
|
var _iterator2 = _createForOfIteratorHelper(instances),
|
|
225
|
-
|
|
226
|
-
|
|
185
|
+
_step2;
|
|
227
186
|
try {
|
|
228
187
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
229
188
|
const instance = _step2.value;
|
|
230
|
-
|
|
231
189
|
if (options.hooks !== false) {
|
|
232
190
|
yield _this6.db.emitAsync(`${_this6.targetCollection.name}.afterUpdateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
233
191
|
transaction
|
|
@@ -242,20 +200,16 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
242
200
|
} finally {
|
|
243
201
|
_iterator2.f();
|
|
244
202
|
}
|
|
245
|
-
|
|
246
203
|
return instances;
|
|
247
204
|
})();
|
|
248
205
|
}
|
|
249
|
-
|
|
250
206
|
destroy(options) {
|
|
251
207
|
return _asyncToGenerator(function* () {
|
|
252
208
|
return false;
|
|
253
209
|
})();
|
|
254
210
|
}
|
|
255
|
-
|
|
256
211
|
destroyByFilter(filter, transaction) {
|
|
257
212
|
var _this7 = this;
|
|
258
|
-
|
|
259
213
|
return _asyncToGenerator(function* () {
|
|
260
214
|
const instances = yield _this7.find({
|
|
261
215
|
filter: filter,
|
|
@@ -267,25 +221,19 @@ class MultipleRelationRepository extends _relationRepository.RelationRepository
|
|
|
267
221
|
});
|
|
268
222
|
})();
|
|
269
223
|
}
|
|
270
|
-
|
|
271
224
|
filterHasInclude(filter, options) {
|
|
272
225
|
const filterResult = this.parseFilter(filter, options);
|
|
273
226
|
return filterResult.include && filterResult.include.length > 0;
|
|
274
227
|
}
|
|
275
|
-
|
|
276
228
|
accessors() {
|
|
277
229
|
return super.accessors();
|
|
278
230
|
}
|
|
279
|
-
|
|
280
231
|
}
|
|
281
|
-
|
|
282
232
|
exports.MultipleRelationRepository = MultipleRelationRepository;
|
|
283
|
-
|
|
284
233
|
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
285
234
|
return {
|
|
286
235
|
tk: args[0],
|
|
287
236
|
transaction
|
|
288
237
|
};
|
|
289
238
|
})], MultipleRelationRepository.prototype, "remove", null);
|
|
290
|
-
|
|
291
239
|
__decorate([(0, _relationRepository.transaction)()], MultipleRelationRepository.prototype, "update", null);
|
|
@@ -4,52 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transaction = exports.RelationRepository = void 0;
|
|
7
|
-
|
|
8
7
|
function _lodash() {
|
|
9
8
|
const data = _interopRequireDefault(require("lodash"));
|
|
10
|
-
|
|
11
9
|
_lodash = function _lodash() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
var _transactionDecorator = require("../decorators/transaction-decorator");
|
|
19
|
-
|
|
20
15
|
var _filterParser = _interopRequireDefault(require("../filter-parser"));
|
|
21
|
-
|
|
22
16
|
var _optionsParser = require("../options-parser");
|
|
23
|
-
|
|
24
17
|
var _updateAssociations = require("../update-associations");
|
|
25
|
-
|
|
26
18
|
var _updateGuard = require("../update-guard");
|
|
27
|
-
|
|
28
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
30
20
|
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; }
|
|
31
|
-
|
|
32
21
|
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; }
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
22
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
24
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
36
25
|
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); } }
|
|
37
|
-
|
|
38
26
|
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); }); }; }
|
|
39
|
-
|
|
40
27
|
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
41
28
|
var c = arguments.length,
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
30
|
+
d;
|
|
44
31
|
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;
|
|
45
32
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
46
33
|
};
|
|
47
|
-
|
|
48
34
|
const transaction = (0, _transactionDecorator.transactionWrapperBuilder)(function () {
|
|
49
35
|
return this.sourceCollection.model.sequelize.transaction();
|
|
50
36
|
});
|
|
51
37
|
exports.transaction = transaction;
|
|
52
|
-
|
|
53
38
|
class RelationRepository {
|
|
54
39
|
constructor(sourceCollection, association, sourceKeyValue) {
|
|
55
40
|
this.sourceCollection = void 0;
|
|
@@ -70,33 +55,25 @@ class RelationRepository {
|
|
|
70
55
|
this.targetModel = this.association.target;
|
|
71
56
|
this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
58
|
get collection() {
|
|
75
59
|
return this.db.getCollection(this.targetModel.name);
|
|
76
60
|
}
|
|
77
|
-
|
|
78
61
|
targetKey() {
|
|
79
62
|
return this.associationField.targetKey;
|
|
80
63
|
}
|
|
81
|
-
|
|
82
64
|
accessors() {
|
|
83
65
|
return this.association.accessors;
|
|
84
66
|
}
|
|
85
|
-
|
|
86
67
|
create(options) {
|
|
87
68
|
var _this = this;
|
|
88
|
-
|
|
89
69
|
return _asyncToGenerator(function* () {
|
|
90
70
|
if (Array.isArray(options.values)) {
|
|
91
71
|
return Promise.all(options.values.map(record => _this.create(_objectSpread(_objectSpread({}, options), {}, {
|
|
92
72
|
values: record
|
|
93
73
|
}))));
|
|
94
74
|
}
|
|
95
|
-
|
|
96
75
|
const createAccessor = _this.accessors().create;
|
|
97
|
-
|
|
98
76
|
const guard = _updateGuard.UpdateGuard.fromOptions(_this.targetModel, options);
|
|
99
|
-
|
|
100
77
|
const values = options.values;
|
|
101
78
|
const transaction = yield _this.getTransaction(options);
|
|
102
79
|
const sourceModel = yield _this.getSourceModel(transaction);
|
|
@@ -106,7 +83,6 @@ class RelationRepository {
|
|
|
106
83
|
yield (0, _updateAssociations.updateAssociations)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
|
|
107
84
|
transaction
|
|
108
85
|
}));
|
|
109
|
-
|
|
110
86
|
if (options.hooks !== false) {
|
|
111
87
|
yield _this.db.emitAsync(`${_this.targetCollection.name}.afterCreateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
112
88
|
transaction
|
|
@@ -116,14 +92,11 @@ class RelationRepository {
|
|
|
116
92
|
transaction
|
|
117
93
|
}));
|
|
118
94
|
}
|
|
119
|
-
|
|
120
95
|
return instance;
|
|
121
96
|
})();
|
|
122
97
|
}
|
|
123
|
-
|
|
124
98
|
getSourceModel(transaction) {
|
|
125
99
|
var _this2 = this;
|
|
126
|
-
|
|
127
100
|
return _asyncToGenerator(function* () {
|
|
128
101
|
if (!_this2.sourceInstance) {
|
|
129
102
|
_this2.sourceInstance = yield _this2.sourceCollection.model.findOne({
|
|
@@ -133,11 +106,9 @@ class RelationRepository {
|
|
|
133
106
|
transaction
|
|
134
107
|
});
|
|
135
108
|
}
|
|
136
|
-
|
|
137
109
|
return _this2.sourceInstance;
|
|
138
110
|
})();
|
|
139
111
|
}
|
|
140
|
-
|
|
141
112
|
buildQueryOptions(options) {
|
|
142
113
|
const parser = new _optionsParser.OptionsParser(options, {
|
|
143
114
|
collection: this.targetCollection,
|
|
@@ -146,7 +117,6 @@ class RelationRepository {
|
|
|
146
117
|
const params = parser.toSequelizeParams();
|
|
147
118
|
return _objectSpread(_objectSpread({}, options), params);
|
|
148
119
|
}
|
|
149
|
-
|
|
150
120
|
parseFilter(filter, options) {
|
|
151
121
|
const parser = new _filterParser.default(filter, {
|
|
152
122
|
collection: this.targetCollection,
|
|
@@ -156,25 +126,18 @@ class RelationRepository {
|
|
|
156
126
|
});
|
|
157
127
|
return parser.toSequelizeParams();
|
|
158
128
|
}
|
|
159
|
-
|
|
160
129
|
getTransaction(options, autoGen = false) {
|
|
161
130
|
var _this3 = this;
|
|
162
|
-
|
|
163
131
|
return _asyncToGenerator(function* () {
|
|
164
132
|
if (_lodash().default.isPlainObject(options) && options.transaction) {
|
|
165
133
|
return options.transaction;
|
|
166
134
|
}
|
|
167
|
-
|
|
168
135
|
if (autoGen) {
|
|
169
136
|
return yield _this3.sourceCollection.model.sequelize.transaction();
|
|
170
137
|
}
|
|
171
|
-
|
|
172
138
|
return null;
|
|
173
139
|
})();
|
|
174
140
|
}
|
|
175
|
-
|
|
176
141
|
}
|
|
177
|
-
|
|
178
142
|
exports.RelationRepository = RelationRepository;
|
|
179
|
-
|
|
180
143
|
__decorate([transaction()], RelationRepository.prototype, "create", null);
|
|
@@ -4,47 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SingleRelationRepository = void 0;
|
|
7
|
-
|
|
8
7
|
function _lodash() {
|
|
9
8
|
const data = _interopRequireDefault(require("lodash"));
|
|
10
|
-
|
|
11
9
|
_lodash = function _lodash() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
var _updateAssociations = require("../update-associations");
|
|
19
|
-
|
|
20
15
|
var _utils = require("../utils");
|
|
21
|
-
|
|
22
16
|
var _relationRepository = require("./relation-repository");
|
|
23
|
-
|
|
24
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
18
|
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; }
|
|
27
|
-
|
|
28
19
|
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; }
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
22
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
32
23
|
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); } }
|
|
33
|
-
|
|
34
24
|
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); }); }; }
|
|
35
|
-
|
|
36
25
|
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
37
26
|
var c = arguments.length,
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
28
|
+
d;
|
|
40
29
|
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;
|
|
41
30
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
42
31
|
};
|
|
43
|
-
|
|
44
32
|
class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
45
33
|
remove(options) {
|
|
46
34
|
var _this = this;
|
|
47
|
-
|
|
48
35
|
return _asyncToGenerator(function* () {
|
|
49
36
|
const transaction = yield _this.getTransaction(options);
|
|
50
37
|
const sourceModel = yield _this.getSourceModel(transaction);
|
|
@@ -53,10 +40,8 @@ class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
|
53
40
|
});
|
|
54
41
|
})();
|
|
55
42
|
}
|
|
56
|
-
|
|
57
43
|
set(options) {
|
|
58
44
|
var _this2 = this;
|
|
59
|
-
|
|
60
45
|
return _asyncToGenerator(function* () {
|
|
61
46
|
const transaction = yield _this2.getTransaction(options);
|
|
62
47
|
let handleKey = _lodash().default.isPlainObject(options) ? options.tk : options;
|
|
@@ -66,21 +51,15 @@ class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
|
66
51
|
});
|
|
67
52
|
})();
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
find(options) {
|
|
71
55
|
var _this3 = this;
|
|
72
|
-
|
|
73
56
|
return _asyncToGenerator(function* () {
|
|
74
57
|
var _findOptions$include;
|
|
75
|
-
|
|
76
58
|
const transaction = yield _this3.getTransaction(options);
|
|
77
|
-
|
|
78
59
|
const findOptions = _this3.buildQueryOptions(_objectSpread({}, options));
|
|
79
|
-
|
|
80
60
|
const getAccessor = _this3.accessors().get;
|
|
81
|
-
|
|
82
61
|
const sourceModel = yield _this3.getSourceModel(transaction);
|
|
83
|
-
|
|
62
|
+
if (!sourceModel) return null;
|
|
84
63
|
if ((findOptions === null || findOptions === void 0 ? void 0 : (_findOptions$include = findOptions.include) === null || _findOptions$include === void 0 ? void 0 : _findOptions$include.length) > 0) {
|
|
85
64
|
const templateModel = yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
86
65
|
includeIgnoreAttributes: false,
|
|
@@ -103,26 +82,21 @@ class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
|
103
82
|
});
|
|
104
83
|
return results[0];
|
|
105
84
|
}
|
|
106
|
-
|
|
107
85
|
return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
108
86
|
transaction
|
|
109
87
|
}));
|
|
110
88
|
})();
|
|
111
89
|
}
|
|
112
|
-
|
|
113
90
|
findOne(options) {
|
|
114
91
|
var _this4 = this;
|
|
115
|
-
|
|
116
92
|
return _asyncToGenerator(function* () {
|
|
117
93
|
return _this4.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
118
94
|
filterByTk: null
|
|
119
95
|
}));
|
|
120
96
|
})();
|
|
121
97
|
}
|
|
122
|
-
|
|
123
98
|
destroy(options) {
|
|
124
99
|
var _this5 = this;
|
|
125
|
-
|
|
126
100
|
return _asyncToGenerator(function* () {
|
|
127
101
|
const transaction = yield _this5.getTransaction(options);
|
|
128
102
|
const target = yield _this5.find({
|
|
@@ -134,44 +108,33 @@ class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
|
134
108
|
return true;
|
|
135
109
|
})();
|
|
136
110
|
}
|
|
137
|
-
|
|
138
111
|
update(options) {
|
|
139
112
|
var _this6 = this;
|
|
140
|
-
|
|
141
113
|
return _asyncToGenerator(function* () {
|
|
142
114
|
const transaction = yield _this6.getTransaction(options);
|
|
143
115
|
const target = yield _this6.find({
|
|
144
116
|
transaction
|
|
145
117
|
});
|
|
146
|
-
|
|
147
118
|
if (!target) {
|
|
148
119
|
throw new Error('The record does not exist');
|
|
149
120
|
}
|
|
150
|
-
|
|
151
121
|
yield (0, _updateAssociations.updateModelByValues)(target, options === null || options === void 0 ? void 0 : options.values, _objectSpread(_objectSpread({}, _lodash().default.omit(options, 'values')), {}, {
|
|
152
122
|
transaction
|
|
153
123
|
}));
|
|
154
124
|
return target;
|
|
155
125
|
})();
|
|
156
126
|
}
|
|
157
|
-
|
|
158
127
|
accessors() {
|
|
159
128
|
return super.accessors();
|
|
160
129
|
}
|
|
161
|
-
|
|
162
130
|
}
|
|
163
|
-
|
|
164
131
|
exports.SingleRelationRepository = SingleRelationRepository;
|
|
165
|
-
|
|
166
132
|
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "remove", null);
|
|
167
|
-
|
|
168
133
|
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
169
134
|
return {
|
|
170
135
|
tk: args[0],
|
|
171
136
|
transaction
|
|
172
137
|
};
|
|
173
138
|
})], SingleRelationRepository.prototype, "set", null);
|
|
174
|
-
|
|
175
139
|
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "destroy", null);
|
|
176
|
-
|
|
177
140
|
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "update", null);
|
package/lib/repository.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export interface CommonFindOptions extends Transactionable {
|
|
|
61
61
|
except?: Except;
|
|
62
62
|
sort?: Sort;
|
|
63
63
|
context?: any;
|
|
64
|
+
tree?: boolean;
|
|
64
65
|
}
|
|
65
66
|
export declare type FindOneOptions = Omit<FindOptions, 'limit'>;
|
|
66
67
|
export interface DestroyOptions extends SequelizeDestroyOptions {
|