@nocobase/database 0.7.0-alpha.34 → 0.7.0-alpha.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/collection-importer.js +101 -67
- package/lib/collection.js +339 -210
- package/lib/database.js +488 -304
- package/lib/fields/array-field.js +45 -25
- package/lib/fields/belongs-to-field.js +101 -54
- package/lib/fields/belongs-to-many-field.js +98 -53
- package/lib/fields/boolean-field.js +24 -9
- package/lib/fields/context-field.js +77 -45
- package/lib/fields/date-field.js +24 -9
- package/lib/fields/field.js +114 -75
- package/lib/fields/has-inverse-field.js +4 -2
- package/lib/fields/has-many-field.js +105 -56
- package/lib/fields/has-one-field.js +105 -54
- package/lib/fields/index.js +277 -33
- package/lib/fields/json-field.js +36 -16
- package/lib/fields/number-field.js +53 -26
- package/lib/fields/password-field.js +118 -73
- package/lib/fields/radio-field.js +75 -47
- package/lib/fields/relation-field.js +41 -28
- package/lib/fields/sort-field.js +165 -89
- package/lib/fields/string-field.js +24 -9
- package/lib/fields/text-field.js +24 -9
- package/lib/fields/time-field.js +24 -9
- package/lib/fields/uid-field.js +57 -28
- package/lib/fields/uuid-field.js +36 -12
- package/lib/fields/virtual-field.js +24 -9
- package/lib/filter-parser.js +288 -179
- package/lib/index.js +210 -29
- package/lib/magic-attribute-model.js +123 -71
- package/lib/mock-database.js +68 -34
- package/lib/model-hook.js +101 -59
- package/lib/model.js +116 -81
- package/lib/operators/array.js +136 -96
- package/lib/operators/association.js +30 -14
- package/lib/operators/date.js +78 -34
- package/lib/operators/empty.js +113 -75
- package/lib/operators/index.js +15 -3
- package/lib/operators/ne.js +27 -12
- package/lib/operators/notIn.js +27 -12
- package/lib/operators/string.js +56 -35
- package/lib/operators/utils.js +18 -10
- package/lib/options-parser.js +323 -215
- package/lib/playground.js +66 -53
- package/lib/relation-repository/belongs-to-many-repository.js +281 -198
- package/lib/relation-repository/belongs-to-repository.js +10 -6
- package/lib/relation-repository/hasmany-repository.js +168 -121
- package/lib/relation-repository/hasone-repository.js +10 -6
- package/lib/relation-repository/multiple-relation-repository.js +263 -148
- package/lib/relation-repository/relation-repository.js +155 -97
- package/lib/relation-repository/single-relation-repository.js +138 -99
- package/lib/relation-repository/types.js +4 -2
- package/lib/repository.js +465 -291
- package/lib/transaction-decorator.js +80 -67
- package/lib/update-associations.js +525 -321
- package/lib/update-guard.js +160 -117
- package/package.json +3 -8
- package/src/database.ts +9 -3
- package/src/mock-database.ts +1 -1
- package/esm/collection-importer.d.ts +0 -7
- package/esm/collection-importer.js +0 -49
- package/esm/collection-importer.js.map +0 -1
- package/esm/collection.d.ts +0 -73
- package/esm/collection.js +0 -224
- package/esm/collection.js.map +0 -1
- package/esm/database.d.ts +0 -104
- package/esm/database.js +0 -305
- package/esm/database.js.map +0 -1
- package/esm/fields/array-field.d.ts +0 -11
- package/esm/fields/array-field.js +0 -26
- package/esm/fields/array-field.js.map +0 -1
- package/esm/fields/belongs-to-field.d.ts +0 -12
- package/esm/fields/belongs-to-field.js +0 -57
- package/esm/fields/belongs-to-field.js.map +0 -1
- package/esm/fields/belongs-to-many-field.d.ts +0 -11
- package/esm/fields/belongs-to-many-field.js +0 -55
- package/esm/fields/belongs-to-many-field.js.map +0 -1
- package/esm/fields/boolean-field.d.ts +0 -8
- package/esm/fields/boolean-field.js +0 -8
- package/esm/fields/boolean-field.js.map +0 -1
- package/esm/fields/context-field.d.ts +0 -13
- package/esm/fields/context-field.js +0 -43
- package/esm/fields/context-field.js.map +0 -1
- package/esm/fields/date-field.d.ts +0 -8
- package/esm/fields/date-field.js +0 -8
- package/esm/fields/date-field.js.map +0 -1
- package/esm/fields/field.d.ts +0 -37
- package/esm/fields/field.js +0 -74
- package/esm/fields/field.js.map +0 -1
- package/esm/fields/has-inverse-field.d.ts +0 -4
- package/esm/fields/has-inverse-field.js +0 -2
- package/esm/fields/has-inverse-field.js.map +0 -1
- package/esm/fields/has-many-field.d.ts +0 -64
- package/esm/fields/has-many-field.js +0 -58
- package/esm/fields/has-many-field.js.map +0 -1
- package/esm/fields/has-one-field.d.ts +0 -64
- package/esm/fields/has-one-field.js +0 -57
- package/esm/fields/has-one-field.js.map +0 -1
- package/esm/fields/index.d.ts +0 -42
- package/esm/fields/index.js +0 -22
- package/esm/fields/index.js.map +0 -1
- package/esm/fields/json-field.d.ts +0 -14
- package/esm/fields/json-field.js +0 -17
- package/esm/fields/json-field.js.map +0 -1
- package/esm/fields/number-field.d.ts +0 -32
- package/esm/fields/number-field.js +0 -28
- package/esm/fields/number-field.js.map +0 -1
- package/esm/fields/password-field.d.ts +0 -21
- package/esm/fields/password-field.js +0 -71
- package/esm/fields/password-field.js.map +0 -1
- package/esm/fields/radio-field.d.ts +0 -14
- package/esm/fields/radio-field.js +0 -49
- package/esm/fields/radio-field.js.map +0 -1
- package/esm/fields/relation-field.d.ts +0 -20
- package/esm/fields/relation-field.js +0 -27
- package/esm/fields/relation-field.js.map +0 -1
- package/esm/fields/sort-field.d.ts +0 -16
- package/esm/fields/sort-field.js +0 -90
- package/esm/fields/sort-field.js.map +0 -1
- package/esm/fields/string-field.d.ts +0 -8
- package/esm/fields/string-field.js +0 -8
- package/esm/fields/string-field.js.map +0 -1
- package/esm/fields/text-field.d.ts +0 -8
- package/esm/fields/text-field.js +0 -8
- package/esm/fields/text-field.js.map +0 -1
- package/esm/fields/time-field.d.ts +0 -8
- package/esm/fields/time-field.js +0 -8
- package/esm/fields/time-field.js.map +0 -1
- package/esm/fields/uid-field.d.ts +0 -10
- package/esm/fields/uid-field.js +0 -27
- package/esm/fields/uid-field.js.map +0 -1
- package/esm/fields/uuid-field.d.ts +0 -9
- package/esm/fields/uuid-field.js +0 -11
- package/esm/fields/uuid-field.js.map +0 -1
- package/esm/fields/virtual-field.d.ts +0 -8
- package/esm/fields/virtual-field.js +0 -8
- package/esm/fields/virtual-field.js.map +0 -1
- package/esm/filter-parser.d.ts +0 -27
- package/esm/filter-parser.js +0 -185
- package/esm/filter-parser.js.map +0 -1
- package/esm/index.d.ts +0 -15
- package/esm/index.js +0 -16
- package/esm/index.js.map +0 -1
- package/esm/magic-attribute-model.d.ts +0 -7
- package/esm/magic-attribute-model.js +0 -70
- package/esm/magic-attribute-model.js.map +0 -1
- package/esm/mock-database.d.ts +0 -22
- package/esm/mock-database.js +0 -34
- package/esm/mock-database.js.map +0 -1
- package/esm/model-hook.d.ts +0 -12
- package/esm/model-hook.js +0 -60
- package/esm/model-hook.js.map +0 -1
- package/esm/model.d.ts +0 -15
- package/esm/model.js +0 -80
- package/esm/model.js.map +0 -1
- package/esm/operators/array.d.ts +0 -26
- package/esm/operators/array.js +0 -105
- package/esm/operators/array.js.map +0 -1
- package/esm/operators/association.d.ts +0 -10
- package/esm/operators/association.js +0 -14
- package/esm/operators/association.js.map +0 -1
- package/esm/operators/date.d.ts +0 -34
- package/esm/operators/date.js +0 -35
- package/esm/operators/date.js.map +0 -1
- package/esm/operators/empty.d.ts +0 -28
- package/esm/operators/empty.js +0 -58
- package/esm/operators/empty.js.map +0 -1
- package/esm/operators/index.d.ts +0 -2
- package/esm/operators/index.js +0 -2
- package/esm/operators/index.js.map +0 -1
- package/esm/operators/ne.d.ts +0 -10
- package/esm/operators/ne.js +0 -12
- package/esm/operators/ne.js.map +0 -1
- package/esm/operators/notIn.d.ts +0 -10
- package/esm/operators/notIn.js +0 -12
- package/esm/operators/notIn.js.map +0 -1
- package/esm/operators/string.d.ts +0 -21
- package/esm/operators/string.js +0 -35
- package/esm/operators/string.js.map +0 -1
- package/esm/operators/utils.d.ts +0 -4
- package/esm/operators/utils.js +0 -11
- package/esm/operators/utils.js.map +0 -1
- package/esm/options-parser.d.ts +0 -31
- package/esm/options-parser.js +0 -225
- package/esm/options-parser.js.map +0 -1
- package/esm/playground.d.ts +0 -1
- package/esm/playground.js +0 -53
- package/esm/playground.js.map +0 -1
- package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
- package/esm/relation-repository/belongs-to-many-repository.js +0 -199
- package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
- package/esm/relation-repository/belongs-to-repository.js +0 -4
- package/esm/relation-repository/belongs-to-repository.js.map +0 -1
- package/esm/relation-repository/hasmany-repository.d.ts +0 -23
- package/esm/relation-repository/hasmany-repository.js +0 -125
- package/esm/relation-repository/hasmany-repository.js.map +0 -1
- package/esm/relation-repository/hasone-repository.d.ts +0 -17
- package/esm/relation-repository/hasone-repository.js +0 -4
- package/esm/relation-repository/hasone-repository.js.map +0 -1
- package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
- package/esm/relation-repository/multiple-relation-repository.js +0 -149
- package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
- package/esm/relation-repository/relation-repository.d.ts +0 -32
- package/esm/relation-repository/relation-repository.js +0 -95
- package/esm/relation-repository/relation-repository.js.map +0 -1
- package/esm/relation-repository/single-relation-repository.d.ts +0 -23
- package/esm/relation-repository/single-relation-repository.js +0 -96
- package/esm/relation-repository/single-relation-repository.js.map +0 -1
- package/esm/relation-repository/types.d.ts +0 -7
- package/esm/relation-repository/types.js +0 -2
- package/esm/relation-repository/types.js.map +0 -1
- package/esm/repository.d.ts +0 -165
- package/esm/repository.js +0 -276
- package/esm/repository.js.map +0 -1
- package/esm/transaction-decorator.d.ts +0 -1
- package/esm/transaction-decorator.js +0 -63
- package/esm/transaction-decorator.js.map +0 -1
- package/esm/update-associations.d.ts +0 -60
- package/esm/update-associations.js +0 -362
- package/esm/update-associations.js.map +0 -1
- package/esm/update-guard.d.ts +0 -26
- package/esm/update-guard.js +0 -122
- package/esm/update-guard.js.map +0 -1
- package/lib/collection-importer.js.map +0 -1
- package/lib/collection.js.map +0 -1
- package/lib/database.js.map +0 -1
- package/lib/fields/array-field.js.map +0 -1
- package/lib/fields/belongs-to-field.js.map +0 -1
- package/lib/fields/belongs-to-many-field.js.map +0 -1
- package/lib/fields/boolean-field.js.map +0 -1
- package/lib/fields/context-field.js.map +0 -1
- package/lib/fields/date-field.js.map +0 -1
- package/lib/fields/field.js.map +0 -1
- package/lib/fields/has-inverse-field.js.map +0 -1
- package/lib/fields/has-many-field.js.map +0 -1
- package/lib/fields/has-one-field.js.map +0 -1
- package/lib/fields/index.js.map +0 -1
- package/lib/fields/json-field.js.map +0 -1
- package/lib/fields/number-field.js.map +0 -1
- package/lib/fields/password-field.js.map +0 -1
- package/lib/fields/radio-field.js.map +0 -1
- package/lib/fields/relation-field.js.map +0 -1
- package/lib/fields/sort-field.js.map +0 -1
- package/lib/fields/string-field.js.map +0 -1
- package/lib/fields/text-field.js.map +0 -1
- package/lib/fields/time-field.js.map +0 -1
- package/lib/fields/uid-field.js.map +0 -1
- package/lib/fields/uuid-field.js.map +0 -1
- package/lib/fields/virtual-field.js.map +0 -1
- package/lib/filter-parser.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/magic-attribute-model.js.map +0 -1
- package/lib/mock-database.js.map +0 -1
- package/lib/model-hook.js.map +0 -1
- package/lib/model.js.map +0 -1
- package/lib/operators/array.js.map +0 -1
- package/lib/operators/association.js.map +0 -1
- package/lib/operators/date.js.map +0 -1
- package/lib/operators/empty.js.map +0 -1
- package/lib/operators/index.js.map +0 -1
- package/lib/operators/ne.js.map +0 -1
- package/lib/operators/notIn.js.map +0 -1
- package/lib/operators/string.js.map +0 -1
- package/lib/operators/utils.js.map +0 -1
- package/lib/options-parser.js.map +0 -1
- package/lib/playground.js.map +0 -1
- package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/lib/relation-repository/belongs-to-repository.js.map +0 -1
- package/lib/relation-repository/hasmany-repository.js.map +0 -1
- package/lib/relation-repository/hasone-repository.js.map +0 -1
- package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
- package/lib/relation-repository/relation-repository.js.map +0 -1
- package/lib/relation-repository/single-relation-repository.js.map +0 -1
- package/lib/relation-repository/types.js.map +0 -1
- package/lib/repository.js.map +0 -1
- package/lib/transaction-decorator.js.map +0 -1
- package/lib/update-associations.js.map +0 -1
- package/lib/update-guard.js.map +0 -1
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
package/lib/database.js
CHANGED
|
@@ -1,334 +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
|
-
|
|
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
|
|
68
131
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
force: false,
|
|
75
|
-
} }, options);
|
|
76
|
-
this.sequelize = new sequelize_1.Sequelize(opts);
|
|
77
|
-
this.options = opts;
|
|
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);
|
|
78
137
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// after collection defined, call bind method on pending fields
|
|
84
|
-
(_a = this.pendingFields.get(collection.name)) === null || _a === void 0 ? void 0 : _a.forEach((field) => field.bind());
|
|
85
|
-
(_b = this.delayCollectionExtend.get(collection.name)) === null || _b === void 0 ? void 0 : _b.forEach((collectionExtend) => {
|
|
86
|
-
collection.updateOptions(collectionExtend.collectionOptions, collectionExtend.mergeOptions);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
// register database field types
|
|
90
|
-
for (const [name, field] of Object.entries(FieldTypes)) {
|
|
91
|
-
if (['Field', 'RelationField'].includes(name)) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
let key = name.replace(/Field$/g, '');
|
|
95
|
-
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
|
96
|
-
this.registerFieldTypes({
|
|
97
|
-
[key]: field,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
this.initOperators();
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Add collection to database
|
|
104
|
-
* @param options
|
|
105
|
-
*/
|
|
106
|
-
collection(options) {
|
|
107
|
-
this.emit('beforeDefineCollection', options);
|
|
108
|
-
const collection = new collection_1.Collection(options, {
|
|
109
|
-
database: this,
|
|
110
|
-
});
|
|
111
|
-
this.collections.set(collection.name, collection);
|
|
112
|
-
this.modelCollection.set(collection.model, collection);
|
|
113
|
-
this.emit('afterDefineCollection', collection);
|
|
114
|
-
return collection;
|
|
115
|
-
}
|
|
116
|
-
getTablePrefix() {
|
|
117
|
-
return this.options.tablePrefix || '';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.sequelize = new (_sequelize().Sequelize)(opts);
|
|
141
|
+
this.options = opts;
|
|
118
142
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
});
|
|
125
170
|
}
|
|
126
|
-
|
|
127
|
-
|
|
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);
|
|
128
215
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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);
|
|
136
234
|
}
|
|
137
|
-
|
|
138
|
-
|
|
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);
|
|
139
253
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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);
|
|
147
263
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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);
|
|
153
273
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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);
|
|
161
283
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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]);
|
|
166
296
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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);
|
|
171
309
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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}`);
|
|
176
318
|
}
|
|
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
|
-
|
|
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;
|
|
207
381
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return result;
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
clean(options) {
|
|
216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
const { drop } = options, others = __rest(options, ["drop"]);
|
|
218
|
-
if (drop) {
|
|
219
|
-
yield this.sequelize.getQueryInterface().dropAllTables(others);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
isSqliteMemory() {
|
|
224
|
-
return this.sequelize.getDialect() === 'sqlite' && lodash_1.default.get(this.options, 'storage') == ':memory:';
|
|
225
|
-
}
|
|
226
|
-
auth(options = {}) {
|
|
227
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
const { repeat = 10 } = options, others = __rest(options, ["repeat"]);
|
|
229
|
-
const delay = (ms) => new Promise((yea) => setTimeout(yea, ms));
|
|
230
|
-
let count = 0;
|
|
231
|
-
const authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
try {
|
|
233
|
-
yield this.sequelize.authenticate(others);
|
|
234
|
-
console.log('Connection has been established successfully.');
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
console.log('reconnecting...', count);
|
|
239
|
-
if (count >= repeat) {
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
++count;
|
|
243
|
-
yield delay(500);
|
|
244
|
-
return yield authenticate();
|
|
245
|
-
}
|
|
246
|
-
});
|
|
382
|
+
|
|
383
|
+
console.log('reconnecting...', count);
|
|
384
|
+
++count;
|
|
385
|
+
yield delay(500);
|
|
247
386
|
return yield authenticate();
|
|
387
|
+
}
|
|
248
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);
|
|
249
441
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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]);
|
|
273
472
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (modelEventName && !this.modelHook.hasBindEvent(modelEventName)) {
|
|
280
|
-
this.sequelize.addHook(modelEventName, this.modelHook.sequelizeHookBuilder(modelEventName));
|
|
281
|
-
this.modelHook.bindEvent(modelEventName);
|
|
473
|
+
} else {
|
|
474
|
+
const collection = _this6.collection(module);
|
|
475
|
+
|
|
476
|
+
result.set(collection.name, collection);
|
|
477
|
+
}
|
|
282
478
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const existCollection = this.getCollection(collectionName);
|
|
294
|
-
if (existCollection) {
|
|
295
|
-
existCollection.updateOptions(module.collectionOptions, module.mergeOptions);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
const existDelayExtends = this.delayCollectionExtend.get(collectionName) || [];
|
|
299
|
-
this.delayCollectionExtend.set(collectionName, [...existDelayExtends, module]);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
const collection = this.collection(module);
|
|
304
|
-
result.set(collection.name, collection);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return result;
|
|
308
|
-
});
|
|
309
|
-
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
_iterator.e(err);
|
|
481
|
+
} finally {
|
|
482
|
+
_iterator.f();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return result;
|
|
486
|
+
})();
|
|
487
|
+
}
|
|
488
|
+
|
|
310
489
|
}
|
|
490
|
+
|
|
311
491
|
exports.Database = Database;
|
|
492
|
+
|
|
312
493
|
function extend(collectionOptions, mergeOptions) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
494
|
+
return {
|
|
495
|
+
collectionOptions,
|
|
496
|
+
mergeOptions,
|
|
497
|
+
extend: true
|
|
498
|
+
};
|
|
318
499
|
}
|
|
319
|
-
|
|
320
|
-
const defineCollection =
|
|
321
|
-
|
|
500
|
+
|
|
501
|
+
const defineCollection = collectionOptions => {
|
|
502
|
+
return collectionOptions;
|
|
322
503
|
};
|
|
504
|
+
|
|
323
505
|
exports.defineCollection = defineCollection;
|
|
506
|
+
|
|
324
507
|
const extendCollection = (collectionOptions, mergeOptions) => {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
508
|
+
return {
|
|
509
|
+
collectionOptions,
|
|
510
|
+
mergeOptions,
|
|
511
|
+
extend: true
|
|
512
|
+
};
|
|
330
513
|
};
|
|
514
|
+
|
|
331
515
|
exports.extendCollection = extendCollection;
|
|
332
|
-
(0,
|
|
333
|
-
|
|
334
|
-
|
|
516
|
+
(0, _utils().applyMixins)(Database, [_utils().AsyncEmitter]);
|
|
517
|
+
var _default = Database;
|
|
518
|
+
exports.default = _default;
|