2026-03-16 21:13:56 -07:00
|
|
|
export type { PluginRuntime } from "../plugins/runtime/types.js";
|
|
|
|
|
|
2026-03-16 01:05:18 -07:00
|
|
|
/** Create a tiny mutable runtime slot with strict access when the runtime has not been initialized. */
|
2026-03-08 19:40:17 +00:00
|
|
|
export function createPluginRuntimeStore<T>(errorMessage: string): {
|
|
|
|
|
setRuntime: (next: T) => void;
|
|
|
|
|
clearRuntime: () => void;
|
|
|
|
|
tryGetRuntime: () => T | null;
|
|
|
|
|
getRuntime: () => T;
|
|
|
|
|
} {
|
|
|
|
|
let runtime: T | null = null;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
setRuntime(next: T) {
|
|
|
|
|
runtime = next;
|
|
|
|
|
},
|
|
|
|
|
clearRuntime() {
|
|
|
|
|
runtime = null;
|
|
|
|
|
},
|
|
|
|
|
tryGetRuntime() {
|
|
|
|
|
return runtime;
|
|
|
|
|
},
|
|
|
|
|
getRuntime() {
|
|
|
|
|
if (!runtime) {
|
|
|
|
|
throw new Error(errorMessage);
|
|
|
|
|
}
|
|
|
|
|
return runtime;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|