codify-plugin-lib 1.0.182-beta29 → 1.0.182-beta30

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.
@@ -17,15 +17,17 @@ export class ParsedResourceSettings {
17
17
  this.settings = settings;
18
18
  const { parameterSettings, schema, ...rest } = settings;
19
19
  Object.assign(this, rest);
20
- this.schema = schema instanceof ZodObject
21
- ? z.toJSONSchema(schema, {
22
- target: 'draft-7',
23
- override(ctx) {
24
- ctx.jsonSchema.title = settings.id;
25
- ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
26
- }
27
- })
28
- : schema;
20
+ if (schema) {
21
+ this.schema = schema instanceof ZodObject
22
+ ? z.toJSONSchema(schema.strict(), {
23
+ target: 'draft-7',
24
+ override(ctx) {
25
+ ctx.jsonSchema.title = settings.id;
26
+ ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
27
+ }
28
+ })
29
+ : schema;
30
+ }
29
31
  this.validateSettings();
30
32
  }
31
33
  get typeId() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta29",
3
+ "version": "1.0.182-beta30",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -7,6 +7,7 @@ import { spy } from 'sinon';
7
7
  import { ResourceSettings } from '../resource/resource-settings.js';
8
8
  import { TestConfig, TestStatefulParameter } from '../utils/test-utils.test.js';
9
9
  import { getPty } from '../pty/index.js';
10
+ import { z } from 'zod';
10
11
 
11
12
  interface TestConfig extends StringIndexedObject {
12
13
  propA: string;
@@ -170,6 +171,36 @@ describe('Plugin tests', () => {
170
171
  })
171
172
  })
172
173
 
