@stryke/capnp 0.12.20 → 0.12.22

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32; var _class33; var _class34; var _class35; var _class36; var _class37; var _class38; var _class39; var _class40; var _class41; var _class42; var _class43; var _class44; var _class45; var _class46;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32; var _class33; var _class34; var _class35; var _class36; var _class37; var _class38; var _class39; var _class40; var _class41; var _class42; var _class43; var _class44;
2
2
 
3
3
 
4
4
 
@@ -4723,123 +4723,6 @@ var DeferredTransport = (_class44 = class {constructor() { _class44.prototype.__
4723
4723
  }, "resolve")}
4724
4724
  }, _class44);
4725
4725
 
4726
- // src/rpc.ts
4727
- var _worker_threads = require('worker_threads');
4728
- var MessageChannelTransport = (_class45 = class extends DeferredTransport {
4729
- static {
4730
- _chunkUSNT2KNTcjs.__name.call(void 0, this, "MessageChannelTransport");
4731
- }
4732
-
4733
- constructor(port) {
4734
- super();_class45.prototype.__init27.call(this);, this.port = port;
4735
- this.port.on("message", this.resolve);
4736
- this.port.on("messageerror", this.reject);
4737
- this.port.on("close", this.close);
4738
- }
4739
- __init27() {this.close = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, () => {
4740
- this.port.off("message", this.resolve);
4741
- this.port.off("messageerror", this.reject);
4742
- this.port.off("close", this.close);
4743
- this.port.close();
4744
- super.close();
4745
- }, "close")}
4746
- sendMessage(msg) {
4747
- const m = new (0, _chunkKMCJ5MIQcjs.Message)();
4748
- m.setRoot(msg);
4749
- const buf = m.toArrayBuffer();
4750
- this.port.postMessage(buf, [
4751
- buf
4752
- ]);
4753
- }
4754
- }, _class45);
4755
- var CapnpRPC = (_class46 = class {constructor() { _class46.prototype.__init28.call(this);_class46.prototype.__init29.call(this);_class46.prototype.__init30.call(this); }
4756
- static {
4757
- _chunkUSNT2KNTcjs.__name.call(void 0, this, "CapnpRPC");
4758
- }
4759
- /**
4760
- * A queue for deferred connections that are waiting to be accepted.
4761
- *
4762
- * @remarks
4763
- * This is used to manage incoming connections when the accept method is called.
4764
- */
4765
- __init28() {this.acceptQueue = new Array()}
4766
- /**
4767
- * A map of connections by their ID.
4768
- *
4769
- * @remarks
4770
- * This is used to manage multiple connections and allows for easy retrieval by ID.
4771
- */
4772
- __init29() {this.connections = {}}
4773
- /**
4774
- * A queue for connections that are waiting to be accepted.
4775
- *
4776
- * @remarks
4777
- * This is used to manage incoming connections when the accept method is called.
4778
- */
4779
- __init30() {this.connectQueue = new Array()}
4780
- /**
4781
- * Creates a new {@link Conn} instance.
4782
- *
4783
- * @remarks
4784
- * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
4785
- */
4786
- connect(id = 0) {
4787
- if (this.connections[id] !== void 0) {
4788
- return this.connections[id];
4789
- }
4790
- const ch = new (0, _worker_threads.MessageChannel)();
4791
- const conn = new Conn(new MessageChannelTransport(ch.port1));
4792
- const accept = this.acceptQueue.pop();
4793
- this.connections[id] = conn;
4794
- if (accept === void 0) {
4795
- this.connectQueue.push(ch.port2);
4796
- } else {
4797
- accept.resolve(new Conn(new MessageChannelTransport(ch.port2)));
4798
- }
4799
- return conn;
4800
- }
4801
- /**
4802
- * Accepts a connection from the connect queue.
4803
- *
4804
- * @returns A promise that resolves to a Conn instance when a connection is accepted.
4805
- * @throws If no connections are available in the connect queue.
4806
- */
4807
- async accept() {
4808
- const port2 = this.connectQueue.pop();
4809
- if (port2 !== void 0) {
4810
- return Promise.resolve(new Conn(new MessageChannelTransport(port2)));
4811
- }
4812
- const deferred = new Deferred();
4813
- this.acceptQueue.push(deferred);
4814
- return deferred.promise;
4815
- }
4816
- /**
4817
- * Closes all connections and clears the queues.
4818
- *
4819
- * @remarks
4820
- * This method will reject all pending accept promises and close all
4821
- * connections in the connect queue.
4822
- */
4823
- close() {
4824
- let i = this.acceptQueue.length;
4825
- while (--i >= 0) {
4826
- _optionalChain([this, 'access', _25 => _25.acceptQueue, 'access', _26 => _26[i], 'optionalAccess', _27 => _27.reject, 'call', _28 => _28()]);
4827
- }
4828
- i = this.connectQueue.length;
4829
- while (--i >= 0) {
4830
- this.connectQueue[i].close();
4831
- }
4832
- for (const id in this.connections) {
4833
- _optionalChain([this, 'access', _29 => _29.connections, 'access', _30 => _30[id], 'optionalAccess', _31 => _31.shutdown, 'call', _32 => _32()]);
4834
- }
4835
- this.acceptQueue.length = 0;
4836
- this.connectQueue.length = 0;
4837
- this.connections = {};
4838
- }
4839
- }, _class46);
4840
-
4841
-
4842
-
4843
4726
 
