@uniformdev/transformer 1.1.50 → 1.1.52

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
@@ -199,6 +199,11 @@ interface SplitContentTypeOptions extends GlobalOptions {
199
199
  fieldId: string;
200
200
  fieldContains: string;
201
201
  }
202
+ interface ClearSlotOptions extends GlobalOptions {
203
+ slot: string;
204
+ parentComponentType?: string;
205
+ compositionIds?: string;
206
+ }
202
207
 
203
208
  declare class TransformError extends Error {
204
209
  constructor(message: string);
@@ -615,6 +620,7 @@ interface RemoveFieldInternalOptions {
615
620
  compositionsDir: string;
616
621
  compositionPatternsDir: string;
617
622
  componentPatternsDir: string;
623
+ contentTypesDir: string;
618
624
  componentType: string;
619
625
  parameterId: string;
620
626
  whatIf: boolean;
@@ -624,6 +630,7 @@ interface RemoveFieldResult {
624
630
  compositionsModified: number;
625
631
  compositionPatternsModified: number;
626
632
  componentPatternsModified: number;
633
+ contentTypesModified: number;
627
634
  instancesUpdated: number;
628
635
  }
629
636
  declare class FieldRemoverService {
@@ -633,6 +640,7 @@ declare class FieldRemoverService {
633
640
  constructor(fileSystem: FileSystemService, componentService: ComponentService, logger: Logger);
634
641
  private compareIds;
635
642
  remove(options: RemoveFieldInternalOptions): Promise<RemoveFieldResult>;
643
+ private removeFieldFromContentTypes;
636
644
  private removeFieldInDirectory;
637
645
  private removeFieldFromTree;
638
646
  private removeFieldFromOverrides;
@@ -640,4 +648,4 @@ declare class FieldRemoverService {
640
648
  private removeKeysFromMap;
641
649
  }
642
650
 
643
- export { type AddComponentOptions, type AddComponentParameterOptions, type AddComponentPatternOptions, type AddContentTypeFieldOptions, ComponentAdderService, ComponentAlreadyExistsError, type ComponentDefinition, type ComponentInstance, ComponentNotFoundError, ComponentRenamerService, ComponentService, type Composition, CompositionConverterService, type CompositionOverrides, type CompositionPatternCandidatesOptions, type CompositionRoot, CompositionService, type ContentTypeDefinition$1 as ContentTypeDefinition, type ContentTypeField$1 as ContentTypeField, type ConvertCompositionsToEntriesOptions, DuplicateIdError, FieldRemoverService, FileNotFoundError, FileSystemService, type FlattenBlockFieldOptions, type GenerateMissingProjectMapNodesOptions, type GlobalOptions, InvalidYamlError, Logger, type PackSerializationOptions, type Parameter, ParameterRemoverService, type ParameterValue, type PropagateRootComponentPropertyOptions, type PropagateRootComponentSlotOptions, type PropagateRootSlotOptions, PropertyNotFoundError, PropertyPropagatorService, type RemoveFieldOptions, type RemoveOrphanEntriesOptions, type RemoveParameterOptions, type RemoveUnusedComponentTypesOptions, type RemoveUnusedContentTypesOptions, type RenameComponentOptions, type RenameSlotOptions, SlotAlreadyExistsError, type SlotDefinition, SlotNotFoundError, SlotRenamerService, type SplitContentTypeOptions, TransformError, type UnpackSerializationOptions, computeGuidHash, regenerateIds };
651
+ export { type AddComponentOptions, type AddComponentParameterOptions, type AddComponentPatternOptions, type AddContentTypeFieldOptions, type ClearSlotOptions, ComponentAdderService, ComponentAlreadyExistsError, type ComponentDefinition, type ComponentInstance, ComponentNotFoundError, ComponentRenamerService, ComponentService, type Composition, CompositionConverterService, type CompositionOverrides, type CompositionPatternCandidatesOptions, type CompositionRoot, CompositionService, type ContentTypeDefinition$1 as ContentTypeDefinition, type ContentTypeField$1 as ContentTypeField, type ConvertCompositionsToEntriesOptions, DuplicateIdError, FieldRemoverService, FileNotFoundError, FileSystemService, type FlattenBlockFieldOptions, type GenerateMissingProjectMapNodesOptions, type GlobalOptions, InvalidYamlError, Logger, type PackSerializationOptions, type Parameter, ParameterRemoverService, type ParameterValue, type PropagateRootComponentPropertyOptions, type PropagateRootComponentSlotOptions, type PropagateRootSlotOptions, PropertyNotFoundError, PropertyPropagatorService, type RemoveFieldOptions, type RemoveOrphanEntriesOptions, type RemoveParameterOptions, type RemoveUnusedComponentTypesOptions, type RemoveUnusedContentTypesOptions, type RenameComponentOptions, type RenameSlotOptions, SlotAlreadyExistsError, type SlotDefinition, SlotNotFoundError, SlotRenamerService, type SplitContentTypeOptions, TransformError, type UnpackSerializationOptions, computeGuidHash, regenerateIds };
package/dist/index.js CHANGED
@@ -3076,6 +3076,7 @@ var FieldRemoverService = class {
3076
3076
  compositionsDir,
3077
3077
  compositionPatternsDir,
3078
3078
  componentPatternsDir,
3079
+ contentTypesDir,
3079
3080
  componentType,
3080
3081
  parameterId,
3081
3082
  whatIf,
@@ -3086,6 +3087,7 @@ var FieldRemoverService = class {
3086
3087
  const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
3087
3088
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
3088
3089
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
3090
+ const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
3089
3091
  let allIdsToRemove = [parameterId];
3090
3092
  try {
3091
3093
  const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
@@ -3100,6 +3102,13 @@ var FieldRemoverService = class {
3100
3102
  this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
3101
3103
  }
3102
3104
  this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
3105
+ const contentTypesModified = await this.removeFieldFromContentTypes(
3106
+ fullContentTypesDir,
3107
+ componentType,
3108
+ allIdsToRemove,
3109
+ whatIf,
3110
+ strict
3111
+ );
3103
3112
  const compositionsResult = await this.removeFieldInDirectory(
3104
3113
  fullCompositionsDir,
3105
3114
  componentType,
@@ -3128,15 +3137,70 @@ var FieldRemoverService = class {
3128
3137
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
3129
3138
  this.logger.info("");
3130
3139
  this.logger.info(
3131
- `Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3140
+ `Summary: ${contentTypesModified} content type(s), ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3132
3141
  );
3133
3142
  return {
3134
3143
  compositionsModified: compositionsResult.filesModified,
3135
3144
  compositionPatternsModified: compositionPatternsResult.filesModified,
3136
3145
  componentPatternsModified: componentPatternsResult.filesModified,
3146
+ contentTypesModified,
3137
3147
  instancesUpdated: totalInstances
3138
3148
  };
3139
3149
  }
3150
+ async removeFieldFromContentTypes(contentTypesDir, componentType, fieldIds, whatIf, strict) {
3151
+ let files;
3152
+ try {
3153
+ files = await this.fileSystem.findFiles(contentTypesDir, "**/*.{json,yaml,yml}");
3154
+ } catch {
3155
+ return 0;
3156
+ }
3157
+ if (files.length === 0) {
3158
+ return 0;
3159
+ }
3160
+ const isWildcard = componentType === "*";
3161
+ let contentTypesModified = 0;
3162
+ for (const filePath of files) {
3163
+ let contentType;
3164
+ try {
3165
+ contentType = await this.fileSystem.readFile(filePath);
3166
+ } catch {
3167
+ continue;
3168
+ }
3169
+ if (!contentType?.id || !contentType.fields) {
3170
+ continue;
3171
+ }
3172
+ if (!isWildcard && !this.compareIds(contentType.id, componentType, strict)) {
3173
+ continue;
3174
+ }
3175
+ const removedFieldIds = [];
3176
+ contentType.fields = contentType.fields.filter((field) => {
3177
+ const shouldRemove = fieldIds.some((id) => this.compareIds(field.id, id, strict));
3178
+ if (shouldRemove) {
3179
+ removedFieldIds.push(field.id);
3180
+ }
3181
+ return !shouldRemove;
3182
+ });
3183
+ if (removedFieldIds.length === 0) {
3184
+ continue;
3185
+ }
3186
+ const entryName = contentType.entryName;
3187
+ if (entryName && removedFieldIds.some((id) => this.compareIds(id, entryName, strict))) {
3188
+ this.logger.info(`Clearing entryName "${entryName}" on content type "${contentType.id}" (field was removed)`);
3189
+ contentType.entryName = "";
3190
+ }
3191
+ const relativePath = this.fileSystem.getBasename(filePath);
3192
+ this.logger.action(
3193
+ whatIf,
3194
+ "UPDATE",
3195
+ `contentType/${relativePath} (removed ${removedFieldIds.length} field(s): ${removedFieldIds.join(", ")})`
3196
+ );
3197
+ if (!whatIf) {
3198
+ await this.fileSystem.writeFile(filePath, contentType);
3199
+ }
3200
+ contentTypesModified++;
3201
+ }
3202
+ return contentTypesModified;
3203
+ }
3140
3204
  async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
3141
3205
  let files;
3142
3206
  try {