Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Dec 24, 2023
1 parent be8a51d commit e4c4469
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 16 deletions.
1 change: 1 addition & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const args = yargs(Deno.args)
description: "List API tokens",
boolean: true,
}).strict().check(
// deno-lint-ignore no-explicit-any
({ g, c, d, l }: any) =>
[g, c, d, l].filter((o) => o != undefined).length == 1
? true
Expand Down
20 changes: 10 additions & 10 deletions cli/src/keyManipulation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { callServer } from "./rpc.ts";
import { inputToCacheKey } from "../../client/src/index.ts";
import { sideLog } from "gamla";

const parseCacheIdAndKey = (hashKey: (...xs: any[]) => string, x: string) => {
const [cacheId, key] = x.split(" ");
return { cacheId, key: hashKey(...JSON.parse(key)) };
const actOnKey = (method: string) => (args: string) => () => {
const [token, cacheId, key] = args.split(" ");
return callServer("", "POST", {
method,
params: {
cacheId,
key: inputToCacheKey(token, undefined)(...sideLog(JSON.parse(key))),
},
})(token);
};
const actOnKey = (action: string) => (args: string) => (secret: string) =>
callServer("", "POST", {
action,
...parseCacheIdAndKey(inputToCacheKey(secret, undefined), args),
})(
secret,
);

export const keyManipulations = {
delete: actOnKey("delete"),
Expand Down
16 changes: 10 additions & 6 deletions cli/src/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { sideLog } from "gamla";
const serverURL = Deno.env.get("RMMBR_SERVER");

export const callServer = (
path: string,
method: "GET" | "POST",
body: undefined | Record<string, string>,
body: any,
) =>
(accessToken: string) =>
fetch(`${serverURL}/${path}`, {
headers: { Authorization: `Bearer ${accessToken}` },
method,
body: JSON.stringify(body),
}).then(
fetch(
`${serverURL}/${path}`,
{
headers: { Authorization: `Bearer ${accessToken}` },
method,
body: JSON.stringify(body),
},
).then(
async (response) =>
response.status === 200
? response.json()
Expand Down
3 changes: 3 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"imports": {
"gamla": "https://deno.land/x/[email protected]/src/index.ts"
},
"tasks": {
"server": "export REDIS_PORT=6666; export REDIS_URL=127.0.0.1; export REDIS_PASSWORD=12345; export PORT=8000; deno run --allow-read --allow-net --allow-env server/src/index.ts",
"server-repl": "export REDIS_PORT=6666; export REDIS_URL=127.0.0.1; export REDIS_PASSWORD=12345; export PORT=8000; deno",
Expand Down
Loading

0 comments on commit e4c4469

Please sign in to comment.