@objectstack/rest 8.0.1 → 9.0.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/dist/index.js CHANGED
@@ -214,6 +214,9 @@ var RouteGroupBuilder = class {
214
214
  // src/rest-server.ts
215
215
  var logError = (...args) => globalThis.console?.error(...args);
216
216
  var TRANSLATABLE_META_TYPES = /* @__PURE__ */ new Set(["view", "action", "object", "app", "dashboard"]);
217
+ function isMetaEnvelope(value) {
218
+ return !!value && typeof value === "object" && typeof value.type === "string" && typeof value.name === "string" && value.item != null && typeof value.item === "object" && !Array.isArray(value.item);
219
+ }
217
220
  function mapDataError(error, object) {
218
221
  if (error?.code === "CONCURRENT_UPDATE" || error?.name === "ConcurrentUpdateError") {
219
222
  return {
@@ -897,21 +900,28 @@ var RestServer = class {
897
900
  const locale = this.extractLocale(req, i18n);
898
901
  if (!locale) return item;
899
902
  const { translateMetadataDocument } = await import("@objectstack/spec/system");
903
+ if (isMetaEnvelope(item)) {
904
+ return { ...item, item: translateMetadataDocument(type, item.item, bundle, { locale }) };
905
+ }
900
906
  return translateMetadataDocument(type, item, bundle, { locale });
901
907
  }
902
908
  /**
903
909
  * Translate a list of metadata documents using `translateMetaItem`.
904
910
  */
905
911
  async translateMetaItems(req, type, environmentId, items) {
906
- if (!Array.isArray(items)) return items;
907
912
  if (!TRANSLATABLE_META_TYPES.has(type)) return items;
913
+ const arr = Array.isArray(items) ? items : items && typeof items === "object" && Array.isArray(items.items) ? items.items : null;
914
+ if (!arr) return items;
908
915
  const i18n = await this.resolveI18nService(environmentId, req);
909
916
  const bundle = this.buildTranslationBundle(i18n);
910
917
  if (!bundle) return items;
911
918
  const locale = this.extractLocale(req, i18n);
912
919
  if (!locale) return items;
913
920
  const { translateMetadataDocument } = await import("@objectstack/spec/system");
914
- return items.map((item) => translateMetadataDocument(type, item, bundle, { locale }));
921
+ const translated = arr.map(
922
+ (item) => isMetaEnvelope(item) ? { ...item, item: translateMetadataDocument(type, item.item, bundle, { locale }) } : translateMetadataDocument(type, item, bundle, { locale })
923
+ );
924
+ return Array.isArray(items) ? translated : { ...items, items: translated };
915
925
  }
916
926
  /**
917
927
  * Translate the `entries` payload returned by `getMetaTypes()` — applies