@nocobase/database 0.7.0-alpha.9 → 0.7.1-alpha.4
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 +85 -68
- package/lib/collection.d.ts +6 -2
- package/lib/collection.js +371 -210
- package/lib/database.d.ts +23 -4
- package/lib/database.js +599 -273
- 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.d.ts +4 -1
- package/lib/fields/field.js +231 -75
- package/lib/fields/formula-field.d.ts +19 -0
- package/lib/fields/formula-field.js +184 -0
- 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.d.ts +5 -1
- package/lib/fields/index.js +290 -32
- package/lib/fields/json-field.js +36 -16
- package/lib/fields/number-field.js +53 -26
- package/lib/fields/password-field.js +120 -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.d.ts +9 -0
- package/lib/fields/uuid-field.js +39 -0
- package/lib/fields/virtual-field.js +24 -9
- package/lib/filter-parser.js +288 -179
- package/lib/index.d.ts +1 -0
- package/lib/index.js +224 -29
- package/lib/magic-attribute-model.js +123 -71
- package/lib/migration.d.ts +35 -0
- package/lib/migration.js +90 -0
- package/lib/mock-database.d.ts +1 -0
- package/lib/mock-database.js +69 -34
- package/lib/model-hook.d.ts +5 -5
- package/lib/model-hook.js +109 -60
- package/lib/model.js +116 -81
- package/lib/operators/array.js +136 -96
- package/lib/operators/association.js +30 -14
- package/lib/operators/boolean.d.ts +13 -0
- package/lib/operators/boolean.js +35 -0
- 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/{esm/operators/ne.d.ts → lib/operators/notIn.d.ts} +2 -2
- package/lib/operators/notIn.js +29 -0
- package/lib/operators/string.js +56 -35
- package/lib/operators/utils.js +18 -10
- package/lib/options-parser.js +345 -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.d.ts +3 -3
- package/lib/relation-repository/multiple-relation-repository.js +263 -148
- package/lib/relation-repository/relation-repository.d.ts +1 -1
- package/lib/relation-repository/relation-repository.js +163 -93
- package/lib/relation-repository/single-relation-repository.d.ts +6 -6
- package/lib/relation-repository/single-relation-repository.js +145 -99
- package/lib/relation-repository/types.js +4 -2
- package/lib/repository.d.ts +4 -7
- package/lib/repository.js +473 -291
- package/lib/transaction-decorator.js +80 -67
- package/lib/update-associations.d.ts +1 -2
- package/lib/update-associations.js +525 -321
- package/lib/update-guard.js +160 -117
- package/package.json +9 -9
- package/src/__tests__/collection.test.ts +27 -0
- package/src/__tests__/database.test.ts +47 -0
- package/src/__tests__/fields/formula-field.test.ts +69 -0
- package/src/__tests__/fields/uuid-field.test.ts +30 -0
- package/src/__tests__/fixtures/migrations/m1.ts +7 -0
- package/src/__tests__/fixtures/migrations/m2.ts +7 -0
- package/src/__tests__/hooks/afterCreateWithAssociations.test.ts +33 -0
- package/src/__tests__/migrator.test.ts +70 -0
- package/src/__tests__/model-hook.test.ts +54 -0
- package/src/__tests__/operator/notIn.test.ts +33 -0
- package/src/__tests__/option-parser.test.ts +30 -6
- package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +1 -1
- package/src/__tests__/sequelize-hooks.test.ts +69 -0
- package/src/__tests__/sort.test.ts +51 -0
- package/src/__tests__/update-associations.test.ts +3 -3
- package/src/collection-importer.ts +12 -20
- package/src/collection.ts +26 -2
- package/src/database.ts +144 -14
- package/src/fields/field.ts +88 -1
- package/src/fields/formula-field.ts +106 -0
- package/src/fields/index.ts +6 -0
- package/src/fields/password-field.ts +2 -0
- package/src/fields/uuid-field.ts +21 -0
- package/src/index.ts +1 -0
- package/src/migration.ts +76 -0
- package/src/mock-database.ts +2 -1
- package/src/model-hook.ts +26 -22
- package/src/operators/boolean.ts +18 -0
- package/src/operators/index.ts +2 -0
- package/src/operators/notIn.ts +12 -0
- package/src/options-parser.ts +14 -10
- package/src/relation-repository/multiple-relation-repository.ts +14 -6
- package/src/relation-repository/relation-repository.ts +12 -6
- package/src/relation-repository/single-relation-repository.ts +11 -7
- package/src/repository.ts +20 -10
- package/src/update-associations.ts +2 -3
- 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 -101
- package/esm/database.js +0 -275
- 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 -40
- package/esm/fields/index.js +0 -21
- 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/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 -61
- 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.js +0 -12
- package/esm/operators/ne.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 -93
- 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/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/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,100 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transaction = exports.RelationRepository = void 0;
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
10
|
+
|
|
11
|
+
_lodash = function _lodash() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _filterParser = _interopRequireDefault(require("../filter-parser"));
|
|
19
|
+
|
|
20
|
+
var _optionsParser = require("../options-parser");
|
|
21
|
+
|
|
22
|
+
var _transactionDecorator = require("../transaction-decorator");
|
|
23
|
+
|
|
24
|
+
var _updateAssociations = require("../update-associations");
|
|
25
|
+
|
|
26
|
+
var _updateGuard = require("../update-guard");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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
|
+
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 _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; }
|
|
35
|
+
|
|
36
|
+
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
|
+
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
|
+
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
41
|
+
var c = arguments.length,
|
|
42
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
43
|
+
d;
|
|
44
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
46
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const filter_parser_1 = __importDefault(require("../filter-parser"));
|
|
18
|
-
const options_parser_1 = require("../options-parser");
|
|
19
|
-
const transaction_decorator_1 = require("../transaction-decorator");
|
|
20
|
-
const update_associations_1 = require("../update-associations");
|
|
21
|
-
const update_guard_1 = require("../update-guard");
|
|
22
|
-
exports.transaction = (0, transaction_decorator_1.transactionWrapperBuilder)(function () {
|
|
23
|
-
return this.sourceCollection.model.sequelize.transaction();
|
|
47
|
+
|
|
48
|
+
const transaction = (0, _transactionDecorator.transactionWrapperBuilder)(function () {
|
|
49
|
+
return this.sourceCollection.model.sequelize.transaction();
|
|
24
50
|
});
|
|
51
|
+
exports.transaction = transaction;
|
|
52
|
+
|
|
25
53
|
class RelationRepository {
|
|
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
|
-
|
|
54
|
+
constructor(sourceCollection, association, sourceKeyValue) {
|
|
55
|
+
this.sourceCollection = void 0;
|
|
56
|
+
this.association = void 0;
|
|
57
|
+
this.targetModel = void 0;
|
|
58
|
+
this.targetCollection = void 0;
|
|
59
|
+
this.associationName = void 0;
|
|
60
|
+
this.associationField = void 0;
|
|
61
|
+
this.sourceKeyValue = void 0;
|
|
62
|
+
this.sourceInstance = void 0;
|
|
63
|
+
this.db = void 0;
|
|
64
|
+
this.db = sourceCollection.context.database;
|
|
65
|
+
this.sourceCollection = sourceCollection;
|
|
66
|
+
this.sourceKeyValue = sourceKeyValue;
|
|
67
|
+
this.associationName = association;
|
|
68
|
+
this.association = this.sourceCollection.model.associations[association];
|
|
69
|
+
this.associationField = this.sourceCollection.getField(association);
|
|
70
|
+
this.targetModel = this.association.target;
|
|
71
|
+
this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
targetKey() {
|
|
75
|
+
return this.associationField.targetKey;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
accessors() {
|
|
79
|
+
return this.association.accessors;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
create(options) {
|
|
83
|
+
var _this = this;
|
|
84
|
+
|
|
85
|
+
return _asyncToGenerator(function* () {
|
|
86
|
+
const createAccessor = _this.accessors().create;
|
|
87
|
+
|
|
88
|
+
const guard = _updateGuard.UpdateGuard.fromOptions(_this.targetModel, options);
|
|
89
|
+
|
|
90
|
+
const values = options.values;
|
|
91
|
+
const transaction = yield _this.getTransaction(options);
|
|
92
|
+
const sourceModel = yield _this.getSourceModel(transaction);
|
|
93
|
+
const instance = yield sourceModel[createAccessor](guard.sanitize(options.values), _objectSpread(_objectSpread({}, options), {}, {
|
|
94
|
+
transaction
|
|
95
|
+
}));
|
|
96
|
+
yield (0, _updateAssociations.updateAssociations)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
|
|
97
|
+
transaction
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
if (options.hooks !== false) {
|
|
101
|
+
yield _this.db.emitAsync(`${_this.targetCollection.name}.afterCreateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
102
|
+
transaction
|
|
103
|
+
}));
|
|
104
|
+
const eventName = `${_this.targetCollection.name}.afterSaveWithAssociations`;
|
|
105
|
+
yield _this.db.emitAsync(eventName, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
106
|
+
transaction
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return instance;
|
|
111
|
+
})();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getSourceModel(transaction) {
|
|
115
|
+
var _this2 = this;
|
|
116
|
+
|
|
117
|
+
return _asyncToGenerator(function* () {
|
|
118
|
+
if (!_this2.sourceInstance) {
|
|
119
|
+
_this2.sourceInstance = yield _this2.sourceCollection.model.findOne({
|
|
120
|
+
where: {
|
|
121
|
+
[_this2.associationField.sourceKey]: _this2.sourceKeyValue
|
|
122
|
+
},
|
|
123
|
+
transaction
|
|
68
124
|
});
|
|
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
|
-
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return _this2.sourceInstance;
|
|
128
|
+
})();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
buildQueryOptions(options) {
|
|
132
|
+
const parser = new _optionsParser.OptionsParser(options, {
|
|
133
|
+
collection: this.targetCollection,
|
|
134
|
+
targetKey: this.targetKey()
|
|
135
|
+
});
|
|
136
|
+
const params = parser.toSequelizeParams();
|
|
137
|
+
return _objectSpread(_objectSpread({}, options), params);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
parseFilter(filter, options) {
|
|
141
|
+
const parser = new _filterParser.default(filter, {
|
|
142
|
+
collection: this.targetCollection,
|
|
143
|
+
app: {
|
|
144
|
+
ctx: options === null || options === void 0 ? void 0 : options.context
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return parser.toSequelizeParams();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
getTransaction(options, autoGen = false) {
|
|
151
|
+
var _this3 = this;
|
|
152
|
+
|
|
153
|
+
return _asyncToGenerator(function* () {
|
|
154
|
+
if (_lodash().default.isPlainObject(options) && options.transaction) {
|
|
155
|
+
return options.transaction;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (autoGen) {
|
|
159
|
+
return yield _this3.sourceCollection.model.sequelize.transaction();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
163
|
+
})();
|
|
164
|
+
}
|
|
165
|
+
|
|
98
166
|
}
|
|
167
|
+
|
|
99
168
|
exports.RelationRepository = RelationRepository;
|
|
100
|
-
|
|
169
|
+
|
|
170
|
+
__decorate([transaction()], RelationRepository.prototype, "create", null);
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { SingleAssociationAccessors } from 'sequelize';
|
|
1
|
+
import { SingleAssociationAccessors, Transactionable } from 'sequelize';
|
|
2
2
|
import { Model } from '../model';
|
|
3
|
-
import { Appends, Except, Fields, Filter, TargetKey,
|
|
3
|
+
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
|
|
4
4
|
import { RelationRepository } from './relation-repository';
|
|
5
|
-
export interface SingleRelationFindOption extends
|
|
5
|
+
export interface SingleRelationFindOption extends Transactionable {
|
|
6
6
|
fields?: Fields;
|
|
7
7
|
except?: Except;
|
|
8
8
|
appends?: Appends;
|
|
9
9
|
filter?: Filter;
|
|
10
10
|
}
|
|
11
|
-
interface SetOption extends
|
|
11
|
+
interface SetOption extends Transactionable {
|
|
12
12
|
tk?: TargetKey;
|
|
13
13
|
}
|
|
14
14
|
export declare abstract class SingleRelationRepository extends RelationRepository {
|
|
15
|
-
remove(options?:
|
|
15
|
+
remove(options?: Transactionable): Promise<void>;
|
|
16
16
|
set(options: TargetKey | SetOption): Promise<void>;
|
|
17
17
|
find(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
18
18
|
findOne(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
19
|
-
destroy(options?:
|
|
19
|
+
destroy(options?: Transactionable): Promise<Boolean>;
|
|
20
20
|
update(options: UpdateOptions): Promise<any>;
|
|
21
21
|
accessors(): SingleAssociationAccessors;
|
|
22
22
|
}
|
|
@@ -1,103 +1,149 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
21
6
|
exports.SingleRelationRepository = void 0;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
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
|
-
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
10
|
+
|
|
11
|
+
_lodash = function _lodash() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _updateAssociations = require("../update-associations");
|
|
19
|
+
|
|
20
|
+
var _relationRepository = require("./relation-repository");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
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); } }
|
|
31
|
+
|
|
32
|
+
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); }); }; }
|
|
33
|
+
|
|
34
|
+
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
35
|
+
var c = arguments.length,
|
|
36
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
37
|
+
d;
|
|
38
|
+
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;
|
|
39
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class SingleRelationRepository extends _relationRepository.RelationRepository {
|
|
43
|
+
remove(options) {
|
|
44
|
+
var _this = this;
|
|
45
|
+
|
|
46
|
+
return _asyncToGenerator(function* () {
|
|
47
|
+
const transaction = yield _this.getTransaction(options);
|
|
48
|
+
const sourceModel = yield _this.getSourceModel(transaction);
|
|
49
|
+
return yield sourceModel[_this.accessors().set](null, {
|
|
50
|
+
transaction
|
|
51
|
+
});
|
|
52
|
+
})();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set(options) {
|
|
56
|
+
var _this2 = this;
|
|
57
|
+
|
|
58
|
+
return _asyncToGenerator(function* () {
|
|
59
|
+
const transaction = yield _this2.getTransaction(options);
|
|
60
|
+
let handleKey = _lodash().default.isPlainObject(options) ? options.tk : options;
|
|
61
|
+
const sourceModel = yield _this2.getSourceModel(transaction);
|
|
62
|
+
return yield sourceModel[_this2.accessors().set](handleKey, {
|
|
63
|
+
transaction
|
|
64
|
+
});
|
|
65
|
+
})();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
find(options) {
|
|
69
|
+
var _this3 = this;
|
|
70
|
+
|
|
71
|
+
return _asyncToGenerator(function* () {
|
|
72
|
+
const transaction = yield _this3.getTransaction(options);
|
|
73
|
+
|
|
74
|
+
const findOptions = _this3.buildQueryOptions(_objectSpread({}, options));
|
|
75
|
+
|
|
76
|
+
const getAccessor = _this3.accessors().get;
|
|
77
|
+
|
|
78
|
+
const sourceModel = yield _this3.getSourceModel(transaction);
|
|
79
|
+
return yield sourceModel[getAccessor](_objectSpread(_objectSpread({}, findOptions), {}, {
|
|
80
|
+
transaction
|
|
81
|
+
}));
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
findOne(options) {
|
|
86
|
+
var _this4 = this;
|
|
87
|
+
|
|
88
|
+
return _asyncToGenerator(function* () {
|
|
89
|
+
return _this4.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
90
|
+
filterByTk: null
|
|
91
|
+
}));
|
|
92
|
+
})();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
destroy(options) {
|
|
96
|
+
var _this5 = this;
|
|
97
|
+
|
|
98
|
+
return _asyncToGenerator(function* () {
|
|
99
|
+
const transaction = yield _this5.getTransaction(options);
|
|
100
|
+
const target = yield _this5.find({
|
|
101
|
+
transaction
|
|
102
|
+
});
|
|
103
|
+
yield target.destroy({
|
|
104
|
+
transaction
|
|
105
|
+
});
|
|
106
|
+
return true;
|
|
107
|
+
})();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
update(options) {
|
|
111
|
+
var _this6 = this;
|
|
112
|
+
|
|
113
|
+
return _asyncToGenerator(function* () {
|
|
114
|
+
const transaction = yield _this6.getTransaction(options);
|
|
115
|
+
const target = yield _this6.find({
|
|
116
|
+
transaction
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!target) {
|
|
120
|
+
throw new Error('The record does not exist');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
yield (0, _updateAssociations.updateModelByValues)(target, options === null || options === void 0 ? void 0 : options.values, _objectSpread(_objectSpread({}, _lodash().default.omit(options, 'values')), {}, {
|
|
124
|
+
transaction
|
|
125
|
+
}));
|
|
126
|
+
return target;
|
|
127
|
+
})();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
accessors() {
|
|
131
|
+
return super.accessors();
|
|
132
|
+
}
|
|
133
|
+
|
|
84
134
|
}
|
|
85
|
-
|
|
86
|
-
(0, relation_repository_1.transaction)()
|
|
87
|
-
], SingleRelationRepository.prototype, "remove", null);
|
|
88
|
-
__decorate([
|
|
89
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
90
|
-
return {
|
|
91
|
-
tk: args[0],
|
|
92
|
-
transaction,
|
|
93
|
-
};
|
|
94
|
-
})
|
|
95
|
-
], SingleRelationRepository.prototype, "set", null);
|
|
96
|
-
__decorate([
|
|
97
|
-
(0, relation_repository_1.transaction)()
|
|
98
|
-
], SingleRelationRepository.prototype, "destroy", null);
|
|
99
|
-
__decorate([
|
|
100
|
-
(0, relation_repository_1.transaction)()
|
|
101
|
-
], SingleRelationRepository.prototype, "update", null);
|
|
135
|
+
|
|
102
136
|
exports.SingleRelationRepository = SingleRelationRepository;
|
|
103
|
-
|
|
137
|
+
|
|
138
|
+
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "remove", null);
|
|
139
|
+
|
|
140
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
141
|
+
return {
|
|
142
|
+
tk: args[0],
|
|
143
|
+
transaction
|
|
144
|
+
};
|
|
145
|
+
})], SingleRelationRepository.prototype, "set", null);
|
|
146
|
+
|
|
147
|
+
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "destroy", null);
|
|
148
|
+
|
|
149
|
+
__decorate([(0, _relationRepository.transaction)()], SingleRelationRepository.prototype, "update", null);
|
package/lib/repository.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Association, BulkCreateOptions, CreateOptions as SequelizeCreateOptions, DestroyOptions as SequelizeDestroyOptions, FindAndCountOptions as SequelizeAndCountOptions, FindOptions as SequelizeFindOptions, ModelCtor,
|
|
1
|
+
import { Association, BulkCreateOptions, CreateOptions as SequelizeCreateOptions, DestroyOptions as SequelizeDestroyOptions, FindAndCountOptions as SequelizeAndCountOptions, FindOptions as SequelizeFindOptions, ModelCtor, Transactionable, UpdateOptions as SequelizeUpdateOptions } from 'sequelize';
|
|
2
2
|
import { Collection } from './collection';
|
|
3
3
|
import { Database } from './database';
|
|
4
4
|
import { Model } from './model';
|
|
@@ -12,9 +12,7 @@ export interface IRepository {
|
|
|
12
12
|
interface CreateManyOptions extends BulkCreateOptions {
|
|
13
13
|
records: Values[];
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
transaction?: Transaction;
|
|
17
|
-
}
|
|
15
|
+
export { Transactionable } from 'sequelize';
|
|
18
16
|
export interface FilterAble {
|
|
19
17
|
filter: Filter;
|
|
20
18
|
}
|
|
@@ -29,7 +27,7 @@ export declare type WhiteList = string[];
|
|
|
29
27
|
export declare type BlackList = string[];
|
|
30
28
|
export declare type AssociationKeysToBeUpdate = string[];
|
|
31
29
|
export declare type Values = any;
|
|
32
|
-
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>,
|
|
30
|
+
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>, Transactionable {
|
|
33
31
|
fields?: Fields;
|
|
34
32
|
filter?: Filter;
|
|
35
33
|
}
|
|
@@ -38,7 +36,7 @@ export interface FilterByTk {
|
|
|
38
36
|
}
|
|
39
37
|
export interface FindOptions extends SequelizeFindOptions, CommonFindOptions, FilterByTk {
|
|
40
38
|
}
|
|
41
|
-
export interface CommonFindOptions {
|
|
39
|
+
export interface CommonFindOptions extends Transactionable {
|
|
42
40
|
filter?: Filter;
|
|
43
41
|
fields?: Fields;
|
|
44
42
|
appends?: Appends;
|
|
@@ -162,4 +160,3 @@ export declare class Repository<TModelAttributes extends {} = any, TCreationAttr
|
|
|
162
160
|
};
|
|
163
161
|
protected getTransaction(options: any, autoGen?: boolean): Promise<any>;
|
|
164
162
|
}
|
|
165
|
-
export {};
|