@terreno/admin-backend 57.4.0 → 57.6.0
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/README.md +3 -3
- package/dist/adminApp.js +1219 -1936
- package/dist/adminConfigIdentity.js +26 -50
- package/dist/adminMigrations.js +83 -168
- package/dist/adminScriptJob.js +142 -300
- package/dist/adminTextSearch.js +21 -78
- package/dist/adminUiV2.js +49 -146
- package/dist/aggregateAdmin.js +102 -227
- package/dist/documentStorageApp.js +184 -325
- package/dist/enrichAdminListFilters.js +4 -15
- package/dist/filterParser.js +158 -238
- package/dist/legacy.js +21 -25
- package/dist/resolvedAdminModel.js +22 -78
- package/dist/routePath.js +3 -3
- package/dist/scriptCli.js +161 -307
- package/dist/tests/bunSetup.js +1 -1
- package/package.json +7 -7
- package/src/adminApp.models.test.ts +89 -3
- package/src/adminApp.ts +31 -8
- package/tsconfig.json +6 -21
package/dist/adminUiV2.js
CHANGED
|
@@ -3,89 +3,45 @@
|
|
|
3
3
|
* Admin UI v2 helpers and constants (Django-parity config contract).
|
|
4
4
|
* @see docs/implementationPlans/admin-ui-v2-django-parity.md
|
|
5
5
|
*/
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __values = (this && this.__values) || function(o) {
|
|
43
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
-
if (m) return m.call(o);
|
|
45
|
-
if (o && typeof o.length === "number") return {
|
|
46
|
-
next: function () {
|
|
47
|
-
if (o && i >= o.length) o = void 0;
|
|
48
|
-
return { value: o && o[i++], done: !o };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
-
};
|
|
53
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
7
|
exports.defaultBulkPatchAllowlistFrom = exports.buildAdminModelQueryFields = exports.normalizeAdminHome = exports.normalizeSidebarRecentLast = exports.SYSTEM_ADMIN_FIELDS = exports.MAX_BULK_PATCH_IDS = exports.ADMIN_SCHEMA_VERSION = void 0;
|
|
55
8
|
exports.ADMIN_SCHEMA_VERSION = 2;
|
|
56
9
|
exports.MAX_BULK_PATCH_IDS = 1000;
|
|
57
10
|
exports.SYSTEM_ADMIN_FIELDS = new Set(["_id", "id", "__v", "created", "updated", "deleted"]);
|
|
58
|
-
|
|
11
|
+
const normalizeSidebarRecentLast = (sidebar) => {
|
|
59
12
|
if (!sidebar || sidebar.length === 0) {
|
|
60
13
|
return sidebar;
|
|
61
14
|
}
|
|
62
15
|
if (!sidebar.includes("recentActivity")) {
|
|
63
16
|
return sidebar;
|
|
64
17
|
}
|
|
65
|
-
|
|
66
|
-
return
|
|
18
|
+
const without = sidebar.filter((id) => id !== "recentActivity");
|
|
19
|
+
return [...without, "recentActivity"];
|
|
67
20
|
};
|
|
68
21
|
exports.normalizeSidebarRecentLast = normalizeSidebarRecentLast;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (home === null || home === void 0 ? void 0 : home.slots) {
|
|
22
|
+
const normalizeAdminHome = (home) => {
|
|
23
|
+
const title = home?.title ?? "Administration";
|
|
24
|
+
if (home?.slots) {
|
|
73
25
|
return {
|
|
74
|
-
slots:
|
|
75
|
-
|
|
26
|
+
slots: {
|
|
27
|
+
...home.slots,
|
|
28
|
+
sidebar: (0, exports.normalizeSidebarRecentLast)(home.slots.sidebar),
|
|
29
|
+
},
|
|
30
|
+
title,
|
|
76
31
|
};
|
|
77
32
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
?
|
|
33
|
+
if (home?.widgets && home.widgets.length > 0) {
|
|
34
|
+
const main = home.widgets.includes("modelsGrid")
|
|
35
|
+
? [...home.widgets]
|
|
36
|
+
: ["modelsGrid", ...home.widgets];
|
|
81
37
|
return {
|
|
82
|
-
slots: { main
|
|
83
|
-
title
|
|
38
|
+
slots: { main },
|
|
39
|
+
title,
|
|
84
40
|
};
|
|
85
41
|
}
|
|
86
42
|
return {
|
|
87
43
|
slots: { main: ["modelsGrid"] },
|
|
88
|
-
title
|
|
44
|
+
title,
|
|
89
45
|
};
|
|
90
46
|
};
|
|
91
47
|
exports.normalizeAdminHome = normalizeAdminHome;
|
|
@@ -93,96 +49,43 @@ exports.normalizeAdminHome = normalizeAdminHome;
|
|
|
93
49
|
* Derives `modelRouter` `queryFields` from admin UI v2 list metadata so changelist
|
|
94
50
|
* filters and sort keys match allowed query parameters on `GET` list routes.
|
|
95
51
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
52
|
+
const buildAdminModelQueryFields = (config) => {
|
|
53
|
+
const fields = new Set(["_id", "q"]);
|
|
54
|
+
for (const name of config.listFields) {
|
|
55
|
+
fields.add(name);
|
|
56
|
+
}
|
|
57
|
+
for (const name of config.listDisplay ?? []) {
|
|
58
|
+
fields.add(name);
|
|
59
|
+
}
|
|
60
|
+
for (const name of config.searchFields ?? []) {
|
|
61
|
+
fields.add(name);
|
|
62
|
+
}
|
|
63
|
+
for (const filter of config.filters ?? []) {
|
|
64
|
+
fields.add(filter.field);
|
|
65
|
+
if (filter.kind === "dateRange") {
|
|
66
|
+
fields.add(`${filter.field}_gte`);
|
|
67
|
+
fields.add(`${filter.field}_lte`);
|
|
110
68
|
}
|
|
111
|
-
finally { if (e_1) throw e_1.error; }
|
|
112
69
|
}
|
|
113
|
-
|
|
114
|
-
for (var _k = __values((_e = config.listDisplay) !== null && _e !== void 0 ? _e : []), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
115
|
-
var name_2 = _l.value;
|
|
116
|
-
fields.add(name_2);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
120
|
-
finally {
|
|
121
|
-
try {
|
|
122
|
-
if (_l && !_l.done && (_b = _k.return)) _b.call(_k);
|
|
123
|
-
}
|
|
124
|
-
finally { if (e_2) throw e_2.error; }
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
for (var _m = __values((_f = config.searchFields) !== null && _f !== void 0 ? _f : []), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
128
|
-
var name_3 = _o.value;
|
|
129
|
-
fields.add(name_3);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
133
|
-
finally {
|
|
134
|
-
try {
|
|
135
|
-
if (_o && !_o.done && (_c = _m.return)) _c.call(_m);
|
|
136
|
-
}
|
|
137
|
-
finally { if (e_3) throw e_3.error; }
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
for (var _p = __values((_g = config.filters) !== null && _g !== void 0 ? _g : []), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
141
|
-
var filter = _q.value;
|
|
142
|
-
fields.add(filter.field);
|
|
143
|
-
if (filter.kind === "dateRange") {
|
|
144
|
-
fields.add("".concat(filter.field, "_gte"));
|
|
145
|
-
fields.add("".concat(filter.field, "_lte"));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
150
|
-
finally {
|
|
151
|
-
try {
|
|
152
|
-
if (_q && !_q.done && (_d = _p.return)) _d.call(_p);
|
|
153
|
-
}
|
|
154
|
-
finally { if (e_4) throw e_4.error; }
|
|
155
|
-
}
|
|
156
|
-
return __spreadArray([], __read(fields), false);
|
|
70
|
+
return [...fields];
|
|
157
71
|
};
|
|
158
72
|
exports.buildAdminModelQueryFields = buildAdminModelQueryFields;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var field = _c.value;
|
|
165
|
-
if (exports.SYSTEM_ADMIN_FIELDS.has(field)) {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
if (params.hiddenFieldSet.has(field)) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (params.readonlyFields.includes(field)) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (!params.schemaPaths.has(field)) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
out.push(field);
|
|
73
|
+
const defaultBulkPatchAllowlistFrom = (params) => {
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const field of params.listFields) {
|
|
76
|
+
if (exports.SYSTEM_ADMIN_FIELDS.has(field)) {
|
|
77
|
+
continue;
|
|
178
78
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
79
|
+
if (params.hiddenFieldSet.has(field)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (params.readonlyFields.includes(field)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!params.schemaPaths.has(field)) {
|
|
86
|
+
continue;
|
|
184
87
|
}
|
|
185
|
-
|
|
88
|
+
out.push(field);
|
|
186
89
|
}
|
|
187
90
|
return out;
|
|
188
91
|
};
|
package/dist/aggregateAdmin.js
CHANGED
|
@@ -1,279 +1,154 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.aggregateFromTerrenoApp = exports.collectPluginAdminContributions = exports.collectRegisteredAdminModels = exports.aggregateAdminContributions = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const legacy_1 = require("./legacy");
|
|
6
|
+
const resolvedAdminModel_1 = require("./resolvedAdminModel");
|
|
7
|
+
const routePath_1 = require("./routePath");
|
|
8
|
+
const isModelRouterRegistration = (registration) => {
|
|
45
9
|
return registration.__type === "modelRouter";
|
|
46
10
|
};
|
|
47
|
-
|
|
11
|
+
const contributionScriptToConfig = (script) => ({
|
|
48
12
|
args: script.args,
|
|
49
13
|
description: script.description,
|
|
50
14
|
name: script.name,
|
|
51
15
|
runner: script.runner,
|
|
52
|
-
});
|
|
53
|
-
|
|
16
|
+
});
|
|
17
|
+
const contributionScreenToConfig = (screen) => ({
|
|
54
18
|
adminAccess: screen.adminAccess,
|
|
55
19
|
displayName: screen.displayName,
|
|
56
20
|
group: screen.group,
|
|
57
21
|
icon: screen.icon,
|
|
58
22
|
name: screen.name,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var item = incoming_1_1.value;
|
|
67
|
-
if (seen.has(item.name)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
seen.add(item.name);
|
|
71
|
-
merged.push(item);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
75
|
-
finally {
|
|
76
|
-
try {
|
|
77
|
-
if (incoming_1_1 && !incoming_1_1.done && (_a = incoming_1.return)) _a.call(incoming_1);
|
|
23
|
+
});
|
|
24
|
+
const mergeUniqueByName = (existing, incoming) => {
|
|
25
|
+
const seen = new Set(existing.map((item) => item.name));
|
|
26
|
+
const merged = [...existing];
|
|
27
|
+
for (const item of incoming) {
|
|
28
|
+
if (seen.has(item.name)) {
|
|
29
|
+
continue;
|
|
78
30
|
}
|
|
79
|
-
|
|
31
|
+
seen.add(item.name);
|
|
32
|
+
merged.push(item);
|
|
80
33
|
}
|
|
81
34
|
return merged;
|
|
82
35
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var widget = incoming_2_1.value;
|
|
90
|
-
if (seen.has(widget.id)) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
seen.add(widget.id);
|
|
94
|
-
merged.push(widget.id);
|
|
36
|
+
const mergeWidgetIds = (existing, incoming) => {
|
|
37
|
+
const seen = new Set(existing);
|
|
38
|
+
const merged = [...existing];
|
|
39
|
+
for (const widget of incoming) {
|
|
40
|
+
if (seen.has(widget.id)) {
|
|
41
|
+
continue;
|
|
95
42
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
finally {
|
|
99
|
-
try {
|
|
100
|
-
if (incoming_2_1 && !incoming_2_1.done && (_a = incoming_2.return)) _a.call(incoming_2);
|
|
101
|
-
}
|
|
102
|
-
finally { if (e_2) throw e_2.error; }
|
|
43
|
+
seen.add(widget.id);
|
|
44
|
+
merged.push(widget.id);
|
|
103
45
|
}
|
|
104
46
|
return merged;
|
|
105
47
|
};
|
|
106
|
-
|
|
107
|
-
api_1.logger.warn(
|
|
48
|
+
const warnShadowed = (path, incoming, existing) => {
|
|
49
|
+
api_1.logger.warn(`[admin] routePath "${path}" from ${incoming.source} (${incoming.sourceLabel}) overrides ${existing.source} (${existing.sourceLabel})`);
|
|
108
50
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (contribution.scripts) {
|
|
142
|
-
scripts = mergeUniqueByName(scripts, contribution.scripts.map(contributionScriptToConfig));
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
for (var _k = (e_5 = void 0, __values((_f = contribution.models) !== null && _f !== void 0 ? _f : [])), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
146
|
-
var modelContribution = _l.value;
|
|
147
|
-
var path = (0, routePath_1.normalizeAdminRoutePath)(modelContribution.routePath);
|
|
148
|
-
var resolved = (0, resolvedAdminModel_1.resolvedModelFromAdminConfig)({
|
|
149
|
-
admin: modelContribution.admin,
|
|
150
|
-
model: modelContribution.model,
|
|
151
|
-
populatePaths: modelContribution.populatePaths,
|
|
152
|
-
queryFilter: undefined,
|
|
153
|
-
routePath: path,
|
|
154
|
-
source: "plugin",
|
|
155
|
-
sourceLabel: modelContribution.admin.displayName,
|
|
156
|
-
});
|
|
157
|
-
var existing = modelsByPath.get(path);
|
|
158
|
-
if (existing) {
|
|
159
|
-
warnShadowed(path, resolved, existing);
|
|
160
|
-
}
|
|
161
|
-
modelsByPath.set(path, resolved);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
165
|
-
finally {
|
|
166
|
-
try {
|
|
167
|
-
if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
|
|
168
|
-
}
|
|
169
|
-
finally { if (e_5) throw e_5.error; }
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
174
|
-
finally {
|
|
175
|
-
try {
|
|
176
|
-
if (pluginContributions_1_1 && !pluginContributions_1_1.done && (_c = pluginContributions_1.return)) _c.call(pluginContributions_1);
|
|
177
|
-
}
|
|
178
|
-
finally { if (e_4) throw e_4.error; }
|
|
179
|
-
}
|
|
180
|
-
try {
|
|
181
|
-
for (var registeredModels_1 = __values(registeredModels), registeredModels_1_1 = registeredModels_1.next(); !registeredModels_1_1.done; registeredModels_1_1 = registeredModels_1.next()) {
|
|
182
|
-
var registered = registeredModels_1_1.value;
|
|
183
|
-
var path = registered.routePath;
|
|
184
|
-
var existingRegistered = registeredByPath.get(path);
|
|
185
|
-
if (existingRegistered) {
|
|
186
|
-
throw new api_1.APIError({
|
|
187
|
-
status: 500,
|
|
188
|
-
title: "Duplicate admin modelRouter routePath \"".concat(path, "\" (").concat(existingRegistered.sourceLabel, " and ").concat(registered.sourceLabel, ")"),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
registeredByPath.set(path, registered);
|
|
192
|
-
var existing = modelsByPath.get(path);
|
|
51
|
+
const aggregateAdminContributions = ({ legacyModels = [], pluginContributions = [], registeredModels = [], }) => {
|
|
52
|
+
const modelsByPath = new Map();
|
|
53
|
+
const registeredByPath = new Map();
|
|
54
|
+
for (const legacy of legacyModels) {
|
|
55
|
+
const resolved = (0, legacy_1.convertLegacyModelConfig)(legacy);
|
|
56
|
+
modelsByPath.set(resolved.routePath, resolved);
|
|
57
|
+
}
|
|
58
|
+
let customScreens = [];
|
|
59
|
+
let scripts = [];
|
|
60
|
+
let widgetIds = [];
|
|
61
|
+
for (const contribution of pluginContributions) {
|
|
62
|
+
if (contribution.homeWidgets) {
|
|
63
|
+
widgetIds = mergeWidgetIds(widgetIds, contribution.homeWidgets);
|
|
64
|
+
}
|
|
65
|
+
if (contribution.customScreens) {
|
|
66
|
+
customScreens = mergeUniqueByName(customScreens, contribution.customScreens.map(contributionScreenToConfig));
|
|
67
|
+
}
|
|
68
|
+
if (contribution.scripts) {
|
|
69
|
+
scripts = mergeUniqueByName(scripts, contribution.scripts.map(contributionScriptToConfig));
|
|
70
|
+
}
|
|
71
|
+
for (const modelContribution of contribution.models ?? []) {
|
|
72
|
+
const path = (0, routePath_1.normalizeAdminRoutePath)(modelContribution.routePath);
|
|
73
|
+
const resolved = (0, resolvedAdminModel_1.resolvedModelFromAdminConfig)({
|
|
74
|
+
admin: modelContribution.admin,
|
|
75
|
+
model: modelContribution.model,
|
|
76
|
+
populatePaths: modelContribution.populatePaths,
|
|
77
|
+
queryFilter: undefined,
|
|
78
|
+
routePath: path,
|
|
79
|
+
source: "plugin",
|
|
80
|
+
sourceLabel: modelContribution.admin.displayName,
|
|
81
|
+
});
|
|
82
|
+
const existing = modelsByPath.get(path);
|
|
193
83
|
if (existing) {
|
|
194
|
-
warnShadowed(path,
|
|
84
|
+
warnShadowed(path, resolved, existing);
|
|
195
85
|
}
|
|
196
|
-
modelsByPath.set(path,
|
|
86
|
+
modelsByPath.set(path, resolved);
|
|
197
87
|
}
|
|
198
88
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
89
|
+
for (const registered of registeredModels) {
|
|
90
|
+
const path = registered.routePath;
|
|
91
|
+
const existingRegistered = registeredByPath.get(path);
|
|
92
|
+
if (existingRegistered) {
|
|
93
|
+
throw new api_1.APIError({
|
|
94
|
+
status: 500,
|
|
95
|
+
title: `Duplicate admin modelRouter routePath "${path}" (${existingRegistered.sourceLabel} and ${registered.sourceLabel})`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
registeredByPath.set(path, registered);
|
|
99
|
+
const existing = modelsByPath.get(path);
|
|
100
|
+
if (existing) {
|
|
101
|
+
warnShadowed(path, registered, existing);
|
|
203
102
|
}
|
|
204
|
-
|
|
103
|
+
modelsByPath.set(path, registered);
|
|
205
104
|
}
|
|
206
105
|
return {
|
|
207
|
-
customScreens
|
|
208
|
-
models:
|
|
209
|
-
scripts
|
|
210
|
-
widgetIds
|
|
106
|
+
customScreens,
|
|
107
|
+
models: [...modelsByPath.values()],
|
|
108
|
+
scripts,
|
|
109
|
+
widgetIds,
|
|
211
110
|
};
|
|
212
111
|
};
|
|
213
112
|
exports.aggregateAdminContributions = aggregateAdminContributions;
|
|
214
|
-
|
|
215
|
-
var e_7, _a;
|
|
113
|
+
const collectRegisteredAdminModels = (terrenoApp) => {
|
|
216
114
|
if (!terrenoApp) {
|
|
217
115
|
return [];
|
|
218
116
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
sourceLabel: registration.model.modelName,
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
238
|
-
finally {
|
|
239
|
-
try {
|
|
240
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
241
|
-
}
|
|
242
|
-
finally { if (e_7) throw e_7.error; }
|
|
117
|
+
const models = [];
|
|
118
|
+
for (const registration of terrenoApp.getRegistrations()) {
|
|
119
|
+
if (!isModelRouterRegistration(registration) || !registration.options.admin) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
models.push((0, resolvedAdminModel_1.resolvedModelFromAdminConfig)({
|
|
123
|
+
admin: registration.options.admin,
|
|
124
|
+
model: registration.model,
|
|
125
|
+
populatePaths: registration.options.populatePaths,
|
|
126
|
+
registrationPath: registration.path,
|
|
127
|
+
routePath: registration.path,
|
|
128
|
+
source: "registered",
|
|
129
|
+
sourceLabel: registration.model.modelName,
|
|
130
|
+
}));
|
|
243
131
|
}
|
|
244
132
|
return models;
|
|
245
133
|
};
|
|
246
134
|
exports.collectRegisteredAdminModels = collectRegisteredAdminModels;
|
|
247
|
-
|
|
248
|
-
var e_8, _a;
|
|
249
|
-
var _b;
|
|
135
|
+
const collectPluginAdminContributions = (terrenoApp) => {
|
|
250
136
|
if (!terrenoApp) {
|
|
251
137
|
return [];
|
|
252
138
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (contribution) {
|
|
259
|
-
contributions.push(contribution);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
264
|
-
finally {
|
|
265
|
-
try {
|
|
266
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
139
|
+
const contributions = [];
|
|
140
|
+
for (const plugin of terrenoApp.getPlugins()) {
|
|
141
|
+
const contribution = plugin.adminContribution?.();
|
|
142
|
+
if (contribution) {
|
|
143
|
+
contributions.push(contribution);
|
|
267
144
|
}
|
|
268
|
-
finally { if (e_8) throw e_8.error; }
|
|
269
145
|
}
|
|
270
146
|
return contributions;
|
|
271
147
|
};
|
|
272
148
|
exports.collectPluginAdminContributions = collectPluginAdminContributions;
|
|
273
|
-
|
|
274
|
-
var _b = _a.legacyModels, legacyModels = _b === void 0 ? [] : _b, terrenoApp = _a.terrenoApp;
|
|
149
|
+
const aggregateFromTerrenoApp = ({ legacyModels = [], terrenoApp, }) => {
|
|
275
150
|
return (0, exports.aggregateAdminContributions)({
|
|
276
|
-
legacyModels
|
|
151
|
+
legacyModels,
|
|
277
152
|
pluginContributions: (0, exports.collectPluginAdminContributions)(terrenoApp),
|
|
278
153
|
registeredModels: (0, exports.collectRegisteredAdminModels)(terrenoApp),
|
|
279
154
|
});
|