codify-plugin-lib 1.0.155 → 1.0.156
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.
|
@@ -198,6 +198,11 @@ export class ResourceController {
|
|
|
198
198
|
...Object.fromEntries(this.settings.importAndDestroy?.refreshKeys.map((k) => [k, null])),
|
|
199
199
|
...this.settings.importAndDestroy?.defaultRefreshValues,
|
|
200
200
|
...parameters,
|
|
201
|
+
...(Object.fromEntries(// If a default value was used, but it was also declared in the defaultRefreshValues, prefer the defaultRefreshValue instead
|
|
202
|
+
Object.entries(parameters).filter(([k, v]) => this.parsedSettings.defaultValues[k] !== undefined
|
|
203
|
+
&& v === this.parsedSettings.defaultValues[k]
|
|
204
|
+
&& context.originalDesiredConfig?.[k] === undefined
|
|
205
|
+
&& this.settings.importAndDestroy?.defaultRefreshValues?.[k] !== undefined).map(([k]) => [k, this.settings.importAndDestroy.defaultRefreshValues[k]])))
|
|
201
206
|
}
|
|
202
207
|
: {
|
|
203
208
|
...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
|
package/package.json
CHANGED
|
@@ -767,10 +767,6 @@ describe('Resource tests', () => {
|
|
|
767
767
|
},
|
|
768
768
|
allowMultiple: {
|
|
769
769
|
matcher: (desired, current) => {
|
|
770
|
-
// console.log('Matcher');
|
|
771
|
-
// console.log(desired);
|
|
772
|
-
// console.log(current);
|
|
773
|
-
|
|
774
770
|
if (desired.path) {
|
|
775
771
|
return desired.path === current.path;
|
|
776
772
|
}
|
|
@@ -791,6 +787,47 @@ describe('Resource tests', () => {
|
|
|
791
787
|
const plan = await controller.plan({ type: 'path' }, { path: '$HOME/.bun/bin' }, null, false);
|
|
792
788
|
|
|
793
789
|
expect(plan.requiresChanges()).to.be.false;
|
|
794
|
-
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
it('Can import with the correct default parameters', async () => {
|
|
793
|
+
const resource = new class extends TestResource {
|
|
794
|
+
getSettings(): ResourceSettings<any> {
|
|
795
|
+
return {
|
|
796
|
+
id: 'path',
|
|
797
|
+
parameterSettings: {
|
|
798
|
+
path: { type: 'string', isEqual: 'directory' },
|
|
799
|
+
paths: { canModify: true, type: 'array', isElementEqual: 'directory' },
|
|
800
|
+
prepend: { default: false, setting: true },
|
|
801
|
+
declarationsOnly: { default: false, setting: true },
|
|
802
|
+
},
|
|
803
|
+
importAndDestroy: {
|
|
804
|
+
refreshKeys: ['paths', 'declarationsOnly'],
|
|
805
|
+
defaultRefreshValues: {
|
|
806
|
+
paths: [],
|
|
807
|
+
declarationsOnly: true,
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
allowMultiple: {
|
|
811
|
+
matcher: (desired, current) => {
|
|
812
|
+
if (desired.path) {
|
|
813
|
+
return desired.path === current.path;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const currentPaths = new Set(current.paths)
|
|
817
|
+
return desired.paths?.some((p) => currentPaths.has(p));
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
|
|
824
|
+
expect(parameters.declarationsOnly).to.be.true;
|
|
825
|
+
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const controller = new ResourceController(resource);
|
|
831
|
+
const plan = await controller.import({ type: 'path' }, {});
|
|
795
832
|
})
|
|
796
833
|
});
|
|
@@ -281,6 +281,14 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
281
281
|
),
|
|
282
282
|
...this.settings.importAndDestroy?.defaultRefreshValues,
|
|
283
283
|
...parameters,
|
|
284
|
+
...(Object.fromEntries( // If a default value was used, but it was also declared in the defaultRefreshValues, prefer the defaultRefreshValue instead
|
|
285
|
+
Object.entries(parameters).filter(([k, v]) =>
|
|
286
|
+
this.parsedSettings.defaultValues[k] !== undefined
|
|
287
|
+
&& v === this.parsedSettings.defaultValues[k]
|
|
288
|
+
&& context.originalDesiredConfig?.[k] === undefined
|
|
289
|
+
&& this.settings.importAndDestroy?.defaultRefreshValues?.[k] !== undefined
|
|
290
|
+
).map(([k]) => [k, this.settings.importAndDestroy!.defaultRefreshValues![k]])
|
|
291
|
+
))
|
|
284
292
|
}
|
|
285
293
|
: {
|
|
286
294
|
...Object.fromEntries(
|