@stryke/capnp 0.9.13 → 0.10.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/dist/rpc.cjs CHANGED
@@ -1,9 +1,121 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
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; }
2
2
 
3
+ var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
4
+ var _capnpes = require('capnp-es');
5
+ var _nodeworker_threads = require('node:worker_threads');
6
+ class MessageChannelTransport extends _capnpes.DeferredTransport {
7
+ static {
8
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "MessageChannelTransport");
9
+ }
10
+
11
+ constructor(port) {
12
+ super(), this.port = port, this.close = () => {
13
+ this.port.off("message", this.resolve);
14
+ this.port.off("messageerror", this.reject);
15
+ this.port.off("close", this.close);
16
+ this.port.close();
17
+ super.close();
18
+ };
19
+ this.port.on("message", this.resolve);
20
+ this.port.on("messageerror", this.reject);
21
+ this.port.on("close", this.close);
22
+ }
23
+
24
+ sendMessage(msg) {
25
+ const m = new (0, _capnpes.Message)();
26
+ m.setRoot(msg);
27
+ const buf = m.toArrayBuffer();
28
+ this.port.postMessage(buf, [
29
+ buf
30
+ ]);
31
+ }
32
+ }
33
+ class CapnpRPC {constructor() { CapnpRPC.prototype.__init.call(this);CapnpRPC.prototype.__init2.call(this);CapnpRPC.prototype.__init3.call(this); }
34
+ static {
35
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "CapnpRPC");
36
+ }
37
+ /**
38
+ * A queue for deferred connections that are waiting to be accepted.
39
+ *
40
+ * @remarks
41
+ * This is used to manage incoming connections when the accept method is called.
42
+ */
43
+ __init() {this.acceptQueue = new Array()}
44
+ /**
45
+ * A map of connections by their ID.
46
+ *
47
+ * @remarks
48
+ * This is used to manage multiple connections and allows for easy retrieval by ID.
49
+ */
50
+ __init2() {this.connections = {}}
51
+ /**
52
+ * A queue for connections that are waiting to be accepted.
53
+ *
54
+ * @remarks
55
+ * This is used to manage incoming connections when the accept method is called.
56
+ */
57
+ __init3() {this.connectQueue = new Array()}
58
+ /**
59
+ * Creates a new {@link Conn} instance.
60
+ *
61
+ * @remarks
62
+ * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
63
+ */
64
+ connect(id = 0) {
65
+ if (this.connections[id] !== void 0) {
66
+ return this.connections[id];
67
+ }
68
+ const ch = new (0, _nodeworker_threads.MessageChannel)();
69
+ const conn = new (0, _capnpes.Conn)(new MessageChannelTransport(ch.port1));
70
+ const accept = this.acceptQueue.pop();
71
+ this.connections[id] = conn;
72
+ if (accept === void 0) {
73
+ this.connectQueue.push(ch.port2);
74
+ } else {
75
+ accept.resolve(new (0, _capnpes.Conn)(new MessageChannelTransport(ch.port2)));
76
+ }
77
+ return conn;
78
+ }
79
+ /**
80
+ * Accepts a connection from the connect queue.
81
+ *
82
+ * @returns A promise that resolves to a Conn instance when a connection is accepted.
83
+ * @throws If no connections are available in the connect queue.
84
+ */
85
+ async accept() {
86
+ const port2 = this.connectQueue.pop();
87
+ if (port2 !== void 0) {
88
+ return Promise.resolve(new (0, _capnpes.Conn)(new MessageChannelTransport(port2)));
89
+ }
90
+ const deferred = new (0, _capnpes.Deferred)();
91
+ this.acceptQueue.push(deferred);
92
+ return deferred.promise;
93
+ }
94
+ /**
95
+ * Closes all connections and clears the queues.
96
+ *
97
+ * @remarks
98
+ * This method will reject all pending accept promises and close all
99
+ * connections in the connect queue.
100
+ */
101
+ close() {
102
+ let i = this.acceptQueue.length;
103
+ while (--i >= 0) {
104
+ _optionalChain([this, 'access', _ => _.acceptQueue, 'access', _2 => _2[i], 'optionalAccess', _3 => _3.reject, 'call', _4 => _4()]);
105
+ }
106
+ i = this.connectQueue.length;
107
+ while (--i >= 0) {
108
+ this.connectQueue[i].close();
109
+ }
110
+ for (const id in this.connections) {
111
+ _optionalChain([this, 'access', _5 => _5.connections, 'access', _6 => _6[id], 'optionalAccess', _7 => _7.shutdown, 'call', _8 => _8()]);
112
+ }
113
+ this.acceptQueue.length = 0;
114
+ this.connectQueue.length = 0;
115
+ this.connections = {};
116
+ }
117
+ }
3
118
 
