-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from hyper63/twilson63/bug-connect-not-publis…
…hing-336 considering adding proxy.js for deno hyper connect
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"./deps.js", | ||
"./egg.json", | ||
"./mod.js", | ||
"./proxy.js", | ||
"./README.md", | ||
"./utils.js", | ||
"./lib/*.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
}; | ||
}, | ||
}); | ||
}, | ||
}); |