codify-plugin-lib 1.0.158 → 1.0.160

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.
@@ -32,4 +32,5 @@ export declare class ResourceController<T extends StringIndexedObject> {
32
32
  private validatePlanInputs;
33
33
  private getSortedStatefulParameterChanges;
34
34
  private getAllParameterKeys;
35
+ private getParametersToRefreshForImport;
35
36
  }
@@ -193,22 +193,7 @@ export class ResourceController {
193
193
  this.addDefaultValues(parameters);
194
194
  await this.applyTransformParameters(parameters);
195
195
  // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
196
- const parametersToRefresh = this.settings.importAndDestroy?.refreshKeys
197
- ? {
198
- ...Object.fromEntries(this.settings.importAndDestroy?.refreshKeys.map((k) => [k, null])),
199
- ...this.settings.importAndDestroy?.defaultRefreshValues,
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]])))
206
- }
207
- : {
208
- ...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
209
- ...this.settings.importAndDestroy?.defaultRefreshValues,
210
- ...parameters,
211
- };
196
+ const parametersToRefresh = this.getParametersToRefreshForImport(parameters, context);
212
197
  // Parse data from the user supplied config
213
198
  const parsedConfig = new ConfigParser(parametersToRefresh, null, this.parsedSettings.statefulParameters);
214
199
  const { allParameters, allNonStatefulParameters, allStatefulParameters, } = parsedConfig;
@@ -373,4 +358,25 @@ ${JSON.stringify(refresh, null, 2)}
373
358
  ? Object.keys(this.settings.schema?.properties)
374
359
  : Object.keys(this.parsedSettings.parameterSettings);
375
360
  }
361
+ getParametersToRefreshForImport(parameters, context) {
362
+ if (this.settings.importAndDestroy?.refreshMapper) {
363
+ return this.settings.importAndDestroy?.refreshMapper(parameters, context);
364
+ }
365
+ return this.settings.importAndDestroy?.refreshKeys
366
+ ? {
367
+ ...Object.fromEntries(this.settings.importAndDestroy?.refreshKeys.map((k) => [k, null])),
368
+ ...this.settings.importAndDestroy?.defaultRefreshValues,
369
+ ...parameters,
370
+ ...(Object.fromEntries(// If a default value was used, but it was also declared in the defaultRefreshValues, prefer the defaultRefreshValue instead
371
+ Object.entries(parameters).filter(([k, v]) => this.parsedSettings.defaultValues[k] !== undefined
372
+ && v === this.parsedSettings.defaultValues[k]
373
+ && context.originalDesiredConfig?.[k] === undefined
374
+ && this.settings.importAndDestroy?.defaultRefreshValues?.[k] !== undefined).map(([k]) => [k, this.settings.importAndDestroy.defaultRefreshValues[k]])))
375
+ }
376
+ : {
377
+ ...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
378
+ ...this.settings.importAndDestroy?.defaultRefreshValues,
379
+ ...parameters,
380
+ };
381
+ }
376
382
  }
@@ -1,6 +1,7 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
2
  import { StringIndexedObject } from 'codify-schemas';
3
3
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
4
+ import { RefreshContext } from './resource.js';
4
5
  export interface InputTransformation {
5
6
  to: (input: any) => Promise<any> | any;
6
7
  from: (current: any, original: any) => Promise<any> | any;
@@ -122,6 +123,14 @@ export interface ResourceSettings<T extends StringIndexedObject> {
122
123
  * See {@link importAndDestroy} for more information on how importing works.
123
124
  */
124
125
  defaultRefreshValues?: Partial<T>;
126
+ /**
127
+ * A custom function that maps the input to what gets passed to refresh for imports. If this is set, then refreshKeys and
128
+ * defaultRefreshValues are ignored.
129
+ *
130
+ * @param input
131
+ * @param context
132
+ */
133
+ refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>;
125
134
  };
126
135
  }
