@uniformdev/transformer 1.1.51 → 1.1.53

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
  }
@@ -620,6 +623,7 @@ interface RemoveFieldInternalOptions {
620
623
  compositionsDir: string;
621
624
  compositionPatternsDir: string;
622
625
  componentPatternsDir: string;
626
+ contentTypesDir: string;
623
627
  componentType: string;
624
628
  parameterId: string;
625
629
  whatIf: boolean;
@@ -629,6 +633,7 @@ interface RemoveFieldResult {
629
633
  compositionsModified: number;
630
634
  compositionPatternsModified: number;
631
635
  componentPatternsModified: number;
636
+ contentTypesModified: number;
632
637
  instancesUpdated: number;
633
638
  }
634
639
  declare class FieldRemoverService {
@@ -638,9 +643,19 @@ declare class FieldRemoverService {
638
643
  constructor(fileSystem: FileSystemService, componentService: ComponentService, logger: Logger);
639
644
  private compareIds;
640
645
  remove(options: RemoveFieldInternalOptions): Promise<RemoveFieldResult>;
646
+ private removeFieldFromContentTypes;
641
647
  private removeFieldInDirectory;
642
648
  private removeFieldFromTree;
643
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
+ */
644
659
  private removeOverridesForMatchingInstances;
645
660
  private removeKeysFromMap;
646
661
  }
package/dist/index.js CHANGED
@@ -2890,6 +2890,9 @@ var ParameterRemoverService = class {
2890
2890
  strict,
2891
2891
  "composition"
2892
2892
  );
2893
+ this.logger.info(
2894
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
2895
+ );
2893
2896
  const compositionPatternsResult = await this.removeParameterInDirectory(
2894
2897
  fullCompositionPatternsDir,
2895
2898
  componentType,
@@ -2898,6 +2901,9 @@ var ParameterRemoverService = class {
2898
2901
  strict,
2899
2902
  "compositionPattern"
2900
2903
  );
2904
+ this.logger.info(
2905
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
2906
+ );
2901
2907
  const componentPatternsResult = await this.removeParameterInDirectory(
2902
2908
  fullComponentPatternsDir,
2903
2909
  componentType,
@@ -2906,6 +2912,9 @@ var ParameterRemoverService = class {
2906
2912
  strict,
2907
2913
  "componentPattern"
2908
2914
  );
2915
+ this.logger.info(
2916
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
2917
+ );
2909
2918
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
2910
2919
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
2911
2920
  this.logger.info("");
@@ -2925,13 +2934,25 @@ var ParameterRemoverService = class {
2925
2934
  try {
2926
2935
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
2927
2936
  } catch {
2928
- return { filesModified: 0, instancesUpdated: 0 };
2937
+ return {
2938
+ filesModified: 0,
2939
+ instancesUpdated: 0,
2940
+ totalFilesMatched: 0,
2941
+ validCompositionDocuments: 0
2942
+ };
2929
2943
  }
2944
+ const totalFilesMatched = files.length;
2930
2945
  if (files.length === 0) {
2931
- return { filesModified: 0, instancesUpdated: 0 };
2946
+ return {
2947
+ filesModified: 0,
2948
+ instancesUpdated: 0,
2949
+ totalFilesMatched: 0,
2950
+ validCompositionDocuments: 0
2951
+ };
2932
2952
  }
2933
2953
  let filesModified = 0;
2934
2954
  let instancesUpdated = 0;
2955
+ let validCompositionDocuments = 0;
2935
2956
  for (const filePath of files) {
2936
2957
  let composition;
2937
2958
  try {
@@ -2942,6 +2963,7 @@ var ParameterRemoverService = class {
2942
2963
  if (!composition?.composition) {
2943
2964
  continue;
2944
2965
  }
2966
+ validCompositionDocuments++;
2945
2967
  const count = this.removeParameterFromTree(
2946
2968
  composition.composition,
2947
2969
  componentType,
@@ -2969,7 +2991,7 @@ var ParameterRemoverService = class {
2969
2991
  instancesUpdated += totalCount;
2970
2992
  }
2971
2993
  }
2972
- return { filesModified, instancesUpdated };
2994
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
2973
2995
  }
2974
2996
  removeParameterFromTree(node, componentType, parameterIds, strict) {
2975
2997
  let count = 0;
@@ -3011,24 +3033,54 @@ var ParameterRemoverService = class {
3011
3033
  componentType,
3012
3034
  parameterIds,
3013
3035
  strict,
3014
- counter
3036
+ counter,
3037
+ [composition.composition._id]
3015
3038
  );
3016
3039
  count += counter.count;
3040
+ const slotTreeCounter = { count: 0 };
3041
+ this.removeParameterFromOverrideSlotTrees(
3042
+ composition.composition._overrides,
3043
+ componentType,
3044
+ parameterIds,
3045
+ strict,
3046
+ slotTreeCounter
3047
+ );
3048
+ count += slotTreeCounter.count;
3017
3049
  return count;
3018
3050
  }
3019
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter) {
3051
+ removeParameterFromOverrideSlotTrees(overrides, componentType, parameterIds, strict, counter) {
3052
+ for (const entry of Object.values(overrides)) {
3053
+ const slots = entry.slots;
3054
+ if (!slots) continue;
3055
+ for (const slotInstances of Object.values(slots)) {
3056
+ if (!Array.isArray(slotInstances)) continue;
3057
+ for (const instance of slotInstances) {
3058
+ counter.count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
3059
+ }
3060
+ }
3061
+ }
3062
+ }
3063
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter, idPath) {
3020
3064
  if (node.slots) {
3021
3065
  for (const slotInstances of Object.values(node.slots)) {
3022
3066
  if (!Array.isArray(slotInstances)) continue;
3023
3067
  for (const instance of slotInstances) {
3024
3068
  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++;
3069
+ const compoundKey = [...idPath, instance._id].join("|");
3070
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
3071
+ let removedAny = false;
3072
+ for (const overrideKey of keysToTry) {
3073
+ const instanceOverrides = overrides[overrideKey];
3074
+ if (instanceOverrides?.parameters) {
3075
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3076
+ if (removed > 0) {
3077
+ removedAny = true;
3078
+ }
3030
3079
  }
3031
3080
  }
3081
+ if (removedAny) {
3082
+ counter.count++;
3083
+ }
3032
3084
  }
3033
3085
  this.removeOverridesForMatchingInstances(
3034
3086
  instance,
@@ -3036,7 +3088,8 @@ var ParameterRemoverService = class {
3036
3088
  componentType,
3037
3089
  parameterIds,
3038
3090
  strict,
3039
- counter
3091
+ counter,
3092
+ [...idPath, instance._id ?? ""]
3040
3093
  );
3041
3094
  }
3042
3095
  }
@@ -3076,6 +3129,7 @@ var FieldRemoverService = class {
3076
3129
  compositionsDir,
3077
3130
  compositionPatternsDir,
3078
3131
  componentPatternsDir,
3132
+ contentTypesDir,
3079
3133
  componentType,
3080
3134
  parameterId,
3081
3135
  whatIf,
@@ -3086,6 +3140,7 @@ var FieldRemoverService = class {
3086
3140
  const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
3087
3141
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
3088
3142
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
3143
+ const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
3089
3144
  let allIdsToRemove = [parameterId];
3090
3145
  try {
3091
3146
  const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
@@ -3100,6 +3155,13 @@ var FieldRemoverService = class {
3100
3155
  this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
3101
3156
  }
3102
3157
  this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
3158
+ const contentTypesModified = await this.removeFieldFromContentTypes(
3159
+ fullContentTypesDir,
3160
+ componentType,
3161
+ allIdsToRemove,
3162
+ whatIf,
3163
+ strict
3164
+ );
3103
3165
  const compositionsResult = await this.removeFieldInDirectory(
3104
3166
  fullCompositionsDir,
3105
3167
  componentType,
@@ -3108,6 +3170,9 @@ var FieldRemoverService = class {
3108
3170
  strict,
3109
3171
  "composition"
3110
3172
  );
3173
+ this.logger.info(
3174
+ `Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
3175
+ );
3111
3176
  const compositionPatternsResult = await this.removeFieldInDirectory(
3112
3177
  fullCompositionPatternsDir,
3113
3178
  componentType,
@@ -3116,6 +3181,9 @@ var FieldRemoverService = class {
3116
3181
  strict,
3117
3182
  "compositionPattern"
3118
3183
  );
3184
+ this.logger.info(
3185
+ `Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
3186
+ );
3119
3187
  const componentPatternsResult = await this.removeFieldInDirectory(
3120
3188
  fullComponentPatternsDir,
3121
3189
  componentType,
@@ -3124,31 +3192,101 @@ var FieldRemoverService = class {
3124
3192
  strict,
3125
3193
  "componentPattern"
3126
3194
  );
3195
+ this.logger.info(
3196
+ `Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
3197
+ );
3127
3198
  const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
3128
3199
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
3129
3200
  this.logger.info("");
3130
3201
  this.logger.info(
3131
- `Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3202
+ `Summary: ${contentTypesModified} content type(s), ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3132
3203
  );
3133
3204
  return {
3134
3205
  compositionsModified: compositionsResult.filesModified,
3135
3206
  compositionPatternsModified: compositionPatternsResult.filesModified,
3136
3207
  componentPatternsModified: componentPatternsResult.filesModified,
3208
+ contentTypesModified,
3137
3209
  instancesUpdated: totalInstances
3138
3210
  };
3139
3211
  }
3212
+ async removeFieldFromContentTypes(contentTypesDir, componentType, fieldIds, whatIf, strict) {
3213
+ let files;
3214
+ try {
3215
+ files = await this.fileSystem.findFiles(contentTypesDir, "**/*.{json,yaml,yml}");
3216
+ } catch {
3217
+ return 0;
3218
+ }
3219
+ if (files.length === 0) {
3220
+ return 0;
3221
+ }
3222
+ const isWildcard = componentType === "*";
3223
+ let contentTypesModified = 0;
3224
+ for (const filePath of files) {
3225
+ let contentType;
3226
+ try {
3227
+ contentType = await this.fileSystem.readFile(filePath);
3228
+ } catch {
3229
+ continue;
3230
+ }
3231
+ if (!contentType?.id || !contentType.fields) {
3232
+ continue;
3233
+ }
3234
+ if (!isWildcard && !this.compareIds(contentType.id, componentType, strict)) {
3235
+ continue;
3236
+ }
3237
+ const removedFieldIds = [];
3238
+ contentType.fields = contentType.fields.filter((field) => {
3239
+ const shouldRemove = fieldIds.some((id) => this.compareIds(field.id, id, strict));
3240
+ if (shouldRemove) {
3241
+ removedFieldIds.push(field.id);
3242
+ }
3243
+ return !shouldRemove;
3244
+ });
3245
+ if (removedFieldIds.length === 0) {
3246
+ continue;
3247
+ }
3248
+ const entryName = contentType.entryName;
3249
+ if (entryName && removedFieldIds.some((id) => this.compareIds(id, entryName, strict))) {
3250
+ this.logger.info(`Clearing entryName "${entryName}" on content type "${contentType.id}" (field was removed)`);
3251
+ contentType.entryName = "";
3252
+ }
3253
+ const relativePath = this.fileSystem.getBasename(filePath);
3254
+ this.logger.action(
3255
+ whatIf,
3256
+ "UPDATE",
3257
+ `contentType/${relativePath} (removed ${removedFieldIds.length} field(s): ${removedFieldIds.join(", ")})`
3258
+ );
3259
+ if (!whatIf) {
3260
+ await this.fileSystem.writeFile(filePath, contentType);
3261
+ }
3262
+ contentTypesModified++;
3263
+ }
3264
+ return contentTypesModified;
3265
+ }
3140
3266
  async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
3141
3267
  let files;
3142
3268
  try {
3143
3269
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
3144
3270
  } catch {
3145
- return { filesModified: 0, instancesUpdated: 0 };
3271
+ return {
3272
+ filesModified: 0,
3273
+ instancesUpdated: 0,
3274
+ totalFilesMatched: 0,
3275
+ validCompositionDocuments: 0
3276
+ };
3146
3277
  }
3278
+ const totalFilesMatched = files.length;
3147
3279
  if (files.length === 0) {
3148
- return { filesModified: 0, instancesUpdated: 0 };
3280
+ return {
3281
+ filesModified: 0,
3282
+ instancesUpdated: 0,
3283
+ totalFilesMatched: 0,
3284
+ validCompositionDocuments: 0
3285
+ };
3149
3286
  }
3150
3287
  let filesModified = 0;
3151
3288
  let instancesUpdated = 0;
3289
+ let validCompositionDocuments = 0;
3152
3290
  for (const filePath of files) {
3153
3291
  let composition;
3154
3292
  try {
@@ -3159,6 +3297,7 @@ var FieldRemoverService = class {
3159
3297
  if (!composition?.composition) {
3160
3298
  continue;
3161
3299
  }
3300
+ validCompositionDocuments++;
3162
3301
  const treeCount = this.removeFieldFromTree(
3163
3302
  composition.composition,
3164
3303
  componentType,
@@ -3186,7 +3325,7 @@ var FieldRemoverService = class {
3186
3325
  instancesUpdated += totalCount;
3187
3326
  }
3188
3327
  }
3189
- return { filesModified, instancesUpdated };
3328
+ return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
3190
3329
  }
3191
3330
  removeFieldFromTree(node, componentType, parameterIds, strict) {
3192
3331
  let count = 0;
@@ -3212,8 +3351,8 @@ var FieldRemoverService = class {
3212
3351
  }
3213
3352
  let count = 0;
3214
3353
  if (this.compareIds(composition.composition.type, componentType, strict)) {
3215
- const rootId = composition.composition._id;
3216
- const rootOverrides = composition.composition._overrides[rootId];
3354
+ const rootId2 = composition.composition._id;
3355
+ const rootOverrides = composition.composition._overrides[rootId2];
3217
3356
  if (rootOverrides?.parameters) {
3218
3357
  const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
3219
3358
  if (removed > 0) {
@@ -3221,8 +3360,16 @@ var FieldRemoverService = class {
3221
3360
  }
3222
3361
  }
3223
3362
  }
3363
+ const rootId = composition.composition._id;
3224
3364
  count += this.removeOverridesForMatchingInstances(
3225
3365
  composition.composition,
3366
+ composition.composition._overrides,
3367
+ componentType,
3368
+ parameterIds,
3369
+ strict,
3370
+ [rootId]
3371
+ );
3372
+ count += this.removeFieldFromOverrideSlotTrees(
3226
3373
  composition.composition._overrides,
3227
3374
  componentType,
3228
3375
  parameterIds,
@@ -3230,27 +3377,58 @@ var FieldRemoverService = class {
3230
3377
  );
3231
3378
  return count;
3232
3379
  }
3233
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict) {
3380
+ /**
3381
+ * Walks every _overrides entry's `slots` trees (if present) and removes parameter keys from
3382
+ * matching component instances. Uniform often stores nested slot patches only here.
3383
+ */
3384
+ removeFieldFromOverrideSlotTrees(overrides, componentType, parameterIds, strict) {
3385
+ let count = 0;
3386
+ for (const entry of Object.values(overrides)) {
3387
+ const slots = entry.slots;
3388
+ if (!slots) continue;
3389
+ for (const slotInstances of Object.values(slots)) {
3390
+ if (!Array.isArray(slotInstances)) continue;
3391
+ for (const instance of slotInstances) {
3392
+ count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
3393
+ }
3394
+ }
3395
+ }
3396
+ return count;
3397
+ }
3398
+ /**
3399
+ * Looks up override entries by compound key (ancestor _id chain joined with |) and,
3400
+ * for backward compatibility, by instance _id alone when it differs from the compound key.
3401
+ */
3402
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, idPath) {
3234
3403
  let count = 0;
3235
3404
  if (node.slots) {
3236
3405
  for (const slotInstances of Object.values(node.slots)) {
3237
3406
  if (!Array.isArray(slotInstances)) continue;
3238
3407
  for (const instance of slotInstances) {
3239
3408
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
3240
- const instanceOverrides = overrides[instance._id];
3241
- if (instanceOverrides?.parameters) {
3242
- const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3243
- if (removed > 0) {
3244
- count++;
3409
+ const compoundKey = [...idPath, instance._id].join("|");
3410
+ const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
3411
+ let removedAny = false;
3412
+ for (const overrideKey of keysToTry) {
3413
+ const instanceOverrides = overrides[overrideKey];
3414
+ if (instanceOverrides?.parameters) {
3415
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
3416
+ if (removed > 0) {
3417
+ removedAny = true;
3418
+ }
3245
3419
  }
3246
3420
  }
3421
+ if (removedAny) {
3422
+ count++;
3423
+ }
3247
3424
  }
3248
3425
  count += this.removeOverridesForMatchingInstances(
3249
3426
  instance,
3250
3427
  overrides,
3251
3428
  componentType,
3252
3429
  parameterIds,
3253
- strict
3430
+ strict,
3431
+ [...idPath, instance._id ?? ""]
3254
3432
  );
3255
3433
  }
3256
3434
  }