@azohra/meteo.station 0.5.0 → 0.7.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.
Files changed (147) hide show
  1. package/README.md +17 -17
  2. package/dist/client/climatology.js +1 -1
  3. package/dist/client/history.js +3 -11
  4. package/dist/client/live.d.ts +2 -1
  5. package/dist/client/live.js +7 -4
  6. package/dist/client/stores.js +10 -2
  7. package/dist/climatology.d.ts +1 -1
  8. package/dist/climatology.js +1 -1
  9. package/dist/connectivity.d.ts +2 -2
  10. package/dist/contract.d.ts +98 -98
  11. package/dist/derive.js +9 -8
  12. package/dist/elements/elements/AirExtremesElement.js +5 -18
  13. package/dist/elements/elements/AirMatrixElement.js +6 -31
  14. package/dist/elements/elements/ClimatologyDailyPatternElement.js +17 -12
  15. package/dist/elements/elements/ClimatologyRoseElement.js +5 -15
  16. package/dist/elements/elements/CompassFanElement.js +5 -64
  17. package/dist/elements/elements/CurrentConditionsElement.js +7 -26
  18. package/dist/elements/elements/DailyPatternElement.d.ts +0 -1
  19. package/dist/elements/elements/DailyPatternElement.js +6 -120
  20. package/dist/elements/elements/DialElement.js +3 -95
  21. package/dist/elements/elements/FavorableShareElement.js +6 -21
  22. package/dist/elements/elements/RecentSummariesElement.js +6 -23
  23. package/dist/elements/elements/SparklineElement.d.ts +0 -1
  24. package/dist/elements/elements/SparklineElement.js +4 -39
  25. package/dist/elements/elements/StationCardElement.js +4 -18
  26. package/dist/elements/elements/StationFeedElement.js +4 -2
  27. package/dist/elements/elements/StationStripElement.js +4 -18
  28. package/dist/elements/elements/StationTableElement.js +15 -51
  29. package/dist/elements/elements/TrendChartElement.js +27 -94
  30. package/dist/elements/elements/WindHistoryChartElement.js +29 -189
  31. package/dist/elements/elements/WindRoseElement.d.ts +0 -1
  32. package/dist/elements/elements/WindRoseElement.js +6 -70
  33. package/dist/elements/elements/atoms.js +11 -38
  34. package/dist/elements/index.js +3 -3
  35. package/dist/elements/lib/fragments.js +8 -37
  36. package/dist/elements/lib/h.js +1 -1
  37. package/dist/elements/lib/pinned-cursor.js +48 -0
  38. package/dist/elements/lib/render.js +30 -0
  39. package/dist/fixtures.d.ts +6 -2
  40. package/dist/fixtures.js +30 -2
  41. package/dist/format.js +7 -3
  42. package/dist/geometry.d.ts +1 -1
  43. package/dist/geometry.js +22 -9
  44. package/dist/instruments.js +2 -2
  45. package/dist/react/components/AirExtremes.d.ts +1 -1
  46. package/dist/react/components/AirExtremes.js +5 -22
  47. package/dist/react/components/AirMatrix.js +10 -43
  48. package/dist/react/components/ClimatologyDailyPattern.d.ts +1 -1
  49. package/dist/react/components/ClimatologyDailyPattern.js +19 -13
  50. package/dist/react/components/ClimatologyRose.d.ts +1 -1
  51. package/dist/react/components/ClimatologyRose.js +11 -28
  52. package/dist/react/components/CompassFan.d.ts +1 -1
  53. package/dist/react/components/CompassFan.js +6 -73
  54. package/dist/react/components/CurrentConditions.d.ts +1 -1
  55. package/dist/react/components/CurrentConditions.js +11 -74
  56. package/dist/react/components/DailyPattern.d.ts +1 -3
  57. package/dist/react/components/DailyPattern.js +10 -149
  58. package/dist/react/components/Dial.d.ts +2 -3
  59. package/dist/react/components/Dial.js +5 -118
  60. package/dist/react/components/FavorableShare.d.ts +1 -1
  61. package/dist/react/components/FavorableShare.js +6 -27
  62. package/dist/react/components/FreshnessBadge.d.ts +1 -1
  63. package/dist/react/components/FreshnessBadge.js +5 -12
  64. package/dist/react/components/RecentSummaries.d.ts +1 -1
  65. package/dist/react/components/RecentSummaries.js +6 -44
  66. package/dist/react/components/SceneTree.js +38 -0
  67. package/dist/react/components/Sparkline.d.ts +1 -1
  68. package/dist/react/components/Sparkline.js +3 -39
  69. package/dist/react/components/StationCard.d.ts +2 -2
  70. package/dist/react/components/StationCard.js +5 -45
  71. package/dist/react/components/StationStrip.d.ts +1 -1
  72. package/dist/react/components/StationStrip.js +5 -60
  73. package/dist/react/components/StationTable.js +21 -75
  74. package/dist/react/components/TrendChart.js +13 -86
  75. package/dist/react/components/WindArrow.d.ts +1 -1
  76. package/dist/react/components/WindArrow.js +3 -15
  77. package/dist/react/components/WindHistoryChart.js +12 -205
  78. package/dist/react/components/WindRose.d.ts +1 -3
  79. package/dist/react/components/WindRose.js +6 -89
  80. package/dist/react/components/WindSampleStrip.js +14 -139
  81. package/dist/react/components/atoms.d.ts +5 -5
  82. package/dist/react/components/atoms.js +12 -48
  83. package/dist/react/hooks/useStation.js +28 -50
  84. package/dist/react/hooks/useStationCurrent.js +3 -2
  85. package/dist/react/hooks/useStationFeed.d.ts +0 -1
  86. package/dist/react/hooks/useStationFeed.js +3 -2
  87. package/dist/react/index.d.ts +2 -2
  88. package/dist/react/index.js +7 -7
  89. package/dist/react/lib/cells.js +4 -24
  90. package/dist/react/lib/use-pinned-cursor.js +32 -0
  91. package/dist/samples.js +7 -43
  92. package/dist/scene/air-extremes.js +12 -27
  93. package/dist/scene/air-matrix.js +45 -58
  94. package/dist/scene/card.js +14 -40
  95. package/dist/scene/cells.d.ts +4 -0
  96. package/dist/scene/cells.js +51 -0
  97. package/dist/scene/chart.js +2 -1
  98. package/dist/scene/climatology-pattern.d.ts +1 -2
  99. package/dist/scene/climatology-pattern.js +10 -11
  100. package/dist/scene/climatology-rose.d.ts +1 -2
  101. package/dist/scene/climatology-rose.js +14 -33
  102. package/dist/scene/compass-fan.js +28 -100
  103. package/dist/scene/current.d.ts +2 -1
  104. package/dist/scene/current.js +29 -56
  105. package/dist/scene/daily-pattern.d.ts +1 -3
  106. package/dist/scene/daily-pattern.js +20 -27
  107. package/dist/scene/dial-parts.d.ts +1 -0
  108. package/dist/scene/dial-parts.js +70 -0
  109. package/dist/scene/dial.d.ts +1 -2
  110. package/dist/scene/dial.js +48 -136
  111. package/dist/scene/favorable-share.js +16 -33
  112. package/dist/scene/glyphs.js +20 -16
  113. package/dist/scene/index.d.ts +5 -3
  114. package/dist/scene/node.js +19 -0
  115. package/dist/scene/recent-summaries.js +26 -66
  116. package/dist/scene/rose.js +89 -117
  117. package/dist/scene/sample-strip.d.ts +1 -2
  118. package/dist/scene/sample-strip.js +35 -36
  119. package/dist/scene/sparkline.js +31 -40
  120. package/dist/scene/strip.js +18 -57
  121. package/dist/scene/table.js +47 -69
  122. package/dist/scene/trend.d.ts +1 -2
  123. package/dist/scene/trend.js +29 -55
  124. package/dist/scene/wind-history.d.ts +1 -2
  125. package/dist/scene/wind-history.js +41 -51
  126. package/dist/scene/wind-plot.js +70 -140
  127. package/dist/server/adapters/campbell.d.ts +7 -7
  128. package/dist/server/adapters/campbell.js +1 -1
  129. package/dist/server/adapters/ecowitt.d.ts +8 -8
  130. package/dist/server/adapters/tempest.d.ts +6 -6
  131. package/dist/server/adapters/windnerd-climatology.js +4 -3
  132. package/dist/server/adapters/windnerd-live.js +3 -2
  133. package/dist/server/adapters/windnerd.d.ts +10 -11
  134. package/dist/server/adapters/windnerd.js +3 -13
  135. package/dist/server/config.d.ts +48 -48
  136. package/dist/server/hologram.js +2 -1
  137. package/dist/server/index.d.ts +2 -2
  138. package/dist/server/index.js +2 -2
  139. package/dist/windnerd.d.ts +3 -1
  140. package/dist/windnerd.js +11 -1
  141. package/package.json +7 -12
  142. package/schema/README.md +3 -3
  143. package/schema/stationclimatology.schema.json +64 -61
  144. package/schema/stationcurrent.schema.json +68 -156
  145. package/schema/stationfeed.schema.json +71 -163
  146. package/schema/stationhistory.schema.json +37 -46
  147. package/schema/stationlive.schema.json +221 -306