4
- var _chunk4Z2FMN72cjs = require('./chunk-4Z2FMN72.cjs');
5
- require('./chunk-USNT2KNT.cjs');
6
119
 
7
120
 
8
-
9
- exports.CapnpRPC = _chunk4Z2FMN72cjs.CapnpRPC; exports.MessageChannelTransport = _chunk4Z2FMN72cjs.MessageChannelTransport;
121
+ exports.CapnpRPC = CapnpRPC; exports.MessageChannelTransport = MessageChannelTransport;
package/dist/rpc.d.cts CHANGED
@@ -1,13 +1,37 @@
1
- import { Deferred, Conn, DeferredTransport } from 'capnp-es';
1
+ import { DeferredTransport, Deferred, Conn } from 'capnp-es';
2
2
  import { Message } from 'capnp-es/capnp/rpc';
3
3
  import { MessagePort } from 'node:worker_threads';
4
4
 
5
+ declare class MessageChannelTransport extends DeferredTransport {
6
+ port: MessagePort;
7
+ constructor(port: MessagePort);
8
+ close: () => void;
9
+ sendMessage(msg: Message): void;
10
+ }
5
11
  /**
6
12
  * A class that manages Cap'n Proto RPC connections.
7
13
  */
8
14
  declare class CapnpRPC {
15
+ /**
16
+ * A queue for deferred connections that are waiting to be accepted.
17
+ *
18
+ * @remarks
19
+ * This is used to manage incoming connections when the accept method is called.
20
+ */
9
21
  protected acceptQueue: Deferred<Conn>[];
22
+ /**
23
+ * A map of connections by their ID.
24
+ *
25
+ * @remarks
26
+ * This is used to manage multiple connections and allows for easy retrieval by ID.
27
+ */
10
28
  protected connections: Record<number, Conn>;
29
+ /**
30
+ * A queue for connections that are waiting to be accepted.
31
+ *
32
+ * @remarks
33
+ * This is used to manage incoming connections when the accept method is called.
34
+ */
11
35
  protected connectQueue: MessagePort[];
12
36
  /**
13
37
  * Creates a new {@link Conn} instance.
@@ -32,11 +56,5 @@ declare class CapnpRPC {
32
56
  */
33
57
  close(): void;
34
58
  }
35
- declare class MessageChannelTransport extends DeferredTransport {
36
- port: MessagePort;
37
- constructor(port: MessagePort);
38
- close: () => void;
39
- sendMessage(msg: Message): void;
40
- }
41
59
 
42
60
  export { CapnpRPC, MessageChannelTransport };
package/dist/rpc.d.ts CHANGED
@@ -1,13 +1,37 @@
1
- import { Deferred, Conn, DeferredTransport } from 'capnp-es';
1
+ import { DeferredTransport, Deferred, Conn } from 'capnp-es';
2
2
  import { Message } from 'capnp-es/capnp/rpc';
3
3
  import { MessagePort } from 'node:worker_threads';
4
4
 
5
+ declare class MessageChannelTransport extends DeferredTransport {
6
+ port: MessagePort;
7
+ constructor(port: MessagePort);
8
+ close: () => void;
9
+ sendMessage(msg: Message): void;
10
+ }
5
11
  /**
6
12
  * A class that manages Cap'n Proto RPC connections.
7
13
  */
