@vehicle-sil/gui-client 0.4.0 → 0.6.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/README.ja.md +452 -730
- package/README.md +452 -728
- package/dist/elements.js +656 -47
- package/dist/empty.js +2 -0
- package/dist/index.js +3362 -1721
- package/package.json +13 -1
- package/timeline/vehicle-sil-timeline.d.ts +76 -0
- package/timeline/vehicle-sil-timeline.js +817 -139
- package/timeline/vehicle-sil-timeline.mjs +817 -139
- package/types/client.d.ts +24 -3
- package/types/connection.d.ts +10 -2
- package/types/elements/contracts.d.ts +112 -0
- package/types/elements/index.d.ts +5 -3
- package/types/elements/outside-parts.d.ts +5 -0
- package/types/elements/page-intent.d.ts +1 -1
- package/types/elements/part.d.ts +11 -4
- package/types/elements/run-parts.d.ts +19 -0
- package/types/elements/scenario-parts.d.ts +5 -1
- package/types/elements/variable-parts.d.ts +58 -11
- package/types/frameworks/all-contracts.d.ts +18 -0
- package/types/frameworks/react.d.ts +40 -0
- package/types/frameworks/svelte.d.ts +22 -0
- package/types/frameworks/vue.d.ts +35 -0
- package/types/front-actions.d.ts +18 -0
- package/types/front-types.d.ts +67 -6
- package/types/front-variable.d.ts +5 -0
- package/types/front.d.ts +11 -24
- package/types/http.d.ts +4 -0
- package/types/index.d.ts +5 -5
- package/types/protocol/launcher.d.ts +87 -1
- package/types/protocol/server.d.ts +44 -1
- package/types/session-state.d.ts +15 -1
- package/types/session.d.ts +8 -2
- package/types/time.d.ts +8 -0
- package/types/variable-binding.d.ts +9 -3
- package/types/variable-state.d.ts +5 -0
- package/types/variables.d.ts +113 -48
package/types/variables.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { ConnectionState } from './connection.js';
|
|
1
2
|
import { HttpTransport } from './http.js';
|
|
2
3
|
import { Open } from './protocol.js';
|
|
3
4
|
import type { VariableAvailability } from './protocol.js';
|
|
5
|
+
import { type SessionView } from './session-state.js';
|
|
4
6
|
import { ErrorSink, Readable } from './values.js';
|
|
5
7
|
import type { BindOptions, VariableBinding } from './variable-binding.js';
|
|
6
8
|
/**
|
|
@@ -21,6 +23,8 @@ export interface VariableInfo {
|
|
|
21
23
|
role: Open<'input' | 'output' | 'parameter'>;
|
|
22
24
|
/** Whether it can be written (role is input or parameter). */
|
|
23
25
|
writable: boolean;
|
|
26
|
+
/** Whether vehicle-sil added the variable (`ecu.connected`, `peer.*`, `j1939.*`, `can.*`, `lin.*`, `eth.*`) rather than the ECU application declaring it. */
|
|
27
|
+
builtin: boolean;
|
|
24
28
|
unit: string;
|
|
25
29
|
min: number | null;
|
|
26
30
|
max: number | null;
|
|
@@ -155,6 +159,26 @@ export interface OperationView {
|
|
|
155
159
|
done: boolean;
|
|
156
160
|
peers: Record<string, OperationPeer>;
|
|
157
161
|
}
|
|
162
|
+
/** Options of waiting for a queued write to settle (`queued.applied(options)`). */
|
|
163
|
+
export interface WriteWaitOptions {
|
|
164
|
+
/**
|
|
165
|
+
* Watchdog timeout budget (ms; default WRITE_TIMEOUT_MS). Must be a finite number greater than 0.
|
|
166
|
+
* Suspended while healthy and paused/holding before all target ECUs settle; scaled by slow playback speed and
|
|
167
|
+
* target ECU step period while advancing towards due; bounded across disconnect/non-sync or past due.
|
|
168
|
+
*/
|
|
169
|
+
timeoutMs?: number;
|
|
170
|
+
/** Aborts the wait (`WriteError('no-answer', ..., 'aborted', lastKnownOperation)`). */
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Stages 1+2 result of `client.variables.enqueue`: the server accepted the write and every target ECU has queued it
|
|
175
|
+
* (or settled as `applied`). Call `applied()` for stages 3+4 (waiting for all target ECUs to apply it).
|
|
176
|
+
*/
|
|
177
|
+
export interface QueuedOperation {
|
|
178
|
+
readonly session: string;
|
|
179
|
+
readonly seq: number;
|
|
180
|
+
applied(options?: WriteWaitOptions): Promise<OperationView>;
|
|
181
|
+
}
|
|
158
182
|
/** Options of a write. */
|
|
159
183
|
export interface WriteOptions {
|
|
160
184
|
/** Optional server instance identifier to reject stale writes across server restarts. */
|
|
@@ -164,49 +188,46 @@ export interface WriteOptions {
|
|
|
164
188
|
/** If the requested time cannot be met: reject (default; not applied) or apply (applied in the next step). */
|
|
165
189
|
late?: 'reject' | 'apply';
|
|
166
190
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* follow the result in operations. `Infinity` never times out (waits until the run changes or close()). Values
|
|
170
|
-
* longer than about 24.8 days (2^31-1 ms) are capped there. A non-number or a value of 0 or less means the default.
|
|
171
|
-
* Counted from the HTTP answer.
|
|
191
|
+
* Watchdog timeout budget for waiting on the applied result (ms; default WRITE_TIMEOUT_MS). Must be a finite number
|
|
192
|
+
* greater than 0. Values longer than about 24.8 days (2^31-1 ms) are capped there.
|
|
172
193
|
*/
|
|
173
194
|
timeoutMs?: number;
|
|
174
195
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* `operations`, so a widget can show "accepted, waiting to be applied" or know that it may send the next write.
|
|
196
|
+
* Forwarded to the HTTP transport (`HttpRequest.keepalive` -> `fetch(..., { keepalive })`). Set `true` for a
|
|
197
|
+
* release write sent from a browser `pagehide` handler so the request can finish as the page unloads.
|
|
178
198
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}) => void;
|
|
199
|
+
keepalive?: boolean;
|
|
200
|
+
/** Aborts the write or wait (`WriteError`). */
|
|
201
|
+
signal?: AbortSignal;
|
|
183
202
|
}
|
|
184
203
|
/**
|
|
185
204
|
* A write that went wrong.
|
|
186
205
|
* - refused: the server did not accept it (wrong type or range, unknown variable, no run and so on; code names the
|
|
187
206
|
* error). It was not sent, so you may fix it and send it again.
|
|
188
|
-
* - failed: accepted but not applied (operation has the state and reason per participant).
|
|
207
|
+
* - failed: accepted but not applied (code names the settled state; operation has the state and reason per participant).
|
|
189
208
|
* - no-answer: unknown whether it was applied. The result did not come within the timeout (operation has the last
|
|
190
|
-
* known state), there was no HTTP answer, the server failed midway (500), the
|
|
191
|
-
*
|
|
192
|
-
* answer, the write settled while reconnecting and its result was lost (not in the summary's list
|
|
193
|
-
* the boundary operations_from_seq), or the server could not keep all unsettled operations and stopped
|
|
194
|
-
* **Sending it again as is may write twice**: check operations and the value first.
|
|
209
|
+
* known state), there was no HTTP answer, the server failed midway (500), the ECUs did not queue it in time
|
|
210
|
+
* (code `write-timeout`) or the connection broke midway (`write-failed`), the wait was aborted (`aborted`), the run
|
|
211
|
+
* changed before the answer, the write settled while reconnecting and its result was lost (not in the summary's list
|
|
212
|
+
* and older than the boundary operations_from_seq), or the server could not keep all unsettled operations and stopped
|
|
213
|
+
* following it. **Sending it again as is may write twice**: check operations and the value first.
|
|
195
214
|
* - closed: the client was closed (unknown whether it was applied).
|
|
196
215
|
*/
|
|
197
216
|
export declare class WriteError extends Error {
|
|
198
217
|
readonly kind: 'refused' | 'failed' | 'no-answer' | 'closed';
|
|
199
218
|
/**
|
|
200
|
-
* Name of the
|
|
201
|
-
*
|
|
219
|
+
* Name of the error (for refused: `unknown-variable`, `not-writable`, `invalid-field`, `unknown-field`,
|
|
220
|
+
* `invalid-argument`, `aborted` and so on; for failed: `invalid`, `busy`, `late`, `rejected`, `cancelled`,
|
|
221
|
+
* `unknown`, `mixed`; for no-answer: `write-timeout`, `write-failed`, `aborted`, or null).
|
|
202
222
|
*/
|
|
203
223
|
readonly code: string | null;
|
|
204
224
|
/** The operation (once its number is known). */
|
|
205
225
|
readonly operation: OperationView | null;
|
|
206
226
|
constructor(kind: 'refused' | 'failed' | 'no-answer' | 'closed', message: string,
|
|
207
227
|
/**
|
|
208
|
-
* Name of the
|
|
209
|
-
*
|
|
228
|
+
* Name of the error (for refused: `unknown-variable`, `not-writable`, `invalid-field`, `unknown-field`,
|
|
229
|
+
* `invalid-argument`, `aborted` and so on; for failed: `invalid`, `busy`, `late`, `rejected`, `cancelled`,
|
|
230
|
+
* `unknown`, `mixed`; for no-answer: `write-timeout`, `write-failed`, `aborted`, or null).
|
|
210
231
|
*/
|
|
211
232
|
code?: string | null,
|
|
212
233
|
/** The operation (once its number is known). */
|
|
@@ -235,11 +256,14 @@ export interface ClientVariables {
|
|
|
235
256
|
*/
|
|
236
257
|
watch(variables: readonly VariableRef[] | 'all', options?: WatchOptions): VariableWatch;
|
|
237
258
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
259
|
+
* Sends a write and resolves with `QueuedOperation` once the server accepted it and every target ECU has queued it
|
|
260
|
+
* (stages 1+2). Rejects immediately with `WriteError` if refused, unanswered, or already terminally failed.
|
|
261
|
+
*/
|
|
262
|
+
enqueue(writes: Record<string, Record<string, number | boolean | string>>, options?: WriteOptions): Promise<QueuedOperation>;
|
|
263
|
+
/**
|
|
264
|
+
* Writes variables: `write({Engine: {'engine.throttle': 50}})`. Sugar for
|
|
265
|
+
* `enqueue(writes, options).then(q => q.applied(...))`: resolves with the operation once applied; rejects with a
|
|
266
|
+
* `WriteError` otherwise. The same write is never resent automatically.
|
|
243
267
|
*/
|
|
244
268
|
write(writes: Record<string, Record<string, number | boolean | string>>, options?: WriteOptions): Promise<OperationView>;
|
|
245
269
|
/**
|
|
@@ -251,6 +275,19 @@ export interface ClientVariables {
|
|
|
251
275
|
*/
|
|
252
276
|
bind(ref: VariableRef, options?: BindOptions): VariableBinding;
|
|
253
277
|
}
|
|
278
|
+
/** Internal hook letting `FrontVariable` release its in-flight token even when `queued.applied()` is never called. */
|
|
279
|
+
export declare const ON_SETTLED: unique symbol;
|
|
280
|
+
export interface InternalQueuedOperation extends QueuedOperation {
|
|
281
|
+
[ON_SETTLED]?(listener: (outcome: OperationView | WriteError) => void): () => void;
|
|
282
|
+
}
|
|
283
|
+
/** Clock and link signals driving the four-mode write watchdog. */
|
|
284
|
+
export interface WriteClockSource {
|
|
285
|
+
readonly connection: Readable<ConnectionState>;
|
|
286
|
+
readonly ready: Readable<boolean>;
|
|
287
|
+
readonly rejected: Readable<boolean>;
|
|
288
|
+
readonly incompatible: Readable<string | null>;
|
|
289
|
+
readonly session: Readable<SessionView | null>;
|
|
290
|
+
}
|
|
254
291
|
/** Default time to wait for the result of a write (ms). */
|
|
255
292
|
export declare const WRITE_TIMEOUT_MS = 10000;
|
|
256
293
|
/** Limit on the number of history points (per variable). */
|
|
@@ -271,6 +308,13 @@ export declare const WATCH_PERIOD_MS = 100;
|
|
|
271
308
|
* subscriptions (the server's limit is 16 per connection).
|
|
272
309
|
*/
|
|
273
310
|
export declare const WATCH_PERIODS_MS: readonly [20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 60000];
|
|
311
|
+
/** Shortest supported watch period (ms). */
|
|
312
|
+
export declare const WATCH_PERIOD_MS_MIN: 20;
|
|
313
|
+
/** Longest supported watch period (ms). */
|
|
314
|
+
export declare const WATCH_PERIOD_MS_MAX: 100 | 1000 | 5000 | 500 | 20 | 60000 | 2000 | 200 | 10000 | 50;
|
|
315
|
+
export declare function isAbortSignalLike(value: unknown): value is AbortSignal;
|
|
316
|
+
export declare function validateWriteOptions(options: unknown): WriteError | null;
|
|
317
|
+
export declare function validateWriteWaitOptions(options: unknown): WriteError | null;
|
|
274
318
|
/** Reads `variables` of a summary. Unreadable parts are skipped as if absent (additions are compatible). */
|
|
275
319
|
export declare function readVariables(value: unknown, session: string | null): VariablesState;
|
|
276
320
|
/** Reads an `operation` notification (or one entry of operations in a summary). null if unreadable. */
|
|
@@ -283,16 +327,6 @@ export interface VariablesLink {
|
|
|
283
327
|
}
|
|
284
328
|
/**
|
|
285
329
|
* ECU variables: list and state, value watches, writes and their results. No framework needed.
|
|
286
|
-
*
|
|
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.
|
|
289
|
-
* - Each variable goes into the subscription with the shortest interval requested for it (one subscription per
|
|
290
|
-
* interval). A changed subscription is resent with the same id (the server replaces it); after a reconnect, resume()
|
|
291
|
-
* resends them all.
|
|
292
|
-
* - Per variable, keeps the last value and as many history points as requested (ring buffer). Dropped when the run
|
|
293
|
-
* changes.
|
|
294
|
-
* - Write results arrive in `operation` notifications. They can arrive before the HTTP answer (the operation number),
|
|
295
|
-
* so recent operations are kept and matched once the number is known.
|
|
296
330
|
*/
|
|
297
331
|
export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
|
|
298
332
|
private readonly link;
|
|
@@ -300,14 +334,21 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
|
|
|
300
334
|
private readonly onError;
|
|
301
335
|
/** Limits (from limits of api/app; the defaults until then). */
|
|
302
336
|
private readonly limits;
|
|
337
|
+
private readonly clock?;
|
|
338
|
+
private readonly defaultWatchPeriodMs;
|
|
303
339
|
private instanceId;
|
|
340
|
+
private epoch;
|
|
341
|
+
private lastValuesSimMs;
|
|
304
342
|
private readonly stateValue;
|
|
305
343
|
private readonly operationsValue;
|
|
306
344
|
private readonly handles;
|
|
307
345
|
private readonly buckets;
|
|
308
346
|
private readonly readings;
|
|
347
|
+
/** Cached keys kept across a reconnect until a post-reconnect `values` sample arrives. */
|
|
348
|
+
private readonly awaitingRefresh;
|
|
309
349
|
private readonly histories;
|
|
310
|
-
private readonly
|
|
350
|
+
private readonly inFlight;
|
|
351
|
+
private readonly trackers;
|
|
311
352
|
/** Variables someone watches (null: a watch observes all). */
|
|
312
353
|
private watched;
|
|
313
354
|
/** History points requested by watches of all variables (the largest request). */
|
|
@@ -328,12 +369,23 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
|
|
|
328
369
|
watch_period_ms_min?: number;
|
|
329
370
|
watch_period_ms_max?: number;
|
|
330
371
|
watch_variables?: number;
|
|
331
|
-
});
|
|
372
|
+
}, clock?: WriteClockSource | undefined, defaultWatchPeriodMs?: number);
|
|
332
373
|
/** Messages sent right after connecting (after authentication): all current subscriptions. */
|
|
333
374
|
resume(): unknown[];
|
|
334
375
|
/** The client was closed: fail the pending writes (including those waiting for the HTTP answer). Watches stay. */
|
|
335
376
|
dispose(): void;
|
|
336
377
|
onInstance(instance: string): void;
|
|
378
|
+
/**
|
|
379
|
+
* Applies messages belonging to the previous session (`beforeBatch`) while `SessionFeed`
|
|
380
|
+
* still holds that session, and processes connection-level resyncs/watch errors across any
|
|
381
|
+
* superseded intermediate runs (`skippedBatch`) before `SessionFeed` commits the final run.
|
|
382
|
+
*/
|
|
383
|
+
beforeRunSwitch(beforeBatch: readonly unknown[], skippedBatch: readonly unknown[], current?: () => boolean): void;
|
|
384
|
+
/**
|
|
385
|
+
* Clears the previous run's observable variable state synchronously before `SessionFeed`
|
|
386
|
+
* notifies `session` subscribers of a new run, returning the deferred variable notifications.
|
|
387
|
+
*/
|
|
388
|
+
stageRunSwitch(instance: string | null, sessionId: string | null, instanceChanged: boolean): () => void;
|
|
337
389
|
private receive;
|
|
338
390
|
/** Returns whether any state changed. Only the availability table changes: `peers` keeps its identity. */
|
|
339
391
|
private takeAvailability;
|
|
@@ -344,26 +396,38 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
|
|
|
344
396
|
*/
|
|
345
397
|
private forgetLost;
|
|
346
398
|
/**
|
|
347
|
-
* Switched to another run: drop the previous run's values, histories and operations
|
|
348
|
-
*
|
|
349
|
-
* waiting for the previous run's result are failed, since the result will not come.
|
|
399
|
+
* Switched to another run: drop the previous run's values, histories and operations. Writes waiting for the previous
|
|
400
|
+
* run's result are failed, since the result will not come.
|
|
350
401
|
*/
|
|
351
402
|
private enter;
|
|
403
|
+
private prepareEnter;
|
|
352
404
|
private takeValues;
|
|
353
405
|
/** Rebuilds values of the watches that observe the changed variables (all watches if touched is null). */
|
|
354
406
|
private publish;
|
|
355
407
|
private valuesOf;
|
|
408
|
+
private findOperation;
|
|
356
409
|
private withOperation;
|
|
357
|
-
/**
|
|
358
|
-
* Replaces the list of operations and clears the writes whose result has settled. `fresh` holds the operations that
|
|
359
|
-
* just arrived (a batch of notifications, the list in a summary): the list is cut to OPERATIONS_KEPT entries, so
|
|
360
|
-
* settled operations cut from the list are picked up from here.
|
|
361
|
-
*/
|
|
362
410
|
private setOperations;
|
|
363
411
|
private prepareOperations;
|
|
364
|
-
private
|
|
412
|
+
private settleTracker;
|
|
413
|
+
private cleanupWaiter;
|
|
414
|
+
private finishWaiter;
|
|
415
|
+
private currentSimMs;
|
|
416
|
+
private evaluateAllWaiters;
|
|
417
|
+
private evaluateWaiter;
|
|
418
|
+
private waitForApplied;
|
|
419
|
+
enqueue(writes: Record<string, Record<string, number | boolean | string>>, options?: WriteOptions): Promise<QueuedOperation>;
|
|
420
|
+
/**
|
|
421
|
+
* Internal path for `VariableBinder`: invokes `onQueued(seq)` synchronously when the HTTP 200 answer arrives so
|
|
422
|
+
* synchronous widget state (`BoundVariable.writeStatus` / held-value dispatch) transitions in the same turn, then
|
|
423
|
+
* waits on the same four-mode clock-aware watchdog (`waitForApplied`).
|
|
424
|
+
*/
|
|
425
|
+
enqueueForBinder(writes: Record<string, Record<string, number | boolean | string>>, onQueued: (seq: number) => void): Promise<OperationView>;
|
|
426
|
+
private enqueueInternal;
|
|
365
427
|
write(writes: Record<string, Record<string, number | boolean | string>>, options?: WriteOptions): Promise<OperationView>;
|
|
366
428
|
watch(variables: readonly VariableRef[] | 'all', options?: WatchOptions): VariableWatch;
|
|
429
|
+
isStale(ref: VariableRef): boolean;
|
|
430
|
+
runEpoch(): number;
|
|
367
431
|
/**
|
|
368
432
|
* Turns a requested interval into the longest of WATCH_PERIODS_MS that is not longer, kept within the server's range
|
|
369
433
|
* (lower and upper limit).
|
|
@@ -380,5 +444,6 @@ export declare class VariablesFeed implements Omit<ClientVariables, 'bind'> {
|
|
|
380
444
|
private watchMessage;
|
|
381
445
|
/** After watches were added or removed, brings the server subscriptions in line, once for all changes. */
|
|
382
446
|
private queueSync;
|
|
447
|
+
private resyncWatches;
|
|
383
448
|
private sync;
|
|
384
449
|
}
|