package/README.md CHANGED
@@ -1,23 +1,24 @@
1
1
  # `@azohra/meteo.station`
2
2
 
3
- The **station** capability of meteo by Azohra: one wire contract, vendor
4
- adapters that normalize into it (WindNerd, WeatherFlow Tempest, Campbell
5
- Scientific loggers, Ecowitt, or your own), a mountable `Request → Response` handler
6
- that serves the whole inventory as a single feed, and hooks and components
7
- that render it natively, in your design system, with no vendor iframe.
3
+ Live weather stations for meteo by Azohra. Adapters read WindNerd,
4
+ WeatherFlow Tempest, Campbell Scientific loggers, Ecowitt, or your own
5
+ hardware and convert it to one wire contract. A handler you mount on your
6
+ server serves every station as a single feed, and React components or
7
+ custom elements render that feed on your page in your own styles, without a
8
+ vendor iframe.
8
9
 
9
10
  ## Surface
10
11
 
11
12
  | Entry point | What it is |
12
13
  |---|---|
13
- | `@azohra/meteo.station` | The isomorphic root: the wire contract (zod), the standalone connectivity contract (`StationConnectivity` — cellular backhaul health for the operator's own routes, never the public feed), pure derivations (period stats, compass, freshness, unit and threshold conversion), framework-free chart and instrument geometry, and the shared display rules (strings, formatting, air sentences, display resolution, merge policy) every binding renders from. |
14
- | `@azohra/meteo.station/client` | The framework-free client data layer: `createJsonPoller` and the station stores (`createStationFeedStore`, `createStationCurrentStore`, `createStationStore`) every binding subscribes to. Client-only at runtime, import-safe anywhere. |
15
- | `@azohra/meteo.station/server` | Vendor adapters plus the custom-adapter interface and `defineStationAdapter`, data-level `loadStationFeed()` / `loadStationCurrent()`, the Hologram connectivity loader (`loadHologramConnectivity`), and the mountable feed handler. Server-only, so it can never leak into a client bundle. |
14
+ | `@azohra/meteo.station` | Runs on server and client. The wire contract (zod); the separate connectivity contract, `StationConnectivity`, which reports cellular backhaul health on the operator's own routes and is never part of the public feed; pure derivations (period stats, compass, freshness, unit and threshold conversion); chart and instrument geometry; and the display rules both bindings share (strings, formatting, air sentences, display resolution, merge policy). |
15
+ | `@azohra/meteo.station/client` | The framework-free client data layer: `createJsonPoller` and the station stores (`createStationFeedStore`, `createStationCurrentStore`, `createStationStore`) every binding subscribes to. It runs only in the browser but is safe to import anywhere. |
16
+ | `@azohra/meteo.station/server` | Vendor adapters plus the custom-adapter interface and `defineStationAdapter`, data-level `loadStationFeed()` / `loadStationCurrent()`, the Hologram connectivity loader (`loadHologramConnectivity`), and the mountable feed handler. It is server-only, so it cannot end up in a client bundle. |
16
17
  | `@azohra/meteo.station/react` | `StationFeedProvider`, polling hooks (`useStation`, `useStationFeed`, `useStationCurrent`), the component set (`StationCard`, `CurrentConditions`, `WindHistoryChart`, `WindSampleStrip`, `TrendChart`, `WindRose`, `DailyPattern`, `StationTable`, `StationStrip`, `AirMatrix`, `FreshnessBadge`), and an atoms layer of inline primitives (`Speed`, `Gust`, `Lull`, `Temperature`, `Pressure`, `Direction`, `UpdatedAt`, `BandChip`, `Dial`, `Sparkline`, `Readout`) for composing your own layouts. |
17
- | `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), a full peer of the react binding, framework-free, held byte-identical by a parity suite. `/register` is the auto-defining one-liner. |
18
+ | `@azohra/meteo.station/elements` | The same surface as light-DOM custom elements (`<meteo-station-feed>`, `<meteo-station-card>`, `<meteo-station-table>`, the charts, the atoms…), with the same features as the React binding and no framework. A parity suite keeps the two byte-identical. Import `/register` to define every element. |
18
19
  | `@azohra/meteo.station/styles.css` | The default skin (an intentional side effect), shared by both bindings. |
19
20
 
20
- ## Taste
21
+ ## Example
21
22
 
22
23
  ```tsx
23
24
  import { StationFeedProvider, useStation, StationCard } from "@azohra/meteo.station/react";
@@ -39,15 +40,14 @@ function LiveWind() {
39
40
 
40
41
  ## Documentation
41
42
 
42
- Station's reference lives in [`docs/`](docs/) and is served at
43
- <https://meteo.azohra.com/docs/station/>.
44
-
45
- JSON Schema for the wire documents lives in [`../schema/`](../schema/).
43
+ The documentation is in [`docs/`](docs/) and published at
44
+ <https://meteo.azohra.com/docs/station/>. JSON Schema for the wire
45
+ documents is in [`schema/`](schema/).
46
46
 
47
47
  ## Stability
48
48
 
49
- Pre-1.0: the wire contract and environment helpers are stable; handler
50
- internals are not. Pin a minor version if you reach past the documented
51
- surface.
49
+ The package is pre-1.0. The wire contract and environment helpers are
50
+ stable, and the handler's internals are not. Pin a minor version if you use
51
+ anything beyond the documented surface.
52
52
 
53
53
  MIT © Justin Watts
@@ -1,6 +1,6 @@
1
1
  import { parseStationClimatologyJson } from "../contract-climatology.js";
2
+ import { REQUEST_TIMEOUT_MS } from "./poll.js";
2
3
  //#region src/client/climatology.ts
3
- const REQUEST_TIMEOUT_MS = 15e3;
4
4
  /**
5
5
  * Fetch-once store for the climatology document: near-immutable history
6
6
  * needs no poller. Every filter interaction re-aggregates the held cube
@@ -1,7 +1,8 @@
1
1
  import { parseStationHistoryJson } from "../contract.js";
2
2
  import { historyEndpoint } from "../endpoints.js";
3
+ import { WINDNERD_RECORD_PERIODS_MINUTES } from "../windnerd.js";
4
+ import { REQUEST_TIMEOUT_MS } from "./poll.js";
3
5
  //#region src/client/history.ts
4
- const REQUEST_TIMEOUT_MS = 15e3;
5
6
  const HISTORY_STORE_DEFAULT_MAX_WINDOWS = 32;
6
7
  /** The default fetcher, against the mounted handler's /history route. */
7
8
  function stationHistoryFetcher(base, stationId, fetchInit) {
@@ -52,16 +53,7 @@ function createStationHistoryStore(fetcher, options = {}) {
52
53
  size: () => held.size
53
54
  };
54
55
  }
55
- const ARCHIVE_DEFAULT_PERIODS_MINUTES = [
56
- 1,
57
- 5,
58
- 10,
59
- 15,
60
- 30,
61
- 60,
62
- 180,
63
- 360
64
- ];
56
+ const ARCHIVE_DEFAULT_PERIODS_MINUTES = WINDNERD_RECORD_PERIODS_MINUTES;
65
57
  const ARCHIVE_TARGET_POINTS = 500;
66
58
  const DAY_MS = 864e5;
67
59
  /** The finest ladder period that keeps the span at or under the point
@@ -9,6 +9,7 @@ type StationLiveSnapshot = {
9
9
  status: LiveStatus;
10
10
  station: Station | null;
11
11
  samples: LiveSample[];
12
+ sampleIntervalSeconds: number | null;
12
13
  servedAt: string | null;
13
14
  receivedAtMs: number | null;
14
15
  error: PollError | null;
@@ -32,6 +33,6 @@ declare function createStationLiveStore(base: string, stationId: string, options
32
33
  fetchInit?: FetchInitOption;
33
34
  windowSeconds?: number;
34
35
  }): StationLiveStore;
35
- declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples">): StationCurrent | null;
36
+ declare function liveSnapshotToCurrent(live: Pick<StationLiveSnapshot, "station" | "servedAt" | "samples" | "sampleIntervalSeconds">): StationCurrent | null;
36
37
  //#endregion
37
38
  export { LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, LiveStatus, StationLiveSnapshot, StationLiveStore, createStationLiveStore, liveSnapshotToCurrent };
@@ -21,6 +21,7 @@ function createStationLiveStore(base, stationId, options = {}) {
21
21
  status: "stopped",
22
22
  station: null,
23
23
  samples: [],
24
+ sampleIntervalSeconds: null,
24
25
  servedAt: null,
25
26
  receivedAtMs: null,
26
27
  error: null
@@ -36,11 +37,12 @@ function createStationLiveStore(base, stationId, options = {}) {
36
37
  switch (frame.type) {
37
38
  case "init": {
38
39
  current.attempt = 0;
39
- const points = frame.station.status === "ok" ? frame.station.samples?.points ?? [] : [];
40
+ const ring = frame.station.status === "ok" ? frame.station.samples ?? null : null;
40
41
  setSnapshot({
41
42
  status: "open",
42
43
  station: frame.station,
43
- samples: mergeSamples(snapshot.samples, points, windowSeconds),
44
+ samples: mergeSamples(snapshot.samples, ring?.points ?? [], windowSeconds),
45
+ sampleIntervalSeconds: ring?.intervalSeconds ?? snapshot.sampleIntervalSeconds,
44
46
  servedAt: frame.servedAt,
45
47
  receivedAtMs: Date.now(),
46
48
  error: null
@@ -52,6 +54,7 @@ function createStationLiveStore(base, stationId, options = {}) {
52
54
  ...snapshot,
53
55
  status: "open",
54
56
  samples: mergeSamples(snapshot.samples, frame.samples.points, windowSeconds),
57
+ sampleIntervalSeconds: frame.samples.intervalSeconds,
55
58
  receivedAtMs: Date.now(),
56
59
  error: null
57
60
  });
@@ -225,10 +228,10 @@ function createStationLiveStore(base, stationId, options = {}) {
225
228
  }
226
229
  function liveSnapshotToCurrent(live) {
227
230
  if (live.station == null || live.servedAt == null) return null;
228
- const station = live.station.status === "ok" && live.samples.length > 0 ? {
231
+ const station = live.station.status === "ok" && live.samples.length > 0 && live.sampleIntervalSeconds != null ? {
229
232
  ...live.station,
230
233
  samples: {
231
- intervalSeconds: live.station.samples?.intervalSeconds ?? 3,
234
+ intervalSeconds: live.sampleIntervalSeconds,
232
235
  points: live.samples
233
236
  }
234
237
  } : live.station;
@@ -80,6 +80,7 @@ function liveCurrentLeg(base, stationId, fetchInit) {
80
80
  error: null,
81
81
  receivedAtMs: null
82
82
  };
83
+ let running = false;
83
84
  const toCurrent = (live) => {
84
85
  const data = liveSnapshotToCurrent(live);
85
86
  return {
@@ -98,9 +99,16 @@ function liveCurrentLeg(base, stationId, fetchInit) {
98
99
  return mapped;
99
100
  },
100
101
  subscribe: (listener) => liveStore.subscribe(listener),
101
- start: () => liveStore.start(),
102
- stop: () => liveStore.stop(),
102
+ start: () => {
103
+ running = true;
104
+ liveStore.start();
105
+ },
106
+ stop: () => {
107
+ running = false;
108
+ liveStore.stop();
109
+ },
103
110
  refresh: () => {
111
+ if (!running) return;
104
112
  liveStore.stop();
105
113
  liveStore.start();
106
114
  }
@@ -60,7 +60,7 @@ declare function coveredSlotCountByYear(accumulator: ClimatologyAccumulator): Ma
60
60
  declare function climatologyCoverage(document: StationClimatology): ClimatologyCoverage;
61
61
  /** The share of the filtered non-calm record blowing from inside the
62
62
  * consumer's arcs, judged at each sector's centre bearing; null when
63
- * nothing non-calm was recorded — absence over a fabricated zero. */
63
+ * nothing non-calm was recorded. */
64
64
  declare function climatologyFavorableShare(document: StationClimatology, arcs: ReadonlyArray<DirectionArc>, filters?: ClimatologyFilters): number | null;
65
65
  //#endregion
66
66
  export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };
@@ -214,7 +214,7 @@ function climatologyCoverage(document) {
214
214
  }
215
215
  /** The share of the filtered non-calm record blowing from inside the
216
216
  * consumer's arcs, judged at each sector's centre bearing; null when
217
- * nothing non-calm was recorded — absence over a fabricated zero. */
217
+ * nothing non-calm was recorded. */
218
218
  function climatologyFavorableShare(document, arcs, filters) {
219
219
  if (arcs.length === 0) return null;
220
220
  const sectorWidth = 360 / document.sectorCount;
@@ -18,11 +18,11 @@ declare const stationConnectivitySchema: z.ZodObject<{
18
18
  radioTechnology: z.ZodNullable<z.ZodString>;
19
19
  sim: z.ZodObject<{
20
20
  service: z.ZodEnum<{
21
- unknown: "unknown";
22
21
  active: "active";
23
- paused: "paused";
24
22
  inactive: "inactive";
23
+ paused: "paused";
25
24
  retired: "retired";
25
+ unknown: "unknown";
26
26
  }>;
27
27
  vendorState: z.ZodNullable<z.ZodString>;
28
28
  expiresAt: z.ZodNullable<z.ZodString>;
@@ -166,6 +166,30 @@ declare const stationMetaSchema: z.ZodObject<{
166
166
  }, z.core.$strip>;
167
167
  type StationMeta = z.infer<typeof stationMetaSchema>;
168
168
  declare const stationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
169
+ id: z.ZodString;
170
+ name: z.ZodString;
171
+ sourceLabel: z.ZodString;
172
+ pageUrl: z.ZodNullable<z.ZodString>;
173
+ latitude: z.ZodNullable<z.ZodNumber>;
174
+ longitude: z.ZodNullable<z.ZodNumber>;
175
+ timeZone: z.ZodNullable<z.ZodString>;
176
+ elevationM: z.ZodNullable<z.ZodNumber>;
177
+ declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
178
+ fromDeg: z.ZodNumber;
179
+ toDeg: z.ZodNumber;
180
+ }, z.core.$strip>>>>;
181
+ broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
182
+ capabilities: z.ZodObject<{
183
+ gustLull: z.ZodBoolean;
184
+ temperature: z.ZodBoolean;
185
+ conditions: z.ZodBoolean;
186
+ history: z.ZodBoolean;
187
+ live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
188
+ battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
189
+ recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
190
+ }, z.core.$strip>;
191
+ samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
192
+ recommendedPollSeconds: z.ZodNumber;
169
193
  status: z.ZodLiteral<"ok">;
170
194
  reading: z.ZodObject<{
171
195
  observedAt: z.ZodString;
@@ -241,6 +265,7 @@ declare const stationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
265
  seaLevelPressureMaxHpa: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
242
266
  }, z.core.$strip>>;
243
267
  }, z.core.$strip>>>>;
268
+ }, z.core.$strip>, z.ZodObject<{
244
269
  id: z.ZodString;
245
270
  name: z.ZodString;
246
271
  sourceLabel: z.ZodString;
@@ -265,41 +290,16 @@ declare const stationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
265
290
  }, z.core.$strip>;
266
291
  samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
267
292
  recommendedPollSeconds: z.ZodNumber;
268
- }, z.core.$strip>, z.ZodObject<{
269
293
  status: z.ZodLiteral<"unavailable">;
270
294
  reason: z.ZodEnum<{
271
- upstream_error: "upstream_error";
272
- timeout: "timeout";
273
- rate_limited: "rate_limited";
274
295
  contract_break: "contract_break";
275
296
  not_configured: "not_configured";
297
+ rate_limited: "rate_limited";
298
+ timeout: "timeout";
299
+ upstream_error: "upstream_error";
276
300
  }>;
277
301
  reading: z.ZodNull;
278
302
  history: z.ZodNull;
279
- id: z.ZodString;
280
- name: z.ZodString;
281
- sourceLabel: z.ZodString;
282
- pageUrl: z.ZodNullable<z.ZodString>;
283
- latitude: z.ZodNullable<z.ZodNumber>;
284
- longitude: z.ZodNullable<z.ZodNumber>;
285
- timeZone: z.ZodNullable<z.ZodString>;
286
- elevationM: z.ZodNullable<z.ZodNumber>;
287
- declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
288
- fromDeg: z.ZodNumber;
289
- toDeg: z.ZodNumber;
290
- }, z.core.$strip>>>>;
291
- broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
292
- capabilities: z.ZodObject<{
293
- gustLull: z.ZodBoolean;
294
- temperature: z.ZodBoolean;
295
- conditions: z.ZodBoolean;
296
- history: z.ZodBoolean;
297
- live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
298
- battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
299
- recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
300
- }, z.core.$strip>;
301
- samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
302
- recommendedPollSeconds: z.ZodNumber;
303
303
  }, z.core.$strip>], "status">;
