@zlink-systems/zlink 0.17.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.
Files changed (199) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +198 -0
  3. package/README.typedoc.md +56 -0
  4. package/THIRD_PARTY_NOTICES.md +84 -0
  5. package/binding.gyp +27 -0
  6. package/dist/index.d.mts +3 -0
  7. package/dist/index.d.ts +24 -0
  8. package/dist/index.js +117 -0
  9. package/dist/index.mjs +4 -0
  10. package/dist/zlink/contracts/core/buffer_like.d.ts +2 -0
  11. package/dist/zlink/contracts/core/buffer_like.js +3 -0
  12. package/dist/zlink/contracts/core/context.d.ts +103 -0
  13. package/dist/zlink/contracts/core/context.js +11 -0
  14. package/dist/zlink/contracts/core/index.d.ts +3 -0
  15. package/dist/zlink/contracts/core/index.js +20 -0
  16. package/dist/zlink/contracts/core/routing_id.d.ts +28 -0
  17. package/dist/zlink/contracts/core/routing_id.js +120 -0
  18. package/dist/zlink/contracts/errors/errors.d.ts +44 -0
  19. package/dist/zlink/contracts/errors/errors.js +89 -0
  20. package/dist/zlink/contracts/errors/index.d.ts +2 -0
  21. package/dist/zlink/contracts/errors/index.js +29 -0
  22. package/dist/zlink/contracts/errors/results.d.ts +106 -0
  23. package/dist/zlink/contracts/errors/results.js +102 -0
  24. package/dist/zlink/contracts/eventing/index.d.ts +3 -0
  25. package/dist/zlink/contracts/eventing/index.js +20 -0
  26. package/dist/zlink/contracts/eventing/monitor.d.ts +157 -0
  27. package/dist/zlink/contracts/eventing/monitor.js +82 -0
  28. package/dist/zlink/contracts/eventing/poller.d.ts +76 -0
  29. package/dist/zlink/contracts/eventing/poller.js +3 -0
  30. package/dist/zlink/contracts/eventing/timer.d.ts +38 -0
  31. package/dist/zlink/contracts/eventing/timer.js +3 -0
  32. package/dist/zlink/contracts/index.d.ts +5 -0
  33. package/dist/zlink/contracts/index.js +22 -0
  34. package/dist/zlink/contracts/messaging/handlers.d.ts +5 -0
  35. package/dist/zlink/contracts/messaging/handlers.js +3 -0
  36. package/dist/zlink/contracts/messaging/index.d.ts +8 -0
  37. package/dist/zlink/contracts/messaging/index.js +15 -0
  38. package/dist/zlink/contracts/messaging/message.d.ts +68 -0
  39. package/dist/zlink/contracts/messaging/message.js +280 -0
  40. package/dist/zlink/contracts/messaging/message_parts_envelope.d.ts +14 -0
  41. package/dist/zlink/contracts/messaging/message_parts_envelope.js +56 -0
  42. package/dist/zlink/contracts/messaging/operations.d.ts +54 -0
  43. package/dist/zlink/contracts/messaging/operations.js +3 -0
  44. package/dist/zlink/contracts/messaging/received.d.ts +41 -0
  45. package/dist/zlink/contracts/messaging/received.js +130 -0
  46. package/dist/zlink/contracts/messaging/stream_packet.d.ts +14 -0
  47. package/dist/zlink/contracts/messaging/stream_packet.js +33 -0
  48. package/dist/zlink/contracts/messaging/subscription_event.d.ts +12 -0
  49. package/dist/zlink/contracts/messaging/subscription_event.js +20 -0
  50. package/dist/zlink/contracts/messaging/topic_message.d.ts +14 -0
  51. package/dist/zlink/contracts/messaging/topic_message.js +36 -0
  52. package/dist/zlink/contracts/sockets/dealer_socket.d.ts +29 -0
  53. package/dist/zlink/contracts/sockets/dealer_socket.js +3 -0
  54. package/dist/zlink/contracts/sockets/index.d.ts +10 -0
  55. package/dist/zlink/contracts/sockets/index.js +15 -0
  56. package/dist/zlink/contracts/sockets/pair_socket.d.ts +20 -0
  57. package/dist/zlink/contracts/sockets/pair_socket.js +3 -0
  58. package/dist/zlink/contracts/sockets/pubsub_sockets.d.ts +40 -0
  59. package/dist/zlink/contracts/sockets/pubsub_sockets.js +3 -0
  60. package/dist/zlink/contracts/sockets/router_socket.d.ts +32 -0
  61. package/dist/zlink/contracts/sockets/router_socket.js +3 -0
  62. package/dist/zlink/contracts/sockets/socket.d.ts +58 -0
  63. package/dist/zlink/contracts/sockets/socket.js +3 -0
  64. package/dist/zlink/contracts/sockets/socket_constants.d.ts +88 -0
  65. package/dist/zlink/contracts/sockets/socket_constants.js +67 -0
  66. package/dist/zlink/contracts/sockets/socket_options.d.ts +105 -0
  67. package/dist/zlink/contracts/sockets/socket_options.js +3 -0
  68. package/dist/zlink/contracts/sockets/stream_socket.d.ts +31 -0
  69. package/dist/zlink/contracts/sockets/stream_socket.js +3 -0
  70. package/dist/zlink/runtime/buffers/message_conversion.d.ts +6 -0
  71. package/dist/zlink/runtime/buffers/message_conversion.js +49 -0
  72. package/dist/zlink/runtime/core/context.d.ts +43 -0
  73. package/dist/zlink/runtime/core/context.js +150 -0
  74. package/dist/zlink/runtime/core/context_options.d.ts +19 -0
  75. package/dist/zlink/runtime/core/context_options.js +23 -0
  76. package/dist/zlink/runtime/core/routing_id.d.ts +3 -0
  77. package/dist/zlink/runtime/core/routing_id.js +30 -0
  78. package/dist/zlink/runtime/core/routing_id_conversion.d.ts +2 -0
  79. package/dist/zlink/runtime/core/routing_id_conversion.js +11 -0
  80. package/dist/zlink/runtime/core/runtime_info.d.ts +8 -0
  81. package/dist/zlink/runtime/core/runtime_info.js +39 -0
  82. package/dist/zlink/runtime/errors/error_mapping.d.ts +4 -0
  83. package/dist/zlink/runtime/errors/error_mapping.js +132 -0
  84. package/dist/zlink/runtime/errors/error_state.d.ts +1 -0
  85. package/dist/zlink/runtime/errors/error_state.js +15 -0
  86. package/dist/zlink/runtime/errors/native_errors.d.ts +16 -0
  87. package/dist/zlink/runtime/errors/native_errors.js +86 -0
  88. package/dist/zlink/runtime/eventing/counters.d.ts +16 -0
  89. package/dist/zlink/runtime/eventing/counters.js +33 -0
  90. package/dist/zlink/runtime/eventing/index.d.ts +6 -0
  91. package/dist/zlink/runtime/eventing/index.js +22 -0
  92. package/dist/zlink/runtime/eventing/monitor_event_state.d.ts +3 -0
  93. package/dist/zlink/runtime/eventing/monitor_event_state.js +19 -0
  94. package/dist/zlink/runtime/eventing/monitor_raw.d.ts +50 -0
  95. package/dist/zlink/runtime/eventing/monitor_raw.js +3 -0
  96. package/dist/zlink/runtime/eventing/monitor_socket.d.ts +9 -0
  97. package/dist/zlink/runtime/eventing/monitor_socket.js +39 -0
  98. package/dist/zlink/runtime/eventing/monitor_status.d.ts +3 -0
  99. package/dist/zlink/runtime/eventing/monitor_status.js +52 -0
  100. package/dist/zlink/runtime/eventing/poll_events.d.ts +20 -0
  101. package/dist/zlink/runtime/eventing/poll_events.js +92 -0
  102. package/dist/zlink/runtime/eventing/poller.d.ts +34 -0
  103. package/dist/zlink/runtime/eventing/poller.js +275 -0
  104. package/dist/zlink/runtime/eventing/thread.d.ts +6 -0
  105. package/dist/zlink/runtime/eventing/thread.js +52 -0
  106. package/dist/zlink/runtime/eventing/timer.d.ts +8 -0
  107. package/dist/zlink/runtime/eventing/timer.js +45 -0
  108. package/dist/zlink/runtime/handles/native_handle.d.ts +7 -0
  109. package/dist/zlink/runtime/handles/native_handle.js +24 -0
  110. package/dist/zlink/runtime/messaging/completion_owner.d.ts +86 -0
  111. package/dist/zlink/runtime/messaging/completion_owner.js +570 -0
  112. package/dist/zlink/runtime/messaging/message_materializer.d.ts +36 -0
  113. package/dist/zlink/runtime/messaging/message_materializer.js +199 -0
  114. package/dist/zlink/runtime/messaging/message_parts_state.d.ts +4 -0
  115. package/dist/zlink/runtime/messaging/message_parts_state.js +20 -0
  116. package/dist/zlink/runtime/messaging/message_snapshot.d.ts +13 -0
  117. package/dist/zlink/runtime/messaging/message_snapshot.js +42 -0
  118. package/dist/zlink/runtime/messaging/received_operations.d.ts +5 -0
  119. package/dist/zlink/runtime/messaging/received_operations.js +46 -0
  120. package/dist/zlink/runtime/messaging/received_state.d.ts +13 -0
  121. package/dist/zlink/runtime/messaging/received_state.js +29 -0
  122. package/dist/zlink/runtime/messaging/request_executor.d.ts +2 -0
  123. package/dist/zlink/runtime/messaging/request_executor.js +8 -0
  124. package/dist/zlink/runtime/messaging/send_operation_base.d.ts +13 -0
  125. package/dist/zlink/runtime/messaging/send_operation_base.js +52 -0
  126. package/dist/zlink/runtime/messaging/subscription_event_state.d.ts +4 -0
  127. package/dist/zlink/runtime/messaging/subscription_event_state.js +17 -0
  128. package/dist/zlink/runtime/messaging/topic_message_state.d.ts +11 -0
  129. package/dist/zlink/runtime/messaging/topic_message_state.js +75 -0
  130. package/dist/zlink/runtime/native/binding.d.ts +6 -0
  131. package/dist/zlink/runtime/native/binding.js +3 -0
  132. package/dist/zlink/runtime/native/binding_context.d.ts +14 -0
  133. package/dist/zlink/runtime/native/binding_context.js +3 -0
  134. package/dist/zlink/runtime/native/binding_core.d.ts +21 -0
  135. package/dist/zlink/runtime/native/binding_core.js +3 -0
  136. package/dist/zlink/runtime/native/binding_eventing.d.ts +40 -0
  137. package/dist/zlink/runtime/native/binding_eventing.js +3 -0
  138. package/dist/zlink/runtime/native/binding_socket.d.ts +52 -0
  139. package/dist/zlink/runtime/native/binding_socket.js +3 -0
  140. package/dist/zlink/runtime/native/binding_types.d.ts +8 -0
  141. package/dist/zlink/runtime/native/binding_types.js +3 -0
  142. package/dist/zlink/runtime/native/native.d.ts +2 -0
  143. package/dist/zlink/runtime/native/native.js +40 -0
  144. package/dist/zlink/runtime/native/native_load_paths.d.ts +16 -0
  145. package/dist/zlink/runtime/native/native_load_paths.js +165 -0
  146. package/dist/zlink/runtime/options/byte_values.d.ts +3 -0
  147. package/dist/zlink/runtime/options/byte_values.js +27 -0
  148. package/dist/zlink/runtime/options/option_mapping.d.ts +72 -0
  149. package/dist/zlink/runtime/options/option_mapping.js +41 -0
  150. package/dist/zlink/runtime/options/validation.d.ts +1 -0
  151. package/dist/zlink/runtime/options/validation.js +17 -0
  152. package/dist/zlink/runtime/public_bridge.d.ts +6 -0
  153. package/dist/zlink/runtime/public_bridge.js +23 -0
  154. package/dist/zlink/runtime/sockets/dealer_socket.d.ts +16 -0
  155. package/dist/zlink/runtime/sockets/dealer_socket.js +56 -0
  156. package/dist/zlink/runtime/sockets/index.d.ts +19 -0
  157. package/dist/zlink/runtime/sockets/index.js +27 -0
  158. package/dist/zlink/runtime/sockets/pair_socket.d.ts +7 -0
  159. package/dist/zlink/runtime/sockets/pair_socket.js +12 -0
  160. package/dist/zlink/runtime/sockets/pub_socket.d.ts +7 -0
  161. package/dist/zlink/runtime/sockets/pub_socket.js +12 -0
  162. package/dist/zlink/runtime/sockets/router_socket.d.ts +19 -0
  163. package/dist/zlink/runtime/sockets/router_socket.js +70 -0
  164. package/dist/zlink/runtime/sockets/socket_base.d.ts +21 -0
  165. package/dist/zlink/runtime/sockets/socket_base.js +102 -0
  166. package/dist/zlink/runtime/sockets/socket_operation_builders.d.ts +38 -0
  167. package/dist/zlink/runtime/sockets/socket_operation_builders.js +93 -0
  168. package/dist/zlink/runtime/sockets/socket_operations.d.ts +40 -0
  169. package/dist/zlink/runtime/sockets/socket_operations.js +177 -0
  170. package/dist/zlink/runtime/sockets/socket_options.d.ts +104 -0
  171. package/dist/zlink/runtime/sockets/socket_options.js +259 -0
  172. package/dist/zlink/runtime/sockets/socket_submit_errors.d.ts +3 -0
  173. package/dist/zlink/runtime/sockets/socket_submit_errors.js +13 -0
  174. package/dist/zlink/runtime/sockets/stream_socket.d.ts +15 -0
  175. package/dist/zlink/runtime/sockets/stream_socket.js +93 -0
  176. package/dist/zlink/runtime/sockets/sub_socket.d.ts +7 -0
  177. package/dist/zlink/runtime/sockets/sub_socket.js +12 -0
  178. package/dist/zlink/runtime/sockets/xpub_socket.d.ts +10 -0
  179. package/dist/zlink/runtime/sockets/xpub_socket.js +39 -0
  180. package/dist/zlink/runtime/sockets/xsub_socket.d.ts +7 -0
  181. package/dist/zlink/runtime/sockets/xsub_socket.js +12 -0
  182. package/native/src/addon.cc +11 -0
  183. package/native/src/addon_common_api.h +57 -0
  184. package/native/src/addon_core.cc +3974 -0
  185. package/native/src/addon_core_api.h +110 -0
  186. package/native/src/addon_core_options.cc +119 -0
  187. package/native/src/addon_core_options.h +9 -0
  188. package/native/src/addon_exports.cc +151 -0
  189. package/native/src/addon_exports.h +7 -0
  190. package/native/src/addon_message_parts.h +67 -0
  191. package/native/src/addon_message_values.h +345 -0
  192. package/native/src/addon_monitor_status_values.h +71 -0
  193. package/native/src/addon_submit_results.h +30 -0
  194. package/package.json +74 -0
  195. package/prebuilds/linux-x64/libzlink.so.0.17.3 +0 -0
  196. package/prebuilds/linux-x64/zlink.node +0 -0
  197. package/provenance/core-package-provenance.json +73 -0
  198. package/scripts/install.js +37 -0
  199. package/scripts/resolve_core.js +86 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RuntimeStreamSocket = exports.RuntimeRouterSocket = exports.RuntimeDealerSocket = exports.RuntimeXSubSocket = exports.RuntimeSubSocket = exports.RuntimeXPubSocket = exports.RuntimePubSocket = exports.RuntimePairSocket = exports.RuntimeSubSocketOptions = exports.RuntimeStreamSocketOptions = exports.RuntimeRouterSocketOptions = exports.RuntimePubSocketOptions = exports.RuntimeDealerSocketOptions = exports.RuntimeCommonSocketOptions = void 0;
