codify-schemas 1.0.28 → 1.0.29
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/messages/apply-request-data-schema.json +57 -2
- package/dist/types/index.d.ts +12 -1
- package/package.json +3 -2
- package/src/messages/apply-request-data-schema.json +57 -2
- package/src/messages/apply-request-data-schema.test.ts +41 -0
- package/src/messages/plan-response-data-schema.test.ts +42 -0
- package/src/types/index.ts +12 -1
|
@@ -6,11 +6,66 @@
|
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"planId": {
|
|
9
|
-
"description": "The plan uuid. This id is used to look up the generated plan on the plugin side",
|
|
9
|
+
"description": "The plan uuid. This id is used to look up the generated plan on the plugin side.",
|
|
10
10
|
"type": "string",
|
|
11
11
|
"format": "uuid"
|
|
12
|
+
},
|
|
13
|
+
"plan": {
|
|
14
|
+
"description": "Alternatively, the client can supply a complete plan instead of a planId",
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"operation": {
|
|
18
|
+
"description": "The plan operation",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"enum": ["create", "destroy", "modify", "recreate", "noop"]
|
|
21
|
+
},
|
|
22
|
+
"resourceType": {
|
|
23
|
+
"description": "The resource type",
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"resourceName": {
|
|
27
|
+
"description": "The resource name",
|
|
28
|
+
"type": ["string", "null"]
|
|
29
|
+
},
|
|
30
|
+
"parameters": {
|
|
31
|
+
"description": "The properties come from the provided config and is not necessarily every parameter on the ",
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"properties": {
|
|
36
|
+
"name": {
|
|
37
|
+
"description": "The property name",
|
|
38
|
+
"type": "string"
|
|
39
|
+
},
|
|
40
|
+
"operation": {
|
|
41
|
+
"description": "The operation to be performed on the parameter",
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": [
|
|
44
|
+
"remove",
|
|
45
|
+
"add",
|
|
46
|
+
"modify",
|
|
47
|
+
"noop"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"previousValue": {
|
|
51
|
+
"description": "The value before the change"
|
|
52
|
+
},
|
|
53
|
+
"newValue": {
|
|
54
|
+
"description": "The new value"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"required": [
|
|
58
|
+
"name",
|
|
59
|
+
"operation",
|
|
60
|
+
"previousValue",
|
|
61
|
+
"newValue"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"required": ["operation", "resourceType", "parameters"]
|
|
12
67
|
}
|
|
13
68
|
},
|
|
14
|
-
"required": [
|
|
69
|
+
"required": [],
|
|
15
70
|
"additionalProperties": false
|
|
16
71
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -54,7 +54,18 @@ export interface PlanResponseData {
|
|
|
54
54
|
}>;
|
|
55
55
|
}
|
|
56
56
|
export interface ApplyRequestData {
|
|
57
|
-
planId
|
|
57
|
+
planId?: string;
|
|
58
|
+
plan?: {
|
|
59
|
+
operation: ResourceOperation;
|
|
60
|
+
resourceName?: string;
|
|
61
|
+
resourceType: string;
|
|
62
|
+
parameters: Array<{
|
|
63
|
+
name: string;
|
|
64
|
+
operation: ParameterOperation;
|
|
65
|
+
previousValue: unknown | null;
|
|
66
|
+
newValue: unknown | null;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
58
69
|
}
|
|
59
70
|
export interface ResourceDefinition {
|
|
60
71
|
type: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-schemas",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"vitest": "^1.4.0",
|
|
20
|
-
"typescript": "^5.3.3"
|
|
20
|
+
"typescript": "^5.3.3",
|
|
21
|
+
"ajv-formats": "^3.0.1"
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -6,11 +6,66 @@
|
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"planId": {
|
|
9
|
-
"description": "The plan uuid. This id is used to look up the generated plan on the plugin side",
|
|
9
|
+
"description": "The plan uuid. This id is used to look up the generated plan on the plugin side.",
|
|
10
10
|
"type": "string",
|
|
11
11
|
"format": "uuid"
|
|
12
|
+
},
|
|
13
|
+
"plan": {
|
|
14
|
+
"description": "Alternatively, the client can supply a complete plan instead of a planId",
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"operation": {
|
|
18
|
+
"description": "The plan operation",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"enum" : ["create", "destroy", "modify", "recreate", "noop"]
|
|
21
|
+
},
|
|
22
|
+
"resourceType": {
|
|
23
|
+
"description": "The resource type",
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"resourceName": {
|
|
27
|
+
"description": "The resource name",
|
|
28
|
+
"type": ["string", "null"]
|
|
29
|
+
},
|
|
30
|
+
"parameters": {
|
|
31
|
+
"description": "The properties come from the provided config and is not necessarily every parameter on the ",
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"properties": {
|
|
36
|
+
"name": {
|
|
37
|
+
"description": "The property name",
|
|
38
|
+
"type": "string"
|
|
39
|
+
},
|
|
40
|
+
"operation": {
|
|
41
|
+
"description": "The operation to be performed on the parameter",
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": [
|
|
44
|
+
"remove",
|
|
45
|
+
"add",
|
|
46
|
+
"modify",
|
|
47
|
+
"noop"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"previousValue": {
|
|
51
|
+
"description": "The value before the change"
|
|
52
|
+
},
|
|
53
|
+
"newValue": {
|
|
54
|
+
"description": "The new value"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"required": [
|
|
58
|
+
"name",
|
|
59
|
+
"operation",
|
|
60
|
+
"previousValue",
|
|
61
|
+
"newValue"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"required": ["operation", "resourceType", "parameters"]
|
|
12
67
|
}
|
|
13
68
|
},
|
|
14
|
-
"required": [
|
|
69
|
+
"required": [],
|
|
15
70
|
"additionalProperties": false
|
|
16
71
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import schema from './apply-request-data-schema.json';
|
|
2
|
+
import resourceSchema from '../resource-schema.json'
|
|
3
|
+
import {describe, expect, it} from 'vitest'
|
|
4
|
+
import Ajv2020 from 'ajv/dist/2020.js'
|
|
5
|
+
import addFormats from 'ajv-formats';
|
|
6
|
+
import {ApplyRequestData, ParameterOperation, ResourceOperation} from "../types/index.js";
|
|
7
|
+
|
|
8
|
+
const ajv = new Ajv2020.default({
|
|
9
|
+
strict: true,
|
|
10
|
+
})
|
|
11
|
+
addFormats.default(ajv);
|
|
12
|
+
ajv.addSchema(resourceSchema);
|
|
13
|
+
|
|
14
|
+
describe('Apply request data schema', () => {
|
|
15
|
+
it('compiles', () => {
|
|
16
|
+
ajv.compile(schema);
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("validates correct config (planId)", () => {
|
|
20
|
+
const validate = ajv.compile(schema);
|
|
21
|
+
expect(validate({
|
|
22
|
+
planId: 'eb367e53-21a8-4c9e-a38b-c99e7c821344',
|
|
23
|
+
} as ApplyRequestData)).to.be.true;
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("validates correct config (plan)", () => {
|
|
27
|
+
const validate = ajv.compile(schema);
|
|
28
|
+
expect(validate({
|
|
29
|
+
plan: {
|
|
30
|
+
operation: ResourceOperation.CREATE,
|
|
31
|
+
resourceType: 'type1',
|
|
32
|
+
parameters: [{
|
|
33
|
+
name: 'parameter1',
|
|
34
|
+
operation: ParameterOperation.ADD,
|
|
35
|
+
previousValue: null,
|
|
36
|
+
newValue: 'abc'
|
|
37
|
+
}]
|
|
38
|
+
}
|
|
39
|
+
} as ApplyRequestData)).to.be.true;
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import schema from './plan-response-data-schema.json';
|
|
2
|
+
import resourceSchema from '../resource-schema.json'
|
|
3
|
+
import {describe, expect, it} from 'vitest'
|
|
4
|
+
import Ajv2020 from 'ajv/dist/2020.js'
|
|
5
|
+
import addFormats from 'ajv-formats';
|
|
6
|
+
import {ParameterOperation, PlanResponseData, ResourceOperation} from "../types/index.js";
|
|
7
|
+
|
|
8
|
+
const ajv = new Ajv2020.default({
|
|
9
|
+
strict: true,
|
|
10
|
+
})
|
|
11
|
+
addFormats.default(ajv);
|
|
12
|
+
ajv.addSchema(resourceSchema);
|
|
13
|
+
|
|
14
|
+
describe('Plan response data schema', () => {
|
|
15
|
+
it('compiles', () => {
|
|
16
|
+
ajv.compile(schema);
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("validates correct config", () => {
|
|
20
|
+
const validate = ajv.compile(schema);
|
|
21
|
+
expect(validate({
|
|
22
|
+
planId: 'eb367e53-21a8-4c9e-a38b-c99e7c821344',
|
|
23
|
+
operation: ResourceOperation.CREATE,
|
|
24
|
+
resourceType: 'type1',
|
|
25
|
+
parameters: [{
|
|
26
|
+
name: 'parameter1',
|
|
27
|
+
operation: ParameterOperation.ADD,
|
|
28
|
+
previousValue: null,
|
|
29
|
+
newValue: 'abc'
|
|
30
|
+
}]
|
|
31
|
+
} as PlanResponseData)).to.be.true;
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it ("validates incorrect config", () => {
|
|
35
|
+
const validate = ajv.compile(schema);
|
|
36
|
+
expect(validate({
|
|
37
|
+
planId: 'eb367e53-21a8-4c9e-a38b-c99e7c821344',
|
|
38
|
+
parameters: []
|
|
39
|
+
})).to.be.false;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
})
|
package/src/types/index.ts
CHANGED
|
@@ -64,7 +64,18 @@ export interface PlanResponseData {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface ApplyRequestData {
|
|
67
|
-
planId
|
|
67
|
+
planId?: string;
|
|
68
|
+
plan?: {
|
|
69
|
+
operation: ResourceOperation;
|
|
70
|
+
resourceName?: string;
|
|
71
|
+
resourceType: string;
|
|
72
|
+
parameters: Array<{
|
|
73
|
+
name: string;
|
|
74
|
+
operation: ParameterOperation;
|
|
75
|
+
previousValue: unknown | null;
|
|
76
|
+
newValue: unknown | null;
|
|
77
|
+
}>
|
|
78
|
+
}
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
export interface ResourceDefinition {
|