apache-iggy 0.10.0 → 0.10.1-edge.2

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 (157) hide show
  1. package/README.md +248 -28
  2. package/dist/client/client.config.d.ts +2 -0
  3. package/dist/client/client.config.js +13 -2
  4. package/dist/client/client.config.test.js +15 -2
  5. package/dist/client/client.connection-string.js +13 -1
  6. package/dist/client/client.connection-string.test.js +43 -1
  7. package/dist/client/client.connection.d.ts +33 -135
  8. package/dist/client/client.connection.js +190 -453
  9. package/dist/client/client.connection.test.js +244 -669
  10. package/dist/client/client.d.ts +4 -35
  11. package/dist/client/client.js +8 -101
  12. package/dist/client/client.operation.d.ts +120 -0
  13. package/dist/client/client.operation.js +428 -0
  14. package/dist/client/client.operation.test.d.ts +2 -0
  15. package/dist/client/client.operation.test.js +285 -0
  16. package/dist/client/client.socket.d.ts +92 -209
  17. package/dist/client/client.socket.js +1205 -981
  18. package/dist/client/client.socket.test.js +4865 -679
  19. package/dist/client/client.type.d.ts +65 -22
  20. package/dist/client/index.d.ts +1 -0
  21. package/dist/client/index.js +1 -0
  22. package/dist/client.e2e.js +3 -5
  23. package/dist/e2e/resource-options.e2e.d.ts +2 -0
  24. package/dist/{wire/stream/purge-stream.command.js → e2e/resource-options.e2e.js} +12 -20
  25. package/dist/e2e/resource-options.suite.d.ts +15 -0
  26. package/dist/e2e/resource-options.suite.js +272 -0
  27. package/dist/e2e/tcp.cluster.e2e.js +1 -0
  28. package/dist/e2e/tcp.consumer-stream.e2e.js +4 -0
  29. package/dist/e2e/tcp.parallel.e2e.js +5 -6
  30. package/dist/e2e/tcp.stream.e2e.js +0 -3
  31. package/dist/e2e/tcp.system.e2e.js +10 -1
  32. package/dist/e2e/tcp.token.e2e.js +8 -2
  33. package/dist/e2e/tcp.topic.e2e.js +0 -3
  34. package/dist/e2e/tcp.user.e2e.js +46 -3
  35. package/dist/e2e/tls.system.e2e.js +21 -12
  36. package/dist/index.d.ts +2 -1
  37. package/dist/index.js +1 -1
  38. package/dist/stream/consumer-stream.js +97 -12
  39. package/dist/wire/cluster/cluster.type.d.ts +2 -2
  40. package/dist/wire/cluster/cluster.utils.d.ts +1 -0
  41. package/dist/wire/cluster/cluster.utils.js +4 -1
  42. package/dist/wire/command-set.d.ts +8 -8
  43. package/dist/wire/command-set.js +18 -9
  44. package/dist/wire/command.code.d.ts +3 -10
  45. package/dist/wire/command.code.js +9 -11
  46. package/dist/wire/command.utils.d.ts +3 -2
  47. package/dist/wire/command.utils.js +3 -2
  48. package/dist/wire/error.code.js +17 -1
  49. package/dist/wire/error.code.test.js +28 -1
  50. package/dist/wire/error.utils.d.ts +4 -2
  51. package/dist/wire/error.utils.js +6 -3
  52. package/dist/wire/identifier.utils.d.ts +2 -0
  53. package/dist/wire/identifier.utils.js +2 -0
  54. package/dist/wire/index.d.ts +1 -0
  55. package/dist/wire/index.js +1 -0
  56. package/dist/wire/message/header.type.d.ts +1 -1
  57. package/dist/wire/message/message-batch.test.js +11 -5
  58. package/dist/wire/message/message.utils.d.ts +0 -10
  59. package/dist/wire/message/message.utils.js +1 -22
  60. package/dist/wire/message/poll-messages.command.d.ts +12 -1
  61. package/dist/wire/message/poll-messages.command.js +64 -16
  62. package/dist/wire/message/poll-messages.command.test.js +143 -5
  63. package/dist/wire/message/poll.utils.d.ts +4 -0
  64. package/dist/wire/message/poll.utils.js +6 -1
  65. package/dist/wire/message/send-messages.command.d.ts +3 -3
  66. package/dist/wire/message/send-messages.command.js +103 -3
  67. package/dist/wire/message/send-messages.command.test.js +113 -2
  68. package/dist/wire/offset/delete-offset.command.d.ts +11 -4
  69. package/dist/wire/offset/delete-offset.command.js +1 -1
  70. package/dist/wire/offset/get-offset.command.d.ts +1 -1
  71. package/dist/wire/offset/offset-write.command.test.d.ts +2 -0
  72. package/dist/wire/offset/offset-write.command.test.js +43 -0
  73. package/dist/wire/offset/offset.utils.js +10 -6
  74. package/dist/wire/offset/store-offset.command.d.ts +10 -0
  75. package/dist/wire/offset/store-offset.command.js +1 -1
  76. package/dist/wire/options.utils.d.ts +46 -0
  77. package/dist/wire/options.utils.js +57 -0
  78. package/dist/wire/partition/partition-route.d.ts +12 -0
  79. package/dist/wire/partition/partition-route.js +40 -0
  80. package/dist/wire/partition/partition-route.test.d.ts +2 -0
  81. package/dist/wire/partition/partition-route.test.js +42 -0
  82. package/dist/wire/session/login-with-token.command.d.ts +2 -2
  83. package/dist/wire/session/login-with-token.command.js +7 -2
  84. package/dist/wire/session/login.command.d.ts +2 -2
  85. package/dist/wire/session/login.command.js +7 -2
  86. package/dist/wire/stream/create-stream.command.d.ts +5 -2
  87. package/dist/wire/stream/create-stream.command.js +20 -2
  88. package/dist/wire/stream/index.d.ts +1 -1
  89. package/dist/wire/stream/index.js +1 -1
  90. package/dist/wire/stream/stream-options.d.ts +77 -0
  91. package/dist/wire/stream/stream-options.js +101 -0
  92. package/dist/wire/stream/stream-options.test.d.ts +2 -0
  93. package/dist/wire/stream/stream-options.test.js +103 -0
  94. package/dist/wire/stream/stream.utils.d.ts +9 -0
  95. package/dist/wire/stream/stream.utils.js +17 -3
  96. package/dist/wire/stream/update-stream.command.d.ts +23 -5
  97. package/dist/wire/stream/update-stream.command.js +10 -17
  98. package/dist/wire/system/describe-options.command.d.ts +23 -6
  99. package/dist/wire/system/describe-options.command.js +21 -2
  100. package/dist/wire/system/get-stats.command.d.ts +17 -0
  101. package/dist/wire/system/get-stats.command.js +69 -16
  102. package/dist/wire/system/get-stats.command.test.d.ts +2 -0
  103. package/dist/wire/system/get-stats.command.test.js +97 -0
  104. package/dist/wire/system/index.d.ts +2 -0
  105. package/dist/wire/system/index.js +2 -0
  106. package/dist/wire/system/snapshot.command.d.ts +64 -0
  107. package/dist/wire/system/snapshot.command.js +76 -0
  108. package/dist/wire/system/snapshot.command.test.d.ts +2 -0
  109. package/dist/wire/system/snapshot.command.test.js +86 -0
  110. package/dist/wire/system/update-resource.command.d.ts +53 -0
  111. package/dist/wire/system/update-resource.command.js +130 -0
  112. package/dist/wire/system/update-resource.command.test.d.ts +2 -0
  113. package/dist/wire/system/update-resource.command.test.js +497 -0
  114. package/dist/wire/token/create-token.command.d.ts +1 -1
  115. package/dist/wire/token/create-token.command.js +1 -1
  116. package/dist/wire/token/create-token.command.test.js +6 -0
  117. package/dist/wire/topic/create-topic.command.d.ts +20 -12
  118. package/dist/wire/topic/create-topic.command.js +11 -4
  119. package/dist/wire/topic/index.d.ts +1 -2
  120. package/dist/wire/topic/index.js +1 -2
  121. package/dist/wire/topic/topic.utils.d.ts +14 -5
  122. package/dist/wire/topic/topic.utils.js +26 -11
  123. package/dist/wire/topic/topic.utils.test.js +13 -13
  124. package/dist/wire/topic/update-topic.command.d.ts +22 -15
  125. package/dist/wire/topic/update-topic.command.js +12 -34
  126. package/dist/wire/user/create-user.command.d.ts +12 -2
  127. package/dist/wire/user/create-user.command.js +7 -3
  128. package/dist/wire/user/index.d.ts +1 -0
  129. package/dist/wire/user/index.js +1 -0
  130. package/dist/wire/user/update-user.command.d.ts +25 -7
  131. package/dist/wire/user/update-user.command.js +18 -31
  132. package/dist/wire/user/user.utils.d.ts +2 -0
  133. package/dist/wire/user/user.utils.js +5 -3
  134. package/dist/wire/vsr/header.d.ts +23 -8
  135. package/dist/wire/vsr/header.js +32 -10
  136. package/dist/wire/vsr/header.test.js +5 -1
  137. package/dist/wire/vsr/index.d.ts +8 -2
  138. package/dist/wire/vsr/index.js +44 -11
  139. package/dist/wire/vsr/operation.d.ts +18 -6
  140. package/dist/wire/vsr/operation.js +46 -16
  141. package/dist/wire/vsr/operation.test.js +32 -8
  142. package/dist/wire/vsr/register.d.ts +10 -6
  143. package/dist/wire/vsr/register.js +24 -7
  144. package/dist/wire/vsr/register.test.js +28 -8
  145. package/dist/wire/vsr/reply.d.ts +4 -1
  146. package/dist/wire/vsr/reply.js +42 -7
  147. package/dist/wire/vsr/reply.test.js +11 -1
  148. package/dist/wire/vsr/session.d.ts +9 -10
  149. package/dist/wire/vsr/session.js +32 -23
  150. package/dist/wire/vsr/session.test.js +33 -7
  151. package/dist/wire/vsr/vsr.test.js +57 -6
  152. package/package.json +6 -7
  153. package/dist/wire/message/flush-unsaved-buffers.command.d.ts +0 -26
  154. package/dist/wire/message/flush-unsaved-buffers.command.js +0 -36
  155. package/dist/wire/stream/purge-stream.command.d.ts +0 -22
  156. package/dist/wire/topic/purge-topic.command.d.ts +0 -24
  157. package/dist/wire/topic/purge-topic.command.js +0 -39
