@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/cli/index.js
CHANGED
|
@@ -3605,10 +3605,15 @@ var CompositionConverterService = class {
|
|
|
3605
3605
|
let contentTypesWritten = 0;
|
|
3606
3606
|
let entriesFromCompositions = 0;
|
|
3607
3607
|
let entriesFromFlattened = 0;
|
|
3608
|
+
let entriesReused = 0;
|
|
3608
3609
|
this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
|
|
3609
3610
|
if (flattenComponentIds.length > 0) {
|
|
3610
3611
|
this.logger.info(`Flatten component types: ${flattenComponentIds.join(", ")}`);
|
|
3611
3612
|
}
|
|
3613
|
+
const sourceItemMap = flattenComponentIds.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
|
|
3614
|
+
if (sourceItemMap.size > 0) {
|
|
3615
|
+
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
3616
|
+
}
|
|
3612
3617
|
const compositionResults = await this.compositionService.findCompositionsByTypes(
|
|
3613
3618
|
compositionsDirFull,
|
|
3614
3619
|
compositionTypes,
|
|
@@ -3616,7 +3621,7 @@ var CompositionConverterService = class {
|
|
|
3616
3621
|
);
|
|
3617
3622
|
if (compositionResults.length === 0) {
|
|
3618
3623
|
this.logger.warn("No compositions found matching the specified types");
|
|
3619
|
-
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromFlattened: 0 };
|
|
3624
|
+
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromFlattened: 0, entriesReused: 0 };
|
|
3620
3625
|
}
|
|
3621
3626
|
this.logger.info(`Found ${compositionResults.length} composition(s)`);
|
|
3622
3627
|
const rootComponentTypes = /* @__PURE__ */ new Set();
|
|
@@ -3690,10 +3695,19 @@ var CompositionConverterService = class {
|
|
|
3690
3695
|
}
|
|
3691
3696
|
}
|
|
3692
3697
|
}
|
|
3698
|
+
const resolvedRefIds = /* @__PURE__ */ new Map();
|
|
3693
3699
|
for (const [flattenType, instances] of flattenedByType) {
|
|
3700
|
+
const refIds = [];
|
|
3701
|
+
for (const inst of instances) {
|
|
3702
|
+
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
3703
|
+
refIds.push(existingId ?? inst.determinisiticId);
|
|
3704
|
+
}
|
|
3705
|
+
resolvedRefIds.set(flattenType, refIds);
|
|
3706
|
+
}
|
|
3707
|
+
for (const [flattenType] of flattenedByType) {
|
|
3694
3708
|
entry.entry.fields[flattenType] = {
|
|
3695
3709
|
type: "contentReference",
|
|
3696
|
-
value:
|
|
3710
|
+
value: resolvedRefIds.get(flattenType)
|
|
3697
3711
|
};
|
|
3698
3712
|
}
|
|
3699
3713
|
if (flattenComponentIds.length > 0) {
|
|
@@ -3712,6 +3726,14 @@ var CompositionConverterService = class {
|
|
|
3712
3726
|
entriesFromCompositions++;
|
|
3713
3727
|
for (const [flattenType, instances] of flattenedByType) {
|
|
3714
3728
|
for (const inst of instances) {
|
|
3729
|
+
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
3730
|
+
if (existingId) {
|
|
3731
|
+
this.logger.info(
|
|
3732
|
+
`Reusing existing entry ${existingId} for ${flattenType} (sourceItem match)`
|
|
3733
|
+
);
|
|
3734
|
+
entriesReused++;
|
|
3735
|
+
continue;
|
|
3736
|
+
}
|
|
3715
3737
|
const flatEntry = this.generateEntryFromFlattenedInstance(inst);
|
|
3716
3738
|
const flatEntryPath = this.fileSystem.joinPath(
|
|
3717
3739
|
entriesDirFull,
|
|
@@ -3786,7 +3808,7 @@ var CompositionConverterService = class {
|
|
|
3786
3808
|
`Flatten component type(s) not found in any composition: ${neverFoundMissingTypes.join(", ")}`
|
|
3787
3809
|
);
|
|
3788
3810
|
}
|
|
3789
|
-
return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened };
|
|
3811
|
+
return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened, entriesReused };
|
|
3790
3812
|
}
|
|
3791
3813
|
// --- Content Type Generation ---
|
|
3792
3814
|
generateContentType(component) {
|
|
@@ -3837,10 +3859,11 @@ var CompositionConverterService = class {
|
|
|
3837
3859
|
}
|
|
3838
3860
|
}
|
|
3839
3861
|
const entryId = computeGuidHash(`entry${comp._id}`);
|
|
3862
|
+
const entryName = this.truncateName(comp._name ?? comp._id, 60);
|
|
3840
3863
|
return {
|
|
3841
3864
|
entry: {
|
|
3842
3865
|
_id: entryId,
|
|
3843
|
-
_name:
|
|
3866
|
+
_name: entryName,
|
|
3844
3867
|
type: comp.type,
|
|
3845
3868
|
fields: { ...comp.parameters ?? {} },
|
|
3846
3869
|
...extraRootProps
|
|
@@ -3849,10 +3872,14 @@ var CompositionConverterService = class {
|
|
|
3849
3872
|
};
|
|
3850
3873
|
}
|
|
3851
3874
|
generateEntryFromFlattenedInstance(inst) {
|
|
3875
|
+
const entryName = this.truncateName(
|
|
3876
|
+
`${inst.componentType} (from ${inst.compositionName})`,
|
|
3877
|
+
60
|
|
3878
|
+
);
|
|
3852
3879
|
return {
|
|
3853
3880
|
entry: {
|
|
3854
3881
|
_id: inst.determinisiticId,
|
|
3855
|
-
_name:
|
|
3882
|
+
_name: entryName,
|
|
3856
3883
|
type: inst.componentType,
|
|
3857
3884
|
fields: { ...inst.instance.parameters ?? {} }
|
|
3858
3885
|
}
|
|
@@ -3923,6 +3950,30 @@ var CompositionConverterService = class {
|
|
|
3923
3950
|
};
|
|
3924
3951
|
}
|
|
3925
3952
|
}
|
|
3953
|
+
// --- Source Item Matching ---
|
|
3954
|
+
async buildSourceItemMap(entriesDirFull) {
|
|
3955
|
+
const sourceItemMap = /* @__PURE__ */ new Map();
|
|
3956
|
+
const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
|
|
3957
|
+
for (const filePath of entryFiles) {
|
|
3958
|
+
try {
|
|
3959
|
+
const entryData = await this.fileSystem.readFile(filePath);
|
|
3960
|
+
const sourceItemField = entryData?.entry?.fields?.sourceItem;
|
|
3961
|
+
if (sourceItemField?.value != null) {
|
|
3962
|
+
sourceItemMap.set(String(sourceItemField.value), entryData.entry._id);
|
|
3963
|
+
}
|
|
3964
|
+
} catch {
|
|
3965
|
+
continue;
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
return sourceItemMap;
|
|
3969
|
+
}
|
|
3970
|
+
findExistingEntryBySourceItem(inst, sourceItemMap) {
|
|
3971
|
+
const sourceItemParam = inst.instance.parameters?.sourceItem;
|
|
3972
|
+
if (sourceItemParam?.value == null) {
|
|
3973
|
+
return void 0;
|
|
3974
|
+
}
|
|
3975
|
+
return sourceItemMap.get(String(sourceItemParam.value));
|
|
3976
|
+
}
|
|
3926
3977
|
// --- Utilities ---
|
|
3927
3978
|
compareTypes(type1, type2, strict) {
|
|
3928
3979
|
if (strict) {
|
|
@@ -3934,6 +3985,10 @@ var CompositionConverterService = class {
|
|
|
3934
3985
|
if (str.length <= maxLength) return str;
|
|
3935
3986
|
return str.substring(0, maxLength - 3) + "...";
|
|
3936
3987
|
}
|
|
3988
|
+
truncateName(name, maxLength) {
|
|
3989
|
+
if (name.length <= maxLength) return name;
|
|
3990
|
+
return name.substring(0, maxLength);
|
|
3991
|
+
}
|
|
3937
3992
|
};
|
|
3938
3993
|
function computeGuidHash(guidOrSeed) {
|
|
3939
3994
|
let uuidStr;
|
|
@@ -4038,8 +4093,9 @@ function createConvertCompositionsToEntriesCommand() {
|
|
|
4038
4093
|
strict: options.strict ?? false
|
|
4039
4094
|
});
|
|
4040
4095
|
const flatInfo = result.entriesFromFlattened > 0 ? `, ${result.entriesFromFlattened} from flattened components` : "";
|
|
4096
|
+
const reusedInfo = result.entriesReused > 0 ? `, ${result.entriesReused} reused existing` : "";
|
|
4041
4097
|
logger.success(
|
|
4042
|
-
`${result.contentTypesWritten} content type(s), ${result.entriesFromCompositions} entry(ies) from compositions${flatInfo}`
|
|
4098
|
+
`${result.contentTypesWritten} content type(s), ${result.entriesFromCompositions} entry(ies) from compositions${flatInfo}${reusedInfo}`
|
|
4043
4099
|
);
|
|
4044
4100
|
} catch (error) {
|
|
4045
4101
|
if (error instanceof TransformError) {
|
|
@@ -4593,7 +4649,7 @@ function createRemoveFieldCommand() {
|
|
|
4593
4649
|
// package.json
|
|
4594
4650
|
var package_default = {
|
|
4595
4651
|
name: "@uniformdev/transformer",
|
|
4596
|
-
version: "1.1.
|
|
4652
|
+
version: "1.1.16",
|
|
4597
4653
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
4598
4654
|
type: "module",
|
|
4599
4655
|
bin: {
|