supertalk 0.0.2 → 0.0.3
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 +36 -0
- package/node.d.ts +7 -0
- package/node.d.ts.map +1 -0
- package/node.js +7 -0
- package/node.js.map +1 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -336,6 +336,42 @@ Proxied objects are tracked with registries on both sides.
|
|
|
336
336
|
- **Consumer side**: Holds weak references; when GC'd, notifies source to
|
|
337
337
|
release.
|
|
338
338
|
|
|
339
|
+
### Node.js Worker Threads
|
|
340
|
+
|
|
341
|
+
For Node.js `worker_threads`, use the `nodeEndpoint` adapter to convert the
|
|
342
|
+
Node-style event API (`on`/`off`) to the browser-style API
|
|
343
|
+
(`addEventListener`/`removeEventListener`).
|
|
344
|
+
|
|
345
|
+
**main.ts:**
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
import {wrap} from 'supertalk';
|
|
349
|
+
import {nodeEndpoint} from 'supertalk/node.js';
|
|
350
|
+
import {Worker} from 'node:worker_threads';
|
|
351
|
+
|
|
352
|
+
const worker = new Worker('./worker.js');
|
|
353
|
+
const remote = await wrap<MyService>(nodeEndpoint(worker));
|
|
354
|
+
|
|
355
|
+
const result = await remote.add(1, 2);
|
|
356
|
+
worker.terminate();
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**worker.ts:**
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import {expose} from 'supertalk';
|
|
363
|
+
import {parentPort} from 'node:worker_threads';
|
|
364
|
+
|
|
365
|
+
const service = {
|
|
366
|
+
add(a: number, b: number) {
|
|
367
|
+
return a + b;
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// parentPort is a MessagePort which has addEventListener/removeEventListener
|
|
372
|
+
expose(service, parentPort!);
|
|
373
|
+
```
|
|
374
|
+
|
|
339
375
|
## Ecosystem
|
|
340
376
|
|
|
341
377
|
This package re-exports `@supertalk/core`. Additional packages are available for
|
package/node.d.ts
ADDED
package/node.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["src/node.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,yBAAyB,CAAC"}
|
package/node.js
ADDED
package/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["src/node.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supertalk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Type-safe client/server communication for workers, iframes, and RPC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./index.d.ts",
|
|
9
9
|
"default": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./node.js": {
|
|
12
|
+
"types": "./node.d.ts",
|
|
13
|
+
"default": "./node.js"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"files": [
|
|
13
17
|
"index.js",
|
|
14
18
|
"index.d.ts",
|
|
15
19
|
"index.d.ts.map",
|
|
16
|
-
"index.js.map"
|
|
20
|
+
"index.js.map",
|
|
21
|
+
"node.js",
|
|
22
|
+
"node.d.ts",
|
|
23
|
+
"node.d.ts.map",
|
|
24
|
+
"node.js.map"
|
|
17
25
|
],
|
|
18
26
|
"scripts": {
|
|
19
27
|
"build": "wireit"
|
|
@@ -31,6 +39,7 @@
|
|
|
31
39
|
],
|
|
32
40
|
"output": [
|
|
33
41
|
"index.*",
|
|
42
|
+
"node.*",
|
|
34
43
|
".tsbuildinfo"
|
|
35
44
|
],
|
|
36
45
|
"clean": "if-file-deleted"
|
|
@@ -57,7 +66,7 @@
|
|
|
57
66
|
"url": "https://github.com/justinfagnani/supertalk/issues"
|
|
58
67
|
},
|
|
59
68
|
"dependencies": {
|
|
60
|
-
"@supertalk/core": "0.0.
|
|
69
|
+
"@supertalk/core": "0.0.2"
|
|
61
70
|
},
|
|
62
71
|
"devDependencies": {
|
|
63
72
|
"typescript": "^5.7.2"
|