@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/cli/index.js +111 -50
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +110 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3634,6 +3634,8 @@ var CompositionConverterService = class {
|
|
|
3634
3634
|
contentTypeMap.set(rootType, contentType);
|
|
3635
3635
|
}
|
|
3636
3636
|
const flattenContentTypeMap = /* @__PURE__ */ new Map();
|
|
3637
|
+
const missingFlattenTypes = [];
|
|
3638
|
+
const foundMissingFlattenTypes = /* @__PURE__ */ new Set();
|
|
3637
3639
|
for (const flattenType of flattenComponentIds) {
|
|
3638
3640
|
const isRootType = [...rootComponentTypes].some(
|
|
3639
3641
|
(rt) => this.compareTypes(rt, flattenType, strict)
|
|
@@ -3651,57 +3653,13 @@ var CompositionConverterService = class {
|
|
|
3651
3653
|
flattenContentTypeMap.set(flattenType, contentType);
|
|
3652
3654
|
} catch (error) {
|
|
3653
3655
|
if (error instanceof ComponentNotFoundError) {
|
|
3654
|
-
|
|
3656
|
+
this.logger.info(`Flatten component type not found: ${flattenType}`);
|
|
3657
|
+
missingFlattenTypes.push(flattenType);
|
|
3658
|
+
continue;
|
|
3655
3659
|
}
|
|
3656
3660
|
throw error;
|
|
3657
3661
|
}
|
|
3658
3662
|
}
|
|
3659
|
-
if (flattenComponentIds.length > 0) {
|
|
3660
|
-
for (const contentType of contentTypeMap.values()) {
|
|
3661
|
-
for (const flattenType of flattenComponentIds) {
|
|
3662
|
-
if (this.compareTypes(flattenType, contentType.id, strict)) {
|
|
3663
|
-
continue;
|
|
3664
|
-
}
|
|
3665
|
-
contentType.fields.push({
|
|
3666
|
-
id: flattenType,
|
|
3667
|
-
name: flattenType,
|
|
3668
|
-
type: "contentReference",
|
|
3669
|
-
typeConfig: {
|
|
3670
|
-
isMulti: true,
|
|
3671
|
-
allowedContentTypes: [flattenType]
|
|
3672
|
-
},
|
|
3673
|
-
localizable: false
|
|
3674
|
-
});
|
|
3675
|
-
}
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
for (const [typeName, contentType] of contentTypeMap) {
|
|
3679
|
-
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
3680
|
-
const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
|
|
3681
|
-
const refCount = contentType.fields.filter((f) => f.type === "contentReference").length;
|
|
3682
|
-
const refInfo = refCount > 0 ? ` + ${refCount} reference(s)` : "";
|
|
3683
|
-
this.logger.action(
|
|
3684
|
-
whatIf,
|
|
3685
|
-
"WRITE",
|
|
3686
|
-
`${contentTypesDir}/${typeName}.json (${fieldCount} fields${refInfo})`
|
|
3687
|
-
);
|
|
3688
|
-
if (!whatIf) {
|
|
3689
|
-
await this.fileSystem.writeFile(filePath, contentType);
|
|
3690
|
-
}
|
|
3691
|
-
contentTypesWritten++;
|
|
3692
|
-
}
|
|
3693
|
-
for (const [typeName, contentType] of flattenContentTypeMap) {
|
|
3694
|
-
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
3695
|
-
this.logger.action(
|
|
3696
|
-
whatIf,
|
|
3697
|
-
"WRITE",
|
|
3698
|
-
`${contentTypesDir}/${typeName}.json (${contentType.fields.length} fields)`
|
|
3699
|
-
);
|
|
3700
|
-
if (!whatIf) {
|
|
3701
|
-
await this.fileSystem.writeFile(filePath, contentType);
|
|
3702
|
-
}
|
|
3703
|
-
contentTypesWritten++;
|
|
3704
|
-
}
|
|
3705
3663
|
for (const { composition } of compositionResults) {
|
|
3706
3664
|
const comp = composition.composition;
|
|
3707
3665
|
const compositionId = comp._id;
|
|
@@ -3726,6 +3684,9 @@ var CompositionConverterService = class {
|
|
|
3726
3684
|
);
|
|
3727
3685
|
if (instances.length > 0) {
|
|
3728
3686
|
flattenedByType.set(flattenType, instances);
|
|
3687
|
+
if (missingFlattenTypes.includes(flattenType)) {
|
|
3688
|
+
foundMissingFlattenTypes.add(flattenType);
|
|
3689
|
+
}
|
|
3729
3690
|
}
|
|
3730
3691
|
}
|
|
3731
3692
|
}
|
|
@@ -3735,6 +3696,9 @@ var CompositionConverterService = class {
|
|
|
3735
3696
|
value: instances.map((inst) => inst.determinisiticId)
|
|
3736
3697
|
};
|
|
3737
3698
|
}
|
|
3699
|
+
if (flattenComponentIds.length > 0) {
|
|
3700
|
+
this.transformContentReferences(entry);
|
|
3701
|
+
}
|
|
3738
3702
|
const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${compositionId}.json`);
|
|
3739
3703
|
this.logger.action(
|
|
3740
3704
|
whatIf,
|
|
@@ -3764,6 +3728,63 @@ var CompositionConverterService = class {
|
|
|
3764
3728
|
}
|
|
3765
3729
|
}
|
|
3766
3730
|
}
|
|
3731
|
+
if (flattenComponentIds.length > 0) {
|
|
3732
|
+
for (const contentType of contentTypeMap.values()) {
|
|
3733
|
+
for (const flattenType of flattenComponentIds) {
|
|
3734
|
+
if (this.compareTypes(flattenType, contentType.id, strict)) {
|
|
3735
|
+
continue;
|
|
3736
|
+
}
|
|
3737
|
+
if (missingFlattenTypes.includes(flattenType) && !foundMissingFlattenTypes.has(flattenType)) {
|
|
3738
|
+
continue;
|
|
3739
|
+
}
|
|
3740
|
+
contentType.fields.push({
|
|
3741
|
+
id: flattenType,
|
|
3742
|
+
name: flattenType,
|
|
3743
|
+
type: "contentReference",
|
|
3744
|
+
typeConfig: {
|
|
3745
|
+
isMulti: true,
|
|
3746
|
+
allowedContentTypes: [flattenType]
|
|
3747
|
+
},
|
|
3748
|
+
localizable: false
|
|
3749
|
+
});
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
for (const [typeName, contentType] of contentTypeMap) {
|
|
3754
|
+
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
3755
|
+
const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
|
|
3756
|
+
const refCount = contentType.fields.filter((f) => f.type === "contentReference").length;
|
|
3757
|
+
const refInfo = refCount > 0 ? ` + ${refCount} reference(s)` : "";
|
|
3758
|
+
this.logger.action(
|
|
3759
|
+
whatIf,
|
|
3760
|
+
"WRITE",
|
|
3761
|
+
`${contentTypesDir}/${typeName}.json (${fieldCount} fields${refInfo})`
|
|
3762
|
+
);
|
|
3763
|
+
if (!whatIf) {
|
|
3764
|
+
await this.fileSystem.writeFile(filePath, contentType);
|
|
3765
|
+
}
|
|
3766
|
+
contentTypesWritten++;
|
|
3767
|
+
}
|
|
3768
|
+
for (const [typeName, contentType] of flattenContentTypeMap) {
|
|
3769
|
+
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
3770
|
+
this.logger.action(
|
|
3771
|
+
whatIf,
|
|
3772
|
+
"WRITE",
|
|
3773
|
+
`${contentTypesDir}/${typeName}.json (${contentType.fields.length} fields)`
|
|
3774
|
+
);
|
|
3775
|
+
if (!whatIf) {
|
|
3776
|
+
await this.fileSystem.writeFile(filePath, contentType);
|
|
3777
|
+
}
|
|
3778
|
+
contentTypesWritten++;
|
|
3779
|
+
}
|
|
3780
|
+
const neverFoundMissingTypes = missingFlattenTypes.filter(
|
|
3781
|
+
(type) => !foundMissingFlattenTypes.has(type)
|
|
3782
|
+
);
|
|
3783
|
+
if (neverFoundMissingTypes.length > 0) {
|
|
3784
|
+
this.logger.warn(
|
|
3785
|
+
`Flatten component type(s) not found in any composition: ${neverFoundMissingTypes.join(", ")}`
|
|
3786
|
+
);
|
|
3787
|
+
}
|
|
3767
3788
|
return { contentTypesWritten, entriesFromCompositions, entriesFromFlattened };
|
|
3768
3789
|
}
|
|
3769
3790
|
// --- Content Type Generation ---
|
|
@@ -3800,13 +3821,29 @@ var CompositionConverterService = class {
|
|
|
3800
3821
|
// --- Entry Generation ---
|
|
3801
3822
|
generateEntryFromComposition(composition) {
|
|
3802
3823
|
const comp = composition.composition;
|
|
3824
|
+
const compositionSpecificKeys = /* @__PURE__ */ new Set(["_id", "_name", "type", "parameters", "slots", "_overrides"]);
|
|
3825
|
+
const extraRootProps = {};
|
|
3826
|
+
for (const [key, value] of Object.entries(comp)) {
|
|
3827
|
+
if (!compositionSpecificKeys.has(key) && value != null) {
|
|
3828
|
+
extraRootProps[key] = value;
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
const wrapperKeys = /* @__PURE__ */ new Set(["composition"]);
|
|
3832
|
+
const extraWrapperProps = {};
|
|
3833
|
+
for (const [key, value] of Object.entries(composition)) {
|
|
3834
|
+
if (!wrapperKeys.has(key) && value != null) {
|
|
3835
|
+
extraWrapperProps[key] = value;
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3803
3838
|
return {
|
|
3804
3839
|
entry: {
|
|
3805
3840
|
_id: comp._id,
|
|
3806
3841
|
_name: comp._name ?? comp._id,
|
|
3807
3842
|
type: comp.type,
|
|
3808
|
-
fields: { ...comp.parameters ?? {} }
|
|
3809
|
-
|
|
3843
|
+
fields: { ...comp.parameters ?? {} },
|
|
3844
|
+
...extraRootProps
|
|
3845
|
+
},
|
|
3846
|
+
...extraWrapperProps
|
|
3810
3847
|
};
|
|
3811
3848
|
}
|
|
3812
3849
|
generateEntryFromFlattenedInstance(inst) {
|
|
@@ -3860,6 +3897,30 @@ var CompositionConverterService = class {
|
|
|
3860
3897
|
}
|
|
3861
3898
|
}
|
|
3862
3899
|
}
|
|
3900
|
+
// --- Content Reference Transformation ---
|
|
3901
|
+
transformContentReferences(entry) {
|
|
3902
|
+
const dataResources = {};
|
|
3903
|
+
for (const [fieldName, field] of Object.entries(entry.entry.fields)) {
|
|
3904
|
+
if (field.type === "contentReference" && Array.isArray(field.value)) {
|
|
3905
|
+
const entryIds = field.value;
|
|
3906
|
+
const resourceKey = `ref-${entry.entry._id}-${fieldName}`;
|
|
3907
|
+
field.value = `\${#jptr:/${resourceKey}/entries}`;
|
|
3908
|
+
dataResources[resourceKey] = {
|
|
3909
|
+
type: "uniformContentInternalReference",
|
|
3910
|
+
variables: {
|
|
3911
|
+
locale: "${locale}",
|
|
3912
|
+
entryIds: entryIds.join(",")
|
|
3913
|
+
}
|
|
3914
|
+
};
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
if (Object.keys(dataResources).length > 0) {
|
|
3918
|
+
entry.entry._dataResources = {
|
|
3919
|
+
...entry.entry._dataResources ?? {},
|
|
3920
|
+
...dataResources
|
|
3921
|
+
};
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3863
3924
|
// --- Utilities ---
|
|
3864
3925
|
compareTypes(type1, type2, strict) {
|
|
3865
3926
|
if (strict) {
|
|
@@ -3992,7 +4053,7 @@ function createConvertCompositionsToEntriesCommand() {
|
|
|
3992
4053
|
// package.json
|
|
3993
4054
|
var package_default = {
|
|
3994
4055
|
name: "@uniformdev/transformer",
|
|
3995
|
-
version: "1.1.
|
|
4056
|
+
version: "1.1.12",
|
|
3996
4057
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
3997
4058
|
type: "module",
|
|
3998
4059
|
bin: {
|