@astroscope/wormhole 0.1.1 → 0.2.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/README.md +5 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -0
- package/dist/react/index.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/types-hCfcC5bZ.d.ts +19 -0
- package/package.json +6 -6
- package/dist/types-DkH89ULF.d.ts +0 -9
package/README.md
CHANGED
|
@@ -18,6 +18,11 @@ Astro recommends [nanostores](https://docs.astro.build/en/recipes/sharing-state/
|
|
|
18
18
|
- Server-loaded configuration (theme, locale, permissions) bridged to the UI
|
|
19
19
|
- Any request-scoped data that multiple disconnected islands need to read
|
|
20
20
|
|
|
21
|
+
## Important notes
|
|
22
|
+
|
|
23
|
+
- **No secrets in wormholes.** All wormhole data is serialized into an inline `<script>` tag and sent to the browser. Never store tokens, API keys, credentials, or any sensitive data in a wormhole.
|
|
24
|
+
- **`set()` is client-only.** Calling `set()` does not work on the server. Use `open(wormhole, data, fn)` from `@astroscope/wormhole/server` to populate data in middleware.
|
|
25
|
+
|
|
21
26
|
## Examples
|
|
22
27
|
|
|
23
28
|
See the [demo/wormhole](../../demo/wormhole) directory for a working example.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { W as Wormhole } from './types-
|
|
1
|
+
import { W as Wormhole } from './types-hCfcC5bZ.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Define a wormhole that transfers state from server middleware to client components.
|
|
5
|
+
*
|
|
6
|
+
* **Security:** wormhole data is serialized into the HTML and sent to the browser.
|
|
7
|
+
* Never store secrets (tokens, API keys, credentials) in a wormhole.
|
|
8
|
+
*/
|
|
3
9
|
declare function defineWormhole<T>(name: string): Wormhole<T>;
|
|
4
10
|
|
|
5
11
|
export { Wormhole, defineWormhole };
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,11 @@ function defineWormhole(name) {
|
|
|
13
13
|
throw new Error(`wormhole "${name}" is not initialized`);
|
|
14
14
|
},
|
|
15
15
|
set(data) {
|
|
16
|
+
if (typeof globalThis.window === "undefined") {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`wormhole "${name}" set() cannot be called on the server as it is not request-scoped; use open(wormhole, data, fn) from "@astroscope/wormhole/server" instead`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
16
21
|
store = data;
|
|
17
22
|
for (const fn of listeners) fn(data);
|
|
18
23
|
},
|
package/dist/react/index.d.ts
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wormhole transfers state from server middleware to client-side components.
|
|
3
|
+
*
|
|
4
|
+
* **Security:** wormhole data is serialized into an inline `<script>` tag and sent to the browser.
|
|
5
|
+
* Never store secrets (tokens, API keys, credentials) in a wormhole.
|
|
6
|
+
*/
|
|
7
|
+
interface Wormhole<T> {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly key: string;
|
|
10
|
+
get(): T;
|
|
11
|
+
/**
|
|
12
|
+
* Update the wormhole value on the **client only**.
|
|
13
|
+
* Throws on the server — use `open(wormhole, data, fn)` from `@astroscope/wormhole/server` instead.
|
|
14
|
+
*/
|
|
15
|
+
set(data: T): void;
|
|
16
|
+
subscribe(fn: (data: T) => void): () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { Wormhole as W };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astroscope/wormhole",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Share dynamic server data with React islands and client scripts — typed, reactive",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsup src/index.ts src/server.ts src/react/index.ts --format esm --dts",
|
|
54
54
|
"typecheck": "tsc --noEmit",
|
|
55
|
-
"lint": "eslint
|
|
56
|
-
"lint:fix": "eslint
|
|
55
|
+
"lint": "eslint src",
|
|
56
|
+
"lint:fix": "eslint src --fix"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@types/react": "^19.2.
|
|
60
|
-
"astro": "^
|
|
59
|
+
"@types/react": "^19.2.14",
|
|
60
|
+
"astro": "^6.0.2",
|
|
61
61
|
"react": "^19.2.4",
|
|
62
62
|
"tsup": "^8.5.1",
|
|
63
63
|
"typescript": "^5.9.3"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"astro": "^
|
|
66
|
+
"astro": "^6.0.0",
|
|
67
67
|
"react": "^18.0.0 || ^19.0.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|