@terreno/admin-backend 57.4.0 → 57.6.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/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/filterParser.js
CHANGED
|
@@ -1,50 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.parseAdminListFilters = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
const POLLUTION_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
11
|
+
const REGEX_META_CHARACTERS = new Set([
|
|
48
12
|
"\\",
|
|
49
13
|
".",
|
|
50
14
|
"*",
|
|
@@ -60,32 +24,21 @@ var REGEX_META_CHARACTERS = new Set([
|
|
|
60
24
|
"[",
|
|
61
25
|
"]",
|
|
62
26
|
]);
|
|
63
|
-
|
|
27
|
+
const isOperatorKey = (key) => {
|
|
64
28
|
return key.startsWith("$");
|
|
65
29
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (POLLUTION_KEYS.has(key)) {
|
|
73
|
-
api_1.logger.warn("[admin] Dropping prototype-pollution query key: ".concat(key));
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
next[key] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
80
|
-
finally {
|
|
81
|
-
try {
|
|
82
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
30
|
+
const dropPollutionKeys = (query) => {
|
|
31
|
+
const next = {};
|
|
32
|
+
for (const [key, value] of Object.entries(query)) {
|
|
33
|
+
if (POLLUTION_KEYS.has(key)) {
|
|
34
|
+
api_1.logger.warn(`[admin] Dropping prototype-pollution query key: ${key}`);
|
|
35
|
+
continue;
|
|
83
36
|
}
|
|
84
|
-
|
|
37
|
+
next[key] = value;
|
|
85
38
|
}
|
|
86
39
|
return next;
|
|
87
40
|
};
|
|
88
|
-
|
|
41
|
+
const scalarString = (value) => {
|
|
89
42
|
if (typeof value === "string") {
|
|
90
43
|
return value;
|
|
91
44
|
}
|
|
@@ -94,15 +47,15 @@ var scalarString = function (value) {
|
|
|
94
47
|
}
|
|
95
48
|
return undefined;
|
|
96
49
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return Object.keys(record).every(
|
|
50
|
+
const hasOnlyKeys = (record, allowedKeys) => {
|
|
51
|
+
const allowed = new Set(allowedKeys);
|
|
52
|
+
return Object.keys(record).every((key) => allowed.has(key));
|
|
100
53
|
};
|
|
101
|
-
|
|
102
|
-
for (
|
|
103
|
-
|
|
54
|
+
const isEscapedRegexLiteral = (value) => {
|
|
55
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
56
|
+
const character = value[index];
|
|
104
57
|
if (character === "\\") {
|
|
105
|
-
|
|
58
|
+
const escapedCharacter = value[index + 1];
|
|
106
59
|
if (!escapedCharacter || !REGEX_META_CHARACTERS.has(escapedCharacter)) {
|
|
107
60
|
return false;
|
|
108
61
|
}
|
|
@@ -115,134 +68,123 @@ var isEscapedRegexLiteral = function (value) {
|
|
|
115
68
|
}
|
|
116
69
|
return true;
|
|
117
70
|
};
|
|
118
|
-
|
|
119
|
-
|
|
71
|
+
const parseBooleanFilter = (field, value) => {
|
|
72
|
+
const scalar = scalarString(value);
|
|
120
73
|
if (scalar === "true") {
|
|
121
74
|
return { ok: true, value: true };
|
|
122
75
|
}
|
|
123
76
|
if (scalar === "false") {
|
|
124
77
|
return { ok: true, value: false };
|
|
125
78
|
}
|
|
126
|
-
return { error:
|
|
79
|
+
return { error: `${field} must be true or false`, ok: false };
|
|
127
80
|
};
|
|
128
|
-
|
|
129
|
-
|
|
81
|
+
const parseTextFilter = (field, value) => {
|
|
82
|
+
const scalar = scalarString(value);
|
|
130
83
|
if (scalar === undefined ||
|
|
131
84
|
Array.isArray(value) ||
|
|
132
85
|
(value != null && typeof value === "object")) {
|
|
133
|
-
return { error:
|
|
86
|
+
return { error: `${field} must be a string`, ok: false };
|
|
134
87
|
}
|
|
135
88
|
return { ok: true, value: scalar };
|
|
136
89
|
};
|
|
137
|
-
|
|
90
|
+
const parseTextRegexFilter = (field, value) => {
|
|
138
91
|
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
139
|
-
return { error:
|
|
92
|
+
return { error: `${field} must be a case-insensitive regex filter`, ok: false };
|
|
140
93
|
}
|
|
141
|
-
|
|
94
|
+
const record = value;
|
|
142
95
|
if (!hasOnlyKeys(record, ["$options", "$regex"])) {
|
|
143
|
-
return { error:
|
|
96
|
+
return { error: `${field} contains an unsupported regex operator`, ok: false };
|
|
144
97
|
}
|
|
145
98
|
if (record.$options !== "i") {
|
|
146
|
-
return { error:
|
|
99
|
+
return { error: `${field} must use $options "i"`, ok: false };
|
|
147
100
|
}
|
|
148
|
-
|
|
101
|
+
const regex = scalarString(record.$regex);
|
|
149
102
|
if (!regex || !isEscapedRegexLiteral(regex)) {
|
|
150
|
-
return { error:
|
|
103
|
+
return { error: `${field} must include an escaped literal $regex pattern`, ok: false };
|
|
151
104
|
}
|
|
152
105
|
return { ok: true, value: { $options: "i", $regex: regex } };
|
|
153
106
|
};
|
|
154
|
-
|
|
107
|
+
const normalizeChoiceMongoValue = (values) => {
|
|
155
108
|
if (values.length === 1) {
|
|
156
109
|
return values[0];
|
|
157
110
|
}
|
|
158
111
|
return { $in: values };
|
|
159
112
|
};
|
|
160
|
-
|
|
113
|
+
const parseChoiceWireValue = (field, wireValue, choices, allowEmpty) => {
|
|
161
114
|
if (wireValue === api_1.ADMIN_LIST_CHOICE_EMPTY_VALUE) {
|
|
162
115
|
if (!allowEmpty) {
|
|
163
116
|
return {
|
|
164
|
-
error:
|
|
117
|
+
error: `${field} must be one of: ${choices.map((choice) => choice.value).join(", ")}`,
|
|
165
118
|
ok: false,
|
|
166
119
|
};
|
|
167
120
|
}
|
|
168
121
|
return { ok: true, value: null };
|
|
169
122
|
}
|
|
170
|
-
|
|
123
|
+
const allowed = new Set(choices.map((choice) => choice.value));
|
|
171
124
|
if (!allowed.has(wireValue)) {
|
|
172
|
-
return { error:
|
|
125
|
+
return { error: `${field} must be one of: ${[...allowed].join(", ")}`, ok: false };
|
|
173
126
|
}
|
|
174
127
|
return { ok: true, value: wireValue };
|
|
175
128
|
};
|
|
176
|
-
|
|
177
|
-
|
|
129
|
+
const parseChoiceFilter = (field, value, declared) => {
|
|
130
|
+
const parsed = parseTextFilter(field, value);
|
|
178
131
|
if (!parsed.ok) {
|
|
179
132
|
return parsed;
|
|
180
133
|
}
|
|
181
|
-
|
|
134
|
+
const wire = parseChoiceWireValue(field, parsed.value, declared.choices, declared.allowEmpty === true);
|
|
182
135
|
if (!wire.ok) {
|
|
183
136
|
return wire;
|
|
184
137
|
}
|
|
185
138
|
return { ok: true, value: wire.value };
|
|
186
139
|
};
|
|
187
|
-
|
|
188
|
-
var e_2, _a;
|
|
140
|
+
const parseChoiceInFilter = (field, value, declared) => {
|
|
189
141
|
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
190
|
-
return { error:
|
|
142
|
+
return { error: `${field} must be a multi-value choice filter`, ok: false };
|
|
191
143
|
}
|
|
192
|
-
|
|
144
|
+
const record = value;
|
|
193
145
|
if (!hasOnlyKeys(record, ["$in"])) {
|
|
194
|
-
return { error:
|
|
146
|
+
return { error: `${field} contains an unsupported choice operator`, ok: false };
|
|
195
147
|
}
|
|
196
148
|
if (!Array.isArray(record.$in)) {
|
|
197
|
-
return { error:
|
|
149
|
+
return { error: `${field} must use $in with string values`, ok: false };
|
|
198
150
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (!scalar) {
|
|
205
|
-
return { error: "".concat(field, " must use $in with string values"), ok: false };
|
|
206
|
-
}
|
|
207
|
-
var wire = parseChoiceWireValue(field, scalar, declared.choices, declared.allowEmpty === true);
|
|
208
|
-
if (!wire.ok) {
|
|
209
|
-
return wire;
|
|
210
|
-
}
|
|
211
|
-
mongoValues.push(wire.value);
|
|
151
|
+
const mongoValues = [];
|
|
152
|
+
for (const entry of record.$in) {
|
|
153
|
+
const scalar = scalarString(entry);
|
|
154
|
+
if (!scalar) {
|
|
155
|
+
return { error: `${field} must use $in with string values`, ok: false };
|
|
212
156
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
157
|
+
const wire = parseChoiceWireValue(field, scalar, declared.choices, declared.allowEmpty === true);
|
|
158
|
+
if (!wire.ok) {
|
|
159
|
+
return wire;
|
|
218
160
|
}
|
|
219
|
-
|
|
161
|
+
mongoValues.push(wire.value);
|
|
220
162
|
}
|
|
221
163
|
if (mongoValues.length === 0) {
|
|
222
|
-
return { error:
|
|
164
|
+
return { error: `${field} must include at least one choice`, ok: false };
|
|
223
165
|
}
|
|
224
166
|
return { ok: true, value: normalizeChoiceMongoValue(mongoValues) };
|
|
225
167
|
};
|
|
226
|
-
|
|
227
|
-
|
|
168
|
+
const parseRefFilter = (field, value) => {
|
|
169
|
+
const parsed = parseTextFilter(field, value);
|
|
228
170
|
if (!parsed.ok) {
|
|
229
171
|
return parsed;
|
|
230
172
|
}
|
|
231
173
|
if (!mongoose_1.default.isValidObjectId(parsed.value)) {
|
|
232
|
-
return { error:
|
|
174
|
+
return { error: `${field} must be a valid id`, ok: false };
|
|
233
175
|
}
|
|
234
176
|
return parsed;
|
|
235
177
|
};
|
|
236
|
-
|
|
237
|
-
|
|
178
|
+
const parseIsoDate = (field, value) => {
|
|
179
|
+
const scalar = scalarString(value);
|
|
238
180
|
if (scalar === undefined ||
|
|
239
181
|
Array.isArray(value) ||
|
|
240
182
|
(value != null && typeof value === "object")) {
|
|
241
|
-
return { error:
|
|
183
|
+
return { error: `${field} must be an ISO date string`, ok: false };
|
|
242
184
|
}
|
|
243
|
-
|
|
185
|
+
const parsed = luxon_1.DateTime.fromISO(scalar, { zone: "utc" });
|
|
244
186
|
if (!parsed.isValid) {
|
|
245
|
-
return { error:
|
|
187
|
+
return { error: `${field} must be an ISO date string`, ok: false };
|
|
246
188
|
}
|
|
247
189
|
return { ok: true, value: parsed.toJSDate() };
|
|
248
190
|
};
|
|
@@ -250,138 +192,116 @@ var parseIsoDate = function (field, value) {
|
|
|
250
192
|
* Parses v2-compatible list query params for declared admin filters.
|
|
251
193
|
* Undeclared keys are ignored; Mongo operator keys are rejected.
|
|
252
194
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
var declared = filters_1_1.value;
|
|
263
|
-
var field = declared.field;
|
|
264
|
-
if (declared.kind === "boolean") {
|
|
265
|
-
if (!(field in safeQuery)) {
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
consumedKeys.add(field);
|
|
269
|
-
var parsed = parseBooleanFilter(field, safeQuery[field]);
|
|
270
|
-
if (!parsed.ok) {
|
|
271
|
-
errors[field] = parsed.error;
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
filter[field] = parsed.value;
|
|
195
|
+
const parseAdminListFilters = (query, filters = []) => {
|
|
196
|
+
const safeQuery = dropPollutionKeys(query);
|
|
197
|
+
const errors = {};
|
|
198
|
+
const filter = {};
|
|
199
|
+
const consumedKeys = new Set();
|
|
200
|
+
for (const declared of filters) {
|
|
201
|
+
const field = declared.field;
|
|
202
|
+
if (declared.kind === "boolean") {
|
|
203
|
+
if (!(field in safeQuery)) {
|
|
275
204
|
continue;
|
|
276
205
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
consumedKeys.add(field);
|
|
282
|
-
var raw = safeQuery[field];
|
|
283
|
-
var regexParsed = parseTextRegexFilter(field, raw);
|
|
284
|
-
if (regexParsed.ok) {
|
|
285
|
-
filter[field] = regexParsed.value;
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
var parsed = parseTextFilter(field, raw);
|
|
289
|
-
if (!parsed.ok) {
|
|
290
|
-
errors[field] = parsed.error;
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
filter[field] = parsed.value;
|
|
206
|
+
consumedKeys.add(field);
|
|
207
|
+
const parsed = parseBooleanFilter(field, safeQuery[field]);
|
|
208
|
+
if (!parsed.ok) {
|
|
209
|
+
errors[field] = parsed.error;
|
|
294
210
|
continue;
|
|
295
211
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
var raw = safeQuery[field];
|
|
302
|
-
var inParsed = parseChoiceInFilter(field, raw, declared);
|
|
303
|
-
if (inParsed.ok) {
|
|
304
|
-
filter[field] = inParsed.value;
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
var parsed = parseChoiceFilter(field, raw, declared);
|
|
308
|
-
if (!parsed.ok) {
|
|
309
|
-
errors[field] = parsed.error;
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
filter[field] = parsed.value;
|
|
212
|
+
filter[field] = parsed.value;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (declared.kind === "text") {
|
|
216
|
+
if (!(field in safeQuery)) {
|
|
313
217
|
continue;
|
|
314
218
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
219
|
+
consumedKeys.add(field);
|
|
220
|
+
const raw = safeQuery[field];
|
|
221
|
+
const regexParsed = parseTextRegexFilter(field, raw);
|
|
222
|
+
if (regexParsed.ok) {
|
|
223
|
+
filter[field] = regexParsed.value;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const parsed = parseTextFilter(field, raw);
|
|
227
|
+
if (!parsed.ok) {
|
|
228
|
+
errors[field] = parsed.error;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
filter[field] = parsed.value;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (declared.kind === "choice") {
|
|
235
|
+
if (!(field in safeQuery)) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
consumedKeys.add(field);
|
|
239
|
+
const raw = safeQuery[field];
|
|
240
|
+
const inParsed = parseChoiceInFilter(field, raw, declared);
|
|
241
|
+
if (inParsed.ok) {
|
|
242
|
+
filter[field] = inParsed.value;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const parsed = parseChoiceFilter(field, raw, declared);
|
|
246
|
+
if (!parsed.ok) {
|
|
247
|
+
errors[field] = parsed.error;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
filter[field] = parsed.value;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (declared.kind === "ref") {
|
|
254
|
+
if (!(field in safeQuery)) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
consumedKeys.add(field);
|
|
258
|
+
const parsed = parseRefFilter(field, safeQuery[field]);
|
|
259
|
+
if (!parsed.ok) {
|
|
260
|
+
errors[field] = parsed.error;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
filter[field] = parsed.value;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (declared.kind === "dateRange") {
|
|
267
|
+
const gteKey = `${field}_gte`;
|
|
268
|
+
const lteKey = `${field}_lte`;
|
|
269
|
+
const hasGte = gteKey in safeQuery;
|
|
270
|
+
const hasLte = lteKey in safeQuery;
|
|
271
|
+
if (!hasGte && !hasLte) {
|
|
326
272
|
continue;
|
|
327
273
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
continue;
|
|
274
|
+
const range = {};
|
|
275
|
+
if (hasGte) {
|
|
276
|
+
consumedKeys.add(gteKey);
|
|
277
|
+
const parsed = parseIsoDate(gteKey, safeQuery[gteKey]);
|
|
278
|
+
if (!parsed.ok) {
|
|
279
|
+
errors[gteKey] = parsed.error;
|
|
335
280
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
consumedKeys.add(gteKey);
|
|
339
|
-
var parsed = parseIsoDate(gteKey, safeQuery[gteKey]);
|
|
340
|
-
if (!parsed.ok) {
|
|
341
|
-
errors[gteKey] = parsed.error;
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
range.$gte = parsed.value;
|
|
345
|
-
}
|
|
281
|
+
else {
|
|
282
|
+
range.$gte = parsed.value;
|
|
346
283
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
else {
|
|
354
|
-
range.$lte = parsed.value;
|
|
355
|
-
}
|
|
284
|
+
}
|
|
285
|
+
if (hasLte) {
|
|
286
|
+
consumedKeys.add(lteKey);
|
|
287
|
+
const parsed = parseIsoDate(lteKey, safeQuery[lteKey]);
|
|
288
|
+
if (!parsed.ok) {
|
|
289
|
+
errors[lteKey] = parsed.error;
|
|
356
290
|
}
|
|
357
|
-
|
|
358
|
-
|
|
291
|
+
else {
|
|
292
|
+
range.$lte = parsed.value;
|
|
359
293
|
}
|
|
360
294
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
364
|
-
finally {
|
|
365
|
-
try {
|
|
366
|
-
if (filters_1_1 && !filters_1_1.done && (_a = filters_1.return)) _a.call(filters_1);
|
|
367
|
-
}
|
|
368
|
-
finally { if (e_3) throw e_3.error; }
|
|
369
|
-
}
|
|
370
|
-
try {
|
|
371
|
-
for (var _c = __values(Object.keys(safeQuery)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
372
|
-
var key = _d.value;
|
|
373
|
-
if (isOperatorKey(key)) {
|
|
374
|
-
errors[key] = "Mongo operators are not allowed in admin list filters";
|
|
295
|
+
if (Object.keys(range).length > 0) {
|
|
296
|
+
filter[field] = range;
|
|
375
297
|
}
|
|
376
298
|
}
|
|
377
299
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
300
|
+
for (const key of Object.keys(safeQuery)) {
|
|
301
|
+
if (isOperatorKey(key)) {
|
|
302
|
+
errors[key] = "Mongo operators are not allowed in admin list filters";
|
|
382
303
|
}
|
|
383
|
-
finally { if (e_4) throw e_4.error; }
|
|
384
304
|
}
|
|
385
|
-
return { consumedKeys
|
|
305
|
+
return { consumedKeys, errors, filter };
|
|
386
306
|
};
|
|
387
307
|
exports.parseAdminListFilters = parseAdminListFilters;
|
package/dist/legacy.js
CHANGED
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.resetLegacyDeprecationWarningsForTests = exports.convertLegacyModelConfig = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const enrichAdminListFilters_1 = require("./enrichAdminListFilters");
|
|
6
|
+
const routePath_1 = require("./routePath");
|
|
7
|
+
const warnedLegacyKeys = new Set();
|
|
8
|
+
const legacyWarningKey = (config) => {
|
|
9
|
+
return `${config.model.modelName}:${(0, routePath_1.normalizeAdminRoutePath)(config.routePath)}`;
|
|
21
10
|
};
|
|
22
11
|
/**
|
|
23
12
|
* Converts legacy `AdminApp.models[]` entries into resolved admin models and emits a
|
|
24
13
|
* one-time deprecation warning per model/routePath per process.
|
|
25
14
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const convertLegacyModelConfig = (config) => {
|
|
16
|
+
const key = legacyWarningKey(config);
|
|
28
17
|
if (!warnedLegacyKeys.has(key)) {
|
|
29
18
|
warnedLegacyKeys.add(key);
|
|
30
|
-
api_1.logger.warn(
|
|
19
|
+
api_1.logger.warn(`[admin] AdminApp.models entry "${config.displayName}" uses the legacy shape (model=${config.model.modelName}, routePath=${config.routePath}). Migrate to modelRouter({admin: {...}}) — see docs/how-to/admin-add-model.md`);
|
|
31
20
|
}
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
const filters = (0, enrichAdminListFilters_1.enrichAdminListFilters)(config.filters, config.model);
|
|
22
|
+
const admin = {
|
|
34
23
|
actions: config.actions,
|
|
35
24
|
autocompleteFields: undefined,
|
|
36
25
|
bulkPatchAllowlist: config.bulkPatchAllowlist,
|
|
@@ -40,7 +29,7 @@ var convertLegacyModelConfig = function (config) {
|
|
|
40
29
|
fieldOrder: config.fieldOrder,
|
|
41
30
|
fieldOverrides: config.fieldOverrides,
|
|
42
31
|
fieldsets: config.fieldsets,
|
|
43
|
-
filters
|
|
32
|
+
filters,
|
|
44
33
|
group: config.group,
|
|
45
34
|
hiddenFields: config.hiddenFields,
|
|
46
35
|
listDisplay: config.listDisplay,
|
|
@@ -53,11 +42,18 @@ var convertLegacyModelConfig = function (config) {
|
|
|
53
42
|
searchFields: config.searchFields,
|
|
54
43
|
sortableFields: config.sortableFields,
|
|
55
44
|
};
|
|
56
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
...config,
|
|
47
|
+
admin,
|
|
48
|
+
filters,
|
|
49
|
+
routePath: (0, routePath_1.normalizeAdminRoutePath)(config.routePath),
|
|
50
|
+
source: "legacy",
|
|
51
|
+
sourceLabel: config.displayName,
|
|
52
|
+
};
|
|
57
53
|
};
|
|
58
54
|
exports.convertLegacyModelConfig = convertLegacyModelConfig;
|
|
59
55
|
/** @internal Test helper — clears one-time legacy deprecation warnings. */
|
|
60
|
-
|
|
56
|
+
const resetLegacyDeprecationWarningsForTests = () => {
|
|
61
57
|
warnedLegacyKeys.clear();
|
|
62
58
|
};
|
|
63
59
|
exports.resetLegacyDeprecationWarningsForTests = resetLegacyDeprecationWarningsForTests;
|