Skip to content

Commit

Permalink
Merge pull request #115 from open-rpc/fix/web-support
Browse files Browse the repository at this point in the history
fix: add browser support
  • Loading branch information
shanejonas authored May 30, 2019
2 parents de1ef7c + a14852f commit 7b18afd
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 158 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
resetMocks: true,
restoreMocks: true,
rootDir: './src',
testEnvironment: 'node',
preset: 'ts-jest',
testEnvironment: 'jsdom',
preset: 'ts-jest'
};
113 changes: 72 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.0.0-semantic-release-dev",
"description": "",
"main": "build/src/index.js",
"browser": "build/src/index-web.js",
"scripts": {
"build": "npm run build:code && npm run build:docs",
"build:docs": "typedoc",
Expand All @@ -29,16 +30,16 @@
},
"homepage": "https://github.com/open-rpc/schema-utils-js#readme",
"dependencies": {
"@open-rpc/meta-schema": "^1.3.1",
"@open-rpc/meta-schema": "^1.3.2",
"ajv": "^6.10.0",
"detect-node": "^2.0.4",
"fs-extra": "^7.0.1",
"is-url": "^1.2.4",
"json-schema-ref-parser": "^6.0.3",
"node-fetch": "^2.3.0"
"isomorphic-fetch": "^2.2.1",
"json-schema-ref-parser": "^6.0.3"
},
"devDependencies": {
"@qiwi/semantic-release-gh-pages-plugin": "^1.6.2",
"@qiwi/semantic-release-gh-pages-plugin": "^1.9.1",
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/commit-analyzer": "^6.1.0",
"@semantic-release/git": "^7.0.8",
Expand All @@ -48,6 +49,7 @@
"@types/detect-node": "^2.0.0",
"@types/fs-extra": "^7.0.0",
"@types/is-url": "^1.2.28",
"@types/isomorphic-fetch": "0.0.35",
"@types/jest": "^24.0.11",
"@types/json-schema": "^7.0.3",
"@types/lodash": "^4.14.123",
Expand Down
17 changes: 17 additions & 0 deletions src/get-open-rpc-document-from-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { OpenRPC } from "@open-rpc/meta-schema";
import { readJson } from "fs-extra";
import { TGetOpenRPCDocument } from "./get-open-rpc-document";

const readSchemaFromFile: TGetOpenRPCDocument = async (filePath: string) => {
try {
return await readJson(filePath) as OpenRPC;
} catch (e) {
if (e.message.includes("SyntaxError")) {
throw new Error(`Failed to parse json in file ${filePath}`);
} else {
throw new Error(`Unable to read openrpc.json file located at ${filePath}`);
}
}
};

export default readSchemaFromFile;
14 changes: 14 additions & 0 deletions src/get-open-rpc-document-from-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { OpenRPC } from "@open-rpc/meta-schema";
import fetch from "isomorphic-fetch";
import { TGetOpenRPCDocument } from "./get-open-rpc-document";

const fetchUrlSchema: TGetOpenRPCDocument = async (schema) => {
try {
const response = await fetch(schema);
return await response.json() as OpenRPC;
} catch (e) {
throw new Error(`Unable to download openrpc.json file located at the url: ${schema}`);
}
};

export default fetchUrlSchema;
Loading

0 comments on commit 7b18afd

Please sign in to comment.