Template
1
0
Files
boilerplate/platform/storage/storage.ts
2025-11-23 22:57:43 +01:00

23 lines
530 B
TypeScript

import { AsyncLocalStorage } from "node:async_hooks";
import { InternalServerError } from "@platform/relay";
export const storage = new AsyncLocalStorage<StorageContext>();
/**
* TODO ...
*/
export function getStorageContext(): StorageContext {
const store = storage.getStore();
if (store === undefined) {
throw new InternalServerError(
"Storage 'store' missing, make sure to resolve within a 'node:async_hooks' wrapped context.",
);
}
return store;
}
export interface StorageContext {
id: string;
}