codify-plugin-lib 1.0.30 → 1.0.31

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,6 +1,6 @@
1
- import Ajv from 'ajv';
2
1
  import addFormats from 'ajv-formats';
3
2
  import { IpcMessageSchema, ResourceSchema, ValidateRequestDataSchema, ValidateResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ApplyRequestDataSchema, ApplyResponseDataSchema } from 'codify-schemas';
3
+ import Ajv2020 from 'ajv/dist/2020.js';
4
4
  const SupportedRequests = {
5
5
  'validate': {
6
6
  requestValidator: ValidateRequestDataSchema,
@@ -28,7 +28,7 @@ export class MessageHandler {
28
28
  requestValidators;
29
29
  responseValidators;
30
30
  constructor(plugin) {
31
- this.ajv = new Ajv.default({ strict: true, code: { esm: true } });
31
+ this.ajv = new Ajv2020.default({ strict: true });
32
32
  addFormats.default(this.ajv);
33
33
  this.ajv.addSchema(ResourceSchema);
34
34
  this.plugin = plugin;
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "test": "vitest",
10
- "prepublish": "tsc"
9
+ "test": "vitest"
11
10
  },
12
11
  "keywords": [],
13
12
  "author": "",
@@ -15,7 +14,7 @@
15
14
  "dependencies": {
16
15
  "ajv": "^8.12.0",
17
16
  "ajv-formats": "^2.1.1",
18
- "codify-schemas": "../codify-schemas",
17
+ "codify-schemas": "1.0.21",
19
18
  "@npmcli/promise-spawn": "^7.0.1"
20
19
  },
21
20
  "devDependencies": {
@@ -1,11 +1,12 @@
1
- import { MessageHandler } from './handlers';
2
- import { Plugin } from '../entities/plugin';
1
+ import { MessageHandler } from './handlers.js';
2
+ import { Plugin } from '../entities/plugin.js';
3
3
  import { describe, it, expect } from 'vitest';
4
- import { createStubInstance } from 'sinon';
4
+ import { vi } from 'vitest'
5
+ import { mock } from 'vitest-mock-extended'
5
6
 
6
7
  describe('Message handler tests', () => {
7
8
  it('handles plan requests', async () => {
8
- const plugin = createStubInstance(Plugin);
9
+ const plugin = mock<Plugin>();
9
10
  const handler = new MessageHandler(plugin);
10
11
 
11
12
  // Message handler also validates the response. That part does not need to be tested
@@ -21,11 +22,11 @@ describe('Message handler tests', () => {
21
22
  })
22
23
  } catch (e) {}
23
24
 
24
- expect(plugin.plan.calledOnce).to.be.true;
25
+ expect(plugin.plan.mock.calls.length).to.eq(1);
25
26
  })
26
27
 
27
28
  it('rejects bad plan requests', async () => {
28
- const plugin = createStubInstance(Plugin);
29
+ const plugin = mock<Plugin>();
29
30
  const handler = new MessageHandler(plugin);
30
31
 
31
32
  // Message handler also validates the response. That part does not need to be tested
@@ -33,7 +34,6 @@ describe('Message handler tests', () => {
33
34
  await handler.onMessage({
34
35
  cmd: 'plan',
35
36
  data: {
36
- type: 'resourceType',
37
37
  name: '1name',
38
38
  prop1: 'A',
39
39
  prop2: 'B',
@@ -41,11 +41,11 @@ describe('Message handler tests', () => {
41
41
  })
42
42
  } catch (e) {}
43
43
 
44
- expect(plugin.plan.called).to.be.false;
44
+ expect(plugin.plan.mock.calls.length).to.eq(0);
45
45
  })
46
46
 
47
47
  it('handles apply requests', async () => {
48
- const plugin = createStubInstance(Plugin);
48
+ const plugin = mock<Plugin>();
49
49
  const handler = new MessageHandler(plugin);
50
50
 
51
51
  // Message handler also validates the response. That part does not need to be tested
@@ -58,11 +58,11 @@ describe('Message handler tests', () => {
58
58
  })
59
59
  } catch (e) {}
60
60
 
61
- expect(plugin.apply.calledOnce).to.be.true;
61
+ expect(plugin.apply.mock.calls.length).to.be.eq(1);
62
62
  })
63
63
 
64
- it('rejects bad plan requests', async () => {
65
- const plugin = createStubInstance(Plugin);
64
+ it('rejects bad apply requests', async () => {
65
+ const plugin = mock<Plugin>();
66
66
  const handler = new MessageHandler(plugin);
67
67
 
68
68
  // Message handler also validates the response. That part does not need to be tested
@@ -73,11 +73,11 @@ describe('Message handler tests', () => {
73
73
  })
74
74
  } catch (e) {}
75
75
 
76
- expect(plugin.apply.called).to.be.false;
76
+ expect(plugin.apply.mock.calls.length).to.be.eq(0);
77
77
  })
78
78
 
79
79
  it('handles validate requests', async () => {
80
- const plugin = createStubInstance(Plugin);
80
+ const plugin = mock<Plugin>();
81
81
  const handler = new MessageHandler(plugin);
82
82
 
83
83
  // Message handler also validates the response. That part does not need to be tested
@@ -103,11 +103,11 @@ describe('Message handler tests', () => {
103
103
  })
104
104
  } catch (e) {}
105
105
 
106
- expect(plugin.validate.calledOnce).to.be.true;
106
+ expect(plugin.validate.mock.calls.length).to.eq(1);
107
107
  })
108
108
 
109
109
  it('rejects bad validate requests', async () => {
110
- const plugin = createStubInstance(Plugin);
110
+ const plugin = mock<Plugin>();
111
111
  const handler = new MessageHandler(plugin);
112
112
 
113
113
  // Message handler also validates the response. That part does not need to be tested
@@ -118,7 +118,7 @@ describe('Message handler tests', () => {
118
118
  })
119
119
  } catch (e) {}
120
120
 
121
- expect(plugin.apply.called).to.be.false;
121
+ expect(plugin.apply.mock.calls.length).to.be.eq(0);
122
122
  })
123
123
 
124
124
  });
@@ -1,4 +1,3 @@
1
- import Ajv, { SchemaObject, ValidateFunction } from 'ajv';
2
1
  import { Plugin } from '../entities/plugin.js';
3
2
  import addFormats from 'ajv-formats';
4
3
  import {
@@ -13,6 +12,7 @@ import {
13
12
  ApplyRequestDataSchema,
14
13
  ApplyResponseDataSchema
15
14
  } from 'codify-schemas';
15
+ import Ajv2020, { SchemaObject, ValidateFunction } from 'ajv/dist/2020.js';
16
16
 
17
17
  const SupportedRequests: Record<string, { requestValidator: SchemaObject; responseValidator: SchemaObject; handler: (plugin: Plugin, data: any) => Promise<unknown> }> = {
18
18
  'validate': {
@@ -36,14 +36,14 @@ const SupportedRequests: Record<string, { requestValidator: SchemaObject; respon
36
36
  }
37
37
 
38
38
  export class MessageHandler {
39
- private ajv: any;
39
+ private ajv: Ajv2020.default;
40
40
  private readonly plugin: Plugin;
41
41
  private messageSchemaValidator: ValidateFunction;
42
42
  private requestValidators: Map<string, ValidateFunction>;
43
43
  private responseValidators: Map<string, ValidateFunction>;
44
44
 
45
45
  constructor(plugin: Plugin) {
46
- this.ajv = new Ajv.default({ strict: true, code: { esm: true } });
46
+ this.ajv = new Ajv2020.default({ strict: true });
47
47
  addFormats.default(this.ajv);
48
48
  this.ajv.addSchema(ResourceSchema);
49
49
  this.plugin = plugin;
package/tsconfig.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "declaration": true,
4
4
  "module": "Node16",
5
+ "moduleResolution": "Node16",
5
6
  "alwaysStrict": true,
6
7
  "noImplicitAny": true,
7
8
  "resolveJsonModule": true,