304
304
  type Station = z.infer<typeof stationSchema>;
305
305
  declare const stationFeedSchema: z.ZodObject<{
@@ -307,6 +307,30 @@ declare const stationFeedSchema: z.ZodObject<{
307
307
  servedAt: z.ZodString;
308
308
  primaryStationId: z.ZodNullable<z.ZodString>;
309
309
  stations: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
310
+ id: z.ZodString;
311
+ name: z.ZodString;
312
+ sourceLabel: z.ZodString;
313
+ pageUrl: z.ZodNullable<z.ZodString>;
314
+ latitude: z.ZodNullable<z.ZodNumber>;
315
+ longitude: z.ZodNullable<z.ZodNumber>;
316
+ timeZone: z.ZodNullable<z.ZodString>;
317
+ elevationM: z.ZodNullable<z.ZodNumber>;
318
+ declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
319
+ fromDeg: z.ZodNumber;
320
+ toDeg: z.ZodNumber;
321
+ }, z.core.$strip>>>>;
322
+ broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
323
+ capabilities: z.ZodObject<{
324
+ gustLull: z.ZodBoolean;
325
+ temperature: z.ZodBoolean;
326
+ conditions: z.ZodBoolean;
327
+ history: z.ZodBoolean;
328
+ live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
329
+ battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
330
+ recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
331
+ }, z.core.$strip>;
332
+ samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
333
+ recommendedPollSeconds: z.ZodNumber;
310
334
  status: z.ZodLiteral<"ok">;
311
335
  reading: z.ZodObject<{
312
336
  observedAt: z.ZodString;
@@ -382,6 +406,7 @@ declare const stationFeedSchema: z.ZodObject<{
382
406
  seaLevelPressureMaxHpa: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
383
407
  }, z.core.$strip>>;
384
408
  }, z.core.$strip>>>>;
409
+ }, z.core.$strip>, z.ZodObject<{
385
410
  id: z.ZodString;
386
411
  name: z.ZodString;
387
412
  sourceLabel: z.ZodString;
@@ -406,17 +431,23 @@ declare const stationFeedSchema: z.ZodObject<{
406
431
  }, z.core.$strip>;
407
432
  samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
408
433
  recommendedPollSeconds: z.ZodNumber;
409
- }, z.core.$strip>, z.ZodObject<{
410
434
  status: z.ZodLiteral<"unavailable">;
411
435
  reason: z.ZodEnum<{
412
- upstream_error: "upstream_error";
413
- timeout: "timeout";
414
- rate_limited: "rate_limited";
415
436
  contract_break: "contract_break";
416
437
  not_configured: "not_configured";
438
+ rate_limited: "rate_limited";
439
+ timeout: "timeout";
440
+ upstream_error: "upstream_error";
417
441
  }>;
418
442
  reading: z.ZodNull;
419
443
  history: z.ZodNull;
444
+ }, z.core.$strip>], "status">>;
445
+ }, z.core.$strip>;
446
+ type StationFeed = z.infer<typeof stationFeedSchema>;
447
+ declare const stationCurrentSchema: z.ZodObject<{
448
+ schemaVersion: z.ZodLiteral<2>;
449
+ servedAt: z.ZodString;
450
+ station: z.ZodDiscriminatedUnion<[z.ZodObject<{
420
451
  id: z.ZodString;
421
452
  name: z.ZodString;
422
453
  sourceLabel: z.ZodString;
@@ -441,13 +472,6 @@ declare const stationFeedSchema: z.ZodObject<{
441
472
  }, z.core.$strip>;
442
473
  samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
443
474
  recommendedPollSeconds: z.ZodNumber;
444
- }, z.core.$strip>], "status">>;
445
- }, z.core.$strip>;
446
- type StationFeed = z.infer<typeof stationFeedSchema>;
447
- declare const stationCurrentSchema: z.ZodObject<{
448
- schemaVersion: z.ZodLiteral<2>;
449
- servedAt: z.ZodString;
450
- station: z.ZodDiscriminatedUnion<[z.ZodObject<{
451
475
  status: z.ZodLiteral<"ok">;
452
476
  reading: z.ZodObject<{
453
477
  observedAt: z.ZodString;
@@ -523,6 +547,7 @@ declare const stationCurrentSchema: z.ZodObject<{
523
547
  seaLevelPressureMaxHpa: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
524
548
  }, z.core.$strip>>;
525
549
  }, z.core.$strip>>>>;
550
+ }, z.core.$strip>, z.ZodObject<{
526
551
  id: z.ZodString;
527
552
  name: z.ZodString;
528
553
  sourceLabel: z.ZodString;
@@ -547,41 +572,16 @@ declare const stationCurrentSchema: z.ZodObject<{
547
572
  }, z.core.$strip>;
548
573
  samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
549
574
  recommendedPollSeconds: z.ZodNumber;
550
- }, z.core.$strip>, z.ZodObject<{
551
575
  status: z.ZodLiteral<"unavailable">;
552
576
  reason: z.ZodEnum<{
553
- upstream_error: "upstream_error";
554
- timeout: "timeout";
555
- rate_limited: "rate_limited";
556
577
  contract_break: "contract_break";
557
578
  not_configured: "not_configured";
579
+ rate_limited: "rate_limited";
580
+ timeout: "timeout";
581
+ upstream_error: "upstream_error";
558
582
  }>;
559
583
  reading: z.ZodNull;
560
584
  history: z.ZodNull;
561
- id: z.ZodString;
562
- name: z.ZodString;
563
- sourceLabel: z.ZodString;
564
- pageUrl: z.ZodNullable<z.ZodString>;
565
- latitude: z.ZodNullable<z.ZodNumber>;
566
- longitude: z.ZodNullable<z.ZodNumber>;
567
- timeZone: z.ZodNullable<z.ZodString>;
568
- elevationM: z.ZodNullable<z.ZodNumber>;
569
- declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
570
- fromDeg: z.ZodNumber;
571
- toDeg: z.ZodNumber;
572
- }, z.core.$strip>>>>;
573
- broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
574
- capabilities: z.ZodObject<{
575
- gustLull: z.ZodBoolean;
576
- temperature: z.ZodBoolean;
577
- conditions: z.ZodBoolean;
578
- history: z.ZodBoolean;
579
- live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
580
- battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
581
- recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
582
- }, z.core.$strip>;
583
- samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
584
- recommendedPollSeconds: z.ZodNumber;
585
585
  }, z.core.$strip>], "status">;
