snapreq 0.0.1 → 0.0.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.
@@ -0,0 +1,233 @@
1
+ /**
2
+ * @typedef {import("./request.js").CompressionEncoding} CompressionEncoding
3
+ */
4
+ /**
5
+ * @typedef {object} NormalizedRequest
6
+ * @property {string} method - Upper-cased HTTP method.
7
+ * @property {string} url - Fully resolved request URL.
8
+ * @property {SnapReqHeaders} headers - Request headers.
9
+ * @property {import("./request.js").NormalizedBody} body - Normalized request body.
10
+ * @property {CompressionEncoding} bodyCompression - Request body compression.
11
+ * @property {AbortSignal} [signal] - Abort signal.
12
+ * @property {string} [credentials] - Fetch credentials mode ("omit" | "same-origin" | "include").
13
+ */
14
+ /**
15
+ * @typedef {object} RequestOptions
16
+ * @property {string} [method] - HTTP method. Defaults to GET.
17
+ * @property {string} [path] - Request path (joined with the client `baseUrl`) or absolute URL.
18
+ * @property {string} [url] - Alias for `path`.
19
+ * @property {Record<string, string | number | boolean | null | undefined>} [query] - Query parameters.
20
+ * @property {Record<string, string | number> | SnapReqHeaders} [headers] - Per-request headers.
21
+ * @property {any} [body] - Request body: string, object (JSON), Uint8Array/ArrayBuffer, or a stream/async-iterable.
22
+ * @property {CompressionEncoding} [bodyCompression] - Compress the request body (Node transport only).
23
+ * @property {AbortSignal} [signal] - Abort signal for the request.
24
+ * @property {string} [credentials] - Fetch credentials mode.
25
+ * @property {boolean | import("./retry.js").RetryOptions} [retry] - Retry transient failures.
26
+ * @property {boolean} [throwOnError] - Throw `SnapReqHttpError` on non-2xx responses.
27
+ */
28
+ /**
29
+ * A cross-platform HTTP client with one API across Node, web, Expo and React
30
+ * Native. The right transport is chosen at runtime; features a platform cannot
31
+ * provide raise `SnapReqUnsupportedFeatureError` rather than silently changing
32
+ * behaviour.
33
+ */
34
+ export default class SnapReq {
35
+ /**
36
+ * @param {object} [config] - Client configuration.
37
+ * @param {string} [config.baseUrl] - Origin (and optional base path) prepended to relative paths.
38
+ * @param {string} [config.socketPath] - Unix domain socket path (Node transport only).
39
+ * @param {{ca?: string | Buffer, cert?: string | Buffer, key?: string | Buffer, rejectUnauthorized?: boolean}} [config.tls] - TLS material (Node transport only).
40
+ * @param {boolean} [config.keepAlive] - Reuse connections across requests (Node transport only). Defaults to true.
41
+ * @param {Record<string, string | number> | (() => Record<string, string | number>)} [config.headers] - Default headers (object or factory).
42
+ * @param {boolean | import("./retry.js").RetryOptions} [config.retry] - Default retry policy.
43
+ * @param {boolean} [config.throwOnError] - Throw `SnapReqHttpError` on non-2xx responses by default. Defaults to false.
44
+ * @param {string} [config.credentials] - Default fetch credentials mode.
45
+ * @param {import("./transports/select.js").TransportName | import("./transports/select.js").Transport} [config.transport] - Transport preference or instance. Defaults to "auto".
46
+ */
47
+ constructor({ baseUrl, socketPath, tls, keepAlive, headers, retry, throwOnError, credentials, transport }?: {
48
+ baseUrl?: string;
49
+ socketPath?: string;
50
+ tls?: {
51
+ ca?: string | Buffer;
52
+ cert?: string | Buffer;
53
+ key?: string | Buffer;
54
+ rejectUnauthorized?: boolean;
55
+ };
56
+ keepAlive?: boolean;
57
+ headers?: Record<string, string | number> | (() => Record<string, string | number>);
58
+ retry?: boolean | import("./retry.js").RetryOptions;
59
+ throwOnError?: boolean;
60
+ credentials?: string;
61
+ transport?: import("./transports/select.js").TransportName | import("./transports/select.js").Transport;
62
+ });
63
+ baseUrl: string;
64
+ defaultHeaders: Record<string, string | number> | (() => Record<string, string | number>);
65
+ defaultRetry: boolean | import("./retry.js").RetryOptions;
66
+ throwOnError: boolean;
67
+ credentials: string;
68
+ _transportPreference: import("./transports/select.js").TransportName | import("./transports/select.js").Transport;
69
+ _nodeConfig: {
70
+ socketPath: string;
71
+ tls: {
72
+ ca?: string | Buffer;
73
+ cert?: string | Buffer;
74
+ key?: string | Buffer;
75
+ rejectUnauthorized?: boolean;
76
+ };
77
+ keepAlive: boolean;
78
+ };
79
+ /** @type {Promise<import("./transports/select.js").Transport> | null} */
80
+ _transportPromise: Promise<import("./transports/select.js").Transport> | null;
81
+ /** @type {import("./transports/select.js").Transport | null} */
82
+ _transport: import("./transports/select.js").Transport | null;
83
+ /** @returns {Promise<import("./transports/select.js").Transport>} - The resolved transport. */
84
+ _resolveTransport(): Promise<import("./transports/select.js").Transport>;
85
+ /** @returns {Promise<import("./capabilities.js").TransportCapabilities>} - The active transport's capabilities. */
86
+ capabilities(): Promise<import("./capabilities.js").TransportCapabilities>;
87
+ /** @returns {Promise<string>} - The active transport's name. */
88
+ transportName(): Promise<string>;
89
+ /**
90
+ * @param {RequestOptions} options - Request options.
91
+ * @returns {NormalizedRequest} - The normalized request.
92
+ */
93
+ _normalize(options: RequestOptions): NormalizedRequest;
94
+ /**
95
+ * Performs a request and buffers nothing eagerly — read the body via the
96
+ * returned response (`json()`, `text()`, `bytes()`). Retries transient
97
+ * failures when a retry policy is configured (never for streamed bodies).
98
+ * @param {RequestOptions} options - Request options.
99
+ * @returns {Promise<import("./response.js").default>} - The response.
100
+ */
101
+ request(options: RequestOptions): Promise<import("./response.js").default>;
102
+ /**
103
+ * Performs a request and returns the response with its body available as a
104
+ * stream (`response.stream()`). Requires a transport that supports response
105
+ * streaming; never retries.
106
+ * @param {RequestOptions} options - Request options.
107
+ * @returns {Promise<import("./response.js").default>} - The streaming response.
108
+ */
109
+ requestStream(options: RequestOptions): Promise<import("./response.js").default>;
110
+ /**
111
+ * @param {string} path - Request path or absolute URL.
112
+ * @param {RequestOptions} [options] - Request options.
113
+ * @returns {Promise<import("./response.js").default>} - The response.
114
+ */
115
+ get(path: string, options?: RequestOptions): Promise<import("./response.js").default>;
116
+ /**
117
+ * @param {string} path - Request path or absolute URL.
118
+ * @param {any} [body] - Request body.
119
+ * @param {RequestOptions} [options] - Request options.
120
+ * @returns {Promise<import("./response.js").default>} - The response.
121
+ */
122
+ post(path: string, body?: any, options?: RequestOptions): Promise<import("./response.js").default>;
123
+ /**
124
+ * @param {string} path - Request path or absolute URL.
125
+ * @param {any} [body] - Request body.
126
+ * @param {RequestOptions} [options] - Request options.
127
+ * @returns {Promise<import("./response.js").default>} - The response.
128
+ */
129
+ put(path: string, body?: any, options?: RequestOptions): Promise<import("./response.js").default>;
130
+ /**
131
+ * @param {string} path - Request path or absolute URL.
132
+ * @param {any} [body] - Request body.
133
+ * @param {RequestOptions} [options] - Request options.
134
+ * @returns {Promise<import("./response.js").default>} - The response.
135
+ */
136
+ patch(path: string, body?: any, options?: RequestOptions): Promise<import("./response.js").default>;
137
+ /**
138
+ * @param {string} path - Request path or absolute URL.
139
+ * @param {RequestOptions} [options] - Request options.
140
+ * @returns {Promise<import("./response.js").default>} - The response.
141
+ */
142
+ delete(path: string, options?: RequestOptions): Promise<import("./response.js").default>;
143
+ /**
144
+ * @param {import("./response.js").default} response - The failed response.
145
+ * @param {NormalizedRequest} request - The request that produced it.
146
+ * @returns {Promise<SnapReqHttpError>} - An error describing the failure.
147
+ */
148
+ _httpError(response: import("./response.js").default, request: NormalizedRequest): Promise<SnapReqHttpError>;
149
+ /**
150
+ * Releases transport resources (for example Node keep-alive sockets).
151
+ * @returns {void}
152
+ */
153
+ close(): void;
154
+ }
155
+ export type CompressionEncoding = import("./request.js").CompressionEncoding;
156
+ export type NormalizedRequest = {
157
+ /**
158
+ * - Upper-cased HTTP method.
159
+ */
160
+ method: string;
161
+ /**
162
+ * - Fully resolved request URL.
163
+ */
164
+ url: string;
165
+ /**
166
+ * - Request headers.
167
+ */
168
+ headers: SnapReqHeaders;
169
+ /**
170
+ * - Normalized request body.
171
+ */
172
+ body: import("./request.js").NormalizedBody;
173
+ /**
174
+ * - Request body compression.
175
+ */
176
+ bodyCompression: CompressionEncoding;
177
+ /**
178
+ * - Abort signal.
179
+ */
180
+ signal?: AbortSignal;
181
+ /**
182
+ * - Fetch credentials mode ("omit" | "same-origin" | "include").
183
+ */
184
+ credentials?: string;
185
+ };
186
+ export type RequestOptions = {
187
+ /**
188
+ * - HTTP method. Defaults to GET.
189
+ */
190
+ method?: string;
191
+ /**
192
+ * - Request path (joined with the client `baseUrl`) or absolute URL.
193
+ */
194
+ path?: string;
195
+ /**
196
+ * - Alias for `path`.
197
+ */
198
+ url?: string;
199
+ /**
200
+ * - Query parameters.
201
+ */
202
+ query?: Record<string, string | number | boolean | null | undefined>;
203
+ /**
204
+ * - Per-request headers.
205
+ */
206
+ headers?: Record<string, string | number> | SnapReqHeaders;
207
+ /**
208
+ * - Request body: string, object (JSON), Uint8Array/ArrayBuffer, or a stream/async-iterable.
209
+ */
210
+ body?: any;
211
+ /**
212
+ * - Compress the request body (Node transport only).
213
+ */
214
+ bodyCompression?: CompressionEncoding;
215
+ /**
216
+ * - Abort signal for the request.
217
+ */
218
+ signal?: AbortSignal;
219
+ /**
220
+ * - Fetch credentials mode.
221
+ */
222
+ credentials?: string;
223
+ /**
224
+ * - Retry transient failures.
225
+ */
226
+ retry?: boolean | import("./retry.js").RetryOptions;
227
+ /**
228
+ * - Throw `SnapReqHttpError` on non-2xx responses.
229
+ */
230
+ throwOnError?: boolean;
231
+ };
232
+ import { SnapReqHttpError } from "./errors.js";
233
+ import SnapReqHeaders from "./headers.js";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Transport backed by the `fetch` global. Works on web, Expo / React Native and
3
+ * Node 18+. It cannot open Unix sockets, present client certificates or
4
+ * compress request bodies — those raise `SnapReqUnsupportedFeatureError`.
5
+ * Response streaming uses `response.body` where available and otherwise buffers
6
+ * the body once, keeping the same stream interface everywhere.
7
+ */
8
+ export default class FetchTransport {
9
+ /** @returns {string} - Transport name. */
10
+ static get transportName(): string;
11
+ /** @returns {boolean} - Whether this transport can run in the current environment. */
12
+ static isAvailable(): boolean;
13
+ /** @returns {import("../capabilities.js").TransportCapabilities} - Supported capabilities. */
14
+ get capabilities(): import("../capabilities.js").TransportCapabilities;
15
+ /**
16
+ * @param {import("../snap-req.js").NormalizedRequest} request - Normalized request.
17
+ * @returns {Promise<SnapReqResponse>} - The response.
18
+ */
19
+ performRequest(request: import("../snap-req.js").NormalizedRequest): Promise<SnapReqResponse>;
20
+ /**
21
+ * @param {Response} response - The fetch response.
22
+ * @returns {SnapReqHeaders} - The response headers.
23
+ */
24
+ _responseHeaders(response: Response): SnapReqHeaders;
25
+ /**
26
+ * Builds an async iterable of byte chunks over a fetch response. Uses the
27
+ * `ReadableStream` body for true streaming when present and otherwise buffers
28
+ * the whole body once so the stream interface stays identical everywhere.
29
+ * @param {Response} response - The fetch response.
30
+ * @returns {AsyncIterable<Uint8Array>} - The response body stream.
31
+ */
32
+ _responseStream(response: Response): AsyncIterable<Uint8Array>;
33
+ }
34
+ import SnapReqResponse from "../response.js";
35
+ import SnapReqHeaders from "../headers.js";
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Full-featured transport backed by Node's `http`/`https` modules. Supports
3
+ * Unix sockets, client TLS, keep-alive, request-body compression, response
4
+ * decompression and streaming. The `node:*` modules are loaded with a dynamic
5
+ * `import()` so this file never has to be bundled by web/Expo bundlers — the
6
+ * transport selector only imports it when running on Node.
7
+ */
8
+ export default class NodeTransport {
9
+ /** @returns {string} - Transport name. */
10
+ static get transportName(): string;
11
+ /** @returns {boolean} - Whether this transport can run in the current environment. */
12
+ static isAvailable(): boolean;
13
+ /**
14
+ * @param {object} [config] - Transport configuration.
15
+ * @param {string} [config.socketPath] - Unix domain socket path.
16
+ * @param {{ca?: string | Buffer, cert?: string | Buffer, key?: string | Buffer, rejectUnauthorized?: boolean}} [config.tls] - TLS material for HTTPS connections.
17
+ * @param {boolean} [config.keepAlive] - Reuse connections across requests. Defaults to true.
18
+ */
19
+ constructor({ socketPath, tls, keepAlive }?: {
20
+ socketPath?: string;
21
+ tls?: {
22
+ ca?: string | Buffer;
23
+ cert?: string | Buffer;
24
+ key?: string | Buffer;
25
+ rejectUnauthorized?: boolean;
26
+ };
27
+ keepAlive?: boolean;
28
+ });
29
+ socketPath: string;
30
+ tls: {
31
+ ca?: string | Buffer;
32
+ cert?: string | Buffer;
33
+ key?: string | Buffer;
34
+ rejectUnauthorized?: boolean;
35
+ };
36
+ keepAlive: boolean;
37
+ /** @type {{http: any, https: any, zlib: any, stream: any} | null} */
38
+ _modules: {
39
+ http: any;
40
+ https: any;
41
+ zlib: any;
42
+ stream: any;
43
+ } | null;
44
+ /** @type {any} */
45
+ _httpAgent: any;
46
+ /** @type {any} */
47
+ _httpsAgent: any;
48
+ /** @returns {import("../capabilities.js").TransportCapabilities} - Supported capabilities. */
49
+ get capabilities(): import("../capabilities.js").TransportCapabilities;
50
+ /** @returns {Promise<{http: any, https: any, zlib: any, stream: any}>} - Lazily-loaded Node modules. */
51
+ _load(): Promise<{
52
+ http: any;
53
+ https: any;
54
+ zlib: any;
55
+ stream: any;
56
+ }>;
57
+ /**
58
+ * @param {boolean} useTls - Whether the request uses TLS.
59
+ * @returns {any} - The keep-alive agent for the protocol.
60
+ */
61
+ _agent(useTls: boolean): any;
62
+ /**
63
+ * Performs a single request and resolves once the response headers arrive,
64
+ * exposing the (decoded) body as a stream so callers can buffer or stream it.
65
+ * @param {import("../snap-req.js").NormalizedRequest} request - Normalized request.
66
+ * @returns {Promise<SnapReqResponse>} - The response.
67
+ */
68
+ performRequest(request: import("../snap-req.js").NormalizedRequest): Promise<SnapReqResponse>;
69
+ /**
70
+ * @param {import("../snap-req.js").NormalizedRequest} request - Normalized request.
71
+ * @param {SnapReqHeaders} headers - Headers, mutated with Content-Length / Content-Encoding.
72
+ * @param {{zlib: any, stream: any}} modules - Node modules.
73
+ * @returns {{buffer: Buffer | null, stream: import("node:stream").Readable | null}} - Prepared body.
74
+ */
75
+ _prepareRequestBody(request: import("../snap-req.js").NormalizedRequest, headers: SnapReqHeaders, { zlib, stream }: {
76
+ zlib: any;
77
+ stream: any;
78
+ }): {
79
+ buffer: Buffer | null;
80
+ stream: import("node:stream").Readable | null;
81
+ };
82
+ /**
83
+ * @param {string} encoding - Compression encoding.
84
+ * @param {any} zlib - The zlib module.
85
+ * @returns {import("node:stream").Transform} - A compressor transform.
86
+ */
87
+ _requestCompressor(encoding: string, zlib: any): import("node:stream").Transform;
88
+ /**
89
+ * @param {import("node:http").IncomingMessage} response - The raw response.
90
+ * @param {any} zlib - The zlib module.
91
+ * @returns {import("node:stream").Readable} - The decoded response body stream.
92
+ */
93
+ _decodeResponseStream(response: import("node:http").IncomingMessage, zlib: any): import("node:stream").Readable;
94
+ /**
95
+ * @param {string} encoding - Content encoding.
96
+ * @param {any} zlib - The zlib module.
97
+ * @returns {import("node:stream").Transform} - A decompressor transform.
98
+ */
99
+ _responseDecoder(encoding: string, zlib: any): import("node:stream").Transform;
100
+ /**
101
+ * @param {import("node:http").IncomingMessage} response - The raw response.
102
+ * @returns {SnapReqHeaders} - The response headers.
103
+ */
104
+ _responseHeaders(response: import("node:http").IncomingMessage): SnapReqHeaders;
105
+ /**
106
+ * Destroys the keep-alive agents, closing all persistent connections.
107
+ * @returns {void}
108
+ */
109
+ close(): void;
110
+ }
111
+ import SnapReqResponse from "../response.js";
112
+ import SnapReqHeaders from "../headers.js";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @typedef {"auto" | "node" | "fetch" | "xhr"} TransportName
3
+ */
4
+ /**
5
+ * @typedef {object} Transport
6
+ * @property {import("../capabilities.js").TransportCapabilities} capabilities - Supported capabilities.
7
+ * @property {(request: import("../snap-req.js").NormalizedRequest) => Promise<import("../response.js").default>} performRequest - Perform a request.
8
+ * @property {() => void} [close] - Optional resource cleanup.
9
+ */
10
+ /**
11
+ * Detects the JavaScript runtime so `auto` can pick the right transport.
12
+ * @returns {"node" | "react-native" | "browser" | "unknown"} - Detected runtime.
13
+ */
14
+ export function detectRuntime(): "node" | "react-native" | "browser" | "unknown";
15
+ /**
16
+ * Resolves a transport for the requested preference. Returns the preference
17
+ * untouched when it is already a transport instance. The Node transport is
18
+ * imported dynamically so web/Expo bundlers never pull in `node:*` modules.
19
+ * @param {TransportName | Transport | undefined} preference - Requested transport.
20
+ * @param {object} nodeConfig - Configuration forwarded to the Node transport.
21
+ * @returns {Promise<Transport>} - The resolved transport.
22
+ */
23
+ export function selectTransport(preference: TransportName | Transport | undefined, nodeConfig: object): Promise<Transport>;
24
+ export type TransportName = "auto" | "node" | "fetch" | "xhr";
25
+ export type Transport = {
26
+ /**
27
+ * - Supported capabilities.
28
+ */
29
+ capabilities: import("../capabilities.js").TransportCapabilities;
30
+ /**
31
+ * - Perform a request.
32
+ */
33
+ performRequest: (request: import("../snap-req.js").NormalizedRequest) => Promise<import("../response.js").default>;
34
+ /**
35
+ * - Optional resource cleanup.
36
+ */
37
+ close?: () => void;
38
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Transport backed by `XMLHttpRequest`. A fallback for web environments that
3
+ * lack `fetch`. Buffers the whole response (no incremental streaming) and, like
4
+ * `fetch`, cannot do Unix sockets, client TLS or request-body compression.
5
+ */
6
+ export default class XhrTransport {
7
+ /** @returns {string} - Transport name. */
8
+ static get transportName(): string;
9
+ /** @returns {boolean} - Whether this transport can run in the current environment. */
10
+ static isAvailable(): boolean;
11
+ /** @returns {import("../capabilities.js").TransportCapabilities} - Supported capabilities. */
12
+ get capabilities(): import("../capabilities.js").TransportCapabilities;
13
+ /**
14
+ * @param {import("../snap-req.js").NormalizedRequest} request - Normalized request.
15
+ * @returns {Promise<SnapReqResponse>} - The response.
16
+ */
17
+ performRequest(request: import("../snap-req.js").NormalizedRequest): Promise<SnapReqResponse>;
18
+ /**
19
+ * @param {string} rawHeaders - Raw header block from `getAllResponseHeaders`.
20
+ * @returns {SnapReqHeaders} - The parsed response headers.
21
+ */
22
+ _parseHeaders(rawHeaders: string): SnapReqHeaders;
23
+ }
24
+ import SnapReqResponse from "../response.js";
25
+ import SnapReqHeaders from "../headers.js";
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Client-side handle for a channel subscription opened via
3
+ * `SnapReqWebSocketClient.subscribeChannel()`. Mirrors the server's
4
+ * subscription lifecycle — `subscribed` (resolves `ready`) / `onMessage` /
5
+ * `onClose`.
6
+ */
7
+ export default class SnapReqWebSocketChannel {
8
+ /**
9
+ * @param {object} args - Channel arguments.
10
+ * @param {import("./websocket-client.js").default} args.client - Owning client.
11
+ * @param {string} args.subscriptionId - Generated id unique within the session.
12
+ * @param {string} args.channelType - Name the server registered the channel under.
13
+ * @param {Record<string, any>} [args.params] - Opaque params forwarded to the server.
14
+ * @param {string} [args.lastEventId] - Resume replay from this event id.
15
+ * @param {(body: any) => void} [args.onMessage] - Fired on each `channel-message` from the server.
16
+ * @param {() => void} [args.onDisconnect] - Fired when the socket drops.
17
+ * @param {() => void} [args.onResume] - Fired when the session resumes after a drop.
18
+ * @param {(reason: string) => void} [args.onClose] - Fired exactly once when the subscription closes permanently.
19
+ */
20
+ constructor({ client, subscriptionId, channelType, params, lastEventId, onMessage, onDisconnect, onResume, onClose }: {
21
+ client: import("./websocket-client.js").default;
22
+ subscriptionId: string;
23
+ channelType: string;
24
+ params?: Record<string, any>;
25
+ lastEventId?: string;
26
+ onMessage?: (body: any) => void;
27
+ onDisconnect?: () => void;
28
+ onResume?: () => void;
29
+ onClose?: (reason: string) => void;
30
+ });
31
+ client: import("./websocket-client.js").default;
32
+ subscriptionId: string;
33
+ channelType: string;
34
+ params: Record<string, any>;
35
+ lastEventId: string;
36
+ _onMessage: (body: any) => void;
37
+ _onDisconnect: () => void;
38
+ _onResume: () => void;
39
+ _onClose: (reason: string) => void;
40
+ _ready: boolean;
41
+ _resumeReadyOnResume: boolean;
42
+ _subscribed: boolean;
43
+ _subscribeSent: boolean;
44
+ _closed: boolean;
45
+ /** @returns {Promise<void>} - Resolves once the subscription is acknowledged. */
46
+ _ensureReadyPromise(): Promise<void>;
47
+ /** @type {Promise<void>} */
48
+ _readyPromise: Promise<void>;
49
+ _resolveReady: (value: void | PromiseLike<void>) => void;
50
+ _rejectReady: (reason?: any) => void;
51
+ /** @returns {Promise<void>} - Resolves once the subscription is acknowledged. */
52
+ get ready(): Promise<void>;
53
+ /** @returns {void} */
54
+ _resolveReadyState(): void;
55
+ /** @returns {void} */
56
+ _markNotReady(): void;
57
+ /** @returns {void} */
58
+ _handleSubscribed(): void;
59
+ /** @returns {void} */
60
+ _markSubscribeSent(): void;
61
+ /** @returns {boolean} - Whether the subscription still needs to be sent. */
62
+ _needsSubscribe(): boolean;
63
+ /**
64
+ * @param {any} body - Message payload.
65
+ * @returns {void}
66
+ */
67
+ _handleMessage(body: any): void;
68
+ /** @returns {void} */
69
+ _handleDisconnected(): void;
70
+ /** @returns {void} */
71
+ _handleResumed(): void;
72
+ /**
73
+ * @param {string} reason - Why the subscription closed.
74
+ * @returns {void}
75
+ */
76
+ _handleClosed(reason: string): void;
77
+ /**
78
+ * @param {{timeoutMs?: number}} [params] - Options.
79
+ * @returns {Promise<void>} - Resolves once ready or rejects on timeout.
80
+ */
81
+ waitForReady({ timeoutMs }?: {
82
+ timeoutMs?: number;
83
+ }): Promise<void>;
84
+ /** @returns {void} */
85
+ close(): void;
86
+ /** @returns {boolean} - Whether the subscription is closed. */
87
+ isClosed(): boolean;
88
+ /** @returns {boolean} - Whether the subscription is acknowledged and ready. */
89
+ isReady(): boolean;
90
+ /** @returns {boolean} - Whether the subscription is active. */
91
+ isSubscribed(): boolean;
92
+ }