@stryke/capnp 0.3.0 → 0.4.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/bin/capnpc.cjs +1179 -0
- package/bin/capnpc.js +1146 -0
- package/dist/chunk-LY3GWW4E.js +977 -0
- package/dist/chunk-ORA4UQMU.cjs +1 -0
- package/dist/chunk-OULCUN6I.js +0 -0
- package/dist/chunk-PV3OG5H3.cjs +977 -0
- package/dist/chunk-SHUYVCID.js +6 -0
- package/dist/chunk-USNT2KNT.cjs +6 -0
- package/dist/compile.cjs +7 -0
- package/dist/compile.js +7 -0
- package/dist/index.cjs +8 -0
- package/dist/index.js +8 -0
- package/dist/rpc.cjs +103 -0
- package/dist/rpc.d.cts +42 -0
- package/dist/rpc.d.ts +42 -0
- package/dist/rpc.js +103 -0
- package/dist/types.cjs +1 -0
- package/dist/types.js +1 -0
- package/package.json +19 -2
- package/dist/bin/capnpc.cjs +0 -11269
- package/dist/bin/capnpc.d.cts +0 -6
- package/dist/bin/capnpc.d.ts +0 -6
- package/dist/bin/capnpc.js +0 -11266
- package/dist/chunk-E5KOPL7Q.cjs +0 -6
- package/dist/chunk-EK5N4FAF.js +0 -55
- package/dist/chunk-IWTVA3JL.cjs +0 -104
- package/dist/chunk-QKE2ND5U.js +0 -104
- package/dist/chunk-TE2KW23K.cjs +0 -55
- package/dist/chunk-UQ2KKHLM.js +0 -6
- package/dist/src/compile.cjs +0 -7
- package/dist/src/compile.js +0 -7
- package/dist/src/index.cjs +0 -13
- package/dist/src/index.js +0 -13
- package/dist/src/types.cjs +0 -2
- package/dist/src/types.js +0 -2
- /package/dist/{src/compile.d.cts → compile.d.cts} +0 -0
- /package/dist/{src/compile.d.ts → compile.d.ts} +0 -0
- /package/dist/{src/index.d.cts → index.d.cts} +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/types.d.cts → types.d.cts} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
package/dist/compile.cjs
ADDED
package/dist/compile.js
ADDED
package/dist/index.cjs
ADDED
package/dist/index.js
ADDED
package/dist/rpc.cjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
|
|
4
|
+
|
|
5
|
+
// src/rpc.ts
|
|
6
|
+
var _capnpes = require('capnp-es');
|
|
7
|
+
var _worker_threads = require('worker_threads');
|
|
8
|
+
var CapnpRPC = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
|
|
9
|
+
static {
|
|
10
|
+
_chunkUSNT2KNTcjs.__name.call(void 0, this, "CapnpRPC");
|
|
11
|
+
}
|
|
12
|
+
__init() {this.acceptQueue = new Array()}
|
|
13
|
+
__init2() {this.connections = {}}
|
|
14
|
+
__init3() {this.connectQueue = new Array()}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link Conn} instance.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
|
|
20
|
+
*/
|
|
21
|
+
connect(id = 0) {
|
|
22
|
+
if (this.connections[id] !== void 0) return this.connections[id];
|
|
23
|
+
const ch = new (0, _worker_threads.MessageChannel)();
|
|
24
|
+
const conn = new (0, _capnpes.Conn)(new MessageChannelTransport(ch.port1));
|
|
25
|
+
const accept = this.acceptQueue.pop();
|
|
26
|
+
this.connections[id] = conn;
|
|
27
|
+
if (accept === void 0) {
|
|
28
|
+
this.connectQueue.push(ch.port2);
|
|
29
|
+
} else {
|
|
30
|
+
accept.resolve(new (0, _capnpes.Conn)(new MessageChannelTransport(ch.port2)));
|
|
31
|
+
}
|
|
32
|
+
return conn;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Accepts a connection from the connect queue.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that resolves to a Conn instance when a connection is accepted.
|
|
38
|
+
* @throws If no connections are available in the connect queue.
|
|
39
|
+
*/
|
|
40
|
+
async accept() {
|
|
41
|
+
const port2 = this.connectQueue.pop();
|
|
42
|
+
if (port2 !== void 0) {
|
|
43
|
+
return Promise.resolve(new (0, _capnpes.Conn)(new MessageChannelTransport(port2)));
|
|
44
|
+
}
|
|
45
|
+
const deferred = new (0, _capnpes.Deferred)();
|
|
46
|
+
this.acceptQueue.push(deferred);
|
|
47
|
+
return deferred.promise;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Closes all connections and clears the queues.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* This method will reject all pending accept promises and close all
|
|
54
|
+
* connections in the connect queue.
|
|
55
|
+
*/
|
|
56
|
+
close() {
|
|
57
|
+
let i = this.acceptQueue.length;
|
|
58
|
+
while (--i >= 0) {
|
|
59
|
+
_optionalChain([this, 'access', _ => _.acceptQueue, 'access', _2 => _2[i], 'optionalAccess', _3 => _3.reject, 'call', _4 => _4()]);
|
|
60
|
+
}
|
|
61
|
+
i = this.connectQueue.length;
|
|
62
|
+
while (--i >= 0) {
|
|
63
|
+
_optionalChain([this, 'access', _5 => _5.connectQueue, 'access', _6 => _6[i], 'optionalAccess', _7 => _7.close, 'call', _8 => _8()]);
|
|
64
|
+
}
|
|
65
|
+
for (const id in this.connections) {
|
|
66
|
+
_optionalChain([this, 'access', _9 => _9.connections, 'access', _10 => _10[id], 'optionalAccess', _11 => _11.shutdown, 'call', _12 => _12()]);
|
|
67
|
+
}
|
|
68
|
+
this.acceptQueue.length = 0;
|
|
69
|
+
this.connectQueue.length = 0;
|
|
70
|
+
this.connections = {};
|
|
71
|
+
}
|
|
72
|
+
}, _class);
|
|
73
|
+
var MessageChannelTransport = class extends _capnpes.DeferredTransport {
|
|
74
|
+
static {
|
|
75
|
+
_chunkUSNT2KNTcjs.__name.call(void 0, this, "MessageChannelTransport");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
constructor(port) {
|
|
79
|
+
super(), this.port = port, this.close = () => {
|
|
80
|
+
this.port.off("message", this.resolve);
|
|
81
|
+
this.port.off("messageerror", this.reject);
|
|
82
|
+
this.port.off("close", this.close);
|
|
83
|
+
this.port.close();
|
|
84
|
+
super.close();
|
|
85
|
+
};
|
|
86
|
+
this.port.on("message", this.resolve);
|
|
87
|
+
this.port.on("messageerror", this.reject);
|
|
88
|
+
this.port.on("close", this.close);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sendMessage(msg) {
|
|
92
|
+
const m = new (0, _capnpes.Message)();
|
|
93
|
+
m.setRoot(msg);
|
|
94
|
+
const buf = m.toArrayBuffer();
|
|
95
|
+
this.port.postMessage(buf, [
|
|
96
|
+
buf
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
exports.CapnpRPC = CapnpRPC; exports.MessageChannelTransport = MessageChannelTransport;
|
package/dist/rpc.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Deferred, Conn, DeferredTransport } from 'capnp-es';
|
|
2
|
+
import { Message } from 'capnp-es/capnp/rpc';
|
|
3
|
+
import { MessagePort } from 'node:worker_threads';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A class that manages Cap'n Proto RPC connections.
|
|
7
|
+
*/
|
|
8
|
+
declare class CapnpRPC {
|
|
9
|
+
protected acceptQueue: Deferred<Conn>[];
|
|
10
|
+
protected connections: Record<number, Conn>;
|
|
11
|
+
protected connectQueue: MessagePort[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link Conn} instance.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
|
|
17
|
+
*/
|
|
18
|
+
connect(id?: number): Conn;
|
|
19
|
+
/**
|
|
20
|
+
* Accepts a connection from the connect queue.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves to a Conn instance when a connection is accepted.
|
|
23
|
+
* @throws If no connections are available in the connect queue.
|
|
24
|
+
*/
|
|
25
|
+
accept(): Promise<Conn>;
|
|
26
|
+
/**
|
|
27
|
+
* Closes all connections and clears the queues.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This method will reject all pending accept promises and close all
|
|
31
|
+
* connections in the connect queue.
|
|
32
|
+
*/
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
declare class MessageChannelTransport extends DeferredTransport {
|
|
36
|
+
port: MessagePort;
|
|
37
|
+
constructor(port: MessagePort);
|
|
38
|
+
close: () => void;
|
|
39
|
+
sendMessage(msg: Message): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { CapnpRPC, MessageChannelTransport };
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Deferred, Conn, DeferredTransport } from 'capnp-es';
|
|
2
|
+
import { Message } from 'capnp-es/capnp/rpc';
|
|
3
|
+
import { MessagePort } from 'node:worker_threads';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A class that manages Cap'n Proto RPC connections.
|
|
7
|
+
*/
|
|
8
|
+
declare class CapnpRPC {
|
|
9
|
+
protected acceptQueue: Deferred<Conn>[];
|
|
10
|
+
protected connections: Record<number, Conn>;
|
|
11
|
+
protected connectQueue: MessagePort[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link Conn} instance.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
|
|
17
|
+
*/
|
|
18
|
+
connect(id?: number): Conn;
|
|
19
|
+
/**
|
|
20
|
+
* Accepts a connection from the connect queue.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves to a Conn instance when a connection is accepted.
|
|
23
|
+
* @throws If no connections are available in the connect queue.
|
|
24
|
+
*/
|
|
25
|
+
accept(): Promise<Conn>;
|
|
26
|
+
/**
|
|
27
|
+
* Closes all connections and clears the queues.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This method will reject all pending accept promises and close all
|
|
31
|
+
* connections in the connect queue.
|
|
32
|
+
*/
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
declare class MessageChannelTransport extends DeferredTransport {
|
|
36
|
+
port: MessagePort;
|
|
37
|
+
constructor(port: MessagePort);
|
|
38
|
+
close: () => void;
|
|
39
|
+
sendMessage(msg: Message): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { CapnpRPC, MessageChannelTransport };
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-SHUYVCID.js";
|
|
4
|
+
|
|
5
|
+
// src/rpc.ts
|
|
6
|
+
import { Conn, Deferred, DeferredTransport, Message } from "capnp-es";
|
|
7
|
+
import { MessageChannel } from "node:worker_threads";
|
|
8
|
+
var CapnpRPC = class {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "CapnpRPC");
|
|
11
|
+
}
|
|
12
|
+
acceptQueue = new Array();
|
|
13
|
+
connections = {};
|
|
14
|
+
connectQueue = new Array();
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link Conn} instance.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
|
|
20
|
+
*/
|
|
21
|
+
connect(id = 0) {
|
|
22
|
+
if (this.connections[id] !== void 0) return this.connections[id];
|
|
23
|
+
const ch = new MessageChannel();
|
|
24
|
+
const conn = new Conn(new MessageChannelTransport(ch.port1));
|
|
25
|
+
const accept = this.acceptQueue.pop();
|
|
26
|
+
this.connections[id] = conn;
|
|
27
|
+
if (accept === void 0) {
|
|
28
|
+
this.connectQueue.push(ch.port2);
|
|
29
|
+
} else {
|
|
30
|
+
accept.resolve(new Conn(new MessageChannelTransport(ch.port2)));
|
|
31
|
+
}
|
|
32
|
+
return conn;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Accepts a connection from the connect queue.
|
|
36
|
+
*
|
|
37
|
+
* @returns A promise that resolves to a Conn instance when a connection is accepted.
|
|
38
|
+
* @throws If no connections are available in the connect queue.
|
|
39
|
+
*/
|
|
40
|
+
async accept() {
|
|
41
|
+
const port2 = this.connectQueue.pop();
|
|
42
|
+
if (port2 !== void 0) {
|
|
43
|
+
return Promise.resolve(new Conn(new MessageChannelTransport(port2)));
|
|
44
|
+
}
|
|
45
|
+
const deferred = new Deferred();
|
|
46
|
+
this.acceptQueue.push(deferred);
|
|
47
|
+
return deferred.promise;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Closes all connections and clears the queues.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* This method will reject all pending accept promises and close all
|
|
54
|
+
* connections in the connect queue.
|
|
55
|
+
*/
|
|
56
|
+
close() {
|
|
57
|
+
let i = this.acceptQueue.length;
|
|
58
|
+
while (--i >= 0) {
|
|
59
|
+
this.acceptQueue[i]?.reject();
|
|
60
|
+
}
|
|
61
|
+
i = this.connectQueue.length;
|
|
62
|
+
while (--i >= 0) {
|
|
63
|
+
this.connectQueue[i]?.close();
|
|
64
|
+
}
|
|
65
|
+
for (const id in this.connections) {
|
|
66
|
+
this.connections[id]?.shutdown();
|
|
67
|
+
}
|
|
68
|
+
this.acceptQueue.length = 0;
|
|
69
|
+
this.connectQueue.length = 0;
|
|
70
|
+
this.connections = {};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var MessageChannelTransport = class extends DeferredTransport {
|
|
74
|
+
static {
|
|
75
|
+
__name(this, "MessageChannelTransport");
|
|
76
|
+
}
|
|
77
|
+
port;
|
|
78
|
+
constructor(port) {
|
|
79
|
+
super(), this.port = port, this.close = () => {
|
|
80
|
+
this.port.off("message", this.resolve);
|
|
81
|
+
this.port.off("messageerror", this.reject);
|
|
82
|
+
this.port.off("close", this.close);
|
|
83
|
+
this.port.close();
|
|
84
|
+
super.close();
|
|
85
|
+
};
|
|
86
|
+
this.port.on("message", this.resolve);
|
|
87
|
+
this.port.on("messageerror", this.reject);
|
|
88
|
+
this.port.on("close", this.close);
|
|
89
|
+
}
|
|
90
|
+
close;
|
|
91
|
+
sendMessage(msg) {
|
|
92
|
+
const m = new Message();
|
|
93
|
+
m.setRoot(msg);
|
|
94
|
+
const buf = m.toArrayBuffer();
|
|
95
|
+
this.port.postMessage(buf, [
|
|
96
|
+
buf
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export {
|
|
101
|
+
CapnpRPC,
|
|
102
|
+
MessageChannelTransport
|
|
103
|
+
};
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";require('./chunk-ORA4UQMU.cjs');
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-OULCUN6I.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/capnp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package to assist in running the Cap'n Proto compiler and creating Cap'n Proto serialization protocol schemas.",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"private": false,
|
|
41
|
-
"bin": {
|
|
41
|
+
"bin": {
|
|
42
|
+
"storm-capnpc": "bin/capnpc.js",
|
|
43
|
+
"storm-capnpc-cjs": "bin/capnpc.cjs",
|
|
44
|
+
"storm-capnpc-esm": "bin/capnpc.js"
|
|
45
|
+
},
|
|
42
46
|
"main": "./dist/index.cjs",
|
|
43
47
|
"module": "./dist/index.js",
|
|
44
48
|
"exports": {
|
|
@@ -72,6 +76,19 @@
|
|
|
72
76
|
"default": "./dist/compile.js"
|
|
73
77
|
}
|
|
74
78
|
},
|
|
79
|
+
"./rpc": {
|
|
80
|
+
"import": { "types": "./dist/rpc.d.ts", "default": "./dist/rpc.js" },
|
|
81
|
+
"require": { "types": "./dist/rpc.d.cts", "default": "./dist/rpc.cjs" },
|
|
82
|
+
"default": { "types": "./dist/rpc.d.ts", "default": "./dist/rpc.js" }
|
|
83
|
+
},
|
|
84
|
+
"./types": {
|
|
85
|
+
"import": { "types": "./dist/types.d.ts", "default": "./dist/types.js" },
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/types.d.cts",
|
|
88
|
+
"default": "./dist/types.cjs"
|
|
89
|
+
},
|
|
90
|
+
"default": { "types": "./dist/types.d.ts", "default": "./dist/types.js" }
|
|
91
|
+
},
|
|
75
92
|
"./package.json": "./package.json"
|
|
76
93
|
},
|
|
77
94
|
"types": "./dist/index.d.ts",
|