codify-plugin-lib 1.0.157 → 1.0.158
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/plan/plan.js +2 -2
- package/dist/resource/resource-controller.js +4 -4
- package/dist/resource/resource-settings.d.ts +1 -1
- package/dist/resource/resource-settings.js +8 -3
- package/package.json +1 -1
- package/src/plan/plan.ts +2 -2
- package/src/resource/resource-controller.ts +4 -4
- package/src/resource/resource-settings.ts +11 -4
package/dist/plan/plan.js
CHANGED
|
@@ -189,8 +189,8 @@ export class Plan {
|
|
|
189
189
|
return null;
|
|
190
190
|
}
|
|
191
191
|
// For stateful mode, we're done after filtering by the keys of desired + state. Stateless mode
|
|
192
|
-
// requires additional filtering for stateful parameter arrays and objects.
|
|
193
|
-
if (isStateful
|
|
192
|
+
// requires additional filtering for stateful parameter arrays and objects.
|
|
193
|
+
if (isStateful) {
|
|
194
194
|
return filteredCurrent;
|
|
195
195
|
}
|
|
196
196
|
// TODO: Add object handling here in addition to arrays in the future
|
|
@@ -222,7 +222,7 @@ export class ResourceController {
|
|
|
222
222
|
const resultParametersArray = currentParametersArray
|
|
223
223
|
?.map((r, idx) => ({ ...r, ...statefulCurrentParameters[idx] }));
|
|
224
224
|
for (const result of resultParametersArray) {
|
|
225
|
-
await this.applyTransformParameters(result,
|
|
225
|
+
await this.applyTransformParameters(result, { original: parameters });
|
|
226
226
|
this.removeDefaultValues(result, parameters);
|
|
227
227
|
}
|
|
228
228
|
return resultParametersArray?.map((r) => ({ core, parameters: r }));
|
|
@@ -287,7 +287,7 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
287
287
|
`);
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
-
async applyTransformParameters(config, reverse
|
|
290
|
+
async applyTransformParameters(config, reverse) {
|
|
291
291
|
if (!config) {
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
@@ -296,12 +296,12 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
296
296
|
continue;
|
|
297
297
|
}
|
|
298
298
|
config[key] = reverse
|
|
299
|
-
? await inputTransformation.from(config[key])
|
|
299
|
+
? await inputTransformation.from(config[key], reverse.original)
|
|
300
300
|
: await inputTransformation.to(config[key]);
|
|
301
301
|
}
|
|
302
302
|
if (this.settings.transformation) {
|
|
303
303
|
const transformed = reverse
|
|
304
|
-
? await this.settings.transformation.from({ ...config })
|
|
304
|
+
? await this.settings.transformation.from({ ...config }, reverse.original)
|
|
305
305
|
: await this.settings.transformation.to({ ...config });
|
|
306
306
|
Object.keys(config).forEach((k) => delete config[k]);
|
|
307
307
|
Object.assign(config, transformed);
|
|
@@ -3,7 +3,7 @@ import { StringIndexedObject } from 'codify-schemas';
|
|
|
3
3
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
4
4
|
export interface InputTransformation {
|
|
5
5
|
to: (input: any) => Promise<any> | any;
|
|
6
|
-
from: (current: any) => Promise<any> | any;
|
|
6
|
+
from: (current: any, original: any) => Promise<any> | any;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* The configuration and settings for a resource.
|
|
@@ -54,7 +54,12 @@ export function resolveFnFromEqualsFnOrString(fnOrString) {
|
|
|
54
54
|
const ParameterTransformationDefaults = {
|
|
55
55
|
'directory': {
|
|
56
56
|
to: (a) => path.resolve(resolvePathWithVariables((untildify(String(a))))),
|
|
57
|
-
from: (a) =>
|
|
57
|
+
from: (a, original) => {
|
|
58
|
+
if (ParameterEqualsDefaults.directory(a, original)) {
|
|
59
|
+
return original;
|
|
60
|
+
}
|
|
61
|
+
return addVariablesToPath(tildify(String(a)));
|
|
62
|
+
},
|
|
58
63
|
},
|
|
59
64
|
'string': {
|
|
60
65
|
to: String,
|
|
@@ -83,8 +88,8 @@ export function resolveParameterTransformFn(parameter) {
|
|
|
83
88
|
to(input) {
|
|
84
89
|
return input.map((i) => itemTransformation.to(i));
|
|
85
90
|
},
|
|
86
|
-
from(input) {
|
|
87
|
-
return input.map((i) => itemTransformation.from(i));
|
|
91
|
+
from(input, original) {
|
|
92
|
+
return input.map((i) => itemTransformation.from(i, original));
|
|
88
93
|
}
|
|
89
94
|
};
|
|
90
95
|
}
|
package/package.json
CHANGED
package/src/plan/plan.ts
CHANGED
|
@@ -312,8 +312,8 @@ export class Plan<T extends StringIndexedObject> {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
// For stateful mode, we're done after filtering by the keys of desired + state. Stateless mode
|
|
315
|
-
// requires additional filtering for stateful parameter arrays and objects.
|
|
316
|
-
if (isStateful
|
|
315
|
+
// requires additional filtering for stateful parameter arrays and objects.
|
|
316
|
+
if (isStateful) {
|
|
317
317
|
return filteredCurrent;
|
|
318
318
|
}
|
|
319
319
|
|
|
@@ -320,7 +320,7 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
320
320
|
?.map((r, idx) => ({ ...r, ...statefulCurrentParameters[idx] }))
|
|
321
321
|
|
|
322
322
|
for (const result of resultParametersArray) {
|
|
323
|
-
await this.applyTransformParameters(result,
|
|
323
|
+
await this.applyTransformParameters(result, { original: parameters });
|
|
324
324
|
this.removeDefaultValues(result, parameters);
|
|
325
325
|
}
|
|
326
326
|
|
|
@@ -403,7 +403,7 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
-
private async applyTransformParameters(config: Partial<T> | null, reverse
|
|
406
|
+
private async applyTransformParameters(config: Partial<T> | null, reverse?: { original: Partial<T> }): Promise<void> {
|
|
407
407
|
if (!config) {
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
@@ -414,13 +414,13 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
(config as Record<string, unknown>)[key] = reverse
|
|
417
|
-
? await inputTransformation.from(config[key])
|
|
417
|
+
? await inputTransformation.from(config[key], reverse.original)
|
|
418
418
|
: await inputTransformation.to(config[key]);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
if (this.settings.transformation) {
|
|
422
422
|
const transformed = reverse
|
|
423
|
-
? await this.settings.transformation.from({ ...config })
|
|
423
|
+
? await this.settings.transformation.from({ ...config }, reverse.original)
|
|
424
424
|
: await this.settings.transformation.to({ ...config })
|
|
425
425
|
|
|
426
426
|
Object.keys(config).forEach((k) => delete config[k])
|
|
@@ -5,10 +5,11 @@ import path from 'node:path';
|
|
|
5
5
|
|
|
6
6
|
import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
|
|
7
7
|
import { addVariablesToPath, areArraysEqual, resolvePathWithVariables, tildify, untildify } from '../utils/utils.js';
|
|
8
|
+
import { or } from 'ajv/dist/compile/codegen/index.js';
|
|
8
9
|
|
|
9
10
|
export interface InputTransformation {
|
|
10
11
|
to: (input: any) => Promise<any> | any;
|
|
11
|
-
from: (current: any) => Promise<any> | any;
|
|
12
|
+
from: (current: any, original: any) => Promise<any> | any;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -369,7 +370,13 @@ export function resolveFnFromEqualsFnOrString(
|
|
|
369
370
|
const ParameterTransformationDefaults: Partial<Record<ParameterSettingType, InputTransformation>> = {
|
|
370
371
|
'directory': {
|
|
371
372
|
to: (a: unknown) => path.resolve(resolvePathWithVariables((untildify(String(a))))),
|
|
372
|
-
from: (a: unknown) =>
|
|
373
|
+
from: (a: unknown, original) => {
|
|
374
|
+
if (ParameterEqualsDefaults.directory!(a, original)) {
|
|
375
|
+
return original;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return addVariablesToPath(tildify(String(a)))
|
|
379
|
+
},
|
|
373
380
|
},
|
|
374
381
|
'string': {
|
|
375
382
|
to: String,
|
|
@@ -406,8 +413,8 @@ export function resolveParameterTransformFn(
|
|
|
406
413
|
to(input: unknown[]) {
|
|
407
414
|
return input.map((i) => itemTransformation.to(i))
|
|
408
415
|
},
|
|
409
|
-
from(input: unknown[]) {
|
|
410
|
-
return input.map((i) => itemTransformation.from(i))
|
|
416
|
+
from(input: unknown[], original) {
|
|
417
|
+
return input.map((i) => itemTransformation.from(i, original))
|
|
411
418
|
}
|
|
412
419
|
}
|
|
413
420
|
}
|