Skip to content

Commit 69eabcf

Browse files
committed
Added an ipc message schema
1 parent aa3b387 commit 69eabcf

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

codify-schemas/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as ConfigFileSchema } from './config-file-schema.json';
22
export { default as ProjectSchema } from './project-schema.json';
33
export { default as ResourceMetaSchema } from './resource-meta-schema.json';
4-
export { default as ResourceSchema } from './resource-schema.json';
4+
export { default as ResourceSchema } from './resource-schema.json';
5+
export { default as IpcMessageSchema } from './ipc-message-schema.json';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
"msg": {
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": ["msg", "data"]
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 msg field to be specified", () => {
16+
const validate = ajv.compile(schema);
17+
assert.equal(validate({ msg: "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({ msg: "doSomething", status: "success", data: "data" }), true)
24+
assert.equal(validate({ msg: "doSomething", status: "error", data: "data" }), true)
25+
assert.equal(validate({ msg: "doSomething", status: "other", data: "data" }), false)
26+
assert.equal(validate({ msg: "doSomething", data: "data" }), true)
27+
})
28+
29+
it ("accepts data or null", () => {
30+
const validate = ajv.compile(schema);
31+
assert.equal(validate({ msg: "doSomething", data: "data" }), true)
32+
assert.equal(validate({ msg: "doSomething", data: null }), true)
33+
assert.equal(validate({ msg: "doSomething" }), false)
34+
assert.equal(validate({ msg: "doSomething", data: {} }), true)
35+
});
36+
37+
});

0 commit comments

Comments
 (0)