@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,105 @@
1
+ import type { Message, MessageLike } from '../messaging';
2
+ import type { RoutingId } from '../core';
3
+ import type { RidDuplicatePolicyValue, StreamRecvMode } from './socket_constants';
4
+ /** Typed facade over the socket options shared by every socket type. */
5
+ export interface CommonSocketOptions {
6
+ /** How long, in ms, close waits to deliver queued messages. */
7
+ linger: number;
8
+ /** Maximum accounted outbound bytes before back-pressure; 0n means unlimited. */
9
+ sendHwm: bigint;
10
+ /** Maximum accounted inbound bytes before back-pressure; 0n means unlimited. */
11
+ recvHwm: bigint;
12
+ /** How long, in ms, a blocking send waits before failing. */
13
+ sendTimeout: number;
14
+ /** How long, in ms, a blocking receive waits before failing. */
15
+ recvTimeout: number;
16
+ /** Whether messages queue only to fully established connections. */
17
+ immediate: boolean;
18
+ /** How the socket reacts when a peer reuses an existing routing id. */
19
+ ridDuplicatePolicy: RidDuplicatePolicyValue;
20
+ /** Time limit, in ms, for a single connection attempt. */
21
+ connectTimeout: number;
22
+ /** Whether IPv6 connections are enabled. */
23
+ ipv6: boolean;
24
+ /** Whether Nagle's algorithm is disabled (`TCP_NODELAY`). */
25
+ tcpNoDelay: boolean;
26
+ /** TCP keep-alive: -1 OS default, 0 off, 1 on. */
27
+ tcpKeepalive: number;
28
+ /** Maximum inbound message size in bytes; -1n means no limit. */
29
+ maxMsgSize: bigint;
30
+ /** The concrete endpoint the socket last bound to (resolves wildcards). */
31
+ readonly lastEndpoint: string;
32
+ /** Maximum length of the pending-connection queue on a bound endpoint. */
33
+ backlog: number;
34
+ /** Base delay, in ms, before reconnecting a broken connection. */
35
+ reconnectInterval: number;
36
+ /** Maximum reconnect delay, in ms, under exponential backoff. */
37
+ reconnectIntervalMax: number;
38
+ /** Whether a submit that fails locally is retried (see RidDuplicatePolicy/SubmitRetryMode constants). */
39
+ submitRetryMode: number;
40
+ /** Total time budget, in ms, for submit retries. */
41
+ submitRetryTimeout: number;
42
+ /** Maximum number of submit retry attempts. */
43
+ submitRetryAttempts: number;
44
+ }
45
+ /** Typed facade over DEALER-specific socket options. */
46
+ export interface DealerSocketOptions extends CommonSocketOptions {
47
+ /** Whether to send an empty probe on connect so the peer learns this socket's routing id. */
48
+ probe: boolean;
49
+ /** How long, in ms, a DEALER request waits for a reply. */
50
+ requestTimeout: number;
51
+ /** This peer's relative load-balancing weight (0-100). */
52
+ peerWeight: number;
53
+ }
54
+ /** Typed facade over ROUTER-specific socket options. */
55
+ export interface RouterSocketOptions extends CommonSocketOptions {
56
+ /** Whether sending to an unknown route raises an error instead of dropping the message. */
57
+ mandatory: boolean;
58
+ /** Whether a new peer reusing an existing routing id takes it over. */
59
+ handover: boolean;
60
+ /** Whether to send an empty probe on connect so the peer learns this socket's routing id. */
61
+ probe: boolean;
62
+ /** The routing id assigned to the next outgoing connection, or null when none is pending. */
63
+ readonly connectRoutingId: RoutingId | null;
64
+ /** Assign `routingId` to the next connection this socket initiates. */
65
+ setConnectRoutingId(routingId: RoutingId): void;
66
+ /** How long, in ms, a ROUTER request waits for a reply. */
67
+ requestTimeout: number;
68
+ /** This peer's relative load-balancing weight (0-100). */
69
+ peerWeight: number;
70
+ }
71
+ /** Typed facade over STREAM-specific socket options. */
72
+ export interface StreamSocketOptions extends CommonSocketOptions {
73
+ /** Whether peer connect and disconnect events are delivered as messages. */
74
+ notify: boolean;
75
+ /** Select RAW byte records or framed packet receive before bind/connect. */
76
+ recvMode: StreamRecvMode;
77
+ }
78
+ /** Typed facade over PUB/XPUB-specific socket options. */
79
+ export interface PubSocketOptions extends CommonSocketOptions {
80
+ /** Whether every subscription message (including duplicates) is delivered. */
81
+ verbose: boolean;
82
+ /** Whether every subscription and unsubscription message is delivered. */
83
+ verboser: boolean;
84
+ /** Whether a back-pressured send raises an error instead of dropping the message. */
85
+ noDrop: boolean;
86
+ /** Whether subscriptions are handled manually via approve/reject. */
87
+ manual: boolean;
88
+ /** Manual handling that replays the last cached message per topic to a new subscriber. */
89
+ manualLastValue: boolean;
90
+ /** The number of distinct topics currently subscribed across subscribers. */
91
+ readonly topicsCount: number;
92
+ /** Return the welcome message sent to new subscribers (caller owns it). */
93
+ welcomeMessage(): Message;
94
+ /** Set a message automatically sent to each newly connected subscriber. */
95
+ setWelcomeMessage(message: MessageLike): void;
96
+ /** Accept a pending subscription from `routingId`; requires manual mode. */
97
+ approveSubscribe(routingId: RoutingId): void;
98
+ /** Decline a pending subscription from `routingId`; requires manual mode. */
99
+ rejectSubscribe(routingId: RoutingId): void;
100
+ }
101
+ /** Typed facade over SUB-specific socket options. */
102
+ export interface SubSocketOptions extends CommonSocketOptions {
103
+ /** The number of active subscriptions on this socket. */
104
+ readonly topicsCount: number;
105
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import type { RoutingId } from '../core';
2
+ import type { Received, SendOperation, StreamPacket } from '../messaging';
3
+ import type { RecvFlags } from './socket_constants';
4
+ import type { StreamSocketOptions } from './socket_options';
5
+ import type { Socket } from './socket';
6
+ /**
7
+ * STREAM socket: exchanges framed packets with raw TCP peers addressed by
8
+ * routing id.
9
+ */
10
+ export interface StreamSocket extends Socket {
11
+ /** The STREAM-specific typed options facade. */
12
+ readonly options: StreamSocketOptions;
13
+ /**
14
+ * Begin an exact-target managed send. `submit()` resolves only after Core
15
+ * accepts the record for the routing id captured by this builder.
16
+ */
17
+ send(routingId: RoutingId): SendOperation;
18
+ /** Receive a message into `result`; false when `RecvFlags.DontWait` is set and none is available. */
19
+ recv(result: Received, flags?: RecvFlags): boolean;
20
+ /** Receive one packet into reusable storage; false for non-blocking no-data. */
21
+ recvPacket(result: StreamPacket, flags?: RecvFlags): boolean;
22
+ /**
23
+ * Set the routing id that identifies this socket to its peers. Apply before
24
+ * connecting so peers observe it from the first packet.
25
+ */
26
+ setRoutingId(routingId: RoutingId): void;
27
+ /** Return the routing id that identifies this socket to its peers. */
28
+ getRoutingId(): RoutingId;
29
+ /** Disconnect the peer identified by `routingId`. */
30
+ disconnectRid(routingId: RoutingId): void;
31
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { Message, type MessageLike } from '../../contracts';
2
+ import { type MessageSnapshot } from '../messaging/message_snapshot';
3
+ export declare function toMessageParts(parts: readonly MessageLike[]): Array<Buffer | MessageSnapshot>;
4
+ export declare function normalizeOperationPayload(parts: MessageLike | readonly MessageLike[]): Buffer | MessageSnapshot | Array<Buffer | MessageSnapshot>;
5
+ export { normalizeOperationPayload as normalizeMessageLikePayload };
6
+ export declare function messageFromNativeBuffer(buffer: Buffer | null | undefined): Message;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.toMessageParts = toMessageParts;
5
+ exports.normalizeOperationPayload = normalizeOperationPayload;
6
+ exports.normalizeMessageLikePayload = normalizeOperationPayload;
7
+ exports.messageFromNativeBuffer = messageFromNativeBuffer;
8
+ const contracts_1 = require("../../contracts");
9
+ const message_snapshot_1 = require("../messaging/message_snapshot");
10
+ function normalizeBufferLike(value, label = 'value') {
11
+ if (Buffer.isBuffer(value))
12
+ return value;
13
+ if (value instanceof Uint8Array) {
14
+ return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
15
+ }
16
+ if (typeof value === 'string')
17
+ return Buffer.from(value);
18
+ throw new TypeError(`${typeof label === 'number' ? `parts[${label}]` : label} must be Buffer, Uint8Array, or string`);
19
+ }
20
+ function toMessageParts(parts) {
21
+ let converted;
22
+ for (let index = 0; index < parts.length; ++index) {
23
+ const part = parts[index];
24
+ const normalized = part instanceof contracts_1.Message
25
+ ? (0, message_snapshot_1.messageToSnapshot)(part) : normalizeBufferLike(part, index);
26
+ if (converted === undefined && normalized !== part) {
27
+ converted = parts.slice(0, index);
28
+ }
29
+ converted?.push(normalized);
30
+ }
31
+ // Native submit only reads the list and copies Buffer bytes synchronously.
32
+ // Allocate a replacement list only when an element actually needs conversion.
33
+ return converted ?? parts;
34
+ }
35
+ function normalizeOperationPayload(parts) {
36
+ if (!Array.isArray(parts)) {
37
+ const scalar = parts;
38
+ return scalar instanceof contracts_1.Message ? (0, message_snapshot_1.messageToSnapshot)(scalar) : normalizeBufferLike(scalar, 'message');
39
+ }
40
+ if (parts.length === 1) {
41
+ const part = parts[0];
42
+ return part instanceof contracts_1.Message ? (0, message_snapshot_1.messageToSnapshot)(part) : normalizeBufferLike(part, 'message');
43
+ }
44
+ return toMessageParts(parts);
45
+ }
46
+ function messageFromNativeBuffer(buffer) {
47
+ // HOT PATH: the addon already transfers payload ownership to a JS Buffer.
48
+ return (0, message_snapshot_1.messageFromOwnedBuffer)(buffer ?? Buffer.alloc(0));
49
+ }
@@ -0,0 +1,43 @@
1
+ import type { AutoHwmProfileValue, CoreHwmBudgetSnapshot } from '../../contracts/core';
2
+ import { NativeHandle } from '../handles/native_handle';
3
+ export declare class ContextOptions {
4
+ private _threadNamePrefix;
5
+ get ioThreads(): number;
6
+ set ioThreads(value: number);
7
+ get maxSockets(): number;
8
+ set maxSockets(value: number);
9
+ get socketLimit(): number;
10
+ get maxMsgSize(): number;
11
+ set maxMsgSize(value: number);
12
+ get msgTSize(): number;
13
+ get threadPriority(): number;
14
+ set threadPriority(value: number);
15
+ get threadSchedulingPolicy(): number;
16
+ set threadSchedulingPolicy(value: number);
17
+ get blocky(): boolean;
18
+ set blocky(value: boolean);
19
+ get autoHwmEnabled(): boolean;
20
+ set autoHwmEnabled(value: boolean);
21
+ get autoHwmRecalcDebounceMs(): number;
22
+ set autoHwmRecalcDebounceMs(value: number);
23
+ get coreHwmProfile(): AutoHwmProfileValue;
24
+ set coreHwmProfile(value: AutoHwmProfileValue);
25
+ get coreHwmMemoryLimitBytes(): bigint;
26
+ set coreHwmMemoryLimitBytes(value: bigint);
27
+ get coreHwmBudgetBytes(): bigint;
28
+ set coreHwmBudgetBytes(value: bigint);
29
+ get threadNamePrefix(): string;
30
+ set threadNamePrefix(value: string);
31
+ addThreadAffinity(cpu: number): void;
32
+ removeThreadAffinity(cpu: number): void;
33
+ }
34
+ export declare class Context extends NativeHandle {
35
+ readonly options: ContextOptions;
36
+ constructor();
37
+ shutdown(): void;
38
+ recalculateAutoHwm(): void;
39
+ getCoreHwmBudgetSnapshot(): CoreHwmBudgetSnapshot;
40
+ resetCoreHwmBudgetMetrics(): void;
41
+ close(): void;
42
+ }
43
+ export { Context as RuntimeContext, ContextOptions as RuntimeContextOptions, };
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RuntimeContextOptions = exports.RuntimeContext = exports.Context = exports.ContextOptions = void 0;
5
+ const node_v8_1 = require("node:v8");
6
+ const error_mapping_1 = require("../errors/error_mapping");
7
+ const native_errors_1 = require("../errors/native_errors");
8
+ const validation_1 = require("../options/validation");
9
+ const native_1 = require("../native/native");
10
+ const native_handle_1 = require("../handles/native_handle");
11
+ const context_options_1 = require("./context_options");
12
+ const byte_values_1 = require("../options/byte_values");
13
+ const OPTION_CREATE_TOKEN = Symbol('OptionFacade.create');
14
+ class ContextOptions {
15
+ /** @internal */
16
+ _context;
17
+ _threadNamePrefix = '';
18
+ /** @internal */
19
+ constructor(token, context) {
20
+ if (token !== OPTION_CREATE_TOKEN) {
21
+ throw new TypeError('context options are created by contexts');
22
+ }
23
+ this._context = context;
24
+ }
25
+ /** @internal */
26
+ static create(context) {
27
+ return new ContextOptions(OPTION_CREATE_TOKEN, context);
28
+ }
29
+ get ioThreads() { return getContextOptionRaw(this._context, context_options_1.ContextOption.IO_THREADS); }
30
+ set ioThreads(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.IO_THREADS, value | 0); }
31
+ get maxSockets() { return getContextOptionRaw(this._context, context_options_1.ContextOption.MAX_SOCKETS); }
32
+ set maxSockets(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.MAX_SOCKETS, value | 0); }
33
+ get socketLimit() { return getContextOptionRaw(this._context, context_options_1.ContextOption.SOCKET_LIMIT); }
34
+ get maxMsgSize() { return getContextOptionRaw(this._context, context_options_1.ContextOption.MAX_MSGSZ); }
35
+ set maxMsgSize(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.MAX_MSGSZ, value | 0); }
36
+ get msgTSize() { return getContextOptionRaw(this._context, context_options_1.ContextOption.MSG_T_SIZE); }
37
+ get threadPriority() { return getContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_PRIORITY); }
38
+ set threadPriority(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_PRIORITY, value | 0); }
39
+ get threadSchedulingPolicy() { return getContextOptionRawStrict(this._context, context_options_1.ContextOption.THREAD_SCHED_POLICY); }
40
+ set threadSchedulingPolicy(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_SCHED_POLICY, value | 0); }
41
+ get blocky() { return getContextOptionRaw(this._context, context_options_1.ContextOption.BLOCKY) !== 0; }
42
+ set blocky(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.BLOCKY, value ? 1 : 0); }
43
+ get autoHwmEnabled() { return getContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_ENABLE) !== 0; }
44
+ set autoHwmEnabled(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_ENABLE, value ? 1 : 0); }
45
+ get autoHwmRecalcDebounceMs() { return getContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_RECALC_DEBOUNCE_MS); }
46
+ set autoHwmRecalcDebounceMs(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_RECALC_DEBOUNCE_MS, value | 0); }
47
+ get coreHwmProfile() { return getContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_PROFILE); }
48
+ set coreHwmProfile(value) { setContextOptionRaw(this._context, context_options_1.ContextOption.AUTO_HWM_PROFILE, value | 0); }
49
+ get coreHwmMemoryLimitBytes() { return getContextUInt64(this._context, context_options_1.ContextOption.AUTO_HWM_MEMORY_LIMIT_BYTES, 'coreHwmMemoryLimitBytes'); }
50
+ set coreHwmMemoryLimitBytes(value) { setContextUInt64(this._context, context_options_1.ContextOption.AUTO_HWM_MEMORY_LIMIT_BYTES, value, 'coreHwmMemoryLimitBytes'); }
51
+ get coreHwmBudgetBytes() { return getContextUInt64(this._context, context_options_1.ContextOption.AUTO_HWM_CORE_BUDGET_BYTES, 'coreHwmBudgetBytes'); }
52
+ set coreHwmBudgetBytes(value) { setContextUInt64(this._context, context_options_1.ContextOption.AUTO_HWM_CORE_BUDGET_BYTES, value, 'coreHwmBudgetBytes'); }
53
+ get threadNamePrefix() { return this._threadNamePrefix; }
54
+ set threadNamePrefix(value) {
55
+ const normalized = (0, validation_1.validateCString)(value, 'threadNamePrefix');
56
+ setContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_NAME_PREFIX, Buffer.from(normalized));
57
+ this._threadNamePrefix = normalized;
58
+ }
59
+ addThreadAffinity(cpu) { setContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_AFFINITY_CPU_ADD, cpu | 0); }
60
+ removeThreadAffinity(cpu) { setContextOptionRaw(this._context, context_options_1.ContextOption.THREAD_AFFINITY_CPU_REMOVE, cpu | 0); }
61
+ }
62
+ exports.ContextOptions = ContextOptions;
63
+ exports.RuntimeContextOptions = ContextOptions;
64
+ function setContextOptionRaw(context, option, value) {
65
+ (0, native_errors_1.configCall)('context option set failed', () => {
66
+ (0, native_1.requireNative)().ctxSetOpt((0, native_handle_1.getNativeHandle)(context), option | 0, typeof value === 'number' ? value | 0 : value);
67
+ });
68
+ }
69
+ function getContextOptionRaw(context, option) {
70
+ try {
71
+ return (0, native_1.requireNative)().ctxGetOpt((0, native_handle_1.getNativeHandle)(context), option | 0);
72
+ }
73
+ catch (error) {
74
+ if ((option | 0) === context_options_1.ContextOption.THREAD_PRIORITY ||
75
+ (option | 0) === context_options_1.ContextOption.THREAD_SCHED_POLICY) {
76
+ return -1;
77
+ }
78
+ throw (0, error_mapping_1.createError)('config', (0, native_errors_1.readErrno)(), (0, native_errors_1.nativeErrorMessage)(error, 'context option get failed'));
79
+ }
80
+ }
81
+ function getContextOptionRawStrict(context, option) {
82
+ try {
83
+ return (0, native_1.requireNative)().ctxGetOpt((0, native_handle_1.getNativeHandle)(context), option | 0);
84
+ }
85
+ catch (error) {
86
+ const message = error instanceof Error && error.message
87
+ ? error.message
88
+ : 'ctx_getopt failed';
89
+ throw (0, error_mapping_1.createError)('config', (0, native_errors_1.readErrno)(), message);
90
+ }
91
+ }
92
+ function getContextUInt64(context, option, name) {
93
+ const value = (0, native_1.requireNative)().ctxGetOptData((0, native_handle_1.getNativeHandle)(context), option | 0);
94
+ if (value.length !== 8)
95
+ throw new Error(`${name} option returned an invalid payload`);
96
+ return value.readBigUInt64LE(0);
97
+ }
98
+ function setContextUInt64(context, option, value, name) {
99
+ setContextOptionRaw(context, option, (0, byte_values_1.uint64Buffer)(value, name));
100
+ }
101
+ class Context extends native_handle_1.NativeHandle {
102
+ options;
103
+ constructor() {
104
+ super((0, native_1.requireNative)().ctxNew());
105
+ if (!this._native)
106
+ throw (0, native_errors_1.lastError)('config', 'context creation failed');
107
+ this.options = ContextOptions.create(this);
108
+ const heapLimitBytes = BigInt(Math.trunc((0, node_v8_1.getHeapStatistics)().heap_size_limit));
109
+ if (heapLimitBytes > 0n) {
110
+ setContextUInt64(this, context_options_1.ContextOption.AUTO_HWM_RUNTIME_MEMORY_LIMIT_BYTES, heapLimitBytes, 'runtimeMemoryLimitBytes');
111
+ }
112
+ }
113
+ shutdown() {
114
+ (0, native_errors_1.closeCall)('context shutdown failed', () => {
115
+ (0, native_1.requireNative)().ctxShutdown(this._native);
116
+ });
117
+ }
118
+ recalculateAutoHwm() {
119
+ (0, native_errors_1.configCall)('context auto HWM recalculation failed', () => {
120
+ (0, native_1.requireNative)().ctxRecalculateAutoHwm(this._native);
121
+ });
122
+ }
123
+ getCoreHwmBudgetSnapshot() {
124
+ const snapshot = (0, native_1.requireNative)().ctxGetAutoHwmBudgetSnapshot(this._native);
125
+ const flags = snapshot.flags >>> 0;
126
+ return Object.freeze({
127
+ ...snapshot,
128
+ reservedUInt64: Object.freeze([...snapshot.reservedUInt64]),
129
+ budgetPlanningActive: (flags & (1 << 0)) !== 0,
130
+ budgetInsufficient: (flags & (1 << 1)) !== 0,
131
+ aggregateHwmValid: (flags & (1 << 2)) !== 0,
132
+ aggregateOverflow: (flags & (1 << 3)) !== 0
133
+ });
134
+ }
135
+ resetCoreHwmBudgetMetrics() {
136
+ (0, native_errors_1.configCall)('context auto HWM metric reset failed', () => {
137
+ (0, native_1.requireNative)().ctxResetAutoHwmBudgetMetrics(this._native);
138
+ });
139
+ }
140
+ close() {
141
+ if (!this._native)
142
+ return;
143
+ (0, native_errors_1.closeCall)('context close failed', () => {
144
+ (0, native_1.requireNative)().ctxTerm(this._native);
145
+ });
146
+ this._native = null;
147
+ }
148
+ }
149
+ exports.Context = Context;
150
+ exports.RuntimeContext = Context;
@@ -0,0 +1,19 @@
1
+ export declare const ContextOption: Readonly<{
2
+ readonly IO_THREADS: 1;
3
+ readonly MAX_SOCKETS: 2;
4
+ readonly SOCKET_LIMIT: 3;
5
+ readonly THREAD_PRIORITY: 3;
6
+ readonly THREAD_SCHED_POLICY: 4;
7
+ readonly MAX_MSGSZ: 5;
8
+ readonly MSG_T_SIZE: 6;
9
+ readonly THREAD_AFFINITY_CPU_ADD: 7;
10
+ readonly THREAD_AFFINITY_CPU_REMOVE: 8;
11
+ readonly THREAD_NAME_PREFIX: 9;
12
+ readonly BLOCKY: 10;
13
+ readonly AUTO_HWM_ENABLE: 12;
14
+ readonly AUTO_HWM_RECALC_DEBOUNCE_MS: 14;
15
+ readonly AUTO_HWM_PROFILE: 17;
16
+ readonly AUTO_HWM_MEMORY_LIMIT_BYTES: 19;
17
+ readonly AUTO_HWM_RUNTIME_MEMORY_LIMIT_BYTES: 20;
18
+ readonly AUTO_HWM_CORE_BUDGET_BYTES: 21;
19
+ }>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ContextOption = void 0;
5
+ exports.ContextOption = Object.freeze({
6
+ IO_THREADS: 1,
7
+ MAX_SOCKETS: 2,
8
+ SOCKET_LIMIT: 3,
9
+ THREAD_PRIORITY: 3,
10
+ THREAD_SCHED_POLICY: 4,
11
+ MAX_MSGSZ: 5,
12
+ MSG_T_SIZE: 6,
13
+ THREAD_AFFINITY_CPU_ADD: 7,
14
+ THREAD_AFFINITY_CPU_REMOVE: 8,
15
+ THREAD_NAME_PREFIX: 9,
16
+ BLOCKY: 10,
17
+ AUTO_HWM_ENABLE: 12,
18
+ AUTO_HWM_RECALC_DEBOUNCE_MS: 14,
19
+ AUTO_HWM_PROFILE: 17,
20
+ AUTO_HWM_MEMORY_LIMIT_BYTES: 19,
21
+ AUTO_HWM_RUNTIME_MEMORY_LIMIT_BYTES: 20,
22
+ AUTO_HWM_CORE_BUDGET_BYTES: 21
23
+ });
@@ -0,0 +1,3 @@
1
+ import { RoutingId } from '../../contracts/core';
2
+ export declare function normalizeRoutingId(routingId: RoutingId, name?: string): Buffer;
3
+ export declare function routingIdFromOwnedBuffer(bytes: Buffer): RoutingId;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.normalizeRoutingId = normalizeRoutingId;
5
+ exports.routingIdFromOwnedBuffer = routingIdFromOwnedBuffer;
6
+ const core_1 = require("../../contracts/core");
7
+ const errors_1 = require("../../contracts/errors/errors");
8
+ const error_state_1 = require("../errors/error_state");
9
+ const ROUTING_ID_MAX_LENGTH = 255;
10
+ function requireRoutingId(routingId, name = 'routingId') {
11
+ if (!(routingId instanceof core_1.RoutingId)) {
12
+ throw new TypeError(`${name} must be a RoutingId`);
13
+ }
14
+ return routingId._bytes;
15
+ }
16
+ function normalizeRoutingId(routingId, name = 'routingId') {
17
+ return requireRoutingId(routingId, name);
18
+ }
19
+ function routingIdFromOwnedBuffer(bytes) {
20
+ if (!Buffer.isBuffer(bytes)) {
21
+ throw new TypeError('bytes must be a Buffer');
22
+ }
23
+ if (bytes.length === 0 || bytes.length > ROUTING_ID_MAX_LENGTH) {
24
+ throw (0, error_state_1.withRuntimeErrorMessage)(new errors_1.ConfigError(errors_1.ConfigResult.InvalidArgument, 0), `bytes must be 1..${ROUTING_ID_MAX_LENGTH} bytes`);
25
+ }
26
+ const routingId = Object.create(core_1.RoutingId.prototype);
27
+ routingId._bytes = bytes;
28
+ Object.freeze(routingId);
29
+ return routingId;
30
+ }
@@ -0,0 +1,2 @@
1
+ import { RoutingId } from '../../contracts/core';
2
+ export declare function wrapRoutingId(routingId: Buffer | Uint8Array | null | undefined): RoutingId | null;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.wrapRoutingId = wrapRoutingId;
5
+ const core_1 = require("../../contracts/core");
6
+ function wrapRoutingId(routingId) {
7
+ if (!routingId || routingId.length === 0) {
8
+ return null;
9
+ }
10
+ return core_1.RoutingId.from(routingId);
11
+ }
@@ -0,0 +1,8 @@
1
+ import type { Message } from '../../contracts';
2
+ import type { RuntimeBaseSocket as BaseSocket } from '../sockets';
3
+ export declare function version(): [number, number, number];
4
+ export declare function strerror(code: number): string;
5
+ export declare function has(capability: string): boolean;
6
+ export declare function proxy(frontend: BaseSocket, backend: BaseSocket, capture?: BaseSocket): void;
7
+ export declare function sleep(seconds: number): void;
8
+ export declare function multipartClose(parts: Message[]): void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: MPL-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.version = version;
5
+ exports.strerror = strerror;
6
+ exports.has = has;
7
+ exports.proxy = proxy;
8
+ exports.sleep = sleep;
9
+ exports.multipartClose = multipartClose;
10
+ const validation_1 = require("../options/validation");
11
+ const native_errors_1 = require("../errors/native_errors");
12
+ const native_handle_1 = require("../handles/native_handle");
13
+ const native_1 = require("../native/native");
14
+ function version() {
15
+ return (0, native_1.requireNative)().version();
16
+ }
17
+ function strerror(code) {
18
+ return (0, native_1.requireNative)().strerror(code);
19
+ }
20
+ function has(capability) {
21
+ const normalized = (0, validation_1.validateCString)(capability, 'capability', Number.MAX_SAFE_INTEGER);
22
+ return (0, native_1.requireNative)().has(normalized);
23
+ }
24
+ function proxy(frontend, backend, capture) {
25
+ if (capture === null) {
26
+ throw new TypeError('capture must be a socket or undefined');
27
+ }
28
+ (0, native_errors_1.configCall)('proxy failed', () => {
29
+ (0, native_1.requireNative)().proxy((0, native_handle_1.getNativeHandle)(frontend), (0, native_handle_1.getNativeHandle)(backend), capture ? (0, native_handle_1.getNativeHandle)(capture) : null);
30
+ });
31
+ }
32
+ function sleep(seconds) {
33
+ (0, native_1.requireNative)().sleep(seconds | 0);
34
+ }
35
+ function multipartClose(parts) {
36
+ for (const part of parts) {
37
+ part.close();
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ import { ZlinkError } from '../../contracts/errors/errors';
2
+ export type NativeErrorCategory = 'submit' | 'request' | 'recv' | 'handler' | 'close' | 'bind' | 'connect' | 'config';
3
+ export declare function mapNativeErrno(category: NativeErrorCategory, errno: number): number;
4
+ export declare function createError(category: NativeErrorCategory, errno: number, message?: string): ZlinkError;