codify-plugin-lib 1.0.96 → 1.0.98

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.
@@ -115,6 +115,11 @@ export class ParsedResourceSettings {
115
115
  'determine the prompt to ask users during imports. It can\'t parse which parameters are needed when ' +
116
116
  'required is declared conditionally.');
117
117
  }
118
+ const importRequiredParameterNotInSchema = this.settings.import?.requiredParameters?.filter((p) => !(schema?.properties[p]));
119
+ if (schema && importRequiredParameterNotInSchema && importRequiredParameterNotInSchema.length > 0) {
120
+ throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
121
+ ${JSON.stringify(importRequiredParameterNotInSchema, null, 2)}`);
122
+ }
118
123
  }
119
124
  validateParameterEqualsFn(parameter, key) {
120
125
  if (parameter.type === 'stateful') {
@@ -133,11 +133,16 @@ export class ResourceController {
133
133
  async import(config) {
134
134
  this.addDefaultValues(config);
135
135
  await this.applyTransformParameters(config);
136
- // Try to refresh as many parameters as possible here
137
- const parametersToRefresh = {
138
- ...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
139
- ...config,
140
- };
136
+ // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
137
+ const parametersToRefresh = this.settings.import?.refreshParameters
138
+ ? {
139
+ ...Object.fromEntries(this.settings.import?.refreshParameters.map((k) => [k, null])),
140
+ ...config,
141
+ }
142
+ : {
143
+ ...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
144
+ ...config,
145
+ };
141
146
  // Parse data from the user supplied config
142
147
  const parsedConfig = new ConfigParser(parametersToRefresh, null, this.parsedSettings.statefulParameters);
143
148
  const { allNonStatefulParameters, allStatefulParameters, coreParameters, } = parsedConfig;
@@ -53,7 +53,8 @@ export interface ResourceSettings<T extends StringIndexedObject> {
53
53
  */
54
54
  inputTransformation?: (desired: Partial<T>) => Promise<unknown> | unknown;
55
55
  import?: {
56
- requiredParameters: Array<Partial<keyof T>>;
56
+ requiredParameters?: Array<Partial<keyof T>>;
57
+ refreshParameters?: Array<Partial<keyof T>>;
57
58
  };
58
59
  }
59
60
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -65,4 +65,30 @@ describe('Resource options parser tests', () => {
65
65
 
66
66
  expect(() => new ParsedResourceSettings(option)).throws;
67
67
  })
68
+
69
+ it('Throws an error when an import.requiredParameters is declared improperly', () => {
70
+ const schema = {
71
+ '$schema': 'http://json-schema.org/draft-07/schema',
72
+ '$id': 'https://www.codifycli.com/git-clone.json',
73
+ 'title': 'Git-clone resource',
74
+ 'type': 'object',
75
+ 'properties': {
76
+ 'remote': {
77
+ 'type': 'string',
78
+ 'description': 'Remote tracking url to clone repo from. Equivalent to repository and only one should be specified'
79
+ },
80
+ },
81
+ 'additionalProperties': false,
82
+ }
83
+
84
+ const option: ResourceSettings<TestConfig> = {
85
+ id: 'typeId',
86
+ schema,
87
+ import: {
88
+ requiredParameters: ['import-error']
89
+ }
90
+ }
91
+
92
+ expect(() => new ParsedResourceSettings(option)).throws;
93
+ })
68
94
  })
@@ -3,10 +3,10 @@ import { StringIndexedObject } from 'codify-schemas';
3
3
 
4
4
  import {
5
5
  ParameterSetting,
6
- ResourceSettings,
7
- StatefulParameterSetting,
8
6
  resolveEqualsFn,
9
- resolveParameterTransformFn
7
+ resolveParameterTransformFn,
8
+ ResourceSettings,
9
+ StatefulParameterSetting
10
10
  } from './resource-settings.js';
11
11
  import { StatefulParameter as StatefulParameterImpl } from './stateful-parameter.js'
12
12
 
@@ -138,7 +138,6 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
138
138
  throw new Error(`Resource: ${this.id}. Stateful parameters are not allowed if multiples of a resource exist`)
139
139
  }
140
140
 
141
-
142
141
  const schema = this.settings.schema as JSONSchemaType<any>;
143
142
  if (!this.settings.import && (schema?.oneOf
144
143
  && Array.isArray(schema.oneOf)
@@ -167,6 +166,13 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
167
166
  'required is declared conditionally.'
168
167
  )
169
168
  }
169
+
170
+ const importRequiredParameterNotInSchema =
171
+ this.settings.import?.requiredParameters?.filter((p) => !(schema?.properties[p]))
172
+ if (schema && importRequiredParameterNotInSchema && importRequiredParameterNotInSchema.length > 0) {
173
+ throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
174
+ ${JSON.stringify(importRequiredParameterNotInSchema, null, 2)}`)
175
+ }
170
176
  }
171
177
 
172
178
  private validateParameterEqualsFn(parameter: ParameterSetting, key: string): void {
@@ -189,8 +189,15 @@ export class ResourceController<T extends StringIndexedObject> {
189
189
  this.addDefaultValues(config);
190
190
  await this.applyTransformParameters(config);
191
191
 
192
- // Try to refresh as many parameters as possible here
193
- const parametersToRefresh = {
192
+ // Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
193
+ const parametersToRefresh = this.settings.import?.refreshParameters
194
+ ? {
195
+ ...Object.fromEntries(
196
+ this.settings.import?.refreshParameters.map((k) => [k, null])
197
+ ),
198
+ ...config,
199
+ }
200
+ : {
194
201
  ...Object.fromEntries(
195
202
  this.getAllParameterKeys().map((k) => [k, null])
196
203
  ),
@@ -66,7 +66,9 @@ export interface ResourceSettings<T extends StringIndexedObject> {
66
66
  inputTransformation?: (desired: Partial<T>) => Promise<unknown> | unknown;
67
67
 
68
68
  import?: {
69
- requiredParameters: Array<Partial<keyof T>>;
69
+ requiredParameters?: Array<Partial<keyof T>>;
70
+
71
+ refreshParameters?: Array<Partial<keyof T>>;
70
72
  }
71
73
  }
72
74