@uniformdev/next-app-router 20.63.0 → 20.63.1-alpha.17

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.esm.js CHANGED
@@ -1122,6 +1122,47 @@ function createLimitPolicy({
1122
1122
  return currentFunc();
1123
1123
  };
1124
1124
  }
1125
+ var SELECT_QUERY_PREFIX = "select.";
1126
+ function appendCsv(out, key, values) {
1127
+ if (values === void 0) {
1128
+ return;
1129
+ }
1130
+ out[key] = values.join(",");
1131
+ }
1132
+ function projectionToQuery(spec) {
1133
+ const out = {};
1134
+ if (!spec) {
1135
+ return out;
1136
+ }
1137
+ const { fields, fieldTypes, slots } = spec;
1138
+ const p = SELECT_QUERY_PREFIX;
1139
+ if (fields) {
1140
+ appendCsv(out, `${p}fields[only]`, fields.only);
1141
+ appendCsv(out, `${p}fields[except]`, fields.except);
1142
+ appendCsv(out, `${p}fields[locales]`, fields.locales);
1143
+ }
1144
+ if (fieldTypes) {
1145
+ appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
1146
+ appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
1147
+ }
1148
+ if (slots) {
1149
+ appendCsv(out, `${p}slots[only]`, slots.only);
1150
+ appendCsv(out, `${p}slots[except]`, slots.except);
1151
+ if (typeof slots.depth === "number") {
1152
+ out[`${p}slots[depth]`] = String(slots.depth);
1153
+ }
1154
+ if (slots.named) {
1155
+ const slotNames = Object.keys(slots.named).sort();
1156
+ for (const slotName of slotNames) {
1157
+ const named = slots.named[slotName];
1158
+ if (named && typeof named.depth === "number") {
1159
+ out[`${p}slots.${slotName}[depth]`] = String(named.depth);
1160
+ }
1161
+ }
1162
+ }
1163
+ }
1164
+ return out;
1165
+ }
1125
1166
  var CANVAS_URL = "/api/v1/canvas";
