@uniformdev/transformer 1.1.31 → 1.1.32

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
@@ -346,18 +346,31 @@ var ComponentService = class {
346
346
  }
347
347
  return component;
348
348
  }
349
+ resolveRemoveIds(component, parameterId, options = {}) {
350
+ const param = this.findParameter(component, parameterId, options);
351
+ if (!param) return [];
352
+ if (!this.isGroupParameter(param)) {
353
+ return [param.id];
354
+ }
355
+ const ids = [param.id];
356
+ for (const childId of param.typeConfig?.childrenParams ?? []) {
357
+ ids.push(...this.resolveRemoveIds(component, childId, options));
358
+ }
359
+ return ids;
360
+ }
349
361
  removeParameter(component, parameterId, options = {}) {
350
362
  const { strict = false } = options;
351
363
  if (!component.parameters) {
352
364
  return component;
353
365
  }
366
+ const idsToRemove = this.resolveRemoveIds(component, parameterId, options);
354
367
  component.parameters = component.parameters.filter(
355
- (p) => !this.compareIds(p.id, parameterId, strict)
368
+ (p) => !idsToRemove.some((id) => this.compareIds(p.id, id, strict))
356
369
  );
357
370
  for (const param of component.parameters) {
358
371
  if (this.isGroupParameter(param) && param.typeConfig?.childrenParams) {
359
372
  param.typeConfig.childrenParams = param.typeConfig.childrenParams.filter(
360
- (id) => !this.compareIds(id, parameterId, strict)
373
+ (id) => !idsToRemove.some((removeId) => this.compareIds(id, removeId, strict))
361
374
  );
362
375
  }
363
376
  }
@@ -4520,11 +4533,20 @@ var ParameterRemoverService = class {
4520
4533
  if (!param) {
4521
4534
  throw new PropertyNotFoundError(parameterId, componentType);
4522
4535
  }
4536
+ const allIdsToRemove = this.componentService.resolveRemoveIds(component, parameterId, findOptions);
4537
+ const childIds = allIdsToRemove.filter((id) => !this.compareIds(id, parameterId, strict));
4523
4538
  this.logger.action(
4524
4539
  whatIf,
4525
4540
  "REMOVE",
4526
4541
  `Parameter "${parameterId}" from component/${this.fileSystem.getBasename(componentFilePath)}`
4527
4542
  );
4543
+ if (childIds.length > 0) {
4544
+ this.logger.action(
4545
+ whatIf,
4546
+ "REMOVE",
4547
+ `Cascade-removing ${childIds.length} child parameter(s) [${childIds.join(", ")}] from component/${this.fileSystem.getBasename(componentFilePath)}`
4548
+ );
4549
+ }
4528
4550
  let modifiedComponent = this.componentService.removeParameter(component, parameterId, findOptions);
4529
4551
  const beforeGroupCount = modifiedComponent.parameters?.filter(
4530
4552
  (p) => this.componentService.isGroupParameter(p)
@@ -4547,7 +4569,7 @@ var ParameterRemoverService = class {
4547
4569
  const compositionsResult = await this.removeParameterInDirectory(
4548
4570
  fullCompositionsDir,
4549
4571
  componentType,
4550
- parameterId,
4572
+ allIdsToRemove,
4551
4573
  whatIf,
4552
4574
  strict,
4553
4575
  "composition"
@@ -4555,7 +4577,7 @@ var ParameterRemoverService = class {
4555
4577
  const compositionPatternsResult = await this.removeParameterInDirectory(
4556
4578
  fullCompositionPatternsDir,
4557
4579
  componentType,
4558
- parameterId,
4580
+ allIdsToRemove,
4559
4581
  whatIf,
4560
4582
  strict,
4561
4583
  "compositionPattern"
@@ -4563,7 +4585,7 @@ var ParameterRemoverService = class {
4563
4585
  const componentPatternsResult = await this.removeParameterInDirectory(
4564
4586
  fullComponentPatternsDir,
4565
4587
  componentType,
4566
- parameterId,
4588
+ allIdsToRemove,
4567
4589
  whatIf,
4568
4590
  strict,
4569
4591
  "componentPattern"
@@ -4582,7 +4604,7 @@ var ParameterRemoverService = class {
4582
4604
  instancesUpdated: totalInstances
4583
4605
  };
4584
4606
  }
4585
- async removeParameterInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
4607
+ async removeParameterInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
4586
4608
  let files;
4587
4609
  try {
4588
4610
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
@@ -4607,13 +4629,13 @@ var ParameterRemoverService = class {
4607
4629
  const count = this.removeParameterFromTree(
4608
4630
  composition.composition,
4609
4631
  componentType,
4610
- parameterId,
4632
+ parameterIds,
4611
4633
  strict
4612
4634
  );
4613
4635
  const overridesCount = this.removeParameterFromOverrides(
4614
4636
  composition,
4615
4637
  componentType,
4616
- parameterId,
4638
+ parameterIds,
4617
4639
  strict
4618
4640
  );
4619
4641
  const totalCount = count + overridesCount;
@@ -4633,11 +4655,11 @@ var ParameterRemoverService = class {
4633
4655
  }
4634
4656
  return { filesModified, instancesUpdated };
4635
4657
  }
4636
- removeParameterFromTree(node, componentType, parameterId, strict) {
4658
+ removeParameterFromTree(node, componentType, parameterIds, strict) {
4637
4659
  let count = 0;
4638
4660
  if (this.compareIds(node.type, componentType, strict) && node.parameters) {
4639
- const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
4640
- if (removed) {
4661
+ const removed = this.removeKeysFromMap(node.parameters, parameterIds, strict);
4662
+ if (removed > 0) {
4641
4663
  count++;
4642
4664
  }
4643
4665
  }
@@ -4645,13 +4667,13 @@ var ParameterRemoverService = class {
4645
4667
  for (const slotInstances of Object.values(node.slots)) {
4646
4668
  if (!Array.isArray(slotInstances)) continue;
4647
4669
  for (const instance of slotInstances) {
4648
- count += this.removeParameterFromTree(instance, componentType, parameterId, strict);
4670
+ count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
4649
4671
  }
4650
4672
  }
4651
4673
  }
4652
4674
  return count;
4653
4675
  }
4654
- removeParameterFromOverrides(composition, componentType, parameterId, strict) {
4676
+ removeParameterFromOverrides(composition, componentType, parameterIds, strict) {
4655
4677
  if (!composition.composition._overrides) {
4656
4678
  return 0;
4657
4679
  }
@@ -4660,8 +4682,8 @@ var ParameterRemoverService = class {
4660
4682
  const rootId = composition.composition._id;
4661
4683
  const rootOverrides = composition.composition._overrides[rootId];
4662
4684
  if (rootOverrides?.parameters) {
4663
- const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
4664
- if (removed) {
4685
+ const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
4686
+ if (removed > 0) {
4665
4687
  count++;
4666
4688
  }
4667
4689
  }
@@ -4671,14 +4693,14 @@ var ParameterRemoverService = class {
4671
4693
  composition.composition,
4672
4694
  composition.composition._overrides,
4673
4695
  componentType,
4674
- parameterId,
4696
+ parameterIds,
4675
4697
  strict,
4676
4698
  counter
4677
4699
  );
4678
4700
  count += counter.count;
4679
4701
  return count;
4680
4702
  }
4681
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict, counter) {
4703
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter) {
4682
4704
  if (node.slots) {
4683
4705
  for (const slotInstances of Object.values(node.slots)) {
4684
4706
  if (!Array.isArray(slotInstances)) continue;
@@ -4686,8 +4708,8 @@ var ParameterRemoverService = class {
4686
4708
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
4687
4709
  const instanceOverrides = overrides[instance._id];
4688
4710
  if (instanceOverrides?.parameters) {
4689
- const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
4690
- if (removed) {
4711
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
4712
+ if (removed > 0) {
4691
4713
  counter.count++;
4692
4714
  }
4693
4715
  }
@@ -4696,7 +4718,7 @@ var ParameterRemoverService = class {
4696
4718
  instance,
4697
4719
  overrides,
4698
4720
  componentType,
4699
- parameterId,
4721
+ parameterIds,
4700
4722
  strict,
4701
4723
  counter
4702
4724
  );
@@ -4704,15 +4726,16 @@ var ParameterRemoverService = class {
4704
4726
  }
4705
4727
  }
4706
4728
  }
4707
- removeKeyFromMap(map, key, strict) {
4708
- const matchingKey = Object.keys(map).find(
4709
- (k) => this.compareIds(k, key, strict)
4710
- );
4711
- if (!matchingKey) {
4712
- return false;
4729
+ removeKeysFromMap(map, keys, strict) {
4730
+ let removed = 0;
4731
+ for (const key of keys) {
4732
+ const matchingKey = Object.keys(map).find((k) => this.compareIds(k, key, strict));
4733
+ if (matchingKey) {
4734
+ delete map[matchingKey];
4735
+ removed++;
4736
+ }
4713
4737
  }
4714
- delete map[matchingKey];
4715
- return true;
4738
+ return removed;
4716
4739
  }
4717
4740
  };
4718
4741
 
@@ -4774,8 +4797,9 @@ import { Command as Command12 } from "commander";
4774
4797
 
4775
4798
  // src/core/services/field-remover.service.ts
4776
4799
  var FieldRemoverService = class {
4777
- constructor(fileSystem, logger) {
4800
+ constructor(fileSystem, componentService, logger) {
4778
4801
  this.fileSystem = fileSystem;
4802
+ this.componentService = componentService;
4779
4803
  this.logger = logger;
4780
4804
  }
4781
4805
  compareIds(id1, id2, strict) {
@@ -4787,6 +4811,7 @@ var FieldRemoverService = class {
4787
4811
  async remove(options) {
4788
4812
  const {
4789
4813
  rootDir,
4814
+ componentsDir,
4790
4815
  compositionsDir,
4791
4816
  compositionPatternsDir,
4792
4817
  componentPatternsDir,
@@ -4795,14 +4820,29 @@ var FieldRemoverService = class {
4795
4820
  whatIf,
4796
4821
  strict
4797
4822
  } = options;
4823
+ const findOptions = { strict };
4824
+ const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
4798
4825
  const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
4799
4826
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
4800
4827
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
4828
+ let allIdsToRemove = [parameterId];
4829
+ try {
4830
+ const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
4831
+ const resolved = this.componentService.resolveRemoveIds(component, parameterId, findOptions);
4832
+ if (resolved.length > 0) {
4833
+ allIdsToRemove = resolved;
4834
+ }
4835
+ } catch {
4836
+ }
4837
+ const childIds = allIdsToRemove.filter((id) => id.toLowerCase() !== parameterId.toLowerCase());
4838
+ if (childIds.length > 0) {
4839
+ this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
4840
+ }
4801
4841
  this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
4802
4842
  const compositionsResult = await this.removeFieldInDirectory(
4803
4843
  fullCompositionsDir,
4804
4844
  componentType,
4805
- parameterId,
4845
+ allIdsToRemove,
4806
4846
  whatIf,
4807
4847
  strict,
4808
4848
  "composition"
@@ -4810,7 +4850,7 @@ var FieldRemoverService = class {
4810
4850
  const compositionPatternsResult = await this.removeFieldInDirectory(
4811
4851
  fullCompositionPatternsDir,
4812
4852
  componentType,
4813
- parameterId,
4853
+ allIdsToRemove,
4814
4854
  whatIf,
4815
4855
  strict,
4816
4856
  "compositionPattern"
@@ -4818,7 +4858,7 @@ var FieldRemoverService = class {
4818
4858
  const componentPatternsResult = await this.removeFieldInDirectory(
4819
4859
  fullComponentPatternsDir,
4820
4860
  componentType,
4821
- parameterId,
4861
+ allIdsToRemove,
4822
4862
  whatIf,
4823
4863
  strict,
4824
4864
  "componentPattern"
@@ -4836,7 +4876,7 @@ var FieldRemoverService = class {
4836
4876
  instancesUpdated: totalInstances
4837
4877
  };
4838
4878
  }
4839
- async removeFieldInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
4879
+ async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
4840
4880
  let files;
4841
4881
  try {
4842
4882
  files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
@@ -4861,13 +4901,13 @@ var FieldRemoverService = class {
4861
4901
  const treeCount = this.removeFieldFromTree(
4862
4902
  composition.composition,
4863
4903
  componentType,
4864
- parameterId,
4904
+ parameterIds,
4865
4905
  strict
4866
4906
  );
4867
4907
  const overridesCount = this.removeFieldFromOverrides(
4868
4908
  composition,
4869
4909
  componentType,
4870
- parameterId,
4910
+ parameterIds,
4871
4911
  strict
4872
4912
  );
4873
4913
  const totalCount = treeCount + overridesCount;
@@ -4887,11 +4927,11 @@ var FieldRemoverService = class {
4887
4927
  }
4888
4928
  return { filesModified, instancesUpdated };
4889
4929
  }
4890
- removeFieldFromTree(node, componentType, parameterId, strict) {
4930
+ removeFieldFromTree(node, componentType, parameterIds, strict) {
4891
4931
  let count = 0;
4892
4932
  if (this.compareIds(node.type, componentType, strict) && node.parameters) {
4893
- const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
4894
- if (removed) {
4933
+ const removed = this.removeKeysFromMap(node.parameters, parameterIds, strict);
4934
+ if (removed > 0) {
4895
4935
  count++;
4896
4936
  }
4897
4937
  }
@@ -4899,13 +4939,13 @@ var FieldRemoverService = class {
4899
4939
  for (const slotInstances of Object.values(node.slots)) {
4900
4940
  if (!Array.isArray(slotInstances)) continue;
4901
4941
  for (const instance of slotInstances) {
4902
- count += this.removeFieldFromTree(instance, componentType, parameterId, strict);
4942
+ count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
4903
4943
  }
4904
4944
  }
4905
4945
  }
4906
4946
  return count;
4907
4947
  }
4908
- removeFieldFromOverrides(composition, componentType, parameterId, strict) {
4948
+ removeFieldFromOverrides(composition, componentType, parameterIds, strict) {
4909
4949
  if (!composition.composition._overrides) {
4910
4950
  return 0;
4911
4951
  }
@@ -4914,8 +4954,8 @@ var FieldRemoverService = class {
4914
4954
  const rootId = composition.composition._id;
4915
4955
  const rootOverrides = composition.composition._overrides[rootId];
4916
4956
  if (rootOverrides?.parameters) {
4917
- const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
4918
- if (removed) {
4957
+ const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
4958
+ if (removed > 0) {
4919
4959
  count++;
4920
4960
  }
4921
4961
  }
@@ -4924,12 +4964,12 @@ var FieldRemoverService = class {
4924
4964
  composition.composition,
4925
4965
  composition.composition._overrides,
4926
4966
  componentType,
4927
- parameterId,
4967
+ parameterIds,
4928
4968
  strict
4929
4969
  );
4930
4970
  return count;
4931
4971
  }
4932
- removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict) {
4972
+ removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict) {
4933
4973
  let count = 0;
4934
4974
  if (node.slots) {
4935
4975
  for (const slotInstances of Object.values(node.slots)) {
@@ -4938,8 +4978,8 @@ var FieldRemoverService = class {
4938
4978
  if (this.compareIds(instance.type, componentType, strict) && instance._id) {
4939
4979
  const instanceOverrides = overrides[instance._id];
4940
4980
  if (instanceOverrides?.parameters) {
4941
- const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
4942
- if (removed) {
4981
+ const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
4982
+ if (removed > 0) {
4943
4983
  count++;
4944
4984
  }
4945
4985
  }
@@ -4948,7 +4988,7 @@ var FieldRemoverService = class {
4948
4988
  instance,
4949
4989
  overrides,
4950
4990
  componentType,
4951
- parameterId,
4991
+ parameterIds,
4952
4992
  strict
4953
4993
  );
4954
4994
  }
@@ -4956,15 +4996,16 @@ var FieldRemoverService = class {
4956
4996
  }
4957
4997
  return count;
4958
4998
  }
4959
- removeKeyFromMap(map, key, strict) {
4960
- const matchingKey = Object.keys(map).find(
4961
- (k) => this.compareIds(k, key, strict)
4962
- );
4963
- if (!matchingKey) {
4964
- return false;
4999
+ removeKeysFromMap(map, keys, strict) {
5000
+ let removed = 0;
5001
+ for (const key of keys) {
5002
+ const matchingKey = Object.keys(map).find((k) => this.compareIds(k, key, strict));
5003
+ if (matchingKey) {
5004
+ delete map[matchingKey];
5005
+ removed++;
5006
+ }
4965
5007
  }
4966
- delete map[matchingKey];
4967
- return true;
5008
+ return removed;
4968
5009
  }
4969
5010
  };
4970
5011
 
@@ -4993,10 +5034,12 @@ function createRemoveFieldCommand() {
4993
5034
  };
4994
5035
  const logger = new Logger();
4995
5036
  const fileSystem = new FileSystemService();
4996
- const remover = new FieldRemoverService(fileSystem, logger);
5037
+ const componentService = new ComponentService(fileSystem);
5038
+ const remover = new FieldRemoverService(fileSystem, componentService, logger);
4997
5039
  try {
4998
5040
  const result = await remover.remove({
4999
5041
  rootDir: options.rootDir,
5042
+ componentsDir: options.componentsDir,
5000
5043
  compositionsDir: options.compositionsDir,
5001
5044
  compositionPatternsDir: options.compositionPatternsDir,
5002
5045
  componentPatternsDir: options.componentPatternsDir,
@@ -5749,7 +5792,7 @@ function createFlattenBlockFieldCommand() {
5749
5792
  // package.json
5750
5793
  var package_default = {
5751
5794
  name: "@uniformdev/transformer",
5752
- version: "1.1.31",
5795
+ version: "1.1.32",
5753
5796
  description: "CLI tool for transforming Uniform.dev serialization files offline",
5754
5797
  type: "module",
5755
5798
  bin: {