174
+ it('Can get resource info (zod schema)', async () => {
175
+ const schema = z
176
+ .object({
177
+ plugins: z
178
+ .array(z.string())
179
+ .describe(
180
+ "Asdf plugins to install. See: https://github.com/asdf-community for a full list"
181
+ )
182
+ })
183
+ .strict()
184
+
185
+ const resource = new class extends TestResource {
186
+ getSettings(): ResourceSettings<TestConfig> {
187
+ return {
188
+ id: 'typeId',
189
+ operatingSystems: [OS.Darwin],
190
+ schema,
191
+ }
192
+ }
193
+ }
194
+ const testPlugin = Plugin.create('testPlugin', [resource as any])
195
+
196
+ const resourceInfo = await testPlugin.getResourceInfo({ type: 'typeId' })
197
+ expect(resourceInfo.import).toMatchObject({
198
+ requiredParameters: [
199
+ 'plugins'
200
+ ]
201
+ })
202
+ })
203
+
173
204
  it('Get resource info to default import to the one specified in the resource settings', async () => {
174
205
  const schema = {
175
206
  '$schema': 'http://json-schema.org/draft-07/schema',
@@ -62,15 +62,18 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
62
62
  const { parameterSettings, schema, ...rest } = settings;
63
63
 
64
64
  Object.assign(this, rest);
65
- this.schema = schema instanceof ZodObject
66
- ? z.toJSONSchema(schema, {
67
- target: 'draft-7',
68
- override(ctx) {
69
- ctx.jsonSchema.title = settings.id;
70
- ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
71
- }
72
- }) as JSONSchemaType<T>
73
- : schema;
65
+
66
+ if (schema) {
67
+ this.schema = schema instanceof ZodObject
68
+ ? z.toJSONSchema(schema.strict(), {
69
+ target: 'draft-7',
70
+ override(ctx) {
71
+ ctx.jsonSchema.title = settings.id;
72
+ ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
73
+ }
74
+ }) as JSONSchemaType<T>
75
+ : schema;
76
+ }
74
77
 
75
78
  this.validateSettings();
76
79
  }
@@ -11,6 +11,7 @@ import { tildify, untildify } from '../utils/functions.js';
11
11
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
12
12
  import { Plan } from '../plan/plan.js';
13
13
  import os from 'node:os';
14
+ import { z } from 'zod';
14
15
 
15
16
  describe('Resource tests', () => {
16
17
 
@@ -952,4 +953,129 @@ describe('Resource tests', () => {
952
953
 
953
954
  process.env = oldProcessEnv;
954
955
  })
956
+
957
+ it('Can import and return all of the imported parameters (zod schema)', async () => {
958
+ const schema = z.object({
959
+ path: z
960
+ .string()
961
+ .describe(
962
+ 'A list of paths to add to the PATH environment variable'
963
+ ),
964
+ paths: z
965
+ .array(z.string())
966
+ .describe(
967
+ 'A list of paths to add to the PATH environment variable'
968
+ ),
969
+ prepend: z
970
+ .boolean()
971
+ .describe(
972
+ 'Whether to prepend the paths to the PATH environment variable'
973
+ ),
974
+ declarationsOnly: z
975
+ .boolean()
976
+ .describe(
977
+ 'Whether to only declare the paths in the PATH environment variable'
978
+ ),
979
+ })
980
+
981
+ const resource = new class extends TestResource {
982
+ getSettings(): ResourceSettings<any> {
983
+ return {
984
+ id: 'path',
985
+ schema,
986
+ operatingSystems: [OS.Darwin],
987
+ parameterSettings: {
988
+ path: { type: 'directory' },
989
+ paths: { canModify: true, type: 'array', itemType: 'directory' },
990
+ prepend: { default: false, setting: true },
991
+ declarationsOnly: { default: false, setting: true },
992
+ },
993
+ importAndDestroy: {
994
+ refreshMapper: (input, context) => {
995
+ if (Object.keys(input).length === 0) {
996
+ return { paths: [], declarationsOnly: true };
997
+ }
998
+
999
+ return input;
1000
+ }
1001
+ },
1002
+ allowMultiple: {
1003
+ matcher: (desired, current) => {
1004
+ if (desired.path) {
1005
+ return desired.path === current.path;
1006
+ }
1007
+
1008
+ const currentPaths = new Set(current.paths)
1009
+ return desired.paths?.some((p) => currentPaths.has(p));
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+
1015
+ async refresh(parameters: Partial<TestConfig>): Promise<Partial<TestConfig> | null> {
1016
+ return {
1017
+ paths: [
1018
+ `${os.homedir()}/.pyenv/bin`,
1019
+ `${os.homedir()}/.bun/bin`,
1020
+ `${os.homedir()}/.deno/bin`,
1021
+ `${os.homedir()}/.jenv/bin`,
1022
+ `${os.homedir()}/a/random/path`,
1023
+ `${os.homedir()}/.nvm/.bin/2`,
1024
+ `${os.homedir()}/.nvm/.bin/3`
1025
+ ]
1026
+ }
1027
+ }
1028
+ }
1029
+
1030
+ const oldProcessEnv = structuredClone(process.env);
1031
+
1032
+ process.env['PYENV_ROOT'] = `${os.homedir()}/.pyenv`
1033
+ process.env['BUN_INSTALL'] = `${os.homedir()}/.bun`
1034
+ process.env['DENO_INSTALL'] = `${os.homedir()}/.deno`
1035
+ process.env['JENV'] = `${os.homedir()}/.jenv`
1036
+ process.env['NVM_DIR'] = `${os.homedir()}/.nvm`
1037
+
1038
+ const controller = new ResourceController(resource);
1039
+ const importResult1 = await controller.import({ type: 'path' }, {});
1040
+ expect(importResult1).toMatchObject([
1041
+ {
1042
+ 'core': {
1043
+ 'type': 'path'
1044
+ },
1045
+ 'parameters': {
1046
+ 'paths': [
1047
+ '$PYENV_ROOT/bin',
1048
+ '$BUN_INSTALL/bin',
1049
+ '$DENO_INSTALL/bin',
1050
+ '$JENV/bin',
1051
+ '~/a/random/path',
1052
+ '$NVM_DIR/.bin/2',
1053
+ '$NVM_DIR/.bin/3'
1054
+ ]
1055
+ }
1056
+ }
1057
+ ])
1058
+
1059
+ const importResult2 = await controller.import({ type: 'path' }, { paths: ['$PYENV_ROOT/bin', '$BUN_INSTALL/bin'] });
1060
+ expect(importResult2).toMatchObject([
1061
+ {
1062
+ 'core': {
1063
+ 'type': 'path'
1064
+ },
1065
+ 'parameters': {
1066
+ 'paths': [
1067
+ '$PYENV_ROOT/bin',
1068
+ '$BUN_INSTALL/bin',
1069
+ '$DENO_INSTALL/bin',
1070
+ '$JENV/bin',
1071
+ '~/a/random/path',
1072
+ '$NVM_DIR/.bin/2',
1073
+ '$NVM_DIR/.bin/3'
1074
+ ]
1075
+ }
1076
+ }
1077
+ ])
1078
+
1079
+ process.env = oldProcessEnv;
1080
+ })
955
1081
  });