mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-16 08:41:03 +02:00
Migrate strict Effect runtime surfaces
This commit is contained in:
parent
f6878d4dd7
commit
b4ee2b691f
35 changed files with 1717 additions and 1410 deletions
|
|
@ -5,7 +5,8 @@
|
|||
*/
|
||||
|
||||
import type { Command } from "commander";
|
||||
import { createSocket, getOpts } from "./util.js";
|
||||
import { Effect } from "effect";
|
||||
import { cliCommandError, withSocket, writeJson } from "./util.js";
|
||||
|
||||
export function registerConfigCommands(program: Command): void {
|
||||
const config = program
|
||||
|
|
@ -15,28 +16,26 @@ export function registerConfigCommands(program: Command): void {
|
|||
config
|
||||
.command("show")
|
||||
.description("Show current configuration")
|
||||
.action(async (_opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
.action((_opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket) =>
|
||||
Effect.gen(function* () {
|
||||
const cfg = socket.config();
|
||||
const resp = await cfg.getConfigAll();
|
||||
console.log(JSON.stringify(resp, null, 2));
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
const resp = yield* Effect.tryPromise({
|
||||
try: () => cfg.getConfigAll(),
|
||||
catch: (error) => cliCommandError("config.show", error),
|
||||
});
|
||||
yield* writeJson(resp);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
|
||||
config
|
||||
.command("get")
|
||||
.description("Get a configuration value")
|
||||
.argument("<key>", "Config key (format: type/key)")
|
||||
.action(async (key: string, _opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
.action((key: string, _opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket) =>
|
||||
Effect.gen(function* () {
|
||||
const cfg = socket.config();
|
||||
// Support "type/key" format; fall back to using the whole string as key
|
||||
const parts = key.split("/");
|
||||
|
|
@ -44,72 +43,74 @@ export function registerConfigCommands(program: Command): void {
|
|||
parts.length >= 2
|
||||
? { type: parts[0], key: parts.slice(1).join("/") }
|
||||
: { type: "config", key };
|
||||
const resp = await cfg.getConfig([configKey]);
|
||||
console.log(JSON.stringify(resp, null, 2));
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
const resp = yield* Effect.tryPromise({
|
||||
try: () => cfg.getConfig([configKey]),
|
||||
catch: (error) => cliCommandError("config.get", error),
|
||||
});
|
||||
yield* writeJson(resp);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
|
||||
config
|
||||
.command("set")
|
||||
.description("Set a configuration value")
|
||||
.argument("<key>", "Config key (format: type/key)")
|
||||
.argument("<value>", "Config value (JSON)")
|
||||
.action(async (key: string, value: string, _opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
.action((key: string, value: string, _opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket) =>
|
||||
Effect.gen(function* () {
|
||||
const cfg = socket.config();
|
||||
const parts = key.split("/");
|
||||
const configEntry =
|
||||
parts.length >= 2
|
||||
? { type: parts[0], key: parts.slice(1).join("/"), value }
|
||||
: { type: "config", key, value };
|
||||
const resp = await cfg.putConfig([configEntry]);
|
||||
console.log(JSON.stringify(resp, null, 2));
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
const resp = yield* Effect.tryPromise({
|
||||
try: () => cfg.putConfig([configEntry]),
|
||||
catch: (error) => cliCommandError("config.set", error),
|
||||
});
|
||||
yield* writeJson(resp);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
|
||||
config
|
||||
.command("list")
|
||||
.description("List configuration keys for a type")
|
||||
.argument("[type]", "Config type to list", "config")
|
||||
.action(async (type: string, _opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
.action((type: string, _opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket) =>
|
||||
Effect.gen(function* () {
|
||||
const cfg = socket.config();
|
||||
const resp = await cfg.list(type);
|
||||
console.log(JSON.stringify(resp, null, 2));
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
const resp = yield* Effect.tryPromise({
|
||||
try: () => cfg.list(type),
|
||||
catch: (error) => cliCommandError("config.list", error),
|
||||
});
|
||||
yield* writeJson(resp);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
|
||||
config
|
||||
.command("delete")
|
||||
.description("Delete a configuration entry")
|
||||
.argument("<key>", "Config key (format: type/key)")
|
||||
.action(async (key: string, _opts, cmd) => {
|
||||
const opts = getOpts(cmd);
|
||||
const socket = await createSocket(opts);
|
||||
|
||||
try {
|
||||
.action((key: string, _opts, cmd) =>
|
||||
Effect.runPromise(withSocket(cmd, (socket) =>
|
||||
Effect.gen(function* () {
|
||||
const cfg = socket.config();
|
||||
const parts = key.split("/");
|
||||
const configKey =
|
||||
parts.length >= 2
|
||||
? { type: parts[0], key: parts.slice(1).join("/") }
|
||||
: { type: "config", key };
|
||||
const resp = await cfg.deleteConfig(configKey);
|
||||
console.log(JSON.stringify(resp, null, 2));
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
const resp = yield* Effect.tryPromise({
|
||||
try: () => cfg.deleteConfig(configKey),
|
||||
catch: (error) => cliCommandError("config.delete", error),
|
||||
});
|
||||
yield* writeJson(resp);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue