@nocobase/database 0.13.0-alpha.4 → 0.13.0-alpha.5
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.js +44 -40
- package/lib/collection-importer.js +62 -60
- package/lib/collection.js +210 -329
- package/lib/database-utils/index.js +43 -24
- package/lib/database.js +354 -529
- package/lib/decorators/must-have-filter-decorator.js +27 -11
- package/lib/decorators/target-collection-decorator.js +38 -19
- package/lib/decorators/transaction-decorator.js +59 -41
- package/lib/eager-loading/eager-loading-tree.js +276 -360
- package/lib/errors/identifier-error.js +31 -9
- package/lib/features/ReferencesMap.js +47 -22
- package/lib/features/referential-integrity-check.js +71 -75
- package/lib/field-repository/array-field-repository.js +148 -146
- package/lib/fields/array-field.js +44 -31
- package/lib/fields/belongs-to-field.js +54 -61
- package/lib/fields/belongs-to-many-field.js +57 -57
- package/lib/fields/boolean-field.js +33 -17
- package/lib/fields/context-field.js +57 -52
- package/lib/fields/date-field.js +36 -20
- package/lib/fields/field.js +132 -141
- package/lib/fields/has-inverse-field.js +15 -5
- package/lib/fields/has-many-field.js +47 -54
- package/lib/fields/has-one-field.js +49 -56
- package/lib/fields/index.js +62 -246
- package/lib/fields/json-field.js +45 -26
- package/lib/fields/number-field.js +72 -38
- package/lib/fields/password-field.js +82 -83
- package/lib/fields/radio-field.js +57 -57
- package/lib/fields/relation-field.js +34 -16
- package/lib/fields/set-field.js +39 -20
- package/lib/fields/sort-field.js +146 -194
- package/lib/fields/string-field.js +33 -17
- package/lib/fields/text-field.js +33 -17
- package/lib/fields/time-field.js +33 -17
- package/lib/fields/uid-field.js +50 -51
- package/lib/fields/uuid-field.js +40 -25
- package/lib/fields/virtual-field.js +33 -17
- package/lib/filter-match.js +38 -41
- package/lib/filter-parser.js +107 -150
- package/lib/index.js +117 -368
- package/lib/inherited-collection.js +74 -109
- package/lib/inherited-map.js +78 -124
- package/lib/listeners/adjacency-list.js +30 -10
- package/lib/listeners/append-child-collection-name-after-repository-find.js +51 -54
- package/lib/listeners/index.js +32 -12
- package/lib/magic-attribute-model.js +93 -163
- package/lib/migration.js +50 -41
- package/lib/mock-database.js +59 -49
- package/lib/model-hook.js +66 -60
- package/lib/model.js +119 -111
- package/lib/operators/array.js +78 -61
- package/lib/operators/association.js +25 -16
- package/lib/operators/boolean.js +27 -18
- package/lib/operators/child-collection.js +48 -34
- package/lib/operators/date.js +55 -62
- package/lib/operators/empty.js +58 -60
- package/lib/operators/eq.js +25 -16
- package/lib/operators/index.d.ts +22 -1
- package/lib/operators/index.js +53 -12
- package/lib/operators/ne.js +28 -19
- package/lib/operators/notIn.js +26 -17
- package/lib/operators/string.js +30 -21
- package/lib/operators/utils.js +38 -16
- package/lib/options-parser.js +173 -223
- package/lib/playground.js +27 -48
- package/lib/query-interface/mysql-query-interface.js +74 -78
- package/lib/query-interface/postgres-query-interface.js +89 -101
- package/lib/query-interface/query-interface-builder.js +40 -13
- package/lib/query-interface/query-interface.js +40 -41
- package/lib/query-interface/sqlite-query-interface.js +81 -78
- package/lib/relation-repository/belongs-to-many-repository.js +221 -224
- package/lib/relation-repository/belongs-to-repository.js +37 -20
- package/lib/relation-repository/hasmany-repository.js +133 -133
- package/lib/relation-repository/hasone-repository.js +31 -9
- package/lib/relation-repository/multiple-relation-repository.js +174 -183
- package/lib/relation-repository/relation-repository.js +117 -110
- package/lib/relation-repository/single-relation-repository.js +121 -109
- package/lib/relation-repository/types.js +15 -5
- package/lib/repositories/tree-repository/adjacency-list-repository.js +117 -116
- package/lib/repositories/view-repository.js +31 -8
- package/lib/repository.d.ts +2 -4
- package/lib/repository.js +474 -561
- package/lib/sql-parser/index.js +1101 -918
- package/lib/sql-parser/postgres.js +25809 -663
- package/lib/sync-runner.js +144 -133
- package/lib/types.js +15 -5
- package/lib/update-associations.js +317 -431
- package/lib/update-guard.js +80 -62
- package/lib/utils.js +84 -42
- package/lib/value-parsers/array-value-parser.js +51 -51
- package/lib/value-parsers/base-value-parser.js +39 -22
- package/lib/value-parsers/boolean-value-parser.js +47 -35
- package/lib/value-parsers/date-value-parser.js +72 -60
- package/lib/value-parsers/index.js +73 -87
- package/lib/value-parsers/json-value-parser.js +43 -26
- package/lib/value-parsers/number-value-parser.js +52 -35
- package/lib/value-parsers/string-value-parser.js +56 -56
- package/lib/value-parsers/to-many-value-parser.js +93 -113
- package/lib/value-parsers/to-one-value-parser.js +46 -33
- package/lib/view/field-type-map.js +62 -51
- package/lib/view/view-inference.js +109 -92
- package/lib/view-collection.js +31 -9
- package/package.json +4 -4
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var collection_group_manager_exports = {};
|
|
20
|
+
__export(collection_group_manager_exports, {
|
|
21
|
+
CollectionGroupManager: () => CollectionGroupManager
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_lodash = function _lodash() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
-
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."); }
|
|
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); }
|
|
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; }
|
|
18
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
19
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
-
class CollectionGroupManager {
|
|
23
|
+
module.exports = __toCommonJS(collection_group_manager_exports);
|
|
24
|
+
var import_lodash = require("lodash");
|
|
25
|
+
const _CollectionGroupManager = class _CollectionGroupManager {
|
|
21
26
|
constructor(db) {
|
|
22
|
-
this.db = void 0;
|
|
23
27
|
this.db = db;
|
|
24
28
|
}
|
|
25
29
|
getGroups() {
|
|
26
30
|
const collections = [...this.db.collections.values()];
|
|
27
|
-
const groups = new Map();
|
|
31
|
+
const groups = /* @__PURE__ */ new Map();
|
|
28
32
|
const skipped = [];
|
|
29
|
-
for (
|
|
30
|
-
const collection = _collections[_i];
|
|
33
|
+
for (const collection of collections) {
|
|
31
34
|
const groupKey = collection.options.namespace;
|
|
32
35
|
if (!groupKey) {
|
|
33
36
|
continue;
|
|
34
37
|
}
|
|
35
|
-
const
|
|
36
|
-
_groupKey$split2 = _slicedToArray(_groupKey$split, 2),
|
|
37
|
-
namespace = _groupKey$split2[0],
|
|
38
|
-
groupFunc = _groupKey$split2[1];
|
|
38
|
+
const [namespace, groupFunc] = groupKey.split(".");
|
|
39
39
|
if (!groupFunc) {
|
|
40
40
|
skipped.push({
|
|
41
41
|
name: collection.name,
|
|
42
|
-
reason:
|
|
42
|
+
reason: "no-group-function"
|
|
43
43
|
});
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
if (!groups.has(groupKey)) {
|
|
47
47
|
const dumpable = (() => {
|
|
48
48
|
if (!collection.options.duplicator) {
|
|
49
|
-
return
|
|
49
|
+
return void 0;
|
|
50
50
|
}
|
|
51
|
-
if ((0,
|
|
51
|
+
if ((0, import_lodash.isString)(collection.options.duplicator)) {
|
|
52
52
|
return {
|
|
53
53
|
dumpable: collection.options.duplicator
|
|
54
54
|
};
|
|
@@ -58,28 +58,27 @@ class CollectionGroupManager {
|
|
|
58
58
|
if (!dumpable) {
|
|
59
59
|
skipped.push({
|
|
60
60
|
name: collection.name,
|
|
61
|
-
reason:
|
|
61
|
+
reason: "no-dumpable"
|
|
62
62
|
});
|
|
63
63
|
continue;
|
|
64
64
|
}
|
|
65
|
-
const
|
|
65
|
+
const group2 = {
|
|
66
66
|
namespace,
|
|
67
67
|
function: groupFunc,
|
|
68
|
-
collections: dumpable.with ? (0,
|
|
68
|
+
collections: dumpable.with ? (0, import_lodash.castArray)(dumpable.with) : [],
|
|
69
69
|
dumpable: dumpable.dumpable
|
|
70
70
|
};
|
|
71
71
|
if (dumpable.delayRestore) {
|
|
72
|
-
|
|
72
|
+
group2.delayRestore = dumpable.delayRestore;
|
|
73
73
|
}
|
|
74
|
-
groups.set(groupKey,
|
|
74
|
+
groups.set(groupKey, group2);
|
|
75
75
|
}
|
|
76
76
|
const group = groups.get(groupKey);
|
|
77
77
|
group.collections.push(collection.name);
|
|
78
78
|
}
|
|
79
79
|
const results = [...groups.values()];
|
|
80
|
-
const groupCollections = results.map(i => i.collections).flat();
|
|
81
|
-
for (
|
|
82
|
-
const skipItem = _skipped[_i2];
|
|
80
|
+
const groupCollections = results.map((i) => i.collections).flat();
|
|
81
|
+
for (const skipItem of skipped) {
|
|
83
82
|
if (groupCollections.includes(skipItem.name)) {
|
|
84
83
|
continue;
|
|
85
84
|
}
|
|
@@ -87,5 +86,10 @@ class CollectionGroupManager {
|
|
|
87
86
|
}
|
|
88
87
|
return results;
|
|
89
88
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
89
|
+
};
|
|
90
|
+
__name(_CollectionGroupManager, "CollectionGroupManager");
|
|
91
|
+
let CollectionGroupManager = _CollectionGroupManager;
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
CollectionGroupManager
|
|
95
|
+
});
|
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var collection_importer_exports = {};
|
|
30
|
+
__export(collection_importer_exports, {
|
|
31
|
+
ImporterReader: () => ImporterReader
|
|
5
32
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _promises() {
|
|
15
|
-
const data = require("fs/promises");
|
|
16
|
-
_promises = function _promises() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _lodash() {
|
|
22
|
-
const data = require("lodash");
|
|
23
|
-
_lodash = function _lodash() {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _utils() {
|
|
29
|
-
const data = require("@nocobase/utils");
|
|
30
|
-
_utils = function _utils() {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
-
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); } }
|
|
37
|
-
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); }); }; }
|
|
38
|
-
class ImporterReader {
|
|
33
|
+
module.exports = __toCommonJS(collection_importer_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_promises = require("fs/promises");
|
|
36
|
+
var import_lodash = require("lodash");
|
|
37
|
+
var import_utils = require("@nocobase/utils");
|
|
38
|
+
const _ImporterReader = class _ImporterReader {
|
|
39
|
+
directory;
|
|
40
|
+
extensions;
|
|
39
41
|
constructor(directory, extensions) {
|
|
40
|
-
this.directory = void 0;
|
|
41
|
-
this.extensions = void 0;
|
|
42
42
|
this.directory = directory;
|
|
43
43
|
if (!extensions) {
|
|
44
|
-
extensions = [
|
|
44
|
+
extensions = ["js", "ts", "json"];
|
|
45
45
|
}
|
|
46
46
|
this.extensions = new Set(extensions);
|
|
47
47
|
}
|
|
48
|
-
read() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
return (yield Promise.all(modules)).filter(module => (0, _lodash().isPlainObject)(module)).map(module => (0, _lodash().cloneDeep)(module));
|
|
65
|
-
})();
|
|
48
|
+
async read() {
|
|
49
|
+
const files = await (0, import_promises.readdir)(this.directory, {
|
|
50
|
+
encoding: "utf-8"
|
|
51
|
+
});
|
|
52
|
+
const modules = files.filter((fileName) => {
|
|
53
|
+
if (fileName.endsWith(".d.ts")) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const ext = import_path.default.parse(fileName).ext.replace(".", "");
|
|
57
|
+
return this.extensions.has(ext);
|
|
58
|
+
}).map((fileName) => {
|
|
59
|
+
const mod = (0, import_utils.requireModule)(import_path.default.join(this.directory, fileName));
|
|
60
|
+
return typeof mod === "function" ? mod() : mod;
|
|
61
|
+
});
|
|
62
|
+
return (await Promise.all(modules)).filter((module2) => (0, import_lodash.isPlainObject)(module2)).map((module2) => (0, import_lodash.cloneDeep)(module2));
|
|
66
63
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
64
|
+
};
|
|
65
|
+
__name(_ImporterReader, "ImporterReader");
|
|
66
|
+
let ImporterReader = _ImporterReader;
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
ImporterReader
|
|
70
|
+
});
|