@camera.ui/transport 0.0.21 → 0.0.22
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/dist/closeCodes-ClWJVOpq.js +14 -0
- package/dist/{contract-d-0gfY8v.js → contract-dt1m8U-o.js} +1 -6
- package/dist/core/kernel.d.ts +1 -0
- package/dist/core/types.d.ts +5 -24
- package/dist/effects/backgroundProbe.d.ts +20 -0
- package/dist/effects/degradedRecovery.d.ts +14 -0
- package/dist/effects/probeLoop.d.ts +2 -0
- package/dist/effects/transportSync.d.ts +2 -0
- package/dist/index.d.ts +15 -10
- package/dist/index.js +522 -352
- package/dist/journal.d.ts +19 -0
- package/dist/race.d.ts +2 -0
- package/dist/signal.d.ts +30 -0
- package/dist/testing/fakeTransport.d.ts +3 -0
- package/dist/testing.js +15 -1
- package/dist/transports/closeCodes.d.ts +8 -0
- package/dist/transports/contract.d.ts +1 -1
- package/dist/transports/http.js +1 -1
- package/dist/transports/nats.d.ts +2 -1
- package/dist/transports/nats.js +46 -6
- package/dist/transports/socketio.d.ts +3 -1
- package/dist/transports/socketio.js +36 -26
- package/dist/transports/ws.js +6 -5
- package/dist/worker.js +0 -1
- package/package.json +3 -3
- package/dist/core/resolver.d.ts +0 -5
- package/dist/effects/reconnectWatchdog.d.ts +0 -10
- package/dist/effects/transportWatchdog.d.ts +0 -16
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/transports/closeCodes.ts
|
|
2
|
+
function classifyClose(input) {
|
|
3
|
+
const obj = typeof input === "string" ? void 0 : input;
|
|
4
|
+
const code = obj?.wsCloseCode ?? obj?.code;
|
|
5
|
+
if (code === 4401 || code === 1008) return "auth-expired";
|
|
6
|
+
if (code === 4403 || code === 4400) return "forbidden";
|
|
7
|
+
const text = (typeof input === "string" ? input : obj?.reason ?? obj?.message ?? "").toLowerCase();
|
|
8
|
+
if (!text) return "other";
|
|
9
|
+
if (text.includes("forbidden") || text.includes("403")) return "forbidden";
|
|
10
|
+
if (text.includes("unauthorized") || text.includes("401") || text.includes("auth")) return "auth-expired";
|
|
11
|
+
return "other";
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { classifyClose as t };
|
|
@@ -12,11 +12,6 @@ function isEndpointChange(a, b) {
|
|
|
12
12
|
if (!a || !b) return true;
|
|
13
13
|
return a.endpoint.url !== b.endpoint.url || a.endpoint.mode !== b.endpoint.mode;
|
|
14
14
|
}
|
|
15
|
-
function isTokenOnlyChange(a, b) {
|
|
16
|
-
if (!a || !b) return false;
|
|
17
|
-
if (isEndpointChange(a, b)) return false;
|
|
18
|
-
return !isSameTarget(a, b);
|
|
19
|
-
}
|
|
20
15
|
var TransportEmitter = class {
|
|
21
16
|
listeners = /* @__PURE__ */ new Map();
|
|
22
17
|
on(event, handler) {
|
|
@@ -40,4 +35,4 @@ var TransportEmitter = class {
|
|
|
40
35
|
}
|
|
41
36
|
};
|
|
42
37
|
//#endregion
|
|
43
|
-
export {
|
|
38
|
+
export { isEndpointChange as n, isSameTarget as r, TransportEmitter as t };
|
package/dist/core/kernel.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type Unsubscribe = () => void;
|
|
|
4
4
|
export interface KernelOptions {
|
|
5
5
|
readonly context: ReducerContext;
|
|
6
6
|
readonly initial?: ConnectionPhase;
|
|
7
|
+
readonly onAction?: (action: Action, prev: ConnectionPhase, next: ConnectionPhase) => void;
|
|
7
8
|
}
|
|
8
9
|
export interface Kernel {
|
|
9
10
|
readonly phase: ConnectionPhase;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -24,33 +24,22 @@ export interface TransportSpec {
|
|
|
24
24
|
readonly id: TransportId;
|
|
25
25
|
readonly kind: TransportKind;
|
|
26
26
|
readonly phaseGating: boolean;
|
|
27
|
-
readonly graceMs?: number;
|
|
28
27
|
}
|
|
29
28
|
export interface TransportStatus {
|
|
30
29
|
readonly up: boolean;
|
|
31
30
|
readonly lastError?: string;
|
|
32
31
|
readonly downSince?: number;
|
|
33
32
|
}
|
|
34
|
-
export type ReconnectCause = 'transport-down' | 'auth-error' | 'network-change' | 'user-retry' | 'endpoint-swap';
|
|
35
33
|
export type ConnectionPhase = {
|
|
36
34
|
readonly kind: 'idle';
|
|
37
35
|
} | {
|
|
38
36
|
readonly kind: 'discovering';
|
|
39
37
|
readonly instanceId: string;
|
|
40
|
-
readonly
|
|
41
|
-
readonly transports?: ReadonlyMap<TransportId, TransportStatus>;
|
|
38
|
+
readonly pendingTokens?: Tokens;
|
|
42
39
|
} | {
|
|
43
40
|
readonly kind: 'online';
|
|
44
41
|
readonly instanceId: string;
|
|
45
42
|
readonly target: ConnectionTarget;
|
|
46
|
-
readonly transports: ReadonlyMap<TransportId, TransportStatus>;
|
|
47
|
-
} | {
|
|
48
|
-
readonly kind: 'reconnecting';
|
|
49
|
-
readonly instanceId: string;
|
|
50
|
-
readonly lastTarget: ConnectionTarget | null;
|
|
51
|
-
readonly cause: ReconnectCause;
|
|
52
|
-
readonly since: number;
|
|
53
|
-
readonly transports: ReadonlyMap<TransportId, TransportStatus>;
|
|
54
43
|
} | {
|
|
55
44
|
readonly kind: 'needs-auth';
|
|
56
45
|
readonly instanceId: string | null;
|
|
@@ -77,16 +66,6 @@ export type Action = {
|
|
|
77
66
|
} | {
|
|
78
67
|
readonly type: 'PROBE_FAILED_ALL';
|
|
79
68
|
readonly error: string;
|
|
80
|
-
} | {
|
|
81
|
-
readonly type: 'TRANSPORT_UP';
|
|
82
|
-
readonly id: TransportId;
|
|
83
|
-
} | {
|
|
84
|
-
readonly type: 'TRANSPORT_DOWN';
|
|
85
|
-
readonly id: TransportId;
|
|
86
|
-
readonly reason: string;
|
|
87
|
-
} | {
|
|
88
|
-
readonly type: 'TRANSPORT_DOWN_CONFIRMED';
|
|
89
|
-
readonly id: TransportId;
|
|
90
69
|
} | {
|
|
91
70
|
readonly type: 'TOKENS_REFRESHED';
|
|
92
71
|
readonly tokens: Tokens;
|
|
@@ -102,9 +81,11 @@ export type Action = {
|
|
|
102
81
|
readonly type: 'BACKOFF_HINT';
|
|
103
82
|
readonly retryAfterMs: number;
|
|
104
83
|
readonly source?: string;
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: 'ENDPOINT_SWAP';
|
|
86
|
+
readonly endpoint: Endpoint;
|
|
87
|
+
readonly tokens: Tokens;
|
|
105
88
|
};
|
|
106
89
|
export interface ReducerContext {
|
|
107
|
-
readonly specs: ReadonlyMap<TransportId, TransportSpec>;
|
|
108
90
|
readonly now: () => number;
|
|
109
|
-
readonly retryBackoffMs?: (attempt: number) => number;
|
|
110
91
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Kernel } from '../core/kernel.js';
|
|
2
|
+
import { ConnectionTarget, Endpoint, Tokens } from '../core/types.js';
|
|
3
|
+
import { TimeoutByModeFn } from '../race.js';
|
|
4
|
+
import { ProbeContext } from './probeLoop.js';
|
|
5
|
+
export type BackgroundProbeOutcome = 'swap' | 'same' | 'failed' | 'skipped';
|
|
6
|
+
export interface BackgroundProbeOptions {
|
|
7
|
+
readonly kernel: Kernel;
|
|
8
|
+
readonly discover: (signal: AbortSignal) => Promise<readonly Endpoint[]>;
|
|
9
|
+
readonly probe: (ctx: ProbeContext) => Promise<Tokens>;
|
|
10
|
+
readonly lastTarget?: () => ConnectionTarget | null;
|
|
11
|
+
readonly timeoutByMode?: TimeoutByModeFn;
|
|
12
|
+
readonly prefer?: (endpoint: Endpoint) => boolean;
|
|
13
|
+
readonly preferGraceMs?: number;
|
|
14
|
+
readonly onResult?: (outcome: BackgroundProbeOutcome, detail?: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface BackgroundProbe {
|
|
17
|
+
run(): Promise<BackgroundProbeOutcome>;
|
|
18
|
+
dispose(): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function createBackgroundProbe(options: BackgroundProbeOptions): BackgroundProbe;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Kernel } from '../core/kernel.js';
|
|
2
|
+
import { ConnectionSignalHandle } from '../signal.js';
|
|
3
|
+
import { BackgroundProbeOutcome } from './backgroundProbe.js';
|
|
4
|
+
export type Detach = () => void;
|
|
5
|
+
export interface DegradedRecoveryOptions {
|
|
6
|
+
readonly kernel: Kernel;
|
|
7
|
+
readonly signal: ConnectionSignalHandle;
|
|
8
|
+
readonly ensureAll: () => void;
|
|
9
|
+
readonly probe: () => Promise<BackgroundProbeOutcome>;
|
|
10
|
+
readonly graceMs?: number;
|
|
11
|
+
readonly onEscalate?: (round: number) => void;
|
|
12
|
+
readonly onOffline?: (reason: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function attachDegradedRecovery(options: DegradedRecoveryOptions): Detach;
|
|
@@ -15,9 +15,11 @@ export interface ProbeContext {
|
|
|
15
15
|
}
|
|
16
16
|
export interface ProbeLoopOptions {
|
|
17
17
|
readonly kernel: Kernel;
|
|
18
|
+
readonly preferGraceMs?: number;
|
|
18
19
|
readonly discover: (signal: AbortSignal) => Promise<readonly Endpoint[]>;
|
|
19
20
|
readonly probe: (ctx: ProbeContext) => Promise<Tokens>;
|
|
20
21
|
readonly timeoutByMode?: TimeoutByModeFn;
|
|
22
|
+
readonly prefer?: (endpoint: Endpoint) => boolean;
|
|
21
23
|
readonly onDiscoverStart?: () => void;
|
|
22
24
|
readonly onDiscoverSuccess?: (pool: readonly Endpoint[]) => void;
|
|
23
25
|
readonly onDiscoverError?: (err: unknown) => void;
|
|
@@ -5,7 +5,9 @@ export type Detach = () => void;
|
|
|
5
5
|
export interface TransportSyncOptions {
|
|
6
6
|
readonly kernel: Kernel;
|
|
7
7
|
readonly transports: readonly Transport[];
|
|
8
|
+
readonly retryMs?: number;
|
|
8
9
|
readonly onError?: (transport: Transport, target: ConnectionTarget | null, error: unknown) => void;
|
|
10
|
+
readonly onRetry?: (transport: Transport, target: ConnectionTarget | null) => void;
|
|
9
11
|
readonly onApplied?: (target: ConnectionTarget | null) => void;
|
|
10
12
|
}
|
|
11
13
|
export declare function attachTransportSync(options: TransportSyncOptions): Detach;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
export { createKernel } from './core/kernel.js';
|
|
2
2
|
export { reducer } from './core/reducer.js';
|
|
3
|
-
export {
|
|
3
|
+
export { createBackgroundProbe } from './effects/backgroundProbe.js';
|
|
4
4
|
export { attachBackoff } from './effects/backoff.js';
|
|
5
5
|
export { attachCrossTab } from './effects/crossTab.js';
|
|
6
|
+
export { attachDegradedRecovery } from './effects/degradedRecovery.js';
|
|
6
7
|
export { attachNetworkChange } from './effects/networkChange.js';
|
|
7
8
|
export { attachPersistence, localStorageAdapter, memoryStorageAdapter } from './effects/persistence.js';
|
|
8
|
-
export { attachPresence
|
|
9
|
+
export { attachPresence } from './effects/presence.js';
|
|
9
10
|
export { attachProbeLoop, isProbeFailure, makeProbeFailure } from './effects/probeLoop.js';
|
|
10
|
-
export { attachReconnectWatchdog } from './effects/reconnectWatchdog.js';
|
|
11
11
|
export { attachTokenLifecycle } from './effects/tokenLifecycle.js';
|
|
12
12
|
export { attachTransportSync } from './effects/transportSync.js';
|
|
13
|
-
export { attachTransportWatchdog } from './effects/transportWatchdog.js';
|
|
14
13
|
export { attachWorkerBridge } from './effects/workerBridge.js';
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export
|
|
14
|
+
export { createConnectionJournal } from './journal.js';
|
|
15
|
+
export { raceFirst } from './race.js';
|
|
16
|
+
export { createConnectionSignal } from './signal.js';
|
|
17
|
+
export { classifyClose } from './transports/closeCodes.js';
|
|
18
|
+
export { isEndpointChange, isSameTarget, TransportEmitter } from './transports/contract.js';
|
|
18
19
|
export type { Kernel, KernelOptions, Listener, Unsubscribe } from './core/kernel.js';
|
|
20
|
+
export type { Action, BackoffHint, ConnectionPhase, ConnectionTarget, Endpoint, EndpointMode, ReducerContext, Tokens, TransportId, TransportKind, TransportSpec, TransportStatus, } from './core/types.js';
|
|
21
|
+
export type { BackgroundProbe, BackgroundProbeOptions, BackgroundProbeOutcome } from './effects/backgroundProbe.js';
|
|
19
22
|
export type { BackoffOptions } from './effects/backoff.js';
|
|
20
23
|
export type { CrossTabOptions, CrossTabSource } from './effects/crossTab.js';
|
|
24
|
+
export type { DegradedRecoveryOptions } from './effects/degradedRecovery.js';
|
|
21
25
|
export type { NetworkChangeOptions, NetworkChangeSource } from './effects/networkChange.js';
|
|
22
26
|
export type { PersistedTarget, Persistence, PersistenceOptions, StorageAdapter } from './effects/persistence.js';
|
|
23
27
|
export type { PresenceCallback, PresenceOptions, VisibilitySource } from './effects/presence.js';
|
|
24
28
|
export type { ProbeContext, ProbeFailure, ProbeFailureKind, ProbeLoopOptions } from './effects/probeLoop.js';
|
|
25
|
-
export type { ReconnectWatchdogOptions } from './effects/reconnectWatchdog.js';
|
|
26
29
|
export type { Detach, RefreshReason, TokenLifecycle, TokenLifecycleOptions } from './effects/tokenLifecycle.js';
|
|
27
30
|
export type { TransportSyncOptions } from './effects/transportSync.js';
|
|
28
|
-
export type { TransportWatchdogOptions, WatchdogClearReason } from './effects/transportWatchdog.js';
|
|
29
31
|
export type { WorkerBridge, WorkerBridgeOptions } from './effects/workerBridge.js';
|
|
32
|
+
export type { ConnectionJournal, JournalEntry, JournalOptions } from './journal.js';
|
|
30
33
|
export type { RaceCandidate, RaceFirstOptions, RaceFirstResult, TimeoutByModeFn } from './race.js';
|
|
31
|
-
export type {
|
|
34
|
+
export type { ConnectionSignal, ConnectionSignalHandle, ConnectionSignalOptions } from './signal.js';
|
|
35
|
+
export type { CloseClass, CloseLike } from './transports/closeCodes.js';
|
|
32
36
|
export type { PerResourceTransport, Transport, TransportEvent, TransportEventHandler, TransportEventPayload } from './transports/contract.js';
|
|
37
|
+
export type { KernelSyncMessage, KernelSyncRequestMessage, MessageSource, WorkerHost, WorkerMessage } from './worker/protocol.js';
|