Template
1
0
Files
boilerplate/platform/storage/storage.ts
2025-09-25 14:29:15 +02:00

22 lines
581 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;
}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export type StorageContext = {};