@nocobase/database 0.7.0-alpha.9 → 0.7.1-alpha.6
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
package/lib/repository.js
CHANGED
|
@@ -1,302 +1,484 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
13
5
|
});
|
|
14
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
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;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
};
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
6
|
exports.Repository = void 0;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = _interopRequireWildcard(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 _filterParser = _interopRequireDefault(require("./filter-parser"));
|
|
29
|
+
|
|
30
|
+
var _optionsParser = require("./options-parser");
|
|
31
|
+
|
|
32
|
+
var _belongsToManyRepository = require("./relation-repository/belongs-to-many-repository");
|
|
33
|
+
|
|
34
|
+
var _belongsToRepository = require("./relation-repository/belongs-to-repository");
|
|
35
|
+
|
|
36
|
+
var _hasmanyRepository = require("./relation-repository/hasmany-repository");
|
|
37
|
+
|
|
38
|
+
var _hasoneRepository = require("./relation-repository/hasone-repository");
|
|
39
|
+
|
|
40
|
+
var _transactionDecorator = require("./transaction-decorator");
|
|
41
|
+
|
|
42
|
+
var _updateAssociations = require("./update-associations");
|
|
43
|
+
|
|
44
|
+
var _updateGuard = require("./update-guard");
|
|
45
|
+
|
|
46
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
|
+
|
|
48
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
49
|
+
|
|
50
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
51
|
+
|
|
52
|
+
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; } } }; }
|
|
53
|
+
|
|
54
|
+
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); }
|
|
55
|
+
|
|
56
|
+
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; }
|
|
57
|
+
|
|
58
|
+
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; }
|
|
59
|
+
|
|
60
|
+
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; }
|
|
61
|
+
|
|
62
|
+
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; }
|
|
63
|
+
|
|
64
|
+
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); } }
|
|
65
|
+
|
|
66
|
+
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); }); }; }
|
|
67
|
+
|
|
68
|
+
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
69
|
+
var c = arguments.length,
|
|
70
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
71
|
+
d;
|
|
72
|
+
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;
|
|
73
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
74
|
+
};
|
|
75
|
+
|
|
52
76
|
const debug = require('debug')('noco-database');
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
|
|
78
|
+
const transaction = (0, _transactionDecorator.transactionWrapperBuilder)(function () {
|
|
79
|
+
return this.collection.model.sequelize.transaction();
|
|
55
80
|
});
|
|
81
|
+
|
|
56
82
|
class RelationRepositoryBuilder {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
constructor(collection, associationName) {
|
|
84
|
+
this.collection = void 0;
|
|
85
|
+
this.associationName = void 0;
|
|
86
|
+
this.association = void 0;
|
|
87
|
+
this.builderMap = {
|
|
88
|
+
HasOne: _hasoneRepository.HasOneRepository,
|
|
89
|
+
BelongsTo: _belongsToRepository.BelongsToRepository,
|
|
90
|
+
BelongsToMany: _belongsToManyRepository.BelongsToManyRepository,
|
|
91
|
+
HasMany: _hasmanyRepository.HasManyRepository
|
|
92
|
+
};
|
|
93
|
+
this.collection = collection;
|
|
94
|
+
this.associationName = associationName;
|
|
95
|
+
this.association = this.collection.model.associations[this.associationName];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
builder() {
|
|
99
|
+
return this.builderMap;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
of(id) {
|
|
103
|
+
const klass = this.builder()[this.association.associationType];
|
|
104
|
+
return new klass(this.collection, this.associationName, id);
|
|
105
|
+
}
|
|
106
|
+
|
|
75
107
|
}
|
|
108
|
+
|
|
76
109
|
class Repository {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
110
|
+
constructor(collection) {
|
|
111
|
+
this.database = void 0;
|
|
112
|
+
this.collection = void 0;
|
|
113
|
+
this.model = void 0;
|
|
114
|
+
this.database = collection.context.database;
|
|
115
|
+
this.collection = collection;
|
|
116
|
+
this.model = collection.model;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* return count by filter
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
count(countOptions) {
|
|
124
|
+
var _this = this;
|
|
125
|
+
|
|
126
|
+
return _asyncToGenerator(function* () {
|
|
127
|
+
let options = countOptions ? _lodash().default.clone(countOptions) : {};
|
|
128
|
+
const transaction = yield _this.getTransaction(options);
|
|
129
|
+
|
|
130
|
+
if (countOptions === null || countOptions === void 0 ? void 0 : countOptions.filter) {
|
|
131
|
+
options = _objectSpread(_objectSpread({}, options), _this.parseFilter(countOptions.filter, countOptions));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const count = yield _this.collection.model.count(_objectSpread(_objectSpread({}, options), {}, {
|
|
135
|
+
distinct: true,
|
|
136
|
+
transaction
|
|
137
|
+
}));
|
|
138
|
+
return count;
|
|
139
|
+
})();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* find
|
|
143
|
+
* @param options
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
find(options) {
|
|
148
|
+
var _this2 = this;
|
|
149
|
+
|
|
150
|
+
return _asyncToGenerator(function* () {
|
|
151
|
+
const model = _this2.collection.model;
|
|
152
|
+
const transaction = yield _this2.getTransaction(options);
|
|
153
|
+
|
|
154
|
+
const opts = _objectSpread({
|
|
155
|
+
subQuery: false
|
|
156
|
+
}, _this2.buildQueryOptions(options));
|
|
157
|
+
|
|
158
|
+
if (opts.include && opts.include.length > 0) {
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
const primaryKeyField = model.primaryKeyField || model.primaryKeyAttribute;
|
|
161
|
+
const ids = (yield model.findAll(_objectSpread(_objectSpread({}, opts), {}, {
|
|
162
|
+
includeIgnoreAttributes: false,
|
|
163
|
+
attributes: [primaryKeyField],
|
|
164
|
+
group: `${model.name}.${primaryKeyField}`,
|
|
165
|
+
transaction
|
|
166
|
+
}))).map(row => row.get(primaryKeyField));
|
|
167
|
+
const where = {
|
|
168
|
+
[primaryKeyField]: {
|
|
169
|
+
[_sequelize().Op.in]: ids
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return yield model.findAll(_objectSpread(_objectSpread({}, (0, _lodash().omit)(opts, ['limit', 'offset'])), {}, {
|
|
173
|
+
where,
|
|
174
|
+
transaction
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return yield model.findAll(_objectSpread(_objectSpread({}, opts), {}, {
|
|
179
|
+
transaction
|
|
180
|
+
}));
|
|
181
|
+
})();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* find and count
|
|
185
|
+
* @param options
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
findAndCount(options) {
|
|
190
|
+
var _this3 = this;
|
|
191
|
+
|
|
192
|
+
return _asyncToGenerator(function* () {
|
|
193
|
+
const transaction = yield _this3.getTransaction(options);
|
|
194
|
+
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
195
|
+
transaction
|
|
196
|
+
});
|
|
197
|
+
return [yield _this3.find(options), yield _this3.count(options)];
|
|
198
|
+
})();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Find By Id
|
|
202
|
+
*
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
findById(id) {
|
|
207
|
+
return this.collection.model.findByPk(id);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Find one record from database
|
|
211
|
+
*
|
|
212
|
+
* @param options
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
findOne(options) {
|
|
217
|
+
var _this4 = this;
|
|
218
|
+
|
|
219
|
+
return _asyncToGenerator(function* () {
|
|
220
|
+
const transaction = yield _this4.getTransaction(options);
|
|
221
|
+
const rows = yield _this4.find(_objectSpread(_objectSpread({}, options), {}, {
|
|
222
|
+
limit: 1,
|
|
223
|
+
transaction
|
|
224
|
+
}));
|
|
225
|
+
return rows.length == 1 ? rows[0] : null;
|
|
226
|
+
})();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Save instance to database
|
|
230
|
+
*
|
|
231
|
+
* @param values
|
|
232
|
+
* @param options
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
create(options) {
|
|
237
|
+
var _this5 = this;
|
|
238
|
+
|
|
239
|
+
return _asyncToGenerator(function* () {
|
|
240
|
+
const transaction = yield _this5.getTransaction(options);
|
|
241
|
+
|
|
242
|
+
const guard = _updateGuard.UpdateGuard.fromOptions(_this5.model, _objectSpread(_objectSpread({}, options), {}, {
|
|
243
|
+
action: 'create'
|
|
244
|
+
}));
|
|
245
|
+
|
|
246
|
+
const values = guard.sanitize(options.values || {});
|
|
247
|
+
const instance = yield _this5.model.create(values, _objectSpread(_objectSpread({}, options), {}, {
|
|
248
|
+
transaction
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
if (!instance) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
yield (0, _updateAssociations.updateAssociations)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
|
|
256
|
+
transaction
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
if (options.hooks !== false) {
|
|
260
|
+
yield _this5.database.emitAsync(`${_this5.collection.name}.afterCreateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
261
|
+
transaction
|
|
262
|
+
}));
|
|
263
|
+
yield _this5.database.emitAsync(`${_this5.collection.name}.afterSaveWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
264
|
+
transaction
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return instance;
|
|
269
|
+
})();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Save Many instances to database
|
|
273
|
+
*
|
|
274
|
+
* @param records
|
|
275
|
+
* @param options
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
createMany(options) {
|
|
280
|
+
var _this6 = this;
|
|
281
|
+
|
|
282
|
+
return _asyncToGenerator(function* () {
|
|
283
|
+
const transaction = yield _this6.getTransaction(options);
|
|
284
|
+
const records = options.records;
|
|
285
|
+
const instances = [];
|
|
286
|
+
|
|
287
|
+
var _iterator = _createForOfIteratorHelper(records),
|
|
288
|
+
_step;
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
292
|
+
const values = _step.value;
|
|
293
|
+
const instance = yield _this6.create({
|
|
294
|
+
values,
|
|
295
|
+
transaction
|
|
296
|
+
});
|
|
297
|
+
instances.push(instance);
|
|
298
|
+
}
|
|
299
|
+
} catch (err) {
|
|
300
|
+
_iterator.e(err);
|
|
301
|
+
} finally {
|
|
302
|
+
_iterator.f();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return instances;
|
|
306
|
+
})();
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Update model value
|
|
310
|
+
*
|
|
311
|
+
* @param values
|
|
312
|
+
* @param options
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
update(options) {
|
|
317
|
+
var _this7 = this;
|
|
318
|
+
|
|
319
|
+
return _asyncToGenerator(function* () {
|
|
320
|
+
const transaction = yield _this7.getTransaction(options);
|
|
321
|
+
|
|
322
|
+
const guard = _updateGuard.UpdateGuard.fromOptions(_this7.model, options);
|
|
323
|
+
|
|
324
|
+
const values = guard.sanitize(options.values);
|
|
325
|
+
|
|
326
|
+
const queryOptions = _this7.buildQueryOptions(options);
|
|
327
|
+
|
|
328
|
+
const instances = yield _this7.find(_objectSpread(_objectSpread({}, queryOptions), {}, {
|
|
329
|
+
transaction
|
|
330
|
+
}));
|
|
331
|
+
|
|
332
|
+
var _iterator2 = _createForOfIteratorHelper(instances),
|
|
333
|
+
_step2;
|
|
334
|
+
|
|
335
|
+
try {
|
|
336
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
337
|
+
const instance = _step2.value;
|
|
338
|
+
yield (0, _updateAssociations.updateModelByValues)(instance, values, _objectSpread(_objectSpread({}, options), {}, {
|
|
339
|
+
sanitized: true,
|
|
340
|
+
transaction
|
|
341
|
+
}));
|
|
342
|
+
}
|
|
343
|
+
} catch (err) {
|
|
344
|
+
_iterator2.e(err);
|
|
345
|
+
} finally {
|
|
346
|
+
_iterator2.f();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (options.hooks !== false) {
|
|
350
|
+
var _iterator3 = _createForOfIteratorHelper(instances),
|
|
351
|
+
_step3;
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
355
|
+
const instance = _step3.value;
|
|
356
|
+
yield _this7.database.emitAsync(`${_this7.collection.name}.afterUpdateWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
357
|
+
transaction
|
|
358
|
+
}));
|
|
359
|
+
yield _this7.database.emitAsync(`${_this7.collection.name}.afterSaveWithAssociations`, instance, _objectSpread(_objectSpread({}, options), {}, {
|
|
360
|
+
transaction
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
} catch (err) {
|
|
364
|
+
_iterator3.e(err);
|
|
365
|
+
} finally {
|
|
366
|
+
_iterator3.f();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return instances;
|
|
371
|
+
})();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
destroy(options) {
|
|
375
|
+
var _this8 = this;
|
|
376
|
+
|
|
377
|
+
return _asyncToGenerator(function* () {
|
|
378
|
+
const transaction = yield _this8.getTransaction(options);
|
|
379
|
+
const modelFilterKey = _this8.collection.filterTargetKey;
|
|
380
|
+
options = options;
|
|
381
|
+
|
|
382
|
+
if (options['individualHooks'] === undefined) {
|
|
383
|
+
options['individualHooks'] = true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const filterByTk = options.filterByTk && !_lodash().default.isArray(options.filterByTk) ? [options.filterByTk] : options.filterByTk;
|
|
387
|
+
|
|
388
|
+
if (filterByTk && !options.filter) {
|
|
389
|
+
return yield _this8.model.destroy(_objectSpread(_objectSpread({}, options), {}, {
|
|
390
|
+
where: {
|
|
391
|
+
[modelFilterKey]: {
|
|
392
|
+
[_sequelize().Op.in]: filterByTk
|
|
279
393
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
394
|
+
},
|
|
395
|
+
transaction
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (options.filter) {
|
|
400
|
+
let pks = (yield _this8.find({
|
|
401
|
+
filter: options.filter,
|
|
402
|
+
transaction
|
|
403
|
+
})).map(instance => instance.get(modelFilterKey));
|
|
404
|
+
|
|
405
|
+
if (filterByTk) {
|
|
406
|
+
pks = _lodash().default.intersection(pks.map(i => `${i}`), filterByTk.map(i => `${i}`));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return yield _this8.destroy(_objectSpread(_objectSpread({}, _lodash().default.omit(options, 'filter')), {}, {
|
|
410
|
+
filterByTk: pks,
|
|
411
|
+
transaction
|
|
412
|
+
}));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (options.truncate) {
|
|
416
|
+
return yield _this8.model.destroy(_objectSpread(_objectSpread({}, options), {}, {
|
|
417
|
+
truncate: true,
|
|
418
|
+
transaction
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
})();
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* @param association target association
|
|
425
|
+
*/
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
relation(association) {
|
|
429
|
+
return new RelationRepositoryBuilder(this.collection, association);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
buildQueryOptions(options) {
|
|
433
|
+
const parser = new _optionsParser.OptionsParser(options, {
|
|
434
|
+
collection: this.collection
|
|
435
|
+
});
|
|
436
|
+
const params = parser.toSequelizeParams();
|
|
437
|
+
debug('sequelize query params %o', params);
|
|
438
|
+
return _objectSpread(_objectSpread({
|
|
439
|
+
where: {}
|
|
440
|
+
}, options), params);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
parseFilter(filter, options) {
|
|
444
|
+
const parser = new _filterParser.default(filter, {
|
|
445
|
+
collection: this.collection,
|
|
446
|
+
app: {
|
|
447
|
+
ctx: options === null || options === void 0 ? void 0 : options.context
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
return parser.toSequelizeParams();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
getTransaction(options, autoGen = false) {
|
|
454
|
+
var _this9 = this;
|
|
455
|
+
|
|
456
|
+
return _asyncToGenerator(function* () {
|
|
457
|
+
if (_lodash().default.isPlainObject(options) && options.transaction) {
|
|
458
|
+
return options.transaction;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (autoGen) {
|
|
462
|
+
return yield _this9.model.sequelize.transaction();
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return null;
|
|
466
|
+
})();
|
|
467
|
+
}
|
|
468
|
+
|
|
283
469
|
}
|
|
284
|
-
|
|
285
|
-
transaction()
|
|
286
|
-
], Repository.prototype, "create", null);
|
|
287
|
-
__decorate([
|
|
288
|
-
transaction()
|
|
289
|
-
], Repository.prototype, "createMany", null);
|
|
290
|
-
__decorate([
|
|
291
|
-
transaction()
|
|
292
|
-
], Repository.prototype, "update", null);
|
|
293
|
-
__decorate([
|
|
294
|
-
transaction((args, transaction) => {
|
|
295
|
-
return {
|
|
296
|
-
filterByTk: args[0],
|
|
297
|
-
transaction,
|
|
298
|
-
};
|
|
299
|
-
})
|
|
300
|
-
], Repository.prototype, "destroy", null);
|
|
470
|
+
|
|
301
471
|
exports.Repository = Repository;
|
|
302
|
-
|
|
472
|
+
|
|
473
|
+
__decorate([transaction()], Repository.prototype, "create", null);
|
|
474
|
+
|
|
475
|
+
__decorate([transaction()], Repository.prototype, "createMany", null);
|
|
476
|
+
|
|
477
|
+
__decorate([transaction()], Repository.prototype, "update", null);
|
|
478
|
+
|
|
479
|
+
__decorate([transaction((args, transaction) => {
|
|
480
|
+
return {
|
|
481
|
+
filterByTk: args[0],
|
|
482
|
+
transaction
|
|
483
|
+
};
|
|
484
|
+
})], Repository.prototype, "destroy", null);
|