codify-schemas 1.0.39 → 1.0.41

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.
@@ -4,6 +4,14 @@
4
4
  "title": "Config file Schema",
5
5
  "type": "array",
6
6
  "items": {
7
- "$ref": "resource-schema.json"
7
+ "type": "object",
8
+ "properties": {
9
+ "type": {
10
+ "type": "string",
11
+ "description": "All config blocks must contain the keyword type",
12
+ "pattern": "^[a-zA-Z][\\w-]+$"
13
+ }
14
+ },
15
+ "required": ["type"]
8
16
  }
9
17
  }
@@ -4,7 +4,7 @@
4
4
  "title": "Validate Response Schema Data",
5
5
  "type": "object",
6
6
  "properties": {
7
- "validationResults": {
7
+ "resourceValidations": {
8
8
  "type": "array",
9
9
  "items": {
10
10
  "type": "object",
@@ -15,15 +15,23 @@
15
15
  "resourceName": {
16
16
  "type": "string"
17
17
  },
18
- "isValid": {
19
- "type": "boolean"
20
- },
21
- "errors": {
18
+ "schemaValidationErrors": {
22
19
  "type": "array",
23
- "description": "Any errors in validation"
20
+ "description": "Schema validation errors. Right now only ajv schemas are supported",
21
+ "items": {
22
+ "type": "object"
23
+ }
24
+ },
25
+ "customValidationErrorMessage": {
26
+ "type": "string",
27
+ "description": "Custom plugin validation errors. These are a string that should be displayed to the user"
28
+ },
29
+ "isValid": {
30
+ "type": "boolean",
31
+ "description": "Indicates if the resources are valid. True if no errors, false if there are"
24
32
  }
25
33
  },
26
- "required": ["resourceType", "isValid"]
34
+ "required": ["resourceType", "isValid", "schemaValidationErrors"]
27
35
  }
28
36
  }
29
37
  },
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import { SpawnOptions } from "node:child_process";
3
+ import { ErrorObject } from "ajv";
3
4
  export interface StringIndexedObject {
4
5
  [x: string]: unknown;
5
6
  }
@@ -28,11 +29,12 @@ export interface ValidateRequestData {
28
29
  configs: ResourceConfig[];
29
30
  }
30
31
  export interface ValidateResponseData {
31
- validationResults: Array<{
32
+ resourceValidations: Array<{
32
33
  resourceType: string;
33
34
  resourceName?: string;
35
+ schemaValidationErrors?: ErrorObject[] | null;
36
+ customValidationErrorMessage: string;
34
37
  isValid: boolean;
35
- errors?: unknown[] | null;
36
38
  }>;
37
39
  }
38
40
  export interface PlanRequestData extends ResourceConfig {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAuBD,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,kCAAa,CAAA;AACf,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,iCAAW,CAAA;IACX,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACf,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAmDD,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,8BAAe,CAAA;AACjB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAwBD,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,kCAAa,CAAA;AACf,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,iCAAW,CAAA;IACX,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACf,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAmDD,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,8BAAe,CAAA;AACjB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-schemas",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -4,6 +4,14 @@
4
4
  "title": "Config file Schema",
5
5
  "type": "array",
6
6
  "items": {
7
- "$ref": "resource-schema.json"
7
+ "type": "object",
8
+ "properties": {
9
+ "type": {
10
+ "type": "string",
11
+ "description": "All config blocks must contain the keyword type",
12
+ "pattern": "^[a-zA-Z][\\w-]+$"
13
+ }
14
+ },
15
+ "required": ["type"]
8
16
  }
9
17
  }
@@ -1,20 +1,20 @@
1
- import configSchema from './config-file-schema.json';
2
- import resourceSchema from './resource-schema.json';
1
+ import configFileSchema from './config-file-schema.json';
3
2
  import { describe, it, expect } from 'vitest'
4
3
  import Ajv2020 from 'ajv/dist/2020.js'
5
4
 
6
5
  const ajv = new Ajv2020.default({
7
6
  strict: true,
8
7
  })
9
- ajv.addSchema(resourceSchema);
10
8
 
11
- describe("config file schema tests", () => {
12
- it('compiles', () => {
13
- ajv.compile(configSchema);
9
+ describe("Config file schema tests", () => {
10
+ it('Compiles', () => {
11
+ ajv.compile(configFileSchema);
14
12
  })
15
13
 
16
- it('accepts resource blocks', () => {
17
- const validator = ajv.compile(configSchema);
14
+ it('And successfully validate blocks with type', () => {
15
+ const validator = ajv.compile(configFileSchema);
16
+
17
+ expect(validator([])).to.be.true;
18
18
 
19
19
  expect(validator([
20
20
  {
@@ -33,18 +33,39 @@ describe("config file schema tests", () => {
33
33
  expect(validator([
34
34
  {
35
35
  "type": "resource1",
36
- },
37
- {}
38
- ])).to.be.false;
36
+ }
37
+ ])).to.be.true;
39
38
 
40
39
  expect(validator([
41
40
  {
42
41
  "type": "project",
43
- },
44
- {
45
- "type": "resource2"
42
+ "description": "description",
46
43
  }
47
44
  ])).to.be.true;
48
45
  })
49
46
 
47
+ it('And errors on improper json', () => {
48
+ const validator = ajv.compile(configFileSchema);
49
+
50
+ expect(validator({
51
+ "a": {},
52
+ "b": {},
53
+ })).to.be.false;
54
+
55
+ expect(validator([
56
+ {
57
+ "type": "resource1"
58
+ },
59
+ "homebrew"
60
+ ])).to.be.false;
61
+
62
+ validator([
63
+ {
64
+ "type": "resource1"
65
+ },
66
+ {}
67
+ ])
68
+
69
+ console.log(validator.errors)
70
+ })
50
71
  })
@@ -4,7 +4,7 @@
4
4
  "title": "Validate Response Schema Data",
5
5
  "type": "object",
6
6
  "properties": {
7
- "validationResults": {
7
+ "resourceValidations": {
8
8
  "type": "array",
9
9
  "items": {
10
10
  "type": "object",
@@ -15,15 +15,23 @@
15
15
  "resourceName": {
16
16
  "type": "string"
17
17
  },
18
- "isValid": {
19
- "type": "boolean"
20
- },
21
- "errors": {
18
+ "schemaValidationErrors": {
22
19
  "type": "array",
23
- "description": "Any errors in validation"
20
+ "description": "Schema validation errors. Right now only ajv schemas are supported",
21
+ "items": {
22
+ "type": "object"
23
+ }
24
+ },
25
+ "customValidationErrorMessage": {
26
+ "type": "string",
27
+ "description": "Custom plugin validation errors. These are a string that should be displayed to the user"
28
+ },
29
+ "isValid": {
30
+ "type": "boolean",
31
+ "description": "Indicates if the resources are valid. True if no errors, false if there are"
24
32
  }
25
33
  },
26
- "required": ["resourceType", "isValid"]
34
+ "required": ["resourceType", "isValid", "schemaValidationErrors"]
27
35
  }
28
36
  }
29
37
  },
@@ -17,9 +17,24 @@ describe('Plan response data schema', () => {
17
17
  it("validates correct config", () => {
18
18
  const validate = ajv.compile(schema);
19
19
  expect(validate({
20
- validationResults: [
21
- { resourceType: 'abc', isValid: true },
22
- { resourceType: 'abc', resourceName: 'def', isValid: false, errors: ["error1", "error2"] },
20
+ resourceValidations: [
21
+ {
22
+ resourceType: 'abc',
23
+ schemaValidationErrors: [],
24
+ isValid: true
25
+ },
26
+ {
27
+ resourceType: 'abc',
28
+ resourceName: 'def',
29
+ schemaValidationErrors: [
30
+ {
31
+ schemaPath: '/0',
32
+ instancePath: '/0'
33
+ }
34
+ ],
35
+ customValidationErrorMessage: "this is also an error message",
36
+ isValid: false,
37
+ },
23
38
  ]
24
39
  } as ValidateResponseData)).to.be.true;
25
40
  })
@@ -27,7 +42,7 @@ describe('Plan response data schema', () => {
27
42
  it ("validates incorrect config", () => {
28
43
  const validate = ajv.compile(schema);
29
44
  expect(validate({
30
- validationResults: [
45
+ resourceValidations: [
31
46
  { resourceName: 'abc', isValid: true },
32
47
  ]
33
48
  } as ValidateResponseData)).to.be.false;
@@ -1,4 +1,5 @@
1
- import {SpawnOptions} from "node:child_process";
1
+ import { SpawnOptions } from "node:child_process";
2
+ import { ErrorObject } from "ajv";
2
3
 
3
4
  export interface StringIndexedObject {
4
5
  [x: string]: unknown;
@@ -35,11 +36,12 @@ export interface ValidateRequestData {
35
36
  }
36
37
 
37
38
  export interface ValidateResponseData {
38
- validationResults: Array<{
39
+ resourceValidations: Array<{
39
40
  resourceType: string;
40
41
  resourceName?: string;
42
+ schemaValidationErrors?: ErrorObject[] | null;
43
+ customValidationErrorMessage: string;
41
44
  isValid: boolean;
42
- errors?: unknown[] | null;
43
45
  }>;
44
46
  }
45
47