1126
1167
  var CanvasClient = class extends ApiClient {
1127
1168
  constructor(options) {
@@ -1136,17 +1177,24 @@ var CanvasClient = class extends ApiClient {
1136
1177
  /** Fetches lists of Canvas compositions, optionally by type */
1137
1178
  async getCompositionList(params = {}) {
1138
1179
  const { projectId } = this.options;
1139
- const { resolveData, filters, ...originParams } = params;
1180
+ const { resolveData, filters, select, ...originParams } = params;
1140
1181
  const rewrittenFilters = rewriteFiltersForApi(filters);
1182
+ const rewrittenSelect = projectionToQuery(select);
1141
1183
  if (!resolveData) {
1142
- const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
1184
+ const fetchUri = this.createUrl(CANVAS_URL, {
1185
+ ...originParams,
1186
+ projectId,
1187
+ ...rewrittenFilters,
1188
+ ...rewrittenSelect
1189
+ });
1143
1190
  return this.apiClient(fetchUri);
1144
1191
  }
1145
1192
  const edgeParams = {
1146
1193
  ...originParams,
1147
1194
  projectId,
1148
1195
  diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1149
- ...rewrittenFilters
1196
+ ...rewrittenFilters,
1197
+ ...rewrittenSelect
1150
1198
  };
1151
1199
  const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1152
1200
  return this.apiClient(edgeUrl, this.edgeApiRequestInit);
@@ -1256,15 +1304,21 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1256
1304
  }
1257
1305
  getEntries(options) {
1258
1306
  const { projectId } = this.options;
1259
- const { skipDataResolution, filters, ...params } = options;
1307
+ const { skipDataResolution, filters, select, ...params } = options;
1260
1308
  const rewrittenFilters = rewriteFiltersForApi(filters);
1309
+ const rewrittenSelect = projectionToQuery(select);
1261
1310
  if (skipDataResolution) {
1262
- const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
1311
+ const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1312
+ ...params,
1313
+ ...rewrittenFilters,
1314
+ ...rewrittenSelect,
1315
+ projectId
1316
+ });
1263
1317
  return this.apiClient(url);
1264
1318
  }
1265
1319
  const edgeUrl = this.createUrl(
1266
1320
  __privateGet2(_ContentClient2, _entriesUrl),
1267
- { ...this.getEdgeOptions(params), ...rewrittenFilters },
1321
+ { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
1268
1322
  this.edgeApiHost
1269
1323
  );
1270
1324
  return this.apiClient(
@@ -1506,7 +1560,7 @@ function hasReferencedVariables(value) {
1506
1560
  return variableTokenCount;
1507
1561
  }
1508
1562
  function walkNodeTree(node, visitor, options) {
1509
- var _a, _b;
1563
+ var _a, _b, _c;
1510
1564
  const componentQueue = [
1511
1565
  {
1512
1566
  ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
@@ -1514,12 +1568,14 @@ function walkNodeTree(node, visitor, options) {
1514
1568
  }
1515
1569
  ];
1516
1570
  const childContexts = /* @__PURE__ */ new Map();
1571
+ const order = (_a = options == null ? void 0 : options.order) != null ? _a : "dfs";
1572
+ const takeNext = () => order === "bfs" ? componentQueue.shift() : componentQueue.pop();
1517
1573
  do {
1518
- const currentQueueEntry = componentQueue.pop();
1574
+ const currentQueueEntry = takeNext();
1519
1575
  if (!currentQueueEntry) continue;
1520
1576
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1521
1577
  let visitDescendants = true;
1522
- let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1578
+ let descendantContext = (_b = childContexts.get(currentComponent.node)) != null ? _b : currentQueueEntry.context;
1523
1579
  let visitorInfo;
1524
1580
  if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
1525
1581
  visitorInfo = {
@@ -1706,39 +1762,11 @@ function walkNodeTree(node, visitor, options) {
1706
1762
  continue;
1707
1763
  }
1708
1764
  const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1709
- if (slots) {
1710
- const slotKeys = Object.keys(slots);
1711
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1712
- const slotKey = slotKeys[slotIndex];
1713
- const components = slots[slotKey];
1714
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1715
- const enqueueingComponent = components[componentIndex];
1716
- const parentSlotIndexFn = () => {
1717
- const result = currentComponent.node.slots[slotKey].findIndex(
1718
- (x) => x === enqueueingComponent
1719
- );
1720
- return result;
1721
- };
1722
- componentQueue.push({
1723
- ancestorsAndSelf: [
1724
- {
1725
- type: "slot",
1726
- node: enqueueingComponent,
1727
- parentSlot: slotKey,
1728
- parentSlotIndexFn
1729
- },
1730
- ...currentQueueEntry.ancestorsAndSelf
1731
- ],
1732
- context: descendantContext
1733
- });
1734
- }
1735
- }
1736
- }
1765
+ const childEntries = [];
1737
1766
  const properties = getPropertiesValue(currentComponent.node);
1738
1767
  if (properties) {
1739
1768
  const propertyEntries = Object.entries(properties);
1740
- for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1741
- const [propKey, propObject] = propertyEntries[propIndex];
1769
+ for (const [propKey, propObject] of propertyEntries) {
1742
1770
  if (!isNestedNodeType(propObject.type)) {
1743
1771
  continue;
1744
1772
  }
@@ -1758,13 +1786,12 @@ function walkNodeTree(node, visitor, options) {
1758
1786
  continue;
1759
1787
  }
1760
1788
  }
1761
- const blocks = (_b = propObject.value) != null ? _b : [];
1762
- for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1763
- const enqueueingBlock = blocks[blockIndex];
1789
+ const blocks = (_c = propObject.value) != null ? _c : [];
1790
+ for (const enqueueingBlock of blocks) {
1764
1791
  const blockIndexFn = () => {
1765
1792
  return getBlockValue(currentComponent.node, propKey).findIndex((x) => x === enqueueingBlock);
1766
1793
  };
1767
- componentQueue.push({
1794
+ childEntries.push({
1768
1795
  ancestorsAndSelf: [
1769
1796
  {
1770
1797
  type: "block",
@@ -1779,6 +1806,36 @@ function walkNodeTree(node, visitor, options) {
1779
1806
  }
1780
1807
  }
1781
1808
  }
1809
+ if (slots) {
1810
+ const slotKeys = Object.keys(slots);
1811
+ for (const slotKey of slotKeys) {
1812
+ const components = slots[slotKey];
1813
+ for (const enqueueingComponent of components) {
1814
+ const parentSlotIndexFn = () => {
1815
+ const result = currentComponent.node.slots[slotKey].findIndex(
1816
+ (x) => x === enqueueingComponent
1817
+ );
1818
+ return result;
1819
+ };
1820
+ childEntries.push({
1821
+ ancestorsAndSelf: [
1822
+ {
1823
+ type: "slot",
1824
+ node: enqueueingComponent,
1825
+ parentSlot: slotKey,
1826
+ parentSlotIndexFn
1827
+ },
1828
+ ...currentQueueEntry.ancestorsAndSelf
1829
+ ],
1830
+ context: descendantContext
1831
+ });
1832
+ }
1833
+ }
1834
+ }
1835
+ if (order === "dfs") {
1836
+ childEntries.reverse();
1837
+ }
1838
+ componentQueue.push(...childEntries);
1782
1839
  } while (componentQueue.length > 0);
1783
1840
  }
1784
1841
  function isNestedNodeType(type) {
@@ -1903,7 +1960,9 @@ var RouteClient = class extends ApiClient {
1903
1960
  /** Fetches lists of Canvas compositions, optionally by type */
1904
1961
  async getRoute(options) {
1905
1962
  const { projectId } = this.options;
1906
- const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
1963
+ const { select, ...rest } = options != null ? options : {};
1964
+ const rewrittenSelect = projectionToQuery(select);
1965
+ const fetchUri = this.createUrl(ROUTE_URL, { ...rest, projectId, ...rewrittenSelect }, this.edgeApiHost);
1907
1966
  return await this.apiClient(
1908
1967
  fetchUri,
1909
1968
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
package/dist/index.js CHANGED
@@ -1149,6 +1149,47 @@ function createLimitPolicy({
1149
1149
  return currentFunc();
1150
1150
  };
1151
1151
  }
1152
+ var SELECT_QUERY_PREFIX = "select.";
1153
+ function appendCsv(out, key, values) {
1154
+ if (values === void 0) {
1155
+ return;
1156
+ }
1157
+ out[key] = values.join(",");
1158
+ }
1159
+ function projectionToQuery(spec) {
1160
+ const out = {};
1161
+ if (!spec) {
1162
+ return out;
1163
+ }
1164
+ const { fields, fieldTypes, slots } = spec;
1165
+ const p = SELECT_QUERY_PREFIX;
1166
+ if (fields) {
1167
+ appendCsv(out, `${p}fields[only]`, fields.only);
1168
+ appendCsv(out, `${p}fields[except]`, fields.except);
1169
+ appendCsv(out, `${p}fields[locales]`, fields.locales);
1170
+ }
1171
+ if (fieldTypes) {
1172
+ appendCsv(out, `${p}fieldTypes[only]`, fieldTypes.only);
1173
+ appendCsv(out, `${p}fieldTypes[except]`, fieldTypes.except);
1174
+ }
1175
+ if (slots) {
1176
+ appendCsv(out, `${p}slots[only]`, slots.only);
1177
+ appendCsv(out, `${p}slots[except]`, slots.except);
1178
+ if (typeof slots.depth === "number") {
1179
+ out[`${p}slots[depth]`] = String(slots.depth);
1180
+ }
1181
+ if (slots.named) {
1182
+ const slotNames = Object.keys(slots.named).sort();
1183
+ for (const slotName of slotNames) {
1184
+ const named = slots.named[slotName];
1185
+ if (named && typeof named.depth === "number") {
1186
+ out[`${p}slots.${slotName}[depth]`] = String(named.depth);
1187
+ }
1188
+ }
1189
+ }
1190
+ }
1191
+ return out;
1192
+ }
1152
1193
  var CANVAS_URL = "/api/v1/canvas";
1153
1194
  var CanvasClient = class extends ApiClient {
1154
1195
  constructor(options) {
@@ -1163,17 +1204,24 @@ var CanvasClient = class extends ApiClient {
1163
1204
  /** Fetches lists of Canvas compositions, optionally by type */
1164
1205
  async getCompositionList(params = {}) {
1165
1206
  const { projectId } = this.options;
1166
- const { resolveData, filters, ...originParams } = params;
1207
+ const { resolveData, filters, select, ...originParams } = params;
1167
1208
  const rewrittenFilters = rewriteFiltersForApi(filters);
1209
+ const rewrittenSelect = projectionToQuery(select);
1168
1210
  if (!resolveData) {
1169
- const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
1211
+ const fetchUri = this.createUrl(CANVAS_URL, {
1212
+ ...originParams,
1213
+ projectId,
1214
+ ...rewrittenFilters,
1215
+ ...rewrittenSelect
1216
+ });
1170
1217
  return this.apiClient(fetchUri);
1171
1218
  }
1172
1219
  const edgeParams = {
1173
1220
  ...originParams,
1174
1221
  projectId,
1175
1222
  diagnostics: typeof params.diagnostics === "boolean" ? params.diagnostics : params.diagnostics === "no-data" ? "no-data" : void 0,
1176
- ...rewrittenFilters
1223
+ ...rewrittenFilters,
1224
+ ...rewrittenSelect
1177
1225
  };
1178
1226
  const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
1179
1227
  return this.apiClient(edgeUrl, this.edgeApiRequestInit);
@@ -1283,15 +1331,21 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
1283
1331
  }
1284
1332
  getEntries(options) {
1285
1333
  const { projectId } = this.options;
1286
- const { skipDataResolution, filters, ...params } = options;
1334
+ const { skipDataResolution, filters, select, ...params } = options;
1287
1335
  const rewrittenFilters = rewriteFiltersForApi(filters);
1336
+ const rewrittenSelect = projectionToQuery(select);
1288
1337
  if (skipDataResolution) {
1289
- const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
1338
+ const url = this.createUrl(__privateGet2(_ContentClient2, _entriesUrl), {
1339
+ ...params,
1340
+ ...rewrittenFilters,
1341
+ ...rewrittenSelect,
1342
+ projectId
1343
+ });
1290
1344
  return this.apiClient(url);
1291
1345
  }
1292
1346
  const edgeUrl = this.createUrl(
1293
1347
  __privateGet2(_ContentClient2, _entriesUrl),
1294
- { ...this.getEdgeOptions(params), ...rewrittenFilters },
1348
+ { ...this.getEdgeOptions(params), ...rewrittenFilters, ...rewrittenSelect },
1295
1349
  this.edgeApiHost
1296
1350
  );
1297
1351
  return this.apiClient(
@@ -1533,7 +1587,7 @@ function hasReferencedVariables(value) {
1533
1587
  return variableTokenCount;
1534
1588
  }
1535
1589
  function walkNodeTree(node, visitor, options) {
1536
- var _a, _b;
1590
+ var _a, _b, _c;
1537
1591
  const componentQueue = [
1538
1592
  {
1539
1593
  ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
@@ -1541,12 +1595,14 @@ function walkNodeTree(node, visitor, options) {
1541
1595
  }
1542
1596
  ];
1543
1597
  const childContexts = /* @__PURE__ */ new Map();
1598
+ const order = (_a = options == null ? void 0 : options.order) != null ? _a : "dfs";
1599
+ const takeNext = () => order === "bfs" ? componentQueue.shift() : componentQueue.pop();
1544
1600
  do {
1545
- const currentQueueEntry = componentQueue.pop();
1601
+ const currentQueueEntry = takeNext();
1546
1602
  if (!currentQueueEntry) continue;
1547
1603
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1548
1604
  let visitDescendants = true;
1549
- let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1605
+ let descendantContext = (_b = childContexts.get(currentComponent.node)) != null ? _b : currentQueueEntry.context;
1550
1606
  let visitorInfo;
1551
1607
  if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
1552
1608
  visitorInfo = {
@@ -1733,39 +1789,11 @@ function walkNodeTree(node, visitor, options) {
1733
1789
  continue;
1734
1790
  }
1735
1791
  const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1736
- if (slots) {
1737
- const slotKeys = Object.keys(slots);
1738
- for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1739
- const slotKey = slotKeys[slotIndex];
1740
- const components = slots[slotKey];
1741
- for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1742
- const enqueueingComponent = components[componentIndex];
1743
- const parentSlotIndexFn = () => {
1744
- const result = currentComponent.node.slots[slotKey].findIndex(
1745
- (x) => x === enqueueingComponent
1746
- );
1747
- return result;
1748
- };
1749
- componentQueue.push({
1750
- ancestorsAndSelf: [
1751
- {
1752
- type: "slot",
1753
- node: enqueueingComponent,
1754
- parentSlot: slotKey,
1755
- parentSlotIndexFn
1756
- },
1757
- ...currentQueueEntry.ancestorsAndSelf
1758
- ],
1759
- context: descendantContext
1760
- });
1761
- }
1762
- }
1763
- }
1792
+ const childEntries = [];
1764
1793
  const properties = getPropertiesValue(currentComponent.node);
1765
1794
  if (properties) {
1766
1795
  const propertyEntries = Object.entries(properties);
1767
- for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1768
- const [propKey, propObject] = propertyEntries[propIndex];
1796
+ for (const [propKey, propObject] of propertyEntries) {
1769
1797
  if (!isNestedNodeType(propObject.type)) {
1770
1798
  continue;
1771
1799
  }
@@ -1785,13 +1813,12 @@ function walkNodeTree(node, visitor, options) {
1785
1813
  continue;
1786
1814
  }
1787
1815
  }
1788
- const blocks = (_b = propObject.value) != null ? _b : [];
1789
- for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1790
- const enqueueingBlock = blocks[blockIndex];
1816
+ const blocks = (_c = propObject.value) != null ? _c : [];
1817
+ for (const enqueueingBlock of blocks) {
1791
1818
  const blockIndexFn = () => {
1792
1819
  return getBlockValue(currentComponent.node, propKey).findIndex((x) => x === enqueueingBlock);
1793
1820
  };
1794
- componentQueue.push({
1821
+ childEntries.push({
1795
1822
  ancestorsAndSelf: [
1796
1823
  {
1797
1824
  type: "block",
@@ -1806,6 +1833,36 @@ function walkNodeTree(node, visitor, options) {
1806
1833
  }
1807
1834
  }
1808
1835
  }
1836
+ if (slots) {
1837
+ const slotKeys = Object.keys(slots);
1838
+ for (const slotKey of slotKeys) {
1839
+ const components = slots[slotKey];
1840
+ for (const enqueueingComponent of components) {
1841
+ const parentSlotIndexFn = () => {
1842
+ const result = currentComponent.node.slots[slotKey].findIndex(
1843
+ (x) => x === enqueueingComponent
1844
+ );
1845
+ return result;
1846
+ };
1847
+ childEntries.push({
1848
+ ancestorsAndSelf: [
1849
+ {
1850
+ type: "slot",
1851
+ node: enqueueingComponent,
1852
+ parentSlot: slotKey,
1853
+ parentSlotIndexFn
1854
+ },
1855
+ ...currentQueueEntry.ancestorsAndSelf
1856
+ ],
1857
+ context: descendantContext
1858
+ });
1859
+ }
1860
+ }
1861
+ }
1862
+ if (order === "dfs") {
1863
+ childEntries.reverse();
1864
+ }
1865
+ componentQueue.push(...childEntries);
1809
1866
  } while (componentQueue.length > 0);
1810
1867
  }
1811
1868
  function isNestedNodeType(type) {
@@ -1930,7 +1987,9 @@ var RouteClient = class extends ApiClient {
1930
1987
  /** Fetches lists of Canvas compositions, optionally by type */
1931
1988
  async getRoute(options) {
1932
1989
  const { projectId } = this.options;
1933
- const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
1990
+ const { select, ...rest } = options != null ? options : {};
1991
+ const rewrittenSelect = projectionToQuery(select);
1992
+ const fetchUri = this.createUrl(ROUTE_URL, { ...rest, projectId, ...rewrittenSelect }, this.edgeApiHost);
1934
1993
  return await this.apiClient(
1935
1994
  fetchUri,
1936
1995
  this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0