@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/cli/index.js +144 -65
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +143 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -710,32 +710,12 @@ var CompositionConverterService = class {
|
|
|
710
710
|
this.logger.debug(`Generated reference content type "${targetType}" with ${contentType.fields.length} field(s): ${contentType.fields.map((f) => f.id).join(", ")}`);
|
|
711
711
|
}
|
|
712
712
|
if (isBlockType) {
|
|
713
|
-
|
|
714
|
-
let needsRename = false;
|
|
715
|
-
if (isRefType) {
|
|
716
|
-
needsRename = true;
|
|
717
|
-
}
|
|
718
|
-
if (!needsRename) {
|
|
719
|
-
const existingPath = this.fileSystem.joinPath(contentTypesDirFull, `${targetType}.json`);
|
|
720
|
-
if (await this.fileSystem.fileExists(existingPath)) {
|
|
721
|
-
try {
|
|
722
|
-
const existing = await this.fileSystem.readFile(existingPath);
|
|
723
|
-
if (existing?.type !== "block") {
|
|
724
|
-
needsRename = true;
|
|
725
|
-
}
|
|
726
|
-
} catch {
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if (needsRename) {
|
|
731
|
-
blockId = `${targetType}Block`;
|
|
732
|
-
this.logger.info(`Content type "${targetType}" already exists as non-block, using "${blockId}" for block`);
|
|
733
|
-
}
|
|
713
|
+
const blockId = `${targetType}Block`;
|
|
734
714
|
blockTypeIdMap.set(targetType, blockId);
|
|
735
715
|
const blockContentType = this.generateContentType(component);
|
|
736
716
|
blockContentType.type = "block";
|
|
737
717
|
blockContentType.id = blockId;
|
|
738
|
-
blockContentType.name =
|
|
718
|
+
blockContentType.name = `${blockContentType.name} Block`;
|
|
739
719
|
targetContentTypeMap.set(blockId, blockContentType);
|
|
740
720
|
this.logger.debug(`Generated block content type "${blockId}" with ${blockContentType.fields.length} field(s): ${blockContentType.fields.map((f) => f.id).join(", ")}`);
|
|
741
721
|
}
|
|
@@ -750,7 +730,7 @@ var CompositionConverterService = class {
|
|
|
750
730
|
this.logger.info(`Component type not found: ${targetType}`);
|
|
751
731
|
missingTargetTypes.push(targetType);
|
|
752
732
|
if (isBlockType) {
|
|
753
|
-
blockTypeIdMap.set(targetType, targetType);
|
|
733
|
+
blockTypeIdMap.set(targetType, `${targetType}Block`);
|
|
754
734
|
}
|
|
755
735
|
continue;
|
|
756
736
|
}
|
|
@@ -801,34 +781,19 @@ var CompositionConverterService = class {
|
|
|
801
781
|
this.logger.debug(`Generated slot reference content type "${targetType}" with ${contentType.fields.length} field(s)`);
|
|
802
782
|
}
|
|
803
783
|
if (isSlotBlockType && !blockTypeIdMap.has(targetType)) {
|
|
804
|
-
|
|
805
|
-
let needsRename = isSlotRefType;
|
|
806
|
-
if (!needsRename) {
|
|
807
|
-
const existingPath = this.fileSystem.joinPath(contentTypesDirFull, `${targetType}.json`);
|
|
808
|
-
if (await this.fileSystem.fileExists(existingPath)) {
|
|
809
|
-
try {
|
|
810
|
-
const existing = await this.fileSystem.readFile(existingPath);
|
|
811
|
-
if (existing?.type !== "block") needsRename = true;
|
|
812
|
-
} catch {
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
if (needsRename) {
|
|
817
|
-
blockId = `${targetType}Block`;
|
|
818
|
-
this.logger.info(`Content type "${targetType}" already exists as non-block, using "${blockId}" for block`);
|
|
819
|
-
}
|
|
784
|
+
const blockId = `${targetType}Block`;
|
|
820
785
|
blockTypeIdMap.set(targetType, blockId);
|
|
821
786
|
const blockContentType = this.generateContentType(component);
|
|
822
787
|
blockContentType.type = "block";
|
|
823
788
|
blockContentType.id = blockId;
|
|
824
|
-
blockContentType.name =
|
|
789
|
+
blockContentType.name = `${blockContentType.name} Block`;
|
|
825
790
|
targetContentTypeMap.set(blockId, blockContentType);
|
|
826
791
|
this.logger.debug(`Generated slot block content type "${blockId}" with ${blockContentType.fields.length} field(s)`);
|
|
827
792
|
}
|
|
828
793
|
} catch (error) {
|
|
829
794
|
if (error instanceof ComponentNotFoundError) {
|
|
830
795
|
this.logger.info(`Component type not found: ${targetType}`);
|
|
831
|
-
if (isSlotBlockType && !blockTypeIdMap.has(targetType)) blockTypeIdMap.set(targetType, targetType);
|
|
796
|
+
if (isSlotBlockType && !blockTypeIdMap.has(targetType)) blockTypeIdMap.set(targetType, `${targetType}Block`);
|
|
832
797
|
continue;
|
|
833
798
|
}
|
|
834
799
|
throw error;
|
|
@@ -4977,6 +4942,9 @@ var ParameterRemoverService = class {
|
|
|
4977
4942
|
strict,
|
|
4978
4943
|
"composition"
|
|
4979
4944
|
);
|
|
4945
|
+
this.logger.info(
|
|
4946
|
+
`Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
|
|
4947
|
+
);
|
|
4980
4948
|
const compositionPatternsResult = await this.removeParameterInDirectory(
|
|
4981
4949
|
fullCompositionPatternsDir,
|
|
4982
4950
|
componentType,
|
|
@@ -4985,6 +4953,9 @@ var ParameterRemoverService = class {
|
|
|
4985
4953
|
strict,
|
|
4986
4954
|
"compositionPattern"
|
|
4987
4955
|
);
|
|
4956
|
+
this.logger.info(
|
|
4957
|
+
`Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
|
|
4958
|
+
);
|
|
4988
4959
|
const componentPatternsResult = await this.removeParameterInDirectory(
|
|
4989
4960
|
fullComponentPatternsDir,
|
|
4990
4961
|
componentType,
|
|
@@ -4993,6 +4964,9 @@ var ParameterRemoverService = class {
|
|
|
4993
4964
|
strict,
|
|
4994
4965
|
"componentPattern"
|
|
4995
4966
|
);
|
|
4967
|
+
this.logger.info(
|
|
4968
|
+
`Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
|
|
4969
|
+
);
|
|
4996
4970
|
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
4997
4971
|
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
4998
4972
|
this.logger.info("");
|
|
@@ -5012,13 +4986,25 @@ var ParameterRemoverService = class {
|
|
|
5012
4986
|
try {
|
|
5013
4987
|
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
5014
4988
|
} catch {
|
|
5015
|
-
return {
|
|
4989
|
+
return {
|
|
4990
|
+
filesModified: 0,
|
|
4991
|
+
instancesUpdated: 0,
|
|
4992
|
+
totalFilesMatched: 0,
|
|
4993
|
+
validCompositionDocuments: 0
|
|
4994
|
+
};
|
|
5016
4995
|
}
|
|
4996
|
+
const totalFilesMatched = files.length;
|
|
5017
4997
|
if (files.length === 0) {
|
|
5018
|
-
return {
|
|
4998
|
+
return {
|
|
4999
|
+
filesModified: 0,
|
|
5000
|
+
instancesUpdated: 0,
|
|
5001
|
+
totalFilesMatched: 0,
|
|
5002
|
+
validCompositionDocuments: 0
|
|
5003
|
+
};
|
|
5019
5004
|
}
|
|
5020
5005
|
let filesModified = 0;
|
|
5021
5006
|
let instancesUpdated = 0;
|
|
5007
|
+
let validCompositionDocuments = 0;
|
|
5022
5008
|
for (const filePath of files) {
|
|
5023
5009
|
let composition;
|
|
5024
5010
|
try {
|
|
@@ -5029,6 +5015,7 @@ var ParameterRemoverService = class {
|
|
|
5029
5015
|
if (!composition?.composition) {
|
|
5030
5016
|
continue;
|
|
5031
5017
|
}
|
|
5018
|
+
validCompositionDocuments++;
|
|
5032
5019
|
const count = this.removeParameterFromTree(
|
|
5033
5020
|
composition.composition,
|
|
5034
5021
|
componentType,
|
|
@@ -5056,7 +5043,7 @@ var ParameterRemoverService = class {
|
|
|
5056
5043
|
instancesUpdated += totalCount;
|
|
5057
5044
|
}
|
|
5058
5045
|
}
|
|
5059
|
-
return { filesModified, instancesUpdated };
|
|
5046
|
+
return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
|
|
5060
5047
|
}
|
|
5061
5048
|
removeParameterFromTree(node, componentType, parameterIds, strict) {
|
|
5062
5049
|
let count = 0;
|
|
@@ -5098,24 +5085,54 @@ var ParameterRemoverService = class {
|
|
|
5098
5085
|
componentType,
|
|
5099
5086
|
parameterIds,
|
|
5100
5087
|
strict,
|
|
5101
|
-
counter
|
|
5088
|
+
counter,
|
|
5089
|
+
[composition.composition._id]
|
|
5102
5090
|
);
|
|
5103
5091
|
count += counter.count;
|
|
5092
|
+
const slotTreeCounter = { count: 0 };
|
|
5093
|
+
this.removeParameterFromOverrideSlotTrees(
|
|
5094
|
+
composition.composition._overrides,
|
|
5095
|
+
componentType,
|
|
5096
|
+
parameterIds,
|
|
5097
|
+
strict,
|
|
5098
|
+
slotTreeCounter
|
|
5099
|
+
);
|
|
5100
|
+
count += slotTreeCounter.count;
|
|
5104
5101
|
return count;
|
|
5105
5102
|
}
|
|
5106
|
-
|
|
5103
|
+
removeParameterFromOverrideSlotTrees(overrides, componentType, parameterIds, strict, counter) {
|
|
5104
|
+
for (const entry of Object.values(overrides)) {
|
|
5105
|
+
const slots = entry.slots;
|
|
5106
|
+
if (!slots) continue;
|
|
5107
|
+
for (const slotInstances of Object.values(slots)) {
|
|
5108
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
5109
|
+
for (const instance of slotInstances) {
|
|
5110
|
+
counter.count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
|
|
5111
|
+
}
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter, idPath) {
|
|
5107
5116
|
if (node.slots) {
|
|
5108
5117
|
for (const slotInstances of Object.values(node.slots)) {
|
|
5109
5118
|
if (!Array.isArray(slotInstances)) continue;
|
|
5110
5119
|
for (const instance of slotInstances) {
|
|
5111
5120
|
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
5112
|
-
const
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5121
|
+
const compoundKey = [...idPath, instance._id].join("|");
|
|
5122
|
+
const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
|
|
5123
|
+
let removedAny = false;
|
|
5124
|
+
for (const overrideKey of keysToTry) {
|
|
5125
|
+
const instanceOverrides = overrides[overrideKey];
|
|
5126
|
+
if (instanceOverrides?.parameters) {
|
|
5127
|
+
const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
|
|
5128
|
+
if (removed > 0) {
|
|
5129
|
+
removedAny = true;
|
|
5130
|
+
}
|
|
5117
5131
|
}
|
|
5118
5132
|
}
|
|
5133
|
+
if (removedAny) {
|
|
5134
|
+
counter.count++;
|
|
5135
|
+
}
|
|
5119
5136
|
}
|
|
5120
5137
|
this.removeOverridesForMatchingInstances(
|
|
5121
5138
|
instance,
|
|
@@ -5123,7 +5140,8 @@ var ParameterRemoverService = class {
|
|
|
5123
5140
|
componentType,
|
|
5124
5141
|
parameterIds,
|
|
5125
5142
|
strict,
|
|
5126
|
-
counter
|
|
5143
|
+
counter,
|
|
5144
|
+
[...idPath, instance._id ?? ""]
|
|
5127
5145
|
);
|
|
5128
5146
|
}
|
|
5129
5147
|
}
|
|
@@ -5300,6 +5318,9 @@ var FieldRemoverService = class {
|
|
|
5300
5318
|
strict,
|
|
5301
5319
|
"composition"
|
|
5302
5320
|
);
|
|
5321
|
+
this.logger.info(
|
|
5322
|
+
`Compositions (${compositionsDir}): ${compositionsResult.totalFilesMatched} file(s) matched, ${compositionsResult.validCompositionDocuments} with a composition root.`
|
|
5323
|
+
);
|
|
5303
5324
|
const compositionPatternsResult = await this.removeFieldInDirectory(
|
|
5304
5325
|
fullCompositionPatternsDir,
|
|
5305
5326
|
componentType,
|
|
@@ -5308,6 +5329,9 @@ var FieldRemoverService = class {
|
|
|
5308
5329
|
strict,
|
|
5309
5330
|
"compositionPattern"
|
|
5310
5331
|
);
|
|
5332
|
+
this.logger.info(
|
|
5333
|
+
`Composition patterns (${compositionPatternsDir}): ${compositionPatternsResult.totalFilesMatched} file(s) matched, ${compositionPatternsResult.validCompositionDocuments} with a composition root.`
|
|
5334
|
+
);
|
|
5311
5335
|
const componentPatternsResult = await this.removeFieldInDirectory(
|
|
5312
5336
|
fullComponentPatternsDir,
|
|
5313
5337
|
componentType,
|
|
@@ -5316,6 +5340,9 @@ var FieldRemoverService = class {
|
|
|
5316
5340
|
strict,
|
|
5317
5341
|
"componentPattern"
|
|
5318
5342
|
);
|
|
5343
|
+
this.logger.info(
|
|
5344
|
+
`Component patterns (${componentPatternsDir}): ${componentPatternsResult.totalFilesMatched} file(s) matched, ${componentPatternsResult.validCompositionDocuments} with a composition root.`
|
|
5345
|
+
);
|
|
5319
5346
|
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
5320
5347
|
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
5321
5348
|
this.logger.info("");
|
|
@@ -5389,13 +5416,25 @@ var FieldRemoverService = class {
|
|
|
5389
5416
|
try {
|
|
5390
5417
|
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
5391
5418
|
} catch {
|
|
5392
|
-
return {
|
|
5419
|
+
return {
|
|
5420
|
+
filesModified: 0,
|
|
5421
|
+
instancesUpdated: 0,
|
|
5422
|
+
totalFilesMatched: 0,
|
|
5423
|
+
validCompositionDocuments: 0
|
|
5424
|
+
};
|
|
5393
5425
|
}
|
|
5426
|
+
const totalFilesMatched = files.length;
|
|
5394
5427
|
if (files.length === 0) {
|
|
5395
|
-
return {
|
|
5428
|
+
return {
|
|
5429
|
+
filesModified: 0,
|
|
5430
|
+
instancesUpdated: 0,
|
|
5431
|
+
totalFilesMatched: 0,
|
|
5432
|
+
validCompositionDocuments: 0
|
|
5433
|
+
};
|
|
5396
5434
|
}
|
|
5397
5435
|
let filesModified = 0;
|
|
5398
5436
|
let instancesUpdated = 0;
|
|
5437
|
+
let validCompositionDocuments = 0;
|
|
5399
5438
|
for (const filePath of files) {
|
|
5400
5439
|
let composition;
|
|
5401
5440
|
try {
|
|
@@ -5406,6 +5445,7 @@ var FieldRemoverService = class {
|
|
|
5406
5445
|
if (!composition?.composition) {
|
|
5407
5446
|
continue;
|
|
5408
5447
|
}
|
|
5448
|
+
validCompositionDocuments++;
|
|
5409
5449
|
const treeCount = this.removeFieldFromTree(
|
|
5410
5450
|
composition.composition,
|
|
5411
5451
|
componentType,
|
|
@@ -5433,7 +5473,7 @@ var FieldRemoverService = class {
|
|
|
5433
5473
|
instancesUpdated += totalCount;
|
|
5434
5474
|
}
|
|
5435
5475
|
}
|
|
5436
|
-
return { filesModified, instancesUpdated };
|
|
5476
|
+
return { filesModified, instancesUpdated, totalFilesMatched, validCompositionDocuments };
|
|
5437
5477
|
}
|
|
5438
5478
|
removeFieldFromTree(node, componentType, parameterIds, strict) {
|
|
5439
5479
|
let count = 0;
|
|
@@ -5459,8 +5499,8 @@ var FieldRemoverService = class {
|
|
|
5459
5499
|
}
|
|
5460
5500
|
let count = 0;
|
|
5461
5501
|
if (this.compareIds(composition.composition.type, componentType, strict)) {
|
|
5462
|
-
const
|
|
5463
|
-
const rootOverrides = composition.composition._overrides[
|
|
5502
|
+
const rootId2 = composition.composition._id;
|
|
5503
|
+
const rootOverrides = composition.composition._overrides[rootId2];
|
|
5464
5504
|
if (rootOverrides?.parameters) {
|
|
5465
5505
|
const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
|
|
5466
5506
|
if (removed > 0) {
|
|
@@ -5468,8 +5508,16 @@ var FieldRemoverService = class {
|
|
|
5468
5508
|
}
|
|
5469
5509
|
}
|
|
5470
5510
|
}
|
|
5511
|
+
const rootId = composition.composition._id;
|
|
5471
5512
|
count += this.removeOverridesForMatchingInstances(
|
|
5472
5513
|
composition.composition,
|
|
5514
|
+
composition.composition._overrides,
|
|
5515
|
+
componentType,
|
|
5516
|
+
parameterIds,
|
|
5517
|
+
strict,
|
|
5518
|
+
[rootId]
|
|
5519
|
+
);
|
|
5520
|
+
count += this.removeFieldFromOverrideSlotTrees(
|
|
5473
5521
|
composition.composition._overrides,
|
|
5474
5522
|
componentType,
|
|
5475
5523
|
parameterIds,
|
|
@@ -5477,27 +5525,58 @@ var FieldRemoverService = class {
|
|
|
5477
5525
|
);
|
|
5478
5526
|
return count;
|
|
5479
5527
|
}
|
|
5480
|
-
|
|
5528
|
+
/**
|
|
5529
|
+
* Walks every _overrides entry's `slots` trees (if present) and removes parameter keys from
|
|
5530
|
+
* matching component instances. Uniform often stores nested slot patches only here.
|
|
5531
|
+
*/
|
|
5532
|
+
removeFieldFromOverrideSlotTrees(overrides, componentType, parameterIds, strict) {
|
|
5533
|
+
let count = 0;
|
|
5534
|
+
for (const entry of Object.values(overrides)) {
|
|
5535
|
+
const slots = entry.slots;
|
|
5536
|
+
if (!slots) continue;
|
|
5537
|
+
for (const slotInstances of Object.values(slots)) {
|
|
5538
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
5539
|
+
for (const instance of slotInstances) {
|
|
5540
|
+
count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5544
|
+
return count;
|
|
5545
|
+
}
|
|
5546
|
+
/**
|
|
5547
|
+
* Looks up override entries by compound key (ancestor _id chain joined with |) and,
|
|
5548
|
+
* for backward compatibility, by instance _id alone when it differs from the compound key.
|
|
5549
|
+
*/
|
|
5550
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, idPath) {
|
|
5481
5551
|
let count = 0;
|
|
5482
5552
|
if (node.slots) {
|
|
5483
5553
|
for (const slotInstances of Object.values(node.slots)) {
|
|
5484
5554
|
if (!Array.isArray(slotInstances)) continue;
|
|
5485
5555
|
for (const instance of slotInstances) {
|
|
5486
5556
|
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
5487
|
-
const
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5557
|
+
const compoundKey = [...idPath, instance._id].join("|");
|
|
5558
|
+
const keysToTry = compoundKey === instance._id ? [compoundKey] : [compoundKey, instance._id];
|
|
5559
|
+
let removedAny = false;
|
|
5560
|
+
for (const overrideKey of keysToTry) {
|
|
5561
|
+
const instanceOverrides = overrides[overrideKey];
|
|
5562
|
+
if (instanceOverrides?.parameters) {
|
|
5563
|
+
const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
|
|
5564
|
+
if (removed > 0) {
|
|
5565
|
+
removedAny = true;
|
|
5566
|
+
}
|
|
5492
5567
|
}
|
|
5493
5568
|
}
|
|
5569
|
+
if (removedAny) {
|
|
5570
|
+
count++;
|
|
5571
|
+
}
|
|
5494
5572
|
}
|
|
5495
5573
|
count += this.removeOverridesForMatchingInstances(
|
|
5496
5574
|
instance,
|
|
5497
5575
|
overrides,
|
|
5498
5576
|
componentType,
|
|
5499
5577
|
parameterIds,
|
|
5500
|
-
strict
|
|
5578
|
+
strict,
|
|
5579
|
+
[...idPath, instance._id ?? ""]
|
|
5501
5580
|
);
|
|
5502
5581
|
}
|
|
5503
5582
|
}
|
|
@@ -7773,7 +7852,7 @@ function createClearSlotCommand() {
|
|
|
7773
7852
|
// package.json
|
|
7774
7853
|
var package_default = {
|
|
7775
7854
|
name: "@uniformdev/transformer",
|
|
7776
|
-
version: "1.1.
|
|
7855
|
+
version: "1.1.54",
|
|
7777
7856
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
7778
7857
|
type: "module",
|
|
7779
7858
|
bin: {
|