@uniformdev/transformer 1.1.52 → 1.1.54

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
@@ -36,6 +36,8 @@ interface ComponentInstance {
36
36
  }
37
37
  interface CompositionOverrides {
38
38
  parameters?: Record<string, ParameterValue>;
39
+ /** Slot patches stored only under _overrides (not duplicated on the main tree instance). */
40
+ slots?: Record<string, ComponentInstance[]>;
39
41
  [key: string]: unknown;
40
42
  }
41
43
  interface CompositionRoot {
@@ -610,6 +612,7 @@ declare class ParameterRemoverService {
610
612
  private removeParameterInDirectory;
611
613
  private removeParameterFromTree;
612
614
  private removeParameterFromOverrides;
615
+ private removeParameterFromOverrideSlotTrees;
613
616
  private removeOverridesForMatchingInstances;
614
617
  private removeKeysFromMap;
615
618
  }
@@ -644,6 +647,15 @@ declare class FieldRemoverService {
644
647
  private removeFieldInDirectory;
645
648
  private removeFieldFromTree;
646
649
  private removeFieldFromOverrides;
650
+ /**
651
+ * Walks every _overrides entry's `slots` trees (if present) and removes parameter keys from
652
+ * matching component instances. Uniform often stores nested slot patches only here.
653
+ */
654
+ private removeFieldFromOverrideSlotTrees;
655
+ /**
656
+ * Looks up override entries by compound key (ancestor _id chain joined with |) and,
657
+ * for backward compatibility, by instance _id alone when it differs from the compound key.
658
+ */
647
659
  private removeOverridesForMatchingInstances;
648
660
  private removeKeysFromMap;
649
661
  }
package/dist/index.js CHANGED
@@ -700,32 +700,12 @@ var CompositionConverterService = class {
700
700
  this.logger.debug(`Generated reference content type "${targetType}" with ${contentType.fields.length} field(s): ${contentType.fields.map((f) => f.id).join(", ")}`);
701
701
  }
702
702
  if (isBlockType) {
703
- let blockId = targetType;
704
- let needsRename = false;
705
- if (isRefType) {
706
- needsRename = true;
707
- }
708
- if (!needsRename) {
709
- const existingPath = this.fileSystem.joinPath(contentTypesDirFull, `${targetType}.json`);
710
- if (await this.fileSystem.fileExists(existingPath)) {
711
- try {
712
- const existing = await this.fileSystem.readFile(existingPath);
713
- if (existing?.type !== "block") {
714
- needsRename = true;
715
- }
716
- } catch {
717
- }
718
- }
719
- }
720
- if (needsRename) {
721
- blockId = `${targetType}Block`;
722
- this.logger.info(`Content type "${targetType}" already exists as non-block, using "${blockId}" for block`);
723
- }
703
+ const blockId = `${targetType}Block`;
724
704
  blockTypeIdMap.set(targetType, blockId);
725
705
  const blockContentType = this.generateContentType(component);
726
706
  blockContentType.type = "block";
727
707
  blockContentType.id = blockId;
728
- blockContentType.name = needsRename ? `${blockContentType.name} Block` : blockContentType.name;
708
+ blockContentType.name = `${blockContentType.name} Block`;
729
709
  targetContentTypeMap.set(blockId, blockContentType);
730
710
  this.logger.debug(`Generated block content type "${blockId}" with ${blockContentType.fields.length} field(s): ${blockContentType.fields.map((f) => f.id).join(", ")}`);
731
711
  }
@@ -740,7 +720,7 @@ var CompositionConverterService = class {
740
720
  this.logger.info(`Component type not found: ${targetType}`);
741
721
  missingTargetTypes.push(targetType);
742
722
  if (isBlockType) {
743
- blockTypeIdMap.set(targetType, targetType);
723
+ blockTypeIdMap.set(targetType, `${targetType}Block`);
744
724
  }
745
725
  continue;
746
726
  }
@@ -791,34 +771,19 @@ var CompositionConverterService = class {
791
771
  this.logger.debug(`Generated slot reference content type "${targetType}" with ${contentType.fields.length} field(s)`);
792
772
  }
793
773
  if (isSlotBlockType && !blockTypeIdMap.has(targetType)) {
794
- let blockId = targetType;
795
- let needsRename = isSlotRefType;
796
- if (!needsRename) {
797
- const existingPath = this.fileSystem.joinPath(contentTypesDirFull, `${targetType}.json`);
798
- if (await this.fileSystem.fileExists(existingPath)) {
799
- try {
800
- const existing = await this.fileSystem.readFile(existingPath);
801
- if (existing?.type !== "block") needsRename = true;
802
- } catch {
803
- }
804
- }
805
- }
806
- if (needsRename) {
807
- blockId = `${targetType}Block`;
808
- this.logger.info(`Content type "${targetType}" already exists as non-block, using "${blockId}" for block`);
809
- }
774
+ const blockId = `${targetType}Block`;
810
775
  blockTypeIdMap.set(targetType, blockId);
811
776
  const blockContentType = this.generateContentType(component);
812
777
  blockContentType.type = "block";
813
778
  blockContentType.id = blockId;
814
- blockContentType.name = needsRename ? `${blockContentType.name} Block` : blockContentType.name;
779
+ blockContentType.name = `${blockContentType.name} Block`;
815
780
  targetContentTypeMap.set(blockId, blockContentType);
816
781
  this.logger.debug(`Generated slot block content type "${blockId}" with ${blockContentType.fields.length} field(s)`);
817
782
  }
818
783
  } catch (error) {
819
784
  if (error instanceof ComponentNotFoundError) {
820
785
  this.logger.info(`Component type not found: ${targetType}`);
821
- if (isSlotBlockType && !blockTypeIdMap.has(targetType)) blockTypeIdMap.set(targetType, targetType);
786
+ if (isSlotBlockType && !blockTypeIdMap.has(targetType)) blockTypeIdMap.set(targetType, `${targetType}Block`);
822
787
  continue;
823
788
  }
824
789
  throw error;
@@ -2890,6 +2855,9 @@ var ParameterRemoverService = class {
2890
2855
  strict,
2891
2856
  "composition"
2892
2857
  );
2858
+ this.logger.info(
2859
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
2860
+ );
2893
2861
  const compositionPatternsResult = await this.removeParameterInDirectory(
2894
2862
  fullCompositionPatternsDir,
2895
2863
  componentType,
@@ -2898,6 +2866,9 @@ var ParameterRemoverService = class {
2898
2866
  strict,
2899
2867
  "compositionPattern"
2900
2868
  );
2869
+ this.logger.info(
2870
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
2871
+ );
2901
2872
  const componentPatternsResult = await this.removeParameterInDirectory(
2902
2873
  fullComponentPatternsDir,
2903
2874
  componentType,
@@ -2906,6 +2877,9 @@ var ParameterRemoverService = class {
2906
2877
  strict,
2907
2878
  "componentPattern"
2908
2879
  );
2880
+ this.logger.info(
2881
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
2882
+ );
2909
2883
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
2910
2884
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
2911
2885
  this.logger.info("");
@@ -2925,13 +2899,25 @@ var ParameterRemoverService = class {
2925
2899
  try {
2926
2900
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
2927
2901
  } catch {
2928
- return { filesModified: 0, instancesUpdated: 0 };
2902
+ return {
2903
+ filesModified: 0,
2904
+ instancesUpdated: 0,
2905
+ totalFilesMatched: 0,
2906
+ validCompositionDocuments: 0
2907
+ };
2929
2908
  }
2909
+ const totalFilesMatched = files.length;
2930
2910
  if (files.length === 0) {
2931
- return { filesModified: 0, instancesUpdated: 0 };
2911
+ return {
2912
+ filesModified: 0,
2913
+ instancesUpdated: 0,
2914
+ totalFilesMatched: 0,
2915
+ validCompositionDocuments: 0
2916
+ };
2932
2917
  }
2933
2918
  let filesModified = 0;
2934
2919
  let instancesUpdated = 0;
2920
+ let validCompositionDocuments = 0;
2935
2921
  for (const filePath of files) {
2936
2922
  let composition;
2937
2923
  try {
@@ -2942,6 +2928,7 @@ var ParameterRemoverService = class {
2942
2928
  if (!composition?.composition) {
2943
2929
  continue;
2944
2930
  }
2931
+ validCompositionDocuments++;
2945
2932
  const count = this.removeParameterFromTree(
2946
2933
  composition.composition,
2947
2934
  componentType,
@@ -2969,7 +2956,7 @@ var ParameterRemoverService = class {
2969
2956
  instancesUpdated += totalCount;
2970
2957
  }
2971
2958
  }
2972
- return { filesModified, instancesUpdated };
2959
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
2973
2960
  }
2974
2961
  removeParameterFromTree(node, componentType, parameterIds, strict) {
2975
2962
  let count = 0;
@@ -3011,24 +2998,54 @@ var ParameterRemoverService = class {
3011
2998
  componentType,
3012
2999
  parameterIds,
3013
3000
  strict,
3014
- counter
3001
+ counter,
3002
+ [composition.composition._id]
3015
3003
  );
3016
3004
  count += counter.count;
3005
+ const slotTreeCounter = { count: 0 };
3006
+ this.removeParameterFromOverrideSlotTrees(
3007
+ composition.composition._overrides,
3008
+ componentType,
3009
+ parameterIds,
3010
+ strict,
3011
+ slotTreeCounter
3012
+ );
3013
+ count += slotTreeCounter.count;
3017
3014
  return count;
3018
3015
  }
3019
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter) {
3016
+ removeParameterFromOverrideSlotTrees(overrides, componentType, parameterIds, strict, counter) {
3017
+ for (const entry of Object.values(overrides)) {
3018
+ const slots = entry.slots;
3019
+ if (!slots) continue;
3020
+ for (const slotInstances of Object.values(slots)) {
3021
+ if (!Array.isArray(slotInstances)) continue;
3022
+ for (const instance of slotInstances) {
3023
+ counter.count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
3024
+ }
3025
+ }
3026
+ }
3027
+ }
3028
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter, idPath) {
3020
3029
  if (node.slots) {
3021
3030
  for (const slotInstances of Object.values(node.slots)) {
3022
3031
  if (!Array.isArray(slotInstances)) continue;
3023
3032
  for (const instance of slotInstances) {
3024
3033
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
3025
- const instanceOverrides = overrides[instance._id];
3026
- if (instanceOverrides?.parameters) {
3027
- const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3028
- if (removed > 0) {
3029
- counter.count++;
3034
+ const compoundKey = [...idPath, instance._id].join("|");
3035
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
3036
+ let removedAny = false;
3037
+ for (const overrideKey of keysToTry) {
3038
+ const instanceOverrides = overrides[overrideKey];
3039
+ if (instanceOverrides?.parameters) {
3040
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3041
+ if (removed > 0) {
3042
+ removedAny = true;
3043
+ }
3030
3044
  }
3031
3045
  }
3046
+ if (removedAny) {
3047
+ counter.count++;
3048
+ }
3032
3049
  }
3033
3050
  this.removeOverridesForMatchingInstances(
3034
3051
  instance,
@@ -3036,7 +3053,8 @@ var ParameterRemoverService = class {
3036
3053
  componentType,
3037
3054
  parameterIds,
3038
3055
  strict,
3039
- counter
3056
+ counter,
3057
+ [...idPath, instance._id ?? ""]
3040
3058
  );
3041
3059
  }
3042
3060
  }
@@ -3117,6 +3135,9 @@ var FieldRemoverService = class {
3117
3135
  strict,
3118
3136
  "composition"
3119
3137
  );
3138
+ this.logger.info(
3139
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
3140
+ );
3120
3141
  const compositionPatternsResult = await this.removeFieldInDirectory(
3121
3142
  fullCompositionPatternsDir,
3122
3143
  componentType,
@@ -3125,6 +3146,9 @@ var FieldRemoverService = class {
3125
3146
  strict,
3126
3147
  "compositionPattern"
3127
3148
  );
3149
+ this.logger.info(
3150
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
3151
+ );
3128
3152
  const componentPatternsResult = await this.removeFieldInDirectory(
3129
3153
  fullComponentPatternsDir,
3130
3154
  componentType,
@@ -3133,6 +3157,9 @@ var FieldRemoverService = class {
3133
3157
  strict,
3134
3158
  "componentPattern"
3135
3159
  );
3160
+ this.logger.info(
3161
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
3162
+ );
3136
3163
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
3137
3164
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
3138
3165
  this.logger.info("");
@@ -3206,13 +3233,25 @@ var FieldRemoverService = class {
3206
3233
  try {
3207
3234
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
3208
3235
  } catch {
3209
- return { filesModified: 0, instancesUpdated: 0 };
3236
+ return {
3237
+ filesModified: 0,
3238
+ instancesUpdated: 0,
3239
+ totalFilesMatched: 0,
3240
+ validCompositionDocuments: 0
3241
+ };
3210
3242
  }
3243
+ const totalFilesMatched = files.length;
3211
3244
  if (files.length === 0) {
3212
- return { filesModified: 0, instancesUpdated: 0 };
3245
+ return {
3246
+ filesModified: 0,
3247
+ instancesUpdated: 0,
3248
+ totalFilesMatched: 0,
3249
+ validCompositionDocuments: 0
3250
+ };
3213
3251
  }
3214
3252
  let filesModified = 0;
3215
3253
  let instancesUpdated = 0;
3254
+ let validCompositionDocuments = 0;
3216
3255
  for (const filePath of files) {
3217
3256
  let composition;
3218
3257
  try {
@@ -3223,6 +3262,7 @@ var FieldRemoverService = class {
3223
3262
  if (!composition?.composition) {
3224
3263
  continue;
3225
3264
  }
3265
+ validCompositionDocuments++;
3226
3266
  const treeCount = this.removeFieldFromTree(
3227
3267
  composition.composition,
3228
3268
  componentType,
@@ -3250,7 +3290,7 @@ var FieldRemoverService = class {
3250
3290
  instancesUpdated += totalCount;
3251
3291
  }
3252
3292
  }
3253
- return { filesModified, instancesUpdated };
3293
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
3254
3294
  }
3255
3295
  removeFieldFromTree(node, componentType, parameterIds, strict) {
3256
3296
  let count = 0;
@@ -3276,8 +3316,8 @@ var FieldRemoverService = class {
3276
3316
  }
3277
3317
  let count = 0;
3278
3318
  if (this.compareIds(composition.composition.type, componentType, strict)) {
3279
- const rootId = composition.composition._id;
3280
- const rootOverrides = composition.composition._overrides[rootId];
3319
+ const rootId2 = composition.composition._id;
3320
+ const rootOverrides = composition.composition._overrides[rootId2];
3281
3321
  if (rootOverrides?.parameters) {
3282
3322
  const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
3283
3323
  if (removed > 0) {
@@ -3285,8 +3325,16 @@ var FieldRemoverService = class {
3285
3325
  }
3286
3326
  }
3287
3327
  }
3328
+ const rootId = composition.composition._id;
3288
3329
  count += this.removeOverridesForMatchingInstances(
3289
3330
  composition.composition,
3331
+ composition.composition._overrides,
3332
+ componentType,
3333
+ parameterIds,
3334
+ strict,
3335
+ [rootId]
3336
+ );
3337
+ count += this.removeFieldFromOverrideSlotTrees(
3290
3338
  composition.composition._overrides,
3291
3339
  componentType,
3292
3340
  parameterIds,
@@ -3294,27 +3342,58 @@ var FieldRemoverService = class {
3294
3342
  );
3295
3343
  return count;
3296
3344
  }
3297
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict) {
3345
+ /**
3346
+ * Walks every _overrides entry's `slots` trees (if present) and removes parameter keys from
3347
+ * matching component instances. Uniform often stores nested slot patches only here.
3348
+ */
3349
+ removeFieldFromOverrideSlotTrees(overrides, componentType, parameterIds, strict) {
3350
+ let count = 0;
3351
+ for (const entry of Object.values(overrides)) {
3352
+ const slots = entry.slots;
3353
+ if (!slots) continue;
3354
+ for (const slotInstances of Object.values(slots)) {
3355
+ if (!Array.isArray(slotInstances)) continue;
3356
+ for (const instance of slotInstances) {
3357
+ count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
3358
+ }
3359
+ }
3360
+ }
3361
+ return count;
3362
+ }
3363
+ /**
3364
+ * Looks up override entries by compound key (ancestor _id chain joined with |) and,
3365
+ * for backward compatibility, by instance _id alone when it differs from the compound key.
3366
+ */
3367
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, idPath) {
3298
3368
  let count = 0;
3299
3369
  if (node.slots) {
3300
3370
  for (const slotInstances of Object.values(node.slots)) {
3301
3371
  if (!Array.isArray(slotInstances)) continue;
3302
3372
  for (const instance of slotInstances) {
3303
3373
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
3304
- const instanceOverrides = overrides[instance._id];
3305
- if (instanceOverrides?.parameters) {
3306
- const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3307
- if (removed > 0) {
3308
- count++;
3374
+ const compoundKey = [...idPath, instance._id].join("|");
3375
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
3376
+ let removedAny = false;
3377
+ for (const overrideKey of keysToTry) {
3378
+ const instanceOverrides = overrides[overrideKey];
3379
+ if (instanceOverrides?.parameters) {
3380
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3381
+ if (removed > 0) {
3382
+ removedAny = true;
3383
+ }
3309
3384
  }
3310
3385
  }
3386
+ if (removedAny) {
3387
+ count++;
3388
+ }
3311
3389
  }
3312
3390
  count += this.removeOverridesForMatchingInstances(
3313
3391
  instance,
3314
3392
  overrides,
3315
3393
  componentType,
3316
3394
  parameterIds,
3317
- strict
3395
+ strict,
3396
+ [...idPath, instance._id ?? ""]
3318
3397
  );
3319
3398
  }
3320
3399
  }