127
136
  /**
@@ -58,7 +58,7 @@ const ParameterTransformationDefaults = {
58
58
  if (ParameterEqualsDefaults.directory(a, original)) {
59
59
  return original;
60
60
  }
61
- return addVariablesToPath(tildify(String(a)));
61
+ return tildify(addVariablesToPath(String(a)));
62
62
  },
63
63
  },
64
64
  'string': {
@@ -33,7 +33,7 @@ export function resolvePathWithVariables(pathWithVariables) {
33
33
  export function addVariablesToPath(pathWithoutVariables) {
34
34
  let result = pathWithoutVariables;
35
35
  for (const [key, value] of Object.entries(process.env)) {
36
- if (!value || !path.isAbsolute(value) || value === '/') {
36
+ if (!value || !path.isAbsolute(value) || value === '/' || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
37
37
  continue;
38
38
  }
39
39
  result = result.replaceAll(value, `$${key}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.158",
3
+ "version": "1.0.160",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -274,29 +274,7 @@ export class ResourceController<T extends StringIndexedObject> {
274
274
  await this.applyTransformParameters(parameters);
275
275
 
276
276
  // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
277
- const parametersToRefresh = this.settings.importAndDestroy?.refreshKeys
278
- ? {
279
- ...Object.fromEntries(
280
- this.settings.importAndDestroy?.refreshKeys.map((k) => [k, null])
281
- ),
282
- ...this.settings.importAndDestroy?.defaultRefreshValues,
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
- ))
292
- }
293
- : {
294
- ...Object.fromEntries(
295
- this.getAllParameterKeys().map((k) => [k, null])
296
- ),
297
- ...this.settings.importAndDestroy?.defaultRefreshValues,
298
- ...parameters,
299
- };
277
+ const parametersToRefresh = this.getParametersToRefreshForImport(parameters, context);
300
278
 
301
279
  // Parse data from the user supplied config
302
280
  const parsedConfig = new ConfigParser(parametersToRefresh, null, this.parsedSettings.statefulParameters)
@@ -325,6 +303,8 @@ export class ResourceController<T extends StringIndexedObject> {
325
303
  }
326
304
 
327
305
  return resultParametersArray?.map((r) => ({ core, parameters: r }))
306
+
307
+
328
308
  }
329
309
 
330
310
  private async applyCreate(plan: Plan<T>): Promise<void> {
@@ -523,5 +503,35 @@ ${JSON.stringify(refresh, null, 2)}
523
503
  ? Object.keys((this.settings.schema as any)?.properties)
524
504
  : Object.keys(this.parsedSettings.parameterSettings);
525
505
  }
506
+
507
+ private getParametersToRefreshForImport(parameters: Partial<T>, context: RefreshContext<T>): Partial<T> {
508
+ if (this.settings.importAndDestroy?.refreshMapper) {
509
+ return this.settings.importAndDestroy?.refreshMapper(parameters, context);
510
+ }
511
+
512
+ return this.settings.importAndDestroy?.refreshKeys
513
+ ? {
514
+ ...Object.fromEntries(
515
+ this.settings.importAndDestroy?.refreshKeys.map((k) => [k, null])
516
+ ),
517
+ ...this.settings.importAndDestroy?.defaultRefreshValues,
518
+ ...parameters,
519
+ ...(Object.fromEntries( // If a default value was used, but it was also declared in the defaultRefreshValues, prefer the defaultRefreshValue instead
520
+ Object.entries(parameters).filter(([k, v]) =>
521
+ this.parsedSettings.defaultValues[k] !== undefined
522
+ && v === this.parsedSettings.defaultValues[k]
523
+ && context.originalDesiredConfig?.[k] === undefined
524
+ && this.settings.importAndDestroy?.defaultRefreshValues?.[k] !== undefined
525
+ ).map(([k]) => [k, this.settings.importAndDestroy!.defaultRefreshValues![k]])
526
+ ))
527
+ }
528
+ : {
529
+ ...Object.fromEntries(
530
+ this.getAllParameterKeys().map((k) => [k, null])
531
+ ),
532
+ ...this.settings.importAndDestroy?.defaultRefreshValues,
533
+ ...parameters,
534
+ };
535
+ }
526
536
  }
527
537
 
@@ -6,6 +6,7 @@ import path from 'node:path';
6
6
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
7
7
  import { addVariablesToPath, areArraysEqual, resolvePathWithVariables, tildify, untildify } from '../utils/utils.js';
8
8
  import { or } from 'ajv/dist/compile/codegen/index.js';
9
+ import { RefreshContext } from './resource.js';
9
10
 
10
11
  export interface InputTransformation {
11
12
  to: (input: any) => Promise<any> | any;
@@ -142,6 +143,15 @@ export interface ResourceSettings<T extends StringIndexedObject> {
142
143
  * See {@link importAndDestroy} for more information on how importing works.
143
144
  */
144
145
  defaultRefreshValues?: Partial<T>;
146
+
147
+ /**
148
+ * A custom function that maps the input to what gets passed to refresh for imports. If this is set, then refreshKeys and
149
+ * defaultRefreshValues are ignored.
150
+ *
151
+ * @param input
152
+ * @param context
153
+ */
154
+ refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>
145
155
  }
146
156
  }
147
157
 
@@ -375,7 +385,7 @@ const ParameterTransformationDefaults: Partial<Record<ParameterSettingType, Inpu
375
385
  return original;
376
386
  }
377
387
 
378
- return addVariablesToPath(tildify(String(a)))
388
+ return tildify(addVariablesToPath(String(a)))
379
389
  },
380
390
  },
381
391
  'string': {
@@ -46,7 +46,7 @@ export function resolvePathWithVariables(pathWithVariables: string) {
46
46
  export function addVariablesToPath(pathWithoutVariables: string) {
47
47
  let result = pathWithoutVariables;
48
48
  for (const [key, value] of Object.entries(process.env)) {
49
- if (!value || !path.isAbsolute(value) || value === '/') {
49
+ if (!value || !path.isAbsolute(value) || value === '/' || key === 'HOME' || key === 'PATH' || key === 'SHELL' || key === 'PWD') {
50
50
  continue;
51
51
  }
52
52