Skip to content

Commit cdd9aa3

Browse files
committed
Updated codify schemas version to the latest (json schema draft07) and fixed tests
1 parent de7fdb9 commit cdd9aa3

5 files changed

Lines changed: 36 additions & 32 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.75",
3+
"version": "1.0.76",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"ajv": "^8.12.0",
1616
"ajv-formats": "^2.1.1",
17-
"codify-schemas": "1.0.44",
17+
"codify-schemas": "1.0.45",
1818
"@npmcli/promise-spawn": "^7.0.1"
1919
},
2020
"devDependencies": {

src/entities/resource-options.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import { StringIndexedObject } from 'codify-schemas';
2+
3+
import { ParameterOptions } from './plan-types.js';
4+
import { ResourceParameterOptions } from './resource-types.js';
25
import { StatefulParameter } from './stateful-parameter.js';
36
import { TransformParameter } from './transform-parameter.js';
4-
import { ResourceParameterOptions } from './resource-types.js';
5-
import { ParameterOptions } from './plan-types.js';
67

78
export interface ResourceOptions<T extends StringIndexedObject> {
89

9-
/**
10-
* The id of the resource.
11-
*/
12-
type: string;
13-
14-
/**
15-
* Schema to validate user configs with. Must be in the format JSON Schema 2020-12
16-
*/
17-
schema?: unknown
18-
1910
/**
2011
* If true, statefulParameter.applyRemove() will be called before resource destruction.
2112
* Defaults to false.
@@ -36,16 +27,26 @@ export interface ResourceOptions<T extends StringIndexedObject> {
3627
| ResourceStatefulParameterOptions<T>
3728
| ResourceTransformParameterOptions<T>
3829
>>
30+
31+
/**
32+
* Schema to validate user configs with. Must be in the format JSON Schema draft07
33+
*/
34+
schema?: unknown
35+
36+
/**
37+
* The id of the resource.
38+
*/
39+
type: string;
3940
}
4041

4142
export interface ResourceStatefulParameterOptions<T extends StringIndexedObject> {
42-
statefulParameter: StatefulParameter<T, T[keyof T]>;
4343
order?: number;
44+
statefulParameter: StatefulParameter<T, T[keyof T]>;
4445
}
4546

4647
export interface ResourceTransformParameterOptions<T extends StringIndexedObject> {
47-
transformParameter: TransformParameter<T>;
4848
order?: number;
49+
transformParameter: TransformParameter<T>;
4950
}
5051

5152
export class ResourceOptionsParser<T extends StringIndexedObject> {
@@ -90,15 +91,13 @@ export class ResourceOptionsParser<T extends StringIndexedObject> {
9091
);
9192

9293
const statefulParameters = [...this.statefulParameters.entries()]
93-
?.reduce((obj, sp) => {
94-
return {
94+
?.reduce((obj, sp) => ({
9595
...obj,
9696
[sp[0]]: {
9797
...sp[1].options,
9898
isStatefulParameter: true,
9999
}
100-
}
101-
}, {} as Record<keyof T, ParameterOptions>)
100+
}), {} as Record<keyof T, ParameterOptions>)
102101

103102
return {
104103
...resourceParameters,

src/entities/resource.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import Ajv from 'ajv';
2-
import Ajv2020, { ValidateFunction } from 'ajv/dist/2020.js';
1+
import { Ajv, ValidateFunction } from 'ajv';
32
import {
43
ParameterOperation,
54
ResourceConfig,
@@ -38,7 +37,7 @@ export abstract class Resource<T extends StringIndexedObject> {
3837
readonly options: ResourceOptions<T>;
3938
readonly defaultValues: Partial<Record<keyof T, unknown>>;
4039

41-
protected ajv?: Ajv.default;
40+
protected ajv?: Ajv;
4241
protected schemaValidator?: ValidateFunction;
4342

4443
protected constructor(options: ResourceOptions<T>) {
@@ -47,7 +46,7 @@ export abstract class Resource<T extends StringIndexedObject> {
4746
this.options = options;
4847

4948
if (this.options.schema) {
50-
this.ajv = new Ajv2020.default({
49+
this.ajv = new Ajv({
5150
allErrors: true,
5251
strict: true,
5352
strictRequired: false,

src/messages/handlers.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ describe('Message handler tests', () => {
2525
await handler.onMessage({
2626
cmd: 'plan',
2727
data: {
28-
type: 'resourceType',
29-
name: 'name',
30-
prop1: 'A',
31-
prop2: 'B',
28+
desired: {
29+
type: 'resourceType',
30+
name: 'name',
31+
prop1: 'A',
32+
prop2: 'B',
33+
},
34+
isStateful: false,
3235
}
3336
})
3437
} catch (e) {}
@@ -165,7 +168,10 @@ describe('Message handler tests', () => {
165168
expect(async () => await handler.onMessage({
166169
cmd: 'plan',
167170
data: {
168-
type: 'resourceA'
171+
desired: {
172+
type: 'resourceA'
173+
},
174+
isStateful: false,
169175
}
170176
})).rejects.to.not.throw;
171177

src/messages/handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ajv2020, { SchemaObject, ValidateFunction } from 'ajv/dist/2020.js';
1+
import { Ajv, SchemaObject, ValidateFunction } from 'ajv';
22
import addFormats from 'ajv-formats';
33
import {
44
ApplyRequestDataSchema,
@@ -45,14 +45,14 @@ const SupportedRequests: Record<string, { handler: (plugin: Plugin, data: any) =
4545
}
4646

4747
export class MessageHandler {
48-
private ajv: Ajv2020.default;
48+
private ajv: Ajv;
4949
private readonly plugin: Plugin;
5050
private messageSchemaValidator: ValidateFunction;
5151
private requestValidators: Map<string, ValidateFunction>;
5252
private responseValidators: Map<string, ValidateFunction>;
5353

5454
constructor(plugin: Plugin) {
55-
this.ajv = new Ajv2020.default({ strict: true, strictRequired: false });
55+
this.ajv = new Ajv({ strict: true, strictRequired: false });
5656
addFormats.default(this.ajv);
5757
this.ajv.addSchema(ResourceSchema);
5858
this.plugin = plugin;

0 commit comments

Comments
 (0)