@nocobase/utils 0.13.0-alpha.4 → 0.13.0-alpha.6
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/assign.js +85 -61
- package/lib/client.js +66 -195
- package/lib/collections-graph.js +79 -117
- package/lib/common.js +46 -22
- package/lib/date.js +111 -97
- package/lib/dayjs.js +61 -121
- package/lib/forEach.js +29 -9
- package/lib/getValuesByPath.js +33 -26
- package/lib/index.js +74 -242
- package/lib/json-templates.js +74 -77
- package/lib/koa-multer.js +75 -54
- package/lib/log.js +28 -8
- package/lib/merge.js +44 -23
- package/lib/mixin/AsyncEmitter.js +67 -54
- package/lib/mixin/index.js +35 -9
- package/lib/notification.js +30 -16
- package/lib/number.js +33 -18
- package/lib/parse-date.js +101 -83
- package/lib/parse-filter.js +194 -193
- package/lib/registry.js +35 -15
- package/lib/requireModule.js +31 -10
- package/lib/server.js +36 -103
- package/lib/toposort.js +64 -36
- package/lib/uid.js +34 -12
- package/lib/url.js +29 -7
- package/package.json +2 -2
package/lib/assign.js
CHANGED
|
@@ -1,41 +1,56 @@
|
|
|
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 assign_exports = {};
|
|
30
|
+
__export(assign_exports, {
|
|
31
|
+
assign: () => assign,
|
|
32
|
+
mergeStrategies: () => mergeStrategies
|
|
5
33
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_deepmerge = function _deepmerge() {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _lodash() {
|
|
16
|
-
const data = _interopRequireDefault(require("lodash"));
|
|
17
|
-
_lodash = function _lodash() {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
var _common = require("./common");
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
+
module.exports = __toCommonJS(assign_exports);
|
|
35
|
+
var import_deepmerge = __toESM(require("deepmerge"));
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_common = require("./common");
|
|
24
38
|
function getEnumerableOwnPropertySymbols(target) {
|
|
25
|
-
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(symbol => target.propertyIsEnumerable(symbol)) : [];
|
|
39
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol)) : [];
|
|
26
40
|
}
|
|
41
|
+
__name(getEnumerableOwnPropertySymbols, "getEnumerableOwnPropertySymbols");
|
|
27
42
|
function getKeys(target) {
|
|
28
43
|
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
mergeStrategies.set(
|
|
33
|
-
if (typeof y ===
|
|
34
|
-
y = y.split(
|
|
45
|
+
__name(getKeys, "getKeys");
|
|
46
|
+
const mergeStrategies = /* @__PURE__ */ new Map();
|
|
47
|
+
mergeStrategies.set("overwrite", (_, y) => {
|
|
48
|
+
if (typeof y === "string") {
|
|
49
|
+
y = y.split(",");
|
|
35
50
|
}
|
|
36
51
|
return y;
|
|
37
52
|
});
|
|
38
|
-
mergeStrategies.set(
|
|
53
|
+
mergeStrategies.set("andMerge", (x, y) => {
|
|
39
54
|
if (!x && !y) {
|
|
40
55
|
return;
|
|
41
56
|
}
|
|
@@ -49,7 +64,7 @@ mergeStrategies.set('andMerge', (x, y) => {
|
|
|
49
64
|
$and: [x, y]
|
|
50
65
|
};
|
|
51
66
|
});
|
|
52
|
-
mergeStrategies.set(
|
|
67
|
+
mergeStrategies.set("orMerge", (x, y) => {
|
|
53
68
|
if (!x && !y) {
|
|
54
69
|
return;
|
|
55
70
|
}
|
|
@@ -63,48 +78,57 @@ mergeStrategies.set('orMerge', (x, y) => {
|
|
|
63
78
|
$or: [x, y]
|
|
64
79
|
};
|
|
65
80
|
});
|
|
66
|
-
mergeStrategies.set(
|
|
67
|
-
return (0,
|
|
68
|
-
arrayMerge: (
|
|
81
|
+
mergeStrategies.set("deepMerge", (x, y) => {
|
|
82
|
+
return (0, import_common.isPlainObject)(x) && (0, import_common.isPlainObject)(y) ? (0, import_deepmerge.default)(x, y, {
|
|
83
|
+
arrayMerge: (x2, y2) => y2
|
|
69
84
|
}) : y;
|
|
70
85
|
});
|
|
71
|
-
mergeStrategies.set(
|
|
72
|
-
return (0,
|
|
86
|
+
mergeStrategies.set("merge", (x, y) => {
|
|
87
|
+
return (0, import_common.isPlainObject)(x) && (0, import_common.isPlainObject)(y) ? Object.assign(x, y) : y;
|
|
73
88
|
});
|
|
74
|
-
mergeStrategies.set(
|
|
75
|
-
if (typeof x ===
|
|
76
|
-
x = x.split(
|
|
89
|
+
mergeStrategies.set("union", (x, y) => {
|
|
90
|
+
if (typeof x === "string") {
|
|
91
|
+
x = x.split(",");
|
|
77
92
|
}
|
|
78
|
-
if (typeof y ===
|
|
79
|
-
y = y.split(
|
|
93
|
+
if (typeof y === "string") {
|
|
94
|
+
y = y.split(",");
|
|
80
95
|
}
|
|
81
|
-
return
|
|
96
|
+
return import_lodash.default.uniq((x || []).concat(y || [])).filter(Boolean);
|
|
82
97
|
});
|
|
83
|
-
mergeStrategies.set(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
+
mergeStrategies.set(
|
|
99
|
+
"intersect",
|
|
100
|
+
(x, y) => (() => {
|
|
101
|
+
if (typeof x === "string") {
|
|
102
|
+
x = x.split(",");
|
|
103
|
+
}
|
|
104
|
+
if (typeof y === "string") {
|
|
105
|
+
y = y.split(",");
|
|
106
|
+
}
|
|
107
|
+
if (!Array.isArray(x) || x.length === 0) {
|
|
108
|
+
return y || [];
|
|
109
|
+
}
|
|
110
|
+
if (!Array.isArray(y) || y.length === 0) {
|
|
111
|
+
return x || [];
|
|
112
|
+
}
|
|
113
|
+
return x.filter((v) => y.includes(v));
|
|
114
|
+
})().filter(Boolean)
|
|
115
|
+
);
|
|
98
116
|
function assign(target, source, strategies = {}) {
|
|
99
|
-
getKeys(source).forEach(sourceKey => {
|
|
117
|
+
getKeys(source).forEach((sourceKey) => {
|
|
100
118
|
const strategy = strategies[sourceKey];
|
|
101
|
-
let func = mergeStrategies.get(
|
|
102
|
-
if (typeof strategy ===
|
|
119
|
+
let func = mergeStrategies.get("deepMerge");
|
|
120
|
+
if (typeof strategy === "function") {
|
|
103
121
|
func = strategy;
|
|
104
|
-
} else if (typeof strategy ===
|
|
122
|
+
} else if (typeof strategy === "string" && mergeStrategies.has(strategy)) {
|
|
105
123
|
func = mergeStrategies.get(strategy);
|
|
106
124
|
}
|
|
107
125
|
target[sourceKey] = func(target[sourceKey], source[sourceKey]);
|
|
108
126
|
});
|
|
109
127
|
return target;
|
|
110
|
-
}
|
|
128
|
+
}
|
|
129
|
+
__name(assign, "assign");
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
assign,
|
|
133
|
+
mergeStrategies
|
|
134
|
+
});
|
package/lib/client.js
CHANGED
|
@@ -1,198 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "lodash", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function get() {
|
|
19
|
-
return _lodash().default;
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
16
|
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
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 client_exports = {};
|
|
30
|
+
__export(client_exports, {
|
|
31
|
+
dayjs: () => import_dayjs.dayjs,
|
|
32
|
+
lodash: () => import_lodash.default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(client_exports);
|
|
35
|
+
var import_lodash = __toESM(require("lodash"));
|
|
36
|
+
var import_dayjs = require("./dayjs");
|
|
37
|
+
__reExport(client_exports, require("./collections-graph"), module.exports);
|
|
38
|
+
__reExport(client_exports, require("./common"), module.exports);
|
|
39
|
+
__reExport(client_exports, require("./date"), module.exports);
|
|
40
|
+
__reExport(client_exports, require("./forEach"), module.exports);
|
|
41
|
+
__reExport(client_exports, require("./getValuesByPath"), module.exports);
|
|
42
|
+
__reExport(client_exports, require("./json-templates"), module.exports);
|
|
43
|
+
__reExport(client_exports, require("./log"), module.exports);
|
|
44
|
+
__reExport(client_exports, require("./merge"), module.exports);
|
|
45
|
+
__reExport(client_exports, require("./notification"), module.exports);
|
|
46
|
+
__reExport(client_exports, require("./number"), module.exports);
|
|
47
|
+
__reExport(client_exports, require("./parse-filter"), module.exports);
|
|
48
|
+
__reExport(client_exports, require("./registry"), module.exports);
|
|
49
|
+
__reExport(client_exports, require("./uid"), module.exports);
|
|
50
|
+
__reExport(client_exports, require("./url"), module.exports);
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
dayjs,
|
|
54
|
+
lodash,
|
|
55
|
+
...require("./collections-graph"),
|
|
56
|
+
...require("./common"),
|
|
57
|
+
...require("./date"),
|
|
58
|
+
...require("./forEach"),
|
|
59
|
+
...require("./getValuesByPath"),
|
|
60
|
+
...require("./json-templates"),
|
|
61
|
+
...require("./log"),
|
|
62
|
+
...require("./merge"),
|
|
63
|
+
...require("./notification"),
|
|
64
|
+
...require("./number"),
|
|
65
|
+
...require("./parse-filter"),
|
|
66
|
+
...require("./registry"),
|
|
67
|
+
...require("./uid"),
|
|
68
|
+
...require("./url")
|
|
21
69
|
});
|
|
22
|
-
function _lodash() {
|
|
23
|
-
const data = _interopRequireDefault(require("lodash"));
|
|
24
|
-
_lodash = function _lodash() {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
var _dayjs = require("./dayjs");
|
|
30
|
-
var _collectionsGraph = require("./collections-graph");
|
|
31
|
-
Object.keys(_collectionsGraph).forEach(function (key) {
|
|
32
|
-
if (key === "default" || key === "__esModule") return;
|
|
33
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
34
|
-
if (key in exports && exports[key] === _collectionsGraph[key]) return;
|
|
35
|
-
Object.defineProperty(exports, key, {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function get() {
|
|
38
|
-
return _collectionsGraph[key];
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
var _common = require("./common");
|
|
43
|
-
Object.keys(_common).forEach(function (key) {
|
|
44
|
-
if (key === "default" || key === "__esModule") return;
|
|
45
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
46
|
-
if (key in exports && exports[key] === _common[key]) return;
|
|
47
|
-
Object.defineProperty(exports, key, {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function get() {
|
|
50
|
-
return _common[key];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
var _date = require("./date");
|
|
55
|
-
Object.keys(_date).forEach(function (key) {
|
|
56
|
-
if (key === "default" || key === "__esModule") return;
|
|
57
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
58
|
-
if (key in exports && exports[key] === _date[key]) return;
|
|
59
|
-
Object.defineProperty(exports, key, {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function get() {
|
|
62
|
-
return _date[key];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
var _forEach = require("./forEach");
|
|
67
|
-
Object.keys(_forEach).forEach(function (key) {
|
|
68
|
-
if (key === "default" || key === "__esModule") return;
|
|
69
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
70
|
-
if (key in exports && exports[key] === _forEach[key]) return;
|
|
71
|
-
Object.defineProperty(exports, key, {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function get() {
|
|
74
|
-
return _forEach[key];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
var _getValuesByPath = require("./getValuesByPath");
|
|
79
|
-
Object.keys(_getValuesByPath).forEach(function (key) {
|
|
80
|
-
if (key === "default" || key === "__esModule") return;
|
|
81
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
82
|
-
if (key in exports && exports[key] === _getValuesByPath[key]) return;
|
|
83
|
-
Object.defineProperty(exports, key, {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: function get() {
|
|
86
|
-
return _getValuesByPath[key];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
var _jsonTemplates = require("./json-templates");
|
|
91
|
-
Object.keys(_jsonTemplates).forEach(function (key) {
|
|
92
|
-
if (key === "default" || key === "__esModule") return;
|
|
93
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
94
|
-
if (key in exports && exports[key] === _jsonTemplates[key]) return;
|
|
95
|
-
Object.defineProperty(exports, key, {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
get: function get() {
|
|
98
|
-
return _jsonTemplates[key];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
var _log = require("./log");
|
|
103
|
-
Object.keys(_log).forEach(function (key) {
|
|
104
|
-
if (key === "default" || key === "__esModule") return;
|
|
105
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
106
|
-
if (key in exports && exports[key] === _log[key]) return;
|
|
107
|
-
Object.defineProperty(exports, key, {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function get() {
|
|
110
|
-
return _log[key];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
var _merge = require("./merge");
|
|
115
|
-
Object.keys(_merge).forEach(function (key) {
|
|
116
|
-
if (key === "default" || key === "__esModule") return;
|
|
117
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
118
|
-
if (key in exports && exports[key] === _merge[key]) return;
|
|
119
|
-
Object.defineProperty(exports, key, {
|
|
120
|
-
enumerable: true,
|
|
121
|
-
get: function get() {
|
|
122
|
-
return _merge[key];
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
var _notification = require("./notification");
|
|
127
|
-
Object.keys(_notification).forEach(function (key) {
|
|
128
|
-
if (key === "default" || key === "__esModule") return;
|
|
129
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
130
|
-
if (key in exports && exports[key] === _notification[key]) return;
|
|
131
|
-
Object.defineProperty(exports, key, {
|
|
132
|
-
enumerable: true,
|
|
133
|
-
get: function get() {
|
|
134
|
-
return _notification[key];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
var _number = require("./number");
|
|
139
|
-
Object.keys(_number).forEach(function (key) {
|
|
140
|
-
if (key === "default" || key === "__esModule") return;
|
|
141
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
142
|
-
if (key in exports && exports[key] === _number[key]) return;
|
|
143
|
-
Object.defineProperty(exports, key, {
|
|
144
|
-
enumerable: true,
|
|
145
|
-
get: function get() {
|
|
146
|
-
return _number[key];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
var _parseFilter = require("./parse-filter");
|
|
151
|
-
Object.keys(_parseFilter).forEach(function (key) {
|
|
152
|
-
if (key === "default" || key === "__esModule") return;
|
|
153
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
154
|
-
if (key in exports && exports[key] === _parseFilter[key]) return;
|
|
155
|
-
Object.defineProperty(exports, key, {
|
|
156
|
-
enumerable: true,
|
|
157
|
-
get: function get() {
|
|
158
|
-
return _parseFilter[key];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
var _registry = require("./registry");
|
|
163
|
-
Object.keys(_registry).forEach(function (key) {
|
|
164
|
-
if (key === "default" || key === "__esModule") return;
|
|
165
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
166
|
-
if (key in exports && exports[key] === _registry[key]) return;
|
|
167
|
-
Object.defineProperty(exports, key, {
|
|
168
|
-
enumerable: true,
|
|
169
|
-
get: function get() {
|
|
170
|
-
return _registry[key];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
var _uid = require("./uid");
|
|
175
|
-
Object.keys(_uid).forEach(function (key) {
|
|
176
|
-
if (key === "default" || key === "__esModule") return;
|
|
177
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
178
|
-
if (key in exports && exports[key] === _uid[key]) return;
|
|
179
|
-
Object.defineProperty(exports, key, {
|
|
180
|
-
enumerable: true,
|
|
181
|
-
get: function get() {
|
|
182
|
-
return _uid[key];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
var _url = require("./url");
|
|
187
|
-
Object.keys(_url).forEach(function (key) {
|
|
188
|
-
if (key === "default" || key === "__esModule") return;
|
|
189
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
190
|
-
if (key in exports && exports[key] === _url[key]) return;
|
|
191
|
-
Object.defineProperty(exports, key, {
|
|
192
|
-
enumerable: true,
|
|
193
|
-
get: function get() {
|
|
194
|
-
return _url[key];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/collections-graph.js
CHANGED
|
@@ -1,137 +1,99 @@
|
|
|
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 collections_graph_exports = {};
|
|
30
|
+
__export(collections_graph_exports, {
|
|
31
|
+
CollectionsGraph: () => CollectionsGraph
|
|
5
32
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _lodash() {
|
|
15
|
-
const data = require("lodash");
|
|
16
|
-
_lodash = function _lodash() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
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; } } }; }
|
|
24
|
-
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); }
|
|
25
|
-
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; }
|
|
26
|
-
class CollectionsGraph {
|
|
33
|
+
module.exports = __toCommonJS(collections_graph_exports);
|
|
34
|
+
var graphlib = __toESM(require("graphlib"));
|
|
35
|
+
var import_lodash = require("lodash");
|
|
36
|
+
const _CollectionsGraph = class _CollectionsGraph {
|
|
27
37
|
static graphlib() {
|
|
28
|
-
return graphlib
|
|
38
|
+
return graphlib;
|
|
29
39
|
}
|
|
30
40
|
static connectedNodes(options) {
|
|
31
|
-
const nodes = (0,
|
|
32
|
-
const excludes = (0,
|
|
33
|
-
const graph =
|
|
34
|
-
const connectedNodes = new Set();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _iterator2 = _createForOfIteratorHelper(connected),
|
|
42
|
-
_step2;
|
|
43
|
-
try {
|
|
44
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
45
|
-
const connectedNode = _step2.value;
|
|
46
|
-
if (excludes.includes(connectedNode)) continue;
|
|
47
|
-
connectedNodes.add(connectedNode);
|
|
48
|
-
}
|
|
49
|
-
} catch (err) {
|
|
50
|
-
_iterator2.e(err);
|
|
51
|
-
} finally {
|
|
52
|
-
_iterator2.f();
|
|
53
|
-
}
|
|
41
|
+
const nodes = (0, import_lodash.castArray)(options.nodes);
|
|
42
|
+
const excludes = (0, import_lodash.castArray)(options.excludes || []);
|
|
43
|
+
const graph = _CollectionsGraph.build(options);
|
|
44
|
+
const connectedNodes = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const node of nodes) {
|
|
46
|
+
const connected = graphlib.alg.preorder(graph, node);
|
|
47
|
+
for (const connectedNode of connected) {
|
|
48
|
+
if (excludes.includes(connectedNode))
|
|
49
|
+
continue;
|
|
50
|
+
connectedNodes.add(connectedNode);
|
|
54
51
|
}
|
|
55
|
-
} catch (err) {
|
|
56
|
-
_iterator.e(err);
|
|
57
|
-
} finally {
|
|
58
|
-
_iterator.f();
|
|
59
52
|
}
|
|
60
53
|
return Array.from(connectedNodes);
|
|
61
54
|
}
|
|
62
55
|
static preOrder(options) {
|
|
63
|
-
return
|
|
56
|
+
return _CollectionsGraph.graphlib().alg.preorder(_CollectionsGraph.build(options), options.node);
|
|
64
57
|
}
|
|
65
58
|
static build(options) {
|
|
66
59
|
const collections = options.collections;
|
|
67
|
-
const direction = (options
|
|
68
|
-
const isForward = direction ===
|
|
69
|
-
const graph = new
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
74
|
-
const collection = _step3.value;
|
|
75
|
-
graph.setNode(collection.name);
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_iterator3.e(err);
|
|
79
|
-
} finally {
|
|
80
|
-
_iterator3.f();
|
|
60
|
+
const direction = (options == null ? void 0 : options.direction) || "forward";
|
|
61
|
+
const isForward = direction === "forward";
|
|
62
|
+
const graph = new graphlib.Graph();
|
|
63
|
+
for (const collection of collections) {
|
|
64
|
+
graph.setNode(collection.name);
|
|
81
65
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
graph.setEdge(collection.name, parent);
|
|
95
|
-
} else {
|
|
96
|
-
graph.setEdge(parent, collection.name);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} catch (err) {
|
|
100
|
-
_iterator5.e(err);
|
|
101
|
-
} finally {
|
|
102
|
-
_iterator5.f();
|
|
66
|
+
for (const collection of collections) {
|
|
67
|
+
const parents = collection.inherits || [];
|
|
68
|
+
for (const parent of parents) {
|
|
69
|
+
if (isForward) {
|
|
70
|
+
graph.setEdge(collection.name, parent);
|
|
71
|
+
} else {
|
|
72
|
+
graph.setEdge(parent, collection.name);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const field of collection.fields || []) {
|
|
76
|
+
if (field.type === "hasMany" || field.type === "belongsTo" || field.type === "hasOne") {
|
|
77
|
+
isForward ? graph.setEdge(collection.name, field.target) : graph.setEdge(field.target, collection.name);
|
|
103
78
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (field.type === 'belongsToMany') {
|
|
113
|
-
const throughCollection = field.through;
|
|
114
|
-
if (isForward) {
|
|
115
|
-
graph.setEdge(collection.name, throughCollection);
|
|
116
|
-
graph.setEdge(throughCollection, field.target);
|
|
117
|
-
} else {
|
|
118
|
-
graph.setEdge(field.target, throughCollection);
|
|
119
|
-
graph.setEdge(throughCollection, collection.name);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
79
|
+
if (field.type === "belongsToMany") {
|
|
80
|
+
const throughCollection = field.through;
|
|
81
|
+
if (isForward) {
|
|
82
|
+
graph.setEdge(collection.name, throughCollection);
|
|
83
|
+
graph.setEdge(throughCollection, field.target);
|
|
84
|
+
} else {
|
|
85
|
+
graph.setEdge(field.target, throughCollection);
|
|
86
|
+
graph.setEdge(throughCollection, collection.name);
|
|
122
87
|
}
|
|
123
|
-
} catch (err) {
|
|
124
|
-
_iterator6.e(err);
|
|
125
|
-
} finally {
|
|
126
|
-
_iterator6.f();
|
|
127
88
|
}
|
|
128
89
|
}
|
|
129
|
-
} catch (err) {
|
|
130
|
-
_iterator4.e(err);
|
|
131
|
-
} finally {
|
|
132
|
-
_iterator4.f();
|
|
133
90
|
}
|
|
134
91
|
return graph;
|
|
135
92
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
93
|
+
};
|
|
94
|
+
__name(_CollectionsGraph, "CollectionsGraph");
|
|
95
|
+
let CollectionsGraph = _CollectionsGraph;
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
CollectionsGraph
|
|
99
|
+
});
|