@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 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: instances.map((inst) => inst.determinisiticId)
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) {
@@ -3928,6 +3950,30 @@ var CompositionConverterService = class {
3928
3950
  };
3929
3951
  }
3930
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
+ }
3931
3977
  // --- Utilities ---
3932
3978
  compareTypes(type1, type2, strict) {
3933
3979
  if (strict) {
@@ -4047,8 +4093,9 @@ function createConvertCompositionsToEntriesCommand() {
4047
4093
  strict: options.strict ?? false
4048
4094
  });
4049
4095
  const flatInfo = result.entriesFromFlattened > 0 ? `, ${result.entriesFromFlattened} from flattened components` : "";
4096
+ const reusedInfo = result.entriesReused > 0 ? `, ${result.entriesReused} reused existing` : "";
4050
4097
  logger.success(
4051
- `${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}`
4052
4099
  );
4053
4100
  } catch (error) {
4054
4101
  if (error instanceof TransformError) {
@@ -4602,7 +4649,7 @@ function createRemoveFieldCommand() {
4602
4649
  // package.json
4603
4650
  var package_default = {
4604
4651
  name: "@uniformdev/transformer",
4605
- version: "1.1.15",
4652
+ version: "1.1.16",
4606
4653
  description: "CLI tool for transforming Uniform.dev serialization files offline",
4607
4654
  type: "module",
4608
4655
  bin: {