@fest-lib/uniform 0.1.13 → 0.1.15
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 +52 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,46 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@fest-lib/uniform</strong><br>
|
|
3
|
+
One channel API across workers, ports, BroadcastChannel, WebSocket, Chrome, Atomics, and WebRTC.
|
|
4
|
+
</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/@fest-lib/uniform"><img src="https://img.shields.io/npm/v/@fest-lib/uniform?style=flat-square" alt="npm"></a>
|
|
8
|
+
<a href="LICENSE"><img src="https://img.shields.io/npm/l/@fest-lib/uniform?style=flat-square" alt="MIT"></a>
|
|
9
|
+
<a href="https://github.com/fest-live/uniform.ts"><img src="https://img.shields.io/github/stars/fest-live/uniform.ts?style=flat-square" alt="stars"></a>
|
|
10
|
+
</p>
|
|
4
11
|
|
|
5
|
-
Canonical runtime: `UnifiedChannel` / `createUnifiedChannel`. Invoker (`Requestor` / `Responder`)
|
|
12
|
+
Canonical runtime: `UnifiedChannel` / `createUnifiedChannel`. Invoker (`Requestor` / `Responder` / `createInvoker`) is request/response on a **channel name**. Older worker helpers stay under `src/original` and `src/newer/next/utils`.
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
core
|
|
16
|
+
└── fest/uniform ← you are here
|
|
17
|
+
└── object · lure · fl-ui
|
|
18
|
+
```
|
|
6
19
|
|
|
7
20
|
## Install
|
|
8
21
|
|
|
9
22
|
```bash
|
|
10
|
-
npm install @fest-lib/uniform
|
|
23
|
+
npm install @fest-lib/core @fest-lib/uniform
|
|
11
24
|
```
|
|
12
25
|
|
|
26
|
+
Peer: `@fest-lib/core` `>=0.1.0`.
|
|
27
|
+
|
|
28
|
+
### Unified channel (host ↔ worker)
|
|
29
|
+
|
|
13
30
|
```ts
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
31
|
+
import { createUnifiedChannel } from "@fest-lib/uniform";
|
|
32
|
+
|
|
33
|
+
// worker
|
|
34
|
+
const w = createUnifiedChannel("worker");
|
|
35
|
+
w.expose("calc", { add: (a: number, b: number) => a + b });
|
|
36
|
+
|
|
37
|
+
// window
|
|
38
|
+
const host = createUnifiedChannel("host");
|
|
39
|
+
host.connect(worker);
|
|
40
|
+
const calc = host.proxy("worker", ["calc"]);
|
|
41
|
+
await calc.add(2, 3); // 5
|
|
22
42
|
```
|
|
23
43
|
|
|
24
|
-
|
|
44
|
+
`createUnifiedChannel` accepts a name string or a config object (`{ name, autoListen, … }`).
|
|
45
|
+
|
|
46
|
+
### Invoker (named channel)
|
|
25
47
|
|
|
26
48
|
```ts
|
|
27
|
-
import {
|
|
49
|
+
import { createInvoker, autoInvoker, detectContextType } from "@fest-lib/uniform";
|
|
28
50
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
const result = await worker.request("processData", { data: "hello" });
|
|
51
|
+
const invoker = createInvoker("opfs");
|
|
52
|
+
autoInvoker("opfs"); // connects `self` in worker / SW / Chrome
|
|
53
|
+
detectContextType(); // "window" | "worker" | "chrome-*" | …
|
|
34
54
|
```
|
|
35
55
|
|
|
56
|
+
`createInvoker(channelName)` — the first argument is the **string name**, not a `UnifiedChannel` instance. Use `.connect(target)` or `setupInvoker(name, worker)`.
|
|
57
|
+
|
|
36
58
|
## Layout
|
|
37
59
|
|
|
38
60
|
| Path | Role |
|
|
39
61
|
| --- | --- |
|
|
40
62
|
| `src/newer/next/channel/UnifiedChannel.ts` | primary channel |
|
|
41
|
-
| `src/newer/next/proxy/Invoker.ts` | request/response |
|
|
63
|
+
| `src/newer/next/proxy/Invoker.ts` | request / response |
|
|
42
64
|
| `src/newer/core/TransportCore.ts` | transport factory |
|
|
43
65
|
| `src/newer/messaging/*` | queues / protocol |
|
|
44
66
|
| `src/original/*` | older worker helpers |
|
|
45
67
|
|
|
46
|
-
|
|
68
|
+
## Workspace
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
cd modules/projects/uniform.ts
|
|
72
|
+
npm test # node + deno + browser
|
|
73
|
+
npm run build
|
|
74
|
+
npm run publish
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Typedoc: `npm run docs:md`. License: [MIT](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fest-lib/uniform",
|
|
3
3
|
"description": "fest-lib UnifiedChannel: workers, ports, BroadcastChannel, Chrome, Atomics, WebRTC",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": true,
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"prepack": "npm run build:publish",
|
|
61
61
|
"preview": "vite preview",
|
|
62
62
|
"release": "PUPPETEER_SKIP_DOWNLOAD=1 npm run build:publish && npm publish --access public --ignore-scripts",
|
|
63
|
-
"publish": "npm run release",
|
|
63
|
+
"publish": "node ../scripts/bump-patch-version.mjs && npm run release",
|
|
64
64
|
"docs": "typedoc ./src/index.ts --options ./typedoc.json --out ./docs --tsconfig ./tsconfig.json --excludeExternals --excludePrivate --excludeProtected --skipErrorChecking",
|
|
65
65
|
"docs:clean": "rm -rf ./docs && typedoc --options ./typedoc.json",
|
|
66
66
|
"docs:md": "typedoc --options ./typedoc.md.json",
|