@codifycli/plugin-core 1.0.0-beta6 → 1.0.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z, ZodObject } from 'zod';
|
|
2
2
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
3
3
|
import { resolveElementEqualsFn, resolveEqualsFn, resolveMatcher, resolveParameterTransformFn } from './resource-settings.js';
|
|
4
4
|
export class ParsedResourceSettings {
|
|
@@ -23,8 +23,11 @@ export class ParsedResourceSettings {
|
|
|
23
23
|
? z.toJSONSchema(schema.strict(), {
|
|
24
24
|
target: 'draft-7',
|
|
25
25
|
override(ctx) {
|
|
26
|
-
ctx.
|
|
27
|
-
|
|
26
|
+
if (ctx.path.length === 0) {
|
|
27
|
+
ctx.jsonSchema.title = settings.id;
|
|
28
|
+
ctx.jsonSchema.description = schema.description ?? settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
|
|
29
|
+
ctx.jsonSchema.$comment = schema.meta().$comment;
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
})
|
|
30
33
|
: schema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codifycli/plugin-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
"@oclif/prettier-config": "^0.2.1",
|
|
52
52
|
"@oclif/test": "^3",
|
|
53
53
|
"@types/lodash.isequal": "^4.5.8",
|
|
54
|
-
"@types/node": "^
|
|
55
|
-
"@types/npmcli__promise-spawn": "^6.0.3",
|
|
54
|
+
"@types/node": "^22",
|
|
56
55
|
"@types/semver": "^7.5.4",
|
|
57
56
|
"@types/sinon": "^17.0.3",
|
|
58
57
|
"@types/uuid": "^10.0.0",
|
|
@@ -165,9 +165,18 @@ describe('Resource options parser tests', () => {
|
|
|
165
165
|
it('Can handle a zod schema', () => {
|
|
166
166
|
|
|
167
167
|
const schema = z.object({
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
plugins: z
|
|
169
|
+
.array(z.string())
|
|
170
|
+
.describe(
|
|
171
|
+
'Asdf plugins to install. See: https://github.com/asdf-community for a full list'
|
|
172
|
+
)
|
|
173
|
+
.optional(),
|
|
174
|
+
repository: z
|
|
175
|
+
.string()
|
|
176
|
+
.describe('Remote repository to clone repo from. Equivalent to remote and only one should be specified')
|
|
177
|
+
.optional(),
|
|
178
|
+
}).meta({ $comment: 'https://codifycli.com/docs/resources/asdf/asdf' })
|
|
179
|
+
.describe('This is my test resource');
|
|
171
180
|
|
|
172
181
|
const option: ResourceSettings<z.infer<typeof schema>> = {
|
|
173
182
|
id: 'typeId',
|
|
@@ -180,7 +189,29 @@ describe('Resource options parser tests', () => {
|
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
|
|
192
|
+
expect((new ParsedResourceSettings(option)).schema).toMatchObject({
|
|
193
|
+
'$schema': 'http://json-schema.org/draft-07/schema#',
|
|
194
|
+
type: 'object',
|
|
195
|
+
properties: {
|
|
196
|
+
plugins: {
|
|
197
|
+
description: 'Asdf plugins to install. See: https://github.com/asdf-community for a full list',
|
|
198
|
+
type: 'array',
|
|
199
|
+
items: {
|
|
200
|
+
"type": "string",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
repository: {
|
|
204
|
+
description: 'Remote repository to clone repo from. Equivalent to remote and only one should be specified',
|
|
205
|
+
type: 'string'
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
additionalProperties: false,
|
|
209
|
+
title: 'typeId',
|
|
210
|
+
description: 'This is my test resource',
|
|
211
|
+
'$comment': 'https://codifycli.com/docs/resources/asdf/asdf'
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
console.log((new ParsedResourceSettings(option)).schema)
|
|
184
215
|
|
|
185
216
|
})
|
|
186
217
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
|
|
2
2
|
import { JSONSchemaType } from 'ajv';
|
|
3
|
-
import {
|
|
3
|
+
import { z, ZodObject } from 'zod';
|
|
4
4
|
|
|
5
5
|
import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
|
|
6
6
|
import {
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
DefaultParameterSetting,
|
|
9
9
|
InputTransformation,
|
|
10
10
|
ParameterSetting,
|
|
11
|
-
ResourceSettings,
|
|
12
|
-
StatefulParameterSetting,
|
|
13
11
|
resolveElementEqualsFn,
|
|
14
12
|
resolveEqualsFn,
|
|
15
13
|
resolveMatcher,
|
|
16
|
-
resolveParameterTransformFn
|
|
14
|
+
resolveParameterTransformFn,
|
|
15
|
+
ResourceSettings,
|
|
16
|
+
StatefulParameterSetting
|
|
17
17
|
} from './resource-settings.js';
|
|
18
18
|
|
|
19
19
|
export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
|
|
@@ -69,8 +69,11 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
|
|
|
69
69
|
? z.toJSONSchema(schema.strict(), {
|
|
70
70
|
target: 'draft-7',
|
|
71
71
|
override(ctx) {
|
|
72
|
-
ctx.
|
|
73
|
-
|
|
72
|
+
if (ctx.path.length === 0) {
|
|
73
|
+
ctx.jsonSchema.title = settings.id;
|
|
74
|
+
ctx.jsonSchema.description = schema.description ?? settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
|
|
75
|
+
ctx.jsonSchema.$comment = (schema.meta() as Record<string, string | undefined>).$comment;
|
|
76
|
+
}
|
|
74
77
|
}
|
|
75
78
|
}) as JSONSchemaType<T>
|
|
76
79
|
: schema;
|