@uniformdev/transformer 1.1.11 → 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
@@ -1767,6 +1767,9 @@ var CompositionConverterService = class {
1767
1767
  value: instances.map((inst) => inst.determinisiticId)
1768
1768
  };
1769
1769
  }
1770
+ if (flattenComponentIds.length > 0) {
1771
+ this.transformContentReferences(entry);
1772
+ }
1770
1773
  const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${compositionId}.json`);
1771
1774
  this.logger.action(
1772
1775
  whatIf,
@@ -1889,13 +1892,29 @@ var CompositionConverterService = class {
1889
1892
  // --- Entry Generation ---
1890
1893
  generateEntryFromComposition(composition) {
1891
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
+ }
1892
1909
  return {
1893
1910
  entry: {
1894
1911
  _id: comp._id,
1895
1912
  _name: comp._name ?? comp._id,
1896
1913
  type: comp.type,
1897
- fields: { ...comp.parameters ?? {} }
1898
- }
1914
+ fields: { ...comp.parameters ?? {} },
1915
+ ...extraRootProps
1916
+ },
1917
+ ...extraWrapperProps
1899
1918
  };
1900
1919
  }
1901
1920
  generateEntryFromFlattenedInstance(inst) {
@@ -1949,6 +1968,30 @@ var CompositionConverterService = class {
1949
1968
  }
1950
1969
  }
1951
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
+ }
1952
1995
  // --- Utilities ---
1953
1996
  compareTypes(type1, type2, strict) {
1954
1997
  if (strict) {