@@ -43,11 +43,11 @@ export declare const capability: Partial<{
4343 * To correctly connect two sockets with this mechanism:
4444 *
4545 * * 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
4747 * {@link Socket.curveSecretKey} and {@link Socket.curvePublicKey}.
4848 * * 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
5151 * {@link Socket.curveServerKey}. The server does *not* need to know its own
5252 * public key. Key distribution is *not* handled by the CURVE security
5353 * mechanism.
@@ -112,15 +112,24 @@ export declare class Context {
112112 */
113113export declare const context : Context
114114
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 {
116119 code : string
117120 errno : number
118121}
119122
123+ /**
124+ * An event that represents an authorization error.
125+ */
120126export interface AuthError extends Error {
121127 status : 300 | 400 | 500
122128}
123129
130+ /**
131+ * An event that represents a protocol error.
132+ */
124133export interface ProtoError extends Error {
125134 code :
126135 | "ERR_ZMTP_UNSPECIFIED"
@@ -145,18 +154,39 @@ export interface ProtoError extends Error {
145154 | "ERR_ZAP_INVALID_METADATA"
146155}
147156
157+ /**
158+ * An object that contains the address of an event.
159+ */
148160export interface EventAddress {
149161 address : string
150162}
151163
164+ /**
165+ * An object that contains the interval for an event.
166+ */
152167export interface EventInterval {
153168 interval : number
154169}
155170
171+ /**
172+ * An object that contains an error for an event.
173+ */
156174export interface EventError < E = ErrnoError > {
157175 error : E
158176}
159177
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+ */
160190export type EventFor < T extends string , D = { } > = Expand < { type : T } & D >
161191
162192/**
@@ -176,78 +206,78 @@ export type EventFor<T extends string, D = {}> = Expand<{type: T} & D>
176206 * errors) that correspond to a specific operation are namespaced with a colon
177207 * `:`, e.g. `bind:error` or `connect:retry`.
178208 *
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
180210 * remote peer.
181211 *
182- * * **accept:error** - ZMQ_EVENT_ACCEPT_FAILED The socket has rejected a
212+ * - **accept:error** - ZMQ_EVENT_ACCEPT_FAILED The socket has rejected a
183213 * connection from a remote peer.
184214 *
185215 * The following additional details will be included with this event:
186216 *
187- * * `error` - An error object that describes the specific error
217+ * - `error` - An error object that describes the specific error
188218 * that occurred.
189219 *
190- * * **bind** - ZMQ_EVENT_LISTENING The socket was successfully bound to a
220+ * - **bind** - ZMQ_EVENT_LISTENING The socket was successfully bound to a
191221 * network interface.
192222 *
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
194224 * interface.
195225 *
196226 * The following additional details will be included with this event:
197227 *
198- * * `error` - An error object that describes the specific error
228+ * - `error` - An error object that describes the specific error
199229 * that occurred.
200230 *
201- * * **connect** - ZMQ_EVENT_CONNECTED The socket has successfully connected to
231+ * - **connect** - ZMQ_EVENT_CONNECTED The socket has successfully connected to
202232 * a remote peer.
203233 *
204- * * **connect:delay** - ZMQ_EVENT_CONNECT_DELAYED A connect request on the
234+ * - **connect:delay** - ZMQ_EVENT_CONNECT_DELAYED A connect request on the
205235 * socket is pending.
206236 *
207- * * **connect:retry** - ZMQ_EVENT_CONNECT_RETRIED A connection attempt is being
237+ * - **connect:retry** - ZMQ_EVENT_CONNECT_RETRIED A connection attempt is being
208238 * handled by reconnect timer. Note that the reconnect interval is
209239 * recalculated at each retry.
210240 *
211241 * The following additional details will be included with this event:
212242 *
213- * * `interval` - The current reconnect interval.
243+ * - `interval` - The current reconnect interval.
214244 *
215- * * **close** - ZMQ_EVENT_CLOSED The socket was closed.
245+ * - **close** - ZMQ_EVENT_CLOSED The socket was closed.
216246 *
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
218248 * this event occurs **only on IPC** transports..
219249 *
220250 * The following additional details will be included with this event:
221251 *
222- * * `error` - An error object that describes the specific error
252+ * - `error` - An error object that describes the specific error
223253 * that occurred.
224254 *
225- * * **disconnect** - ZMQ_EVENT_DISCONNECTED The socket was disconnected
255+ * - **disconnect** - ZMQ_EVENT_DISCONNECTED The socket was disconnected
226256 * unexpectedly.
227257 *
228- * * **handshake** - ZMQ_EVENT_HANDSHAKE_SUCCEEDED The ZMTP security mechanism
258+ * - **handshake** - ZMQ_EVENT_HANDSHAKE_SUCCEEDED The ZMTP security mechanism
229259 * handshake succeeded. NOTE: This event may still be in DRAFT statea and not
230260 * yet available in stable releases.
231261 *
232- * * **handshake:error:protocol** - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL The ZMTP
262+ * - **handshake:error:protocol** - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL The ZMTP
233263 * security mechanism handshake failed due to some mechanism protocol error,
234264 * either between the ZMTP mechanism peers, or between the mechanism server
235265 * and the ZAP handler. This indicates a configuration or implementation error
236266 * in either peer resp. the ZAP handler. NOTE: This event may still be in
237267 * DRAFT state and not yet available in stable releases.
238268 *
239- * * **handshake:error:auth** - ZMQ_EVENT_HANDSHAKE_FAILED_AUTH The ZMTP
269+ * - **handshake:error:auth** - ZMQ_EVENT_HANDSHAKE_FAILED_AUTH The ZMTP
240270 * security mechanism handshake failed due to an authentication failure. NOTE:
241271 * This event may still be in DRAFT state and not yet available in stable
242272 * releases.
243273 *
244- * * **handshake:error:other** - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
274+ * - **handshake:error:other** - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
245275 * Unspecified error during handshake. NOTE: This event may still be in DRAFT
246276 * state and not yet available in stable releases.
247277 *
248- * * **end** - ZMQ_EVENT_MONITOR_STOPPED Monitoring on this socket ended.
278+ * - **end** - ZMQ_EVENT_MONITOR_STOPPED Monitoring on this socket ended.
249279 *
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
251281 * not interpret. Please submit a pull request for new event types if they are
252282 * not yet included.
253283 */
@@ -321,9 +351,9 @@ export declare class Observer {
321351 close ( ) : void
322352
323353 /**
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
325355 * 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
327357 * available.
328358 *
329359 * When reading events with {@link receive}() the observer may **not** be in
@@ -593,7 +623,7 @@ export declare abstract class Socket {
593623
594624 /**
595625 * 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
597627 * background.
598628 *
599629 * ```typescript
@@ -656,19 +686,49 @@ export const enum SocketType {
656686type IfEquals < X , Y , A , B = never > =
657687 ( < T > ( ) => T extends X ? 1 : 2 ) extends < T > ( ) => T extends Y ? 1 : 2 ? A : B
658688
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+ */
660695export type Expand < T > = T extends infer O ? { [ K in keyof O ] : O [ K ] } : never
661696
662697/** @internal */
663698export type ReadableKeys < T > = {
664699 [ P in keyof T ] -?: T [ P ] extends Function ? never : P
665700} [ keyof T ]
666701
667- /** @internal */
702+ /**
703+ * Get the writable keys of a type.
704+ * @internal
705+ */
668706export type WritableKeys < T > = {
669707 [ P in keyof T ] -?: T [ P ] extends Function
670708 ? never
671709 : IfEquals < { [ Q in P ] : T [ P ] } , { - readonly [ Q in P ] : T [ P ] } , P >
672710} [ keyof T ]
673711
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+ */
674734export type Options < T , E = { } > = Expand < Partial < E & Pick < T , WritableKeys < T > > > >
0 commit comments