8
14
  declare class CapnpRPC {
15
+ /**
16
+ * A queue for deferred connections that are waiting to be accepted.
17
+ *
18
+ * @remarks
19
+ * This is used to manage incoming connections when the accept method is called.
20
+ */
9
21
  protected acceptQueue: Deferred<Conn>[];
22
+ /**
23
+ * A map of connections by their ID.
24
+ *
25
+ * @remarks
26
+ * This is used to manage multiple connections and allows for easy retrieval by ID.
27
+ */
10
28
  protected connections: Record<number, Conn>;
29
+ /**
30
+ * A queue for connections that are waiting to be accepted.
31
+ *
32
+ * @remarks
33
+ * This is used to manage incoming connections when the accept method is called.
34
+ */
11
35
  protected connectQueue: MessagePort[];
12
36
  /**
13
37
  * Creates a new {@link Conn} instance.
@@ -32,11 +56,5 @@ declare class CapnpRPC {
32
56
  */
33
57
  close(): void;
34
58
  }
35
- declare class MessageChannelTransport extends DeferredTransport {
36
- port: MessagePort;
37
- constructor(port: MessagePort);
38
- close: () => void;
39
- sendMessage(msg: Message): void;
40
- }
41
59
 
42
60
  export { CapnpRPC, MessageChannelTransport };
package/dist/rpc.js CHANGED
@@ -1,8 +1,120 @@
1
1
  import {
2
- CapnpRPC,
3
- MessageChannelTransport
4
- } from "./chunk-L563IRIF.js";
5
- import "./chunk-SHUYVCID.js";
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
4
+ import { Conn, Deferred, DeferredTransport, Message } from "capnp-es";
5
+ import { MessageChannel } from "node:worker_threads";
6
+ class MessageChannelTransport extends DeferredTransport {
7
+ static {
8
+ __name(this, "MessageChannelTransport");
9
+ }
10
+ port;
11
+ constructor(port) {
12
+ super(), this.port = port, this.close = () => {
13
+ this.port.off("message", this.resolve);
14
+ this.port.off("messageerror", this.reject);
15
+ this.port.off("close", this.close);
16
+ this.port.close();
17
+ super.close();
18
+ };
19
+ this.port.on("message", this.resolve);
20
+ this.port.on("messageerror", this.reject);
21
+ this.port.on("close", this.close);
22
+ }
23
+ close;
24
+ sendMessage(msg) {
25
+ const m = new Message();
26
+ m.setRoot(msg);
27
+ const buf = m.toArrayBuffer();
28
+ this.port.postMessage(buf, [
29
+ buf
30
+ ]);
31
+ }
32
+ }
33
+ class CapnpRPC {
34
+ static {
35
+ __name(this, "CapnpRPC");
36
+ }
37
+ /**
38
+ * A queue for deferred connections that are waiting to be accepted.
39
+ *
40
+ * @remarks
41
+ * This is used to manage incoming connections when the accept method is called.
42
+ */
43
+ acceptQueue = new Array();
44
+ /**
45
+ * A map of connections by their ID.
46
+ *
47
+ * @remarks
48
+ * This is used to manage multiple connections and allows for easy retrieval by ID.
49
+ */
50
+ connections = {};
51
+ /**
52
+ * A queue for connections that are waiting to be accepted.
53
+ *
54
+ * @remarks
55
+ * This is used to manage incoming connections when the accept method is called.
56
+ */
57
+ connectQueue = new Array();
58
+ /**
59
+ * Creates a new {@link Conn} instance.
60
+ *
61
+ * @remarks
62
+ * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
63
+ */
64
+ connect(id = 0) {
65
+ if (this.connections[id] !== void 0) {
66
+ return this.connections[id];
67
+ }
68
+ const ch = new MessageChannel();
69
+ const conn = new Conn(new MessageChannelTransport(ch.port1));
70
+ const accept = this.acceptQueue.pop();
71
+ this.connections[id] = conn;
72
+ if (accept === void 0) {
73
+ this.connectQueue.push(ch.port2);
74
+ } else {
75
+ accept.resolve(new Conn(new MessageChannelTransport(ch.port2)));
76
+ }
77
+ return conn;
78
+ }
79
+ /**
80
+ * Accepts a connection from the connect queue.
81
+ *
82
+ * @returns A promise that resolves to a Conn instance when a connection is accepted.
83
+ * @throws If no connections are available in the connect queue.
84
+ */
85
+ async accept() {
86
+ const port2 = this.connectQueue.pop();
87
+ if (port2 !== void 0) {
88
+ return Promise.resolve(new Conn(new MessageChannelTransport(port2)));
89
+ }
90
+ const deferred = new Deferred();
91
+ this.acceptQueue.push(deferred);
92
+ return deferred.promise;
93
+ }
94
+ /**
95
+ * Closes all connections and clears the queues.
96
+ *
97
+ * @remarks
98
+ * This method will reject all pending accept promises and close all
99
+ * connections in the connect queue.
100
+ */
101
+ close() {
102
+ let i = this.acceptQueue.length;
103
+ while (--i >= 0) {
104
+ this.acceptQueue[i]?.reject();
105
+ }
106
+ i = this.connectQueue.length;
107
+ while (--i >= 0) {
108
+ this.connectQueue[i].close();
109
+ }
110
+ for (const id in this.connections) {
111
+ this.connections[id]?.shutdown();
112
+ }
113
+ this.acceptQueue.length = 0;
114
+ this.connectQueue.length = 0;
115
+ this.connections = {};
116
+ }
117
+ }
6
118
  export {
7
119
  CapnpRPC,
8
120
  MessageChannelTransport
package/dist/types.cjs CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkR2JXWA7Qcjs = require('./chunk-R2JXWA7Q.cjs');
4
- require('./chunk-USNT2KNT.cjs');
3
+ var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
4
+ class CodeGeneratorContext {constructor() { CodeGeneratorContext.prototype.__init.call(this); }
5
+ static {
6
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "CodeGeneratorContext");
7
+ }
8
+ __init() {this.files = []}
9
+ }
5
10
 