586
586
  }, z.core.$strip>;
587
587
  type StationCurrent = z.infer<typeof stationCurrentSchema>;
@@ -615,6 +615,30 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
615
615
  schemaVersion: z.ZodLiteral<2>;
616
616
  servedAt: z.ZodString;
617
617
  station: z.ZodDiscriminatedUnion<[z.ZodObject<{
618
+ id: z.ZodString;
619
+ name: z.ZodString;
620
+ sourceLabel: z.ZodString;
621
+ pageUrl: z.ZodNullable<z.ZodString>;
622
+ latitude: z.ZodNullable<z.ZodNumber>;
623
+ longitude: z.ZodNullable<z.ZodNumber>;
624
+ timeZone: z.ZodNullable<z.ZodString>;
625
+ elevationM: z.ZodNullable<z.ZodNumber>;
626
+ declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
627
+ fromDeg: z.ZodNumber;
628
+ toDeg: z.ZodNumber;
629
+ }, z.core.$strip>>>>;
630
+ broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
631
+ capabilities: z.ZodObject<{
632
+ gustLull: z.ZodBoolean;
633
+ temperature: z.ZodBoolean;
634
+ conditions: z.ZodBoolean;
635
+ history: z.ZodBoolean;
636
+ live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
637
+ battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
638
+ recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
639
+ }, z.core.$strip>;
640
+ samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
641
+ recommendedPollSeconds: z.ZodNumber;
618
642
  status: z.ZodLiteral<"ok">;
619
643
  reading: z.ZodObject<{
620
644
  observedAt: z.ZodString;
@@ -690,6 +714,7 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
690
714
  seaLevelPressureMaxHpa: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
691
715
  }, z.core.$strip>>;
692
716
  }, z.core.$strip>>>>;
