@azohra/meteo.station 0.1.1 → 0.1.3
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/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +2 -1
- package/dist/client/live.d.ts +37 -0
- package/dist/client/live.js +241 -0
- package/dist/client/stores.d.ts +1 -0
- package/dist/client/stores.js +41 -6
- package/dist/contract.d.ts +237 -1
- package/dist/contract.js +57 -3
- package/dist/endpoints.d.ts +2 -1
- package/dist/endpoints.js +4 -1
- package/dist/geometry.d.ts +4 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/react/hooks/useStation.d.ts +1 -0
- package/dist/react/hooks/useStation.js +25 -5
- package/dist/react/hooks/useStationLive.d.ts +20 -0
- package/dist/react/hooks/useStationLive.js +33 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/samples.d.ts +20 -0
- package/dist/samples.js +88 -0
- package/dist/server/adapter.d.ts +3 -1
- package/dist/server/adapter.js +3 -1
- package/dist/server/adapters/windnerd-live.d.ts +21 -0
- package/dist/server/adapters/windnerd-live.js +179 -0
- package/dist/server/adapters/windnerd.d.ts +36 -5
- package/dist/server/adapters/windnerd.js +177 -15
- package/dist/server/config.d.ts +2 -0
- package/dist/server/config.js +2 -1
- package/dist/server/environment.d.ts +25 -5
- package/dist/server/environment.js +65 -21
- package/dist/server/feed.d.ts +20 -2
- package/dist/server/feed.js +28 -1
- package/dist/server/handler.d.ts +1 -1
- package/dist/server/handler.js +37 -3
- package/dist/server/index.d.ts +6 -4
- package/dist/server/index.js +6 -4
- package/dist/server/live.d.ts +15 -0
- package/dist/server/live.js +19 -0
- package/dist/sse.js +56 -0
- package/package.json +1 -1
- package/schema/README.md +1 -1
- package/schema/example-feed.json +26 -1
- package/schema/example-live.json +74 -0
- package/schema/stationcurrent.schema.json +115 -0
- package/schema/stationfeed.schema.json +115 -0
- package/schema/stationlive.schema.json +868 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { emptyConditions } from "../../contract.js";
|
|
2
2
|
import { isCalm, normalizeDegrees, pressureTendency, seaLevelPressureHpa } from "../../derive.js";
|
|
3
3
|
import { windnerdStationUrl } from "../../windnerd.js";
|
|
4
|
-
import {
|
|
4
|
+
import { sseEvents } from "../../sse.js";
|
|
5
|
+
import { coalesceUpstreamLoad, fetchUpstreamStream, fetchUpstreamText, logUpstreamFailure } from "../environment.js";
|
|
5
6
|
import { defineStationAdapter } from "../adapter.js";
|
|
6
|
-
import {
|
|
7
|
+
import { UpstreamError } from "@azohra/meteo.core";
|
|
7
8
|
//#region src/server/adapters/windnerd.ts
|
|
8
9
|
const WINDNERD_RECORDS_URL = "https://windnerd.net/api/records";
|
|
10
|
+
const WINDNERD_LIVE_URL = "https://windnerd.net/api/live-url";
|
|
9
11
|
const RECORD_PERIOD_MINUTES = 1;
|
|
10
12
|
const WINDNERD_RECORD_PERIODS_MINUTES = [
|
|
11
13
|
1,
|
|
@@ -15,13 +17,19 @@ const WINDNERD_RECORD_PERIODS_MINUTES = [
|
|
|
15
17
|
];
|
|
16
18
|
const CACHE_TTL_SECONDS = 60;
|
|
17
19
|
const AGGREGATE_CACHE_TTL_SECONDS = 900;
|
|
20
|
+
const LIVE_CACHE_TTL_SECONDS = 15;
|
|
21
|
+
const WINDNERD_LIVE_INIT_TIMEOUT_MS = 8e3;
|
|
22
|
+
const WINDNERD_LIVE_SAMPLE_INTERVAL_SECONDS = 3;
|
|
18
23
|
const SENSOR_VALUE_LOOKBACK_MS = 15 * 6e4;
|
|
24
|
+
const MAX_WIND_MPS = 140;
|
|
19
25
|
const STATION_PRESSURE_MIN_HPA = 300;
|
|
20
26
|
const STATION_PRESSURE_MAX_HPA = 1100;
|
|
27
|
+
const BATTERY_VOLTAGE_MIN = 0;
|
|
28
|
+
const BATTERY_VOLTAGE_MAX = 100;
|
|
21
29
|
const UTC_OFFSET_MIN_MINUTES = -720;
|
|
22
30
|
const UTC_OFFSET_MAX_MINUTES = 840;
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
function windnerdStationMeta(config) {
|
|
32
|
+
return {
|
|
25
33
|
id: config.id,
|
|
26
34
|
name: config.name,
|
|
27
35
|
sourceLabel: "WindNerd",
|
|
@@ -34,12 +42,22 @@ const loadWindnerdStation = defineStationAdapter({
|
|
|
34
42
|
gustLull: true,
|
|
35
43
|
temperature: config.hasTemperature,
|
|
36
44
|
conditions: config.hasPressure,
|
|
37
|
-
history: true
|
|
45
|
+
history: true,
|
|
46
|
+
live: true,
|
|
47
|
+
battery: config.hasBattery
|
|
38
48
|
},
|
|
39
49
|
samplingWindowSeconds: 60,
|
|
40
50
|
recommendedPollSeconds: 60
|
|
41
|
-
}
|
|
42
|
-
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const loadWindnerdStation = defineStationAdapter({
|
|
54
|
+
meta: windnerdStationMeta,
|
|
55
|
+
load: async (config, { environment, historyHours, mode, options }) => {
|
|
56
|
+
if (mode === "current") try {
|
|
57
|
+
return await loadWindnerdLiveCurrent(config, environment, options);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logUpstreamFailure(environment, `${config.name} live current unavailable, serving records`, error, { station: config.id });
|
|
60
|
+
}
|
|
43
61
|
const periodMinutes = options.recordPeriodMinutes ?? RECORD_PERIOD_MINUTES;
|
|
44
62
|
if (!WINDNERD_RECORD_PERIODS_MINUTES.includes(periodMinutes)) throw new Error(`WindNerd location ${config.locationId}: recordPeriodMinutes must be one of ${WINDNERD_RECORD_PERIODS_MINUTES.join(", ")}, got ${periodMinutes}`);
|
|
45
63
|
const now = environment.now();
|
|
@@ -79,13 +97,13 @@ const loadWindnerdStation = defineStationAdapter({
|
|
|
79
97
|
function windnerdHistoryPoints(records, config) {
|
|
80
98
|
const barometerElevationM = config.hasPressure ? config.elevationM ?? null : null;
|
|
81
99
|
return records.observedAt.map((observedAt, index) => {
|
|
82
|
-
const windAvgMps =
|
|
100
|
+
const windAvgMps = records.averageSpeedMps[index];
|
|
83
101
|
const stationPressure = records.stationPressureHpa[index] ?? null;
|
|
84
102
|
return {
|
|
85
103
|
observedAt,
|
|
86
104
|
windAvgMps,
|
|
87
|
-
windGustMps:
|
|
88
|
-
windLullMps:
|
|
105
|
+
windGustMps: records.gustSpeedMps[index],
|
|
106
|
+
windLullMps: records.lullSpeedMps[index],
|
|
89
107
|
windDirectionDeg: isCalm(windAvgMps) ? null : normalizeDegrees(records.windDirectionDeg[index]),
|
|
90
108
|
temperatureC: config.hasTemperature ? records.temperatureC[index] ?? null : null,
|
|
91
109
|
seaLevelPressureHpa: barometerElevationM != null && stationPressure != null ? seaLevelPressureHpa(stationPressure, barometerElevationM, records.temperatureC[index] ?? null) : null
|
|
@@ -100,6 +118,150 @@ function windnerdConditions(records, points, config, readingObservedAtMs) {
|
|
|
100
118
|
seaLevelPressureHpa: reduced
|
|
101
119
|
});
|
|
102
120
|
}
|
|
121
|
+
function windnerdLiveStreamUrl(config, base = WINDNERD_LIVE_URL) {
|
|
122
|
+
const trimmed = base.endsWith("/") ? base.slice(0, -1) : base;
|
|
123
|
+
return new URL(`${trimmed}/${encodeURIComponent(config.stationKey)}`);
|
|
124
|
+
}
|
|
125
|
+
function parseWindnerdLiveInit(value, locationId) {
|
|
126
|
+
let data;
|
|
127
|
+
try {
|
|
128
|
+
data = JSON.parse(value);
|
|
129
|
+
} catch {
|
|
130
|
+
throw new Error(`WindNerd location ${locationId} returned an unparseable live frame`);
|
|
131
|
+
}
|
|
132
|
+
if (!isRecord(data) || data.type !== "INIT") throw new Error(`WindNerd location ${locationId} returned no live init frame`);
|
|
133
|
+
return {
|
|
134
|
+
digest: parseWindnerdLiveDigest(data.digest, locationId),
|
|
135
|
+
samples: parseWindnerdLiveSampleRecords(data.samples, locationId)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function parseWindnerdLiveDigest(value, locationId) {
|
|
139
|
+
const fail = (name) => {
|
|
140
|
+
throw new Error(`WindNerd location ${locationId} returned an invalid live ${name}`);
|
|
141
|
+
};
|
|
142
|
+
if (!isRecord(value) || !isRecord(value.recent)) fail("digest");
|
|
143
|
+
const digest = value;
|
|
144
|
+
const recent = digest.recent;
|
|
145
|
+
const rangeOrNull = (entry, minimum, maximum, name) => {
|
|
146
|
+
if (entry == null) return null;
|
|
147
|
+
if (typeof entry !== "number" || !Number.isFinite(entry) || entry < minimum || entry > maximum) fail(name);
|
|
148
|
+
return entry;
|
|
149
|
+
};
|
|
150
|
+
if (typeof recent.date_utc !== "string") fail("digest time");
|
|
151
|
+
const observedAt = recordTimeToIso(recent.date_utc, locationId);
|
|
152
|
+
const minutes = Array.isArray(digest.last_10mn_by_1mn) ? digest.last_10mn_by_1mn : [];
|
|
153
|
+
const lastMinute = minutes.length > 0 ? minutes[minutes.length - 1] : null;
|
|
154
|
+
const wind = isRecord(lastMinute) ? lastMinute : recent;
|
|
155
|
+
const windAvgMps = rangeOrNull(wind.wind_avg_1D, 0, MAX_WIND_MPS, "wind_avg_1D") ?? rangeOrNull(wind.wind_avg_2D, 0, MAX_WIND_MPS, "wind_avg_2D") ?? fail("wind average");
|
|
156
|
+
const windDirectionDeg = rangeOrNull(wind.wind_dir, 0, 360, "wind_dir") ?? fail("wind_dir");
|
|
157
|
+
return {
|
|
158
|
+
observedAt,
|
|
159
|
+
windAvgMps,
|
|
160
|
+
gustMps: rangeOrNull(wind.wind_max, 0, MAX_WIND_MPS, "wind_max"),
|
|
161
|
+
lullMps: rangeOrNull(wind.wind_min, 0, MAX_WIND_MPS, "wind_min"),
|
|
162
|
+
windDirectionDeg,
|
|
163
|
+
temperatureC: rangeOrNull(recent.temperature, -Infinity, Infinity, "temperature"),
|
|
164
|
+
stationPressureHpa: rangeOrNull(recent.pressure_hpa, STATION_PRESSURE_MIN_HPA, STATION_PRESSURE_MAX_HPA, "pressure_hpa"),
|
|
165
|
+
batteryVoltage: rangeOrNull(recent.voltage, BATTERY_VOLTAGE_MIN, BATTERY_VOLTAGE_MAX, "voltage")
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function parseWindnerdLiveSampleRecords(value, locationId) {
|
|
169
|
+
const fail = (name) => {
|
|
170
|
+
throw new Error(`WindNerd location ${locationId} returned an invalid live ${name}`);
|
|
171
|
+
};
|
|
172
|
+
if (!Array.isArray(value)) fail("samples");
|
|
173
|
+
return value.filter((entry) => entry != null).map((entry) => {
|
|
174
|
+
if (!isRecord(entry) || typeof entry.ts !== "string") fail("sample");
|
|
175
|
+
const record = entry;
|
|
176
|
+
const speedMps = record.sp;
|
|
177
|
+
const directionDeg = record.dir;
|
|
178
|
+
if (typeof speedMps !== "number" || !Number.isFinite(speedMps) || speedMps < 0 || speedMps > MAX_WIND_MPS) fail("sample sp");
|
|
179
|
+
if (typeof directionDeg !== "number" || !Number.isFinite(directionDeg) || directionDeg < 0 || directionDeg > 360) fail("sample dir");
|
|
180
|
+
return {
|
|
181
|
+
observedAt: recordTimeToIso(record.ts, locationId),
|
|
182
|
+
speedMps,
|
|
183
|
+
directionDeg
|
|
184
|
+
};
|
|
185
|
+
}).sort((a, b) => Date.parse(a.observedAt) - Date.parse(b.observedAt));
|
|
186
|
+
}
|
|
187
|
+
function windnerdLiveReading(digest, config) {
|
|
188
|
+
const windAvgMps = digest.windAvgMps;
|
|
189
|
+
return {
|
|
190
|
+
reading: {
|
|
191
|
+
observedAt: digest.observedAt,
|
|
192
|
+
windAvgMps,
|
|
193
|
+
windDirectionDeg: isCalm(windAvgMps) ? null : normalizeDegrees(digest.windDirectionDeg),
|
|
194
|
+
windGustMps: digest.gustMps,
|
|
195
|
+
windLullMps: digest.lullMps,
|
|
196
|
+
temperatureC: config.hasTemperature ? digest.temperatureC : null,
|
|
197
|
+
windChillC: null,
|
|
198
|
+
conditions: config.hasPressure ? emptyConditions({ seaLevelPressureHpa: digest.stationPressureHpa != null && config.elevationM != null ? seaLevelPressureHpa(digest.stationPressureHpa, config.elevationM, digest.temperatureC) : null }) : null
|
|
199
|
+
},
|
|
200
|
+
telemetry: config.hasBattery ? { batteryVoltage: digest.batteryVoltage } : null
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function windnerdLiveSamples(records) {
|
|
204
|
+
return {
|
|
205
|
+
intervalSeconds: 3,
|
|
206
|
+
points: records.map((record) => {
|
|
207
|
+
const windMps = record.speedMps;
|
|
208
|
+
return {
|
|
209
|
+
observedAt: record.observedAt,
|
|
210
|
+
windMps,
|
|
211
|
+
windDirectionDeg: isCalm(windMps) ? null : normalizeDegrees(record.directionDeg)
|
|
212
|
+
};
|
|
213
|
+
})
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
async function loadWindnerdLiveCurrent(config, environment, options) {
|
|
217
|
+
const init = parseWindnerdLiveInit(await fetchWindnerdLiveInitText(config, environment, options), config.locationId);
|
|
218
|
+
const { reading, telemetry } = windnerdLiveReading(init.digest, config);
|
|
219
|
+
return {
|
|
220
|
+
reading,
|
|
221
|
+
history: null,
|
|
222
|
+
telemetry,
|
|
223
|
+
samples: windnerdLiveSamples(init.samples),
|
|
224
|
+
meta: { recommendedPollSeconds: 15 }
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
async function fetchWindnerdLiveInitText(config, environment, options) {
|
|
228
|
+
const cacheKey = `windnerd/live/${config.locationId}`;
|
|
229
|
+
const cached = await environment.cache.get(cacheKey);
|
|
230
|
+
if (cached != null) return cached;
|
|
231
|
+
return coalesceUpstreamLoad(environment.cache, cacheKey, async () => {
|
|
232
|
+
const subject = `WindNerd location ${config.locationId} live stream`;
|
|
233
|
+
const controller = new AbortController();
|
|
234
|
+
const timer = setTimeout(() => controller.abort(), WINDNERD_LIVE_INIT_TIMEOUT_MS);
|
|
235
|
+
try {
|
|
236
|
+
const body = (await fetchUpstreamStream(environment, {
|
|
237
|
+
url: windnerdLiveStreamUrl(config, options.liveUrl),
|
|
238
|
+
subject,
|
|
239
|
+
signal: controller.signal
|
|
240
|
+
})).body;
|
|
241
|
+
for await (const event of sseEvents(body, { signal: controller.signal })) {
|
|
242
|
+
if (event.event !== "message") continue;
|
|
243
|
+
let type;
|
|
244
|
+
try {
|
|
245
|
+
const frame = JSON.parse(event.data);
|
|
246
|
+
type = isRecord(frame) ? frame.type : void 0;
|
|
247
|
+
} catch {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (type === "INIT") {
|
|
251
|
+
await environment.cache.put(cacheKey, event.data, LIVE_CACHE_TTL_SECONDS);
|
|
252
|
+
return event.data;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
throw new UpstreamError(`${subject} ended before its init frame`);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (controller.signal.aborted && !(error instanceof UpstreamError)) throw new UpstreamError(`${subject} timed out`, "timeout");
|
|
258
|
+
throw error;
|
|
259
|
+
} finally {
|
|
260
|
+
clearTimeout(timer);
|
|
261
|
+
controller.abort();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
103
265
|
function parseWindnerdRecords(value, locationId, hasPressure = false) {
|
|
104
266
|
const data = JSON.parse(value);
|
|
105
267
|
if (!isRecord(data) || !isRecord(data.records)) throw new Error(`WindNerd location ${locationId} returned no records`);
|
|
@@ -109,12 +271,12 @@ function parseWindnerdRecords(value, locationId, hasPressure = false) {
|
|
|
109
271
|
const fail = (name) => {
|
|
110
272
|
throw new Error(`WindNerd location ${locationId} returned an invalid ${name}`);
|
|
111
273
|
};
|
|
112
|
-
const speeds = (name) => numberSeries(records[name], dates.length, 0,
|
|
274
|
+
const speeds = (name) => numberSeries(records[name], dates.length, 0, MAX_WIND_MPS, name, fail);
|
|
113
275
|
return {
|
|
114
|
-
|
|
276
|
+
averageSpeedMps: speeds("wind_avg_1D"),
|
|
115
277
|
windDirectionDeg: numberSeries(records.wind_dir, dates.length, 0, 360, "wind_dir", fail),
|
|
116
|
-
|
|
117
|
-
|
|
278
|
+
gustSpeedMps: speeds("wind_max"),
|
|
279
|
+
lullSpeedMps: speeds("wind_min"),
|
|
118
280
|
observedAt: dates.map((date) => recordTimeToIso(date, locationId)),
|
|
119
281
|
temperatureC: nullableSeries(records.temperature_avg, dates.length, "temperature_avg", fail),
|
|
120
282
|
stationPressureHpa: hasPressure ? nullableSeries(records.pressure_hpa_avg, dates.length, "pressure_hpa_avg", fail, STATION_PRESSURE_MIN_HPA, STATION_PRESSURE_MAX_HPA) : dates.map(() => null),
|
|
@@ -156,4 +318,4 @@ function isRecord(value) {
|
|
|
156
318
|
return typeof value === "object" && value !== null;
|
|
157
319
|
}
|
|
158
320
|
//#endregion
|
|
159
|
-
export { WINDNERD_RECORD_PERIODS_MINUTES, loadWindnerdStation, parseWindnerdRecords, windnerdHistoryPoints };
|
|
321
|
+
export { WINDNERD_LIVE_INIT_TIMEOUT_MS, WINDNERD_LIVE_SAMPLE_INTERVAL_SECONDS, WINDNERD_RECORD_PERIODS_MINUTES, loadWindnerdStation, parseWindnerdLiveDigest, parseWindnerdLiveInit, parseWindnerdLiveSampleRecords, parseWindnerdRecords, windnerdHistoryPoints, windnerdLiveReading, windnerdLiveSamples, windnerdLiveStreamUrl, windnerdStationMeta };
|
package/dist/server/config.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare const windnerdStationConfigSchema: z.ZodObject<{
|
|
|
8
8
|
locationId: z.ZodNumber;
|
|
9
9
|
hasTemperature: z.ZodDefault<z.ZodBoolean>;
|
|
10
10
|
hasPressure: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
hasBattery: z.ZodDefault<z.ZodBoolean>;
|
|
11
12
|
timeZone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
13
|
pageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
14
|
elevationM: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
@@ -82,6 +83,7 @@ declare const stationConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
82
83
|
locationId: z.ZodNumber;
|
|
83
84
|
hasTemperature: z.ZodDefault<z.ZodBoolean>;
|
|
84
85
|
hasPressure: z.ZodDefault<z.ZodBoolean>;
|
|
86
|
+
hasBattery: z.ZodDefault<z.ZodBoolean>;
|
|
85
87
|
timeZone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
86
88
|
pageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
87
89
|
elevationM: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
package/dist/server/config.js
CHANGED
|
@@ -16,7 +16,8 @@ const windnerdStationConfigSchema = z.strictObject({
|
|
|
16
16
|
stationKey: windnerdStationKey,
|
|
17
17
|
locationId: z.number().int().positive(),
|
|
18
18
|
hasTemperature: z.boolean().default(true),
|
|
19
|
-
hasPressure: z.boolean().default(false)
|
|
19
|
+
hasPressure: z.boolean().default(false),
|
|
20
|
+
hasBattery: z.boolean().default(false)
|
|
20
21
|
}).refine((config) => !config.hasPressure || config.elevationM != null, {
|
|
21
22
|
message: "pressure needs the sensor's elevation to reduce to sea level — set elevationM to the sensor's elevation, not the launch's",
|
|
22
23
|
path: ["elevationM"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UPSTREAM_FAILURE_REASONS as UPSTREAM_FAILURE_REASONS$1, UpstreamError, UpstreamErrorReason, UpstreamFailureReason, unavailableReasonForError } from "@azohra/meteo.core";
|
|
1
|
+
import { UPSTREAM_FAILURE_REASONS as UPSTREAM_FAILURE_REASONS$1, UpstreamError as UpstreamError$1, UpstreamErrorReason, UpstreamFailureReason, unavailableReasonForError } from "@azohra/meteo.core";
|
|
2
2
|
//#region src/server/environment.d.ts
|
|
3
3
|
type FeedCache = {
|
|
4
4
|
get(key: string): Promise<string | null>;
|
|
@@ -37,12 +37,32 @@ type UpstreamTextRequest = {
|
|
|
37
37
|
limitBytes?: number;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
40
|
+
* Coalesces concurrent misses on the same (cache instance, key) onto a single
|
|
41
|
+
* in-flight load. The load owns its own cache fill; this only deduplicates.
|
|
42
|
+
*/
|
|
43
|
+
declare function coalesceUpstreamLoad(cache: FeedCache, key: string, load: () => Promise<string>): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* The one road to an upstream document: cache lookup, bounded fetch under a
|
|
46
|
+
* timeout, cache fill. Concurrent misses on the same (cache instance,
|
|
47
|
+
* cacheKey) coalesce onto a single in-flight load.
|
|
43
48
|
*/
|
|
44
49
|
declare function fetchUpstreamText(environment: ResolvedEnvironment, request: UpstreamTextRequest): Promise<string>;
|
|
50
|
+
type UpstreamStreamRequest = {
|
|
51
|
+
url: string | URL;
|
|
52
|
+
subject: string;
|
|
53
|
+
accept?: string;
|
|
54
|
+
headers?: Record<string, string>;
|
|
55
|
+
connectTimeoutMs?: number;
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
};
|
|
58
|
+
declare const UPSTREAM_CONNECT_TIMEOUT_MS = 10000;
|
|
59
|
+
/**
|
|
60
|
+
* The road to a long-lived upstream body. No cache and no byte cap — the
|
|
61
|
+
* consumer bounds its own buffering — and never coalesced: every caller owns
|
|
62
|
+
* its connection and tears it down through its signal.
|
|
63
|
+
*/
|
|
64
|
+
declare function fetchUpstreamStream(environment: ResolvedEnvironment, request: UpstreamStreamRequest): Promise<Response>;
|
|
45
65
|
declare function boundedResponseText(response: Response, limitBytes: number, subject: string): Promise<string>;
|
|
46
66
|
declare function logUpstreamFailure(environment: ResolvedEnvironment, message: string, error: unknown, detail?: Record<string, unknown>): void;
|
|
47
67
|
//#endregion
|
|
48
|
-
export { DEFAULT_USER_AGENT, FeedCache, LogEvent, LogEventCode, ResolvedEnvironment, ServerEnvironment, UPSTREAM_FAILURE_REASONS$1 as UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError, type UpstreamErrorReason, type UpstreamFailureReason, UpstreamTextRequest, boundedResponseText, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError };
|
|
68
|
+
export { DEFAULT_USER_AGENT, FeedCache, LogEvent, LogEventCode, ResolvedEnvironment, ServerEnvironment, UPSTREAM_CONNECT_TIMEOUT_MS, UPSTREAM_FAILURE_REASONS$1 as UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError$1 as UpstreamError, type UpstreamErrorReason, type UpstreamFailureReason, UpstreamStreamRequest, UpstreamTextRequest, boundedResponseText, coalesceUpstreamLoad, fetchUpstreamStream, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UPSTREAM_FAILURE_REASONS as UPSTREAM_FAILURE_REASONS$1, UpstreamError, unavailableReasonForError } from "@azohra/meteo.core";
|
|
1
|
+
import { UPSTREAM_FAILURE_REASONS as UPSTREAM_FAILURE_REASONS$1, UpstreamError as UpstreamError$1, unavailableReasonForError } from "@azohra/meteo.core";
|
|
2
2
|
//#region src/server/environment.ts
|
|
3
3
|
const UPSTREAM_FETCH_TIMEOUT_MS = 4e3;
|
|
4
4
|
const UPSTREAM_RESPONSE_LIMIT_BYTES = 524288;
|
|
@@ -47,26 +47,33 @@ function resolveEnvironment(environment = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
const inFlightLoads = /* @__PURE__ */ new WeakMap();
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* coalesce onto a single in-flight load.
|
|
50
|
+
* Coalesces concurrent misses on the same (cache instance, key) onto a single
|
|
51
|
+
* in-flight load. The load owns its own cache fill; this only deduplicates.
|
|
53
52
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (cached != null) return cached;
|
|
57
|
-
let pending = inFlightLoads.get(environment.cache);
|
|
53
|
+
function coalesceUpstreamLoad(cache, key, load) {
|
|
54
|
+
let pending = inFlightLoads.get(cache);
|
|
58
55
|
if (!pending) {
|
|
59
56
|
pending = /* @__PURE__ */ new Map();
|
|
60
|
-
inFlightLoads.set(
|
|
57
|
+
inFlightLoads.set(cache, pending);
|
|
61
58
|
}
|
|
62
|
-
const inFlight = pending.get(
|
|
59
|
+
const inFlight = pending.get(key);
|
|
63
60
|
if (inFlight) return inFlight;
|
|
64
61
|
const settled = pending;
|
|
65
|
-
const
|
|
66
|
-
settled.delete(
|
|
62
|
+
const loading = load().finally(() => {
|
|
63
|
+
settled.delete(key);
|
|
67
64
|
});
|
|
68
|
-
pending.set(
|
|
69
|
-
return
|
|
65
|
+
pending.set(key, loading);
|
|
66
|
+
return loading;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The one road to an upstream document: cache lookup, bounded fetch under a
|
|
70
|
+
* timeout, cache fill. Concurrent misses on the same (cache instance,
|
|
71
|
+
* cacheKey) coalesce onto a single in-flight load.
|
|
72
|
+
*/
|
|
73
|
+
async function fetchUpstreamText(environment, request) {
|
|
74
|
+
const cached = await environment.cache.get(request.cacheKey);
|
|
75
|
+
if (cached != null) return cached;
|
|
76
|
+
return coalesceUpstreamLoad(environment.cache, request.cacheKey, () => loadUpstreamText(environment, request));
|
|
70
77
|
}
|
|
71
78
|
async function loadUpstreamText(environment, request) {
|
|
72
79
|
let response;
|
|
@@ -82,23 +89,60 @@ async function loadUpstreamText(environment, request) {
|
|
|
82
89
|
signal: AbortSignal.timeout(request.timeoutMs ?? 4e3)
|
|
83
90
|
});
|
|
84
91
|
} catch (error) {
|
|
85
|
-
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) throw new UpstreamError(`${request.subject} timed out`, "timeout");
|
|
86
|
-
throw new UpstreamError(`${request.subject} could not be reached: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) throw new UpstreamError$1(`${request.subject} timed out`, "timeout");
|
|
93
|
+
throw new UpstreamError$1(`${request.subject} could not be reached: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
94
|
}
|
|
88
95
|
if (!response.ok) {
|
|
89
96
|
try {
|
|
90
97
|
await response.body?.cancel();
|
|
91
98
|
} catch {}
|
|
92
|
-
if (response.status === 429) throw new UpstreamError(`${request.subject} is rate limiting requests`, "rate_limited");
|
|
93
|
-
throw new UpstreamError(`${request.subject} returned ${response.status}`);
|
|
99
|
+
if (response.status === 429) throw new UpstreamError$1(`${request.subject} is rate limiting requests`, "rate_limited");
|
|
100
|
+
throw new UpstreamError$1(`${request.subject} returned ${response.status}`);
|
|
94
101
|
}
|
|
95
102
|
const text = await boundedResponseText(response, request.limitBytes ?? 524288, request.subject);
|
|
96
103
|
await environment.cache.put(request.cacheKey, text, request.cacheTtlSeconds);
|
|
97
104
|
return text;
|
|
98
105
|
}
|
|
106
|
+
const UPSTREAM_CONNECT_TIMEOUT_MS = 1e4;
|
|
107
|
+
/**
|
|
108
|
+
* The road to a long-lived upstream body. No cache and no byte cap — the
|
|
109
|
+
* consumer bounds its own buffering — and never coalesced: every caller owns
|
|
110
|
+
* its connection and tears it down through its signal.
|
|
111
|
+
*/
|
|
112
|
+
async function fetchUpstreamStream(environment, request) {
|
|
113
|
+
const connect = new AbortController();
|
|
114
|
+
const connectTimer = setTimeout(() => connect.abort(), request.connectTimeoutMs ?? 1e4);
|
|
115
|
+
const signal = request.signal ? AbortSignal.any([request.signal, connect.signal]) : connect.signal;
|
|
116
|
+
let response;
|
|
117
|
+
try {
|
|
118
|
+
response = await environment.fetch(request.url, {
|
|
119
|
+
headers: {
|
|
120
|
+
Accept: request.accept ?? "text/event-stream",
|
|
121
|
+
"User-Agent": environment.userAgent,
|
|
122
|
+
...request.headers
|
|
123
|
+
},
|
|
124
|
+
signal
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (request.signal?.aborted) throw error;
|
|
128
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) throw new UpstreamError$1(`${request.subject} timed out`, "timeout");
|
|
129
|
+
throw new UpstreamError$1(`${request.subject} could not be reached: ${error instanceof Error ? error.message : String(error)}`);
|
|
130
|
+
} finally {
|
|
131
|
+
clearTimeout(connectTimer);
|
|
132
|
+
}
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
try {
|
|
135
|
+
await response.body?.cancel();
|
|
136
|
+
} catch {}
|
|
137
|
+
if (response.status === 429) throw new UpstreamError$1(`${request.subject} is rate limiting requests`, "rate_limited");
|
|
138
|
+
throw new UpstreamError$1(`${request.subject} returned ${response.status}`);
|
|
139
|
+
}
|
|
140
|
+
if (!response.body) throw new UpstreamError$1(`${request.subject} returned no body`);
|
|
141
|
+
return response;
|
|
142
|
+
}
|
|
99
143
|
async function boundedResponseText(response, limitBytes, subject) {
|
|
100
144
|
const reader = response.body?.getReader();
|
|
101
|
-
if (!reader) throw new UpstreamError(`${subject} returned no body`);
|
|
145
|
+
if (!reader) throw new UpstreamError$1(`${subject} returned no body`);
|
|
102
146
|
const decoder = new TextDecoder();
|
|
103
147
|
let result = "";
|
|
104
148
|
let totalBytes = 0;
|
|
@@ -108,7 +152,7 @@ async function boundedResponseText(response, limitBytes, subject) {
|
|
|
108
152
|
totalBytes += value.byteLength;
|
|
109
153
|
if (totalBytes > limitBytes) {
|
|
110
154
|
await reader.cancel();
|
|
111
|
-
throw new UpstreamError(`${subject} exceeded the response limit`);
|
|
155
|
+
throw new UpstreamError$1(`${subject} exceeded the response limit`);
|
|
112
156
|
}
|
|
113
157
|
result += decoder.decode(value, { stream: true });
|
|
114
158
|
}
|
|
@@ -125,4 +169,4 @@ function logUpstreamFailure(environment, message, error, detail = {}) {
|
|
|
125
169
|
});
|
|
126
170
|
}
|
|
127
171
|
//#endregion
|
|
128
|
-
export { DEFAULT_USER_AGENT, UPSTREAM_FAILURE_REASONS$1 as UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError, boundedResponseText, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError };
|
|
172
|
+
export { DEFAULT_USER_AGENT, UPSTREAM_CONNECT_TIMEOUT_MS, UPSTREAM_FAILURE_REASONS$1 as UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError$1 as UpstreamError, boundedResponseText, coalesceUpstreamLoad, fetchUpstreamStream, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError };
|
package/dist/server/feed.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Station, StationCurrent, StationFeed } from "../contract.js";
|
|
1
|
+
import { Station, StationCurrent, StationFeed, StationLiveFrame } from "../contract.js";
|
|
2
2
|
import { ResolvedEnvironment, ServerEnvironment } from "./environment.js";
|
|
3
3
|
import { StationConfig, StationConfigInput } from "./config.js";
|
|
4
4
|
//#region src/server/feed.d.ts
|
|
@@ -19,6 +19,24 @@ type LoadStationCurrentOptions = LoadStationFeedOptions & {
|
|
|
19
19
|
declare class UnknownStationError extends Error {
|
|
20
20
|
constructor(stationId: string);
|
|
21
21
|
}
|
|
22
|
+
declare class StationLiveUnsupportedError extends Error {
|
|
23
|
+
constructor(stationId: string);
|
|
24
|
+
}
|
|
25
|
+
type OpenStationLiveOptions = {
|
|
26
|
+
stations: StationsInput;
|
|
27
|
+
stationId: string;
|
|
28
|
+
environment?: ServerEnvironment;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
request?: Request;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Opens the live stream for one configured station. Unknown ids throw
|
|
34
|
+
* UnknownStationError; stations whose vendor has no live arm — and stations
|
|
35
|
+
* whose config failed validation — throw StationLiveUnsupportedError; connect
|
|
36
|
+
* failures reject with the upstream error. One call is one upstream
|
|
37
|
+
* connection.
|
|
38
|
+
*/
|
|
39
|
+
declare function openStationLive(options: OpenStationLiveOptions): Promise<ReadableStream<StationLiveFrame>>;
|
|
22
40
|
declare function loadStationFeed(options: LoadStationFeedOptions): Promise<StationFeed>;
|
|
23
41
|
declare function loadStationCurrent(options: LoadStationCurrentOptions): Promise<StationCurrent>;
|
|
24
42
|
type AssembledStation = {
|
|
@@ -28,4 +46,4 @@ type AssembledStation = {
|
|
|
28
46
|
};
|
|
29
47
|
declare function assembleStations(candidates: StationConfigInput[], environment: ResolvedEnvironment): AssembledStation[];
|
|
30
48
|
//#endregion
|
|
31
|
-
export { DEFAULT_HISTORY_HOURS, LoadStationCurrentOptions, LoadStationFeedOptions, StationsInput, StationsResolver, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed };
|
|
49
|
+
export { DEFAULT_HISTORY_HOURS, LoadStationCurrentOptions, LoadStationFeedOptions, OpenStationLiveOptions, StationLiveUnsupportedError, StationsInput, StationsResolver, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed, openStationLive };
|
package/dist/server/feed.js
CHANGED
|
@@ -4,6 +4,7 @@ import { stationConfigSchema } from "./config.js";
|
|
|
4
4
|
import { loadCampbellStation } from "./adapters/campbell.js";
|
|
5
5
|
import { loadTempestStation } from "./adapters/tempest.js";
|
|
6
6
|
import { loadWindnerdStation } from "./adapters/windnerd.js";
|
|
7
|
+
import { openWindnerdLive } from "./adapters/windnerd-live.js";
|
|
7
8
|
//#region src/server/feed.ts
|
|
8
9
|
const DEFAULT_HISTORY_HOURS = 6;
|
|
9
10
|
var UnknownStationError = class extends Error {
|
|
@@ -12,6 +13,32 @@ var UnknownStationError = class extends Error {
|
|
|
12
13
|
this.name = "UnknownStationError";
|
|
13
14
|
}
|
|
14
15
|
};
|
|
16
|
+
var StationLiveUnsupportedError = class extends Error {
|
|
17
|
+
constructor(stationId) {
|
|
18
|
+
super(`station "${stationId}" has no live stream`);
|
|
19
|
+
this.name = "StationLiveUnsupportedError";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Opens the live stream for one configured station. Unknown ids throw
|
|
24
|
+
* UnknownStationError; stations whose vendor has no live arm — and stations
|
|
25
|
+
* whose config failed validation — throw StationLiveUnsupportedError; connect
|
|
26
|
+
* failures reject with the upstream error. One call is one upstream
|
|
27
|
+
* connection.
|
|
28
|
+
*/
|
|
29
|
+
async function openStationLive(options) {
|
|
30
|
+
const environment = resolveEnvironment(options.environment);
|
|
31
|
+
const entry = assembleStations(await resolveStations({
|
|
32
|
+
stations: options.stations,
|
|
33
|
+
request: options.request
|
|
34
|
+
}, environment), environment).find((candidate) => ("config" in candidate ? candidate.config.id : candidate.degraded.id) === options.stationId);
|
|
35
|
+
if (!entry) throw new UnknownStationError(options.stationId);
|
|
36
|
+
if ("degraded" in entry || entry.config.vendor !== "windnerd") throw new StationLiveUnsupportedError(options.stationId);
|
|
37
|
+
return openWindnerdLive(entry.config, {
|
|
38
|
+
environment,
|
|
39
|
+
signal: options.signal
|
|
40
|
+
});
|
|
41
|
+
}
|
|
15
42
|
async function loadStationFeed(options) {
|
|
16
43
|
const environment = resolveEnvironment(options.environment);
|
|
17
44
|
const assembled = assembleStations(await resolveStations(options, environment), environment);
|
|
@@ -213,4 +240,4 @@ function neverThrewButDid(config, environment, error) {
|
|
|
213
240
|
return unavailableStation(configFallbackMeta(config), "contract_break");
|
|
214
241
|
}
|
|
215
242
|
//#endregion
|
|
216
|
-
export { DEFAULT_HISTORY_HOURS, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed };
|
|
243
|
+
export { DEFAULT_HISTORY_HOURS, StationLiveUnsupportedError, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed, openStationLive };
|
package/dist/server/handler.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerEnvironment } from "./environment.js";
|
|
2
2
|
import { StationsInput } from "./feed.js";
|
|
3
3
|
//#region src/server/handler.d.ts
|
|
4
|
-
type StationFeedHandlerRoute = "feed" | "current";
|
|
4
|
+
type StationFeedHandlerRoute = "feed" | "current" | "live";
|
|
5
5
|
type StationFeedHandlerOptions = {
|
|
6
6
|
stations: StationsInput;
|
|
7
7
|
primaryStationId?: string;
|
package/dist/server/handler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { resolveEnvironment } from "./environment.js";
|
|
2
|
-
import { UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed } from "./feed.js";
|
|
1
|
+
import { resolveEnvironment, unavailableReasonForError } from "./environment.js";
|
|
2
|
+
import { StationLiveUnsupportedError, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed, openStationLive } from "./feed.js";
|
|
3
|
+
import { STATION_LIVE_SSE_HEADERS, encodeStationLiveSse } from "./live.js";
|
|
3
4
|
//#region src/server/handler.ts
|
|
4
5
|
const ALLOWED_METHODS = "GET, HEAD, OPTIONS";
|
|
5
6
|
function createStationFeedHandler(options) {
|
|
@@ -53,8 +54,41 @@ function createStationFeedHandler(options) {
|
|
|
53
54
|
});
|
|
54
55
|
const url = new URL(request.url);
|
|
55
56
|
const pathname = url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname;
|
|
56
|
-
const route = basePath != null ? pathname === `${basePath}/feed` ? "feed" : pathname === `${basePath}/current` ? "current" : null : pathname.endsWith("/feed") ? "feed" : pathname.endsWith("/current") ? "current" : null;
|
|
57
|
+
const route = basePath != null ? pathname === `${basePath}/feed` ? "feed" : pathname === `${basePath}/current` ? "current" : pathname === `${basePath}/live` ? "live" : null : pathname.endsWith("/feed") ? "feed" : pathname.endsWith("/current") ? "current" : pathname.endsWith("/live") ? "live" : null;
|
|
57
58
|
if (!route) return respond({ error: "not found" }, 404);
|
|
59
|
+
if (route === "live") {
|
|
60
|
+
const stationId = url.searchParams.get("station");
|
|
61
|
+
if (!stationId) return respond({ error: "missing station parameter" }, 400);
|
|
62
|
+
const liveHeaders = {
|
|
63
|
+
...baseHeaders(),
|
|
64
|
+
...STATION_LIVE_SSE_HEADERS
|
|
65
|
+
};
|
|
66
|
+
if (isHead) return new Response(null, {
|
|
67
|
+
status: 200,
|
|
68
|
+
headers: liveHeaders
|
|
69
|
+
});
|
|
70
|
+
let frames;
|
|
71
|
+
try {
|
|
72
|
+
frames = await openStationLive({
|
|
73
|
+
stations: options.stations,
|
|
74
|
+
stationId,
|
|
75
|
+
environment: options.environment,
|
|
76
|
+
signal: request.signal,
|
|
77
|
+
request
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof UnknownStationError) return respond({ error: "unknown station" }, 404);
|
|
81
|
+
if (error instanceof StationLiveUnsupportedError) return respond({ error: "station has no live stream" }, 404);
|
|
82
|
+
return respond({
|
|
83
|
+
error: "live stream unavailable",
|
|
84
|
+
reason: unavailableReasonForError(error)
|
|
85
|
+
}, 502);
|
|
86
|
+
}
|
|
87
|
+
return new Response(encodeStationLiveSse(frames), {
|
|
88
|
+
status: 200,
|
|
89
|
+
headers: liveHeaders
|
|
90
|
+
});
|
|
91
|
+
}
|
|
58
92
|
const hours = parseHoursParam(url, maxHistoryHours);
|
|
59
93
|
if (hours == null) return respond({ error: `invalid hours: expected a number in (0, ${maxHistoryHours}]` }, 400);
|
|
60
94
|
const loadOptions = {
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { normalizeWindnerdStationKey, windnerdStationUrl } from "../windnerd.js";
|
|
2
|
-
import { DEFAULT_USER_AGENT, FeedCache, LogEvent, LogEventCode, ResolvedEnvironment, ServerEnvironment, UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError, UpstreamErrorReason, UpstreamFailureReason, UpstreamTextRequest, boundedResponseText, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError } from "./environment.js";
|
|
2
|
+
import { DEFAULT_USER_AGENT, FeedCache, LogEvent, LogEventCode, ResolvedEnvironment, ServerEnvironment, UPSTREAM_CONNECT_TIMEOUT_MS, UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UpstreamError, UpstreamErrorReason, UpstreamFailureReason, UpstreamStreamRequest, UpstreamTextRequest, boundedResponseText, coalesceUpstreamLoad, fetchUpstreamStream, fetchUpstreamText, logUpstreamFailure, memoryCache, resolveEnvironment, unavailableReasonForError } from "./environment.js";
|
|
3
3
|
import { CampbellStationConfig, CustomStationConfig, CustomStationContext, CustomStationIdentity, CustomStationLoader, StationConfig, StationConfigInput, TempestStationConfig, WindnerdStationConfig, campbellStationConfigSchema, customStationConfigSchema, parseStationConfig, stationConfigSchema, tempestStationConfigSchema, windnerdStationConfigSchema } from "./config.js";
|
|
4
4
|
import { StationAdapter, StationAdapterContext, StationAdapterDefinition, StationAdapterMode, StationAdapterOptions, StationAdapterResult, defineStationAdapter } from "./adapter.js";
|
|
5
|
-
import { DEFAULT_HISTORY_HOURS, LoadStationCurrentOptions, LoadStationFeedOptions, StationsInput, StationsResolver, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed } from "./feed.js";
|
|
5
|
+
import { DEFAULT_HISTORY_HOURS, LoadStationCurrentOptions, LoadStationFeedOptions, OpenStationLiveOptions, StationLiveUnsupportedError, StationsInput, StationsResolver, UnknownStationError, assembleStations, loadStationCurrent, loadStationFeed, openStationLive } from "./feed.js";
|
|
6
6
|
import { StationFeedHandler, StationFeedHandlerOptions, StationFeedHandlerRoute, createStationFeedHandler } from "./handler.js";
|
|
7
|
-
import {
|
|
7
|
+
import { STATION_LIVE_SSE_HEADERS, encodeStationLiveSse } from "./live.js";
|
|
8
|
+
import { WindnerdLiveOptions, openWindnerdLive } from "./adapters/windnerd-live.js";
|
|
9
|
+
import { WINDNERD_LIVE_SAMPLE_INTERVAL_SECONDS, WindnerdAdapterOptions, WindnerdLiveDigest, WindnerdLiveInit, WindnerdLiveSampleRecord, WindnerdRecords, loadWindnerdStation, parseWindnerdLiveDigest, parseWindnerdLiveInit, parseWindnerdLiveSampleRecords, parseWindnerdRecords, windnerdHistoryPoints, windnerdLiveReading, windnerdLiveSamples, windnerdLiveStreamUrl } from "./adapters/windnerd.js";
|
|
8
10
|
import { TempestAdapterOptions, TempestObservation, loadTempestStation, parseTempestWind } from "./adapters/tempest.js";
|
|
9
11
|
import { CAMPBELL_FIELD_CONTRACTS, CampbellAdapterOptions, CampbellTable, CampbellTableExpectation, loadCampbellCurrent, loadCampbellStation, naiveLocalToIso, parseCampbellCurrent, parseCampbellHistory, parseCampbellTable } from "./adapters/campbell.js";
|
|
10
|
-
export { CAMPBELL_FIELD_CONTRACTS, type CampbellAdapterOptions, CampbellStationConfig, type CampbellTable, type CampbellTableExpectation, CustomStationConfig, CustomStationContext, CustomStationIdentity, CustomStationLoader, DEFAULT_HISTORY_HOURS, DEFAULT_USER_AGENT, FeedCache, LoadStationCurrentOptions, LoadStationFeedOptions, LogEvent, LogEventCode, ResolvedEnvironment, ServerEnvironment, StationAdapter, StationAdapterContext, StationAdapterDefinition, StationAdapterMode, StationAdapterOptions, StationAdapterResult, StationConfig, StationConfigInput, StationFeedHandler, StationFeedHandlerOptions, StationFeedHandlerRoute, StationsInput, StationsResolver, type TempestAdapterOptions, type TempestObservation, TempestStationConfig, UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UnknownStationError, UpstreamError, type UpstreamErrorReason, type UpstreamFailureReason, UpstreamTextRequest, type WindnerdAdapterOptions, type WindnerdRecords, WindnerdStationConfig, assembleStations, boundedResponseText, campbellStationConfigSchema, createStationFeedHandler, customStationConfigSchema, defineStationAdapter, fetchUpstreamText, loadCampbellCurrent, loadCampbellStation, loadStationCurrent, loadStationFeed, loadTempestStation, loadWindnerdStation, logUpstreamFailure, memoryCache, naiveLocalToIso, normalizeWindnerdStationKey, parseCampbellCurrent, parseCampbellHistory, parseCampbellTable, parseStationConfig, parseTempestWind, parseWindnerdRecords, resolveEnvironment, stationConfigSchema, tempestStationConfigSchema, unavailableReasonForError, windnerdHistoryPoints, windnerdStationConfigSchema, windnerdStationUrl };
|
|
12
|
+
export { CAMPBELL_FIELD_CONTRACTS, type CampbellAdapterOptions, CampbellStationConfig, type CampbellTable, type CampbellTableExpectation, CustomStationConfig, CustomStationContext, CustomStationIdentity, CustomStationLoader, DEFAULT_HISTORY_HOURS, DEFAULT_USER_AGENT, FeedCache, LoadStationCurrentOptions, LoadStationFeedOptions, LogEvent, LogEventCode, OpenStationLiveOptions, ResolvedEnvironment, STATION_LIVE_SSE_HEADERS, ServerEnvironment, StationAdapter, StationAdapterContext, StationAdapterDefinition, StationAdapterMode, StationAdapterOptions, StationAdapterResult, StationConfig, StationConfigInput, StationFeedHandler, StationFeedHandlerOptions, StationFeedHandlerRoute, StationLiveUnsupportedError, StationsInput, StationsResolver, type TempestAdapterOptions, type TempestObservation, TempestStationConfig, UPSTREAM_CONNECT_TIMEOUT_MS, UPSTREAM_FAILURE_REASONS, UPSTREAM_FETCH_TIMEOUT_MS, UPSTREAM_RESPONSE_LIMIT_BYTES, UnknownStationError, UpstreamError, type UpstreamErrorReason, type UpstreamFailureReason, UpstreamStreamRequest, UpstreamTextRequest, WINDNERD_LIVE_SAMPLE_INTERVAL_SECONDS, type WindnerdAdapterOptions, type WindnerdLiveDigest, type WindnerdLiveInit, type WindnerdLiveOptions, type WindnerdLiveSampleRecord, type WindnerdRecords, WindnerdStationConfig, assembleStations, boundedResponseText, campbellStationConfigSchema, coalesceUpstreamLoad, createStationFeedHandler, customStationConfigSchema, defineStationAdapter, encodeStationLiveSse, fetchUpstreamStream, fetchUpstreamText, loadCampbellCurrent, loadCampbellStation, loadStationCurrent, loadStationFeed, loadTempestStation, loadWindnerdStation, logUpstreamFailure, memoryCache, naiveLocalToIso, normalizeWindnerdStationKey, openStationLive, openWindnerdLive, parseCampbellCurrent, parseCampbellHistory, parseCampbellTable, parseStationConfig, parseTempestWind, parseWindnerdLiveDigest, parseWindnerdLiveInit, parseWindnerdLiveSampleRecords, parseWindnerdRecords, resolveEnvironment, stationConfigSchema, tempestStationConfigSchema, unavailableReasonForError, windnerdHistoryPoints, windnerdLiveReading, windnerdLiveSamples, windnerdLiveStreamUrl, windnerdStationConfigSchema, windnerdStationUrl };
|