@nocobase/database 0.7.0-alpha.6 → 0.7.0-alpha.62
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 +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.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/context-field.ts +1 -1
- package/src/fields/index.ts +3 -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
|
@@ -1,30 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.ArrayField = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
super.bind();
|
|
22
|
-
this.on('beforeSave', this.sortValue.bind(this));
|
|
7
|
+
|
|
8
|
+
var _field = require("./field");
|
|
9
|
+
|
|
10
|
+
function _sequelize() {
|
|
11
|
+
const data = require("sequelize");
|
|
12
|
+
|
|
13
|
+
_sequelize = function _sequelize() {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class ArrayField extends _field.Field {
|
|
21
|
+
get dataType() {
|
|
22
|
+
if (this.database.sequelize.getDialect() === 'postgres') {
|
|
23
|
+
return _sequelize().DataTypes.JSONB;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
return _sequelize().DataTypes.JSON;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
sortValue(model) {
|
|
30
|
+
const oldValue = model.get(this.options.name);
|
|
31
|
+
|
|
32
|
+
if (oldValue) {
|
|
33
|
+
const newValue = oldValue.sort();
|
|
34
|
+
model.set(this.options.name, newValue);
|
|
27
35
|
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bind() {
|
|
39
|
+
super.bind();
|
|
40
|
+
this.on('beforeSave', this.sortValue.bind(this));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
unbind() {
|
|
44
|
+
super.unbind();
|
|
45
|
+
this.off('beforeSave', this.sortValue.bind(this));
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
}
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
|
|
50
|
+
exports.ArrayField = ArrayField;
|
|
@@ -1,61 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.BelongsToField = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = 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 _relationField = require("./relation-field");
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
+
|
|
34
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
|
+
|
|
36
|
+
class BelongsToField extends _relationField.RelationField {
|
|
37
|
+
get target() {
|
|
38
|
+
const _this$options = this.options,
|
|
39
|
+
target = _this$options.target,
|
|
40
|
+
name = _this$options.name;
|
|
41
|
+
return target || _sequelize().Utils.pluralize(name);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
bind() {
|
|
45
|
+
const _this$context = this.context,
|
|
46
|
+
database = _this$context.database,
|
|
47
|
+
collection = _this$context.collection;
|
|
48
|
+
const Target = this.TargetModel; // if target model not exists, add it to pending field,
|
|
49
|
+
// it will bind later
|
|
50
|
+
|
|
51
|
+
if (!Target) {
|
|
52
|
+
database.addPendingField(this);
|
|
53
|
+
return false;
|
|
11
54
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// 建立关系之后从 pending 列表中删除
|
|
29
|
-
database.removePendingField(this);
|
|
30
|
-
if (!this.options.foreignKey) {
|
|
31
|
-
this.options.foreignKey = association.foreignKey;
|
|
32
|
-
}
|
|
33
|
-
if (!this.options.sourceKey) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
this.options.sourceKey = association.sourceKey;
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
55
|
+
|
|
56
|
+
if (collection.model.associations[this.name]) {
|
|
57
|
+
delete collection.model.associations[this.name];
|
|
58
|
+
} // define relation on sequelize model
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const association = collection.model.belongsTo(Target, _objectSpread({
|
|
62
|
+
as: this.name
|
|
63
|
+
}, (0, _lodash().omit)(this.options, ['name', 'type', 'target']))); // inverse relation
|
|
64
|
+
// this.TargetModel.hasMany(collection.model);
|
|
65
|
+
// 建立关系之后从 pending 列表中删除
|
|
66
|
+
|
|
67
|
+
database.removePendingField(this);
|
|
68
|
+
|
|
69
|
+
if (!this.options.foreignKey) {
|
|
70
|
+
this.options.foreignKey = association.foreignKey;
|
|
38
71
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// 如果外键没有显式的创建,关系表也无反向关联字段,删除关系时,外键也删除掉
|
|
44
|
-
const tcoll = database.collections.get(this.target);
|
|
45
|
-
const foreignKey = this.options.foreignKey;
|
|
46
|
-
const field1 = collection.getField(foreignKey);
|
|
47
|
-
const field2 = tcoll.findField((field) => {
|
|
48
|
-
return field.type === 'hasMany' && field.foreignKey === foreignKey;
|
|
49
|
-
});
|
|
50
|
-
if (!field1 && !field2) {
|
|
51
|
-
collection.model.removeAttribute(foreignKey);
|
|
52
|
-
}
|
|
53
|
-
// 删掉 model 的关联字段
|
|
54
|
-
delete collection.model.associations[this.name];
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
collection.model.refreshAttributes();
|
|
72
|
+
|
|
73
|
+
if (!this.options.sourceKey) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
this.options.sourceKey = association.sourceKey;
|
|
57
76
|
}
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
unbind() {
|
|
82
|
+
const _this$context2 = this.context,
|
|
83
|
+
database = _this$context2.database,
|
|
84
|
+
collection = _this$context2.collection; // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
|
|
85
|
+
|
|
86
|
+
database.removePendingField(this); // 如果外键没有显式的创建,关系表也无反向关联字段,删除关系时,外键也删除掉
|
|
87
|
+
|
|
88
|
+
const tcoll = database.collections.get(this.target);
|
|
89
|
+
const foreignKey = this.options.foreignKey;
|
|
90
|
+
const field1 = collection.getField(foreignKey);
|
|
91
|
+
const field2 = tcoll.findField(field => {
|
|
92
|
+
return field.type === 'hasMany' && field.foreignKey === foreignKey;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (!field1 && !field2) {
|
|
96
|
+
collection.model.removeAttribute(foreignKey);
|
|
97
|
+
} // 删掉 model 的关联字段
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
delete collection.model.associations[this.name]; // @ts-ignore
|
|
101
|
+
|
|
102
|
+
collection.model.refreshAttributes();
|
|
103
|
+
}
|
|
104
|
+
|
|
58
105
|
}
|
|
106
|
+
|
|
59
107
|
exports.BelongsToField = BelongsToField;
|
|
60
|
-
BelongsToField.type = 'belongsTo';
|
|
61
|
-
//# sourceMappingURL=belongs-to-field.js.map
|
|
108
|
+
BelongsToField.type = 'belongsTo';
|
|
@@ -1,59 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.BelongsToManyField = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = 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 _relationField = require("./relation-field");
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
+
|
|
34
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
|
+
|
|
36
|
+
class BelongsToManyField extends _relationField.RelationField {
|
|
37
|
+
get through() {
|
|
38
|
+
return this.options.through || _sequelize().Utils.camelize([this.context.collection.model.name, this.target].map(name => name.toLowerCase()).sort().join('_'));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
bind() {
|
|
42
|
+
const _this$context = this.context,
|
|
43
|
+
database = _this$context.database,
|
|
44
|
+
collection = _this$context.collection;
|
|
45
|
+
const Target = this.TargetModel;
|
|
46
|
+
|
|
47
|
+
if (!Target) {
|
|
48
|
+
database.addPendingField(this);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const through = this.through;
|
|
53
|
+
let Through;
|
|
54
|
+
|
|
55
|
+
if (database.hasCollection(through)) {
|
|
56
|
+
Through = database.getCollection(through);
|
|
57
|
+
} else {
|
|
58
|
+
Through = database.collection({
|
|
59
|
+
name: through
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(Through.model, 'isThrough', {
|
|
62
|
+
value: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const association = collection.model.belongsToMany(Target, _objectSpread(_objectSpread({}, (0, _lodash().omit)(this.options, ['name', 'type', 'target'])), {}, {
|
|
67
|
+
as: this.name,
|
|
68
|
+
through: Through.model
|
|
69
|
+
})); // 建立关系之后从 pending 列表中删除
|
|
70
|
+
|
|
71
|
+
database.removePendingField(this);
|
|
72
|
+
|
|
73
|
+
if (!this.options.foreignKey) {
|
|
74
|
+
this.options.foreignKey = association.foreignKey;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!this.options.sourceKey) {
|
|
78
|
+
this.options.sourceKey = association.sourceKey;
|
|
14
79
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!Target) {
|
|
19
|
-
database.addPendingField(this);
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
const through = this.through;
|
|
23
|
-
let Through;
|
|
24
|
-
if (database.hasCollection(through)) {
|
|
25
|
-
Through = database.getCollection(through);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
Through = database.collection({
|
|
29
|
-
name: through,
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(Through.model, 'isThrough', { value: true });
|
|
32
|
-
}
|
|
33
|
-
const association = collection.model.belongsToMany(Target, Object.assign(Object.assign({}, (0, lodash_1.omit)(this.options, ['name', 'type', 'target'])), { as: this.name, through: Through.model }));
|
|
34
|
-
// 建立关系之后从 pending 列表中删除
|
|
35
|
-
database.removePendingField(this);
|
|
36
|
-
if (!this.options.foreignKey) {
|
|
37
|
-
this.options.foreignKey = association.foreignKey;
|
|
38
|
-
}
|
|
39
|
-
if (!this.options.sourceKey) {
|
|
40
|
-
this.options.sourceKey = association.sourceKey;
|
|
41
|
-
}
|
|
42
|
-
if (!this.options.otherKey) {
|
|
43
|
-
this.options.otherKey = association.otherKey;
|
|
44
|
-
}
|
|
45
|
-
if (!this.options.through) {
|
|
46
|
-
this.options.through = this.through;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
80
|
+
|
|
81
|
+
if (!this.options.otherKey) {
|
|
82
|
+
this.options.otherKey = association.otherKey;
|
|
49
83
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
database.removePendingField(this);
|
|
54
|
-
// 删掉 model 的关联字段
|
|
55
|
-
delete collection.model.associations[this.name];
|
|
84
|
+
|
|
85
|
+
if (!this.options.through) {
|
|
86
|
+
this.options.through = this.through;
|
|
56
87
|
}
|
|
88
|
+
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
unbind() {
|
|
93
|
+
const _this$context2 = this.context,
|
|
94
|
+
database = _this$context2.database,
|
|
95
|
+
collection = _this$context2.collection; // 如果关系字段还没建立就删除了,也同步删除待建立关联的关系字段
|
|
96
|
+
|
|
97
|
+
database.removePendingField(this); // 删掉 model 的关联字段
|
|
98
|
+
|
|
99
|
+
delete collection.model.associations[this.name];
|
|
100
|
+
}
|
|
101
|
+
|
|
57
102
|
}
|
|
58
|
-
|
|
59
|
-
|
|
103
|
+
|
|
104
|
+
exports.BelongsToManyField = BelongsToManyField;
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.BooleanField = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
function _sequelize() {
|
|
9
|
+
const data = require("sequelize");
|
|
10
|
+
|
|
11
|
+
_sequelize = function _sequelize() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
10
16
|
}
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
|
|
18
|
+
var _field = require("./field");
|
|
19
|
+
|
|
20
|
+
class BooleanField extends _field.Field {
|
|
21
|
+
get dataType() {
|
|
22
|
+
return _sequelize().DataTypes.BOOLEAN;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.BooleanField = BooleanField;
|
|
@@ -1,47 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
12
6
|
exports.ContextField = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
10
|
+
|
|
11
|
+
_lodash = function _lodash() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _sequelize() {
|
|
19
|
+
const data = require("sequelize");
|
|
20
|
+
|
|
21
|
+
_sequelize = function _sequelize() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _field = require("./field");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
33
|
+
|
|
34
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
35
|
+
|
|
36
|
+
class ContextField extends _field.Field {
|
|
37
|
+
get dataType() {
|
|
38
|
+
const type = this.options.dataType || 'string';
|
|
39
|
+
return _sequelize().DataTypes[type.toUpperCase()] || _sequelize().DataTypes.STRING;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
init() {
|
|
43
|
+
const _this$options = this.options,
|
|
44
|
+
name = _this$options.name,
|
|
45
|
+
dataIndex = _this$options.dataIndex;
|
|
46
|
+
|
|
47
|
+
this.listener = /*#__PURE__*/function () {
|
|
48
|
+
var _ref = _asyncToGenerator(function* (model, options) {
|
|
49
|
+
const context = options.context;
|
|
50
|
+
model.set(name, _lodash().default.get(context, dataIndex));
|
|
51
|
+
model.changed(name, true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return function (_x, _x2) {
|
|
55
|
+
return _ref.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
}();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bind() {
|
|
61
|
+
super.bind();
|
|
62
|
+
const createOnly = this.options.createOnly;
|
|
63
|
+
this.on('beforeCreate', this.listener);
|
|
64
|
+
|
|
65
|
+
if (!createOnly) {
|
|
66
|
+
this.on('beforeUpdate', this.listener);
|
|
36
67
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
unbind() {
|
|
71
|
+
super.unbind();
|
|
72
|
+
const createOnly = this.options.createOnly;
|
|
73
|
+
this.off('beforeCreate', this.listener);
|
|
74
|
+
|
|
75
|
+
if (!createOnly) {
|
|
76
|
+
this.off('beforeUpdate', this.listener);
|
|
44
77
|
}
|
|
78
|
+
}
|
|
79
|
+
|
|
45
80
|
}
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
|
|
82
|
+
exports.ContextField = ContextField;
|
package/lib/fields/date-field.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.DateField = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
function _sequelize() {
|
|
9
|
+
const data = require("sequelize");
|
|
10
|
+
|
|
11
|
+
_sequelize = function _sequelize() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
10
16
|
}
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
|
|
18
|
+
var _field = require("./field");
|
|
19
|
+
|
|
20
|
+
class DateField extends _field.Field {
|
|
21
|
+
get dataType() {
|
|
22
|
+
return _sequelize().DataTypes.DATE;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.DateField = DateField;
|