5
+ var socket_options_1 = require("./socket_options");
6
+ Object.defineProperty(exports, "RuntimeCommonSocketOptions", { enumerable: true, get: function () { return socket_options_1.CommonSocketOptions; } });
7
+ Object.defineProperty(exports, "RuntimeDealerSocketOptions", { enumerable: true, get: function () { return socket_options_1.DealerSocketOptions; } });
8
+ Object.defineProperty(exports, "RuntimePubSocketOptions", { enumerable: true, get: function () { return socket_options_1.PubSocketOptions; } });
9
+ Object.defineProperty(exports, "RuntimeRouterSocketOptions", { enumerable: true, get: function () { return socket_options_1.RouterSocketOptions; } });
10
+ Object.defineProperty(exports, "RuntimeStreamSocketOptions", { enumerable: true, get: function () { return socket_options_1.StreamSocketOptions; } });
11
+ Object.defineProperty(exports, "RuntimeSubSocketOptions", { enumerable: true, get: function () { return socket_options_1.SubSocketOptions; } });
12
+ var pair_socket_1 = require("./pair_socket");
13
+ Object.defineProperty(exports, "RuntimePairSocket", { enumerable: true, get: function () { return pair_socket_1.PairSocket; } });
14
+ var pub_socket_1 = require("./pub_socket");
15
+ Object.defineProperty(exports, "RuntimePubSocket", { enumerable: true, get: function () { return pub_socket_1.PubSocket; } });
16
+ var xpub_socket_1 = require("./xpub_socket");
17
+ Object.defineProperty(exports, "RuntimeXPubSocket", { enumerable: true, get: function () { return xpub_socket_1.XPubSocket; } });
18
+ var sub_socket_1 = require("./sub_socket");
19
+ Object.defineProperty(exports, "RuntimeSubSocket", { enumerable: true, get: function () { return sub_socket_1.SubSocket; } });
20
+ var xsub_socket_1 = require("./xsub_socket");
21
+ Object.defineProperty(exports, "RuntimeXSubSocket", { enumerable: true, get: function () { return xsub_socket_1.XSubSocket; } });
22
+ var dealer_socket_1 = require("./dealer_socket");
23
+ Object.defineProperty(exports, "RuntimeDealerSocket", { enumerable: true, get: function () { return dealer_socket_1.DealerSocket; } });
24
+ var router_socket_1 = require("./router_socket");
25
+ Object.defineProperty(exports, "RuntimeRouterSocket", { enumerable: true, get: function () { return router_socket_1.RouterSocket; } });
26
+ var stream_socket_1 = require("./stream_socket");
27
+ Object.defineProperty(exports, "RuntimeStreamSocket", { enumerable: true, get: function () { return stream_socket_1.StreamSocket; } });
@@ -0,0 +1,7 @@
1
+ import { CommonSocketOptions } from './socket_options';
2
+ import { SendSocket } from './socket_operations';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ export declare class PairSocket extends SendSocket {
5
+ readonly options: CommonSocketOptions;
6
+ constructor(ctx: Context);
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PairSocket = void 0;
5
+ const socket_options_1 = require("./socket_options");
6
+ const socket_operations_1 = require("./socket_operations");
7
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
8
+ class PairSocket extends socket_operations_1.SendSocket {
9
+ options;
10
+ constructor(ctx) { super(ctx, socket_constants_1.SocketType.PAIR); this.options = socket_options_1.CommonSocketOptions.create(this); }
11
+ }
12
+ exports.PairSocket = PairSocket;
@@ -0,0 +1,7 @@
1
+ import { PubSocketOptions } from './socket_options';
2
+ import { PublisherSocket } from './socket_operations';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ export declare class PubSocket extends PublisherSocket {
5
+ readonly options: PubSocketOptions;
6
+ constructor(ctx: Context);
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PubSocket = void 0;
5
+ const socket_options_1 = require("./socket_options");
6
+ const socket_operations_1 = require("./socket_operations");
7
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
8
+ class PubSocket extends socket_operations_1.PublisherSocket {
9
+ options;
10
+ constructor(ctx) { super(ctx, socket_constants_1.SocketType.PUB); this.options = socket_options_1.PubSocketOptions.create(this); }
11
+ }
12
+ exports.PubSocket = PubSocket;
@@ -0,0 +1,19 @@
1
+ import { ReplyToken, RoutingId, type MessageLike } from '../../contracts';
2
+ import type { ReplyOperation, RequestOperation, SendOperation } from '../../contracts/messaging';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ import { RoutedMessageSocket } from './socket_operations';
5
+ import { RouterSocketOptions } from './socket_options';
6
+ export declare class RouterSocket extends RoutedMessageSocket {
7
+ readonly options: RouterSocketOptions;
8
+ constructor(ctx: Context);
9
+ setRoutingId(routingId: RoutingId): void;
10
+ getRoutingId(): RoutingId;
11
+ send(peerRid: RoutingId): SendOperation;
12
+ request(peerRid: RoutingId): RequestOperation;
13
+ reply(peerRid: RoutingId, token: ReplyToken): ReplyOperation;
14
+ protected replyToRoutedMessage(sourceRid: RoutingId, token: ReplyToken, parts: readonly MessageLike[]): void;
15
+ protected sendReceivedManaged(routingId: Buffer, parts: readonly import('../../contracts').Message[]): Promise<void>;
16
+ private replyDirect;
17
+ private validateReplyToken;
18
+ private resolveRequestTimeout;
19
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RouterSocket = void 0;
5
+ const contracts_1 = require("../../contracts");
6
+ const received_1 = require("../../contracts/messaging/received");
7
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
8
+ const message_conversion_1 = require("../buffers/message_conversion");
9
+ const routing_id_1 = require("../core/routing_id");
10
+ const native_errors_1 = require("../errors/native_errors");
11
+ const native_handle_1 = require("../handles/native_handle");
12
+ const completion_owner_1 = require("../messaging/completion_owner");
13
+ const native_1 = require("../native/native");
14
+ const socket_operations_1 = require("./socket_operations");
15
+ const socket_options_1 = require("./socket_options");
16
+ const native = (0, native_1.requireNative)();
17
+ class RouterSocket extends socket_operations_1.RoutedMessageSocket {
18
+ options;
19
+ constructor(ctx) {
20
+ super(ctx, socket_constants_1.SocketType.ROUTER);
21
+ this.options = socket_options_1.RouterSocketOptions.create(this);
22
+ }
23
+ setRoutingId(routingId) {
24
+ const normalized = (0, routing_id_1.normalizeRoutingId)(routingId);
25
+ (0, native_errors_1.configCall)('routing id set failed', () => native.handleSetRoutingId((0, native_handle_1.getNativeHandle)(this), normalized));
26
+ }
27
+ getRoutingId() {
28
+ return contracts_1.RoutingId.from((0, native_errors_1.configCall)('routing id get failed', () => native.handleGetRoutingId((0, native_handle_1.getNativeHandle)(this))));
29
+ }
30
+ send(peerRid) {
31
+ const target = Buffer.from((0, routing_id_1.normalizeRoutingId)(peerRid, 'peerRid'));
32
+ return new socket_operations_1.RuntimeSendOperation((parts) => (0, completion_owner_1.completionOwnerOf)(this).submitSend(parts, target), (parts) => (0, completion_owner_1.completionOwnerOf)(this).sendSync(parts, target));
33
+ }
34
+ request(peerRid) {
35
+ const target = Buffer.from((0, routing_id_1.normalizeRoutingId)(peerRid, 'peerRid'));
36
+ return new socket_operations_1.RuntimeRequestOperation((parts, timeoutMs) => (0, completion_owner_1.completionOwnerOf)(this).submitRequest(parts, target, this.resolveRequestTimeout(timeoutMs)), (parts, timeoutMs) => (0, completion_owner_1.completionOwnerOf)(this).requestSync(parts, target, this.resolveRequestTimeout(timeoutMs)));
37
+ }
38
+ reply(peerRid, token) {
39
+ const target = Buffer.from((0, routing_id_1.normalizeRoutingId)(peerRid, 'peerRid'));
40
+ this.validateReplyToken(token);
41
+ return new socket_operations_1.RuntimeReplyOperation((parts) => this.replyDirect(target, token, parts));
42
+ }
43
+ replyToRoutedMessage(sourceRid, token, parts) {
44
+ this.replyDirect((0, routing_id_1.normalizeRoutingId)(sourceRid), token, parts);
45
+ }
46
+ sendReceivedManaged(routingId, parts) {
47
+ return (0, completion_owner_1.completionOwnerOf)(this).submitSend(parts, routingId);
48
+ }
49
+ replyDirect(sourceRid, token, payload) {
50
+ this.validateReplyToken(token);
51
+ try {
52
+ native.socketReply((0, native_handle_1.getNativeHandle)(this), sourceRid, (0, received_1.replyTokenNativeValue)(token), (0, message_conversion_1.normalizeOperationPayload)(payload));
53
+ }
54
+ catch (error) {
55
+ throw (0, native_errors_1.submitNativeError)(error, 0, 'reply failed');
56
+ }
57
+ (0, completion_owner_1.consumeSubmittedMessages)(payload);
58
+ }
59
+ validateReplyToken(token) {
60
+ if (!(token instanceof contracts_1.ReplyToken) || !(0, received_1.replyTokenOwnerMatches)(token, this.replyOwner)) {
61
+ throw new TypeError('ReplyToken belongs to a different RouterSocket');
62
+ }
63
+ }
64
+ resolveRequestTimeout(timeoutMs) {
65
+ return timeoutMs === 0
66
+ ? (this.options.requestTimeout === 0 ? 5_000 : this.options.requestTimeout)
67
+ : timeoutMs;
68
+ }
69
+ }
70
+ exports.RouterSocket = RouterSocket;
@@ -0,0 +1,21 @@
1
+ import { RuntimeContext as Context } from '../core/context';
2
+ import { NativeHandle } from '../handles/native_handle';
3
+ import { RoutingId } from '../../contracts';
4
+ import { type MonitorEventType } from '../../contracts/eventing';
5
+ import { type ReceiveFlowState } from '../../contracts/sockets/socket_constants';
6
+ import { MonitorSocket } from '../eventing/monitor_socket';
7
+ export declare class SocketBase extends NativeHandle {
8
+ constructor(ctx: Context, type: number);
9
+ bind(endpoint: string): void;
10
+ unbind(endpoint: string): void;
11
+ setTlsServer(cert: string, key: string, requireClientCert?: boolean): void;
12
+ setTlsClient(ca: string, hostname: string, trustSystem?: boolean): void;
13
+ setReceiveFlowState(state: ReceiveFlowState): void;
14
+ monitorOpen(events?: readonly MonitorEventType[], monitorHwmBytes?: bigint): MonitorSocket;
15
+ close(): void;
16
+ }
17
+ export declare class ConnectableSocket extends SocketBase {
18
+ connect(endpoint: string): void;
19
+ disconnect(endpoint: string): void;
20
+ disconnectRid(routingId: RoutingId): void;
21
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ConnectableSocket = exports.SocketBase = void 0;
5
+ const native_handle_1 = require("../handles/native_handle");
6
+ const native_1 = require("../native/native");
7
+ const native_errors_1 = require("../errors/native_errors");
8
+ const validation_1 = require("../options/validation");
9
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
10
+ const routing_id_1 = require("../core/routing_id");
11
+ const monitor_socket_1 = require("../eventing/monitor_socket");
12
+ const byte_values_1 = require("../options/byte_values");
13
+ const completion_owner_1 = require("../messaging/completion_owner");
14
+ class SocketBase extends native_handle_1.NativeHandle {
15
+ constructor(ctx, type) {
16
+ super((0, native_1.requireNative)().socketNew((0, native_handle_1.getNativeHandle)(ctx), type));
17
+ if (!this._native) {
18
+ throw (0, native_errors_1.lastError)('config', 'socket creation failed');
19
+ }
20
+ (0, completion_owner_1.installCompletionOwner)(this, this._native);
21
+ }
22
+ bind(endpoint) {
23
+ const normalizedEndpoint = (0, validation_1.validateCString)(endpoint, 'endpoint');
24
+ (0, native_errors_1.bindCall)('socket bind failed', () => {
25
+ (0, native_1.requireNative)().socketBind((0, native_handle_1.getNativeHandle)(this), normalizedEndpoint);
26
+ });
27
+ }
28
+ unbind(endpoint) {
29
+ const normalizedEndpoint = (0, validation_1.validateCString)(endpoint, 'endpoint');
30
+ (0, native_errors_1.connectCall)('socket unbind failed', () => {
31
+ (0, native_1.requireNative)().socketUnbind((0, native_handle_1.getNativeHandle)(this), normalizedEndpoint);
32
+ });
33
+ }
34
+ setTlsServer(cert, key, requireClientCert = false) {
35
+ const normalizedCert = (0, validation_1.validateCString)(cert, 'cert', Number.MAX_SAFE_INTEGER);
36
+ const normalizedKey = (0, validation_1.validateCString)(key, 'key', Number.MAX_SAFE_INTEGER);
37
+ (0, native_errors_1.configCall)('socket TLS server configuration failed', () => {
38
+ (0, native_1.requireNative)().socketSetTlsServer((0, native_handle_1.getNativeHandle)(this), normalizedCert, normalizedKey, requireClientCert ? 1 : 0);
39
+ });
40
+ }
41
+ setTlsClient(ca, hostname, trustSystem = false) {
42
+ const normalizedCa = (0, validation_1.validateCString)(ca, 'ca', Number.MAX_SAFE_INTEGER);
43
+ const normalizedHostname = (0, validation_1.validateCString)(hostname, 'hostname', Number.MAX_SAFE_INTEGER);
44
+ (0, native_errors_1.configCall)('socket TLS client configuration failed', () => {
45
+ (0, native_1.requireNative)().socketSetTlsClient((0, native_handle_1.getNativeHandle)(this), normalizedCa, normalizedHostname, trustSystem ? 1 : 0);
46
+ });
47
+ }
48
+ setReceiveFlowState(state) {
49
+ (0, native_errors_1.configCall)('socket receive-flow-state configuration failed', () => {
50
+ (0, native_1.requireNative)().socketSetReceiveFlowState((0, native_handle_1.getNativeHandle)(this), state | 0);
51
+ });
52
+ }
53
+ /** @internal */
54
+ setSockOptRaw(option, value) {
55
+ const buf = typeof value === 'number' ? Buffer.from([value & 0xff, 0, 0, 0]) : value;
56
+ (0, native_errors_1.configCall)('socket option set failed', () => {
57
+ (0, native_1.requireNative)().socketSetOpt((0, native_handle_1.getNativeHandle)(this), option | 0, buf);
58
+ });
59
+ }
60
+ /** @internal */
61
+ getSockOptRaw(option) {
62
+ return (0, native_errors_1.configCall)('socket option get failed', () => (0, native_1.requireNative)().socketGetOpt((0, native_handle_1.getNativeHandle)(this), option | 0));
63
+ }
64
+ monitorOpen(events, monitorHwmBytes = 0n) {
65
+ const mask = events === undefined
66
+ ? socket_constants_1.SOCKET_MONITOR_EVENT_ALL
67
+ : events.reduce((current, event) => current | (event | 0), 0);
68
+ const exactMonitorHwmBytes = (0, byte_values_1.validateUInt64)(monitorHwmBytes, 'monitorHwmBytes');
69
+ return new monitor_socket_1.MonitorSocket((0, native_errors_1.configCall)('monitor open failed', () => (0, native_1.requireNative)().monitorOpen((0, native_handle_1.getNativeHandle)(this), mask | 0, exactMonitorHwmBytes)));
70
+ }
71
+ close() {
72
+ if (!this._native)
73
+ return;
74
+ (0, completion_owner_1.releaseCompletionOwner)(this);
75
+ (0, native_errors_1.closeCall)('socket close failed', () => {
76
+ (0, native_1.requireNative)().socketClose(this._native);
77
+ });
78
+ this._native = null;
79
+ }
80
+ }
81
+ exports.SocketBase = SocketBase;
82
+ class ConnectableSocket extends SocketBase {
83
+ connect(endpoint) {
84
+ const normalizedEndpoint = (0, validation_1.validateCString)(endpoint, 'endpoint');
85
+ (0, native_errors_1.connectCall)('socket connect failed', () => {
86
+ (0, native_1.requireNative)().socketConnect((0, native_handle_1.getNativeHandle)(this), normalizedEndpoint);
87
+ });
88
+ }
89
+ disconnect(endpoint) {
90
+ const normalizedEndpoint = (0, validation_1.validateCString)(endpoint, 'endpoint');
91
+ (0, native_errors_1.connectCall)('socket disconnect failed', () => {
92
+ (0, native_1.requireNative)().socketDisconnect((0, native_handle_1.getNativeHandle)(this), normalizedEndpoint);
93
+ });
94
+ }
95
+ disconnectRid(routingId) {
96
+ const normalizedRoutingId = (0, routing_id_1.normalizeRoutingId)(routingId);
97
+ (0, native_errors_1.connectCall)('socket disconnect by routing id failed', () => {
98
+ (0, native_1.requireNative)().socketDisconnectRid((0, native_handle_1.getNativeHandle)(this), normalizedRoutingId);
99
+ });
100
+ }
101
+ }
102
+ exports.ConnectableSocket = ConnectableSocket;
@@ -0,0 +1,38 @@
1
+ import { Message, type MessageLike } from '../../contracts';
2
+ import type { PublishOperation as PublishOperationContract, PublishSubmitOperation, RequestOperation, RequestSubmitOperation, ReplyOperation, ReplySubmitOperation, SendOperation, SendSubmitOperation } from '../../contracts/messaging';
3
+ import { PartOperationBase, type OperationPayloadValue } from '../messaging/send_operation_base';
4
+ export type ManagedSendInvoker = (parts: OperationPayloadValue<MessageLike>) => Promise<void>;
5
+ export type SyncSendInvoker = (parts: OperationPayloadValue<MessageLike>) => void;
6
+ export type PublishInvoker = (topic: string, payload: OperationPayloadValue<MessageLike>) => void;
7
+ export type RequestInvoker = (parts: OperationPayloadValue<MessageLike>, timeoutMs: number) => Promise<Message[]>;
8
+ export type SyncRequestInvoker = (parts: OperationPayloadValue<MessageLike>, timeoutMs: number) => Message[];
9
+ export type ReplyInvoker = (parts: OperationPayloadValue<MessageLike>) => void;
10
+ /** Event-loop-driven send builder with WRITABLE-token retry. */
11
+ export declare class RuntimeSendOperation extends PartOperationBase<MessageLike, MessageLike> implements SendOperation, SendSubmitOperation {
12
+ private readonly _invoke;
13
+ private readonly _invokeSync;
14
+ constructor(_invoke: ManagedSendInvoker, _invokeSync: SyncSendInvoker);
15
+ submit(): Promise<void>;
16
+ submit_sync(): void;
17
+ }
18
+ /** Synchronous PUB/XPUB builder; Core decides drop versus NODROP error. */
19
+ export declare class PublishOperation extends PartOperationBase<MessageLike, MessageLike> implements PublishOperationContract, PublishSubmitOperation {
20
+ private readonly _invoke;
21
+ private readonly _topic;
22
+ constructor(_invoke: PublishInvoker, _topic: string);
23
+ submit(): void;
24
+ }
25
+ export declare class RuntimeRequestOperation extends PartOperationBase<MessageLike, MessageLike> implements RequestOperation, RequestSubmitOperation {
26
+ private readonly _invoke;
27
+ private readonly _invokeSync;
28
+ private _timeoutMs;
29
+ constructor(_invoke: RequestInvoker, _invokeSync: SyncRequestInvoker);
30
+ timeout(timeoutMs: number): this;
31
+ submit(): Promise<Message[]>;
32
+ submit_sync(): Message[];
33
+ }
34
+ export declare class RuntimeReplyOperation extends PartOperationBase<MessageLike, MessageLike> implements ReplyOperation, ReplySubmitOperation {
35
+ private readonly _invoke;
36
+ constructor(_invoke: ReplyInvoker);
37
+ submit(): void;
38
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RuntimeReplyOperation = exports.RuntimeRequestOperation = exports.PublishOperation = exports.RuntimeSendOperation = void 0;
5
+ const contracts_1 = require("../../contracts");
6
+ const message_1 = require("../../contracts/messaging/message");
7
+ const send_operation_base_1 = require("../messaging/send_operation_base");
8
+ function consumeSubmittedMessages(payload) {
9
+ if (payload instanceof contracts_1.Message) {
10
+ (0, message_1.consumeSubmittedMessage)(payload);
11
+ return;
12
+ }
13
+ if (Array.isArray(payload)) {
14
+ for (const part of payload) {
15
+ if (part instanceof contracts_1.Message)
16
+ (0, message_1.consumeSubmittedMessage)(part);
17
+ }
18
+ }
19
+ }
20
+ /** Event-loop-driven send builder with WRITABLE-token retry. */
21
+ class RuntimeSendOperation extends send_operation_base_1.PartOperationBase {
22
+ _invoke;
23
+ _invokeSync;
24
+ constructor(_invoke, _invokeSync) {
25
+ super();
26
+ this._invoke = _invoke;
27
+ this._invokeSync = _invokeSync;
28
+ }
29
+ submit() { return this._invoke(this.consumePayload()); }
30
+ submit_sync() {
31
+ const payload = this.consumePayload();
32
+ this._invokeSync(payload);
33
+ consumeSubmittedMessages(payload);
34
+ }
35
+ }
36
+ exports.RuntimeSendOperation = RuntimeSendOperation;
37
+ /** Synchronous PUB/XPUB builder; Core decides drop versus NODROP error. */
38
+ class PublishOperation extends send_operation_base_1.PartOperationBase {
39
+ _invoke;
40
+ _topic;
41
+ constructor(_invoke, _topic) {
42
+ super();
43
+ this._invoke = _invoke;
44
+ this._topic = _topic;
45
+ }
46
+ submit() {
47
+ const payload = this.consumePayload();
48
+ this._invoke(this._topic, payload);
49
+ consumeSubmittedMessages(payload);
50
+ }
51
+ }
52
+ exports.PublishOperation = PublishOperation;
53
+ class RuntimeRequestOperation extends send_operation_base_1.PartOperationBase {
54
+ _invoke;
55
+ _invokeSync;
56
+ _timeoutMs = 0;
57
+ constructor(_invoke, _invokeSync) {
58
+ super();
59
+ this._invoke = _invoke;
60
+ this._invokeSync = _invokeSync;
61
+ }
62
+ timeout(timeoutMs) {
63
+ this.ensureOpen();
64
+ if (!Number.isInteger(timeoutMs)) {
65
+ throw new TypeError('timeoutMs must be an integer');
66
+ }
67
+ if (timeoutMs < 0 || timeoutMs > 0x7fffffff) {
68
+ throw new RangeError('timeoutMs must be in the range 0..2147483647');
69
+ }
70
+ this._timeoutMs = timeoutMs;
71
+ return this;
72
+ }
73
+ submit() {
74
+ return this._invoke(this.consumePayload(), this._timeoutMs);
75
+ }
76
+ submit_sync() {
77
+ return this._invokeSync(this.consumePayload(), this._timeoutMs);
78
+ }
79
+ }
80
+ exports.RuntimeRequestOperation = RuntimeRequestOperation;
81
+ class RuntimeReplyOperation extends send_operation_base_1.PartOperationBase {
82
+ _invoke;
83
+ constructor(_invoke) {
84
+ super();
85
+ this._invoke = _invoke;
86
+ }
87
+ submit() {
88
+ const payload = this.consumePayload();
89
+ this._invoke(payload);
90
+ consumeSubmittedMessages(payload);
91
+ }
92
+ }
93
+ exports.RuntimeReplyOperation = RuntimeReplyOperation;
@@ -0,0 +1,40 @@
1
+ import { ConnectableSocket } from './socket_base';
2
+ import { Message, Received, RoutingId, TopicMessage, type MessageLike } from '../../contracts';
3
+ import { RecvFlags } from '../../contracts/sockets/socket_constants';
4
+ import type { SubscriptionEntry, SendOperation, PublishOperation as PublishOperationContract } from '../../contracts/messaging';
5
+ export { PublishOperation, RuntimeReplyOperation, RuntimeRequestOperation, RuntimeSendOperation, } from './socket_operation_builders';
6
+ export declare class ReceiveSocket extends ConnectableSocket {
7
+ /**
8
+ * Receives into caller-provided storage. Pass a long-lived {@link Received}
9
+ * and the binding refills its internal state in place each successful call.
10
+ * Returns true on success and false when DontWait finds no data.
11
+ */
12
+ recv(result: Received, flags?: RecvFlags): boolean;
13
+ }
14
+ export declare class SendSocket extends ReceiveSocket {
15
+ send(): SendOperation;
16
+ }
17
+ export declare class PublisherSocket extends ConnectableSocket {
18
+ private lastPublishTopic;
19
+ private lastValidatedPublishTopic;
20
+ private readonly publishInvoker;
21
+ constructor(ctx: import('../core/context').RuntimeContext, type: number);
22
+ publish(topic: string): PublishOperationContract;
23
+ }
24
+ export declare class SubscriberSocket extends ConnectableSocket {
25
+ setSubscription(topicOrPattern: string): void;
26
+ unsetSubscription(topicOrPattern: string): void;
27
+ subscriptionAt(index: number): SubscriptionEntry | null;
28
+ subscribe(result: TopicMessage, flags?: RecvFlags): boolean;
29
+ }
30
+ export declare class RoutedMessageSocket extends ConnectableSocket {
31
+ protected readonly replyOwner: {};
32
+ private readonly receivedOperations;
33
+ protected sendDirect(routingId: RoutingId, payload: MessageLike | readonly MessageLike[]): void;
34
+ protected replyToRoutedMessage(_sourceRid: RoutingId, _replyToken: import('../../contracts').ReplyToken, _parts: readonly Message[]): void;
35
+ protected sendReceivedManaged(_routingId: Buffer, _parts: readonly Message[]): Promise<void>;
36
+ /**
37
+ * Receives into caller-provided storage. See {@link MessageSocket.recv}.
38
+ */
39
+ recv(result: Received, flags?: RecvFlags): boolean;
40
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RoutedMessageSocket = exports.SubscriberSocket = exports.PublisherSocket = exports.SendSocket = exports.ReceiveSocket = exports.RuntimeSendOperation = exports.RuntimeRequestOperation = exports.RuntimeReplyOperation = exports.PublishOperation = void 0;
5
+ const native_1 = require("../native/native");
6
+ const native_handle_1 = require("../handles/native_handle");
7
+ const native_errors_1 = require("../errors/native_errors");
8
+ const message_materializer_1 = require("../messaging/message_materializer");
9
+ const message_conversion_1 = require("../buffers/message_conversion");
10
+ const routing_id_1 = require("../core/routing_id");
11
+ const socket_base_1 = require("./socket_base");
12
+ const contracts_1 = require("../../contracts");
13
+ const validation_1 = require("../options/validation");
14
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
15
+ const errors_1 = require("../../contracts/errors/errors");
16
+ const socket_operation_builders_1 = require("./socket_operation_builders");
17
+ const completion_owner_1 = require("../messaging/completion_owner");
18
+ var socket_operation_builders_2 = require("./socket_operation_builders");
19
+ Object.defineProperty(exports, "PublishOperation", { enumerable: true, get: function () { return socket_operation_builders_2.PublishOperation; } });
20
+ Object.defineProperty(exports, "RuntimeReplyOperation", { enumerable: true, get: function () { return socket_operation_builders_2.RuntimeReplyOperation; } });
21
+ Object.defineProperty(exports, "RuntimeRequestOperation", { enumerable: true, get: function () { return socket_operation_builders_2.RuntimeRequestOperation; } });
22
+ Object.defineProperty(exports, "RuntimeSendOperation", { enumerable: true, get: function () { return socket_operation_builders_2.RuntimeSendOperation; } });
23
+ const socket_submit_errors_1 = require("./socket_submit_errors");
24
+ const native = (0, native_1.requireNative)();
25
+ class ReceiveSocket extends socket_base_1.ConnectableSocket {
26
+ /**
27
+ * Receives into caller-provided storage. Pass a long-lived {@link Received}
28
+ * and the binding refills its internal state in place each successful call.
29
+ * Returns true on success and false when DontWait finds no data.
30
+ */
31
+ recv(result, flags = socket_constants_1.RecvFlags.None) {
32
+ let raw;
33
+ try {
34
+ raw = ((flags | 0) & (socket_constants_1.RecvFlags.DontWait | 0))
35
+ ? native.socketRecvMessageNoWait((0, native_handle_1.getNativeHandle)(this))
36
+ : native.socketRecvMessage((0, native_handle_1.getNativeHandle)(this), flags | 0);
37
+ }
38
+ catch (error) {
39
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'recv failed');
40
+ }
41
+ if (raw == null)
42
+ return false;
43
+ (0, message_materializer_1.materializeReceivedInto)(result, raw);
44
+ return true;
45
+ }
46
+ }
47
+ exports.ReceiveSocket = ReceiveSocket;
48
+ class SendSocket extends ReceiveSocket {
49
+ send() {
50
+ return new socket_operation_builders_1.RuntimeSendOperation((payload) => (0, completion_owner_1.completionOwnerOf)(this).submitSend(payload, null), (payload) => (0, completion_owner_1.completionOwnerOf)(this).sendSync(payload, null));
51
+ }
52
+ }
53
+ exports.SendSocket = SendSocket;
54
+ class PublisherSocket extends socket_base_1.ConnectableSocket {
55
+ lastPublishTopic;
56
+ lastValidatedPublishTopic;
57
+ publishInvoker = (topic, payload) => this.publishDirect(topic, payload);
58
+ constructor(ctx, type) {
59
+ super(ctx, type);
60
+ }
61
+ publish(topic) {
62
+ const normalizedTopic = topic === this.lastPublishTopic
63
+ ? this.lastValidatedPublishTopic
64
+ : (0, validation_1.validateCString)(topic, 'topic', Number.MAX_SAFE_INTEGER);
65
+ this.lastPublishTopic = topic;
66
+ this.lastValidatedPublishTopic = normalizedTopic;
67
+ return new socket_operation_builders_1.PublishOperation(this.publishInvoker, normalizedTopic);
68
+ }
69
+ /** @internal */
70
+ publishDirect(topic, payload, flags = socket_constants_1.SendFlags.None) {
71
+ const normalized = (0, message_conversion_1.normalizeOperationPayload)(payload);
72
+ if ((flags | 0) & (socket_constants_1.SendFlags.DontWait | 0)) {
73
+ let result;
74
+ try {
75
+ result = native.socketTryPublish((0, native_handle_1.getNativeHandle)(this), topic, normalized);
76
+ }
77
+ catch (error) {
78
+ throw (0, native_errors_1.submitNativeError)(error, flags, 'publish failed');
79
+ }
80
+ if (result === errors_1.SubmitResult.Ok)
81
+ return true;
82
+ if (result === errors_1.SubmitResult.Backpressured)
83
+ return false;
84
+ throw (0, socket_submit_errors_1.submitErrorFromResult)(result, 'publish failed');
85
+ }
86
+ try {
87
+ native.socketPublish((0, native_handle_1.getNativeHandle)(this), topic, normalized, flags | 0);
88
+ return true;
89
+ }
90
+ catch (error) {
91
+ return (0, native_errors_1.submitOrBackpressure)(error, flags, 'publish failed');
92
+ }
93
+ }
94
+ }
95
+ exports.PublisherSocket = PublisherSocket;
96
+ class SubscriberSocket extends socket_base_1.ConnectableSocket {
97
+ setSubscription(topicOrPattern) {
98
+ const topic = (0, validation_1.validateCString)(topicOrPattern, 'topicOrPattern', Number.MAX_SAFE_INTEGER);
99
+ (0, native_errors_1.configCall)('subscription set failed', () => {
100
+ native.socketSetSubscription((0, native_handle_1.getNativeHandle)(this), topic);
101
+ });
102
+ }
103
+ unsetSubscription(topicOrPattern) {
104
+ const topic = (0, validation_1.validateCString)(topicOrPattern, 'topicOrPattern', Number.MAX_SAFE_INTEGER);
105
+ (0, native_errors_1.configCall)('subscription unset failed', () => {
106
+ native.socketUnsetSubscription((0, native_handle_1.getNativeHandle)(this), topic);
107
+ });
108
+ }
109
+ subscriptionAt(index) {
110
+ return (0, native_errors_1.configCall)('subscription lookup failed', () => native.subscriptionAt((0, native_handle_1.getNativeHandle)(this), index >>> 0));
111
+ }
112
+ subscribe(resultOrFlags = socket_constants_1.RecvFlags.None, maybeFlags = socket_constants_1.RecvFlags.None) {
113
+ const hasResult = resultOrFlags instanceof contracts_1.TopicMessage;
114
+ const flags = hasResult ? maybeFlags : resultOrFlags;
115
+ let raw;
116
+ try {
117
+ raw = ((flags | 0) & (socket_constants_1.RecvFlags.DontWait | 0))
118
+ ? native.socketTrySubscribeMessage((0, native_handle_1.getNativeHandle)(this))
119
+ : native.socketSubscribeMessage((0, native_handle_1.getNativeHandle)(this), flags | 0);
120
+ }
121
+ catch (error) {
122
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'subscribe failed');
123
+ }
124
+ if (!raw) {
125
+ return hasResult ? false : null;
126
+ }
127
+ if (hasResult) {
128
+ (0, message_materializer_1.adoptTopicMessage)(resultOrFlags, raw);
129
+ return true;
130
+ }
131
+ return (0, message_materializer_1.materializeTopicMessage)(raw);
132
+ }
133
+ }
134
+ exports.SubscriberSocket = SubscriberSocket;
135
+ class RoutedMessageSocket extends socket_base_1.ConnectableSocket {
136
+ replyOwner = {};
137
+ receivedOperations = {
138
+ replyOwner: this.replyOwner,
139
+ send: (routingId, parts) => (0, completion_owner_1.completionOwnerOf)(this).sendSync(parts, routingId),
140
+ sendManaged: (routingId, parts) => this.sendReceivedManaged(routingId, parts),
141
+ reply: (routingId, token, parts) => this.replyToRoutedMessage((0, routing_id_1.routingIdFromOwnedBuffer)(routingId), token, parts),
142
+ };
143
+ sendDirect(routingId, payload) {
144
+ const normalizedRoutingId = (0, routing_id_1.normalizeRoutingId)(routingId);
145
+ (0, completion_owner_1.completionOwnerOf)(this).sendSync(payload, normalizedRoutingId);
146
+ }
147
+ replyToRoutedMessage(_sourceRid, _replyToken, _parts) {
148
+ throw (0, socket_submit_errors_1.submitErrorFromResult)(errors_1.SubmitResult.InvalidState, 'request reply is only supported by RouterSocket');
149
+ }
150
+ sendReceivedManaged(_routingId, _parts) {
151
+ return Promise.reject((0, socket_submit_errors_1.submitErrorFromResult)(errors_1.SubmitResult.InvalidState, 'managed received send is not supported by this socket'));
152
+ }
153
+ /**
154
+ * Receives into caller-provided storage. See {@link MessageSocket.recv}.
155
+ */
156
+ recv(result, flags = socket_constants_1.RecvFlags.None) {
157
+ // HOT PATH: terminal readers repeatedly materialize data(), whereas
158
+ // relays consume the movable native frame. Use the previous refill to
159
+ // select the next internal storage mode without changing the public API.
160
+ const preferManagedSinglePart = (0, message_materializer_1.routedReceivedPrefersManagedBuffer)(result);
161
+ const routingIdStorage = (0, message_materializer_1.routedReceivedRoutingBytes)(result);
162
+ let raw;
163
+ try {
164
+ raw = ((flags | 0) & (socket_constants_1.RecvFlags.DontWait | 0))
165
+ ? native.routerRecvMessageNoWait((0, native_handle_1.getNativeHandle)(this), preferManagedSinglePart, routingIdStorage)
166
+ : native.routerRecvMessage((0, native_handle_1.getNativeHandle)(this), flags | 0, preferManagedSinglePart, routingIdStorage);
167
+ }
168
+ catch (error) {
169
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'recv failed');
170
+ }
171
+ if (raw == null)
172
+ return false;
173
+ (0, message_materializer_1.materializeRoutedReceivedInto)(result, raw, this.receivedOperations);
174
+ return true;
175
+ }
176
+ }
177
+ exports.RoutedMessageSocket = RoutedMessageSocket;