@sailingnaturali/signalk-currents 0.4.0 → 0.5.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.md CHANGED
@@ -112,6 +112,7 @@ Served at `/signalk/v2/api/resources/currents` (anonymously readable under
112
112
  "lon": -125.1567,
113
113
  "floodDir": 160,
114
114
  "ebbDir": 340,
115
+ "dirsSource": "config",
115
116
  "events": [
116
117
  { "utc": "2026-06-06T04:14:00.000Z", "kind": "slack", "speedKn": 0 },
117
118
  { "utc": "2026-06-06T05:40:00.000Z", "kind": "flood", "speedKn": 4.1 }
@@ -122,8 +123,11 @@ Served at `/signalk/v2/api/resources/currents` (anonymously readable under
122
123
  ```
123
124
 
124
125
  `kind` is `slack` | `flood` | `ebb`; `speedKn` is the event speed magnitude in knots.
125
- `floodDir` / `ebbDir` are the station's set directions in °true, straight from the
126
- station config — so consumers can say which way the water flows, not just when it turns.
126
+ `floodDir` / `ebbDir` are the station's set directions in °true so consumers can say
127
+ which way the water flows, not just when it turns. `dirsSource` says where they came
128
+ from: `"api"` (NOAA-measured) or `"config"`; absent means nobody knows. Config-sourced
129
+ directions may also carry `floodDirEstimated` / `ebbDirEstimated: true` when the config
130
+ value is an assumption (e.g. the reciprocal of a stated flood) — consumers should say so.
127
131
 
128
132
  ## Development
129
133
 
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@ module.exports = function (app) {
27
27
  label: { type: 'string' }, lat: { type: 'number' }, lon: { type: 'number' },
28
28
  floodDir: { type: 'number', title: 'Flood set (°true) — required for CHS; NOAA stations use the API\'s measured meanFloodDir' },
29
29
  ebbDir: { type: 'number', title: 'Ebb set (°true) — required for CHS; NOAA stations use the API\'s measured meanEbbDir' },
30
+ floodDirEstimated: { type: 'boolean', title: 'Flood set is an assumption (not from the tables)' },
31
+ ebbDirEstimated: { type: 'boolean', title: 'Ebb set is an assumption (e.g. reciprocal of flood)' },
30
32
  } },
31
33
  },
32
34
  horizonDays: { type: 'number', default: 3 },
@@ -62,7 +64,11 @@ module.exports = function (app) {
62
64
  try {
63
65
  const data = await (0, fetch_1.stationData)(station, now, horizonDays, cache);
64
66
  // Provider-measured set directions (NOAA) beat the config values.
65
- series.set(station.stationId, { station: (0, types_1.resolveStation)(station, data), events: data.events });
67
+ series.set(station.stationId, {
68
+ station: (0, types_1.resolveStation)(station, data),
69
+ events: data.events,
70
+ dirsSource: (0, types_1.dirsSource)(station, data),
71
+ });
66
72
  }
67
73
  catch (e) {
68
74
  app.error(`station ${station.label} fetch failed: ${e.message}`);
package/dist/routes.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { StationConfig, CurrentEvent } from './types';
1
+ import { StationConfig, CurrentEvent, DirsSource } from './types';
2
2
  export interface StationSeries {
3
3
  station: StationConfig;
4
4
  events: CurrentEvent[];
5
+ dirsSource?: DirsSource;
5
6
  }
6
7
  export declare function currentsPayload(series: Map<string, StationSeries>): {
7
8
  stations: {
@@ -11,6 +12,9 @@ export declare function currentsPayload(series: Map<string, StationSeries>): {
11
12
  lon: number;
12
13
  floodDir: number | undefined;
13
14
  ebbDir: number | undefined;
15
+ dirsSource: DirsSource | undefined;
16
+ floodDirEstimated: boolean | undefined;
17
+ ebbDirEstimated: boolean | undefined;
14
18
  events: CurrentEvent[];
15
19
  }[];
16
20
  };
package/dist/routes.js CHANGED
@@ -9,6 +9,11 @@ function currentsPayload(series) {
9
9
  stationId: s.station.stationId, label: s.station.label,
10
10
  lat: s.station.lat, lon: s.station.lon,
11
11
  floodDir: s.station.floodDir, ebbDir: s.station.ebbDir,
12
+ dirsSource: s.dirsSource,
13
+ // Estimated flags qualify *config* values; API-measured dirs supersede
14
+ // the config entry the flags were describing.
15
+ floodDirEstimated: s.dirsSource === 'config' ? s.station.floodDirEstimated : undefined,
16
+ ebbDirEstimated: s.dirsSource === 'config' ? s.station.ebbDirEstimated : undefined,
12
17
  events: s.events,
13
18
  })),
14
19
  };
package/dist/types.d.ts CHANGED
@@ -13,10 +13,14 @@ export interface StationConfig {
13
13
  lon: number;
14
14
  floodDir?: number;
15
15
  ebbDir?: number;
16
+ floodDirEstimated?: boolean;
17
+ ebbDirEstimated?: boolean;
16
18
  }
17
19
  export interface StationDirs {
18
20
  floodDir?: number;
19
21
  ebbDir?: number;
20
22
  }
21
23
  export declare function resolveStation(station: StationConfig, fetched: StationDirs): StationConfig;
24
+ export type DirsSource = 'api' | 'config';
25
+ export declare function dirsSource(station: StationConfig, fetched: StationDirs): DirsSource | undefined;
22
26
  export declare function eventFromParts(utc: string, kind: CurrentKind, speed: number): CurrentEvent;
package/dist/types.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveStation = resolveStation;
4
+ exports.dirsSource = dirsSource;
4
5
  exports.eventFromParts = eventFromParts;
5
6
  // Measured dirs from the provider (NOAA meanFloodDir/meanEbbDir) beat whatever
6
7
  // was typed into config; config is the fallback (and the only source for CHS).
@@ -11,6 +12,15 @@ function resolveStation(station, fetched) {
11
12
  ebbDir: fetched.ebbDir ?? station.ebbDir,
12
13
  };
13
14
  }
15
+ // Where the resolved directions came from: provider-measured ('api'), config
16
+ // ('config'), or undefined when neither knows.
17
+ function dirsSource(station, fetched) {
18
+ if (fetched.floodDir !== undefined || fetched.ebbDir !== undefined)
19
+ return 'api';
20
+ if (station.floodDir !== undefined || station.ebbDir !== undefined)
21
+ return 'config';
22
+ return undefined;
23
+ }
14
24
  function eventFromParts(utc, kind, speed) {
15
25
  return { utc: new Date(utc).toISOString(), kind, speedKn: Math.abs(speed) };
16
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingnaturali/signalk-currents",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Publish CHS/NOAA tidal-current predictions to SignalK — environment.current + a /currents resource, for a configured station list.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {