@operato/ops-contract 0.9.48 → 0.9.50

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,83 @@
1
+ import type { ISOTime } from './contract.ts';
2
+ export interface TravelState {
3
+ /** The last location on the route network this equipment passed. */
4
+ lastPassed?: string;
5
+ /** Heading in degrees, 0 <= h < 360, in the published network edition's frame. */
6
+ heading?: number;
7
+ /** Connections reserved ahead, in the order they will be travelled. */
8
+ reservedConnectionIds?: string[];
9
+ link?: TravelLink;
10
+ /** A position the equipment itself reported. Absent in simulation. */
11
+ pose?: ObservedPose;
12
+ }
13
+ export declare const TRAVEL_LINK_STATE: readonly ["online", "stale", "lost"];
14
+ export type TravelLinkState = (typeof TRAVEL_LINK_STATE)[number];
15
+ /** Who said the link state: the source itself, or a judgement from how long it has been silent. */
16
+ export declare const TRAVEL_LINK_JUDGED_BY: readonly ["source", "derived"];
17
+ export type TravelLinkJudgedBy = (typeof TRAVEL_LINK_JUDGED_BY)[number];
18
+ export interface TravelLink {
19
+ state: TravelLinkState;
20
+ /** When anything was last received from this equipment. */
21
+ lastSeenAt: ISOTime;
22
+ /** Where it was then. */
23
+ lastLocation?: string;
24
+ judgedBy: TravelLinkJudgedBy;
25
+ }
26
+ /**
27
+ * A measured position, as the equipment reported it - material for the twin's position correction.
28
+ *
29
+ * This does not break the rule that geometry stays out of the contract: the contract computes nothing from coordinates. It only
30
+ * carries what a source observed, tagged with the network edition whose map frame the numbers are in. Poses from different
31
+ * editions are not compared.
32
+ */
33
+ export interface ObservedPose {
34
+ /** Metres. */
35
+ x: number;
36
+ /** Metres. */
37
+ y: number;
38
+ /** Radians. */
39
+ theta: number;
40
+ networkVersion: string;
41
+ at: ISOTime;
42
+ /** Position uncertainty the source reported, metres. */
43
+ deviationM?: number;
44
+ }
45
+ /** The equipment passed a location of the route network. Carries `lastPassed` and `heading`. */
46
+ export interface TravelPassedFact {
47
+ equipmentId: string;
48
+ location: string;
49
+ heading?: number;
50
+ }
51
+ /** The connections now reserved ahead - the whole list, replacing the previous one. An empty list releases all. */
52
+ export interface TravelReservationFact {
53
+ equipmentId: string;
54
+ connectionIds: string[];
55
+ }
56
+ /** The link state changed. */
57
+ export interface TravelLinkFact {
58
+ equipmentId: string;
59
+ link: TravelLink;
60
+ }
61
+ /** A pose the equipment reported. */
62
+ export interface TravelPoseFact {
63
+ equipmentId: string;
64
+ pose: ObservedPose;
65
+ }
66
+ export interface TravelLinkThresholds {
67
+ /** Silent longer than this: `stale`. */
68
+ staleAfterMs: number;
69
+ /** Silent longer than this: `lost`. Must be >= staleAfterMs. */
70
+ lostAfterMs: number;
71
+ }
72
+ /**
73
+ * The link state at `nowTime`.
74
+ *
75
+ * A state the source gave (`judgedBy: 'source'`) is returned as it is - a judgement never overrides what the source said. Otherwise
76
+ * the state is judged from how long the equipment has been silent and marked `derived`.
77
+ *
78
+ * Returns `undefined` when it cannot judge: no `nowTime` (the twin's own clock - a consumer that substitutes wall-clock time gets
79
+ * nonsense in a simulated twin), an unreadable time, or thresholds that do not make sense.
80
+ */
81
+ export declare function linkStateAt(link: TravelLink, nowTime: ISOTime | undefined, thresholds: TravelLinkThresholds): TravelLink | undefined;
82
+ /** Whether a heading is a number in [0, 360). */
83
+ export declare function isHeading(v: unknown): v is number;
package/dist/travel.js ADDED
@@ -0,0 +1,32 @@
1
+ export const TRAVEL_LINK_STATE = ['online', 'stale', 'lost'];
2
+ /** Who said the link state: the source itself, or a judgement from how long it has been silent. */
3
+ export const TRAVEL_LINK_JUDGED_BY = ['source', 'derived'];
4
+ /**
5
+ * The link state at `nowTime`.
6
+ *
7
+ * A state the source gave (`judgedBy: 'source'`) is returned as it is - a judgement never overrides what the source said. Otherwise
8
+ * the state is judged from how long the equipment has been silent and marked `derived`.
9
+ *
10
+ * Returns `undefined` when it cannot judge: no `nowTime` (the twin's own clock - a consumer that substitutes wall-clock time gets
11
+ * nonsense in a simulated twin), an unreadable time, or thresholds that do not make sense.
12
+ */
13
+ export function linkStateAt(link, nowTime, thresholds) {
14
+ if (link.judgedBy === 'source')
15
+ return link;
16
+ if (!nowTime)
17
+ return undefined;
18
+ const now = Date.parse(nowTime);
19
+ const seen = Date.parse(link.lastSeenAt);
20
+ const { staleAfterMs, lostAfterMs } = thresholds;
21
+ if (!Number.isFinite(now) || !Number.isFinite(seen))
22
+ return undefined;
23
+ if (!(staleAfterMs >= 0 && lostAfterMs >= staleAfterMs))
24
+ return undefined;
25
+ const silentMs = now - seen;
26
+ const state = silentMs > lostAfterMs ? 'lost' : silentMs > staleAfterMs ? 'stale' : 'online';
27
+ return { ...link, state, judgedBy: 'derived' };
28
+ }
29
+ /** Whether a heading is a number in [0, 360). */
30
+ export function isHeading(v) {
31
+ return typeof v === 'number' && Number.isFinite(v) && v >= 0 && v < 360;
32
+ }
@@ -57,7 +57,7 @@ export type YardMode = (typeof YARD_MODE)[number];
57
57
  /**
58
58
  * 예약의 **상태** — 닫힌 목록.
59
59
  *
60
- * 끝나는 낱말 둘(`completed` · `cancelled`)은 계약의 `ORDER_TERMINAL_STATUS` 와 **같은 낱말**이다. 다르게 쓰면 `isOrderTerminal` 이
60
+ * 끝나는 낱말 둘(`completed` · `cancelled`)은 계약의 `ORDER_TERMINAL_STATUS` 에 **든 낱말**이다. 다르게 쓰면 `isOrderTerminal` 이
61
61
  * 그것을 모르고 트윈에서 그 예약은 영영 열린 오더가 된다.
62
62
  */
63
63
  export declare const YMS_APPOINTMENT_STATUS: readonly ["scheduled", "checked-in", "at-door", "completed", "cancelled"];
@@ -91,7 +91,7 @@ export const YARD_MODE = ['drop', 'live'];
91
91
  /**
92
92
  * 예약의 **상태** — 닫힌 목록.
93
93
  *
94
- * 끝나는 낱말 둘(`completed` · `cancelled`)은 계약의 `ORDER_TERMINAL_STATUS` 와 **같은 낱말**이다. 다르게 쓰면 `isOrderTerminal` 이
94
+ * 끝나는 낱말 둘(`completed` · `cancelled`)은 계약의 `ORDER_TERMINAL_STATUS` 에 **든 낱말**이다. 다르게 쓰면 `isOrderTerminal` 이
95
95
  * 그것을 모르고 트윈에서 그 예약은 영영 열린 오더가 된다.
96
96
  */
97
97
  export const YMS_APPOINTMENT_STATUS = ['scheduled', 'checked-in', 'at-door', 'completed', 'cancelled'];