@tanstack/start-storage-context 1.129.0
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.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/cjs/async-local-storage.cjs +19 -0
- package/dist/cjs/async-local-storage.cjs.map +1 -0
- package/dist/cjs/async-local-storage.d.cts +8 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/esm/async-local-storage.d.ts +8 -0
- package/dist/esm/async-local-storage.js +19 -0
- package/dist/esm/async-local-storage.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +53 -0
- package/src/async-local-storage.ts +29 -0
- package/src/index.tsx +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<img src="https://static.scarf.sh/a.png?x-pxid=d988eb79-b0fc-4a2b-8514-6a1ab932d188" />
|
|
2
|
+
|
|
3
|
+
# TanStack Start - Storage Context
|
|
4
|
+
|
|
5
|
+
This package is not meant to be used directly. It is a dependency of the TanStack Start framework-specific packages:
|
|
6
|
+
|
|
7
|
+
- [`@tanstack/react-start`](https://www.npmjs.com/package/@tanstack/react-start)
|
|
8
|
+
- [`@tanstack/solid-start`](https://www.npmjs.com/package/@tanstack/solid-start).
|
|
9
|
+
|
|
10
|
+
It provides the core functionality for TanStack Start, which is a fullstack-framework made for SSR, Streaming, Server Functions, API Routes, bundling and more powered by [TanStack Router](https://tanstack.com/router).
|
|
11
|
+
|
|
12
|
+
Head over to [tanstack.com/start](https://tanstack.com/start) for more information about getting started.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_async_hooks = require("node:async_hooks");
|
|
4
|
+
const startStorage = new node_async_hooks.AsyncLocalStorage();
|
|
5
|
+
async function runWithStartContext(context, fn) {
|
|
6
|
+
return startStorage.run(context, fn);
|
|
7
|
+
}
|
|
8
|
+
function getStartContext(opts) {
|
|
9
|
+
const context = startStorage.getStore();
|
|
10
|
+
if (!context && (opts == null ? void 0 : opts.throwIfNotFound) !== false) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
exports.getStartContext = getStartContext;
|
|
18
|
+
exports.runWithStartContext = runWithStartContext;
|
|
19
|
+
//# sourceMappingURL=async-local-storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-local-storage.cjs","sources":["../../src/async-local-storage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport interface StartStorageContext {\n router: AnyRouter\n}\n\nconst startStorage = new AsyncLocalStorage<StartStorageContext>()\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"],"names":["AsyncLocalStorage"],"mappings":";;;AAOA,MAAM,eAAe,IAAIA,iBAAAA,kBAAuC;AAE1C,eAAA,oBACpB,SACA,IACY;AACL,SAAA,aAAa,IAAI,SAAS,EAAE;AACrC;AAEO,SAAS,gBAA+C,MAIvC;AAChB,QAAA,UAAU,aAAa,SAAS;AACtC,MAAI,CAAC,YAAW,6BAAM,qBAAoB,OAAO;AAC/C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEK,SAAA;AACT;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyRouter } from '@tanstack/router-core';
|
|
2
|
+
export interface StartStorageContext {
|
|
3
|
+
router: AnyRouter;
|
|
4
|
+
}
|
|
5
|
+
export declare function runWithStartContext<T>(context: StartStorageContext, fn: () => T | Promise<T>): Promise<T>;
|
|
6
|
+
export declare function getStartContext<TThrow extends boolean = true>(opts?: {
|
|
7
|
+
throwIfNotFound?: TThrow;
|
|
8
|
+
}): TThrow extends false ? StartStorageContext | undefined : StartStorageContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const asyncLocalStorage = require("./async-local-storage.cjs");
|
|
4
|
+
exports.getStartContext = asyncLocalStorage.getStartContext;
|
|
5
|
+
exports.runWithStartContext = asyncLocalStorage.runWithStartContext;
|
|
6
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyRouter } from '@tanstack/router-core';
|
|
2
|
+
export interface StartStorageContext {
|
|
3
|
+
router: AnyRouter;
|
|
4
|
+
}
|
|
5
|
+
export declare function runWithStartContext<T>(context: StartStorageContext, fn: () => T | Promise<T>): Promise<T>;
|
|
6
|
+
export declare function getStartContext<TThrow extends boolean = true>(opts?: {
|
|
7
|
+
throwIfNotFound?: TThrow;
|
|
8
|
+
}): TThrow extends false ? StartStorageContext | undefined : StartStorageContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
const startStorage = new AsyncLocalStorage();
|
|
3
|
+
async function runWithStartContext(context, fn) {
|
|
4
|
+
return startStorage.run(context, fn);
|
|
5
|
+
}
|
|
6
|
+
function getStartContext(opts) {
|
|
7
|
+
const context = startStorage.getStore();
|
|
8
|
+
if (!context && (opts == null ? void 0 : opts.throwIfNotFound) !== false) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
`No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
getStartContext,
|
|
17
|
+
runWithStartContext
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=async-local-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-local-storage.js","sources":["../../src/async-local-storage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport interface StartStorageContext {\n router: AnyRouter\n}\n\nconst startStorage = new AsyncLocalStorage<StartStorageContext>()\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"],"names":[],"mappings":";AAOA,MAAM,eAAe,IAAI,kBAAuC;AAE1C,eAAA,oBACpB,SACA,IACY;AACL,SAAA,aAAa,IAAI,SAAS,EAAE;AACrC;AAEO,SAAS,gBAA+C,MAIvC;AAChB,QAAA,UAAU,aAAa,SAAS;AACtC,MAAI,CAAC,YAAW,6BAAM,qBAAoB,OAAO;AAC/C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEK,SAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/start-storage-context",
|
|
3
|
+
"version": "1.129.0",
|
|
4
|
+
"description": "Modern and scalable routing for React applications",
|
|
5
|
+
"author": "Tanner Linsley",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/router.git",
|
|
10
|
+
"directory": "packages/start-storage-context"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://tanstack.com/start",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react",
|
|
19
|
+
"location",
|
|
20
|
+
"router",
|
|
21
|
+
"routing",
|
|
22
|
+
"async",
|
|
23
|
+
"async router",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"types": "dist/esm/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"default": "./dist/esm/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/cjs/index.d.cts",
|
|
36
|
+
"default": "./dist/cjs/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=12"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@tanstack/router-core": "1.129.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {}
|
|
53
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
|
+
import type { AnyRouter } from '@tanstack/router-core'
|
|
3
|
+
|
|
4
|
+
export interface StartStorageContext {
|
|
5
|
+
router: AnyRouter
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const startStorage = new AsyncLocalStorage<StartStorageContext>()
|
|
9
|
+
|
|
10
|
+
export async function runWithStartContext<T>(
|
|
11
|
+
context: StartStorageContext,
|
|
12
|
+
fn: () => T | Promise<T>,
|
|
13
|
+
): Promise<T> {
|
|
14
|
+
return startStorage.run(context, fn)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getStartContext<TThrow extends boolean = true>(opts?: {
|
|
18
|
+
throwIfNotFound?: TThrow
|
|
19
|
+
}): TThrow extends false
|
|
20
|
+
? StartStorageContext | undefined
|
|
21
|
+
: StartStorageContext {
|
|
22
|
+
const context = startStorage.getStore()
|
|
23
|
+
if (!context && opts?.throwIfNotFound !== false) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
return context as any
|
|
29
|
+
}
|
package/src/index.tsx
ADDED