717
+ }, z.core.$strip>, z.ZodObject<{
693
718
  id: z.ZodString;
694
719
  name: z.ZodString;
695
720
  sourceLabel: z.ZodString;
@@ -714,41 +739,16 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
714
739
  }, z.core.$strip>;
715
740
  samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
716
741
  recommendedPollSeconds: z.ZodNumber;
717
- }, z.core.$strip>, z.ZodObject<{
718
742
  status: z.ZodLiteral<"unavailable">;
719
743
  reason: z.ZodEnum<{
720
- upstream_error: "upstream_error";
721
- timeout: "timeout";
722
- rate_limited: "rate_limited";
723
744
  contract_break: "contract_break";
724
745
  not_configured: "not_configured";
746
+ rate_limited: "rate_limited";
747
+ timeout: "timeout";
748
+ upstream_error: "upstream_error";
725
749
  }>;
726
750
  reading: z.ZodNull;
727
751
  history: z.ZodNull;
728
- id: z.ZodString;
729
- name: z.ZodString;
730
- sourceLabel: z.ZodString;
731
- pageUrl: z.ZodNullable<z.ZodString>;
732
- latitude: z.ZodNullable<z.ZodNumber>;
733
- longitude: z.ZodNullable<z.ZodNumber>;
734
- timeZone: z.ZodNullable<z.ZodString>;
735
- elevationM: z.ZodNullable<z.ZodNumber>;
736
- declaredFavorableDirections: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
737
- fromDeg: z.ZodNumber;
738
- toDeg: z.ZodNumber;
739
- }, z.core.$strip>>>>;
740
- broadcastDelaySeconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
741
- capabilities: z.ZodObject<{
742
- gustLull: z.ZodBoolean;
743
- temperature: z.ZodBoolean;
744
- conditions: z.ZodBoolean;
745
- history: z.ZodBoolean;
746
- live: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
747
- battery: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
748
- recentSummaries: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
749
- }, z.core.$strip>;
750
- samplingWindowSeconds: z.ZodNullable<z.ZodNumber>;
751
- recommendedPollSeconds: z.ZodNumber;
752
752
  }, z.core.$strip>], "status">;
