@vehicle-sil/gui-client 0.3.0 → 0.4.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.
@@ -1,5 +1,5 @@
1
1
  import { Connection } from './connection.js';
2
- import { AuthMessage, RuntimeStatus, ServerAllowed, ServerMessage, SessionSummary } from './protocol.js';
2
+ import { AuthMessage, RuntimeStatus, ServerAllowed, ServerMessage } from './protocol.js';
3
3
  import { SessionView } from './session-state.js';
4
4
  import { ErrorSink, Readable } from './values.js';
5
5
  /** How many kinds of notices not tied to a session are kept. */
@@ -21,7 +21,7 @@ export interface Notice {
21
21
  }
22
22
  /** Identity of one run across all starts of the server. */
23
23
  export interface RunTarget {
24
- session: number;
24
+ run_id: string;
25
25
  instance: string;
26
26
  }
27
27
  export declare function sameRunTarget(left: RunTarget | null, right: RunTarget | null): boolean;
@@ -44,7 +44,7 @@ export interface ClientSession {
44
44
  * does not say. What the launcher accepts is `launcherState` of the session.
45
45
  */
46
46
  readonly allowed: Readable<ServerAllowed | null>;
47
- /** Persistent launcher status reported on hello, runtime notifications, and prepare answers. */
47
+ /** Persistent launcher status reported on hello and runtime notifications. */
48
48
  readonly runtime: Readable<RuntimeStatus | null>;
49
49
  /** When an event was last applied (Date.now()). The starting point for advancing elapsed time with the clock. */
50
50
  readonly lastEventAt: Readable<number>;
@@ -76,19 +76,14 @@ export interface ClientSession {
76
76
  /** Removes a notice. */
77
77
  dismissNotice(id: number): void;
78
78
  }
79
- interface Adoption {
80
- revision: number;
81
- instance: string | null;
82
- session: number | null;
83
- }
84
79
  /**
85
80
  * Copy of a session (one run of the launcher). Reads the notifications of the connection (Connection) and builds the
86
- * state from the server's summary and events.
81
+ * state from the server's single WebSocket stream (summary and events).
87
82
  *
88
83
  * - Rebuilds the state from the summary in hello (the summary is authoritative), then applies the events that follow
89
84
  * (the resent log and new events).
90
- * - On every connect, puts into the authentication message where in the session it holds the server should resend
91
- * from (resumeFields).
85
+ * - On every connect, puts into the authentication message where in the stream it holds the server should resend
86
+ * from (`{instance, run_id, after_stream_seq}` via `resumeFields`).
92
87
  * - On a hello or session whose summary core is unreadable, marks itself not in sync and asks the connection to
93
88
  * restart (receive again from hello).
94
89
  * - Passes unknown notifications and unknown events through without applying them (onMessages gets only the readable
@@ -99,11 +94,11 @@ interface Adoption {
99
94
  export declare class SessionFeed implements ClientSession {
100
95
  private readonly connection;
101
96
  private readonly onError;
97
+ private readonly onInstance?;
102
98
  private readonly rawListeners;
103
- private snapshotVersion;
104
99
  private instanceId;
105
- private adoptionRevision;
106
- private instanceListener;
100
+ private lastStreamSeq;
101
+ private resyncing;
107
102
  private stopTarget;
108
103
  private readonly current;
109
104
  private readonly synced;
@@ -116,7 +111,6 @@ export declare class SessionFeed implements ClientSession {
116
111
  private readonly messageListeners;
117
112
  private noticeId;
118
113
  private stoppedFlag;
119
- private replayLogs;
120
114
  readonly session: Readable<SessionView | null>;
121
115
  readonly ready: Readable<boolean>;
122
116
  readonly allowed: Readable<ServerAllowed | null>;
@@ -125,46 +119,24 @@ export declare class SessionFeed implements ClientSession {
125
119
  readonly notices: Readable<readonly Notice[]>;
126
120
  readonly rejected: Readable<boolean>;
127
121
  readonly incompatible: Readable<string | null>;
128
- constructor(connection: Connection, onError?: ErrorSink);
122
+ constructor(connection: Connection, onError?: ErrorSink, onInstance?: ((instance: string) => void) | undefined);
129
123
  /** Refused, or the versions differ: never connect again (set before the readable values and before disconnecting). */
130
124
  get stopped(): boolean;
131
125
  /**
132
- * Fields to add to the authentication message: where in the session it holds the server should resend from. Called
126
+ * Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
133
127
  * on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
134
128
  * only inside the library.
135
129
  */
136
- resumeFields(): Pick<AuthMessage, 'session' | 'from_seq'>;
130
+ resumeFields(): Pick<AuthMessage, 'instance' | 'run_id' | 'after_stream_seq'>;
137
131
  onMessages(listener: (batch: readonly ServerMessage[]) => void): () => void;
138
- /**
139
- * Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
140
- * fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
141
- * request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
142
- * run over a new one.
143
- */
144
- onRawMessages(listener: (batch: readonly unknown[], current: () => boolean, snapshotVersion: number) => void): () => void;
145
- onSnapshotVersion(read: () => number): void;
146
- /** Called before a new server's session can be published. */
147
- onInstance(listener: (instance: string, current: () => boolean) => void): void;
132
+ onRawMessages(listener: (batch: readonly unknown[], current: () => boolean) => void): () => void;
148
133
  /** Instance associated with the current session, or null if its origin is not known. */
149
134
  currentInstance(): string | null;
150
135
  currentTarget(): RunTarget | null;
151
- adopt(summary: SessionSummary | null, instance: string, resyncFrom?: string | null): Adoption | null;
152
- sameRun(adoption: Adoption): boolean;
153
- isCurrent(revision: number): boolean;
154
- /**
155
- * Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
156
- * server that does not number it: the newest arrival wins). Used inside the library.
157
- */
158
- adoptAllowed(allowed: ServerAllowed | null): void;
159
- /** Updates the current persistent runtime status (from HTTP `prepare`/`session`). Used inside the library. */
160
- adoptRuntime(runtime: RuntimeStatus | null): void;
161
136
  report(message: string, count?: number): void;
162
137
  dismissNotice(id: number): void;
163
138
  /** Reads and applies a batch from the connection. */
164
139
  private receive;
165
- /** Keep messages at or after the run already observed over HTTP, within each server instance. */
166
- private filterOlderRuns;
167
140
  private apply;
168
141
  private notify;
169
142
  }
