codify-plugin-lib 1.0.130 → 1.0.132

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.
@@ -7,7 +7,7 @@ on: [ push ]
7
7
 
8
8
  jobs:
9
9
  build-and-test:
10
- runs-on: ubuntu-latest
10
+ runs-on: macos-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v4
13
13
  - uses: actions/setup-node@v4
@@ -15,5 +15,4 @@ jobs:
15
15
  node-version: '20.x'
16
16
  cache: 'npm'
17
17
  - run: npm ci
18
- - run: tsc
19
18
  - run: npm run test
@@ -31,11 +31,12 @@ export class ResourceController {
31
31
  return this.resource.initialize();
32
32
  }
33
33
  async validate(core, parameters) {
34
+ const originalParameters = structuredClone(parameters);
34
35
  await this.applyTransformParameters(parameters);
35
36
  this.addDefaultValues(parameters);
36
37
  if (this.schemaValidator) {
37
38
  // Schema validator uses pre transformation parameters
38
- const isValid = this.schemaValidator(parameters);
39
+ const isValid = this.schemaValidator(originalParameters);
39
40
  if (!isValid) {
40
41
  return {
41
42
  isValid: false,
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.130",
3
+ "version": "1.0.132",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "test": "vitest"
9
+ "test": "vitest",
10
+ "posttest": "tsc",
11
+ "prepublishOnly": "tsc"
10
12
  },
11
13
  "keywords": [],
12
14
  "author": "",
@@ -14,7 +16,7 @@
14
16
  "dependencies": {
15
17
  "ajv": "^8.12.0",
16
18
  "ajv-formats": "^2.1.1",
17
- "codify-schemas": "1.0.61",
19
+ "codify-schemas": "1.0.63",
18
20
  "@npmcli/promise-spawn": "^7.0.1",
19
21
  "@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
20
22
  "uuid": "^10.0.0",
@@ -280,4 +280,49 @@ describe('Plugin tests', () => {
280
280
  await testPlugin.apply({ plan })
281
281
  expect(resource.refresh.calledOnce).to.be.true;
282
282
  })
283
+
284
+ it('Maintains types for validate', async () => {
285
+ const resource = new class extends TestResource {
286
+ getSettings(): ResourceSettings<TestConfig> {
287
+ return {
288
+ id: 'type',
289
+ schema: {
290
+ '$schema': 'http://json-schema.org/draft-07/schema',
291
+ '$id': 'https://www.codifycli.com/ssh-config.json',
292
+ 'type': 'object',
293
+ 'properties': {
294
+ 'hosts': {
295
+ 'description': 'The host blocks inside of the ~/.ssh/config file. See http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5 ',
296
+ 'type': 'array',
297
+ 'items': {
298
+ 'type': 'object',
299
+ 'description': 'The individual host blocks inside of the ~/.ssh/config file',
300
+ 'properties': {
301
+ 'UseKeychain': {
302
+ 'type': 'boolean',
303
+ 'description': 'A UseKeychain option was introduced in macOS Sierra allowing users to specify whether they would like for the passphrase to be stored in the keychain'
304
+ },
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ }
311
+ };
312
+ }
313
+
314
+ const plugin = Plugin.create('testPlugin', [resource as any]);
315
+ const result = await plugin.validate({
316
+ configs: [{
317
+ core: { type: 'type' },
318
+ parameters: {
319
+ hosts: [{
320
+ UseKeychain: true,
321
+ }]
322
+ }
323
+ }]
324
+ })
325
+
326
+ console.log(result);
327
+ })
283
328
  });
@@ -18,21 +18,22 @@ describe('BackgroundPty tests', () => {
18
18
  });
19
19
  })
20
20
 
21
- it('Can launch 100 commands in parallel', { timeout: 15000 }, async () => {
22
- const pty = new BackgroundPty();
23
-
24
- const fn = async () => pty.spawnSafe('ls');
25
-
26
- const results = await Promise.all(
27
- Array.from({ length: 100 }, (_, i) => i + 1)
28
- .map(() => fn())
29
- )
30
-
31
- expect(results.length).to.eq(100);
32
- expect(results.every((r) => r.exitCode === 0))
33
-
34
- await pty.kill();
35
- })
21
+ // This test takes forever so going to disable for now.
22
+ // it('Can launch 100 commands in parallel', { timeout: 15000 }, async () => {
23
+ // const pty = new BackgroundPty();
24
+ //
25
+ // const fn = async () => pty.spawnSafe('ls');
26
+ //
27
+ // const results = await Promise.all(
28
+ // Array.from({ length: 100 }, (_, i) => i + 1)
29
+ // .map(() => fn())
30
+ // )
31
+ //
32
+ // expect(results.length).to.eq(100);
33
+ // expect(results.every((r) => r.exitCode === 0))
34
+ //
35
+ // await pty.kill();
36
+ // })
36
37
 
37
38
  it('Reports back the correct exit code and status', async () => {
38
39
  const pty = new BackgroundPty();
@@ -25,9 +25,8 @@ describe('General tests for PTYs', () => {
25
25
 
26
26
  const plugin = Plugin.create('test plugin', [testResource])
27
27
  const plan = await plugin.plan({
28
- desired: {
29
- type: 'type'
30
- },
28
+ core: { type: 'type' },
29
+ desired: {},
31
30
  state: undefined,
32
31
  isStateful: false,
33
32
  })
@@ -84,17 +83,15 @@ describe('General tests for PTYs', () => {
84
83
 
85
84
  const plugin = Plugin.create('test plugin', [testResource1, testResource2]);
86
85
  await plugin.plan({
87
- desired: {
88
- type: 'type1'
89
- },
86
+ core: { type: 'type1' },
87
+ desired: {},
90
88
  state: undefined,
91
89
  isStateful: false,
92
90
  })
93
91
 
94
92
  await plugin.plan({
95
- desired: {
96
- type: 'type2'
97
- },
93
+ core: { type: 'type2' },
94
+ desired: {},
98
95
  state: undefined,
99
96
  isStateful: false,
100
97
  })
@@ -57,12 +57,13 @@ export class ResourceController<T extends StringIndexedObject> {
57
57
  core: ResourceConfig,
58
58
  parameters: Partial<T>,
59
59
  ): Promise<ValidateResponseData['resourceValidations'][0]> {
60
+ const originalParameters = structuredClone(parameters);
60
61
  await this.applyTransformParameters(parameters);
61
62
  this.addDefaultValues(parameters);
62
63
 
63
64
  if (this.schemaValidator) {
64
65
  // Schema validator uses pre transformation parameters
65
- const isValid = this.schemaValidator(parameters);
66
+ const isValid = this.schemaValidator(originalParameters);
66
67
 
67
68
  if (!isValid) {
68
69
  return {
@@ -5,6 +5,7 @@ import { Resource } from '../resource/resource.js';
5
5
  import { CreatePlan, DestroyPlan } from '../plan/plan-types.js';
6
6
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
7
7
  import { ParsedResourceSettings } from '../resource/parsed-resource-settings.js';
8
+ import { describe, it } from 'vitest';
8
9
 
9
10
  export function testPlan<T extends StringIndexedObject>(params: {
10
11
  desired?: Partial<T> | null;
@@ -85,3 +86,8 @@ export class TestArrayStatefulParameter extends ArrayStatefulParameter<TestConfi
85
86
  return Promise.resolve(undefined);
86
87
  }
87
88
  }
89
+
90
+ describe('Empty tests', () => {
91
+ it('empty', () => {
92
+ })
93
+ })
package/vitest.config.ts CHANGED
@@ -2,10 +2,9 @@ import { defaultExclude, defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
+ pool: 'forks',
5
6
  exclude: [
6
- ...defaultExclude,
7
- './src/utils/test-utils.test.ts',
8
- './src/pty/*'
7
+ ...defaultExclude
9
8
  ]
10
9
  },
11
10
  });
@@ -1,11 +0,0 @@
1
- import { defaultExclude, defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- pool: 'forks',
6
- fileParallelism: false,
7
- exclude: [
8
- ...defaultExclude,
9
- ]
10
- },
11
- });