@arttecs/murmur 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +318 -2
- package/dist/channel.d.ts +22 -0
- package/dist/chunk-QZPDZV62.js +1086 -0
- package/dist/client.d.ts +206 -0
- package/dist/echo.d.ts +119 -0
- package/dist/echo.js +346 -0
- package/dist/envelope.d.ts +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/invoke-listener.d.ts +2 -0
- package/dist/stream.d.ts +34 -0
- package/dist/transport.d.ts +84 -0
- package/package.json +56 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { Channel } from './channel.js';
|
|
2
|
+
export { Murmur, type Authorizer, type AuthorizationToken, type AuthOptions, type MurmurOptions, type MurmurStats } from './client.js';
|
|
3
|
+
export type { MurmurStream, StreamOptions } from './stream.js';
|
|
4
|
+
export type { RetryOptions } from './transport.js';
|
package/dist/index.js
ADDED
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Transport, type RetryOptions } from './transport.js';
|
|
2
|
+
/** Overrides the client's retry settings for one stream. */
|
|
3
|
+
export interface StreamOptions extends Partial<RetryOptions> {
|
|
4
|
+
/** The limit on consecutive attempts without attachment or replay progress. */
|
|
5
|
+
maxFailures?: number;
|
|
6
|
+
}
|
|
7
|
+
/** Consumes an independent Murmur stream from a server-issued URL. */
|
|
8
|
+
export declare class MurmurStream {
|
|
9
|
+
protected readonly url: string;
|
|
10
|
+
/** The transport that opens and retries the subscription. */
|
|
11
|
+
protected readonly transport: Transport;
|
|
12
|
+
/** The callbacks registered for data and control events. */
|
|
13
|
+
protected readonly listeners: Map<string, Set<(data?: unknown) => void>>;
|
|
14
|
+
/** Whether the stream has stopped permanently. */
|
|
15
|
+
protected closed: boolean;
|
|
16
|
+
/** Releases the owning client's reference to this stream. */
|
|
17
|
+
protected onClose?: (stream: MurmurStream) => void;
|
|
18
|
+
/** Returns the current replay cursor, including after the stream expires. */
|
|
19
|
+
get lastEventId(): string | undefined;
|
|
20
|
+
/** Registers a callback for a literal stream event. */
|
|
21
|
+
on(event: string, callback: (data: unknown) => void): this;
|
|
22
|
+
/** Registers a callback for a stream control event. */
|
|
23
|
+
on(event: 'end' | 'gap' | 'expired', callback: () => void): this;
|
|
24
|
+
/** Stops the subscription, cancels retries, and releases its callbacks. */
|
|
25
|
+
close(): void;
|
|
26
|
+
/** Keeps the supplied URL until an event ID is received, then changes only the replay cursor. */
|
|
27
|
+
protected connectionUrl(lastEventId: string | undefined): string;
|
|
28
|
+
/** Delivers control events or unwrapped data. */
|
|
29
|
+
protected receive(event: string, data: string): void;
|
|
30
|
+
/** Delivers a data payload or gap notification to its listeners. */
|
|
31
|
+
protected emit(event: string, ...args: [data?: unknown]): void;
|
|
32
|
+
/** Closes the connection before notifying listeners of terminal events. */
|
|
33
|
+
protected finish(event: 'end' | 'expired'): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** The current source and the listeners registered on it. */
|
|
2
|
+
type Connection = {
|
|
3
|
+
/** The active event source. */
|
|
4
|
+
source: EventSource;
|
|
5
|
+
/** Whether the source has opened. */
|
|
6
|
+
opened: boolean;
|
|
7
|
+
/** Whether the server has acknowledged attachment. */
|
|
8
|
+
attached: boolean;
|
|
9
|
+
/** Whether an event advanced the cursor before attachment. */
|
|
10
|
+
replayed: boolean;
|
|
11
|
+
/** Handles a successful connection. */
|
|
12
|
+
open: (event: Event) => void;
|
|
13
|
+
/** Handles a failed connection. */
|
|
14
|
+
error: (event: Event) => void;
|
|
15
|
+
/** Handles a named stream message. */
|
|
16
|
+
message: (event: Event) => void;
|
|
17
|
+
};
|
|
18
|
+
/** Configures the delay between connection attempts. */
|
|
19
|
+
export interface RetryOptions {
|
|
20
|
+
/** The base delay before the first retry, in milliseconds. */
|
|
21
|
+
retryMs: number;
|
|
22
|
+
/** The maximum base delay before jitter, in milliseconds. */
|
|
23
|
+
maxRetryMs: number;
|
|
24
|
+
/** The maximum fraction of the base delay added as jitter on each retry. */
|
|
25
|
+
retryJitter: number;
|
|
26
|
+
}
|
|
27
|
+
/** Rejects invalid values or combinations of retry options. */
|
|
28
|
+
export declare function validateRetryOptions({ retryMs, maxRetryMs, retryJitter }: RetryOptions): void;
|
|
29
|
+
/** Carries a minimum delay requested by the endpoint for a failed attempt. */
|
|
30
|
+
export declare class RetryAfterError extends Error {
|
|
31
|
+
readonly delayMs: number;
|
|
32
|
+
/** Records the retry delay and the original failure. */
|
|
33
|
+
constructor(delayMs: number, cause: unknown);
|
|
34
|
+
}
|
|
35
|
+
/** Reads a valid replay cursor from an absolute or relative URL. */
|
|
36
|
+
export declare function readRequestedCursor(url: string): string | undefined;
|
|
37
|
+
/** Owns the EventSource lifecycle, retry timer and replay cursor. */
|
|
38
|
+
export declare class Transport {
|
|
39
|
+
protected readonly eventSource: typeof EventSource | undefined;
|
|
40
|
+
protected readonly withCredentials: boolean;
|
|
41
|
+
protected readonly retryOptions: RetryOptions;
|
|
42
|
+
protected readonly connectionUrl: (signal: AbortSignal, lastEventId: string | undefined) => string | undefined | Promise<string | undefined>;
|
|
43
|
+
protected readonly onMessage: (event: string, data: string) => void;
|
|
44
|
+
protected readonly onStatus: (event: 'connected' | 'disconnected', madeProgress: boolean) => void;
|
|
45
|
+
protected readonly onPreOpenError?: ((url: string, status: number | undefined) => void) | undefined;
|
|
46
|
+
protected readonly initialCursor?: string | undefined;
|
|
47
|
+
/** The current connection and its registered listeners. */
|
|
48
|
+
protected connection?: Connection;
|
|
49
|
+
/** The controller for URL preparation on the current attempt. */
|
|
50
|
+
protected pending?: AbortController;
|
|
51
|
+
/** The time scheduled for the next attempt. */
|
|
52
|
+
protected retryTimer?: ReturnType<typeof setTimeout>;
|
|
53
|
+
/** The number of failures since the last attach marker. */
|
|
54
|
+
protected failures: number;
|
|
55
|
+
/** The latest replay position acknowledged by the server or an application event. */
|
|
56
|
+
protected lastEventId?: string;
|
|
57
|
+
/** The wire events that the connection should listen for. */
|
|
58
|
+
protected events: Set<string>;
|
|
59
|
+
/** Creates a transport that prepares a fresh URL for every attempt. */
|
|
60
|
+
constructor(eventSource: typeof EventSource | undefined, withCredentials: boolean, retryOptions: RetryOptions, connectionUrl: (signal: AbortSignal, lastEventId: string | undefined) => string | undefined | Promise<string | undefined>, onMessage: (event: string, data: string) => void, onStatus: (event: 'connected' | 'disconnected', madeProgress: boolean) => void, onPreOpenError?: ((url: string, status: number | undefined) => void) | undefined, initialCursor?: string | undefined);
|
|
61
|
+
/** Reports whether the active source has opened. */
|
|
62
|
+
get connected(): boolean;
|
|
63
|
+
/** Returns the cursor used when opening the next source. */
|
|
64
|
+
get replayCursor(): string | undefined;
|
|
65
|
+
/** Replaces the active connection with a new attempt. */
|
|
66
|
+
connect(): void;
|
|
67
|
+
/** Updates named listeners on the active connection and future attempts. */
|
|
68
|
+
setEvents(events: Set<string>): void;
|
|
69
|
+
/** Cancels work that could open a connection for obsolete subscriptions. */
|
|
70
|
+
cancelPending(): void;
|
|
71
|
+
/** Stops the active connection and removes its listeners. */
|
|
72
|
+
close(): void;
|
|
73
|
+
/** Prepares the connection and binds its named events. */
|
|
74
|
+
protected open(): Promise<void>;
|
|
75
|
+
/** Binds listeners to the active source, including polyfills without currentTarget. */
|
|
76
|
+
protected attach(source: EventSource, url: string): void;
|
|
77
|
+
/** Schedules a replacement connection with capped exponential backoff and jitter. */
|
|
78
|
+
protected retry(minimumDelay?: number): void;
|
|
79
|
+
/** Closes the failed connection, schedules a retry, and reports the failure. */
|
|
80
|
+
protected handleFailure(minimumDelay?: number): void;
|
|
81
|
+
/** Captures the resume cursor and dispatches named stream data. */
|
|
82
|
+
protected receive(connection: Connection, event: string, data: string, lastEventId: unknown): void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arttecs/murmur",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript client for Murmur server-sent events.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Arthur Purcino (https://github.com/pvrcino)",
|
|
8
|
+
"homepage": "https://github.com/arttecs/murmur/tree/main/js#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/arttecs/murmur.git",
|
|
12
|
+
"directory": "js"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/arttecs/murmur/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"sse",
|
|
19
|
+
"server-sent-events",
|
|
20
|
+
"eventsource",
|
|
21
|
+
"laravel",
|
|
22
|
+
"realtime",
|
|
23
|
+
"murmur"
|
|
24
|
+
],
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./echo": {
|
|
40
|
+
"types": "./dist/echo.d.ts",
|
|
41
|
+
"default": "./dist/echo.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
46
|
+
"prepack": "npm run build",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"eventsource": "^5.1.5",
|
|
53
|
+
"laravel-echo": "^2.6.3",
|
|
54
|
+
"tsup": "^9.0.0",
|
|
55
|
+
"typescript": "^7.0.2",
|
|
56
|
+
"vitest": "^5.1.1"
|
|
57
|
+
}
|
|
58
|
+
}
|