@uniformdev/transformer 1.1.14 → 1.1.16
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/cli/index.js +63 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +60 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -452,6 +452,7 @@ interface ConvertResult {
|
|
|
452
452
|
contentTypesWritten: number;
|
|
453
453
|
entriesFromCompositions: number;
|
|
454
454
|
entriesFromFlattened: number;
|
|
455
|
+
entriesReused: number;
|
|
455
456
|
}
|
|
456
457
|
declare class CompositionConverterService {
|
|
457
458
|
private fileSystem;
|
|
@@ -467,8 +468,11 @@ declare class CompositionConverterService {
|
|
|
467
468
|
findFlattenTargets(slots: Record<string, ComponentInstance[]>, targetType: string, compositionId: string, compositionName: string, strict: boolean): FlattenedInstance[];
|
|
468
469
|
private walkSlots;
|
|
469
470
|
private transformContentReferences;
|
|
471
|
+
buildSourceItemMap(entriesDirFull: string): Promise<Map<string, string>>;
|
|
472
|
+
private findExistingEntryBySourceItem;
|
|
470
473
|
private compareTypes;
|
|
471
474
|
private truncate;
|
|
475
|
+
private truncateName;
|
|
472
476
|
}
|
|
473
477
|
/**
|
|
474
478
|
* Computes a deterministic UUID v4 from a string seed.
|
package/dist/index.js
CHANGED
|
@@ -1676,10 +1676,15 @@ var CompositionConverterService = class {
|
|
|
1676
1676
|
let contentTypesWritten = 0;
|
|
1677
1677
|
let entriesFromCompositions = 0;
|
|
1678
1678
|
let entriesFromFlattened = 0;
|
|
1679
|
+
let entriesReused = 0;
|
|
1679
1680
|
this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
|
|
1680
1681
|
if (flattenComponentIds.length > 0) {
|
|
1681
1682
|
this.logger.info(`Flatten component types: ${flattenComponentIds.join(", ")}`);
|
|
1682
1683
|
}
|
|
1684
|
+
const sourceItemMap = flattenComponentIds.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
|
|
1685
|
+
if (sourceItemMap.size > 0) {
|
|
1686
|
+
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
1687
|
+
}
|
|
1683
1688
|
const compositionResults = await this.compositionService.findCompositionsByTypes(
|
|
1684
1689
|
compositionsDirFull,
|
|
1685
1690
|
compositionTypes,
|
|
@@ -1687,7 +1692,7 @@ var CompositionConverterService = class {
|
|
|
1687
1692
|
);
|
|
1688
1693
|
if (compositionResults.length === 0) {
|
|
1689
1694
|
this.logger.warn("No compositions found matching the specified types");
|
|
1690
|
-
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromFlattened: 0 };
|
|
1695
|
+
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromFlattened: 0, entriesReused: 0 };
|
|
1691
1696
|
}
|
|
1692
1697
|
this.logger.info(`Found ${compositionResults.length} composition(s)`);
|
|
1693
1698
|
const rootComponentTypes = /* @__PURE__ */ new Set();
|
|
@@ -1761,10 +1766,19 @@ var CompositionConverterService = class {
|
|
|
1761
1766
|
}
|
|
1762
1767
|
}
|
|
1763
1768
|
}
|
|
1769
|
+
const resolvedRefIds = /* @__PURE__ */ new Map();
|
|
1764
1770
|
for (const [flattenType, instances] of flattenedByType) {
|
|
1771
|
+
const refIds = [];
|
|
1772
|
+
for (const inst of instances) {
|
|
1773
|
+
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
1774
|
+
refIds.push(existingId ?? inst.determinisiticId);
|
|
1775
|
+
}
|
|
1776
|
+
resolvedRefIds.set(flattenType, refIds);
|
|
1777
|
+
}
|
|
1778
|
+
for (const [flattenType] of flattenedByType) {
|
|
1765
1779
|
entry.entry.fields[flattenType] = {
|
|
1766
1780
|
type: "contentReference",
|
|
1767
|
-
value:
|
|
1781
|
+
value: resolvedRefIds.get(flattenType)
|
|
1768
1782
|
};
|
|
1769
1783
|
}
|
|
1770
1784
|
if (flattenComponentIds.length > 0) {
|
|
@@ -1783,6 +1797,14 @@ var CompositionConverterService = class {
|
|
|
1783
1797
|
entriesFromCompositions++;
|
|
1784
1798
|
for (const [flattenType, instances] of flattenedByType) {
|
|
1785
1799
|
for (const inst of instances) {
|
|
1800
|
+
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
1801
|
+
if (existingId) {
|
|
1802
|
+
this.logger.info(
|
|
1803
|
+
`Reusing existing entry ${existingId} for ${flattenType} (sourceItem match)`
|
|
1804
|
+
);
|
|
1805
|
+
entriesReused++;
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1786
1808
|
const flatEntry = this.generateEntryFromFlattenedInstance(inst);
|
|
1787
1809
|
const flatEntryPath = this.fileSystem.joinPath(
|
|
1788
1810
|
entriesDirFull,
|
|
@@ -1857,7 +1879,7 @@ var CompositionConverterService = class {
|
|
|
1857
1879
|
`Flatten component type(s) not found in any composition: ${neverFoundMissingTypes.join(", ")}`
|
|
1858
1880
|
);
|
|
1859
1881
|
}
|
|
1860
|
-
return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened };
|
|
1882
|
+
return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened, entriesReused };
|
|
1861
1883
|
}
|
|
1862
1884
|
// --- Content Type Generation ---
|
|
1863
1885
|
generateContentType(component) {
|
|
@@ -1908,10 +1930,11 @@ var CompositionConverterService = class {
|
|
|
1908
1930
|
}
|
|
1909
1931
|
}
|
|
1910
1932
|
const entryId = computeGuidHash(`entry${comp._id}`);
|
|
1933
|
+
const entryName = this.truncateName(comp._name ?? comp._id, 60);
|
|
1911
1934
|
return {
|
|
1912
1935
|
entry: {
|
|
1913
1936
|
_id: entryId,
|
|
1914
|
-
_name:
|
|
1937
|
+
_name: entryName,
|
|
1915
1938
|
type: comp.type,
|
|
1916
1939
|
fields: { ...comp.parameters ?? {} },
|
|
1917
1940
|
...extraRootProps
|
|
@@ -1920,10 +1943,14 @@ var CompositionConverterService = class {
|
|
|
1920
1943
|
};
|
|
1921
1944
|
}
|
|
1922
1945
|
generateEntryFromFlattenedInstance(inst) {
|
|
1946
|
+
const entryName = this.truncateName(
|
|
1947
|
+
`${inst.componentType} (from ${inst.compositionName})`,
|
|
1948
|
+
60
|
|
1949
|
+
);
|
|
1923
1950
|
return {
|
|
1924
1951
|
entry: {
|
|
1925
1952
|
_id: inst.determinisiticId,
|
|
1926
|
-
_name:
|
|
1953
|
+
_name: entryName,
|
|
1927
1954
|
type: inst.componentType,
|
|
1928
1955
|
fields: { ...inst.instance.parameters ?? {} }
|
|
1929
1956
|
}
|
|
@@ -1994,6 +2021,30 @@ var CompositionConverterService = class {
|
|
|
1994
2021
|
};
|
|
1995
2022
|
}
|
|
1996
2023
|
}
|
|
2024
|
+
// --- Source Item Matching ---
|
|
2025
|
+
async buildSourceItemMap(entriesDirFull) {
|
|
2026
|
+
const sourceItemMap = /* @__PURE__ */ new Map();
|
|
2027
|
+
const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
|
|
2028
|
+
for (const filePath of entryFiles) {
|
|
2029
|
+
try {
|
|
2030
|
+
const entryData = await this.fileSystem.readFile(filePath);
|
|
2031
|
+
const sourceItemField = entryData?.entry?.fields?.sourceItem;
|
|
2032
|
+
if (sourceItemField?.value != null) {
|
|
2033
|
+
sourceItemMap.set(String(sourceItemField.value), entryData.entry._id);
|
|
2034
|
+
}
|
|
2035
|
+
} catch {
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return sourceItemMap;
|
|
2040
|
+
}
|
|
2041
|
+
findExistingEntryBySourceItem(inst, sourceItemMap) {
|
|
2042
|
+
const sourceItemParam = inst.instance.parameters?.sourceItem;
|
|
2043
|
+
if (sourceItemParam?.value == null) {
|
|
2044
|
+
return void 0;
|
|
2045
|
+
}
|
|
2046
|
+
return sourceItemMap.get(String(sourceItemParam.value));
|
|
2047
|
+
}
|
|
1997
2048
|
// --- Utilities ---
|
|
1998
2049
|
compareTypes(type1, type2, strict) {
|
|
1999
2050
|
if (strict) {
|
|
@@ -2005,6 +2056,10 @@ var CompositionConverterService = class {
|
|
|
2005
2056
|
if (str.length <= maxLength) return str;
|
|
2006
2057
|
return str.substring(0, maxLength - 3) + "...";
|
|
2007
2058
|
}
|
|
2059
|
+
truncateName(name, maxLength) {
|
|
2060
|
+
if (name.length <= maxLength) return name;
|
|
2061
|
+
return name.substring(0, maxLength);
|
|
2062
|
+
}
|
|
2008
2063
|
};
|
|
2009
2064
|
function computeGuidHash(guidOrSeed) {
|
|
2010
2065
|
let uuidStr;
|