@uniformdev/transformer 1.1.10 → 1.1.12

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.d.ts CHANGED
@@ -417,13 +417,20 @@ interface ContentTypeField {
417
417
  localizable?: boolean;
418
418
  typeConfig?: Record<string, unknown>;
419
419
  }
420
+ interface DataResourceDefinition {
421
+ type: string;
422
+ variables?: Record<string, string>;
423
+ }
420
424
  interface EntryDefinition {
421
425
  entry: {
422
426
  _id: string;
423
427
  _name: string;
424
428
  type: string;
425
429
  fields: Record<string, ParameterValue>;
430
+ _dataResources?: Record<string, DataResourceDefinition>;
431
+ [key: string]: unknown;
426
432
  };
433
+ [key: string]: unknown;
427
434
  }
428
435
  interface FlattenedInstance {
429
436
  instance: ComponentInstance;
@@ -451,6 +458,7 @@ declare class CompositionConverterService {
451
458
  generateEntryFromFlattenedInstance(inst: FlattenedInstance): EntryDefinition;
452
459
  findFlattenTargets(slots: Record<string, ComponentInstance[]>, targetType: string, compositionId: string, compositionName: string, strict: boolean): FlattenedInstance[];
453
460
  private walkSlots;
461
+ private transformContentReferences;
454
462
  private compareTypes;
455
463
  private truncate;
456
464
  }
package/dist/index.js CHANGED
@@ -1705,6 +1705,8 @@ var CompositionConverterService = class {
1705
1705
  contentTypeMap.set(rootType, contentType);
1706
1706
  }
1707
1707
  const flattenContentTypeMap = /* @__PURE__ */ new Map();
1708
+ const missingFlattenTypes = [];
1709
+ const foundMissingFlattenTypes = /* @__PURE__ */ new Set();
1708
1710
  for (const flattenType of flattenComponentIds) {
1709
1711
  const isRootType = [...rootComponentTypes].some(
1710
1712
  (rt) => this.compareTypes(rt, flattenType, strict)
@@ -1722,57 +1724,13 @@ var CompositionConverterService = class {
1722
1724
  flattenContentTypeMap.set(flattenType, contentType);
1723
1725
  } catch (error) {
1724
1726
  if (error instanceof ComponentNotFoundError) {
1725
- throw new ComponentNotFoundError(flattenType, componentsDirFull);
1727
+ this.logger.info(`Flatten component type not found: ${flattenType}`);
1728
+ missingFlattenTypes.push(flattenType);
1729
+ continue;
1726
1730
  }
1727
1731
  throw error;
1728
1732
  }
1729
1733
  }
1730
- if (flattenComponentIds.length > 0) {
1731
- for (const contentType of contentTypeMap.values()) {
1732
- for (const flattenType of flattenComponentIds) {
1733
- if (this.compareTypes(flattenType, contentType.id, strict)) {
1734
- continue;
1735
- }
1736
- contentType.fields.push({
1737
- id: flattenType,
1738
- name: flattenType,
1739
- type: "contentReference",
1740
- typeConfig: {
1741
- isMulti: true,
1742
- allowedContentTypes: [flattenType]
1743
- },
1744
- localizable: false
1745
- });
1746
- }
1747
- }
1748
- }
1749
- for (const [typeName, contentType] of contentTypeMap) {
1750
- const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
1751
- const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
1752
- const refCount = contentType.fields.filter((f) => f.type === "contentReference").length;
1753
- const refInfo = refCount > 0 ? ` + ${refCount} reference(s)` : "";
1754
- this.logger.action(
1755
- whatIf,
1756
- "WRITE",
1757
- `${contentTypesDir}/${typeName}.json (${fieldCount} fields${refInfo})`
1758
- );
1759
- if (!whatIf) {
1760
- await this.fileSystem.writeFile(filePath, contentType);
1761
- }
1762
- contentTypesWritten++;
1763
- }
1764
- for (const [typeName, contentType] of flattenContentTypeMap) {
1765
- const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
1766
- this.logger.action(
1767
- whatIf,
1768
- "WRITE",
1769
- `${contentTypesDir}/${typeName}.json (${contentType.fields.length} fields)`
1770
- );
1771
- if (!whatIf) {
1772
- await this.fileSystem.writeFile(filePath, contentType);
1773
- }
1774
- contentTypesWritten++;
1775
- }
1776
1734
  for (const { composition } of compositionResults) {
1777
1735
  const comp = composition.composition;
1778
1736
  const compositionId = comp._id;
@@ -1797,6 +1755,9 @@ var CompositionConverterService = class {
1797
1755
  );
1798
1756
  if (instances.length > 0) {
1799
1757
  flattenedByType.set(flattenType, instances);
1758
+ if (missingFlattenTypes.includes(flattenType)) {
1759
+ foundMissingFlattenTypes.add(flattenType);
1760
+ }
1800
1761
  }
1801
1762
  }
1802
1763
  }
@@ -1806,6 +1767,9 @@ var CompositionConverterService = class {
1806
1767
  value: instances.map((inst) => inst.determinisiticId)
1807
1768
  };
1808
1769
  }
