@tanstack/start-storage-context 1.166.23 → 1.166.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { Awaitable, RegisteredRouter } from '@tanstack/router-core';
|
|
1
|
+
import { Awaitable, RegisteredRouter, RouterManagedTag } from '@tanstack/router-core';
|
|
2
|
+
export type StartHandlerType = 'router' | 'serverFn';
|
|
2
3
|
export interface StartStorageContext {
|
|
3
4
|
getRouter: () => Awaitable<RegisteredRouter>;
|
|
4
5
|
request: Request;
|
|
5
6
|
startOptions: any;
|
|
6
7
|
contextAfterGlobalMiddlewares: any;
|
|
7
8
|
executedRequestMiddlewares: Set<any>;
|
|
9
|
+
handlerType: StartHandlerType;
|
|
10
|
+
/**
|
|
11
|
+
* Additional assets to inject for this request.
|
|
12
|
+
* Plugins can push RouterManagedTag items here during request processing.
|
|
13
|
+
* Merged into manifest at dehydration time without mutating cached manifest.
|
|
14
|
+
*/
|
|
15
|
+
requestAssets?: Array<RouterManagedTag>;
|
|
8
16
|
}
|
|
9
17
|
export declare function runWithStartContext<T>(context: StartStorageContext, fn: () => T | Promise<T>): Promise<T>;
|
|
10
18
|
export declare function getStartContext<TThrow extends boolean = true>(opts?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-local-storage.js","names":[],"sources":["../../src/async-local-storage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type {
|
|
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 RegisteredRouter,\n RouterManagedTag,\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 push RouterManagedTag items here during request processing.\n * Merged into manifest at dehydration time without mutating cached manifest.\n */\n requestAssets?: Array<RouterManagedTag>\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"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { getStartContext, runWithStartContext } from './async-local-storage.js';
|
|
2
|
-
export type { StartStorageContext } from './async-local-storage.js';
|
|
2
|
+
export type { StartStorageContext, StartHandlerType, } from './async-local-storage.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-storage-context",
|
|
3
|
-
"version": "1.166.
|
|
3
|
+
"version": "1.166.25",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node": ">=22.12.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tanstack/router-core": "1.168.
|
|
46
|
+
"@tanstack/router-core": "1.168.11"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"vite": "*",
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Awaitable,
|
|
4
|
+
RegisteredRouter,
|
|
5
|
+
RouterManagedTag,
|
|
6
|
+
} from '@tanstack/router-core'
|
|
7
|
+
|
|
8
|
+
export type StartHandlerType = 'router' | 'serverFn'
|
|
3
9
|
|
|
4
10
|
export interface StartStorageContext {
|
|
5
11
|
getRouter: () => Awaitable<RegisteredRouter>
|
|
@@ -11,6 +17,15 @@ export interface StartStorageContext {
|
|
|
11
17
|
// Track middlewares that have already executed in the request phase
|
|
12
18
|
// to prevent duplicate execution
|
|
13
19
|
executedRequestMiddlewares: Set<any>
|
|
20
|
+
// Type of handler processing this request
|
|
21
|
+
handlerType: StartHandlerType
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Additional assets to inject for this request.
|
|
25
|
+
* Plugins can push RouterManagedTag items here during request processing.
|
|
26
|
+
* Merged into manifest at dehydration time without mutating cached manifest.
|
|
27
|
+
*/
|
|
28
|
+
requestAssets?: Array<RouterManagedTag>
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
// Use a global symbol to ensure the same AsyncLocalStorage instance is shared
|
package/src/index.tsx
CHANGED