@nocobase/database 0.7.0-alpha.6 → 0.7.0-alpha.60
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
package/lib/playground.js
CHANGED
|
@@ -1,55 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const db = new database_1.Database({
|
|
14
|
-
dialect: 'sqlite',
|
|
15
|
-
dialectModule: require('sqlite3'),
|
|
16
|
-
storage: ':memory:',
|
|
2
|
+
|
|
3
|
+
var _database = require("./database");
|
|
4
|
+
|
|
5
|
+
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); } }
|
|
6
|
+
|
|
7
|
+
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); }); }; }
|
|
8
|
+
|
|
9
|
+
const db = new _database.Database({
|
|
10
|
+
dialect: 'sqlite',
|
|
11
|
+
dialectModule: require('sqlite3'),
|
|
12
|
+
storage: ':memory:'
|
|
17
13
|
});
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
14
|
+
|
|
15
|
+
_asyncToGenerator(function* () {
|
|
16
|
+
const User = db.collection({
|
|
17
|
+
name: 'users',
|
|
18
|
+
fields: [{
|
|
19
|
+
type: 'string',
|
|
20
|
+
name: 'name'
|
|
21
|
+
}]
|
|
22
|
+
});
|
|
23
|
+
const Post = db.collection({
|
|
24
|
+
name: 'posts',
|
|
25
|
+
fields: [{
|
|
26
|
+
type: 'string',
|
|
27
|
+
name: 'title'
|
|
28
|
+
}, {
|
|
29
|
+
type: 'belongsTo',
|
|
30
|
+
name: 'user'
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
yield db.sync();
|
|
34
|
+
const repository = User.repository;
|
|
35
|
+
yield repository.createMany({
|
|
36
|
+
records: [{
|
|
37
|
+
name: 'u1',
|
|
38
|
+
posts: [{
|
|
39
|
+
title: 'u1t1'
|
|
40
|
+
}]
|
|
41
|
+
}, {
|
|
42
|
+
name: 'u2',
|
|
43
|
+
posts: [{
|
|
44
|
+
title: 'u2t1'
|
|
45
|
+
}]
|
|
46
|
+
}, {
|
|
47
|
+
name: 'u3',
|
|
48
|
+
posts: [{
|
|
49
|
+
title: 'u3t1'
|
|
50
|
+
}]
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
const Model = User.model;
|
|
54
|
+
const user = yield Model.findOne({
|
|
55
|
+
subQuery: false,
|
|
56
|
+
where: {
|
|
57
|
+
'$posts.title$': 'u1t1'
|
|
58
|
+
},
|
|
59
|
+
include: {
|
|
60
|
+
association: 'posts',
|
|
61
|
+
attributes: []
|
|
62
|
+
},
|
|
63
|
+
attributes: {
|
|
64
|
+
include: []
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
console.log(user.toJSON());
|
|
68
|
+
})();
|
|
@@ -1,206 +1,289 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
21
6
|
exports.BelongsToManyRepository = void 0;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
transaction,
|
|
124
|
-
});
|
|
125
|
-
yield (0, update_associations_1.updateThroughTableValue)(instance, this.throughName(), throughValues, sourceModel, transaction);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
add(options) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
yield this.setTargets('add', options);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
set(options) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
yield this.setTargets('set', options);
|
|
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 _updateAssociations = require("../update-associations");
|
|
29
|
+
|
|
30
|
+
var _multipleRelationRepository = require("./multiple-relation-repository");
|
|
31
|
+
|
|
32
|
+
var _relationRepository = require("./relation-repository");
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
|
|
36
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
37
|
+
|
|
38
|
+
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."); }
|
|
39
|
+
|
|
40
|
+
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); }
|
|
41
|
+
|
|
42
|
+
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; }
|
|
43
|
+
|
|
44
|
+
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; }
|
|
45
|
+
|
|
46
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
47
|
+
|
|
48
|
+
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; }
|
|
49
|
+
|
|
50
|
+
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; }
|
|
51
|
+
|
|
52
|
+
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; }
|
|
53
|
+
|
|
54
|
+
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); } }
|
|
55
|
+
|
|
56
|
+
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); }); }; }
|
|
57
|
+
|
|
58
|
+
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
|
|
59
|
+
var c = arguments.length,
|
|
60
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
61
|
+
d;
|
|
62
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
class BelongsToManyRepository extends _multipleRelationRepository.MultipleRelationRepository {
|
|
67
|
+
create(options) {
|
|
68
|
+
var _this = this;
|
|
69
|
+
|
|
70
|
+
return _asyncToGenerator(function* () {
|
|
71
|
+
const transaction = yield _this.getTransaction(options);
|
|
72
|
+
|
|
73
|
+
const createAccessor = _this.accessors().create;
|
|
74
|
+
|
|
75
|
+
const values = options.values || {};
|
|
76
|
+
const sourceModel = yield _this.getSourceModel(transaction);
|
|
77
|
+
|
|
78
|
+
const createOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
79
|
+
through: values[_this.throughName()],
|
|
80
|
+
transaction
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return sourceModel[createAccessor](values, createOptions);
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
destroy(options) {
|
|
88
|
+
var _this2 = this;
|
|
89
|
+
|
|
90
|
+
return _asyncToGenerator(function* () {
|
|
91
|
+
const transaction = yield _this2.getTransaction(options);
|
|
92
|
+
const association = _this2.association;
|
|
93
|
+
|
|
94
|
+
const instancesToIds = instances => {
|
|
95
|
+
return instances.map(instance => instance.get(_this2.targetKey()));
|
|
96
|
+
}; // Through Table
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const throughTableWhere = [{
|
|
100
|
+
[association.foreignKey]: _this2.sourceKeyValue
|
|
101
|
+
}];
|
|
102
|
+
let ids;
|
|
103
|
+
|
|
104
|
+
if (options && options['filter']) {
|
|
105
|
+
const instances = yield _this2.find({
|
|
106
|
+
filter: options['filter'],
|
|
107
|
+
transaction
|
|
138
108
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
return;
|
|
109
|
+
ids = instancesToIds(instances);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (options && options['filterByTk']) {
|
|
113
|
+
const instances = _this2.association.toInstanceArray(options['filterByTk']);
|
|
114
|
+
|
|
115
|
+
ids = ids ? _lodash().default.intersection(ids, instancesToIds(instances)) : instancesToIds(instances);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (options && !options['filterByTk'] && !options['filter']) {
|
|
119
|
+
const sourceModel = yield _this2.getSourceModel(transaction);
|
|
120
|
+
const instances = yield sourceModel[_this2.accessors().get]({
|
|
121
|
+
transaction
|
|
154
122
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
123
|
+
ids = instancesToIds(instances);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
throughTableWhere.push({
|
|
127
|
+
[association.otherKey]: {
|
|
128
|
+
[_sequelize().Op.in]: ids
|
|
160
129
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
130
|
+
}); // delete through table data
|
|
131
|
+
|
|
132
|
+
yield _this2.throughModel().destroy({
|
|
133
|
+
where: throughTableWhere,
|
|
134
|
+
transaction
|
|
135
|
+
});
|
|
136
|
+
yield _this2.targetModel.destroy({
|
|
137
|
+
where: {
|
|
138
|
+
[_this2.targetKey()]: {
|
|
139
|
+
[_sequelize().Op.in]: ids
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
transaction
|
|
143
|
+
});
|
|
144
|
+
return true;
|
|
145
|
+
})();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setTargets(call, options) {
|
|
149
|
+
var _this3 = this;
|
|
150
|
+
|
|
151
|
+
return _asyncToGenerator(function* () {
|
|
152
|
+
let handleKeys;
|
|
153
|
+
const transaction = yield _this3.getTransaction(options, false);
|
|
154
|
+
|
|
155
|
+
if (_lodash().default.isPlainObject(options)) {
|
|
156
|
+
options = options.tk || [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (_lodash().default.isString(options) || _lodash().default.isNumber(options)) {
|
|
160
|
+
handleKeys = [options];
|
|
161
|
+
} // if it is type primaryKeyWithThroughValues
|
|
162
|
+
else if (_lodash().default.isArray(options) && options.length == 2 && _lodash().default.isPlainObject(options[0][1])) {
|
|
163
|
+
handleKeys = [options];
|
|
164
|
+
} else {
|
|
165
|
+
handleKeys = options;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const sourceModel = yield _this3.getSourceModel(transaction);
|
|
169
|
+
const setObj = handleKeys.reduce((carry, item) => {
|
|
170
|
+
if (Array.isArray(item)) {
|
|
171
|
+
carry[item[0]] = item[1];
|
|
172
|
+
} else {
|
|
173
|
+
carry[item] = true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return carry;
|
|
177
|
+
}, {});
|
|
178
|
+
yield sourceModel[_this3.accessors()[call]](Object.keys(setObj), {
|
|
179
|
+
transaction
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
for (var _i = 0, _Object$entries = Object.entries(setObj); _i < _Object$entries.length; _i++) {
|
|
183
|
+
const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
184
|
+
id = _Object$entries$_i[0],
|
|
185
|
+
throughValues = _Object$entries$_i[1];
|
|
186
|
+
|
|
187
|
+
if (typeof throughValues === 'object') {
|
|
188
|
+
const instance = yield _this3.targetModel.findByPk(id, {
|
|
189
|
+
transaction
|
|
190
|
+
});
|
|
191
|
+
yield (0, _updateAssociations.updateThroughTableValue)(instance, _this3.throughName(), throughValues, sourceModel, transaction);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
})();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
add(options) {
|
|
198
|
+
var _this4 = this;
|
|
199
|
+
|
|
200
|
+
return _asyncToGenerator(function* () {
|
|
201
|
+
yield _this4.setTargets('add', options);
|
|
202
|
+
})();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
set(options) {
|
|
206
|
+
var _this5 = this;
|
|
207
|
+
|
|
208
|
+
return _asyncToGenerator(function* () {
|
|
209
|
+
yield _this5.setTargets('set', options);
|
|
210
|
+
})();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
toggle(options) {
|
|
214
|
+
var _this6 = this;
|
|
215
|
+
|
|
216
|
+
return _asyncToGenerator(function* () {
|
|
217
|
+
const transaction = yield _this6.getTransaction(options);
|
|
218
|
+
const sourceModel = yield _this6.getSourceModel(transaction);
|
|
219
|
+
const has = yield sourceModel[_this6.accessors().hasSingle](options['tk'], {
|
|
220
|
+
transaction
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
if (has) {
|
|
224
|
+
yield _this6.remove(_objectSpread(_objectSpread({}, options), {}, {
|
|
225
|
+
transaction
|
|
226
|
+
}));
|
|
227
|
+
} else {
|
|
228
|
+
yield _this6.add(_objectSpread(_objectSpread({}, options), {}, {
|
|
229
|
+
transaction
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return;
|
|
234
|
+
})();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
extendFindOptions(findOptions) {
|
|
238
|
+
let joinTableAttributes;
|
|
239
|
+
|
|
240
|
+
if (_lodash().default.get(findOptions, 'fields')) {
|
|
241
|
+
joinTableAttributes = [];
|
|
168
242
|
}
|
|
243
|
+
|
|
244
|
+
return _objectSpread(_objectSpread({}, findOptions), {}, {
|
|
245
|
+
joinTableAttributes
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
throughName() {
|
|
250
|
+
return this.throughModel().name;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
throughModel() {
|
|
254
|
+
return this.association.through.model;
|
|
255
|
+
}
|
|
256
|
+
|
|
169
257
|
}
|
|
170
|
-
|
|
171
|
-
(0, relation_repository_1.transaction)()
|
|
172
|
-
], BelongsToManyRepository.prototype, "create", null);
|
|
173
|
-
__decorate([
|
|
174
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
175
|
-
return {
|
|
176
|
-
filterByTk: args[0],
|
|
177
|
-
transaction,
|
|
178
|
-
};
|
|
179
|
-
})
|
|
180
|
-
], BelongsToManyRepository.prototype, "destroy", null);
|
|
181
|
-
__decorate([
|
|
182
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
183
|
-
return {
|
|
184
|
-
tk: args[0],
|
|
185
|
-
transaction,
|
|
186
|
-
};
|
|
187
|
-
})
|
|
188
|
-
], BelongsToManyRepository.prototype, "add", null);
|
|
189
|
-
__decorate([
|
|
190
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
191
|
-
return {
|
|
192
|
-
tk: args[0],
|
|
193
|
-
transaction,
|
|
194
|
-
};
|
|
195
|
-
})
|
|
196
|
-
], BelongsToManyRepository.prototype, "set", null);
|
|
197
|
-
__decorate([
|
|
198
|
-
(0, relation_repository_1.transaction)((args, transaction) => {
|
|
199
|
-
return {
|
|
200
|
-
tk: args[0],
|
|
201
|
-
transaction,
|
|
202
|
-
};
|
|
203
|
-
})
|
|
204
|
-
], BelongsToManyRepository.prototype, "toggle", null);
|
|
258
|
+
|
|
205
259
|
exports.BelongsToManyRepository = BelongsToManyRepository;
|
|
206
|
-
|
|
260
|
+
|
|
261
|
+
__decorate([(0, _relationRepository.transaction)()], BelongsToManyRepository.prototype, "create", null);
|
|
262
|
+
|
|
263
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
264
|
+
return {
|
|
265
|
+
filterByTk: args[0],
|
|
266
|
+
transaction
|
|
267
|
+
};
|
|
268
|
+
})], BelongsToManyRepository.prototype, "destroy", null);
|
|
269
|
+
|
|
270
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
271
|
+
return {
|
|
272
|
+
tk: args[0],
|
|
273
|
+
transaction
|
|
274
|
+
};
|
|
275
|
+
})], BelongsToManyRepository.prototype, "add", null);
|
|
276
|
+
|
|
277
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
278
|
+
return {
|
|
279
|
+
tk: args[0],
|
|
280
|
+
transaction
|
|
281
|
+
};
|
|
282
|
+
})], BelongsToManyRepository.prototype, "set", null);
|
|
283
|
+
|
|
284
|
+
__decorate([(0, _relationRepository.transaction)((args, transaction) => {
|
|
285
|
+
return {
|
|
286
|
+
tk: args[0],
|
|
287
|
+
transaction
|
|
288
|
+
};
|
|
289
|
+
})], BelongsToManyRepository.prototype, "toggle", null);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.BelongsToRepository = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
var _singleRelationRepository = require("./single-relation-repository");
|
|
9
|
+
|
|
10
|
+
class BelongsToRepository extends _singleRelationRepository.SingleRelationRepository {}
|
|
11
|
+
|
|
12
|
+
exports.BelongsToRepository = BelongsToRepository;
|