753
753
  }, z.core.$strip>, z.ZodObject<{
754
754
  type: z.ZodLiteral<"samples">;
@@ -825,11 +825,11 @@ declare const stationLiveFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
825
825
  type: z.ZodLiteral<"unavailable">;
826
826
  stationId: z.ZodString;
827
827
  reason: z.ZodEnum<{
828
- upstream_error: "upstream_error";
829
- timeout: "timeout";
830
- rate_limited: "rate_limited";
831
828
  contract_break: "contract_break";
832
829
  not_configured: "not_configured";
830
+ rate_limited: "rate_limited";
831
+ timeout: "timeout";
832
+ upstream_error: "upstream_error";
833
833
  }>;
834
834
  }, z.core.$strip>], "type">;
835
835
  type StationLiveFrame = z.infer<typeof stationLiveFrameSchema>;
package/dist/derive.js CHANGED
@@ -150,24 +150,25 @@ function lastNightLowC(points, latitude, longitude, nowMs) {
150
150
  return null;
151
151
  }
152
152
  const DEFAULT_FRESHNESS_THRESHOLDS = {
153
- currentForMs: 10 * 6e4,
154
- staleAfterMs: 45 * 6e4
153
+ currentForMs: 6e5,
154
+ staleAfterMs: 27e5
155
155
  };