@@ -1,153 +1,51 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import type { Socket } from 'node:net';
3
3
  import type { ClientConfig } from "./client.type.js";
4
- /** One node of the cluster, as a redial candidate. */
4
+ import { type FrozenFrame } from './client.operation.js';
5
5
  export type Endpoint = {
6
6
  host: string;
7
7
  port: number;
8
8
  };
9
- /**
10
- * Manages the low-level TCP/TLS connection to the Iggy server.
11
- * Handles connection lifecycle, reconnection, and data buffering.
12
- */
9
+ export declare const DIAL_TIMEOUT_MS = 2000;
10
+ export declare const LINK_WRITE_QUEUE = 32;
11
+ export declare const MAX_PENDING_PER_LINK = 256;
12
+ /** A connected socket was lost; a later bootstrap can bind it again. */
13
+ export declare class ConnectionClosedError extends Error {
14
+ constructor(cause?: Error);
15
+ }
16
+ export type LinkAttempt = {
17
+ response?: Buffer;
18
+ error?: unknown;
19
+ started: boolean;
20
+ };
21
+ /** One physical endpoint, with independent reader framing and a bounded writer. */
13
22
  export declare class IggyConnection extends EventEmitter {
14
- /** Client configuration */
15
- config: ClientConfig;
16
- /** Underlying socket connection */
23
+ readonly config: ClientConfig;
17
24
  socket: Socket;
18
- /** Whether the connection is established */
19
25
  connected: boolean;
20
- /** Whether a connection attempt is in progress */
21
- connecting: boolean;
22
- /** Whether the connection is being intentionally closed */
23
26
  ending: boolean;
24
- /**
25
- * Whether the socket is being replaced by a deliberate leader redirect
26
- * rather than lost. The drop looks the same from the outside, but nothing a
27
- * caller submitted is in doubt: work waiting to be sent belongs on the node
28
- * the client moves to, not in an error.
29
- */
30
- redirecting: boolean;
31
- /** Reconnection configuration */
32
- private reconnectOption;
33
- /**
34
- * Number of passes made over the known endpoints. One pass dials the
35
- * endpoint the client is on, the endpoint it was configured with, and every
36
- * node the roster named.
37
- */
38
- private reconnectCount;
39
- /** Shared promise for concurrent callers waiting on one connection attempt */
27
+ failure?: unknown;
28
+ readonly closed: Promise<void>;
29
+ private close;
40
30
  private connectPromise?;
41
- /** Shared promise for callers waiting on automatic reconnection */
42
- private reconnectPromise?;
43
- /** Endpoint the client was configured with, kept across leader redirects */
44
- private readonly seedOptions;
45
- /**
46
- * Every node the roster named on the last read, kept as redial candidates.
47
- * A node dies together with its address, and the roster is unreachable
48
- * exactly when it is needed, so it has to have been remembered while the
49
- * connection was still healthy.
50
- */
51
- private rosterEndpoints;
52
- /** Incremental response frame decoder */
53
- private responseDecoder;
54
- /**
55
- * Creates a new IggyConnection.
56
- *
57
- * @param config - Client configuration
58
- */
31
+ private readonly decoder;
32
+ private readonly pending;
33
+ private readonly writes;
34
+ private readonly changed;
35
+ private readonly admissions;
36
+ private writing;
37
+ private frameTimer?;
38
+ private failed;
59
39
  constructor(config: ClientConfig);
60
- /**
61
- * Attaches the lifecycle listeners exactly once per socket instance.
62
- * Attaching them in `connect()` would stack duplicate handlers whenever a
63
- * failed attempt is retried on the same socket.
64
- */
65
- private _installSocket;
66
- /**
67
- * Establishes the connection to the server.
68
- *
69
- * @returns Promise that resolves when connected
70
- */
71
- connect(boundDial?: boolean): Promise<this>;
72
- /**
73
- * Waits for one dial, bounded while other endpoints are queued behind it.
74
- *
75
- * A socket has no connect deadline of its own and there is no 'timeout'
76
- * listener on it, so a node whose syns are dropped holds the pass for the
77
- * whole OS connect timeout -- and it leads every pass, because the current
78
- * endpoint only moves on success. The bound covers the TLS handshake too,
79
- * which is what `_readyEvent()` waits for and has no deadline of its own
80
- * either. It matches the Rust, Go and C# SDKs'.
81
- */
82
- private _dialWithin;
83
- /**
84
- * The event that says a socket can carry a request.
85
- *
86
- * On TLS that is 'secureConnect', not 'connect': the latter fires as soon as
87
- * the TCP handshake completes, so waiting on it would treat a peer that
88
- * never answers the ClientHello as connected and leave the handshake with no
89
- * deadline at all.
90
- */
91
- private _readyEvent;
92
- private _waitForConnection;
93
- /**
94
- * Attempts to reconnect to the server.
95
- * Respects maxRetries limit and emits error when exceeded.
96
- *
97
- * @param err - Optional error that triggered the reconnection
98
- */
99
- reconnect(err?: Error): Promise<this | undefined>;
100
- private _reconnectUntilConnected;
101
- /**
102
- * Records the cluster roster as redial candidates.
103
- *
104
- * Replaced wholesale rather than merged: the roster is the cluster's own
105
- * answer about where its nodes are, so a node it dropped stops being
106
- * dialed. The configured seed is kept separately and outlives it.
107
- */
108
- rememberRoster(endpoints: Endpoint[]): void;
109
- /**
110
- * The roster endpoint after the one this connection is on, for a request
111
- * the current node keeps refusing to admit. Metadata and partition
112
- * consensus groups elect independently, so the metadata leader can hold a
113
- * follower replica of the partition a request targets, and only walking
114
- * the roster reaches that group's primary. `undefined` when the roster
115
- * names nowhere else to go.
116
- */
117
- nextRosterEndpoint(visited: Set<string>): Endpoint | undefined;
118
- /**
119
- * Endpoints a redial rotates through, likeliest first: where the client
120
- * currently is, the endpoint it was configured with, then the roster it
121
- * learned while connected. After a leader redirect the current endpoint may
122
- * die with the leader, and the rest of the list is the way back to the
123
- * cluster.
124
- *
125
- * Duplicates are dropped by spelling: the loopback aliases and an
126
- * IPv4-mapped IPv6 address collapse onto one endpoint. Names are not
127
- * resolved, so a seed given as a DNS name and the roster's IP for the same
128
- * node still count as two candidates -- one wasted dial per pass, not a
129
- * correctness problem.
130
- */
131
- _redialCandidates(): ClientConfig['options'][];
132
- redirect(host: string, port: number): Promise<void>;
133
- abort(): void;
40
+ connect(signal?: AbortSignal): Promise<this>;
41
+ private dial;
42
+ exchange(frame: () => Buffer, deadline: number, signal: AbortSignal, owner?: FrozenFrame): Promise<LinkAttempt>;
43
+ private writeFrames;
44
+ private onData;
45
+ private finish;
46
+ private fail;
134
47
  isConnectedTo(host: string, port: number): boolean;
135
- /**
136
- * Destroys the connection and marks it as ending.
137
- */
138
48
  _destroy(): void;
139
- /**
140
- * Clears the response buffer and resets the waiting state.
141
- */
142
- _endResponseWait(): void;
143
- /**
144
- * Handles incoming data from the socket.
145
- * Buffers incomplete responses and emits complete ones.
146
- *
147
- * @param data - Incoming data buffer
148
- */
149
- _onData(data: Buffer): void;
150
- writeFrame(frame: Buffer): void;
151
49
  }
152
50
  export declare const endpointKey: (endpoint: Endpoint) => string;
153
51
  //# sourceMappingURL=client.connection.d.ts.map