Start on plugin ctx API (#64)

This commit is contained in:
Gregory Schier
2024-08-14 06:42:54 -07:00
committed by GitHub
parent e47a2c5fab
commit 12f4c2c668
106 changed files with 1086 additions and 1219 deletions

View File

@@ -17,6 +17,20 @@ export async function setKeyValue<T>({
});
}
export async function getKeyValueRaw({
namespace = 'global',
key,
}: {
namespace?: string;
key: string | string[];
}) {
const kv = (await invokeCmd('cmd_get_key_value', {
namespace,
key: buildKeyValueKey(key),
})) as KeyValue | null;
return kv;
}
export async function getKeyValue<T>({
namespace = 'global',
key,
@@ -26,14 +40,11 @@ export async function getKeyValue<T>({
key: string | string[];
fallback: T;
}) {
const kv = (await invokeCmd('cmd_get_key_value', {
namespace,
key: buildKeyValueKey(key),
})) as KeyValue | null;
const kv = await getKeyValueRaw({ namespace, key });
return extractKeyValueOrFallback(kv, fallback);
}
function extractKeyValue<T>(kv: KeyValue | null): T | undefined {
export function extractKeyValue<T>(kv: KeyValue | null): T | undefined {
if (kv === null) return undefined;
try {
return JSON.parse(kv.value) as T;