type PluginRuntimeStoreRegistry = Map<string, { runtime: unknown }>;
type PluginRuntimeStoreKeyOptions = {
key: string;
errorMessage: string;
};
type PluginRuntimeStorePluginOptions = {
pluginId: string;
errorMessage: string;
};
type PluginRuntimeStoreOptions = PluginRuntimeStoreKeyOptions | PluginRuntimeStorePluginOptions;
function getPluginRuntimeStoreRegistry(): PluginRuntimeStoreRegistry { const globalRecord = globalThis as typeof globalThis & {
[pluginRuntimeStoreRegistryKey]?: PluginRuntimeStoreRegistry;
};
globalRecord[pluginRuntimeStoreRegistryKey] ??= new Map(); return globalRecord[pluginRuntimeStoreRegistryKey];
}
function pluginRuntimeStoreKeyForPluginId(pluginId: string): string { const normalizedPluginId = pluginId.trim(); if (!normalizedPluginId) { thrownew Error("createPluginRuntimeStore: pluginId must not be empty");
} return `plugin-runtime:${normalizedPluginId}`;
}
function resolvePluginRuntimeStoreOptions(
options: string | PluginRuntimeStoreOptions,
): PluginRuntimeStoreKeyOptions { if (typeof options === "string") { return { key: options, errorMessage: options };
} if ("pluginId" in options) { return {
key: pluginRuntimeStoreKeyForPluginId(options.pluginId),
errorMessage: options.errorMessage,
};
} return options;
}
/** Create a tiny mutable runtime slot with strict access when the runtime has not been initialized. */
export function createPluginRuntimeStore<T>(errorMessage: string): {
setRuntime: (next: T) => void;
clearRuntime: () => void;
tryGetRuntime: () => T | null;
getRuntime: () => T;
};
export function createPluginRuntimeStore<T>(options: PluginRuntimeStoreOptions): {
setRuntime: (next: T) => void;
clearRuntime: () => void;
tryGetRuntime: () => T | null;
getRuntime: () => T;
};
export function createPluginRuntimeStore<T>(options: string | PluginRuntimeStoreOptions): {
setRuntime: (next: T) => void;
clearRuntime: () => void;
tryGetRuntime: () => T | null;
getRuntime: () => T;
} { const resolved = resolvePluginRuntimeStoreOptions(options); const slot = typeof options === "string"
? { runtime: null }
: (() => { const registry = getPluginRuntimeStoreRegistry();
let existingSlot = registry.get(resolved.key); if (!existingSlot) {
existingSlot = { runtime: null };
registry.set(resolved.key, existingSlot);
} return existingSlot;
})();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.