@gscdump/sdk 1.4.0 → 1.4.1

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,109 @@
1
+ import { RealtimeV1Cursor, RealtimeV1Event, RealtimeV1StreamHead, RealtimeV1StreamId } from "@gscdump/contracts/v1";
2
+ type MaybePromise<T> = T | Promise<T>;
3
+ declare const GSCDUMP_REALTIME_V1_SDK_VERSION: '1.4.1';
4
+ type GscdumpRealtimeV1TransportState = 'idle' | 'ticketing' | 'connecting' | 'handshaking' | 'replaying' | 'live' | 'waiting' | 'stopped' | 'terminal';
5
+ type GscdumpRealtimeV1Freshness = 'unknown' | 'stale' | 'applying' | 'fresh' | 'resyncing' | 'degraded';
6
+ type GscdumpRealtimeV1ErrorCode = 'cursor_store_failed' | 'effect_failed' | 'heartbeat_stale' | 'integration_failed' | 'protocol_error' | 'resync_failed' | 'runtime_unavailable' | 'socket_error' | 'ticket_invalid' | 'ticket_provider_failed' | 'upgrade_rejected';
7
+ interface GscdumpRealtimeV1ErrorOptions {
8
+ code: GscdumpRealtimeV1ErrorCode;
9
+ message: string;
10
+ retryable: boolean;
11
+ terminal: boolean;
12
+ details?: Record<string, unknown>;
13
+ cause?: unknown;
14
+ }
15
+ declare class GscdumpRealtimeV1Error extends Error {
16
+ readonly tag: 'GscdumpRealtimeV1Error';
17
+ readonly code: GscdumpRealtimeV1ErrorCode;
18
+ readonly retryable: boolean;
19
+ readonly terminal: boolean;
20
+ readonly details: Record<string, unknown>;
21
+ readonly cause?: unknown;
22
+ constructor(options: GscdumpRealtimeV1ErrorOptions);
23
+ }
24
+ interface GscdumpRealtimeV1CursorStore {
25
+ load: () => MaybePromise<RealtimeV1Cursor | null>;
26
+ save: (cursor: RealtimeV1Cursor) => MaybePromise<void>;
27
+ }
28
+ interface GscdumpRealtimeV1SocketLike {
29
+ readonly readyState: number;
30
+ readonly protocol: string;
31
+ onopen: ((event: unknown) => void) | null;
32
+ onmessage: ((event: {
33
+ data: unknown;
34
+ }) => void) | null;
35
+ onerror: ((event: unknown) => void) | null;
36
+ onclose: ((event: {
37
+ code?: number;
38
+ reason?: string;
39
+ wasClean?: boolean;
40
+ }) => void) | null;
41
+ send: (data: string) => void;
42
+ close: (code?: number, reason?: string) => void;
43
+ }
44
+ interface GscdumpRealtimeV1Runtime {
45
+ createSocket: (url: string, protocols: readonly string[]) => GscdumpRealtimeV1SocketLike;
46
+ setTimeout: (handler: () => void, ms: number) => unknown;
47
+ clearTimeout: (handle: unknown) => void;
48
+ random: () => number;
49
+ now: () => number;
50
+ }
51
+ type GscdumpRealtimeV1ResyncReason = 'cursor_expired' | 'retention_gap' | 'sequence_gap' | 'stream_mismatch' | 'initial_cursor_missing' | 'effect_application_failed';
52
+ interface GscdumpRealtimeV1ResyncRequest {
53
+ reason: GscdumpRealtimeV1ResyncReason;
54
+ source: 'server' | 'client';
55
+ streamId: RealtimeV1StreamId;
56
+ previousCursor: RealtimeV1Cursor | null;
57
+ resumeAfter: RealtimeV1Cursor;
58
+ failedEvent?: RealtimeV1Event;
59
+ cause?: unknown;
60
+ }
61
+ interface GscdumpRealtimeV1Snapshot {
62
+ transport: GscdumpRealtimeV1TransportState;
63
+ freshness: GscdumpRealtimeV1Freshness;
64
+ attempt: number;
65
+ streamId: RealtimeV1StreamId | null;
66
+ cursor: RealtimeV1Cursor | null;
67
+ head: RealtimeV1StreamHead | null;
68
+ error: GscdumpRealtimeV1Error | null;
69
+ }
70
+ type GscdumpRealtimeV1Observation = {
71
+ type: 'state';
72
+ state: GscdumpRealtimeV1Snapshot;
73
+ } | {
74
+ type: 'event';
75
+ event: RealtimeV1Event;
76
+ cursor: RealtimeV1Cursor | null;
77
+ } | {
78
+ type: 'error';
79
+ error: GscdumpRealtimeV1Error;
80
+ state: GscdumpRealtimeV1Snapshot;
81
+ } | {
82
+ type: 'advisory';
83
+ code: 'unknown_event' | 'unknown_resource' | 'unsupported_event_version';
84
+ event: RealtimeV1Event;
85
+ };
86
+ interface CreateGscdumpRealtimeV1ClientOptions {
87
+ /** Called for every connection attempt. A ticket is never reused. */
88
+ ticketProvider: () => MaybePromise<unknown>;
89
+ /** Required correctness effect for each contiguous durable event. */
90
+ applyEvent: (event: RealtimeV1Event) => Promise<void>;
91
+ /** Required full authoritative reseed used whenever replay is unsafe. */
92
+ resync: (request: GscdumpRealtimeV1ResyncRequest) => Promise<void>;
93
+ cursorStore?: GscdumpRealtimeV1CursorStore;
94
+ /** One isolated callback for state, event, advisory, and error observations. */
95
+ onObservation?: (observation: GscdumpRealtimeV1Observation) => unknown;
96
+ runtime?: GscdumpRealtimeV1Runtime;
97
+ sdkVersion?: string;
98
+ }
99
+ interface GscdumpRealtimeV1Client {
100
+ start: () => Promise<void>;
101
+ stop: () => void;
102
+ getSnapshot: () => GscdumpRealtimeV1Snapshot;
103
+ }
104
+ /**
105
+ * Own the v1 cursor/ACK correctness state machine. Framework adapters provide
106
+ * required effects; they never need to reproduce transport ordering rules.
107
+ */
108
+ declare function createGscdumpRealtimeV1Client(options: CreateGscdumpRealtimeV1ClientOptions): GscdumpRealtimeV1Client;
109
+ export { CreateGscdumpRealtimeV1ClientOptions, GSCDUMP_REALTIME_V1_SDK_VERSION, GscdumpRealtimeV1Client, GscdumpRealtimeV1CursorStore, GscdumpRealtimeV1Error, GscdumpRealtimeV1ErrorCode, GscdumpRealtimeV1ErrorOptions, GscdumpRealtimeV1Freshness, GscdumpRealtimeV1Observation, GscdumpRealtimeV1ResyncReason, GscdumpRealtimeV1ResyncRequest, GscdumpRealtimeV1Runtime, GscdumpRealtimeV1Snapshot, GscdumpRealtimeV1SocketLike, GscdumpRealtimeV1TransportState, createGscdumpRealtimeV1Client };