6
11
 
7
- exports.CodeGeneratorContext = _chunkR2JXWA7Qcjs.CodeGeneratorContext;
12
+ exports.CodeGeneratorContext = CodeGeneratorContext;
package/dist/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node, CodeGeneratorRequest_RequestedFile_Import, Field } from 'capnp-es/capnp/schema';
2
- import { ParsedCommandLine } from 'typescript';
2
+ import { CompilerOptions } from 'typescript';
3
3
 
4
4
  interface CodeGeneratorFileContext {
5
5
  readonly nodes: Node[];
@@ -32,7 +32,7 @@ interface CapnpcCLIOptions {
32
32
  tty?: boolean;
33
33
  }
34
34
  type CapnpcOptions = Omit<CapnpcCLIOptions, "noTs" | "noDts" | "tsconfig" | "schema"> & {
35
- tsconfig: ParsedCommandLine;
35
+ tsconfig: CompilerOptions;
36
36
  schemas: string[];
37
37
  };
38
38
  interface CapnpcResult {
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node, CodeGeneratorRequest_RequestedFile_Import, Field } from 'capnp-es/capnp/schema';
2
- import { ParsedCommandLine } from 'typescript';
2
+ import { CompilerOptions } from 'typescript';
3
3
 
4
4
  interface CodeGeneratorFileContext {
5
5
  readonly nodes: Node[];
@@ -32,7 +32,7 @@ interface CapnpcCLIOptions {
32
32
  tty?: boolean;
33
33
  }
34
34
  type CapnpcOptions = Omit<CapnpcCLIOptions, "noTs" | "noDts" | "tsconfig" | "schema"> & {
35
- tsconfig: ParsedCommandLine;
35
+ tsconfig: CompilerOptions;
36
36
  schemas: string[];
37
37
  };
38
38
  interface CapnpcResult {
package/dist/types.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import {
2
- CodeGeneratorContext
3
- } from "./chunk-CCU32X36.js";
4
- import "./chunk-SHUYVCID.js";
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
4
+ class CodeGeneratorContext {
5
+ static {
6
+ __name(this, "CodeGeneratorContext");
7
+ }
8
+ files = [];
9
+ }
5
10
  export {
6
11
  CodeGeneratorContext
7
12
  };