Standardize code style to no semicolons and remove unused @types/node dependency

🤖 Generated with opencode
Co-Authored-By: opencode <noreply@opencode.ai>
This commit is contained in:
Dax Raad
2025-05-30 22:14:09 -04:00
parent fba56d6871
commit 6df19f1828
4 changed files with 217 additions and 215 deletions

View File

@@ -1,60 +1,61 @@
import { App } from "../app/app";
import { Bus } from "../bus";
import { Session } from "../session/session";
import { Storage } from "../storage/storage";
import { Log } from "../util/log";
import { App } from "../app/app"
import { Bus } from "../bus"
import { Session } from "../session/session"
import { Storage } from "../storage/storage"
import { Log } from "../util/log"
export namespace Share {
const log = Log.create({ service: "share" });
const log = Log.create({ service: "share" })
let queue: Promise<void> = Promise.resolve();
const pending = new Map<string, any>();
let queue: Promise<void> = Promise.resolve()
const pending = new Map<string, any>()
const state = App.state("share", async () => {
Bus.subscribe(Storage.Event.Write, async (payload) => {
const [root, ...splits] = payload.properties.key.split("/");
if (root !== "session") return;
const [, sessionID] = splits;
const session = await Session.get(sessionID);
if (!session.share) return;
const { secret } = session.share;
await sync(payload.properties.key, payload.properties.content)
})
})
const key = payload.properties.key;
pending.set(key, payload.properties.content);
export async function sync(key: string, content: any) {
const [root, ...splits] = key.split("/")
if (root !== "session") return
const [, sessionID] = splits
const session = await Session.get(sessionID)
if (!session.share) return
const { secret } = session.share
pending.set(key, content)
queue = queue
.then(async () => {
const content = pending.get(key)
if (content === undefined) return
pending.delete(key)
queue = queue
.then(async () => {
const content = pending.get(key);
if (content === undefined) return;
pending.delete(key);
return fetch(`${URL}/share_sync`, {
method: "POST",
body: JSON.stringify({
sessionID: sessionID,
secret,
key: key,
content,
}),
});
return fetch(`${URL}/share_sync`, {
method: "POST",
body: JSON.stringify({
sessionID: sessionID,
secret,
key: key,
content,
}),
})
.then((x) => {
if (x) {
log.info("synced", {
key: key,
status: x.status,
});
}
});
});
});
})
.then((x) => {
if (x) {
log.info("synced", {
key: key,
status: x.status,
})
}
})
}
export async function init() {
await state();
await state()
}
export const URL =
process.env["OPENCODE_API"] ?? "https://api.dev.opencode.ai";
process.env["OPENCODE_API"] ?? "https://api.dev.opencode.ai"
export async function create(sessionID: string) {
return fetch(`${URL}/share_create`, {
@@ -62,6 +63,6 @@ export namespace Share {
body: JSON.stringify({ sessionID: sessionID }),
})
.then((x) => x.json())
.then((x) => x as { url: string; secret: string });
.then((x) => x as { url: string; secret: string })
}
}