@nocobase/database 0.7.1-alpha.4 → 0.7.1-alpha.7
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/database.d.ts +1 -0
- package/lib/database.js +34 -0
- package/package.json +3 -3
package/lib/database.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
|
|
|
78
78
|
getCollection(name: string): Collection;
|
|
79
79
|
hasCollection(name: string): boolean;
|
|
80
80
|
removeCollection(name: string): Collection<any, any>;
|
|
81
|
+
getCollectionFieldByPath(path: string): FieldTypes.Field;
|
|
81
82
|
getModel<M extends Model>(name: string): ModelCtor<M>;
|
|
82
83
|
getRepository<R extends Repository>(name: string): R;
|
|
83
84
|
getRepository<R extends RelationRepository>(name: string, relationId: string | number): R;
|
package/lib/database.js
CHANGED
|
@@ -106,6 +106,10 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
106
106
|
|
|
107
107
|
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); }); }; }
|
|
108
108
|
|
|
109
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
110
|
+
|
|
111
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
112
|
+
|
|
109
113
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
110
114
|
|
|
111
115
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -315,6 +319,36 @@ class Database extends _events().EventEmitter {
|
|
|
315
319
|
return collection;
|
|
316
320
|
}
|
|
317
321
|
|
|
322
|
+
getCollectionFieldByPath(path) {
|
|
323
|
+
const _path$split = path.split('.'),
|
|
324
|
+
_path$split2 = _toArray(_path$split),
|
|
325
|
+
collectionName = _path$split2[0],
|
|
326
|
+
fieldName = _path$split2[1],
|
|
327
|
+
others = _path$split2.slice(2);
|
|
328
|
+
|
|
329
|
+
const collection = this.getCollection(collectionName);
|
|
330
|
+
|
|
331
|
+
if (!collection) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const field = collection.getField(fieldName);
|
|
336
|
+
|
|
337
|
+
if (others.length === 0) {
|
|
338
|
+
return field;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (field.target) {
|
|
342
|
+
const target = this.getCollection(field.target);
|
|
343
|
+
|
|
344
|
+
if (!target) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return target.getField(others[0]);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
318
352
|
getModel(name) {
|
|
319
353
|
return this.getCollection(name).model;
|
|
320
354
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "0.7.1-alpha.
|
|
3
|
+
"version": "0.7.1-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@nocobase/utils": "0.7.1-alpha.
|
|
15
|
+
"@nocobase/utils": "0.7.1-alpha.7",
|
|
16
16
|
"async-mutex": "^0.3.2",
|
|
17
17
|
"deepmerge": "^4.2.2",
|
|
18
18
|
"flat": "^5.0.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
30
30
|
"directory": "packages/database"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "87601930b09f7df3eec5d493b62a7ec27871caa1"
|
|
33
33
|
}
|