@nocobase/database 0.7.0-alpha.8 → 0.7.0-alpha.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/collection-importer.js +101 -67
- package/lib/collection.js +339 -210
- package/lib/database.d.ts +4 -1
- package/lib/database.js +489 -275
- 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 -42
- package/lib/fields/date-field.js +24 -9
- package/lib/fields/field.js +114 -75
- package/lib/fields/has-inverse-field.js +4 -2
- package/lib/fields/has-many-field.js +105 -56
- package/lib/fields/has-one-field.js +105 -54
- package/lib/fields/index.d.ts +3 -1
- package/lib/fields/index.js +277 -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.js +210 -29
- package/lib/magic-attribute-model.js +123 -71
- package/lib/mock-database.js +68 -34
- package/lib/model-hook.js +101 -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 +323 -215
- package/lib/playground.js +66 -53
- package/lib/relation-repository/belongs-to-many-repository.js +281 -198
- package/lib/relation-repository/belongs-to-repository.js +10 -6
- package/lib/relation-repository/hasmany-repository.js +168 -121
- package/lib/relation-repository/hasone-repository.js +10 -6
- package/lib/relation-repository/multiple-relation-repository.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 +155 -95
- package/lib/relation-repository/single-relation-repository.d.ts +6 -6
- package/lib/relation-repository/single-relation-repository.js +138 -99
- package/lib/relation-repository/types.js +4 -2
- package/lib/repository.d.ts +4 -7
- package/lib/repository.js +465 -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 +3 -8
- package/src/__tests__/fields/uuid-field.test.ts +30 -0
- package/src/__tests__/operator/notIn.test.ts +33 -0
- package/src/__tests__/option-parser.test.ts +20 -0
- package/src/database.ts +51 -4
- package/src/fields/index.ts +3 -0
- package/src/fields/password-field.ts +2 -0
- package/src/fields/uuid-field.ts +21 -0
- package/src/mock-database.ts +1 -1
- package/src/model-hook.ts +1 -1
- 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 +1 -1
- package/src/relation-repository/multiple-relation-repository.ts +8 -6
- package/src/relation-repository/relation-repository.ts +11 -6
- package/src/relation-repository/single-relation-repository.ts +6 -6
- package/src/repository.ts +4 -6
- package/src/update-associations.ts +1 -2
- 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/database.js
CHANGED
|
@@ -1,304 +1,518 @@
|
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
6
|
+
exports.defineCollection = exports.default = exports.Database = void 0;
|
|
7
|
+
exports.extend = extend;
|
|
8
|
+
exports.extendCollection = void 0;
|
|
9
|
+
|
|
10
|
+
function _utils() {
|
|
11
|
+
const data = require("@nocobase/utils");
|
|
12
|
+
|
|
13
|
+
_utils = function _utils() {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _events() {
|
|
21
|
+
const data = require("events");
|
|
22
|
+
|
|
23
|
+
_events = function _events() {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _lodash() {
|
|
31
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
32
|
+
|
|
33
|
+
_lodash = function _lodash() {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _path() {
|
|
41
|
+
const data = require("path");
|
|
42
|
+
|
|
43
|
+
_path = function _path() {
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _sequelize() {
|
|
51
|
+
const data = require("sequelize");
|
|
52
|
+
|
|
53
|
+
_sequelize = function _sequelize() {
|
|
54
|
+
return data;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var _collection = require("./collection");
|
|
61
|
+
|
|
62
|
+
var _collectionImporter = require("./collection-importer");
|
|
63
|
+
|
|
64
|
+
var FieldTypes = _interopRequireWildcard(require("./fields"));
|
|
65
|
+
|
|
66
|
+
var _modelHook = require("./model-hook");
|
|
67
|
+
|
|
68
|
+
var _operators = _interopRequireDefault(require("./operators"));
|
|
69
|
+
|
|
70
|
+
const _excluded = ["drop"],
|
|
71
|
+
_excluded2 = ["repeat"];
|
|
72
|
+
|
|
73
|
+
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); }
|
|
74
|
+
|
|
75
|
+
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; }
|
|
76
|
+
|
|
77
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
|
+
|
|
79
|
+
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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
80
|
+
|
|
81
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
82
|
+
|
|
83
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
84
|
+
|
|
85
|
+
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); } }
|
|
86
|
+
|
|
87
|
+
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); }); }; }
|
|
88
|
+
|
|
89
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
90
|
+
|
|
91
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
92
|
+
|
|
93
|
+
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); }
|
|
94
|
+
|
|
95
|
+
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; }
|
|
96
|
+
|
|
97
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
98
|
+
|
|
99
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
100
|
+
|
|
101
|
+
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; }
|
|
102
|
+
|
|
103
|
+
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; }
|
|
104
|
+
|
|
105
|
+
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; }
|
|
106
|
+
|
|
107
|
+
class Database extends _events().EventEmitter {
|
|
108
|
+
constructor(options) {
|
|
109
|
+
super();
|
|
110
|
+
this.sequelize = void 0;
|
|
111
|
+
this.fieldTypes = new Map();
|
|
112
|
+
this.options = void 0;
|
|
113
|
+
this.models = new Map();
|
|
114
|
+
this.repositories = new Map();
|
|
115
|
+
this.operators = new Map();
|
|
116
|
+
this.collections = new Map();
|
|
117
|
+
this.pendingFields = new Map();
|
|
118
|
+
this.modelCollection = new Map();
|
|
119
|
+
this.modelHook = void 0;
|
|
120
|
+
this.delayCollectionExtend = new Map();
|
|
121
|
+
|
|
122
|
+
if (options instanceof _sequelize().Sequelize) {
|
|
123
|
+
this.sequelize = options;
|
|
124
|
+
} else {
|
|
125
|
+
const opts = _objectSpread({
|
|
126
|
+
sync: {
|
|
127
|
+
alter: {
|
|
128
|
+
drop: false
|
|
129
|
+
},
|
|
130
|
+
force: false
|
|
93
131
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
collection(options) {
|
|
101
|
-
this.emit('beforeDefineCollection', options);
|
|
102
|
-
const collection = new collection_1.Collection(options, {
|
|
103
|
-
database: this,
|
|
104
|
-
});
|
|
105
|
-
this.collections.set(collection.name, collection);
|
|
106
|
-
this.modelCollection.set(collection.model, collection);
|
|
107
|
-
this.emit('afterDefineCollection', collection);
|
|
108
|
-
return collection;
|
|
109
|
-
}
|
|
110
|
-
getTablePrefix() {
|
|
111
|
-
return this.options.tablePrefix || '';
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* get exists collection by its name
|
|
115
|
-
* @param name
|
|
116
|
-
*/
|
|
117
|
-
getCollection(name) {
|
|
118
|
-
return this.collections.get(name);
|
|
119
|
-
}
|
|
120
|
-
hasCollection(name) {
|
|
121
|
-
return this.collections.has(name);
|
|
122
|
-
}
|
|
123
|
-
removeCollection(name) {
|
|
124
|
-
const collection = this.collections.get(name);
|
|
125
|
-
this.emit('beforeRemoveCollection', collection);
|
|
126
|
-
const result = this.collections.delete(name);
|
|
127
|
-
if (result) {
|
|
128
|
-
this.emit('afterRemoveCollection', collection);
|
|
132
|
+
}, options);
|
|
133
|
+
|
|
134
|
+
if (options.storage && options.storage !== ':memory:') {
|
|
135
|
+
if (!(0, _path().isAbsolute)(options.storage)) {
|
|
136
|
+
opts.storage = (0, _path().resolve)(process.cwd(), options.storage);
|
|
129
137
|
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.sequelize = new (_sequelize().Sequelize)(opts);
|
|
141
|
+
this.options = opts;
|
|
130
142
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
|
|
144
|
+
this.collections = new Map();
|
|
145
|
+
this.modelHook = new _modelHook.ModelHook(this);
|
|
146
|
+
this.on('afterDefineCollection', collection => {
|
|
147
|
+
var _this$pendingFields$g, _this$delayCollection;
|
|
148
|
+
|
|
149
|
+
// after collection defined, call bind method on pending fields
|
|
150
|
+
(_this$pendingFields$g = this.pendingFields.get(collection.name)) === null || _this$pendingFields$g === void 0 ? void 0 : _this$pendingFields$g.forEach(field => field.bind());
|
|
151
|
+
(_this$delayCollection = this.delayCollectionExtend.get(collection.name)) === null || _this$delayCollection === void 0 ? void 0 : _this$delayCollection.forEach(collectionExtend => {
|
|
152
|
+
collection.updateOptions(collectionExtend.collectionOptions, collectionExtend.mergeOptions);
|
|
153
|
+
});
|
|
154
|
+
}); // register database field types
|
|
155
|
+
|
|
156
|
+
for (var _i = 0, _Object$entries = Object.entries(FieldTypes); _i < _Object$entries.length; _i++) {
|
|
157
|
+
const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
158
|
+
name = _Object$entries$_i[0],
|
|
159
|
+
field = _Object$entries$_i[1];
|
|
160
|
+
|
|
161
|
+
if (['Field', 'RelationField'].includes(name)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let key = name.replace(/Field$/g, '');
|
|
166
|
+
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
|
167
|
+
this.registerFieldTypes({
|
|
168
|
+
[key]: field
|
|
169
|
+
});
|
|
141
170
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
171
|
+
|
|
172
|
+
this.initOperators();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Add collection to database
|
|
176
|
+
* @param options
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
collection(options) {
|
|
181
|
+
this.emit('beforeDefineCollection', options);
|
|
182
|
+
const collection = new _collection.Collection(options, {
|
|
183
|
+
database: this
|
|
184
|
+
});
|
|
185
|
+
this.collections.set(collection.name, collection);
|
|
186
|
+
this.modelCollection.set(collection.model, collection);
|
|
187
|
+
this.emit('afterDefineCollection', collection);
|
|
188
|
+
return collection;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
getTablePrefix() {
|
|
192
|
+
return this.options.tablePrefix || '';
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* get exists collection by its name
|
|
196
|
+
* @param name
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
getCollection(name) {
|
|
201
|
+
return this.collections.get(name);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
hasCollection(name) {
|
|
205
|
+
return this.collections.has(name);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
removeCollection(name) {
|
|
209
|
+
const collection = this.collections.get(name);
|
|
210
|
+
this.emit('beforeRemoveCollection', collection);
|
|
211
|
+
const result = this.collections.delete(name);
|
|
212
|
+
|
|
213
|
+
if (result) {
|
|
214
|
+
this.emit('afterRemoveCollection', collection);
|
|
147
215
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getModel(name) {
|
|
219
|
+
return this.getCollection(name).model;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getRepository(name, relationId) {
|
|
223
|
+
var _this$getCollection;
|
|
224
|
+
|
|
225
|
+
if (relationId) {
|
|
226
|
+
var _this$getRepository, _this$getRepository$r;
|
|
227
|
+
|
|
228
|
+
const _name$split = name.split('.'),
|
|
229
|
+
_name$split2 = _slicedToArray(_name$split, 2),
|
|
230
|
+
collection = _name$split2[0],
|
|
231
|
+
relation = _name$split2[1];
|
|
232
|
+
|
|
233
|
+
return (_this$getRepository = this.getRepository(collection)) === null || _this$getRepository === void 0 ? void 0 : (_this$getRepository$r = _this$getRepository.relation(relation)) === null || _this$getRepository$r === void 0 ? void 0 : _this$getRepository$r.of(relationId);
|
|
155
234
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
235
|
+
|
|
236
|
+
return (_this$getCollection = this.getCollection(name)) === null || _this$getCollection === void 0 ? void 0 : _this$getCollection.repository;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
addPendingField(field) {
|
|
240
|
+
const associating = this.pendingFields;
|
|
241
|
+
const items = this.pendingFields.get(field.target) || [];
|
|
242
|
+
items.push(field);
|
|
243
|
+
associating.set(field.target, items);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
removePendingField(field) {
|
|
247
|
+
const items = this.pendingFields.get(field.target) || [];
|
|
248
|
+
const index = items.indexOf(field);
|
|
249
|
+
|
|
250
|
+
if (index !== -1) {
|
|
251
|
+
delete items[index];
|
|
252
|
+
this.pendingFields.set(field.target, items);
|
|
160
253
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
registerFieldTypes(fieldTypes) {
|
|
257
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(fieldTypes); _i2 < _Object$entries2.length; _i2++) {
|
|
258
|
+
const _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
259
|
+
type = _Object$entries2$_i[0],
|
|
260
|
+
fieldType = _Object$entries2$_i[1];
|
|
261
|
+
|
|
262
|
+
this.fieldTypes.set(type, fieldType);
|
|
165
263
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
registerModels(models) {
|
|
267
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(models); _i3 < _Object$entries3.length; _i3++) {
|
|
268
|
+
const _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
269
|
+
type = _Object$entries3$_i[0],
|
|
270
|
+
schemaType = _Object$entries3$_i[1];
|
|
271
|
+
|
|
272
|
+
this.models.set(type, schemaType);
|
|
170
273
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.operators = operators;
|
|
181
|
-
this.registerOperators(Object.assign({}, operators_1.default));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
registerRepositories(repositories) {
|
|
277
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(repositories); _i4 < _Object$entries4.length; _i4++) {
|
|
278
|
+
const _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
279
|
+
type = _Object$entries4$_i[0],
|
|
280
|
+
schemaType = _Object$entries4$_i[1];
|
|
281
|
+
|
|
282
|
+
this.repositories.set(type, schemaType);
|
|
182
283
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
initOperators() {
|
|
287
|
+
const operators = new Map(); // Sequelize 内置
|
|
288
|
+
|
|
289
|
+
for (const key in _sequelize().Op) {
|
|
290
|
+
operators.set('$' + key, _sequelize().Op[key]);
|
|
291
|
+
|
|
292
|
+
const val = _sequelize().Utils.underscoredIf(key, true);
|
|
293
|
+
|
|
294
|
+
operators.set('$' + val, _sequelize().Op[key]);
|
|
295
|
+
operators.set('$' + val.replace(/_/g, ''), _sequelize().Op[key]);
|
|
187
296
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
297
|
+
|
|
298
|
+
this.operators = operators;
|
|
299
|
+
this.registerOperators(_objectSpread({}, _operators.default));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
registerOperators(operators) {
|
|
303
|
+
for (var _i5 = 0, _Object$entries5 = Object.entries(operators); _i5 < _Object$entries5.length; _i5++) {
|
|
304
|
+
const _Object$entries5$_i = _slicedToArray(_Object$entries5[_i5], 2),
|
|
305
|
+
key = _Object$entries5$_i[0],
|
|
306
|
+
operator = _Object$entries5$_i[1];
|
|
307
|
+
|
|
308
|
+
this.operators.set(key, operator);
|
|
195
309
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
yield this.sequelize.query('SET FOREIGN_KEY_CHECKS = 1', null);
|
|
205
|
-
}
|
|
206
|
-
return result;
|
|
207
|
-
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
buildField(options, context) {
|
|
313
|
+
const type = options.type;
|
|
314
|
+
const Field = this.fieldTypes.get(type);
|
|
315
|
+
|
|
316
|
+
if (!Field) {
|
|
317
|
+
throw Error(`unsupported field type ${type}`);
|
|
208
318
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
319
|
+
|
|
320
|
+
return new Field(options, context);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
sync(options) {
|
|
324
|
+
var _this = this;
|
|
325
|
+
|
|
326
|
+
return _asyncToGenerator(function* () {
|
|
327
|
+
const isMySQL = _this.sequelize.getDialect() === 'mysql';
|
|
328
|
+
|
|
329
|
+
if (isMySQL) {
|
|
330
|
+
yield _this.sequelize.query('SET FOREIGN_KEY_CHECKS = 0', null);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const result = yield _this.sequelize.sync(options);
|
|
334
|
+
|
|
335
|
+
if (isMySQL) {
|
|
336
|
+
yield _this.sequelize.query('SET FOREIGN_KEY_CHECKS = 1', null);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return result;
|
|
340
|
+
})();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
clean(options) {
|
|
344
|
+
var _this2 = this;
|
|
345
|
+
|
|
346
|
+
return _asyncToGenerator(function* () {
|
|
347
|
+
const drop = options.drop,
|
|
348
|
+
others = _objectWithoutProperties(options, _excluded);
|
|
349
|
+
|
|
350
|
+
if (drop) {
|
|
351
|
+
yield _this2.sequelize.getQueryInterface().dropAllTables(others);
|
|
352
|
+
}
|
|
353
|
+
})();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
isSqliteMemory() {
|
|
357
|
+
return this.sequelize.getDialect() === 'sqlite' && _lodash().default.get(this.options, 'storage') == ':memory:';
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
auth(options = {}) {
|
|
361
|
+
var _this3 = this;
|
|
362
|
+
|
|
363
|
+
return _asyncToGenerator(function* () {
|
|
364
|
+
const _options$repeat = options.repeat,
|
|
365
|
+
repeat = _options$repeat === void 0 ? 10 : _options$repeat,
|
|
366
|
+
others = _objectWithoutProperties(options, _excluded2);
|
|
367
|
+
|
|
368
|
+
const delay = ms => new Promise(yea => setTimeout(yea, ms));
|
|
369
|
+
|
|
370
|
+
let count = 1;
|
|
371
|
+
|
|
372
|
+
const authenticate = /*#__PURE__*/function () {
|
|
373
|
+
var _ref = _asyncToGenerator(function* () {
|
|
374
|
+
try {
|
|
375
|
+
yield _this3.sequelize.authenticate(others);
|
|
376
|
+
console.log('Connection has been established successfully.');
|
|
377
|
+
return true;
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (count >= repeat) {
|
|
380
|
+
throw error;
|
|
214
381
|
}
|
|
382
|
+
|
|
383
|
+
console.log('reconnecting...', count);
|
|
384
|
+
++count;
|
|
385
|
+
yield delay(500);
|
|
386
|
+
return yield authenticate();
|
|
387
|
+
}
|
|
215
388
|
});
|
|
389
|
+
|
|
390
|
+
return function authenticate() {
|
|
391
|
+
return _ref.apply(this, arguments);
|
|
392
|
+
};
|
|
393
|
+
}();
|
|
394
|
+
|
|
395
|
+
return yield authenticate();
|
|
396
|
+
})();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
reconnect() {
|
|
400
|
+
var _this4 = this;
|
|
401
|
+
|
|
402
|
+
return _asyncToGenerator(function* () {
|
|
403
|
+
if (_this4.isSqliteMemory()) {
|
|
404
|
+
return;
|
|
405
|
+
} // @ts-ignore
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
const ConnectionManager = _this4.sequelize.dialect.connectionManager.constructor; // @ts-ignore
|
|
409
|
+
|
|
410
|
+
const connectionManager = new ConnectionManager(_this4.sequelize.dialect, _this4.sequelize); // @ts-ignore
|
|
411
|
+
|
|
412
|
+
_this4.sequelize.dialect.connectionManager = connectionManager; // @ts-ignore
|
|
413
|
+
|
|
414
|
+
_this4.sequelize.connectionManager = connectionManager;
|
|
415
|
+
})();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
closed() {
|
|
419
|
+
// @ts-ignore
|
|
420
|
+
return this.sequelize.connectionManager.pool._draining;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
close() {
|
|
424
|
+
var _this5 = this;
|
|
425
|
+
|
|
426
|
+
return _asyncToGenerator(function* () {
|
|
427
|
+
if (_this5.isSqliteMemory()) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return _this5.sequelize.close();
|
|
432
|
+
})();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
on(event, listener) {
|
|
436
|
+
const modelEventName = this.modelHook.isModelHook(event);
|
|
437
|
+
|
|
438
|
+
if (modelEventName && !this.modelHook.hasBindEvent(modelEventName)) {
|
|
439
|
+
this.sequelize.addHook(modelEventName, this.modelHook.sequelizeHookBuilder(modelEventName));
|
|
440
|
+
this.modelHook.bindEvent(modelEventName);
|
|
216
441
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
442
|
+
|
|
443
|
+
return super.on(event, listener);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
import(options) {
|
|
447
|
+
var _this6 = this;
|
|
448
|
+
|
|
449
|
+
return _asyncToGenerator(function* () {
|
|
450
|
+
const reader = new _collectionImporter.ImporterReader(options.directory, options.extensions);
|
|
451
|
+
const modules = yield reader.read();
|
|
452
|
+
const result = new Map();
|
|
453
|
+
|
|
454
|
+
var _iterator = _createForOfIteratorHelper(modules),
|
|
455
|
+
_step;
|
|
456
|
+
|
|
457
|
+
try {
|
|
458
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
459
|
+
const module = _step.value;
|
|
460
|
+
|
|
461
|
+
if (module.extend) {
|
|
462
|
+
const collectionName = module.collectionOptions.name;
|
|
463
|
+
|
|
464
|
+
const existCollection = _this6.getCollection(collectionName);
|
|
465
|
+
|
|
466
|
+
if (existCollection) {
|
|
467
|
+
existCollection.updateOptions(module.collectionOptions, module.mergeOptions);
|
|
468
|
+
} else {
|
|
469
|
+
const existDelayExtends = _this6.delayCollectionExtend.get(collectionName) || [];
|
|
470
|
+
|
|
471
|
+
_this6.delayCollectionExtend.set(collectionName, [...existDelayExtends, module]);
|
|
224
472
|
}
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this.sequelize.dialect.connectionManager = connectionManager;
|
|
231
|
-
// @ts-ignore
|
|
232
|
-
this.sequelize.connectionManager = connectionManager;
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
closed() {
|
|
236
|
-
// @ts-ignore
|
|
237
|
-
return this.sequelize.connectionManager.pool._draining;
|
|
238
|
-
}
|
|
239
|
-
close() {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
if (this.isSqliteMemory()) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
return this.sequelize.close();
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
on(event, listener) {
|
|
248
|
-
const modelEventName = this.modelHook.isModelHook(event);
|
|
249
|
-
if (modelEventName && !this.modelHook.hasBindEvent(modelEventName)) {
|
|
250
|
-
this.sequelize.addHook(modelEventName, this.modelHook.sequelizeHookBuilder(modelEventName));
|
|
251
|
-
this.modelHook.bindEvent(modelEventName);
|
|
473
|
+
} else {
|
|
474
|
+
const collection = _this6.collection(module);
|
|
475
|
+
|
|
476
|
+
result.set(collection.name, collection);
|
|
477
|
+
}
|
|
252
478
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const existCollection = this.getCollection(collectionName);
|
|
264
|
-
if (existCollection) {
|
|
265
|
-
existCollection.updateOptions(module.collectionOptions, module.mergeOptions);
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
const existDelayExtends = this.delayCollectionExtend.get(collectionName) || [];
|
|
269
|
-
this.delayCollectionExtend.set(collectionName, [...existDelayExtends, module]);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
const collection = this.collection(module);
|
|
274
|
-
result.set(collection.name, collection);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return result;
|
|
278
|
-
});
|
|
279
|
-
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
_iterator.e(err);
|
|
481
|
+
} finally {
|
|
482
|
+
_iterator.f();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return result;
|
|
486
|
+
})();
|
|
487
|
+
}
|
|
488
|
+
|
|
280
489
|
}
|
|
490
|
+
|
|
281
491
|
exports.Database = Database;
|
|
492
|
+
|
|
282
493
|
function extend(collectionOptions, mergeOptions) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
494
|
+
return {
|
|
495
|
+
collectionOptions,
|
|
496
|
+
mergeOptions,
|
|
497
|
+
extend: true
|
|
498
|
+
};
|
|
288
499
|
}
|
|
289
|
-
|
|
290
|
-
const defineCollection =
|
|
291
|
-
|
|
500
|
+
|
|
501
|
+
const defineCollection = collectionOptions => {
|
|
502
|
+
return collectionOptions;
|
|
292
503
|
};
|
|
504
|
+
|
|
293
505
|
exports.defineCollection = defineCollection;
|
|
506
|
+
|
|
294
507
|
const extendCollection = (collectionOptions, mergeOptions) => {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
508
|
+
return {
|
|
509
|
+
collectionOptions,
|
|
510
|
+
mergeOptions,
|
|
511
|
+
extend: true
|
|
512
|
+
};
|
|
300
513
|
};
|
|
514
|
+
|
|
301
515
|
exports.extendCollection = extendCollection;
|
|
302
|
-
(0,
|
|
303
|
-
|
|
304
|
-
|
|
516
|
+
(0, _utils().applyMixins)(Database, [_utils().AsyncEmitter]);
|
|
517
|
+
var _default = Database;
|
|
518
|
+
exports.default = _default;
|