@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.js CHANGED
@@ -1482,6 +1482,16 @@ var RestServer = class {
1482
1482
  visible = Array.isArray(raw) ? filtered : { ...raw, items: filtered };
1483
1483
  }
1484
1484
  }
1485
+ if (req.params.type === "doc") {
1486
+ const locale = this.extractLocale(req);
1487
+ const { resolveDocLocale } = await import("@objectstack/spec/system");
1488
+ const raw = visible;
1489
+ const list = Array.isArray(raw) ? raw : raw && typeof raw === "object" && Array.isArray(raw.items) ? raw.items : null;
1490
+ if (list) {
1491
+ const localized = list.map((it) => it && typeof it === "object" ? resolveDocLocale(it, locale) : it);
1492
+ visible = Array.isArray(raw) ? localized : { ...raw, items: localized };
1493
+ }
1494
+ }
1485
1495
  if (req.params.type === "doc" && req.query?.include !== "content") {
1486
1496
  const raw = visible;
1487
1497
  const list = Array.isArray(raw) ? raw : raw && typeof raw === "object" && Array.isArray(raw.items) ? raw.items : null;
@@ -1545,9 +1555,11 @@ var RestServer = class {
1545
1555
  const p = await this.resolveProtocol(environmentId, req);
1546
1556
  const wantLayered = req.query?.layers !== void 0 && req.query?.layers !== "";
1547
1557
  if (wantLayered && typeof p.getMetaItemLayered === "function") {
1558
+ const layeredPackageId = req.query?.package || void 0;
1548
1559
  const layered = await p.getMetaItemLayered({
1549
1560
  type: req.params.type,
1550
1561
  name: req.params.name,
1562
+ ...layeredPackageId ? { packageId: layeredPackageId } : {},
1551
1563
  ...environmentId ? { environmentId } : {}
1552
1564
  });
1553
1565
  res.json(layered);
@@ -1556,7 +1568,8 @@ var RestServer = class {
1556
1568
  const isAppType = req.params.type === "app";
1557
1569
  const isDraftRead = typeof req.query?.state === "string" && req.query.state.toLowerCase() === "draft";
1558
1570
  const previewDrafts = typeof req.query?.preview === "string" && req.query.preview.toLowerCase() === "draft";
1559
- if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead && !previewDrafts) {
1571
+ const packageScoped = typeof req.query?.package === "string" && req.query.package.length > 0;
1572
+ if (metadata.enableCache && p.getMetaItemCached && !isAppType && !isDraftRead && !previewDrafts && !packageScoped && req.params.type !== "doc") {
1560
1573
  const cacheRequest = {
1561
1574
  ifNoneMatch: req.headers["if-none-match"],
1562
1575
  ifModifiedSince: req.headers["if-modified-since"]
@@ -1615,6 +1628,11 @@ var RestServer = class {
1615
1628
  }
1616
1629
  }
1617
1630
  }
1631
+ if (req.params.type === "doc" && visible) {
1632
+ const locale = this.extractLocale(req);
1633
+ const { resolveDocLocale } = await import("@objectstack/spec/system");
1634
+ visible = isMetaEnvelope(visible) ? { ...visible, item: resolveDocLocale(visible.item, locale) } : resolveDocLocale(visible, locale);
1635
+ }
1618
1636
  res.header("Vary", "Accept-Language");
1619
1637
  res.json(await this.translateMetaItem(req, req.params.type, environmentId, visible));
1620
1638
  }