4844
4727
 
4845
4728
 
@@ -4874,4 +4757,4 @@ var CapnpRPC = (_class46 = class {constructor() { _class46.prototype.__init28.ca
4874
4757
 
4875
4758
 
4876
4759
 
4877
- exports.Interface = Interface; exports.isFuncCall = isFuncCall; exports.isDataCall = isDataCall; exports.copyCall = copyCall; exports.placeParams = placeParams; exports.Deferred = Deferred; exports.Pipeline = Pipeline; exports.Registry = Registry; exports.Server = Server; exports.Void = Void; exports.utils = utils; exports.PointerList = PointerList; exports.AnyPointerList = AnyPointerList; exports.BoolList = BoolList; exports.DataList = DataList; exports.Float32List = Float32List; exports.Float64List = Float64List; exports.Int8List = Int8List; exports.Int16List = Int16List; exports.Int32List = Int32List; exports.Int64List = Int64List; exports.InterfaceList = InterfaceList; exports.TextList = TextList; exports.Uint8List = Uint8List; exports.Uint16List = Uint16List; exports.Uint32List = Uint32List; exports.Uint64List = Uint64List; exports.VoidList = VoidList; exports.isSameClient = isSameClient; exports.clientFromResolution = clientFromResolution; exports.Conn = Conn; exports.answerPipelineClient = answerPipelineClient; exports.DeferredTransport = DeferredTransport; exports.MessageChannelTransport = MessageChannelTransport; exports.CapnpRPC = CapnpRPC;
4760
+ exports.Interface = Interface; exports.isFuncCall = isFuncCall; exports.isDataCall = isDataCall; exports.copyCall = copyCall; exports.placeParams = placeParams; exports.Deferred = Deferred; exports.Pipeline = Pipeline; exports.Registry = Registry; exports.Server = Server; exports.Void = Void; exports.utils = utils; exports.PointerList = PointerList; exports.AnyPointerList = AnyPointerList; exports.BoolList = BoolList; exports.DataList = DataList; exports.Float32List = Float32List; exports.Float64List = Float64List; exports.Int8List = Int8List; exports.Int16List = Int16List; exports.Int32List = Int32List; exports.Int64List = Int64List; exports.InterfaceList = InterfaceList; exports.TextList = TextList; exports.Uint8List = Uint8List; exports.Uint16List = Uint16List; exports.Uint32List = Uint32List; exports.Uint64List = Uint64List; exports.VoidList = VoidList; exports.isSameClient = isSameClient; exports.clientFromResolution = clientFromResolution; exports.Conn = Conn; exports.answerPipelineClient = answerPipelineClient; exports.DeferredTransport = DeferredTransport;
@@ -4723,121 +4723,6 @@ var DeferredTransport = class {
4723
4723
  }, "resolve");
4724
4724
  };
4725
4725
 
4726
- // src/rpc.ts
4727
- import { MessageChannel } from "worker_threads";
4728
- var MessageChannelTransport = class extends DeferredTransport {
4729
- static {
4730
- __name(this, "MessageChannelTransport");
4731
- }
4732
- port;
4733
- constructor(port) {
4734
- super(), this.port = port;
4735
- this.port.on("message", this.resolve);
4736
- this.port.on("messageerror", this.reject);
4737
- this.port.on("close", this.close);
4738
- }
4739
- close = /* @__PURE__ */ __name(() => {
4740
- this.port.off("message", this.resolve);
4741
- this.port.off("messageerror", this.reject);
4742
- this.port.off("close", this.close);
4743
- this.port.close();
4744
- super.close();
4745
- }, "close");
4746
- sendMessage(msg) {
4747
- const m = new Message();
4748
- m.setRoot(msg);
4749
- const buf = m.toArrayBuffer();
4750
- this.port.postMessage(buf, [
4751
- buf
4752
- ]);
4753
- }
4754
- };
4755
- var CapnpRPC = class {
4756
- static {
4757
- __name(this, "CapnpRPC");
4758
- }
4759
- /**
4760
- * A queue for deferred connections that are waiting to be accepted.
4761
- *
4762
- * @remarks
4763
- * This is used to manage incoming connections when the accept method is called.
4764
- */
4765
- acceptQueue = new Array();
4766
- /**
4767
- * A map of connections by their ID.
4768
- *
4769
- * @remarks
4770
- * This is used to manage multiple connections and allows for easy retrieval by ID.
4771
- */
4772
- connections = {};
4773
- /**
4774
- * A queue for connections that are waiting to be accepted.
4775
- *
4776
- * @remarks
4777
- * This is used to manage incoming connections when the accept method is called.
4778
- */
4779
- connectQueue = new Array();
4780
- /**
4781
- * Creates a new {@link Conn} instance.
4782
- *
4783
- * @remarks
4784
- * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
4785
- */
4786
- connect(id = 0) {
4787
- if (this.connections[id] !== void 0) {
4788
- return this.connections[id];
4789
- }
4790
- const ch = new MessageChannel();
4791
- const conn = new Conn(new MessageChannelTransport(ch.port1));
4792
- const accept = this.acceptQueue.pop();
4793
- this.connections[id] = conn;
4794
- if (accept === void 0) {
4795
- this.connectQueue.push(ch.port2);
4796
- } else {
4797
- accept.resolve(new Conn(new MessageChannelTransport(ch.port2)));
4798
- }
4799
- return conn;
4800
- }
4801
- /**
4802
- * Accepts a connection from the connect queue.
4803
- *
4804
- * @returns A promise that resolves to a Conn instance when a connection is accepted.
4805
- * @throws If no connections are available in the connect queue.
4806
- */
4807
- async accept() {
4808
- const port2 = this.connectQueue.pop();
4809
- if (port2 !== void 0) {
4810
- return Promise.resolve(new Conn(new MessageChannelTransport(port2)));
4811
- }
4812
- const deferred = new Deferred();
4813
- this.acceptQueue.push(deferred);
4814
- return deferred.promise;
4815
- }
4816
- /**
4817
- * Closes all connections and clears the queues.
4818
- *
4819
- * @remarks
4820
- * This method will reject all pending accept promises and close all
4821
- * connections in the connect queue.
4822
- */
4823
- close() {
4824
- let i = this.acceptQueue.length;
4825
- while (--i >= 0) {
4826
- this.acceptQueue[i]?.reject();
4827
- }
4828
- i = this.connectQueue.length;
4829
- while (--i >= 0) {
4830
- this.connectQueue[i].close();
4831
- }
4832
- for (const id in this.connections) {
4833
- this.connections[id]?.shutdown();
4834
- }
4835
- this.acceptQueue.length = 0;
4836
- this.connectQueue.length = 0;
4837
- this.connections = {};
4838
- }
4839
- };
4840
-
4841
4726
  export {
4842
4727
  Interface,
4843
4728
  isFuncCall,
@@ -4871,7 +4756,5 @@ export {
4871
4756
  clientFromResolution,
4872
4757
  Conn,
4873
4758
  answerPipelineClient,
4874
- DeferredTransport,
4875
- MessageChannelTransport,
4876
- CapnpRPC
4759
+ DeferredTransport
4877
4760
  };
@@ -1,6 +1,7 @@
1
1
  import * as capnp_es_capnp_schema from 'capnp-es/capnp/schema';
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { CapnpcResolvedOptions, CapnpcResult, CapnpcOptions } from './types.cjs';
4
+ import 'capnp-es';
4
5
  import 'typescript';
5
6
 
6
7
  /**
package/dist/compile.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as capnp_es_capnp_schema from 'capnp-es/capnp/schema';
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { CapnpcResolvedOptions, CapnpcResult, CapnpcOptions } from './types.js';
4
+ import 'capnp-es';
4
5
  import 'typescript';
5
6
 
6
7
  /**
package/dist/index.cjs CHANGED
@@ -37,9 +37,7 @@ require('./chunk-AVGQAS6B.cjs');
37
37
 
38
38
 
39
39
 
40
-
41
-
42
- var _chunkCUP3M7JHcjs = require('./chunk-CUP3M7JH.cjs');
40
+ var _chunkLFP6TIPQcjs = require('./chunk-LFP6TIPQ.cjs');
43
41
 
44
42
 
45
43
 
@@ -133,6 +131,4 @@ require('./chunk-USNT2KNT.cjs');
133
131
 
134
132
 
135
133
 
136
-
137
-
138
- exports.AnyPointerList = _chunkCUP3M7JHcjs.AnyPointerList; exports.BoolList = _chunkCUP3M7JHcjs.BoolList; exports.CapnpRPC = _chunkCUP3M7JHcjs.CapnpRPC; exports.CodeGeneratorContext = _chunkR2JXWA7Qcjs.CodeGeneratorContext; exports.CompositeList = _chunkKMCJ5MIQcjs.CompositeList; exports.Conn = _chunkCUP3M7JHcjs.Conn; exports.Data = _chunkKMCJ5MIQcjs.Data; exports.DataList = _chunkCUP3M7JHcjs.DataList; exports.Deferred = _chunkCUP3M7JHcjs.Deferred; exports.DeferredTransport = _chunkCUP3M7JHcjs.DeferredTransport; exports.ErrorClient = _chunkKMCJ5MIQcjs.ErrorClient; exports.Float32List = _chunkCUP3M7JHcjs.Float32List; exports.Float64List = _chunkCUP3M7JHcjs.Float64List; exports.Int16List = _chunkCUP3M7JHcjs.Int16List; exports.Int32List = _chunkCUP3M7JHcjs.Int32List; exports.Int64List = _chunkCUP3M7JHcjs.Int64List; exports.Int8List = _chunkCUP3M7JHcjs.Int8List; exports.Interface = _chunkCUP3M7JHcjs.Interface; exports.InterfaceList = _chunkCUP3M7JHcjs.InterfaceList; exports.List = _chunkKMCJ5MIQcjs.List; exports.ListElementSize = _chunkKMCJ5MIQcjs.ListElementSize; exports.Message = _chunkKMCJ5MIQcjs.Message; exports.MessageChannelTransport = _chunkCUP3M7JHcjs.MessageChannelTransport; exports.ObjectSize = _chunkKMCJ5MIQcjs.ObjectSize; exports.Orphan = _chunkKMCJ5MIQcjs.Orphan; exports.Pipeline = _chunkCUP3M7JHcjs.Pipeline; exports.Pointer = _chunkKMCJ5MIQcjs.Pointer; exports.PointerList = _chunkCUP3M7JHcjs.PointerList; exports.PointerType = _chunkKMCJ5MIQcjs.PointerType; exports.Registry = _chunkCUP3M7JHcjs.Registry; exports.Server = _chunkCUP3M7JHcjs.Server; exports.Struct = _chunkKMCJ5MIQcjs.Struct; exports.Text = _chunkKMCJ5MIQcjs.Text; exports.TextList = _chunkCUP3M7JHcjs.TextList; exports.Uint16List = _chunkCUP3M7JHcjs.Uint16List; exports.Uint32List = _chunkCUP3M7JHcjs.Uint32List; exports.Uint64List = _chunkCUP3M7JHcjs.Uint64List; exports.Uint8List = _chunkCUP3M7JHcjs.Uint8List; exports.Void = _chunkCUP3M7JHcjs.Void; exports.VoidList = _chunkCUP3M7JHcjs.VoidList; exports.answerPipelineClient = _chunkCUP3M7JHcjs.answerPipelineClient; exports.capnpc = _chunk7JOFTCPGcjs.capnpc; exports.clientFromResolution = _chunkCUP3M7JHcjs.clientFromResolution; exports.clientOrNull = _chunkKMCJ5MIQcjs.clientOrNull; exports.compile = _chunk7JOFTCPGcjs.compile; exports.copyCall = _chunkCUP3M7JHcjs.copyCall; exports.getBitMask = _chunkKMCJ5MIQcjs.getBitMask; exports.getFloat32Mask = _chunkKMCJ5MIQcjs.getFloat32Mask; exports.getFloat64Mask = _chunkKMCJ5MIQcjs.getFloat64Mask; exports.getInt16Mask = _chunkKMCJ5MIQcjs.getInt16Mask; exports.getInt32Mask = _chunkKMCJ5MIQcjs.getInt32Mask; exports.getInt64Mask = _chunkKMCJ5MIQcjs.getInt64Mask; exports.getInt8Mask = _chunkKMCJ5MIQcjs.getInt8Mask; exports.getUint16Mask = _chunkKMCJ5MIQcjs.getUint16Mask; exports.getUint32Mask = _chunkKMCJ5MIQcjs.getUint32Mask; exports.getUint64Mask = _chunkKMCJ5MIQcjs.getUint64Mask; exports.getUint8Mask = _chunkKMCJ5MIQcjs.getUint8Mask; exports.isDataCall = _chunkCUP3M7JHcjs.isDataCall; exports.isFuncCall = _chunkCUP3M7JHcjs.isFuncCall; exports.isSameClient = _chunkCUP3M7JHcjs.isSameClient; exports.placeParams = _chunkCUP3M7JHcjs.placeParams; exports.readRawPointer = _chunkKMCJ5MIQcjs.readRawPointer; exports.utils = _chunkCUP3M7JHcjs.utils;
134
+ exports.AnyPointerList = _chunkLFP6TIPQcjs.AnyPointerList; exports.BoolList = _chunkLFP6TIPQcjs.BoolList; exports.CodeGeneratorContext = _chunkR2JXWA7Qcjs.CodeGeneratorContext; exports.CompositeList = _chunkKMCJ5MIQcjs.CompositeList; exports.Conn = _chunkLFP6TIPQcjs.Conn; exports.Data = _chunkKMCJ5MIQcjs.Data; exports.DataList = _chunkLFP6TIPQcjs.DataList; exports.Deferred = _chunkLFP6TIPQcjs.Deferred; exports.DeferredTransport = _chunkLFP6TIPQcjs.DeferredTransport; exports.ErrorClient = _chunkKMCJ5MIQcjs.ErrorClient; exports.Float32List = _chunkLFP6TIPQcjs.Float32List; exports.Float64List = _chunkLFP6TIPQcjs.Float64List; exports.Int16List = _chunkLFP6TIPQcjs.Int16List; exports.Int32List = _chunkLFP6TIPQcjs.Int32List; exports.Int64List = _chunkLFP6TIPQcjs.Int64List; exports.Int8List = _chunkLFP6TIPQcjs.Int8List; exports.Interface = _chunkLFP6TIPQcjs.Interface; exports.InterfaceList = _chunkLFP6TIPQcjs.InterfaceList; exports.List = _chunkKMCJ5MIQcjs.List; exports.ListElementSize = _chunkKMCJ5MIQcjs.ListElementSize; exports.Message = _chunkKMCJ5MIQcjs.Message; exports.ObjectSize = _chunkKMCJ5MIQcjs.ObjectSize; exports.Orphan = _chunkKMCJ5MIQcjs.Orphan; exports.Pipeline = _chunkLFP6TIPQcjs.Pipeline; exports.Pointer = _chunkKMCJ5MIQcjs.Pointer; exports.PointerList = _chunkLFP6TIPQcjs.PointerList; exports.PointerType = _chunkKMCJ5MIQcjs.PointerType; exports.Registry = _chunkLFP6TIPQcjs.Registry; exports.Server = _chunkLFP6TIPQcjs.Server; exports.Struct = _chunkKMCJ5MIQcjs.Struct; exports.Text = _chunkKMCJ5MIQcjs.Text; exports.TextList = _chunkLFP6TIPQcjs.TextList; exports.Uint16List = _chunkLFP6TIPQcjs.Uint16List; exports.Uint32List = _chunkLFP6TIPQcjs.Uint32List; exports.Uint64List = _chunkLFP6TIPQcjs.Uint64List; exports.Uint8List = _chunkLFP6TIPQcjs.Uint8List; exports.Void = _chunkLFP6TIPQcjs.Void; exports.VoidList = _chunkLFP6TIPQcjs.VoidList; exports.answerPipelineClient = _chunkLFP6TIPQcjs.answerPipelineClient; exports.capnpc = _chunk7JOFTCPGcjs.capnpc; exports.clientFromResolution = _chunkLFP6TIPQcjs.clientFromResolution; exports.clientOrNull = _chunkKMCJ5MIQcjs.clientOrNull; exports.compile = _chunk7JOFTCPGcjs.compile; exports.copyCall = _chunkLFP6TIPQcjs.copyCall; exports.getBitMask = _chunkKMCJ5MIQcjs.getBitMask; exports.getFloat32Mask = _chunkKMCJ5MIQcjs.getFloat32Mask; exports.getFloat64Mask = _chunkKMCJ5MIQcjs.getFloat64Mask; exports.getInt16Mask = _chunkKMCJ5MIQcjs.getInt16Mask; exports.getInt32Mask = _chunkKMCJ5MIQcjs.getInt32Mask; exports.getInt64Mask = _chunkKMCJ5MIQcjs.getInt64Mask; exports.getInt8Mask = _chunkKMCJ5MIQcjs.getInt8Mask; exports.getUint16Mask = _chunkKMCJ5MIQcjs.getUint16Mask; exports.getUint32Mask = _chunkKMCJ5MIQcjs.getUint32Mask; exports.getUint64Mask = _chunkKMCJ5MIQcjs.getUint64Mask; exports.getUint8Mask = _chunkKMCJ5MIQcjs.getUint8Mask; exports.isDataCall = _chunkLFP6TIPQcjs.isDataCall; exports.isFuncCall = _chunkLFP6TIPQcjs.isFuncCall; exports.isSameClient = _chunkLFP6TIPQcjs.isSameClient; exports.placeParams = _chunkLFP6TIPQcjs.placeParams; exports.readRawPointer = _chunkKMCJ5MIQcjs.readRawPointer; exports.utils = _chunkLFP6TIPQcjs.utils;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,6 @@
1
1
  export { capnpc, compile } from './compile.cjs';
2
- export { CapnpRPC, MessageChannelTransport } from './rpc.cjs';
3
2
  export { CapnpcCLIOptions, CapnpcOptions, CapnpcResolvedOptions, CapnpcResult, CodeGeneratorContext, CodeGeneratorFileContext } from './types.cjs';
4
3
  export * from 'capnp-es';
5
4
  import 'capnp-es/capnp/schema';
6
5
  import 'node:buffer';
7
- import 'capnp-es/capnp/rpc';
8
- import 'node:worker_threads';
9
6
  import 'typescript';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export { capnpc, compile } from './compile.js';
2
- export { CapnpRPC, MessageChannelTransport } from './rpc.js';
3
2
  export { CapnpcCLIOptions, CapnpcOptions, CapnpcResolvedOptions, CapnpcResult, CodeGeneratorContext, CodeGeneratorFileContext } from './types.js';
4
3
  export * from 'capnp-es';
5
4
  import 'capnp-es/capnp/schema';
6
5
  import 'node:buffer';
7
- import 'capnp-es/capnp/rpc';
8
- import 'node:worker_threads';
9
6
  import 'typescript';
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import "./chunk-JNOQ32JO.js";
6
6
  import {
7
7
  AnyPointerList,
8
8
  BoolList,
9
- CapnpRPC,
10
9
  Conn,
11
10
  DataList,
12
11
  Deferred,
@@ -19,7 +18,6 @@ import {
19
18
  Int8List,
20
19
  Interface,
21
20
  InterfaceList,
22
- MessageChannelTransport,
23
21
  Pipeline,
24
22
  PointerList,
25
23
  Registry,
@@ -39,7 +37,7 @@ import {
39
37
  isSameClient,
40
38
  placeParams,
41
39
  utils
42
- } from "./chunk-MO4AXOIN.js";
40
+ } from "./chunk-ZIENMW4V.js";
43
41
  import {
44
42
  CompositeList,
45
43
  Data,
@@ -74,7 +72,6 @@ import "./chunk-SHUYVCID.js";
74
72
  export {
75
73
  AnyPointerList,
76
74
  BoolList,
77
- CapnpRPC,
78
75
  CodeGeneratorContext,
79
76
  CompositeList,
80
77
  Conn,
@@ -94,7 +91,6 @@ export {
94
91
  List,
95
92
  ListElementSize,
96
93
  Message,
97
- MessageChannelTransport,
98
94
  ObjectSize,
99
95
  Orphan,
100
96
  Pipeline,
package/dist/rpc.cjs CHANGED
@@ -1,10 +1,139 @@
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; } var _class; var _class2;
2
2
 
3
3
 
4
- var _chunkCUP3M7JHcjs = require('./chunk-CUP3M7JH.cjs');
5
- require('./chunk-KMCJ5MIQ.cjs');
6
- require('./chunk-USNT2KNT.cjs');
7
4
 
5
+ var _chunkLFP6TIPQcjs = require('./chunk-LFP6TIPQ.cjs');
8
6
 
9
7
 
10
- exports.CapnpRPC = _chunkCUP3M7JHcjs.CapnpRPC; exports.MessageChannelTransport = _chunkCUP3M7JHcjs.MessageChannelTransport;
8
+ var _chunkKMCJ5MIQcjs = require('./chunk-KMCJ5MIQ.cjs');
9
+
10
+
11
+ var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
12
+
13
+ // src/rpc.ts
14
+ var _worker_threads = require('worker_threads');
15
+ var CapnpRPCMessageChannelTransport = (_class = class extends _chunkLFP6TIPQcjs.DeferredTransport {
16
+ static {
17
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "CapnpRPCMessageChannelTransport");
18
+ }
19
+
20
+ constructor(port) {
21
+ super();_class.prototype.__init.call(this);;
22
+ this.port = port;
23
+ this.port.on("message", this.resolve);
24
+ this.port.on("messageerror", this.reject);
25
+ this.port.on("close", this.close);
26
+ }
27
+ /**
28
+ * Closes the transport and removes all event listeners.
29
+ */
30
+ __init() {this.close = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, () => {
31
+ this.port.off("message", this.resolve);
32
+ this.port.off("messageerror", this.reject);
33
+ this.port.off("close", this.close);
34
+ this.port.close();
35
+ super.close();
36
+ }, "close")}
37
+ /**
38
+ * Sends a Cap'n Proto RPC message over the MessagePort.
39
+ *
40
+ * @param msg - The RPC message to send.
41
+ */
42
+ sendMessage(msg) {
43
+ const m = new (0, _chunkKMCJ5MIQcjs.Message)();
44
+ m.setRoot(msg);
45
+ const buf = m.toArrayBuffer();
46
+ this.port.postMessage(buf, [
47
+ buf
48
+ ]);
49
+ }
50
+ }, _class);
51
+ var CapnpRPC = (_class2 = class {constructor() { _class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this); }
52
+ static {
53
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "CapnpRPC");
54
+ }
55
+ /**
56
+ * A queue for deferred connections that are waiting to be accepted.
57
+ *
58
+ * @remarks
59
+ * This is used to manage incoming connections when the accept method is called.
60
+ */
61
+ __init2() {this.acceptQueue = new Array()}
62
+ /**
63
+ * A map of connections by their ID.
64
+ *
65
+ * @remarks
66
+ * This is used to manage multiple connections and allows for easy retrieval by ID.
67
+ */
68
+ __init3() {this.connections = {}}
69
+ /**
70
+ * A queue for connections that are waiting to be accepted.
71
+ *
72
+ * @remarks
73
+ * This is used to manage incoming connections when the accept method is called.
74
+ */
75
+ __init4() {this.connectQueue = new Array()}
76
+ /**
77
+ * Creates a new {@link Conn} instance.
78
+ *
79
+ * @remarks
80
+ * This class is used to manage connections and accept incoming connections using the {@link MessageChannel} API.
81
+ */
82
+ connect(id = 0) {
83
+ if (this.connections[id] !== void 0) {
84
+ return this.connections[id];
85
+ }
86
+ const ch = new (0, _worker_threads.MessageChannel)();
87
+ const conn = new (0, _chunkLFP6TIPQcjs.Conn)(new CapnpRPCMessageChannelTransport(ch.port1));
88
+ const accept = this.acceptQueue.pop();
89
+ this.connections[id] = conn;
90
+ if (accept === void 0) {
91
+ this.connectQueue.push(ch.port2);
92
+ } else {
93
+ accept.resolve(new (0, _chunkLFP6TIPQcjs.Conn)(new CapnpRPCMessageChannelTransport(ch.port2)));
94
+ }
95
+ return conn;
96
+ }
97
+ /**
98
+ * Accepts a connection from the connect queue.
99
+ *
100
+ * @returns A promise that resolves to a Conn instance when a connection is accepted.
101
+ * @throws If no connections are available in the connect queue.
102
+ */
103
+ async accept() {
104
+ const port2 = this.connectQueue.pop();
105
+ if (port2 !== void 0) {
106
+ return Promise.resolve(new (0, _chunkLFP6TIPQcjs.Conn)(new CapnpRPCMessageChannelTransport(port2)));
107
+ }
108
+ const deferred = new (0, _chunkLFP6TIPQcjs.Deferred)();
109
+ this.acceptQueue.push(deferred);
110
+ return deferred.promise;
111
+ }
112
+ /**
113
+ * Closes all connections and clears the queues.
114
+ *
115
+ * @remarks
116
+ * This method will reject all pending accept promises and close all
117
+ * connections in the connect queue.
118
+ */
119
+ close() {
120
+ let i = this.acceptQueue.length;
121
+ while (--i >= 0) {
122
+ _optionalChain([this, 'access', _ => _.acceptQueue, 'access', _2 => _2[i], 'optionalAccess', _3 => _3.reject, 'call', _4 => _4()]);
123
+ }
124
+ i = this.connectQueue.length;
125
+ while (--i >= 0) {
126
+ this.connectQueue[i].close();
127
+ }
128
+ for (const id in this.connections) {
129
+ _optionalChain([this, 'access', _5 => _5.connections, 'access', _6 => _6[id], 'optionalAccess', _7 => _7.shutdown, 'call', _8 => _8()]);
130
+ }
131
+ this.acceptQueue.length = 0;
132
+ this.connectQueue.length = 0;
133
+ this.connections = {};
134
+ }
135
+ }, _class2);
136
+
137
+
138
+
139
+ exports.CapnpRPC = CapnpRPC; exports.CapnpRPCMessageChannelTransport = CapnpRPCMessageChannelTransport;
package/dist/rpc.d.cts CHANGED
@@ -2,10 +2,21 @@ 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 {
5
+ /**
6
+ * A transport class for Cap'n Proto RPC that uses {@link MessageChannel} for communication.
7
+ */
8
+ declare class CapnpRPCMessageChannelTransport extends DeferredTransport {
6
9
  port: MessagePort;
7
10
  constructor(port: MessagePort);
11
+ /**
12
+ * Closes the transport and removes all event listeners.
13
+ */
8
14
  close: () => void;
15
+ /**
16
+ * Sends a Cap'n Proto RPC message over the MessagePort.
17
+ *
18
+ * @param msg - The RPC message to send.
19
+ */
9
20
  sendMessage(msg: Message): void;
10
21
  }
11
22
  /**
@@ -57,4 +68,4 @@ declare class CapnpRPC {
57
68
  close(): void;
58
69
  }
59
70
 
60
- export { CapnpRPC, MessageChannelTransport };
71
+ export { CapnpRPC, CapnpRPCMessageChannelTransport };
package/dist/rpc.d.ts CHANGED
@@ -2,10 +2,21 @@ 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 {
5
+ /**
6
+ * A transport class for Cap'n Proto RPC that uses {@link MessageChannel} for communication.
7
+ */
8
+ declare class CapnpRPCMessageChannelTransport extends DeferredTransport {
6
9
  port: MessagePort;
7
10
  constructor(port: MessagePort);
11
+ /**
12
+ * Closes the transport and removes all event listeners.
13
+ */
8
14
  close: () => void;
15
+ /**
16
+ * Sends a Cap'n Proto RPC message over the MessagePort.
17
+ *
18
+ * @param msg - The RPC message to send.
19
+ */
9
20
  sendMessage(msg: Message): void;
10
21
  }
11
22
  /**
@@ -57,4 +68,4 @@ declare class CapnpRPC {
57
68
  close(): void;
58
69
  }
59
70
 
60
- export { CapnpRPC, MessageChannelTransport };
71
+ export { CapnpRPC, CapnpRPCMessageChannelTransport };