Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an ipfs worker message #40

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,47 @@ export const jsonrpc = {
],
};

export const ipfs = {
type: "object",
properties: {
type: {
type: "string",
enum: ["ipfs"],
},
commissioner: {
type: "string",
},
version: {
type: "string",
},
options: {
type: "object",
properties: {
timeout: {
$comment: "temporal unit is milliseconds",
type: "integer",
},
uri: { type: "string" },
gateway: {
type: "string",
pattern: "^.+ipfs/$",
TimDaub marked this conversation as resolved.
Show resolved Hide resolved
$comment: "http gateway for ipfs should end with ipfs/",
},
},
required: ["uri", "gateway"],
},
results: {
type: "object",
nullable: true,
},
error: {
type: "string",
nullable: true,
},
},
required: ["type", "commissioner", "version", "error", "results", "options"],
};

export const exit = {
type: "object",
required: ["type", "version"],
Expand All @@ -140,7 +181,7 @@ export const exit = {
};

export const workerMessage = {
oneOf: [https, graphql, jsonrpc, exit],
oneOf: [https, graphql, jsonrpc, ipfs, exit],
};

export const config = {
Expand Down
38 changes: 38 additions & 0 deletions test/schema_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
manifestations,
config,
crawlPath,
ipfs,
} from "../src/schema.mjs";

const ajv = new Ajv();
Expand Down Expand Up @@ -331,3 +332,40 @@ test("if crawl path validator throws if transformer.args[0] isn't a string", (t)
t.true(check.errors[0].instancePath.includes("transformer/args/0"));
t.is(check.errors[0].message, "must be string");
});

test("should be a valid ipfs message", async (t) => {
const check = ajv.compile(ipfs);
const message = {
options: {
uri: "ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu",
gateway: `https://ipfs.io/ipfs/`,
},
version: "1.0.0",
type: "ipfs",
commissioner: "test",
results: null,
error: null,
};

const valid = check(message);
t.true(valid);
});

test("ipfs message url should end with ipfs/", async (t) => {
const check = ajv.compile(ipfs);
const message = {
options: {
uri: "ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu",
gateway: `https://ipfs.io/`,
},
version: "1.0.0",
type: "ipfs",
commissioner: "test",
results: null,
error: null,
};

const valid = check(message);
t.false(valid);
t.true(check.errors[0].instancePath.includes("/options/gateway"));
});