@genkit-ai/core
Version:
Genkit AI framework core libraries.
1 lines • 1.8 kB
Source Map (JSON)
{"version":3,"sources":["../src/node-async-context.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { AsyncContext, setAsyncContext } from './async-context.js';\n\n/**\n * Manages AsyncLocalStorage instances in a single place.\n */\nexport class NodeAsyncContext implements AsyncContext {\n private asls: Record<string, AsyncLocalStorage<any>> = {};\n\n getStore<T>(key: string): T | undefined {\n return this.asls[key]?.getStore();\n }\n\n run<T, R>(key: string, store: T, callback: () => R): R {\n if (!this.asls[key]) {\n this.asls[key] = new AsyncLocalStorage<T>();\n }\n return this.asls[key].run(store, callback);\n }\n}\n\nexport function initNodeAsyncContext() {\n setAsyncContext(new NodeAsyncContext());\n}\n"],"mappings":"AAgBA,SAAS,yBAAyB;AAClC,SAAuB,uBAAuB;AAKvC,MAAM,iBAAyC;AAAA,EAC5C,OAA+C,CAAC;AAAA,EAExD,SAAY,KAA4B;AACtC,WAAO,KAAK,KAAK,GAAG,GAAG,SAAS;AAAA,EAClC;AAAA,EAEA,IAAU,KAAa,OAAU,UAAsB;AACrD,QAAI,CAAC,KAAK,KAAK,GAAG,GAAG;AACnB,WAAK,KAAK,GAAG,IAAI,IAAI,kBAAqB;AAAA,IAC5C;AACA,WAAO,KAAK,KAAK,GAAG,EAAE,IAAI,OAAO,QAAQ;AAAA,EAC3C;AACF;AAEO,SAAS,uBAAuB;AACrC,kBAAgB,IAAI,iBAAiB,CAAC;AACxC;","names":[]}