codify-schemas 1.0.0

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.
package/.mocharc.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "require": "ts-node/register",
3
+ "extensions": ["ts"],
4
+ "spec": [
5
+ "src/**/*.test.ts"
6
+ ]
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ValidateResponseDataSchema = exports.ValidateRequestDataSchema = exports.PlanResponseDataSchema = exports.PlanRequestDataSchema = exports.ErrorResponseDataSchema = exports.ApplyRequestDataSchema = exports.IpcMessageSchema = exports.ResourceSchema = exports.ResourceMetaSchema = exports.ProjectSchema = exports.ConfigFileSchema = void 0;
21
+ var config_file_schema_json_1 = require("./config-file-schema.json");
22
+ Object.defineProperty(exports, "ConfigFileSchema", { enumerable: true, get: function () { return __importDefault(config_file_schema_json_1).default; } });
23
+ var project_schema_json_1 = require("./project-schema.json");
24
+ Object.defineProperty(exports, "ProjectSchema", { enumerable: true, get: function () { return __importDefault(project_schema_json_1).default; } });
25
+ var resource_meta_schema_json_1 = require("./resource-meta-schema.json");
26
+ Object.defineProperty(exports, "ResourceMetaSchema", { enumerable: true, get: function () { return __importDefault(resource_meta_schema_json_1).default; } });
27
+ var resource_schema_json_1 = require("./resource-schema.json");
28
+ Object.defineProperty(exports, "ResourceSchema", { enumerable: true, get: function () { return __importDefault(resource_schema_json_1).default; } });
29
+ var ipc_message_schema_json_1 = require("./ipc-message-schema.json");
30
+ Object.defineProperty(exports, "IpcMessageSchema", { enumerable: true, get: function () { return __importDefault(ipc_message_schema_json_1).default; } });
31
+ var apply_request_data_schema_json_1 = require("./messages/apply-request-data-schema.json");
32
+ Object.defineProperty(exports, "ApplyRequestDataSchema", { enumerable: true, get: function () { return __importDefault(apply_request_data_schema_json_1).default; } });
33
+ var error_response_data_schema_json_1 = require("./messages/error-response-data-schema.json");
34
+ Object.defineProperty(exports, "ErrorResponseDataSchema", { enumerable: true, get: function () { return __importDefault(error_response_data_schema_json_1).default; } });
35
+ var plan_request_data_schema_json_1 = require("./messages/plan-request-data-schema.json");
36
+ Object.defineProperty(exports, "PlanRequestDataSchema", { enumerable: true, get: function () { return __importDefault(plan_request_data_schema_json_1).default; } });
37
+ var plan_response_data_schema_json_1 = require("./messages/plan-response-data-schema.json");
38
+ Object.defineProperty(exports, "PlanResponseDataSchema", { enumerable: true, get: function () { return __importDefault(plan_response_data_schema_json_1).default; } });
39
+ var validate_request_data_schema_json_1 = require("./messages/validate-request-data-schema.json");
40
+ Object.defineProperty(exports, "ValidateRequestDataSchema", { enumerable: true, get: function () { return __importDefault(validate_request_data_schema_json_1).default; } });
41
+ var validate_response_data_schema_json_1 = require("./messages/validate-response-data-schema.json");
42
+ Object.defineProperty(exports, "ValidateResponseDataSchema", { enumerable: true, get: function () { return __importDefault(validate_response_data_schema_json_1).default; } });
43
+ __exportStar(require("./types"), exports);
44
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "codify-schemas",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "tsc": "tsc"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "ajv": "^8.12.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/chai": "^4.3.11",
19
+ "@types/mocha": "^10.0.6",
20
+ "chai": "^5.0.3",
21
+ "mocha": "^10.2.0",
22
+ "ts-node": "^10.9.2",
23
+ "typescript": "^5.3.3"
24
+ }
25
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/config-file-schema.json",
4
+ "title": "Config file Schema",
5
+ "type": "array",
6
+ "items": {
7
+ "$ref": "resource-schema.json"
8
+ }
9
+ }
@@ -0,0 +1,52 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import configSchema from './config-file-schema.json';
3
+ import resourceSchema from './resource-schema.json';
4
+ import assert from "node:assert";
5
+
6
+ const ajv = new Ajv2020({
7
+ strict: true,
8
+ })
9
+ ajv.addSchema(resourceSchema);
10
+
11
+ describe("config file schema tests", () => {
12
+ it('compiles', () => {
13
+ ajv.compile(configSchema);
14
+ })
15
+
16
+ it('accepts resource blocks', () => {
17
+ const validator = ajv.compile(configSchema);
18
+
19
+ assert.equal(validator([
20
+ {
21
+ "type": "resource1",
22
+ },
23
+ {
24
+ "type": "resource2",
25
+ "name": "abc",
26
+ "prop1": {
27
+ "a": "b",
28
+ },
29
+ "prop2": "c"
30
+ }
31
+ ]), true)
32
+
33
+ assert.equal(validator([
34
+ {
35
+ "type": "resource1",
36
+ },
37
+ {}
38
+ ]), false)
39
+
40
+ assert.equal(validator([
41
+ {
42
+ "type": "project",
43
+ },
44
+ {
45
+ "type": "resource2"
46
+ }
47
+ ]), true)
48
+
49
+ })
50
+
51
+
52
+ })
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { default as ConfigFileSchema } from './config-file-schema.json';
2
+ export { default as ProjectSchema } from './project-schema.json';
3
+ export { default as ResourceMetaSchema } from './resource-meta-schema.json';
4
+ export { default as ResourceSchema } from './resource-schema.json';
5
+ export { default as IpcMessageSchema } from './ipc-message-schema.json';
6
+ export { default as ApplyRequestDataSchema } from './messages/apply-request-data-schema.json';
7
+ export { default as ErrorResponseDataSchema } from './messages/error-response-data-schema.json';
8
+ export { default as PlanRequestDataSchema } from './messages/plan-request-data-schema.json';
9
+ export { default as PlanResponseDataSchema } from './messages/plan-response-data-schema.json';
10
+ export { default as ValidateRequestDataSchema } from './messages/validate-request-data-schema.json';
11
+ export { default as ValidateResponseDataSchema } from './messages/validate-response-data-schema.json';
12
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/ipc-message-schema.json",
4
+ "title": "IPC Message Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "cmd": {
8
+ "description": "The uri for the message. Like an http url",
9
+ "type": "string"
10
+ },
11
+ "status": {
12
+ "description": "The status of the request. Only used for responses. Can be either success or error",
13
+ "type": "string",
14
+ "enum": ["success", "error"]
15
+ },
16
+ "data": {
17
+ "description": "The data of the message."
18
+ }
19
+ },
20
+ "required": ["cmd", "data"]
21
+ }
@@ -0,0 +1,37 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import { describe, it } from 'mocha';
3
+ import schema from './ipc-message-schema.json';
4
+ import assert from "node:assert";
5
+
6
+ const ajv = new Ajv2020({
7
+ strict: true,
8
+ })
9
+
10
+ describe("Ipc message schema tests", () => {
11
+ it("compiles", () => {
12
+ ajv.compile(schema);
13
+ })
14
+
15
+ it("requires a cmd field to be specified", () => {
16
+ const validate = ajv.compile(schema);
17
+ assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
18
+ assert.equal(validate({ data: "data" }), false)
19
+ })
20
+
21
+ it("has an optional status field for responses", () => {
22
+ const validate = ajv.compile(schema);
23
+ assert.equal(validate({ cmd: "doSomething", status: "success", data: "data" }), true)
24
+ assert.equal(validate({ cmd: "doSomething", status: "error", data: "data" }), true)
25
+ assert.equal(validate({ cmd: "doSomething", status: "other", data: "data" }), false)
26
+ assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
27
+ })
28
+
29
+ it ("accepts data or null", () => {
30
+ const validate = ajv.compile(schema);
31
+ assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
32
+ assert.equal(validate({ cmd: "doSomething", data: null }), true)
33
+ assert.equal(validate({ cmd: "doSomething" }), false)
34
+ assert.equal(validate({ cmd: "doSomething", data: {} }), true)
35
+ });
36
+
37
+ });
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/apply-request-data-schema.json",
4
+ "title": "Apply Request Schema Data",
5
+ "description": "Apply the previously generated plan. The plan must already be generated in order for apply to work.",
6
+ "type": "object",
7
+ "properties": {
8
+ "planId": {
9
+ "description": "The plan uuid. This id is used to look up the generated plan on the plugin side",
10
+ "type": "string",
11
+ "format": "uuid"
12
+ }
13
+ },
14
+ "required": ["planId"],
15
+ "additionalProperties": false
16
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/apply-response-data-schema.json",
4
+ "title": "Apply Response Schema Data",
5
+ "type": "null",
6
+ "additionalProperties": false
7
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/error-response-data-schema.json",
4
+ "title": "Error Response Schema Data",
5
+ "type": "object",
6
+ "properties": {
7
+ "reason": {
8
+ "description": "A human read-able reason for the error",
9
+ "type": "string"
10
+ }
11
+ },
12
+ "required": ["reason"],
13
+ "additionalProperties": false
14
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/get-resources-response-data-schema.json",
4
+ "title": "Get Resources Response Schema Data",
5
+ "type": "object",
6
+ "properties": {
7
+ "resources": {
8
+ "type": "array",
9
+ "items": {
10
+ "type": "object",
11
+ "properties": {
12
+ "type": {
13
+ "$ref": "resource-schema.json#/properties/type"
14
+ },
15
+ "dependencies": {
16
+ "type": "array",
17
+ "items": {
18
+ "type": "string"
19
+ }
20
+ }
21
+ },
22
+ "required": ["type"]
23
+ }
24
+ }
25
+ },
26
+ "required": ["resources"],
27
+ "additionalProperties": false
28
+ }
@@ -0,0 +1,43 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import schema from './get-resources-response-data-schema.json';
3
+ import resourceSchema from '../resource-schema.json'
4
+ import {it} from "mocha";
5
+ import assert from "node:assert";
6
+
7
+ const ajv = new Ajv2020({
8
+ strict: true,
9
+ })
10
+ ajv.addSchema(resourceSchema);
11
+
12
+ describe('Get resources response data schema', () => {
13
+ it('compiles', () => {
14
+ ajv.compile(schema);
15
+ })
16
+
17
+ it("requires a type field to be specified", () => {
18
+ const validate = ajv.compile(schema);
19
+ assert.equal(validate({ resources: [
20
+ {
21
+ type: "typeA",
22
+ dependencies: [
23
+ "typeB"
24
+ ]
25
+ },
26
+ {
27
+ type: "typeB"
28
+ }
29
+ ]}), true)
30
+ assert.equal(validate({
31
+ resources: [
32
+ {
33
+ type: "typeA",
34
+ dependencies: [
35
+ "typeB"
36
+ ]
37
+ },
38
+ {}
39
+ ]
40
+ }), false)
41
+ })
42
+
43
+ })
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/plan-request-data-schema.json",
4
+ "title": "Plan Request Schema Data",
5
+ "$ref": "resource-schema.json"
6
+ }
@@ -0,0 +1,34 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import schema from './plan-request-data-schema.json';
3
+ import resourceSchema from '../resource-schema.json'
4
+ import {it} from "mocha";
5
+ import assert from "node:assert";
6
+
7
+ const ajv = new Ajv2020({
8
+ strict: true,
9
+ })
10
+ ajv.addSchema(resourceSchema);
11
+
12
+ describe('Plan request data schema', () => {
13
+ it('compiles', () => {
14
+ ajv.compile(schema);
15
+ })
16
+
17
+ it("requires a type field to be specified", () => {
18
+ const validate = ajv.compile(schema);
19
+ assert.equal(validate({ type: "type" }), true)
20
+ assert.equal(validate({}), false)
21
+ })
22
+
23
+ it ("name and type are alpha-numeric and follow variable naming conventions", () => {
24
+ const validate = ajv.compile(schema);
25
+ assert.equal(validate({ type: "a234abcDEF_-"}), true)
26
+ assert.equal(validate({ type: "234"}), false);
27
+ assert.equal(validate({ type: "ABCDEF$"}), false);
28
+
29
+ assert.equal(validate({ type: "type", name: "a234abcDEF_-"}), true)
30
+ assert.equal(validate({ type: "type", name: "234"}), false);
31
+ assert.equal(validate({ type: "type", name: "ABCDEF$"}), false);
32
+ });
33
+
34
+ })
@@ -0,0 +1,53 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/plan-response-data-schema.json",
4
+ "title": "Plan Response Schema Data",
5
+ "type": "object",
6
+ "properties": {
7
+ "planId": {
8
+ "description": "The id of the plan to look up for the apply operation",
9
+ "type": "string",
10
+ "format": "uuid"
11
+ },
12
+ "operation": {
13
+ "description": "The plan operation",
14
+ "type": "string",
15
+ "enum" : ["create", "destroy", "modify", "recreate", "noop"]
16
+ },
17
+ "resourceType": {
18
+ "description": "The resource type",
19
+ "type": "string"
20
+ },
21
+ "resourceName": {
22
+ "description": "The resource name",
23
+ "type": ["string", "null"]
24
+ },
25
+ "parameters": {
26
+ "description": "The properties come from the provided config and is not necessarily every parameter on the ",
27
+ "type": "array",
28
+ "items": {
29
+ "type": "object",
30
+ "properties": {
31
+ "name": {
32
+ "description": "The property name",
33
+ "type": "string"
34
+ },
35
+ "operation": {
36
+ "description": "The operation to be performed on the parameter",
37
+ "type": "string",
38
+ "enum": ["remove", "add", "modify", "noop"]
39
+ },
40
+ "previousValue": {
41
+ "description": "The value before the change"
42
+ },
43
+ "newValue": {
44
+ "description": "The new value"
45
+ }
46
+ },
47
+ "required": ["name", "operation", "previousValue", "newValue"]
48
+ }
49
+ }
50
+ },
51
+ "required": ["planId", "operation", "resourceType", "parameters"],
52
+ "additionalProperties": false
53
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/validate-request-data-schema.json",
4
+ "title": "Validate Request Schema Data",
5
+ "type": "object",
6
+ "properties": {
7
+ "configs": {
8
+ "type": "array",
9
+ "items": {
10
+ "$ref": "resource-schema.json"
11
+ }
12
+ }
13
+ },
14
+ "required": [],
15
+ "additionalProperties": false
16
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/validate-response-data-schema.json",
4
+ "title": "Validate Response Schema Data",
5
+ "type": "null"
6
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/resource-schema.json",
4
+ "title": "Resource Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "type": {
8
+ "description": "All project configs are of the type project",
9
+ "type": "string",
10
+ "const": "project"
11
+ },
12
+ "version": {
13
+ "description": "Semver version. Codify will throw an error if this is not satisfied",
14
+ "type": "string",
15
+ "pattern": "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$"
16
+ },
17
+ "plugins": {
18
+ "type": "object",
19
+ "patternProperties": {
20
+ ".*": {
21
+ "type": "string"
22
+ }
23
+ }
24
+ },
25
+ "description": {
26
+ "description": "An optional description of the codify project",
27
+ "type": "string"
28
+ }
29
+ },
30
+ "additionalProperties": false,
31
+ "required": ["type"]
32
+ }
@@ -0,0 +1,47 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import schema from './project-schema.json';
3
+ import assert from "node:assert";
4
+
5
+ const ajv = new Ajv2020({
6
+ strict: true,
7
+ })
8
+
9
+ describe("project file schema tests", () => {
10
+ it('compiles', () => {
11
+ ajv.compile(schema);
12
+ })
13
+
14
+ it("must have type project", () => {
15
+ const validator = ajv.compile(schema);
16
+ assert.equal(validator({ type: 'project' }), true)
17
+ assert.equal(validator({}), false)
18
+ assert.equal(validator({ type: 'resource' }), false)
19
+ })
20
+
21
+ it("plugins must be <string, string>", () => {
22
+ const validator = ajv.compile(schema);
23
+ assert.equal(validator({
24
+ type: 'project',
25
+ plugins: {
26
+ "plugin1": "3.2.3"
27
+ }
28
+ }), true)
29
+
30
+ assert.equal(validator({
31
+ type: 'project',
32
+ plugins: {
33
+ "plugin1": 1,
34
+ }
35
+ }), false)
36
+
37
+ assert.equal(validator({
38
+ type: 'project',
39
+ plugins: {
40
+ "plugins2": "https://link.to.plugin.com"
41
+ }
42
+ }), true)
43
+ })
44
+
45
+
46
+
47
+ })
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Config file Schema",
4
+ "type": "object",
5
+ "properties": {
6
+ "$id": {
7
+ "type": "string",
8
+ "pattern": "^https://www.codify.com/"
9
+ },
10
+ "type": {
11
+ "const": "object"
12
+ },
13
+ "properties": {
14
+ "type": "object",
15
+ "properties": {
16
+ "type": false,
17
+ "name": false,
18
+ "dependsOn": false,
19
+ "$ref": {
20
+ "const": "https://www.codify.com/resource-schema.json#properties"
21
+ }
22
+ }
23
+ },
24
+ "$ref": {
25
+ "const": "https://www.codify.com/resource-schema.json"
26
+ },
27
+ "unevaluatedProperties": {
28
+ "const": false
29
+ }
30
+ },
31
+ "required": ["unevaluatedProperties", "$ref"]
32
+ }
@@ -0,0 +1,121 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import { describe, it } from 'mocha';
3
+ import schema from './resource-meta-schema.json';
4
+ import resourceSchema from './resource-schema.json';
5
+ import assert from "node:assert";
6
+
7
+ const ajv = new Ajv2020({
8
+ strict: true,
9
+ })
10
+
11
+ describe("Resource meta schema tests", () => {
12
+ it("compiles", () => {
13
+ ajv.compile(schema);
14
+ })
15
+
16
+ it("must have additional properties and $ref to resource-schema specified", () => {
17
+ const validate = ajv.compile(schema);
18
+
19
+ assert.equal(validate({
20
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
21
+ "type": "object",
22
+ "properties": {
23
+ "prop1": {
24
+ "type": "string"
25
+ }
26
+ }
27
+ }), false);
28
+
29
+ assert.equal(validate({
30
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
31
+ "type": "object",
32
+ "properties": {
33
+ "prop1": {
34
+ "type": "string"
35
+ }
36
+ },
37
+ "additionalProperties": false,
38
+ "$ref": "https://www.codify.com/resource-schema.json"
39
+ }), true);
40
+ })
41
+
42
+ it("does not allow resource keywords to be specified", () => {
43
+ const validate = ajv.compile(schema);
44
+
45
+ assert.equal(validate({
46
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
47
+ "type": "object",
48
+ "properties": {
49
+ "type": {
50
+ "type": "string"
51
+ }
52
+ },
53
+ "additionalProperties": false,
54
+ "$ref": "https://www.codify.com/resource-schema.json"
55
+ }), false);
56
+
57
+ assert.equal(validate({
58
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
59
+ "type": "object",
60
+ "properties": {
61
+ "name": {
62
+ "type": "string"
63
+ }
64
+ },
65
+ "additionalProperties": false,
66
+ "$ref": "https://www.codify.com/resource-schema.json"
67
+ }), false);
68
+
69
+ assert.equal(validate({
70
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
71
+ "type": "object",
72
+ "properties": {
73
+ "dependsOn": {
74
+ "type": "array"
75
+ }
76
+ },
77
+ "additionalProperties": false,
78
+ "$ref": "https://www.codify.com/resource-schema.json"
79
+ }), false);
80
+ })
81
+
82
+ it("allows for schema composition with base resource schema", () => {
83
+ const resourceMetaSchema = schema;
84
+ const propertySchema = {
85
+ $id: "https://www.codify.com/property-schema.json",
86
+ type: "object",
87
+ properties: {
88
+ prop1: {
89
+ type: "string"
90
+ },
91
+ prop2: {
92
+ type: "string"
93
+ },
94
+ },
95
+ $ref: "https://www.codify.com/resource-schema.json",
96
+ unevaluatedProperties: false,
97
+ }
98
+
99
+ const resourceConfigInvalid = {
100
+ prop1: "a",
101
+ }
102
+
103
+ const resourceConfigValid = {
104
+ type: "resource-config",
105
+ prop1: "a",
106
+ dependsOn: ["resource-config-2"]
107
+ }
108
+
109
+ const ajv = new Ajv2020({
110
+ strict: true,
111
+ schemas: [resourceSchema]
112
+ });
113
+
114
+ const metaSchemaValidator = ajv.compile(resourceMetaSchema);
115
+ assert.equal(metaSchemaValidator(propertySchema), true)
116
+
117
+ const resourceValidator = ajv.compile(propertySchema);
118
+ assert.equal(resourceValidator(resourceConfigValid), true);
119
+ assert.equal(resourceValidator(resourceConfigInvalid), false);
120
+ })
121
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://www.codify.com/resource-schema.json",
4
+ "title": "Resource Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "type": {
8
+ "description": "The resource type",
9
+ "type": "string",
10
+ "pattern": "^[a-zA-Z-_][\\w-]+$"
11
+ },
12
+ "name": {
13
+ "description": "Optional name. Useful for specifying multiple resources of the same type",
14
+ "type": "string",
15
+ "pattern": "^[a-zA-Z-_][\\w-]+$"
16
+ },
17
+ "dependsOn": {
18
+ "type": "array",
19
+ "items": {
20
+ "type": "string"
21
+ },
22
+ "uniqueItems": true
23
+ }
24
+ },
25
+ "required": ["type"]
26
+ }
@@ -0,0 +1,39 @@
1
+ import Ajv2020 from "ajv/dist/2020";
2
+ import { describe, it } from 'mocha';
3
+ import schema from './resource-schema.json';
4
+ import assert from "node:assert";
5
+
6
+ const ajv = new Ajv2020({
7
+ strict: true,
8
+ })
9
+
10
+ describe("Resource schema tests", () => {
11
+ it("compiles", () => {
12
+ ajv.compile(schema);
13
+ })
14
+
15
+ it("requires a type field to be specified", () => {
16
+ const validate = ajv.compile(schema);
17
+ assert.equal(validate({ type: "type" }), true)
18
+ assert.equal(validate({}), false)
19
+ })
20
+
21
+ it ("name and type are alpha-numeric and follow variable naming conventions", () => {
22
+ const validate = ajv.compile(schema);
23
+ assert.equal(validate({ type: "a234abcDEF_-"}), true)
24
+ assert.equal(validate({ type: "234"}), false);
25
+ assert.equal(validate({ type: "ABCDEF$"}), false);
26
+
27
+ assert.equal(validate({ type: "type", name: "a234abcDEF_-"}), true)
28
+ assert.equal(validate({ type: "type", name: "234"}), false);
29
+ assert.equal(validate({ type: "type", name: "ABCDEF$"}), false);
30
+ });
31
+
32
+ it("dependsOn is an array of unique strings", () => {
33
+ const validate = ajv.compile(schema);
34
+ assert.equal(validate({ type: "type", dependsOn: ["item1", "item2"] }), true)
35
+ assert.equal(validate({ type: "type", dependsOn: ["item1", "item1"] }), false)
36
+ assert.equal(validate({ type: "type", dependsOn: "item1" }), false)
37
+ assert.equal(validate({ type: "type", dependsOn: [6] }), false)
38
+ })
39
+ });
@@ -0,0 +1,63 @@
1
+ export interface ProjectConfig {
2
+ type: string;
3
+ version?: string;
4
+ plugins?: Record<string, string>;
5
+ description?: string;
6
+ }
7
+
8
+ export interface ResourceConfig {
9
+ type: string;
10
+ name?: string;
11
+ dependsOn?: string[];
12
+ }
13
+
14
+ export enum MessageStatus {
15
+ SUCCESS = 'success',
16
+ ERROR = 'error',
17
+ }
18
+
19
+ export interface IpcMessage {
20
+ cmd: string;
21
+ status?: MessageStatus;
22
+ data: unknown | null;
23
+ }
24
+
25
+ export interface ValidateRequestData {
26
+ configs: ResourceConfig[];
27
+ }
28
+
29
+ export type ValidateResponseData = null;
30
+
31
+ export interface PlanRequestData extends ResourceConfig {}
32
+
33
+ export enum ResourceOperation {
34
+ CREATE = "create",
35
+ DESTROY = "destroy",
36
+ MODIFY = "modify",
37
+ RECREATE = "recreate",
38
+ NOOP = "noop"
39
+ }
40
+
41
+ export enum ParameterOperation {
42
+ ADD = "add",
43
+ REMOVE = "remove",
44
+ MODIFY = "modify",
45
+ NOOP = "noop"
46
+ }
47
+
48
+ export interface PlanResponseData {
49
+ planId: string;
50
+ operation: ResourceOperation;
51
+ resourceName?: string;
52
+ resourceType: string;
53
+ parameters: Array<{
54
+ name: string;
55
+ operation: ParameterOperation;
56
+ previousValue: string | null;
57
+ newValue: string | null;
58
+ }>
59
+ }
60
+
61
+ export interface ApplyRequestData {
62
+ planId: string;
63
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es5",
5
+ "sourceMap": true,
6
+ "esModuleInterop": true,
7
+ "resolveJsonModule": true,
8
+ "alwaysStrict": true,
9
+ "noImplicitAny": true,
10
+ "removeComments": true,
11
+ "strictNullChecks": true,
12
+ "declaration": true,
13
+ "emitDecoratorMetadata": true,
14
+ "experimentalDecorators": true,
15
+ "rootDir": "src",
16
+ "outDir": "./dist"
17
+ },
18
+ "exclude": [
19
+ "node_modules",
20
+ "src/**/*.test.ts"
21
+ ],
22
+ "include": [
23
+ "src/**/*.ts"
24
+ ]
25
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "tsconfig.json",
3
+ "compilerOptions": {
4
+ "strictNullChecks": false
5
+ },
6
+ "include": [
7
+ "src/**/*.test.ts"
8
+ ],
9
+ }