@uniformdev/transformer 1.1.27 → 1.1.29

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/index.d.ts CHANGED
@@ -484,7 +484,10 @@ declare class CompositionConverterService {
484
484
  buildEntryIdMap(entriesDirFull: string): Promise<Map<string, string>>;
485
485
  buildSourceItemMap(entriesDirFull: string): Promise<Map<string, string>>;
486
486
  private findExistingEntryBySourceItem;
487
+ private matchesType;
487
488
  private compareTypes;
489
+ private expandWildcardTypes;
490
+ private collectMatchingTypes;
488
491
  private truncate;
489
492
  private truncateName;
490
493
  }
package/dist/index.js CHANGED
@@ -587,8 +587,8 @@ var CompositionConverterService = class {
587
587
  whatIf,
588
588
  strict
589
589
  } = options;
590
- const componentsToReferences = [...new Set(rawComponentsToReferences)];
591
- const componentsToBlocks = [...new Set(rawComponentsToBlocks)];
590
+ const initialComponentsToReferences = [...new Set(rawComponentsToReferences)];
591
+ const initialComponentsToBlocks = [...new Set(rawComponentsToBlocks)];
592
592
  const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
593
593
  const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
594
594
  const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
@@ -599,13 +599,13 @@ var CompositionConverterService = class {
599
599
  let entriesReused = 0;
600
600
  let blocksEmbedded = 0;
601
601
  this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
602
- if (componentsToReferences.length > 0) {
603
- this.logger.info(`Components to references: ${componentsToReferences.join(", ")}`);
602
+ if (initialComponentsToReferences.length > 0) {
603
+ this.logger.info(`Components to references: ${initialComponentsToReferences.join(", ")}`);
604
604
  }
605
- if (componentsToBlocks.length > 0) {
606
- this.logger.info(`Components to blocks: ${componentsToBlocks.join(", ")}`);
605
+ if (initialComponentsToBlocks.length > 0) {
606
+ this.logger.info(`Components to blocks: ${initialComponentsToBlocks.join(", ")}`);
607
607
  }
608
- const sourceItemMap = componentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
608
+ const sourceItemMap = initialComponentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
609
609
  if (sourceItemMap.size > 0) {
610
610
  this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
611
611
  }
@@ -620,19 +620,29 @@ var CompositionConverterService = class {
620
620
  return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromReferences: 0, entriesReused: 0, blocksEmbedded: 0 };
621
621
  }
622
622
  this.logger.info(`Found ${compositionResults.length} composition(s)`);
623
+ const componentsToReferences = this.expandWildcardTypes(compositionResults, initialComponentsToReferences, strict);
624
+ const componentsToBlocks = this.expandWildcardTypes(compositionResults, initialComponentsToBlocks, strict);
623
625
  const rootComponentTypes = /* @__PURE__ */ new Set();
624
626
  for (const { composition } of compositionResults) {
625
627
  rootComponentTypes.add(composition.composition.type);
626
628
  }
627
629
  const contentTypeMap = /* @__PURE__ */ new Map();
628
630
  for (const rootType of rootComponentTypes) {
629
- const { component } = await this.componentService.loadComponent(
630
- componentsDirFull,
631
- rootType,
632
- { strict }
633
- );
634
- const contentType = this.generateContentType(component);
635
- contentTypeMap.set(rootType, contentType);
631
+ try {
632
+ const { component } = await this.componentService.loadComponent(
633
+ componentsDirFull,
634
+ rootType,
635
+ { strict }
636
+ );
637
+ const contentType = this.generateContentType(component);
638
+ contentTypeMap.set(rootType, contentType);
639
+ } catch (error) {
640
+ if (error instanceof ComponentNotFoundError) {
641
+ this.logger.warn(`Component not found: ${rootType} \u2014 skipping content type generation`);
642
+ continue;
643
+ }
644
+ throw error;
645
+ }
636
646
  }
637
647
  const allTargetTypes = [.../* @__PURE__ */ new Set([...componentsToReferences, ...componentsToBlocks])];
638
648
  const targetContentTypeMap = /* @__PURE__ */ new Map();
@@ -714,7 +724,8 @@ var CompositionConverterService = class {
714
724
  const compositionId = comp._id;
715
725
  const compositionName = comp._name ?? compositionId;
716
726
  const compositionType = comp.type;
717
- const existingEntryPath = existingEntryMap.get(compositionId);
727
+ const compSourceItem = comp.parameters?.sourceItem?.value;
728
+ const existingEntryPath = existingEntryMap.get(compositionId) ?? (compSourceItem != null ? existingEntryMap.get(String(compSourceItem)) : void 0);
718
729
  let entry;
719
730
  let isExistingEntry = false;
720
731
  if (existingEntryPath) {
@@ -723,7 +734,7 @@ var CompositionConverterService = class {
723
734
  entry = existingEntry;
724
735
  isExistingEntry = true;
725
736
  this.logger.info(
726
- `Found existing entry "${compositionId}" \u2014 merging references and blocks`
737
+ `Found existing entry "${existingEntry.entry._id}" \u2014 merging references and blocks`
727
738
  );
728
739
  } else {
729
740
  entry = this.generateEntryFromComposition(composition);
@@ -1148,11 +1159,57 @@ var CompositionConverterService = class {
1148
1159
  return sourceItemMap.get(String(sourceItemParam.value));
1149
1160
  }
1150
1161
  // --- Utilities ---
1162
+ matchesType(instanceType, pattern, strict) {
1163
+ if (!pattern.includes("*")) {
1164
+ return strict ? instanceType === pattern : instanceType.toLowerCase() === pattern.toLowerCase();
1165
+ }
1166
+ const flags = strict ? "" : "i";
1167
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
1168
+ const regex = new RegExp(`^${escaped}$`, flags);
1169
+ return regex.test(instanceType);
1170
+ }
1151
1171
  compareTypes(type1, type2, strict) {
1152
- if (strict) {
1153
- return type1 === type2;
1172
+ if (type1.includes("*")) return this.matchesType(type2, type1, strict);
1173
+ if (type2.includes("*")) return this.matchesType(type1, type2, strict);
1174
+ return strict ? type1 === type2 : type1.toLowerCase() === type2.toLowerCase();
1175
+ }
1176
+ expandWildcardTypes(compositionResults, patterns, strict) {
1177
+ const expanded = [];
1178
+ for (const pattern of patterns) {
1179
+ if (!pattern.includes("*")) {
1180
+ expanded.push(pattern);
1181
+ continue;
1182
+ }
1183
+ const matched = /* @__PURE__ */ new Set();
1184
+ for (const { composition } of compositionResults) {
1185
+ if (composition.composition.slots) {
1186
+ this.collectMatchingTypes(composition.composition.slots, pattern, strict, matched);
1187
+ }
1188
+ }
1189
+ if (matched.size === 0) {
1190
+ this.logger.warn(`Wildcard pattern "${pattern}" did not match any component types`);
1191
+ } else {
1192
+ this.logger.info(`Wildcard "${pattern}" expanded to: ${[...matched].join(", ")}`);
1193
+ }
1194
+ for (const type of matched) {
1195
+ expanded.push(type);
1196
+ }
1197
+ }
1198
+ return [...new Set(expanded)];
1199
+ }
1200
+ collectMatchingTypes(slots, pattern, strict, matched) {
1201
+ for (const instances of Object.values(slots)) {
1202
+ if (!Array.isArray(instances)) continue;
1203
+ for (const instance of instances) {
1204
+ if (instance._pattern) continue;
1205
+ if (this.matchesType(instance.type, pattern, strict)) {
1206
+ matched.add(instance.type);
1207
+ }
1208
+ if (instance.slots) {
1209
+ this.collectMatchingTypes(instance.slots, pattern, strict, matched);
1210
+ }
1211
+ }
1154
1212
  }
1155
- return type1.toLowerCase() === type2.toLowerCase();
1156
1213
  }
1157
1214
  truncate(str, maxLength) {
1158
1215
  if (str.length <= maxLength) return str;