Skip to content

Commit

Permalink
Merge pull request #339 from hyper63/twilson63/bug-connect-not-publis…
Browse files Browse the repository at this point in the history
…hing-336

considering adding proxy.js for deno hyper connect
  • Loading branch information
twilson63 committed Oct 1, 2021
2 parents 6e221e2 + 488f997 commit e685de4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hyper/monorepo",
"name": "@hyper/monorepo",
"version": "1.0.0",
"private": true,
"description": "one api, many services...",
Expand Down
1 change: 1 addition & 0 deletions packages/connect/egg.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"./deps.js",
"./egg.json",
"./mod.js",
"./proxy.js",
"./README.md",
"./utils.js",
"./lib/*.js"
Expand Down
39 changes: 39 additions & 0 deletions packages/connect/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import connect from "./connect.js";

const h = connect(Deno.env.get("HYPER") || "http://localhost:6363/app")();

const SERVICES = ["data", "storage", "search", "cache", "queue"];
const ACTIONS = [
"add",
"get",
"list",
"update",
"remove",
"query",
"index",
"load",
"set",
"create",
"destroy",
"bulk",
];

export const hyper = new Proxy({}, {
get(_t, service) {
return new Proxy({}, {
get(_t2, action) {
return async function (...params) {
if (!SERVICES.includes(service)) {
throw new Error(`ERROR: ${service} not in ${SERVICES}`);
}
if (!ACTIONS.includes(action)) {
throw new Error(`ERROR: ${action} not in ${ACTIONS}`);
}
return fetch(await h[service][action](...params)).then((r) =>
r.json()
);
};
},
});
},
});

0 comments on commit e685de4

Please sign in to comment.