@nocobase/database 0.9.1-alpha.1 → 0.9.2-alpha.1
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-group-manager.d.ts +13 -0
- package/lib/collection-group-manager.js +91 -0
- package/lib/collection-importer.js +0 -24
- package/lib/collection.d.ts +26 -4
- package/lib/collection.js +190 -234
- package/lib/database-utils/index.js +3 -15
- package/lib/database.d.ts +9 -0
- package/lib/database.js +171 -299
- package/lib/decorators/must-have-filter-decorator.js +0 -7
- package/lib/decorators/transaction-decorator.js +5 -18
- package/lib/errors/identifier-error.js +0 -3
- package/lib/features/ReferencesMap.js +1 -14
- package/lib/features/referential-integrity-check.js +7 -21
- package/lib/field-repository/array-field-repository.js +5 -45
- package/lib/fields/array-field.js +0 -13
- package/lib/fields/belongs-to-field.js +24 -50
- package/lib/fields/belongs-to-many-field.js +29 -47
- package/lib/fields/boolean-field.js +0 -7
- package/lib/fields/context-field.js +2 -23
- package/lib/fields/date-field.d.ts +4 -0
- package/lib/fields/date-field.js +15 -7
- package/lib/fields/field.js +32 -85
- package/lib/fields/has-many-field.js +16 -49
- package/lib/fields/has-one-field.js +18 -52
- package/lib/fields/index.js +0 -44
- package/lib/fields/json-field.js +0 -12
- package/lib/fields/number-field.js +0 -23
- package/lib/fields/password-field.js +8 -35
- package/lib/fields/radio-field.js +0 -18
- package/lib/fields/relation-field.js +4 -16
- package/lib/fields/set-field.js +0 -8
- package/lib/fields/sort-field.js +84 -73
- package/lib/fields/string-field.js +0 -7
- package/lib/fields/text-field.js +0 -7
- package/lib/fields/time-field.js +0 -7
- package/lib/fields/uid-field.js +4 -22
- package/lib/fields/uuid-field.js +3 -12
- package/lib/fields/virtual-field.js +0 -7
- package/lib/filter-match.js +7 -22
- package/lib/filter-parser.js +38 -102
- package/lib/index.d.ts +3 -0
- package/lib/index.js +36 -42
- package/lib/inherited-collection.js +15 -62
- package/lib/inherited-map.js +7 -48
- package/lib/listeners/adjacency-list.d.ts +3 -0
- package/lib/listeners/adjacency-list.js +91 -0
- package/lib/listeners/index.d.ts +2 -0
- package/lib/listeners/index.js +12 -0
- package/lib/magic-attribute-model.js +58 -114
- package/lib/migration.js +7 -28
- package/lib/mock-database.d.ts +4 -4
- package/lib/mock-database.js +15 -18
- package/lib/model-hook.js +4 -35
- package/lib/model.js +12 -54
- package/lib/operators/array.js +2 -32
- package/lib/operators/association.js +0 -6
- package/lib/operators/boolean.js +0 -6
- package/lib/operators/child-collection.d.ts +2 -0
- package/lib/operators/child-collection.js +32 -0
- package/lib/operators/date.js +123 -60
- package/lib/operators/empty.js +3 -32
- package/lib/operators/eq.d.ts +2 -0
- package/lib/operators/eq.js +26 -0
- package/lib/operators/index.js +4 -7
- package/lib/operators/ne.js +5 -5
- package/lib/operators/notIn.js +0 -5
- package/lib/operators/string.js +0 -11
- package/lib/operators/utils.js +0 -6
- package/lib/options-parser.d.ts +1 -1
- package/lib/options-parser.js +47 -107
- package/lib/playground.js +0 -4
- package/lib/query-interface/mysql-query-interface.d.ts +18 -0
- package/lib/query-interface/mysql-query-interface.js +88 -0
- package/lib/query-interface/postgres-query-interface.d.ts +14 -0
- package/lib/query-interface/postgres-query-interface.js +99 -0
- package/lib/query-interface/query-interface-builder.d.ts +2 -0
- package/lib/query-interface/query-interface-builder.js +18 -0
- package/lib/query-interface/query-interface.d.ts +21 -0
- package/lib/query-interface/query-interface.js +48 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +17 -0
- package/lib/query-interface/sqlite-query-interface.js +89 -0
- package/lib/relation-repository/belongs-to-many-repository.js +21 -78
- package/lib/relation-repository/belongs-to-repository.js +0 -3
- package/lib/relation-repository/hasmany-repository.js +8 -44
- package/lib/relation-repository/hasone-repository.js +0 -3
- package/lib/relation-repository/multiple-relation-repository.js +16 -68
- package/lib/relation-repository/relation-repository.js +5 -42
- package/lib/relation-repository/single-relation-repository.js +6 -43
- package/lib/repository.d.ts +1 -0
- package/lib/repository.js +36 -182
- package/lib/sql-parser/index.js +10527 -0
- package/lib/sql-parser/sql.pegjs +1297 -0
- package/lib/sync-runner.d.ts +1 -1
- package/lib/sync-runner.js +26 -64
- package/lib/update-associations.js +58 -157
- package/lib/update-guard.js +10 -49
- package/lib/utils.js +16 -54
- package/lib/value-parsers/array-value-parser.js +3 -21
- package/lib/value-parsers/base-value-parser.js +0 -13
- package/lib/value-parsers/boolean-value-parser.js +4 -10
- package/lib/value-parsers/date-value-parser.js +0 -23
- package/lib/value-parsers/index.js +0 -10
- package/lib/value-parsers/json-value-parser.js +0 -7
- package/lib/value-parsers/number-value-parser.js +0 -9
- package/lib/value-parsers/string-value-parser.js +3 -20
- package/lib/value-parsers/to-many-value-parser.js +1 -42
- package/lib/value-parsers/to-one-value-parser.js +0 -14
- package/lib/view/field-type-map.d.ts +47 -0
- package/lib/view/field-type-map.js +56 -0
- package/lib/view/view-inference.d.ts +31 -0
- package/lib/view/view-inference.js +92 -0
- package/lib/view-collection.d.ts +6 -0
- package/lib/view-collection.js +24 -0
- package/package.json +4 -3
- package/src/__tests__/collection.test.ts +44 -0
- package/src/__tests__/fields/date.test.ts +75 -0
- package/src/__tests__/fields/sort-field.test.ts +100 -0
- package/src/__tests__/filter.test.ts +60 -0
- package/src/__tests__/group.test.ts +50 -0
- package/src/__tests__/inhertits/collection-inherits.test.ts +114 -0
- package/src/__tests__/operator/date-operator.test.ts +244 -98
- package/src/__tests__/operator/eq.test.ts +76 -0
- package/src/__tests__/operator/ne.test.ts +19 -1
- package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +82 -0
- package/src/__tests__/repository/find.test.ts +33 -0
- package/src/__tests__/repository.test.ts +88 -0
- package/src/__tests__/sql-parser.test.ts +13 -0
- package/src/__tests__/tree.test.ts +217 -0
- package/src/__tests__/view/list-view.test.ts +34 -0
- package/src/__tests__/view/view-collection.test.ts +199 -0
- package/src/__tests__/view/view-inference.test.ts +145 -0
- package/src/__tests__/view/view-repository.test.ts +67 -0
- package/src/collection-group-manager.ts +94 -0
- package/src/collection.ts +126 -16
- package/src/database-utils/index.ts +1 -0
- package/src/database.ts +98 -17
- package/src/features/ReferencesMap.ts +3 -2
- package/src/fields/belongs-to-many-field.ts +23 -4
- package/src/fields/date-field.ts +18 -0
- package/src/fields/field.ts +17 -7
- package/src/fields/json-field.ts +1 -0
- package/src/fields/sort-field.ts +90 -29
- package/src/filter-parser.ts +2 -1
- package/src/index.ts +3 -1
- package/src/listeners/adjacency-list.ts +60 -0
- package/src/listeners/index.ts +7 -0
- package/src/mock-database.ts +14 -2
- package/src/model.ts +4 -0
- package/src/operators/child-collection.ts +24 -0
- package/src/operators/date.ts +108 -24
- package/src/operators/eq.ts +14 -0
- package/src/operators/index.ts +2 -0
- package/src/operators/ne.ts +12 -7
- package/src/options-parser.ts +25 -11
- package/src/query-interface/mysql-query-interface.ts +72 -0
- package/src/query-interface/postgres-query-interface.ts +103 -0
- package/src/query-interface/query-interface-builder.ts +14 -0
- package/src/query-interface/query-interface.ts +43 -0
- package/src/query-interface/sqlite-query-interface.ts +79 -0
- package/src/relation-repository/belongs-to-many-repository.ts +20 -1
- package/src/relation-repository/hasmany-repository.ts +5 -3
- package/src/relation-repository/multiple-relation-repository.ts +13 -1
- package/src/relation-repository/single-relation-repository.ts +2 -0
- package/src/repository.ts +6 -13
- package/src/sql-parser/index.js +10698 -0
- package/src/sql-parser/readme.md +2 -0
- package/src/sql-parser/sql.pegjs +1297 -0
- package/src/sync-runner.ts +27 -32
- package/src/update-associations.ts +26 -22
- package/src/utils.ts +4 -3
- package/src/view/field-type-map.ts +56 -0
- package/src/view/view-inference.ts +106 -0
- package/src/view-collection.ts +21 -0
|
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.NumberValueParser = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("../utils");
|
|
9
|
-
|
|
10
8
|
var _baseValueParser = require("./base-value-parser");
|
|
11
|
-
|
|
12
9
|
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); } }
|
|
13
|
-
|
|
14
10
|
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); }); }; }
|
|
15
|
-
|
|
16
11
|
class NumberValueParser extends _baseValueParser.BaseValueParser {
|
|
17
12
|
setValue(value) {
|
|
18
13
|
var _this = this;
|
|
19
|
-
|
|
20
14
|
return _asyncToGenerator(function* () {
|
|
21
15
|
if (value === null || value === undefined || typeof value === 'number') {
|
|
22
16
|
_this.value = value;
|
|
@@ -31,7 +25,6 @@ class NumberValueParser extends _baseValueParser.BaseValueParser {
|
|
|
31
25
|
} else {
|
|
32
26
|
value = +value;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
if (isNaN(value)) {
|
|
36
29
|
_this.errors.push(`Invalid value - "${value}"`);
|
|
37
30
|
} else {
|
|
@@ -43,7 +36,5 @@ class NumberValueParser extends _baseValueParser.BaseValueParser {
|
|
|
43
36
|
}
|
|
44
37
|
})();
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
exports.NumberValueParser = NumberValueParser;
|
|
@@ -4,33 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.StringValueParser = void 0;
|
|
7
|
-
|
|
8
7
|
var _baseValueParser = require("./base-value-parser");
|
|
9
|
-
|
|
10
8
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
-
|
|
12
9
|
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); }
|
|
13
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
11
|
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); } }
|
|
17
|
-
|
|
18
12
|
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); }); }; }
|
|
19
|
-
|
|
20
13
|
class StringValueParser extends _baseValueParser.BaseValueParser {
|
|
21
14
|
setValue(value) {
|
|
22
15
|
var _this = this;
|
|
23
|
-
|
|
24
16
|
return _asyncToGenerator(function* () {
|
|
25
17
|
const _this$getOptions = _this.getOptions(),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
map = _this$getOptions.map,
|
|
19
|
+
set = _this$getOptions.set;
|
|
29
20
|
if (set.size > 0) {
|
|
30
21
|
if (map.has(value)) {
|
|
31
22
|
value = map.get(value);
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
if (set.has(value)) {
|
|
35
25
|
_this.value = value;
|
|
36
26
|
} else {
|
|
@@ -41,17 +31,13 @@ class StringValueParser extends _baseValueParser.BaseValueParser {
|
|
|
41
31
|
}
|
|
42
32
|
})();
|
|
43
33
|
}
|
|
44
|
-
|
|
45
34
|
getOptions() {
|
|
46
35
|
var _this$field$options, _this$field$options$u;
|
|
47
|
-
|
|
48
36
|
const options = ((_this$field$options = this.field.options) === null || _this$field$options === void 0 ? void 0 : (_this$field$options$u = _this$field$options['uiSchema']) === null || _this$field$options$u === void 0 ? void 0 : _this$field$options$u.enum) || [];
|
|
49
37
|
const map = new Map();
|
|
50
38
|
const set = new Set();
|
|
51
|
-
|
|
52
39
|
var _iterator = _createForOfIteratorHelper(options),
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
_step;
|
|
55
41
|
try {
|
|
56
42
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
43
|
const option = _step.value;
|
|
@@ -64,13 +50,10 @@ class StringValueParser extends _baseValueParser.BaseValueParser {
|
|
|
64
50
|
} finally {
|
|
65
51
|
_iterator.f();
|
|
66
52
|
}
|
|
67
|
-
|
|
68
53
|
return {
|
|
69
54
|
map,
|
|
70
55
|
set
|
|
71
56
|
};
|
|
72
57
|
}
|
|
73
|
-
|
|
74
58
|
}
|
|
75
|
-
|
|
76
59
|
exports.StringValueParser = StringValueParser;
|
|
@@ -4,29 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ToManyValueParser = void 0;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = require("path");
|
|
10
|
-
|
|
11
9
|
_path = function _path() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
var _baseValueParser = require("./base-value-parser");
|
|
19
|
-
|
|
20
15
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
21
|
-
|
|
22
16
|
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); }
|
|
23
|
-
|
|
24
17
|
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; }
|
|
25
|
-
|
|
26
18
|
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); } }
|
|
27
|
-
|
|
28
19
|
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); }); }; }
|
|
29
|
-
|
|
30
20
|
class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
31
21
|
constructor(...args) {
|
|
32
22
|
super(...args);
|
|
@@ -35,10 +25,8 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
35
25
|
chinaRegion: 'setChinaRegion'
|
|
36
26
|
};
|
|
37
27
|
}
|
|
38
|
-
|
|
39
28
|
setAttachments(value) {
|
|
40
29
|
var _this = this;
|
|
41
|
-
|
|
42
30
|
return _asyncToGenerator(function* () {
|
|
43
31
|
_this.value = _this.toArr(value).map(url => {
|
|
44
32
|
return {
|
|
@@ -50,23 +38,16 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
50
38
|
});
|
|
51
39
|
})();
|
|
52
40
|
}
|
|
53
|
-
|
|
54
41
|
setChinaRegion(value) {
|
|
55
42
|
var _this2 = this;
|
|
56
|
-
|
|
57
43
|
return _asyncToGenerator(function* () {
|
|
58
44
|
const repository = _this2.field.database.getRepository(_this2.field.target);
|
|
59
|
-
|
|
60
45
|
try {
|
|
61
46
|
const values = [];
|
|
62
|
-
|
|
63
47
|
const names = _this2.toArr(value, '/');
|
|
64
|
-
|
|
65
48
|
let parentCode = null;
|
|
66
|
-
|
|
67
49
|
var _iterator = _createForOfIteratorHelper(names),
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
_step;
|
|
70
51
|
try {
|
|
71
52
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
53
|
const name = _step.value;
|
|
@@ -76,11 +57,9 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
76
57
|
parentCode
|
|
77
58
|
}
|
|
78
59
|
});
|
|
79
|
-
|
|
80
60
|
if (!instance) {
|
|
81
61
|
throw new Error(`"${value}" does not exist`);
|
|
82
62
|
}
|
|
83
|
-
|
|
84
63
|
parentCode = instance.get('code');
|
|
85
64
|
values.push(parentCode);
|
|
86
65
|
}
|
|
@@ -89,36 +68,26 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
89
68
|
} finally {
|
|
90
69
|
_iterator.f();
|
|
91
70
|
}
|
|
92
|
-
|
|
93
71
|
if (values.length !== names.length) {
|
|
94
72
|
throw new Error(`"${value}" does not exist`);
|
|
95
73
|
}
|
|
96
|
-
|
|
97
74
|
_this2.value = values;
|
|
98
75
|
} catch (error) {
|
|
99
76
|
_this2.errors.push(error.message);
|
|
100
77
|
}
|
|
101
78
|
})();
|
|
102
79
|
}
|
|
103
|
-
|
|
104
80
|
setAssociations(value) {
|
|
105
81
|
var _this3 = this;
|
|
106
|
-
|
|
107
82
|
return _asyncToGenerator(function* () {
|
|
108
83
|
var _this3$ctx, _this3$ctx$column;
|
|
109
|
-
|
|
110
84
|
const dataIndex = ((_this3$ctx = _this3.ctx) === null || _this3$ctx === void 0 ? void 0 : (_this3$ctx$column = _this3$ctx.column) === null || _this3$ctx$column === void 0 ? void 0 : _this3$ctx$column.dataIndex) || [];
|
|
111
|
-
|
|
112
85
|
if (Array.isArray(dataIndex) && dataIndex.length < 2) {
|
|
113
86
|
_this3.errors.push(`data index invalid`);
|
|
114
|
-
|
|
115
87
|
return;
|
|
116
88
|
}
|
|
117
|
-
|
|
118
89
|
const key = _this3.ctx.column.dataIndex[1];
|
|
119
|
-
|
|
120
90
|
const repository = _this3.field.database.getRepository(_this3.field.target);
|
|
121
|
-
|
|
122
91
|
try {
|
|
123
92
|
_this3.value = yield Promise.all(_this3.toArr(value).map( /*#__PURE__*/function () {
|
|
124
93
|
var _ref = _asyncToGenerator(function* (v) {
|
|
@@ -127,14 +96,11 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
127
96
|
[key]: v
|
|
128
97
|
}
|
|
129
98
|
});
|
|
130
|
-
|
|
131
99
|
if (!instance) {
|
|
132
100
|
throw new Error(`"${v}" does not exist`);
|
|
133
101
|
}
|
|
134
|
-
|
|
135
102
|
return instance.get(_this3.field.targetKey || 'id');
|
|
136
103
|
});
|
|
137
|
-
|
|
138
104
|
return function (_x) {
|
|
139
105
|
return _ref.apply(this, arguments);
|
|
140
106
|
};
|
|
@@ -144,26 +110,19 @@ class ToManyValueParser extends _baseValueParser.BaseValueParser {
|
|
|
144
110
|
}
|
|
145
111
|
})();
|
|
146
112
|
}
|
|
147
|
-
|
|
148
113
|
setValue(value) {
|
|
149
114
|
var _this4 = this;
|
|
150
|
-
|
|
151
115
|
return _asyncToGenerator(function* () {
|
|
152
116
|
const setAccessor = _this4.setAccessors[_this4.getInterface()] || 'setAssociations';
|
|
153
117
|
yield _this4[setAccessor](value);
|
|
154
118
|
})();
|
|
155
119
|
}
|
|
156
|
-
|
|
157
120
|
getInterface() {
|
|
158
121
|
var _this$field, _this$field$options;
|
|
159
|
-
|
|
160
122
|
return (_this$field = this.field) === null || _this$field === void 0 ? void 0 : (_this$field$options = _this$field.options) === null || _this$field$options === void 0 ? void 0 : _this$field$options.interface;
|
|
161
123
|
}
|
|
162
|
-
|
|
163
124
|
isInterface(name) {
|
|
164
125
|
return this.getInterface() === name;
|
|
165
126
|
}
|
|
166
|
-
|
|
167
127
|
}
|
|
168
|
-
|
|
169
128
|
exports.ToManyValueParser = ToManyValueParser;
|
|
@@ -4,38 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ToOneValueParser = void 0;
|
|
7
|
-
|
|
8
7
|
var _baseValueParser = require("./base-value-parser");
|
|
9
|
-
|
|
10
8
|
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); } }
|
|
11
|
-
|
|
12
9
|
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); }); }; }
|
|
13
|
-
|
|
14
10
|
class ToOneValueParser extends _baseValueParser.BaseValueParser {
|
|
15
11
|
setValue(value) {
|
|
16
12
|
var _this = this;
|
|
17
|
-
|
|
18
13
|
return _asyncToGenerator(function* () {
|
|
19
14
|
var _this$ctx, _this$ctx$column;
|
|
20
|
-
|
|
21
15
|
const dataIndex = ((_this$ctx = _this.ctx) === null || _this$ctx === void 0 ? void 0 : (_this$ctx$column = _this$ctx.column) === null || _this$ctx$column === void 0 ? void 0 : _this$ctx$column.dataIndex) || [];
|
|
22
|
-
|
|
23
16
|
if (Array.isArray(dataIndex) && dataIndex.length < 2) {
|
|
24
17
|
_this.errors.push(`data index invalid`);
|
|
25
|
-
|
|
26
18
|
return;
|
|
27
19
|
}
|
|
28
|
-
|
|
29
20
|
const key = _this.ctx.column.dataIndex[1];
|
|
30
|
-
|
|
31
21
|
const repository = _this.field.database.getRepository(_this.field.target);
|
|
32
|
-
|
|
33
22
|
const instance = yield repository.findOne({
|
|
34
23
|
filter: {
|
|
35
24
|
[key]: _this.trim(value)
|
|
36
25
|
}
|
|
37
26
|
});
|
|
38
|
-
|
|
39
27
|
if (instance) {
|
|
40
28
|
_this.value = instance.get(_this.field.targetKey || 'id');
|
|
41
29
|
} else {
|
|
@@ -43,7 +31,5 @@ class ToOneValueParser extends _baseValueParser.BaseValueParser {
|
|
|
43
31
|
}
|
|
44
32
|
})();
|
|
45
33
|
}
|
|
46
|
-
|
|
47
34
|
}
|
|
48
|
-
|
|
49
35
|
exports.ToOneValueParser = ToOneValueParser;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
postgres: {
|
|
3
|
+
'character varying': string;
|
|
4
|
+
varchar: string;
|
|
5
|
+
text: string;
|
|
6
|
+
char: string;
|
|
7
|
+
smallint: string;
|
|
8
|
+
integer: string;
|
|
9
|
+
bigint: string;
|
|
10
|
+
decimal: string;
|
|
11
|
+
numeric: string;
|
|
12
|
+
'double precision': string;
|
|
13
|
+
'timestamp without time zone': string;
|
|
14
|
+
'timestamp with time zone': string;
|
|
15
|
+
date: string;
|
|
16
|
+
boolean: string;
|
|
17
|
+
json: string[];
|
|
18
|
+
jsonb: string[];
|
|
19
|
+
};
|
|
20
|
+
mysql: {
|
|
21
|
+
varchar: string;
|
|
22
|
+
text: string;
|
|
23
|
+
int: string;
|
|
24
|
+
integer: string;
|
|
25
|
+
bigint: string;
|
|
26
|
+
float: string;
|
|
27
|
+
double: string;
|
|
28
|
+
boolean: string;
|
|
29
|
+
tinyint: string;
|
|
30
|
+
datetime: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
json: string[];
|
|
33
|
+
};
|
|
34
|
+
sqlite: {
|
|
35
|
+
text: string;
|
|
36
|
+
varchar: string;
|
|
37
|
+
integer: string;
|
|
38
|
+
real: string;
|
|
39
|
+
datetime: string;
|
|
40
|
+
date: string;
|
|
41
|
+
time: string;
|
|
42
|
+
boolean: string;
|
|
43
|
+
numeric: string;
|
|
44
|
+
json: string[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export default _default;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const postgres = {
|
|
8
|
+
'character varying': 'string',
|
|
9
|
+
varchar: 'string',
|
|
10
|
+
text: 'text',
|
|
11
|
+
char: 'string',
|
|
12
|
+
smallint: 'integer',
|
|
13
|
+
integer: 'integer',
|
|
14
|
+
bigint: 'bigInt',
|
|
15
|
+
decimal: 'float',
|
|
16
|
+
numeric: 'float',
|
|
17
|
+
'double precision': 'float',
|
|
18
|
+
'timestamp without time zone': 'date',
|
|
19
|
+
'timestamp with time zone': 'date',
|
|
20
|
+
date: 'date',
|
|
21
|
+
boolean: 'boolean',
|
|
22
|
+
json: ['json', 'array'],
|
|
23
|
+
jsonb: ['jsonb', 'array']
|
|
24
|
+
};
|
|
25
|
+
const mysql = {
|
|
26
|
+
varchar: 'string',
|
|
27
|
+
text: 'text',
|
|
28
|
+
int: 'integer',
|
|
29
|
+
integer: 'integer',
|
|
30
|
+
bigint: 'bigInt',
|
|
31
|
+
float: 'float',
|
|
32
|
+
double: 'float',
|
|
33
|
+
boolean: 'boolean',
|
|
34
|
+
tinyint: 'integer',
|
|
35
|
+
datetime: 'date',
|
|
36
|
+
timestamp: 'date',
|
|
37
|
+
json: ['json', 'array']
|
|
38
|
+
};
|
|
39
|
+
const sqlite = {
|
|
40
|
+
text: 'text',
|
|
41
|
+
varchar: 'string',
|
|
42
|
+
integer: 'integer',
|
|
43
|
+
real: 'real',
|
|
44
|
+
datetime: 'date',
|
|
45
|
+
date: 'date',
|
|
46
|
+
time: 'time',
|
|
47
|
+
boolean: 'boolean',
|
|
48
|
+
numeric: 'decimal',
|
|
49
|
+
json: ['json', 'array']
|
|
50
|
+
};
|
|
51
|
+
var _default = {
|
|
52
|
+
postgres,
|
|
53
|
+
mysql,
|
|
54
|
+
sqlite
|
|
55
|
+
};
|
|
56
|
+
exports.default = _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Database from '../database';
|
|
2
|
+
declare type InferredField = {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
source?: string;
|
|
6
|
+
};
|
|
7
|
+
declare type InferredFieldResult = {
|
|
8
|
+
[key: string]: InferredField;
|
|
9
|
+
};
|
|
10
|
+
export declare class ViewFieldInference {
|
|
11
|
+
static inferFields(options: {
|
|
12
|
+
db: Database;
|
|
13
|
+
viewName: string;
|
|
14
|
+
viewSchema?: string;
|
|
15
|
+
}): Promise<InferredFieldResult>;
|
|
16
|
+
static inferToFieldType(options: {
|
|
17
|
+
db: Database;
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
}): {
|
|
21
|
+
possibleTypes: string[];
|
|
22
|
+
type?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: any;
|
|
25
|
+
possibleTypes: any[];
|
|
26
|
+
} | {
|
|
27
|
+
type: any;
|
|
28
|
+
possibleTypes?: undefined;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ViewFieldInference = void 0;
|
|
7
|
+
var _fieldTypeMap = _interopRequireDefault(require("./field-type-map"));
|
|
8
|
+
function _mathjs() {
|
|
9
|
+
const data = require("mathjs");
|
|
10
|
+
_mathjs = function _mathjs() {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
|
+
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); } }
|
|
22
|
+
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); }); }; }
|
|
23
|
+
class ViewFieldInference {
|
|
24
|
+
static inferFields(options) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
return _asyncToGenerator(function* () {
|
|
27
|
+
const db = options.db;
|
|
28
|
+
if (!db.inDialect('postgres')) {
|
|
29
|
+
options.viewSchema = undefined;
|
|
30
|
+
}
|
|
31
|
+
const columns = yield db.sequelize.getQueryInterface().describeTable(options.viewName, options.viewSchema);
|
|
32
|
+
const columnUsage = yield db.queryInterface.viewColumnUsage({
|
|
33
|
+
viewName: options.viewName,
|
|
34
|
+
schema: options.viewSchema
|
|
35
|
+
});
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return Object.fromEntries(Object.entries(columns).map(([name, column]) => {
|
|
38
|
+
const usage = columnUsage[name];
|
|
39
|
+
if (usage) {
|
|
40
|
+
const collectionField = (() => {
|
|
41
|
+
const tableName = `${usage.table_schema ? `${usage.table_schema}.` : ''}${usage.table_name}`;
|
|
42
|
+
const collection = db.tableNameCollectionMap.get(tableName);
|
|
43
|
+
if (!collection) return false;
|
|
44
|
+
const fieldValue = Object.values(collection.model.rawAttributes).find(field => field.field === usage.column_name);
|
|
45
|
+
if (!fieldValue) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const fieldName = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.fieldName;
|
|
50
|
+
return collection.getField(fieldName);
|
|
51
|
+
})();
|
|
52
|
+
if (collectionField && collectionField.options.interface) {
|
|
53
|
+
return [name, {
|
|
54
|
+
name,
|
|
55
|
+
type: collectionField.type,
|
|
56
|
+
source: `${collectionField.collection.name}.${collectionField.name}`
|
|
57
|
+
}];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return [name, _objectSpread({
|
|
61
|
+
name
|
|
62
|
+
}, _this.inferToFieldType({
|
|
63
|
+
db,
|
|
64
|
+
name,
|
|
65
|
+
type: column.type
|
|
66
|
+
}))];
|
|
67
|
+
}));
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
70
|
+
static inferToFieldType(options) {
|
|
71
|
+
const db = options.db;
|
|
72
|
+
const dialect = db.sequelize.getDialect();
|
|
73
|
+
const fieldTypeMap = _fieldTypeMap.default[dialect];
|
|
74
|
+
if (!options.type) {
|
|
75
|
+
return {
|
|
76
|
+
possibleTypes: Object.keys(fieldTypeMap)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const queryType = options.type.toLowerCase().replace(/\(\d+\)/, '');
|
|
80
|
+
const mappedType = fieldTypeMap[queryType];
|
|
81
|
+
if ((0, _mathjs().isArray)(mappedType)) {
|
|
82
|
+
return {
|
|
83
|
+
type: mappedType[0],
|
|
84
|
+
possibleTypes: mappedType
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
type: mappedType
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ViewFieldInference = ViewFieldInference;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Collection, CollectionContext, CollectionOptions } from './collection';
|
|
2
|
+
export declare class ViewCollection extends Collection {
|
|
3
|
+
constructor(options: CollectionOptions, context: CollectionContext);
|
|
4
|
+
protected sequelizeModelOptions(): any;
|
|
5
|
+
isView(): boolean;
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ViewCollection = void 0;
|
|
7
|
+
var _collection = require("./collection");
|
|
8
|
+
class ViewCollection extends _collection.Collection {
|
|
9
|
+
constructor(options, context) {
|
|
10
|
+
options.autoGenId = false;
|
|
11
|
+
options.timestamps = false;
|
|
12
|
+
options.underscored = false;
|
|
13
|
+
super(options, context);
|
|
14
|
+
}
|
|
15
|
+
sequelizeModelOptions() {
|
|
16
|
+
const modelOptions = super.sequelizeModelOptions();
|
|
17
|
+
modelOptions.tableName = this.options.viewName || this.options.name;
|
|
18
|
+
return modelOptions;
|
|
19
|
+
}
|
|
20
|
+
isView() {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ViewCollection = ViewCollection;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/
|
|
9
|
+
"@nocobase/logger": "0.9.2-alpha.1",
|
|
10
|
+
"@nocobase/utils": "0.9.2-alpha.1",
|
|
10
11
|
"async-mutex": "^0.3.2",
|
|
11
12
|
"cron-parser": "4.4.0",
|
|
12
13
|
"deepmerge": "^4.2.2",
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
28
29
|
"directory": "packages/database"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "a4f103eb0144f07205aff7b2a6be8ea6aa1330df"
|
|
31
32
|
}
|
|
@@ -328,6 +328,50 @@ describe('collection sync', () => {
|
|
|
328
328
|
expect(error).toBeInstanceOf(IdentifierError);
|
|
329
329
|
});
|
|
330
330
|
|
|
331
|
+
it('should throw error when collection has same table name and same schema', async () => {
|
|
332
|
+
const c1 = db.collection({
|
|
333
|
+
name: 'test',
|
|
334
|
+
tableName: 'test',
|
|
335
|
+
schema: 'public',
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
let err;
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
const c2 = db.collection({
|
|
342
|
+
name: 'test2',
|
|
343
|
+
tableName: 'test',
|
|
344
|
+
schema: 'public',
|
|
345
|
+
});
|
|
346
|
+
} catch (e) {
|
|
347
|
+
err = e;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
expect(err.message).toContain('have same tableName');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should allow same table name in difference schema', async () => {
|
|
354
|
+
const c1 = db.collection({
|
|
355
|
+
name: 'test',
|
|
356
|
+
tableName: 'test',
|
|
357
|
+
schema: 'public',
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
let err;
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
const c2 = db.collection({
|
|
364
|
+
name: 'test2',
|
|
365
|
+
tableName: 'test',
|
|
366
|
+
schema: 'other_schema',
|
|
367
|
+
});
|
|
368
|
+
} catch (e) {
|
|
369
|
+
err = e;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
expect(err).toBeFalsy();
|
|
373
|
+
});
|
|
374
|
+
|
|
331
375
|
test('limit field name length', async () => {
|
|
332
376
|
const longFieldName =
|
|
333
377
|
'this_is_a_very_long_field_name_that_should_be_truncated_this_is_a_very_long_field_name_that_should_be_truncated';
|