156
156
  const clampMs = (value, low, high) => Math.min(high, Math.max(low, value));
157
157
  function stationFreshnessThresholds(meta) {
158
- const currentForMs = clampMs(meta.recommendedPollSeconds * 5 * 1e3, 6e4, 10 * 6e4);
158
+ const currentForMs = clampMs(meta.recommendedPollSeconds * 5 * 1e3, 6e4, 6e5);
159
159
  return {
160
160
  currentForMs,
161
- staleAfterMs: clampMs(currentForMs * 6, 10 * 6e4, 45 * 6e4)
161
+ staleAfterMs: clampMs(currentForMs * 6, 6e5, 27e5)
162
162
  };
163
163
  }
164
+ function anchoredAgeMs(input) {
165
+ return Math.max(0, Date.parse(input.servedAt) - Date.parse(input.observedAt)) + Math.max(0, input.nowMs - input.receivedAtMs);
166
+ }
164
167
  function freshness(input, thresholds = DEFAULT_FRESHNESS_THRESHOLDS) {
165
- const ageAtServeMs = Date.parse(input.servedAt) - Date.parse(input.observedAt);
166
- const sinceReceivedMs = Math.max(0, input.nowMs - input.receivedAtMs);
167
- const ageMs = Math.max(0, ageAtServeMs) + sinceReceivedMs;
168
+ const ageMs = anchoredAgeMs(input);
168
169
  if (ageMs <= thresholds.currentForMs) return "live";
169
170
  if (ageMs <= thresholds.staleAfterMs) return "aging";
170
171
  return "stale";
171
172
  }
