@tanstack/start-storage-context
Advanced tools
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"async-local-storage.js","names":[],"sources":["../../src/async-local-storage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type {\n Awaitable,\n ManifestRouteAssets,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\nexport type StartHandlerType = 'router' | 'serverFn'\n\nexport interface StartStorageContext {\n getRouter: () => Awaitable<RegisteredRouter>\n request: Request\n // TODO type this properly\n startOptions: /* AnyStartInstanceOptions*/ any\n\n contextAfterGlobalMiddlewares: any\n // Track middlewares that have already executed in the request phase\n // to prevent duplicate execution\n executedRequestMiddlewares: Set<any>\n // Type of handler processing this request\n handlerType: StartHandlerType\n\n /**\n * Additional assets to inject for this request.\n * Plugins can add manifest route assets here during request processing.\n * Merged into manifest at dehydration time without mutating cached manifest.\n */\n requestAssets?: ManifestRouteAssets\n}\n\n// Use a global symbol to ensure the same AsyncLocalStorage instance is shared\n// across different bundles that may each bundle this module.\nconst GLOBAL_STORAGE_KEY = Symbol.for('tanstack-start:start-storage-context')\n\nconst globalObj = globalThis as typeof globalThis & {\n [GLOBAL_STORAGE_KEY]?: AsyncLocalStorage<StartStorageContext>\n}\n\nif (!globalObj[GLOBAL_STORAGE_KEY]) {\n globalObj[GLOBAL_STORAGE_KEY] = new AsyncLocalStorage<StartStorageContext>()\n}\n\nconst startStorage = globalObj[GLOBAL_STORAGE_KEY]\n\nexport async function runWithStartContext<T>(\n context: StartStorageContext,\n fn: () => T | Promise<T>,\n): Promise<T> {\n return startStorage.run(context, fn)\n}\n\nexport function getStartContext<TThrow extends boolean = true>(opts?: {\n throwIfNotFound?: TThrow\n}): TThrow extends false\n ? StartStorageContext | undefined\n : StartStorageContext {\n const context = startStorage.getStore()\n if (!context && opts?.throwIfNotFound !== false) {\n throw new Error(\n `No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,\n )\n }\n return context as any\n}\n"],"mappings":";;AAgCA,IAAM,qBAAqB,OAAO,IAAI,uCAAuC;AAE7E,IAAM,YAAY;AAIlB,IAAI,CAAC,UAAU,oBACb,WAAU,sBAAsB,IAAI,mBAAwC;AAG9E,IAAM,eAAe,UAAU;AAE/B,eAAsB,oBACpB,SACA,IACY;AACZ,QAAO,aAAa,IAAI,SAAS,GAAG;;AAGtC,SAAgB,gBAA+C,MAIvC;CACtB,MAAM,UAAU,aAAa,UAAU;AACvC,KAAI,CAAC,WAAW,MAAM,oBAAoB,MACxC,OAAM,IAAI,MACR,+GACD;AAEH,QAAO"} | ||
| {"version":3,"file":"async-local-storage.js","names":[],"sources":["../../src/async-local-storage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type {\n Awaitable,\n ManifestRouteAssets,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\nexport type StartHandlerType = 'router' | 'serverFn'\n\nexport interface StartStorageContext {\n getRouter: () => Awaitable<RegisteredRouter>\n request: Request\n // TODO type this properly\n startOptions: /* AnyStartInstanceOptions*/ any\n\n contextAfterGlobalMiddlewares: any\n // Track middlewares that have already executed in the request phase\n // to prevent duplicate execution\n executedRequestMiddlewares: Set<any>\n // Type of handler processing this request\n handlerType: StartHandlerType\n\n /**\n * Additional assets to inject for this request.\n * Plugins can add manifest route assets here during request processing.\n * Merged into manifest at dehydration time without mutating cached manifest.\n */\n requestAssets?: ManifestRouteAssets\n}\n\n// Use a global symbol to ensure the same AsyncLocalStorage instance is shared\n// across different bundles that may each bundle this module.\nconst GLOBAL_STORAGE_KEY = Symbol.for('tanstack-start:start-storage-context')\n\nconst globalObj = globalThis as typeof globalThis & {\n [GLOBAL_STORAGE_KEY]?: AsyncLocalStorage<StartStorageContext>\n}\n\nif (!globalObj[GLOBAL_STORAGE_KEY]) {\n globalObj[GLOBAL_STORAGE_KEY] = new AsyncLocalStorage<StartStorageContext>()\n}\n\nconst startStorage = globalObj[GLOBAL_STORAGE_KEY]\n\nexport async function runWithStartContext<T>(\n context: StartStorageContext,\n fn: () => T | Promise<T>,\n): Promise<T> {\n return startStorage.run(context, fn)\n}\n\nexport function getStartContext<TThrow extends boolean = true>(opts?: {\n throwIfNotFound?: TThrow\n}): TThrow extends false\n ? StartStorageContext | undefined\n : StartStorageContext {\n const context = startStorage.getStore()\n if (!context && opts?.throwIfNotFound !== false) {\n throw new Error(\n `No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,\n )\n }\n return context as any\n}\n"],"mappings":";;AAgCA,IAAM,qBAAqB,OAAO,IAAI,sCAAsC;AAE5E,IAAM,YAAY;AAIlB,IAAI,CAAC,UAAU,qBACb,UAAU,sBAAsB,IAAI,kBAAuC;AAG7E,IAAM,eAAe,UAAU;AAE/B,eAAsB,oBACpB,SACA,IACY;CACZ,OAAO,aAAa,IAAI,SAAS,EAAE;AACrC;AAEA,SAAgB,gBAA+C,MAIvC;CACtB,MAAM,UAAU,aAAa,SAAS;CACtC,IAAI,CAAC,WAAW,MAAM,oBAAoB,OACxC,MAAM,IAAI,MACR,8GACF;CAEF,OAAO;AACT"} |
+2
-2
| { | ||
| "name": "@tanstack/start-storage-context", | ||
| "version": "1.167.8", | ||
| "version": "1.167.9", | ||
| "description": "Modern and scalable routing for React applications", | ||
@@ -46,3 +46,3 @@ "author": "Tanner Linsley", | ||
| "dependencies": { | ||
| "@tanstack/router-core": "1.171.6" | ||
| "@tanstack/router-core": "1.171.7" | ||
| }, | ||
@@ -49,0 +49,0 @@ "devDependencies": { |
10603
0.08%+ Added
- Removed