@uniformdev/transformer 1.1.15 → 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 +52 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +49 -3
- 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,6 +468,8 @@ 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;
|
|
472
475
|
private truncateName;
|
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) {
|
|
@@ -1999,6 +2021,30 @@ var CompositionConverterService = class {
|
|
|
1999
2021
|
};
|
|
2000
2022
|
}
|
|
2001
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
|
+
}
|
|
2002
2048
|
// --- Utilities ---
|
|
2003
2049
|
compareTypes(type1, type2, strict) {
|
|
2004
2050
|
if (strict) {
|