@terreno/admin-backend 0.10.0 → 0.11.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/bunfig.toml CHANGED
@@ -1,3 +1,8 @@
1
1
  [test]
2
2
  preload = ["../api/src/tests/bunSetup.ts"]
3
3
  root = "./src"
4
+ coveragePathIgnorePatterns = ["**/*.test.ts", "../api/**", "dist/**", "**/node_modules/**"]
5
+ # Enforced by scripts/check-coverage.ts; Bun parses this key but does not
6
+ # fail the run when coverage is below threshold. See
7
+ # https://github.com/oven-sh/bun/issues/7367 and https://github.com/oven-sh/bun/pull/27933.
8
+ coverageThreshold = { line = 95, function = 95 }
package/dist/adminApp.js CHANGED
@@ -83,7 +83,10 @@ var express_1 = __importDefault(require("express"));
83
83
  var luxon_1 = require("luxon");
84
84
  var mongoose_1 = __importDefault(require("mongoose"));
85
85
  var toPlainObject = function (value) {
86
- if (value && typeof value === "object" && typeof value.toObject === "function") {
86
+ if (value &&
87
+ typeof value === "object" &&
88
+ "toObject" in value &&
89
+ typeof value.toObject === "function") {
87
90
  return value.toObject();
88
91
  }
89
92
  return value;
@@ -137,6 +140,16 @@ var extractFieldMeta = function (properties, required) {
137
140
  var itemRequired = (_d = prop.items.required) !== null && _d !== void 0 ? _d : [];
138
141
  fields[key].items = extractFieldMeta(prop.items.properties, itemRequired);
139
142
  }
143
+ // For array fields of primitives, capture the item type and enum
144
+ if (prop.type === "array" && prop.items && !prop.items.properties) {
145
+ var itemProp = prop.items;
146
+ if (itemProp.type) {
147
+ fields[key].itemType = itemProp.type;
148
+ }
149
+ if (itemProp.enum) {
150
+ fields[key].itemEnum = itemProp.enum;
151
+ }
152
+ }
140
153
  // Check for ObjectId references in the raw property
141
154
  if (!fields[key].ref && prop.type === "string" && prop.format === "objectid") {
142
155
  // mongoose-to-swagger may not preserve ref directly; we'll handle this in register()
@@ -226,8 +239,8 @@ var AdminApp = /** @class */ (function () {
226
239
  // Build config response with field metadata from Mongoose schemas
227
240
  var configModels = modelConfigs.map(function (config) {
228
241
  var e_5, _a, e_6, _b;
229
- var _c, _d, _e;
230
- var _f = (0, api_1.getOpenApiSpecForModel)(config.model), properties = _f.properties, required = _f.required;
242
+ var _c, _d, _e, _f, _g;
243
+ var _h = (0, api_1.getOpenApiSpecForModel)(config.model), properties = _h.properties, required = _h.required;
231
244
  var hiddenFieldSet = new Set((_c = config.hiddenFields) !== null && _c !== void 0 ? _c : []);
232
245
  var filteredProperties = Object.fromEntries(Object.entries(properties).filter(function (_a) {
233
246
  var _b = __read(_a, 1), key = _b[0];
@@ -237,33 +250,58 @@ var AdminApp = /** @class */ (function () {
237
250
  // Extract ref information directly from the Mongoose schema
238
251
  var fields = extractFieldMeta(filteredProperties, filteredRequired);
239
252
  try {
240
- for (var _g = __values(Object.entries(fields)), _h = _g.next(); !_h.done; _h = _g.next()) {
241
- var _j = __read(_h.value, 2), key = _j[0], field = _j[1];
253
+ for (var _j = __values(Object.entries(fields)), _k = _j.next(); !_k.done; _k = _j.next()) {
254
+ var _l = __read(_k.value, 2), key = _l[0], field = _l[1];
242
255
  var schemaPath = config.model.schema.path(key);
243
256
  if (schemaPath) {
244
257
  var pathOptions = schemaPath.options;
245
258
  if (pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.ref) {
246
259
  field.ref = pathOptions.ref;
247
260
  }
248
- // Handle array of refs
261
+ // Handle array of refs (legacy: also set ref for back-compat)
249
262
  if (Array.isArray(pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.type) && ((_d = pathOptions.type[0]) === null || _d === void 0 ? void 0 : _d.ref)) {
250
263
  field.ref = pathOptions.type[0].ref;
251
264
  }
265
+ // For arrays, use the caster to infer the primitive item type/ref.
266
+ // Mongoose caster.instance is "String" | "Number" | "Boolean" | "ObjectID".
267
+ if (schemaPath.instance === "Array") {
268
+ var caster = schemaPath.caster;
269
+ if ((caster === null || caster === void 0 ? void 0 : caster.instance) && !field.items) {
270
+ var instanceToType = {
271
+ Boolean: "boolean",
272
+ Number: "number",
273
+ ObjectID: "objectid",
274
+ ObjectId: "objectid",
275
+ SchemaObjectId: "objectid",
276
+ String: "string",
277
+ };
278
+ var mapped = instanceToType[caster.instance];
279
+ if (mapped) {
280
+ field.itemType = mapped;
281
+ }
282
+ if ((_e = caster.options) === null || _e === void 0 ? void 0 : _e.ref) {
283
+ field.itemRef = caster.options.ref;
284
+ }
285
+ if ((_f = caster.options) === null || _f === void 0 ? void 0 : _f.enum) {
286
+ field.itemEnum = caster.options.enum;
287
+ }
288
+ }
289
+ }
252
290
  }
253
291
  }
254
292
  }
255
293
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
256
294
  finally {
257
295
  try {
258
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
296
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
259
297
  }
260
298
  finally { if (e_5) throw e_5.error; }
261
299
  }
262
300
  // Apply field overrides (e.g., widget: "markdown")
263
301
  if (config.fieldOverrides) {
264
302
  try {
265
- for (var _k = __values(Object.entries(config.fieldOverrides)), _l = _k.next(); !_l.done; _l = _k.next()) {
266
- var _m = __read(_l.value, 2), key = _m[0], override = _m[1];
303
+ for (var _m = __values(Object.entries(config.fieldOverrides)), _o = _m.next(); !_o.done; _o = _m.next()) {
304
+ var _p = __read(_o.value, 2), key = _p[0], override = _p[1];
267
305
  if (fields[key] && override.widget) {
268
306
  fields[key].widget = override.widget;
269
307
  }
@@ -272,13 +310,13 @@ var AdminApp = /** @class */ (function () {
272
310
  catch (e_6_1) { e_6 = { error: e_6_1 }; }
273
311
  finally {
274
312
  try {
275
- if (_l && !_l.done && (_b = _k.return)) _b.call(_k);
313
+ if (_o && !_o.done && (_b = _m.return)) _b.call(_m);
276
314
  }
277
315
  finally { if (e_6) throw e_6.error; }
278
316
  }
279
317
  }
280
318
  return {
281
- defaultSort: (_e = config.defaultSort) !== null && _e !== void 0 ? _e : "-created",
319
+ defaultSort: (_g = config.defaultSort) !== null && _g !== void 0 ? _g : "-created",
282
320
  displayName: config.displayName,
283
321
  fieldOrder: config.fieldOrder,
284
322
  fields: fields,
@@ -525,6 +563,7 @@ var AdminApp = /** @class */ (function () {
525
563
  }
526
564
  var _loop_2 = function (config) {
527
565
  var hiddenFieldSet = new Set((_e = config.hiddenFields) !== null && _e !== void 0 ? _e : []);
566
+ // noExplicitAny: ModelRouterOptions<any> matches the Model<any> from AdminModelConfig.
528
567
  var routerOptions = __assign(__assign({}, (openApi ? { openApi: openApi } : {})), { permissions: {
529
568
  create: [api_1.Permissions.IsAdmin],
530
569
  delete: [api_1.Permissions.IsAdmin],
@@ -0,0 +1 @@
1
+ export {};