@objectstack/rest 9.3.0 → 9.5.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.cjs CHANGED
@@ -1522,6 +1522,16 @@ var RestServer = class {
1522
1522
  visible = Array.isArray(raw) ? filtered : { ...raw, items: filtered };
1523
1523
  }
1524
1524
  }
1525
+ if (req.params.type === "doc") {
1526
+ const locale = this.extractLocale(req);
1527
+ const { resolveDocLocale } = await import("@objectstack/spec/system");
1528
+ const raw = visible;
1529
+ const list = Array.isArray(raw) ? raw : raw && typeof raw === "object" && Array.isArray(raw.items) ? raw.items : null;
1530
+ if (list) {
1531
+ const localized = list.map((it) => it && typeof it === "object" ? resolveDocLocale(it, locale) : it);
1532
+ visible = Array.isArray(raw) ? localized : { ...raw, items: localized };
1533
+ }
1534
+ }
1525
1535
  if (req.params.type === "doc" && req.query?.include !== "content") {
1526
1536
  const raw = visible;
1527
1537
  const list = Array.isArray(raw) ? raw : raw && typeof raw === "object" && Array.isArray(raw.items) ? raw.items : null;
@@ -1585,9 +1595,11 @@ var RestServer = class {
1585
1595
  const p = await this.resolveProtocol(environmentId, req);
1586
1596
  const wantLayered = req.query?.layers !== void 0 && req.query?.layers !== "";
1587
1597
  if (wantLayered && typeof p.getMetaItemLayered === "function") {
1598
+ const layeredPackageId = req.query?.package || void 0;
1588
1599
  const layered = await p.getMetaItemLayered({
1589
1600
  type: req.params.type,
1590
1601
  name: req.params.name,
1602
+ ...layeredPackageId ? { packageId: layeredPackageId } : {},
1591
1603
  ...environmentId ? { environmentId } : {}
1592
1604
  });
1593
1605
  res.json(layered);
@@ -1596,7 +1608,8 @@ var RestServer = class {
1596
1608
  const isAppType = req.params.type === "app";
1597
1609
  const isDraftRead = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft";
1598
1610
  const previewDrafts = typeof req.query?.preview === "string" && req.query.preview.toLowerCase() === "draft";
1599
- if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead && !previewDrafts) {
1611
+ const packageScoped = typeof req.query?.package === "string" && req.query.package.length > 0;
1612
+ if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead && !previewDrafts && !packageScoped && req.params.type !== "doc") {
1600
1613
  const cacheRequest = {
1601
1614
  ifNoneMatch: req.headers["if-none-match"],
1602
1615
  ifModifiedSince: req.headers["if-modified-since"]
@@ -1655,6 +1668,11 @@ var RestServer = class {
1655
1668
  }
1656
1669
  }
1657
1670
  }
1671
+ if (req.params.type === "doc" && visible) {
1672
+ const locale = this.extractLocale(req);
1673
+ const { resolveDocLocale } = await import("@objectstack/spec/system");
1674
+ visible = isMetaEnvelope(visible) ? { ...visible, item: resolveDocLocale(visible.item, locale) } : resolveDocLocale(visible, locale);
1675
+ }
1658
1676
  res.header("Vary", "Accept-Language");
1659
1677
  res.json(await this.translateMetaItem(req, req.params.type, environmentId, visible));
1660
1678
  }