@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,104 @@
1
+ import { Message, RoutingId, type MessageLike } from '../../contracts';
2
+ import { type PollEventFlagValue, type RidDuplicatePolicy as RidDuplicatePolicyValue, type StreamRecvMode as StreamRecvModeValue } from '../../contracts/sockets/socket_constants';
3
+ export declare function int32Buffer(value: number, name: string): Buffer;
4
+ export declare function int64Buffer(value: bigint, name: string): Buffer;
5
+ export declare function boolBuffer(value: boolean): Buffer;
6
+ export declare function flagsToMask(events: readonly PollEventFlagValue[]): number;
7
+ export declare function readBoolOption(buffer: Buffer, name: string): boolean;
8
+ export declare function readInt32Option(buffer: Buffer, name: string): number;
9
+ export declare function readInt64Option(buffer: Buffer, name: string): bigint;
10
+ export declare function readRoutingIdOption(buffer: Buffer): RoutingId | null;
11
+ export declare function readStringOption(buffer: Buffer): string;
12
+ export declare const OPTION_CREATE_TOKEN: unique symbol;
13
+ export declare class CommonSocketOptions {
14
+ protected readInt32(option: number, name: string): number;
15
+ protected writeInt32(option: number, value: number, name: string): void;
16
+ protected readBool(option: number, name: string): boolean;
17
+ protected writeBool(option: number, value: boolean): void;
18
+ get linger(): number;
19
+ set linger(value: number);
20
+ get sendHwm(): bigint;
21
+ set sendHwm(value: bigint);
22
+ get recvHwm(): bigint;
23
+ set recvHwm(value: bigint);
24
+ get sendTimeout(): number;
25
+ set sendTimeout(value: number);
26
+ get recvTimeout(): number;
27
+ set recvTimeout(value: number);
28
+ get immediate(): boolean;
29
+ set immediate(value: boolean);
30
+ get ridDuplicatePolicy(): RidDuplicatePolicyValue;
31
+ set ridDuplicatePolicy(value: RidDuplicatePolicyValue);
32
+ get connectTimeout(): number;
33
+ set connectTimeout(value: number);
34
+ get ipv6(): boolean;
35
+ set ipv6(value: boolean);
36
+ get tcpNoDelay(): boolean;
37
+ set tcpNoDelay(value: boolean);
38
+ get tcpKeepalive(): number;
39
+ set tcpKeepalive(value: number);
40
+ get maxMsgSize(): bigint;
41
+ set maxMsgSize(value: bigint);
42
+ get lastEndpoint(): string;
43
+ get backlog(): number;
44
+ set backlog(value: number);
45
+ get reconnectInterval(): number;
46
+ set reconnectInterval(value: number);
47
+ get reconnectIntervalMax(): number;
48
+ set reconnectIntervalMax(value: number);
49
+ get submitRetryMode(): number;
50
+ set submitRetryMode(value: number);
51
+ get submitRetryTimeout(): number;
52
+ set submitRetryTimeout(value: number);
53
+ get submitRetryAttempts(): number;
54
+ set submitRetryAttempts(value: number);
55
+ }
56
+ export declare class DealerSocketOptions extends CommonSocketOptions {
57
+ get probe(): boolean;
58
+ set probe(value: boolean);
59
+ get requestTimeout(): number;
60
+ set requestTimeout(value: number);
61
+ get peerWeight(): number;
62
+ set peerWeight(value: number);
63
+ }
64
+ export declare class RouterSocketOptions extends CommonSocketOptions {
65
+ get mandatory(): boolean;
66
+ set mandatory(value: boolean);
67
+ get handover(): boolean;
68
+ set handover(value: boolean);
69
+ get probe(): boolean;
70
+ set probe(value: boolean);
71
+ get connectRoutingId(): RoutingId | null;
72
+ setConnectRoutingId(routingId: RoutingId): void;
73
+ get requestTimeout(): number;
74
+ set requestTimeout(value: number);
75
+ get peerWeight(): number;
76
+ set peerWeight(value: number);
77
+ }
78
+ export declare class StreamSocketOptions extends CommonSocketOptions {
79
+ get notify(): boolean;
80
+ set notify(value: boolean);
81
+ get recvMode(): StreamRecvModeValue;
82
+ set recvMode(value: StreamRecvModeValue);
83
+ }
84
+ export declare class PubSocketOptions extends CommonSocketOptions {
85
+ private _welcomeMessage;
86
+ get verbose(): boolean;
87
+ set verbose(value: boolean);
88
+ get verboser(): boolean;
89
+ set verboser(value: boolean);
90
+ get noDrop(): boolean;
91
+ set noDrop(value: boolean);
92
+ get manual(): boolean;
93
+ set manual(value: boolean);
94
+ get manualLastValue(): boolean;
95
+ set manualLastValue(value: boolean);
96
+ get topicsCount(): number;
97
+ welcomeMessage(): Message;
98
+ setWelcomeMessage(message: MessageLike): void;
99
+ approveSubscribe(routingId: RoutingId): void;
100
+ rejectSubscribe(routingId: RoutingId): void;
101
+ }
102
+ export declare class SubSocketOptions extends CommonSocketOptions {
103
+ get topicsCount(): number;
104
+ }
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SubSocketOptions = exports.PubSocketOptions = exports.StreamSocketOptions = exports.RouterSocketOptions = exports.DealerSocketOptions = exports.CommonSocketOptions = exports.OPTION_CREATE_TOKEN = void 0;
5
+ exports.int32Buffer = int32Buffer;
6
+ exports.int64Buffer = int64Buffer;
7
+ exports.boolBuffer = boolBuffer;
8
+ exports.flagsToMask = flagsToMask;
9
+ exports.readBoolOption = readBoolOption;
10
+ exports.readInt32Option = readInt32Option;
11
+ exports.readInt64Option = readInt64Option;
12
+ exports.readRoutingIdOption = readRoutingIdOption;
13
+ exports.readStringOption = readStringOption;
14
+ const contracts_1 = require("../../contracts");
15
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
16
+ const message_conversion_1 = require("../buffers/message_conversion");
17
+ const routing_id_1 = require("../core/routing_id");
18
+ const option_mapping_1 = require("../options/option_mapping");
19
+ const byte_values_1 = require("../options/byte_values");
20
+ function int32Buffer(value, name) {
21
+ if (!Number.isInteger(value))
22
+ throw new TypeError(`${name} must be an integer`);
23
+ if (value < -2147483648 || value > 2147483647) {
24
+ throw new RangeError(`${name} must fit in int32`);
25
+ }
26
+ const buf = Buffer.allocUnsafe(4);
27
+ buf.writeInt32LE(value, 0);
28
+ return buf;
29
+ }
30
+ function int64Buffer(value, name) {
31
+ if (typeof value !== 'bigint') {
32
+ throw new TypeError(`${name} must be a bigint`);
33
+ }
34
+ const normalized = value;
35
+ const min = -(1n << 63n);
36
+ const max = (1n << 63n) - 1n;
37
+ if (normalized < min || normalized > max) {
38
+ throw new RangeError(`${name} must fit in int64`);
39
+ }
40
+ const buf = Buffer.allocUnsafe(8);
41
+ buf.writeBigInt64LE(normalized, 0);
42
+ return buf;
43
+ }
44
+ function boolBuffer(value) {
45
+ const buf = Buffer.allocUnsafe(4);
46
+ buf.writeUInt32LE(value ? 1 : 0, 0);
47
+ return buf;
48
+ }
49
+ function flagsToMask(events) {
50
+ if (!Array.isArray(events)) {
51
+ throw new TypeError('events must be an array');
52
+ }
53
+ return events.reduce((mask, event) => mask | (event | 0), 0);
54
+ }
55
+ function readBoolOption(buffer, name) {
56
+ if (buffer.length < 4)
57
+ throw new Error(`${name} option returned an invalid payload`);
58
+ return buffer.readUInt32LE(0) !== 0;
59
+ }
60
+ function readInt32Option(buffer, name) {
61
+ if (buffer.length < 4)
62
+ throw new Error(`${name} option returned an invalid payload`);
63
+ return buffer.readInt32LE(0);
64
+ }
65
+ function readInt64Option(buffer, name) {
66
+ if (buffer.length < 8)
67
+ throw new Error(`${name} option returned an invalid payload`);
68
+ return buffer.readBigInt64LE(0);
69
+ }
70
+ function readRoutingIdOption(buffer) {
71
+ return buffer.length === 0 ? null : contracts_1.RoutingId.from(buffer);
72
+ }
73
+ function readStringOption(buffer) {
74
+ const nul = buffer.indexOf(0);
75
+ return buffer.subarray(0, nul >= 0 ? nul : buffer.length).toString();
76
+ }
77
+ exports.OPTION_CREATE_TOKEN = Symbol('OptionFacade.create');
78
+ class CommonSocketOptions {
79
+ /** @internal */
80
+ _socket;
81
+ /** @internal */
82
+ constructor(token, socket) {
83
+ if (token !== exports.OPTION_CREATE_TOKEN) {
84
+ throw new TypeError('socket options are created by sockets');
85
+ }
86
+ this._socket = socket;
87
+ }
88
+ /** @internal */
89
+ static create(socket) {
90
+ return new CommonSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
91
+ }
92
+ readInt32(option, name) {
93
+ return readInt32Option(this._socket.getSockOptRaw(option), name);
94
+ }
95
+ writeInt32(option, value, name) {
96
+ this._socket.setSockOptRaw(option, int32Buffer(value, name));
97
+ }
98
+ readBool(option, name) {
99
+ return readBoolOption(this._socket.getSockOptRaw(option), name);
100
+ }
101
+ writeBool(option, value) {
102
+ this._socket.setSockOptRaw(option, boolBuffer(value));
103
+ }
104
+ get linger() { return this.readInt32(option_mapping_1.SocketOption.LINGER, 'linger'); }
105
+ set linger(value) { this.writeInt32(option_mapping_1.SocketOption.LINGER, value, 'linger'); }
106
+ get sendHwm() { return (0, byte_values_1.readUInt64Option)(this._socket.getSockOptRaw(option_mapping_1.SocketOption.SNDHWM), 'sendHwm'); }
107
+ set sendHwm(value) { this._socket.setSockOptRaw(option_mapping_1.SocketOption.SNDHWM, (0, byte_values_1.uint64Buffer)(value, 'sendHwm')); }
108
+ get recvHwm() { return (0, byte_values_1.readUInt64Option)(this._socket.getSockOptRaw(option_mapping_1.SocketOption.RCVHWM), 'recvHwm'); }
109
+ set recvHwm(value) { this._socket.setSockOptRaw(option_mapping_1.SocketOption.RCVHWM, (0, byte_values_1.uint64Buffer)(value, 'recvHwm')); }
110
+ get sendTimeout() { return this.readInt32(option_mapping_1.SocketOption.SNDTIMEO, 'sendTimeout'); }
111
+ set sendTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.SNDTIMEO, value, 'sendTimeout'); }
112
+ get recvTimeout() { return this.readInt32(option_mapping_1.SocketOption.RCVTIMEO, 'recvTimeout'); }
113
+ set recvTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.RCVTIMEO, value, 'recvTimeout'); }
114
+ get immediate() { return this.readBool(option_mapping_1.SocketOption.IMMEDIATE, 'immediate'); }
115
+ set immediate(value) { this.writeBool(option_mapping_1.SocketOption.IMMEDIATE, value); }
116
+ get ridDuplicatePolicy() { return this.readInt32(option_mapping_1.SocketOption.RID_DUPLICATE_POLICY, 'ridDuplicatePolicy'); }
117
+ set ridDuplicatePolicy(value) { this.writeInt32(option_mapping_1.SocketOption.RID_DUPLICATE_POLICY, value, 'ridDuplicatePolicy'); }
118
+ get connectTimeout() { return this.readInt32(option_mapping_1.SocketOption.CONNECT_TIMEOUT, 'connectTimeout'); }
119
+ set connectTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.CONNECT_TIMEOUT, value, 'connectTimeout'); }
120
+ get ipv6() { return this.readBool(option_mapping_1.SocketOption.IPV6, 'ipv6'); }
121
+ set ipv6(value) { this.writeBool(option_mapping_1.SocketOption.IPV6, value); }
122
+ get tcpNoDelay() { return this.readBool(option_mapping_1.SocketOption.TCP_NODELAY, 'tcpNoDelay'); }
123
+ set tcpNoDelay(value) { this.writeBool(option_mapping_1.SocketOption.TCP_NODELAY, value); }
124
+ get tcpKeepalive() { return this.readInt32(option_mapping_1.SocketOption.TCP_KEEPALIVE, 'tcpKeepalive'); }
125
+ set tcpKeepalive(value) { this.writeInt32(option_mapping_1.SocketOption.TCP_KEEPALIVE, value, 'tcpKeepalive'); }
126
+ get maxMsgSize() { return readInt64Option(this._socket.getSockOptRaw(option_mapping_1.SocketOption.MAXMSGSIZE), 'maxMsgSize'); }
127
+ set maxMsgSize(value) { this._socket.setSockOptRaw(option_mapping_1.SocketOption.MAXMSGSIZE, int64Buffer(value, 'maxMsgSize')); }
128
+ get lastEndpoint() { return readStringOption(this._socket.getSockOptRaw(option_mapping_1.SocketOption.LAST_ENDPOINT)); }
129
+ get backlog() { return this.readInt32(option_mapping_1.SocketOption.BACKLOG, 'backlog'); }
130
+ set backlog(value) { this.writeInt32(option_mapping_1.SocketOption.BACKLOG, value, 'backlog'); }
131
+ get reconnectInterval() { return this.readInt32(option_mapping_1.SocketOption.RECONNECT_IVL, 'reconnectInterval'); }
132
+ set reconnectInterval(value) { this.writeInt32(option_mapping_1.SocketOption.RECONNECT_IVL, value, 'reconnectInterval'); }
133
+ get reconnectIntervalMax() { return this.readInt32(option_mapping_1.SocketOption.RECONNECT_IVL_MAX, 'reconnectIntervalMax'); }
134
+ set reconnectIntervalMax(value) { this.writeInt32(option_mapping_1.SocketOption.RECONNECT_IVL_MAX, value, 'reconnectIntervalMax'); }
135
+ get submitRetryMode() { return this.readInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_MODE, 'submitRetryMode'); }
136
+ set submitRetryMode(value) { this.writeInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_MODE, value, 'submitRetryMode'); }
137
+ get submitRetryTimeout() { return this.readInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_TIMEOUT, 'submitRetryTimeout'); }
138
+ set submitRetryTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_TIMEOUT, value, 'submitRetryTimeout'); }
139
+ get submitRetryAttempts() { return this.readInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_ATTEMPTS, 'submitRetryAttempts'); }
140
+ set submitRetryAttempts(value) { this.writeInt32(option_mapping_1.SocketOption.SUBMIT_RETRY_ATTEMPTS, value, 'submitRetryAttempts'); }
141
+ }
142
+ exports.CommonSocketOptions = CommonSocketOptions;
143
+ class DealerSocketOptions extends CommonSocketOptions {
144
+ /** @internal */
145
+ constructor(token, socket) { super(token, socket); }
146
+ /** @internal */
147
+ static create(socket) {
148
+ return new DealerSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
149
+ }
150
+ get probe() { return this.readBool(option_mapping_1.SocketOption.DEALER_PROBE, 'probe'); }
151
+ set probe(value) { this.writeBool(option_mapping_1.SocketOption.DEALER_PROBE, value); }
152
+ get requestTimeout() { return this.readInt32(option_mapping_1.SocketOption.DEALER_REQUEST_TIMEOUT_MS, 'requestTimeout'); }
153
+ set requestTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.DEALER_REQUEST_TIMEOUT_MS, value, 'requestTimeout'); }
154
+ get peerWeight() { return this.readInt32(option_mapping_1.SocketOption.DEALER_WEIGHT, 'peerWeight'); }
155
+ set peerWeight(value) { this.writeInt32(option_mapping_1.SocketOption.DEALER_WEIGHT, value, 'peerWeight'); }
156
+ }
157
+ exports.DealerSocketOptions = DealerSocketOptions;
158
+ class RouterSocketOptions extends CommonSocketOptions {
159
+ /** @internal */
160
+ constructor(token, socket) { super(token, socket); }
161
+ /** @internal */
162
+ static create(socket) {
163
+ return new RouterSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
164
+ }
165
+ get mandatory() { return this.readBool(option_mapping_1.SocketOption.ROUTER_MANDATORY, 'mandatory'); }
166
+ set mandatory(value) { this.writeBool(option_mapping_1.SocketOption.ROUTER_MANDATORY, value); }
167
+ get handover() { return this.ridDuplicatePolicy === socket_constants_1.RidDuplicatePolicy.Handover; }
168
+ set handover(value) { this.ridDuplicatePolicy = value ? socket_constants_1.RidDuplicatePolicy.Handover : socket_constants_1.RidDuplicatePolicy.Reject; }
169
+ get probe() { return this.readBool(option_mapping_1.SocketOption.PROBE_ROUTER, 'probe'); }
170
+ set probe(value) { this.writeBool(option_mapping_1.SocketOption.PROBE_ROUTER, value); }
171
+ get connectRoutingId() { return readRoutingIdOption(this._socket.getSockOptRaw(option_mapping_1.SocketOption.CONNECT_ROUTING_ID)); }
172
+ setConnectRoutingId(routingId) {
173
+ this._socket.setSockOptRaw(option_mapping_1.SocketOption.CONNECT_ROUTING_ID, (0, routing_id_1.normalizeRoutingId)(routingId, 'routingId'));
174
+ }
175
+ get requestTimeout() { return this.readInt32(option_mapping_1.SocketOption.ROUTER_REQUEST_TIMEOUT_MS, 'requestTimeout'); }
176
+ set requestTimeout(value) { this.writeInt32(option_mapping_1.SocketOption.ROUTER_REQUEST_TIMEOUT_MS, value, 'requestTimeout'); }
177
+ get peerWeight() { return this.readInt32(option_mapping_1.SocketOption.ROUTER_WEIGHT, 'peerWeight'); }
178
+ set peerWeight(value) { this.writeInt32(option_mapping_1.SocketOption.ROUTER_WEIGHT, value, 'peerWeight'); }
179
+ }
180
+ exports.RouterSocketOptions = RouterSocketOptions;
181
+ class StreamSocketOptions extends CommonSocketOptions {
182
+ /** @internal */
183
+ constructor(token, socket) { super(token, socket); }
184
+ /** @internal */
185
+ static create(socket) {
186
+ return new StreamSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
187
+ }
188
+ get notify() { return this.readBool(option_mapping_1.SocketOption.STREAM_NOTIFY, 'notify'); }
189
+ set notify(value) { this.writeBool(option_mapping_1.SocketOption.STREAM_NOTIFY, value); }
190
+ get recvMode() {
191
+ return this.readInt32(option_mapping_1.SocketOption.STREAM_RECV_MODE, 'recvMode');
192
+ }
193
+ set recvMode(value) {
194
+ if (value !== socket_constants_1.StreamRecvMode.Raw && value !== socket_constants_1.StreamRecvMode.Packet) {
195
+ throw new RangeError('recvMode must be StreamRecvMode.Raw or StreamRecvMode.Packet');
196
+ }
197
+ this.writeInt32(option_mapping_1.SocketOption.STREAM_RECV_MODE, value, 'recvMode');
198
+ }
199
+ }
200
+ exports.StreamSocketOptions = StreamSocketOptions;
201
+ class PubSocketOptions extends CommonSocketOptions {
202
+ _welcomeMessage = Buffer.alloc(0);
203
+ /** @internal */
204
+ constructor(token, socket) { super(token, socket); }
205
+ /** @internal */
206
+ static create(socket) {
207
+ return new PubSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
208
+ }
209
+ get verbose() { return this.readBool(option_mapping_1.SocketOption.XPUB_VERBOSE, 'verbose'); }
210
+ set verbose(value) {
211
+ this.writeBool(option_mapping_1.SocketOption.XPUB_VERBOSE, value);
212
+ this.writeBool(option_mapping_1.SocketOption.XPUB_VERBOSER, false);
213
+ }
214
+ get verboser() { return this.readBool(option_mapping_1.SocketOption.XPUB_VERBOSER, 'verboser'); }
215
+ set verboser(value) {
216
+ this.writeBool(option_mapping_1.SocketOption.XPUB_VERBOSE, value);
217
+ this.writeBool(option_mapping_1.SocketOption.XPUB_VERBOSER, value);
218
+ }
219
+ get noDrop() { return this.readBool(option_mapping_1.SocketOption.XPUB_NODROP, 'noDrop'); }
220
+ set noDrop(value) {
221
+ this.writeBool(option_mapping_1.SocketOption.XPUB_NODROP, value);
222
+ }
223
+ get manual() { return this.readBool(option_mapping_1.SocketOption.XPUB_MANUAL, 'manual'); }
224
+ set manual(value) {
225
+ this.writeBool(option_mapping_1.SocketOption.XPUB_MANUAL, value);
226
+ }
227
+ get manualLastValue() { return this.readBool(option_mapping_1.SocketOption.XPUB_MANUAL_LAST_VALUE, 'manualLastValue'); }
228
+ set manualLastValue(value) {
229
+ this.writeBool(option_mapping_1.SocketOption.XPUB_MANUAL, value);
230
+ this.writeBool(option_mapping_1.SocketOption.XPUB_MANUAL_LAST_VALUE, value);
231
+ }
232
+ get topicsCount() { return this.readInt32(option_mapping_1.SocketOption.XPUB_TOPICS_COUNT, 'topicsCount'); }
233
+ welcomeMessage() { return contracts_1.Message.from(this._welcomeMessage); }
234
+ setWelcomeMessage(message) {
235
+ const payload = (0, message_conversion_1.normalizeMessageLikePayload)(message);
236
+ if (Array.isArray(payload))
237
+ throw new TypeError('welcome payload must contain one frame');
238
+ const data = Buffer.isBuffer(payload) ? payload : payload.data;
239
+ this._socket.setSockOptRaw(option_mapping_1.SocketOption.XPUB_WELCOME_MSG, data);
240
+ this._welcomeMessage = Buffer.from(data);
241
+ }
242
+ approveSubscribe(routingId) {
243
+ this._socket.setSockOptRaw(option_mapping_1.SocketOption.XPUB_APPROVE_SUBSCRIBE, (0, routing_id_1.normalizeRoutingId)(routingId));
244
+ }
245
+ rejectSubscribe(routingId) {
246
+ this._socket.setSockOptRaw(option_mapping_1.SocketOption.XPUB_REJECT_SUBSCRIBE, (0, routing_id_1.normalizeRoutingId)(routingId));
247
+ }
248
+ }
249
+ exports.PubSocketOptions = PubSocketOptions;
250
+ class SubSocketOptions extends CommonSocketOptions {
251
+ /** @internal */
252
+ constructor(token, socket) { super(token, socket); }
253
+ /** @internal */
254
+ static create(socket) {
255
+ return new SubSocketOptions(exports.OPTION_CREATE_TOKEN, socket);
256
+ }
257
+ get topicsCount() { return this.readInt32(option_mapping_1.SocketOption.SUB_TOPICS_COUNT, 'topicsCount'); }
258
+ }
259
+ exports.SubSocketOptions = SubSocketOptions;
@@ -0,0 +1,3 @@
1
+ import { SubmitError, SubmitResult } from '../../contracts/errors/errors';
2
+ export declare function submitErrorFromResult(result: SubmitResult, message: string): SubmitError;
3
+ export declare function submitErrorFromNativeResult(result: number, nativeErrno: number, message: string): SubmitError;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.submitErrorFromResult = submitErrorFromResult;
5
+ exports.submitErrorFromNativeResult = submitErrorFromNativeResult;
6
+ const errors_1 = require("../../contracts/errors/errors");
7
+ const error_state_1 = require("../errors/error_state");
8
+ function submitErrorFromResult(result, message) {
9
+ return (0, error_state_1.withRuntimeErrorMessage)(new errors_1.SubmitError(result, 0), message);
10
+ }
11
+ function submitErrorFromNativeResult(result, nativeErrno, message) {
12
+ return (0, error_state_1.withRuntimeErrorMessage)(new errors_1.SubmitError(result, nativeErrno), message);
13
+ }
@@ -0,0 +1,15 @@
1
+ import { Received, RoutingId, StreamPacket, type SendOperation } from '../../contracts';
2
+ import { RecvFlags } from '../../contracts/sockets/socket_constants';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ import { SocketBase } from './socket_base';
5
+ import { StreamSocketOptions } from './socket_options';
6
+ export declare class StreamSocket extends SocketBase {
7
+ readonly options: StreamSocketOptions;
8
+ constructor(ctx: Context);
9
+ send(routingId: RoutingId): SendOperation;
10
+ recv(result: Received, flags?: RecvFlags): boolean;
11
+ recvPacket(result: StreamPacket, flags?: RecvFlags): boolean;
12
+ setRoutingId(routingId: RoutingId): void;
13
+ getRoutingId(): RoutingId;
14
+ disconnectRid(routingId: RoutingId): void;
15
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.StreamSocket = void 0;
5
+ const contracts_1 = require("../../contracts");
6
+ const stream_packet_1 = require("../../contracts/messaging/stream_packet");
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 message_materializer_1 = require("../messaging/message_materializer");
14
+ const native_1 = require("../native/native");
15
+ const socket_base_1 = require("./socket_base");
16
+ const socket_operations_1 = require("./socket_operations");
17
+ const socket_options_1 = require("./socket_options");
18
+ const native = (0, native_1.requireNative)();
19
+ class StreamSocket extends socket_base_1.SocketBase {
20
+ options;
21
+ constructor(ctx) {
22
+ super(ctx, socket_constants_1.SocketType.STREAM);
23
+ this.options = socket_options_1.StreamSocketOptions.create(this);
24
+ }
25
+ send(routingId) {
26
+ const target = Buffer.from((0, routing_id_1.normalizeRoutingId)(routingId));
27
+ 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));
28
+ }
29
+ recv(result, flags = socket_constants_1.RecvFlags.None) {
30
+ let raw;
31
+ try {
32
+ raw = ((flags | 0) & (socket_constants_1.RecvFlags.DontWait | 0))
33
+ ? native.socketRecvMessageNoWait((0, native_handle_1.getNativeHandle)(this))
34
+ : native.socketRecvMessage((0, native_handle_1.getNativeHandle)(this), flags | 0);
35
+ }
36
+ catch (error) {
37
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'recv failed');
38
+ }
39
+ if (raw == null)
40
+ return false;
41
+ const routingId = (0, message_materializer_1.nativeReceivedRoutingId)(raw);
42
+ const sendSync = (parts) => {
43
+ if (!routingId)
44
+ throw new Error('missing routed send target');
45
+ (0, completion_owner_1.completionOwnerOf)(this).sendSync(parts, routingId);
46
+ };
47
+ const sendManaged = (parts) => {
48
+ if (!routingId)
49
+ return Promise.reject(new Error('missing routed send target'));
50
+ return (0, completion_owner_1.completionOwnerOf)(this).submitSend(parts, routingId);
51
+ };
52
+ (0, message_materializer_1.materializeReceivedInto)(result, raw, sendSync, sendManaged);
53
+ return true;
54
+ }
55
+ recvPacket(result, flags = socket_constants_1.RecvFlags.None) {
56
+ if (!(result instanceof contracts_1.StreamPacket)) {
57
+ throw new TypeError('result must be a StreamPacket');
58
+ }
59
+ const state = (0, stream_packet_1.streamPacketState)(result);
60
+ if (state._receiving)
61
+ throw new Error('StreamPacket is already in use by recvPacket');
62
+ result.close();
63
+ state._receiving = true;
64
+ try {
65
+ const raw = native.socketStreamRecvPacket((0, native_handle_1.getNativeHandle)(this), flags | 0);
66
+ if (raw == null)
67
+ return false;
68
+ state._routingId = contracts_1.RoutingId.from(raw.routingId);
69
+ state._header = (0, message_conversion_1.messageFromNativeBuffer)(raw.header);
70
+ state._body = (0, message_conversion_1.messageFromNativeBuffer)(raw.body);
71
+ return true;
72
+ }
73
+ catch (error) {
74
+ result.close();
75
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'stream packet recv failed');
76
+ }
77
+ finally {
78
+ state._receiving = false;
79
+ }
80
+ }
81
+ setRoutingId(routingId) {
82
+ const normalized = (0, routing_id_1.normalizeRoutingId)(routingId);
83
+ (0, native_errors_1.configCall)('routing id set failed', () => native.handleSetRoutingId((0, native_handle_1.getNativeHandle)(this), normalized));
84
+ }
85
+ getRoutingId() {
86
+ return contracts_1.RoutingId.from((0, native_errors_1.configCall)('routing id get failed', () => native.handleGetRoutingId((0, native_handle_1.getNativeHandle)(this))));
87
+ }
88
+ disconnectRid(routingId) {
89
+ const normalized = (0, routing_id_1.normalizeRoutingId)(routingId);
90
+ (0, native_errors_1.configCall)('stream disconnect by routing id failed', () => native.socketDisconnectRid((0, native_handle_1.getNativeHandle)(this), normalized));
91
+ }
92
+ }
93
+ exports.StreamSocket = StreamSocket;
@@ -0,0 +1,7 @@
1
+ import { SubSocketOptions } from './socket_options';
2
+ import { SubscriberSocket } from './socket_operations';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ export declare class SubSocket extends SubscriberSocket {
5
+ readonly options: SubSocketOptions;
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.SubSocket = 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 SubSocket extends socket_operations_1.SubscriberSocket {
9
+ options;
10
+ constructor(ctx) { super(ctx, socket_constants_1.SocketType.SUB); this.options = socket_options_1.SubSocketOptions.create(this); }
11
+ }
12
+ exports.SubSocket = SubSocket;
@@ -0,0 +1,10 @@
1
+ import { PubSocketOptions } from './socket_options';
2
+ import { PublisherSocket } from './socket_operations';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ import { SubscriptionEvent } from '../../contracts';
5
+ import { RecvFlags } from '../../contracts/sockets/socket_constants';
6
+ export declare class XPubSocket extends PublisherSocket {
7
+ readonly options: PubSocketOptions;
8
+ constructor(ctx: Context);
9
+ receiveSubscriptionEvent(result: SubscriptionEvent, flags?: RecvFlags): boolean;
10
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.XPubSocket = void 0;
5
+ const socket_options_1 = require("./socket_options");
6
+ const socket_operations_1 = require("./socket_operations");
7
+ const native_errors_1 = require("../errors/native_errors");
8
+ const native_handle_1 = require("../handles/native_handle");
9
+ const native_1 = require("../native/native");
10
+ const contracts_1 = require("../../contracts");
11
+ const routing_id_conversion_1 = require("../core/routing_id_conversion");
12
+ const subscription_event_state_1 = require("../messaging/subscription_event_state");
13
+ const socket_constants_1 = require("../../contracts/sockets/socket_constants");
14
+ class XPubSocket extends socket_operations_1.PublisherSocket {
15
+ options;
16
+ constructor(ctx) { super(ctx, socket_constants_1.SocketType.XPUB); this.options = socket_options_1.PubSocketOptions.create(this); }
17
+ receiveSubscriptionEvent(resultOrFlags = socket_constants_1.RecvFlags.None, maybeFlags = socket_constants_1.RecvFlags.None) {
18
+ const hasResult = resultOrFlags instanceof contracts_1.SubscriptionEvent;
19
+ const flags = hasResult ? maybeFlags : resultOrFlags;
20
+ let raw;
21
+ try {
22
+ raw = ((flags | 0) & (socket_constants_1.RecvFlags.DontWait | 0))
23
+ ? (0, native_1.requireNative)().socketTrySubscriptionEvent((0, native_handle_1.getNativeHandle)(this))
24
+ : (0, native_1.requireNative)().socketSubscriptionEvent((0, native_handle_1.getNativeHandle)(this), flags | 0);
25
+ }
26
+ catch (error) {
27
+ throw (0, native_errors_1.recvNativeError)(error, flags, 'subscription event recv failed');
28
+ }
29
+ if (!raw) {
30
+ return hasResult ? false : null;
31
+ }
32
+ if (hasResult) {
33
+ (0, subscription_event_state_1.replaceSubscriptionEvent)(resultOrFlags, raw.topic, raw.subscribed, (0, routing_id_conversion_1.wrapRoutingId)(raw.routingId ?? null));
34
+ return true;
35
+ }
36
+ return (0, subscription_event_state_1.createSubscriptionEvent)(raw.topic, raw.subscribed, (0, routing_id_conversion_1.wrapRoutingId)(raw.routingId ?? null));
37
+ }
38
+ }
39
+ exports.XPubSocket = XPubSocket;
@@ -0,0 +1,7 @@
1
+ import { SubSocketOptions } from './socket_options';
2
+ import { SubscriberSocket } from './socket_operations';
3
+ import type { RuntimeContext as Context } from '../core/context';
4
+ export declare class XSubSocket extends SubscriberSocket {
5
+ readonly options: SubSocketOptions;
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.XSubSocket = 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 XSubSocket extends socket_operations_1.SubscriberSocket {
9
+ options;
10
+ constructor(ctx) { super(ctx, socket_constants_1.SocketType.XSUB); this.options = socket_options_1.SubSocketOptions.create(this); }
11
+ }
12
+ exports.XSubSocket = XSubSocket;
@@ -0,0 +1,11 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+
3
+ #include "addon_exports.h"
4
+
5
+ static napi_value init (napi_env env, napi_value exports)
6
+ {
7
+ define_core_exports (env, exports);
8
+ return exports;
9
+ }
10
+
11
+ NAPI_MODULE (NODE_GYP_MODULE_NAME, init)
@@ -0,0 +1,57 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+
3
+ #pragma once
4
+
5
+ #include <node_api.h>
6
+ #include <stdlib.h>
7
+ #include <string.h>
8
+ #include <stdio.h>
9
+ #include <string>
10
+ #include <vector>
11
+
12
+ #include "zlink.h"
13
+
14
+ napi_value throw_last_error (napi_env env, const char *prefix);
15
+ napi_value throw_submit_error (napi_env env, const char *prefix, int result);
16
+ std::string get_string (napi_env env, napi_value val);
17
+ const char *get_c_string_arg (
18
+ napi_env env, napi_value val, char *stack_buf, size_t stack_buf_size, std::string *heap_buf);
19
+ bool build_msg_vector (napi_env env, napi_value arr, std::vector<zlink_msg_t> *out);
20
+ bool build_msg_vector_or_single (napi_env env, napi_value value, std::vector<zlink_msg_t> *out);
21
+ bool init_msg_from_value (napi_env env,
22
+ napi_value value,
23
+ zlink_msg_t *msg,
24
+ bool *contains_native_frame = NULL);
25
+ void close_msg_vector (std::vector<zlink_msg_t> &parts);
26
+
27
+ // Generic napi object-property setters shared across the addon translation
28
+ // units (message snapshots, discovery summaries, ...). Defined here so each
29
+ // caller pulls in one copy instead of redefining them.
30
+ inline void set_uint32_property (napi_env env, napi_value obj, const char *name, uint32_t value)
31
+ {
32
+ napi_value out;
33
+ napi_create_uint32 (env, value, &out);
34
+ napi_set_named_property (env, obj, name, out);
35
+ }
36
+
37
+ inline void set_int64_property (napi_env env, napi_value obj, const char *name, int64_t value)
38
+ {
39
+ napi_value out;
40
+ napi_create_int64 (env, value, &out);
41
+ napi_set_named_property (env, obj, name, out);
42
+ }
43
+
44
+ inline void set_uint64_bigint_property (napi_env env, napi_value obj, const char *name,
45
+ uint64_t value)
46
+ {
47
+ napi_value out;
48
+ napi_create_bigint_uint64 (env, value, &out);
49
+ napi_set_named_property (env, obj, name, out);
50
+ }
51
+
52
+ inline void set_string_property (napi_env env, napi_value obj, const char *name, const char *value)
53
+ {
54
+ napi_value out;
55
+ napi_create_string_utf8 (env, value ? value : "", NAPI_AUTO_LENGTH, &out);
56
+ napi_set_named_property (env, obj, name, out);
57
+ }