@@ -43,11 +43,11 @@ export declare const capability: Partial<{
43
43
* To correctly connect two sockets with this mechanism:
44
44
*
45
45
* * Generate a **client** keypair with {@link curveKeyPair}().
46
- * * Assign the private and public key on the client socket with
46
+ * - Assign the private and public key on the client socket with
47
47
* {@link Socket.curveSecretKey} and {@link Socket.curvePublicKey}.
48
48
* * Generate a **server** keypair with {@link curveKeyPair}().
49
- * * Assign the private key on the server socket with {@link Socket.curveSecretKey}.
50
- * * Assign the public key **on the client socket** with
49
+ * - Assign the private key on the server socket with {@link Socket.curveSecretKey}.
50
+ * - Assign the public key **on the client socket** with
51
51
* {@link Socket.curveServerKey}. The server does *not* need to know its own
52
52
* public key. Key distribution is *not* handled by the CURVE security
53
53
* mechanism.
@@ -112,15 +112,24 @@ export declare class Context {
112
112
*/
113
113
export declare const context : Context
114
114
115
- interface ErrnoError extends Error {
115
+ /**
116
+ * An error that represents a generic error with an associated error code.
117
+ */
118
+ export interface ErrnoError extends Error {
116
119
code : string
117
120
errno : number
118
121
}
119
122
123
+ /**
124
+ * An event that represents an authorization error.
125
+ */
120
126
export interface AuthError extends Error {
121
127
status : 300 | 400 | 500
122
128
}
123
129
130
+ /**
131
+ * An event that represents a protocol error.
132
+ */
124
133
export interface ProtoError extends Error {
125
134
code :
126
135
| "ERR_ZMTP_UNSPECIFIED"
@@ -145,18 +154,39 @@ export interface ProtoError extends Error {
145
154
| "ERR_ZAP_INVALID_METADATA"
146
155
}
147
156
157
+ /**
158
+ * An object that contains the address of an event.
159
+ */
148
160
export interface EventAddress {
149
161
address : string
150
162
}
151
163
164
+ /**
165
+ * An object that contains the interval for an event.
166
+ */
152
167
export interface EventInterval {
153
168
interval : number
154
169
}
155
170
171
+ /**
172
+ * An object that contains an error for an event.
173
+ */
156
174
export interface EventError < E = ErrnoError > {
157
175
error : E
158
176
}
159
177
178
+ /**
179
+ * Represents a ZeroMQ event type.
180
+ * @typeParam T The event type (e.g., "bind", "connect", "close", etc.), which is stored in the `type` property.
181
+ * @typeParam D The base event data type (which is unified by the type).
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * type AllEvents = EventFor<"bind", { address: string }>
186
+ * // is equivalent to
187
+ * type AllEvents = { type: "bind", address: string }
188
+ * ```
189
+ */
160
190
export type EventFor < T extends string , D = { } > = Expand < { type : T } & D >
161
191
162
192
/**
@@ -176,78 +206,78 @@ export type EventFor<T extends string, D = {}> = Expand<{type: T} & D>
176
206
* errors) that correspond to a specific operation are namespaced with a colon
177
207
* `:`, e.g. `bind:error` or `connect:retry`.
178
208
*
179
- * * **accept** - ZMQ_EVENT_ACCEPTED The socket has accepted a connection from a
209
+ * - **accept** - ZMQ_EVENT_ACCEPTED The socket has accepted a connection from a
180
210
* remote peer.
181
211
*
182
- * * **accept:error** - ZMQ_EVENT_ACCEPT_FAILED The socket has rejected a
212
+ * - **accept:error** - ZMQ_EVENT_ACCEPT_FAILED The socket has rejected a
183
213
* connection from a remote peer.
184
214
*
185
215
* The following additional details will be included with this event:
186
216
*
187
- * * `error` - An error object that describes the specific error
217
+ * - `error` - An error object that describes the specific error
188
218
* that occurred.
189
219
*
190
- * * **bind** - ZMQ_EVENT_LISTENING The socket was successfully bound to a
220
+ * - **bind** - ZMQ_EVENT_LISTENING The socket was successfully bound to a
191
221
* network interface.
192
222
*
193
- * * **bind:error** - ZMQ_EVENT_BIND_FAILED The socket could not bind to a given
223
+ * - **bind:error** - ZMQ_EVENT_BIND_FAILED The socket could not bind to a given
194
224
* interface.
195
225
*
196
226
* The following additional details will be included with this event:
197
227
*
198
- * * `error` - An error object that describes the specific error
228
+ * - `error` - An error object that describes the specific error
199
229
* that occurred.
200
230
*
201
- * * **connect** - ZMQ_EVENT_CONNECTED The socket has successfully connected to
231
+ * - **connect** - ZMQ_EVENT_CONNECTED The socket has successfully connected to
202
232
* a remote peer.
203
233
*
204
- * * **connect:delay** - ZMQ_EVENT_CONNECT_DELAYED A connect request on the
234
+ * - **connect:delay** - ZMQ_EVENT_CONNECT_DELAYED A connect request on the
205
235
* socket is pending.
206
236
*
207
- * * **connect:retry** - ZMQ_EVENT_CONNECT_RETRIED A connection attempt is being
237
+ * - **connect:retry** - ZMQ_EVENT_CONNECT_RETRIED A connection attempt is being
208
238
* handled by reconnect timer. Note that the reconnect interval is
209
239
* recalculated at each retry.
210
240
*
211
241
* The following additional details will be included with this event:
212
242
*
213
- * * `interval` - The current reconnect interval.
243
+ * - `interval` - The current reconnect interval.
214
244
*
215
- * * **close** - ZMQ_EVENT_CLOSED The socket was closed.
245
+ * - **close** - ZMQ_EVENT_CLOSED The socket was closed.
216
246
*
217
- * * **close:error** - ZMQ_EVENT_CLOSE_FAILED The socket close failed. Note that
247
+ * - **close:error** - ZMQ_EVENT_CLOSE_FAILED The socket close failed. Note that
218
248
* this event occurs **only on IPC** transports..
219
249
*
220
250
* The following additional details will be included with this event:
221
251
*
222
- * * `error` - An error object that describes the specific error
252
+ * - `error` - An error object that describes the specific error
223
253
* that occurred.
224
254
*
225
- * * **disconnect** - ZMQ_EVENT_DISCONNECTED The socket was disconnected
255
+ * - **disconnect** - ZMQ_EVENT_DISCONNECTED The socket was disconnected
226
256
* unexpectedly.
227
257
*
228
- * * **handshake** - ZMQ_EVENT_HANDSHAKE_SUCCEEDED The ZMTP security mechanism
258
+ * - **handshake** - ZMQ_EVENT_HANDSHAKE_SUCCEEDED The ZMTP security mechanism
229
259
* handshake succeeded. NOTE: This event may still be in DRAFT statea and not
230
260
* yet available in stable releases.
231
261
*
232
- * * **handshake:error:protocol** - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL The ZMTP
262
+ * - **handshake:error:protocol** - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL The ZMTP
233
263
* security mechanism handshake failed due to some mechanism protocol error,
234
264
* either between the ZMTP mechanism peers, or between the mechanism server
235
265
* and the ZAP handler. This indicates a configuration or implementation error
236
266
* in either peer resp. the ZAP handler. NOTE: This event may still be in
237
267
* DRAFT state and not yet available in stable releases.
238
268
*
239
- * * **handshake:error:auth** - ZMQ_EVENT_HANDSHAKE_FAILED_AUTH The ZMTP
269
+ * - **handshake:error:auth** - ZMQ_EVENT_HANDSHAKE_FAILED_AUTH The ZMTP
240
270
* security mechanism handshake failed due to an authentication failure. NOTE:
241
271
* This event may still be in DRAFT state and not yet available in stable
242
272
* releases.
243
273
*
244
- * * **handshake:error:other** - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
274
+ * - **handshake:error:other** - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
245
275
* Unspecified error during handshake. NOTE: This event may still be in DRAFT
246
276
* state and not yet available in stable releases.
247
277
*
248
- * * **end** - ZMQ_EVENT_MONITOR_STOPPED Monitoring on this socket ended.
278
+ * - **end** - ZMQ_EVENT_MONITOR_STOPPED Monitoring on this socket ended.
249
279
*
250
- * * **unknown** An event was generated by ZeroMQ that the Node.js library could
280
+ * - **unknown** An event was generated by ZeroMQ that the Node.js library could
251
281
* not interpret. Please submit a pull request for new event types if they are
252
282
* not yet included.
253
283
*/
@@ -321,9 +351,9 @@ export declare class Observer {
321
351
close ( ) : void
322
352
323
353
/**
324
- * Waits for the next event to become availeble on the observer. Reads an
354
+ * Waits for the next event to become available on the observer. Reads an
325
355
* event immediately if possible. If no events are queued, it will wait
326
- * asynchonously . The promise will be resolved with the next event when
356
+ * asynchronously . The promise will be resolved with the next event when
327
357
* available.
328
358
*
329
359
* When reading events with {@link receive}() the observer may **not** be in
@@ -593,7 +623,7 @@ export declare abstract class Socket {
593
623
594
624
/**
595
625
* Disconnects a previously connected socket from the given address and
596
- * returns immediately. Disonnection will happen asynchronously in the
626
+ * returns immediately. Disconnection will happen asynchronously in the
597
627
* background.
598
628
*
599
629
* ```typescript
@@ -656,19 +686,49 @@ export const enum SocketType {
656
686
type IfEquals < X , Y , A , B = never > =
657
687
( < T > ( ) => T extends X ? 1 : 2 ) extends < T > ( ) => T extends Y ? 1 : 2 ? A : B
658
688
659
- /* https://stackoverflow.com/questions/57683303 */
689
+ /**
690
+ * Utility type that expands a type into its keys and values.
691
+ *
692
+ * https://stackoverflow.com/questions/57683303
693
+ * @internal
694
+ */
660
695
export type Expand < T > = T extends infer O ? { [ K in keyof O ] : O [ K ] } : never
661
696
662
697
/** @internal */
663
698
export type ReadableKeys < T > = {
664
699
[ P in keyof T ] -?: T [ P ] extends Function ? never : P
665
700
} [ keyof T ]
666
701
667
- /** @internal */
702
+ /**
703
+ * Get the writable keys of a type.
704
+ * @internal
705
+ */
668
706
export type WritableKeys < T > = {
669
707
[ P in keyof T ] -?: T [ P ] extends Function
670
708
? never
671
709
: IfEquals < { [ Q in P ] : T [ P ] } , { - readonly [ Q in P ] : T [ P ] } , P >
672
710
} [ keyof T ]
673
711
712
+ /**
713
+ * Utility type for defining options for a given type.
714
+ * It allows setting the writable properties of a type.
715
+ *
716
+ * @typeParam T The type to define options for.
717
+ * @typeParam E Additional optional properties. Defaults to an empty object.
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * interface Server {
722
+ * port: number
723
+ * readonly name: string
724
+ * }
725
+ * type ServerOptions = Options<Server, { debug?: boolean }>
726
+ * // is equivalent to:
727
+ * interface ServerOptions {
728
+ * port?: number
729
+ * debug?: boolean
730
+ * }
731
+ * ```
732
+ * @internal
733
+ */
674
734
export type Options < T , E = { } > = Expand < Partial < E & Pick < T , WritableKeys < T > > > >
0 commit comments