1770
+ if (flattenComponentIds.length > 0) {
1771
+ this.transformContentReferences(entry);
1772
+ }
1809
1773
  const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${compositionId}.json`);
1810
1774
  this.logger.action(
1811
1775
  whatIf,
@@ -1835,6 +1799,63 @@ var CompositionConverterService = class {
1835
1799
  }
1836
1800
  }
1837
1801
  }
1802
+ if (flattenComponentIds.length > 0) {
1803
+ for (const contentType of contentTypeMap.values()) {
1804
+ for (const flattenType of flattenComponentIds) {
1805
+ if (this.compareTypes(flattenType, contentType.id, strict)) {
1806
+ continue;
1807
+ }
1808
+ if (missingFlattenTypes.includes(flattenType) && !foundMissingFlattenTypes.has(flattenType)) {
1809
+ continue;
1810
+ }
1811
+ contentType.fields.push({
1812
+ id: flattenType,
1813
+ name: flattenType,
1814
+ type: "contentReference",
1815
+ typeConfig: {
1816
+ isMulti: true,
1817
+ allowedContentTypes: [flattenType]
1818
+ },
1819
+ localizable: false
1820
+ });
1821
+ }
1822
+ }
1823
+ }
1824
+ for (const [typeName, contentType] of contentTypeMap) {
1825
+ const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
1826
+ const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
1827
+ const refCount = contentType.fields.filter((f) => f.type === "contentReference").length;
1828
+ const refInfo = refCount > 0 ? ` + ${refCount} reference(s)` : "";
1829
+ this.logger.action(
1830
+ whatIf,
1831
+ "WRITE",
1832
+ `${contentTypesDir}/${typeName}.json (${fieldCount} fields${refInfo})`
1833
+ );
1834
+ if (!whatIf) {
1835
+ await this.fileSystem.writeFile(filePath, contentType);
1836
+ }
1837
+ contentTypesWritten++;
1838
+ }
1839
+ for (const [typeName, contentType] of flattenContentTypeMap) {
1840
+ const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
1841
+ this.logger.action(
1842
+ whatIf,
1843
+ "WRITE",
1844
+ `${contentTypesDir}/${typeName}.json (${contentType.fields.length} fields)`
1845
+ );
1846
+ if (!whatIf) {
1847
+ await this.fileSystem.writeFile(filePath, contentType);
1848
+ }
1849
+ contentTypesWritten++;
1850
+ }
1851
+ const neverFoundMissingTypes = missingFlattenTypes.filter(
1852
+ (type) => !foundMissingFlattenTypes.has(type)
1853
+ );
1854
+ if (neverFoundMissingTypes.length > 0) {
1855
+ this.logger.warn(
1856
+ `Flatten component type(s) not found in any composition: ${neverFoundMissingTypes.join(", ")}`
1857
+ );
1858
+ }
1838
1859
  return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened };
1839
1860
  }
1840
1861
  // --- Content Type Generation ---
@@ -1871,13 +1892,29 @@ var CompositionConverterService = class {
1871
1892
  // --- Entry Generation ---
1872
1893
  generateEntryFromComposition(composition) {
1873
1894
  const comp = composition.composition;
1895
+ const compositionSpecificKeys = /* @__PURE__ */ new Set(["_id", "_name", "type", "parameters", "slots", "_overrides"]);
1896
+ const extraRootProps = {};
1897
+ for (const [key, value] of Object.entries(comp)) {
1898
+ if (!compositionSpecificKeys.has(key) && value != null) {
1899
+ extraRootProps[key] = value;
1900
+ }
1901
+ }
1902
+ const wrapperKeys = /* @__PURE__ */ new Set(["composition"]);
1903
+ const extraWrapperProps = {};
1904
+ for (const [key, value] of Object.entries(composition)) {
1905
+ if (!wrapperKeys.has(key) && value != null) {
1906
+ extraWrapperProps[key] = value;
1907
+ }
1908
+ }
1874
1909
  return {
1875
1910
  entry: {
1876
1911
  _id: comp._id,
1877
1912
  _name: comp._name ?? comp._id,
1878
1913
  type: comp.type,
1879
- fields: { ...comp.parameters ?? {} }
1880
- }
1914
+ fields: { ...comp.parameters ?? {} },
1915
+ ...extraRootProps
1916
+ },
1917
+ ...extraWrapperProps
1881
1918
  };
1882
1919
  }
1883
1920
  generateEntryFromFlattenedInstance(inst) {
@@ -1931,6 +1968,30 @@ var CompositionConverterService = class {
1931
1968
  }
1932
1969
  }
1933
1970
  }
1971
+ // --- Content Reference Transformation ---
1972
+ transformContentReferences(entry) {
1973
+ const dataResources = {};
1974
+ for (const [fieldName, field] of Object.entries(entry.entry.fields)) {
1975
+ if (field.type === "contentReference" && Array.isArray(field.value)) {
1976
+ const entryIds = field.value;
1977
+ const resourceKey = `ref-${entry.entry._id}-${fieldName}`;
1978
+ field.value = `\${#jptr:/${resourceKey}/entries}`;
1979
+ dataResources[resourceKey] = {
1980
+ type: "uniformContentInternalReference",
1981
+ variables: {
1982
+ locale: "${locale}",
1983
+ entryIds: entryIds.join(",")
1984
+ }
1985
+ };
1986
+ }
1987
+ }
1988
+ if (Object.keys(dataResources).length > 0) {
1989
+ entry.entry._dataResources = {
1990
+ ...entry.entry._dataResources ?? {},
1991
+ ...dataResources
1992
+ };
1993
+ }
1994
+ }
1934
1995
  // --- Utilities ---
1935
1996
  compareTypes(type1, type2, strict) {
1936
1997
  if (strict) {