172
173
  //#endregion
173
- export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
174
+ export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, anchoredAgeMs, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
@@ -1,32 +1,19 @@
1
1
  import { resolveStation } from "../../display.js";
2
- import { airExtremesGate, airExtremesScene } from "../../scene/air-extremes.js";
2
+ import { airExtremesScene } from "../../scene/air-extremes.js";
3
3
  import { MeteoStationElement } from "../lib/base.js";
4
- import { h } from "../lib/h.js";
4
+ import { renderOptional } from "../lib/render.js";
5
5
  //#region src/elements/elements/AirExtremesElement.ts
6
6
  var AirExtremesElement = class extends MeteoStationElement {
7
7
  static observedAttributes = ["now-ms", "station-id"];
8
8
  render() {
9
9
  const station = this.station ?? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0) ?? void 0;
10
10
  const { words } = this.display();
11
- const gate = airExtremesGate(station);
12
- if (gate.kind === "hidden") {
13
- this.replaceChildren();
14
- return;
15
- }
16
11
  const nowAttribute = Number(this.getAttribute("now-ms"));
17
- const scene = airExtremesScene({
12
+ this.replaceChildren(...renderOptional(airExtremesScene({
18
13
  nowMs: Number.isFinite(nowAttribute) && nowAttribute > 0 ? nowAttribute : Date.now(),
19
- station: gate.station,
14
+ station,
20
15
  words
21
- });
22
- if (scene == null) {
23
- this.replaceChildren();
24
- return;
25
- }
26
- this.replaceChildren(h("dl", {
27
- "aria-label": scene.ariaLabel,
28
- class: scene.className
29
- }, scene.tiles.map((tile) => h("div", { class: tile.className }, h("dt", { class: "meteo-microlabel" }, tile.label), h("dd", { class: "meteo-air-extremes-value" }, tile.value)))));
16
+ })));
30
17
  }
31
18
  };
32
19
  //#endregion