codify-plugin-lib 1.0.92 → 1.0.94

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,11 +32,18 @@ export class Plugin {
32
32
  throw new Error(`Cannot get info for resource ${data.type}, resource doesn't exist`);
33
33
  }
34
34
  const resource = this.resourceControllers.get(data.type);
35
+ const schema = resource.settings.schema;
36
+ const requiredPropertyNames = (resource.settings.import?.requiredParameters
37
+ ?? schema.required
38
+ ?? null);
35
39
  return {
36
40
  plugin: this.name,
37
41
  type: data.type,
38
42
  dependencies: resource.dependencies,
39
- schema: resource.settings.schema
43
+ schema: schema,
44
+ import: resource.settings.import ? {
45
+ requiredParameters: requiredPropertyNames,
46
+ } : undefined,
40
47
  };
41
48
  }
42
49
  async import(data) {
@@ -52,6 +52,9 @@ export interface ResourceSettings<T extends StringIndexedObject> {
52
52
  * @param desired
53
53
  */
54
54
  inputTransformation?: (desired: Partial<T>) => Promise<unknown> | unknown;
55
+ import?: {
56
+ requiredParameters: Array<Partial<keyof T>>;
57
+ };
55
58
  }
56
59
  /**
57
60
  * The type of parameter. This value is mainly used to determine a pre-set equality method for comparing the current
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "ajv": "^8.12.0",
16
16
  "ajv-formats": "^2.1.1",
17
- "codify-schemas": "1.0.51",
17
+ "codify-schemas": "1.0.52",
18
18
  "@npmcli/promise-spawn": "^7.0.1",
19
19
  "uuid": "^10.0.0"
20
20
  },
@@ -4,7 +4,9 @@ import {
4
4
  ApplyRequestDataSchema,
5
5
  ApplyResponseDataSchema,
6
6
  GetResourceInfoRequestDataSchema,
7
- GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema,
7
+ GetResourceInfoResponseDataSchema,
8
+ ImportRequestDataSchema,
9
+ ImportResponseDataSchema,
8
10
  InitializeRequestDataSchema,
9
11
  InitializeResponseDataSchema,
10
12
  IpcMessage,
@@ -1,3 +1,4 @@
1
+ import { JSONSchemaType } from 'ajv';
1
2
  import {
2
3
  ApplyRequestData,
3
4
  GetResourceInfoRequestData,
@@ -58,11 +59,21 @@ export class Plugin {
58
59
 
59
60
  const resource = this.resourceControllers.get(data.type)!;
60
61
 
62
+ const schema = resource.settings.schema as JSONSchemaType<any>;
63
+ const requiredPropertyNames = (
64
+ resource.settings.import?.requiredParameters
65
+ ?? schema.required
66
+ ?? null
67
+ ) as null | string[];
68
+
61
69
  return {
62
70
  plugin: this.name,
63
71
  type: data.type,
64
72
  dependencies: resource.dependencies,
65
- schema: resource.settings.schema as Record<string, unknown> | undefined
73
+ schema: schema as Record<string, unknown> | undefined,
74
+ import: resource.settings.import ? {
75
+ requiredParameters: requiredPropertyNames,
76
+ } : undefined,
66
77
  }
67
78
  }
68
79
 
@@ -214,7 +214,7 @@ export class ResourceController<T extends StringIndexedObject> {
214
214
  || currentParametersArray.filter(Boolean).length === 0
215
215
  ) {
216
216
  return currentParametersArray
217
- ?.map((r) => ({ ...coreParameters, ...r }))
217
+ ?.map((r) => ({ ...coreParameters, ...r }))
218
218
  ?? null;
219
219
  }
220
220
 
@@ -524,4 +524,20 @@ describe('Resource parameter tests', () => {
524
524
  expect(plan.currentConfig?.propB).to.eq(10);
525
525
  expect(plan.currentConfig?.propC).to.be.undefined;
526
526
  })
527
+
528
+ it('Allows import required parameters customization', () => {
529
+ const resource = new class extends TestResource {
530
+ getSettings(): ResourceSettings<TestConfig> {
531
+ return {
532
+ id: 'resourceType',
533
+ import: {
534
+ requiredParameters: [
535
+ 'propA',
536
+ 'propB',
537
+ ]
538
+ }
539
+ }
540
+ }
541
+ };
542
+ })
527
543
  })
@@ -64,6 +64,10 @@ export interface ResourceSettings<T extends StringIndexedObject> {
64
64
  * @param desired
65
65
  */
66
66
  inputTransformation?: (desired: Partial<T>) => Promise<unknown> | unknown;
67
+
68
+ import?: {
69
+ requiredParameters: Array<Partial<keyof T>>;
70
+ }
67
71
  }
68
72
 
69
73
  /**