codify-plugin-lib 1.0.88 → 1.0.90
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/handlers.js +19 -14
- package/dist/plugin/plugin.d.ts +2 -1
- package/dist/plugin/plugin.js +12 -0
- package/package.json +2 -2
- package/src/messages/handlers.ts +20 -13
- package/src/plugin/plugin.ts +17 -0
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
2
|
import addFormats from 'ajv-formats';
|
|
3
|
-
import { ApplyRequestDataSchema, ApplyResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
|
|
3
|
+
import { ApplyRequestDataSchema, ApplyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
|
|
4
4
|
import { SudoError } from '../errors.js';
|
|
5
5
|
const SupportedRequests = {
|
|
6
|
-
'apply': {
|
|
7
|
-
async handler(plugin, data) {
|
|
8
|
-
await plugin.apply(data);
|
|
9
|
-
return null;
|
|
10
|
-
},
|
|
11
|
-
requestValidator: ApplyRequestDataSchema,
|
|
12
|
-
responseValidator: ApplyResponseDataSchema
|
|
13
|
-
},
|
|
14
6
|
'initialize': {
|
|
15
7
|
handler: async (plugin) => plugin.initialize(),
|
|
16
8
|
requestValidator: InitializeRequestDataSchema,
|
|
17
9
|
responseValidator: InitializeResponseDataSchema
|
|
18
10
|
},
|
|
11
|
+
'validate': {
|
|
12
|
+
handler: async (plugin, data) => plugin.validate(data),
|
|
13
|
+
requestValidator: ValidateRequestDataSchema,
|
|
14
|
+
responseValidator: ValidateResponseDataSchema
|
|
15
|
+
},
|
|
16
|
+
'getResourceInfo': {
|
|
17
|
+
handler: async (plugin, data) => plugin.getResourceInfo(data),
|
|
18
|
+
requestValidator: GetResourceInfoRequestDataSchema,
|
|
19
|
+
responseValidator: GetResourceInfoResponseDataSchema
|
|
20
|
+
},
|
|
19
21
|
'plan': {
|
|
20
22
|
handler: async (plugin, data) => plugin.plan(data),
|
|
21
23
|
requestValidator: PlanRequestDataSchema,
|
|
22
24
|
responseValidator: PlanResponseDataSchema
|
|
23
25
|
},
|
|
24
|
-
'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
'apply': {
|
|
27
|
+
async handler(plugin, data) {
|
|
28
|
+
await plugin.apply(data);
|
|
29
|
+
return null;
|
|
30
|
+
},
|
|
31
|
+
requestValidator: ApplyRequestDataSchema,
|
|
32
|
+
responseValidator: ApplyResponseDataSchema
|
|
33
|
+
},
|
|
29
34
|
};
|
|
30
35
|
export class MessageHandler {
|
|
31
36
|
ajv;
|
package/dist/plugin/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplyRequestData, InitializeResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
1
|
+
import { ApplyRequestData, GetResourceInfoRequestData, GetResourceInfoResponseData, InitializeResponseData, PlanRequestData, PlanResponseData, ResourceConfig, ValidateRequestData, ValidateResponseData } from 'codify-schemas';
|
|
2
2
|
import { Plan } from '../plan/plan.js';
|
|
3
3
|
import { Resource } from '../resource/resource.js';
|
|
4
4
|
import { ResourceController } from '../resource/resource-controller.js';
|
|
@@ -9,6 +9,7 @@ export declare class Plugin {
|
|
|
9
9
|
constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
|
|
10
10
|
static create(name: string, resources: Resource<any>[]): Plugin;
|
|
11
11
|
initialize(): Promise<InitializeResponseData>;
|
|
12
|
+
getResourceInfo(data: GetResourceInfoRequestData): Promise<GetResourceInfoResponseData>;
|
|
12
13
|
validate(data: ValidateRequestData): Promise<ValidateResponseData>;
|
|
13
14
|
plan(data: PlanRequestData): Promise<PlanResponseData>;
|
|
14
15
|
apply(data: ApplyRequestData): Promise<void>;
|
package/dist/plugin/plugin.js
CHANGED
|
@@ -27,6 +27,18 @@ export class Plugin {
|
|
|
27
27
|
}))
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
async getResourceInfo(data) {
|
|
31
|
+
if (!this.resourceControllers.has(data.type)) {
|
|
32
|
+
throw new Error(`Cannot get info for resource ${data.type}, resource doesn't exist`);
|
|
33
|
+
}
|
|
34
|
+
const resource = this.resourceControllers.get(data.type);
|
|
35
|
+
return {
|
|
36
|
+
plugin: this.name,
|
|
37
|
+
type: data.type,
|
|
38
|
+
dependencies: resource.dependencies,
|
|
39
|
+
schema: resource.settings.schema
|
|
40
|
+
};
|
|
41
|
+
}
|
|
30
42
|
async validate(data) {
|
|
31
43
|
const validationResults = [];
|
|
32
44
|
for (const config of data.configs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codify-plugin-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.90",
|
|
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.
|
|
17
|
+
"codify-schemas": "1.0.48",
|
|
18
18
|
"@npmcli/promise-spawn": "^7.0.1",
|
|
19
19
|
"uuid": "^10.0.0"
|
|
20
20
|
},
|
package/src/messages/handlers.ts
CHANGED
|
@@ -3,6 +3,8 @@ import addFormats from 'ajv-formats';
|
|
|
3
3
|
import {
|
|
4
4
|
ApplyRequestDataSchema,
|
|
5
5
|
ApplyResponseDataSchema,
|
|
6
|
+
GetResourceInfoRequestDataSchema,
|
|
7
|
+
GetResourceInfoResponseDataSchema,
|
|
6
8
|
InitializeRequestDataSchema,
|
|
7
9
|
InitializeResponseDataSchema,
|
|
8
10
|
IpcMessage,
|
|
@@ -19,29 +21,34 @@ import { SudoError } from '../errors.js';
|
|
|
19
21
|
import { Plugin } from '../plugin/plugin.js';
|
|
20
22
|
|
|
21
23
|
const SupportedRequests: Record<string, { handler: (plugin: Plugin, data: any) => Promise<unknown>; requestValidator: SchemaObject; responseValidator: SchemaObject }> = {
|
|
22
|
-
'apply': {
|
|
23
|
-
async handler(plugin: Plugin, data: any) {
|
|
24
|
-
await plugin.apply(data);
|
|
25
|
-
return null;
|
|
26
|
-
},
|
|
27
|
-
requestValidator: ApplyRequestDataSchema,
|
|
28
|
-
responseValidator: ApplyResponseDataSchema
|
|
29
|
-
},
|
|
30
24
|
'initialize': {
|
|
31
25
|
handler: async (plugin: Plugin) => plugin.initialize(),
|
|
32
26
|
requestValidator: InitializeRequestDataSchema,
|
|
33
27
|
responseValidator: InitializeResponseDataSchema
|
|
34
28
|
},
|
|
29
|
+
'validate': {
|
|
30
|
+
handler: async (plugin: Plugin, data: any) => plugin.validate(data),
|
|
31
|
+
requestValidator: ValidateRequestDataSchema,
|
|
32
|
+
responseValidator: ValidateResponseDataSchema
|
|
33
|
+
},
|
|
34
|
+
'getResourceInfo': {
|
|
35
|
+
handler: async (plugin: Plugin, data: any) => plugin.getResourceInfo(data),
|
|
36
|
+
requestValidator: GetResourceInfoRequestDataSchema,
|
|
37
|
+
responseValidator: GetResourceInfoResponseDataSchema
|
|
38
|
+
},
|
|
35
39
|
'plan': {
|
|
36
40
|
handler: async (plugin: Plugin, data: any) => plugin.plan(data),
|
|
37
41
|
requestValidator: PlanRequestDataSchema,
|
|
38
42
|
responseValidator: PlanResponseDataSchema
|
|
39
43
|
},
|
|
40
|
-
'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
'apply': {
|
|
45
|
+
async handler(plugin: Plugin, data: any) {
|
|
46
|
+
await plugin.apply(data);
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
requestValidator: ApplyRequestDataSchema,
|
|
50
|
+
responseValidator: ApplyResponseDataSchema
|
|
51
|
+
},
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
export class MessageHandler {
|
package/src/plugin/plugin.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ApplyRequestData,
|
|
3
|
+
GetResourceInfoRequestData,
|
|
4
|
+
GetResourceInfoResponseData,
|
|
3
5
|
InitializeResponseData,
|
|
4
6
|
PlanRequestData,
|
|
5
7
|
PlanResponseData,
|
|
@@ -47,6 +49,21 @@ export class Plugin {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
async getResourceInfo(data: GetResourceInfoRequestData): Promise<GetResourceInfoResponseData> {
|
|
53
|
+
if (!this.resourceControllers.has(data.type)) {
|
|
54
|
+
throw new Error(`Cannot get info for resource ${data.type}, resource doesn't exist`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const resource = this.resourceControllers.get(data.type)!;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
plugin: this.name,
|
|
61
|
+
type: data.type,
|
|
62
|
+
dependencies: resource.dependencies,
|
|
63
|
+
schema: resource.settings.schema as Record<string, unknown> | undefined
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
async validate(data: ValidateRequestData): Promise<ValidateResponseData> {
|
|
51
68
|
const validationResults = [];
|
|
52
69
|
for (const config of data.configs) {
|