@sailingnaturali/signalk-currents 0.1.0 → 0.3.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 +6 -1
- package/dist/index.js +15 -7
- package/dist/routes.d.ts +2 -2
- package/dist/routes.js +5 -9
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -99,7 +99,8 @@ ebb — fill them from a current atlas or pilot book for your stations.
|
|
|
99
99
|
|
|
100
100
|
### `/currents` resource
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
Served at `/signalk/v2/api/resources/currents` (anonymously readable under
|
|
103
|
+
`allow_readonly`):
|
|
103
104
|
|
|
104
105
|
```json
|
|
105
106
|
{
|
|
@@ -109,6 +110,8 @@ Mounted at `/plugins/signalk-currents/currents`:
|
|
|
109
110
|
"label": "Gillard Passage",
|
|
110
111
|
"lat": 50.3933,
|
|
111
112
|
"lon": -125.1567,
|
|
113
|
+
"floodDir": 160,
|
|
114
|
+
"ebbDir": 340,
|
|
112
115
|
"events": [
|
|
113
116
|
{ "utc": "2026-06-06T04:14:00.000Z", "kind": "slack", "speedKn": 0 },
|
|
114
117
|
{ "utc": "2026-06-06T05:40:00.000Z", "kind": "flood", "speedKn": 4.1 }
|
|
@@ -119,6 +122,8 @@ Mounted at `/plugins/signalk-currents/currents`:
|
|
|
119
122
|
```
|
|
120
123
|
|
|
121
124
|
`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.
|
|
122
127
|
|
|
123
128
|
## Development
|
|
124
129
|
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,21 @@ module.exports = function (app) {
|
|
|
36
36
|
const stations = options.stations ?? [];
|
|
37
37
|
const horizonDays = options.horizonDays ?? 3;
|
|
38
38
|
const pollMinutes = options.pollMinutes ?? 60;
|
|
39
|
+
// Expose the per-station series as a SignalK resource — served at
|
|
40
|
+
// /signalk/v2/api/resources/currents, anonymously readable under
|
|
41
|
+
// allow_readonly like the rest of the data API. (A registerWithRouter
|
|
42
|
+
// /plugins/<id> route is gated behind admin auth — wrong mechanism here.)
|
|
43
|
+
app.registerResourceProvider({
|
|
44
|
+
type: 'currents',
|
|
45
|
+
methods: {
|
|
46
|
+
async listResources() {
|
|
47
|
+
return (0, routes_1.currentsPayload)(series);
|
|
48
|
+
},
|
|
49
|
+
getResource() { throw new Error('Not implemented'); },
|
|
50
|
+
setResource() { throw new Error('Not implemented'); },
|
|
51
|
+
deleteResource() { throw new Error('Not implemented'); },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
39
54
|
async function refresh() {
|
|
40
55
|
try {
|
|
41
56
|
const now = new Date();
|
|
@@ -102,13 +117,6 @@ module.exports = function (app) {
|
|
|
102
117
|
timer = undefined;
|
|
103
118
|
}
|
|
104
119
|
},
|
|
105
|
-
// Mounted by the server at /plugins/signalk-currents — so the resource is
|
|
106
|
-
// served at /plugins/signalk-currents/currents. This is the typed
|
|
107
|
-
// equivalent of the express-router mounting signalk-tides does via an
|
|
108
|
-
// app.use() cast; registerWithRouter is the supported Plugin API.
|
|
109
|
-
registerWithRouter(router) {
|
|
110
|
-
router.use('/', (0, routes_1.currentsRouter)(() => series));
|
|
111
|
-
},
|
|
112
120
|
};
|
|
113
121
|
return plugin;
|
|
114
122
|
};
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
1
|
import { StationConfig, CurrentEvent } from './types';
|
|
3
2
|
export interface StationSeries {
|
|
4
3
|
station: StationConfig;
|
|
@@ -10,7 +9,8 @@ export declare function currentsPayload(series: Map<string, StationSeries>): {
|
|
|
10
9
|
label: string;
|
|
11
10
|
lat: number;
|
|
12
11
|
lon: number;
|
|
12
|
+
floodDir: number;
|
|
13
|
+
ebbDir: number;
|
|
13
14
|
events: CurrentEvent[];
|
|
14
15
|
}[];
|
|
15
16
|
};
|
|
16
|
-
export declare function currentsRouter(getSeries: () => Map<string, StationSeries>): Router;
|
package/dist/routes.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.currentsPayload = currentsPayload;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// The payload served by the `currents` resource provider (registered in
|
|
5
|
+
// index.ts) at /signalk/v2/api/resources/currents.
|
|
6
6
|
function currentsPayload(series) {
|
|
7
7
|
return {
|
|
8
8
|
stations: [...series.values()].map(s => ({
|
|
9
9
|
stationId: s.station.stationId, label: s.station.label,
|
|
10
|
-
lat: s.station.lat, lon: s.station.lon,
|
|
10
|
+
lat: s.station.lat, lon: s.station.lon,
|
|
11
|
+
floodDir: s.station.floodDir, ebbDir: s.station.ebbDir,
|
|
12
|
+
events: s.events,
|
|
11
13
|
})),
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
|
-
// Mirror signalk-tides/src/routes.ts for how the router is registered with `app`.
|
|
15
|
-
function currentsRouter(getSeries) {
|
|
16
|
-
const r = (0, express_1.Router)();
|
|
17
|
-
r.get('/currents', (_req, res) => res.json(currentsPayload(getSeries())));
|
|
18
|
-
return r;
|
|
19
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sailingnaturali/signalk-currents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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": {
|
|
@@ -28,12 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@signalk/server-api": "^2.0.0",
|
|
31
|
-
"express": "^4.19.0",
|
|
32
31
|
"geolib": "^3.3.4"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"typescript": "^5.4.0",
|
|
36
|
-
"vitest": "^2.0.0"
|
|
37
|
-
"@types/express": "^4.17.0"
|
|
35
|
+
"vitest": "^2.0.0"
|
|
38
36
|
}
|
|
39
37
|
}
|