170
- export {};
package/types/time.d.ts CHANGED
@@ -27,8 +27,8 @@ export interface TimeFailure {
27
27
  */
28
28
  message: string;
29
29
  command: TimeCommandName;
30
- /** Number of the run it was sent to. */
31
- session: number | null;
30
+ /** Run identifier it was sent to. */
31
+ session: string | null;
32
32
  }
33
33
  /** Lateness figures (meaningful only while the speed is paced, such as at real-time speed). */
34
34
  export interface Lateness {
@@ -50,7 +50,7 @@ export type VariablesStatus = Open<'unknown' | 'off' | 'connecting' | 'ready' |
50
50
  /** List and state of the variables (of the current run). */
51
51
  export interface VariablesState {
52
52
  /** Which run they belong to (null without a run). */
53
- session: number | null;
53
+ session: string | null;
54
54
  status: VariablesStatus;
55
55
  /** Why the API is unavailable or cannot connect (the server's English text). null if none. */
56
56
  reason: string | null;
@@ -143,7 +143,7 @@ export interface OperationPeer {
143
143
  }
144
144
  /** Result of a write (operation). */
145
145
  export interface OperationView {
146
- session: number;
146
+ session: string;
147
147
  /** Operation number (operation in the `api/write` answer). */
148
148
  seq: number;
149
149
  /**
@@ -177,7 +177,7 @@ export interface WriteOptions {
177
177
  * `operations`, so a widget can show "accepted, waiting to be applied" or know that it may send the next write.
178
178
  */
179
179
  onAccepted?: (operation: {
180
- session: number;
180
+ session: string;
181
181
  seq: number;
182
182
  }) => void;
183
183
  }
@@ -272,21 +272,20 @@ export declare const WATCH_PERIOD_MS = 100;
272
272
  */
273
273
  export declare const WATCH_PERIODS_MS: readonly [20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 60000];
274
274
  /** Reads `variables` of a summary. Unreadable parts are skipped as if absent (additions are compatible). */
275
- export declare function readVariables(value: unknown, session: number | null): VariablesState;
275
+ export declare function readVariables(value: unknown, session: string | null): VariablesState;
276
276
  /** Reads an `operation` notification (or one entry of operations in a summary). null if unreadable. */
277
- export declare function readOperation(value: unknown, session: number): OperationView | null;
277
+ export declare function readOperation(value: unknown, session: string): OperationView | null;
278
278
  /** What VariablesFeed asks of the connection. */
279
279
  export interface VariablesLink {
280
280
  /** Sends if connected (does nothing otherwise; resume() sends what is needed on connect). */
281
281
  send(message: unknown): unknown;
282
- onBatch(listener: (batch: readonly unknown[], current?: () => boolean, snapshotVersion?: number) => void): () => void;
282
+ onBatch(listener: (batch: readonly unknown[], current?: () => boolean) => void): () => void;
283
283
  }
284
284
  /**
285
285
  * ECU variables: list and state, value watches, writes and their results. No framework needed.
286
286
  *
287
- * - List and state come from `variables` in hello and in HTTP summaries, and from `variables` notifications (`session`
288
- * notifications do not carry them). When the run changes, they are unknown until that run's `variables`
289
- * notification arrives.
287
+ * - List and state come from `variables` in hello and from `variables` notifications (`session` notifications do not
288
+ * carry them). When the run changes, they are unknown until that run's `variables` notification arrives.
290
289
  * - Each variable goes into the subscription with the shortest interval requested for it (one subscription per
291
290
  * interval). A changed subscription is resent with the same id (the server replaces it); after a reconnect, resume()
292
291
  * resends them all.
@@ -302,9 +301,6 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
302
301
  /** Limits (from limits of api/app; the defaults until then). */
303
302
  private readonly limits;
304
303
  private instanceId;
305
- private snapshotVersionValue;
306
- private snapshotIdentity;
307
- private serverRevision;
308
304
  private readonly stateValue;
309
305
  private readonly operationsValue;
310
306
  private readonly handles;
@@ -337,20 +333,12 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
337
333
  resume(): unknown[];
338
334
  /** The client was closed: fail the pending writes (including those waiting for the HTTP answer). Watches stay. */
339
335
  dispose(): void;
336
+ onInstance(instance: string): void;
340
337
  private receive;
341
338
  /** Returns whether any state changed. Only the availability table changes: `peers` keeps its identity. */
342
339
  private takeAvailability;
343
- snapshotVersion(): number;
344
- /** Compare server capture order when available; legacy peers use the local best-effort watermark. */
345
- isSnapshotCurrent(version: number, instance: string | null, session: number | null, rev: number | null): boolean;
346
- private markSnapshot;
347
- private applySnapshot;
348
- /** A reused numeric session on another server is a different run. */
349
- adoptInstance(value: unknown): void;
350
- /** Applies a summary: an older snapshot can still carry a terminal write result. */
351
- adoptSummary(summary: unknown, current?: () => boolean, snapshotCurrent?: () => boolean): number | null;
352
340
  /**
353
- * With the summary after a reconnect (or from api/session), settles as "no answer came" (lost) the writes waiting for
341
+ * With the summary after a reconnect, settles as "no answer came" (lost) the writes waiting for
354
342
  * a result that will no longer arrive. For writes whose number is not known yet (before the HTTP answer), the summary
355
343
  * is kept and checked the same way once the number is known.
356
344
  */