@sailingnaturali/signalk-currents 0.1.0 → 0.2.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/dist/index.js +15 -7
- package/dist/routes.d.ts +0 -2
- package/dist/routes.js +2 -8
- package/package.json +2 -4
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;
|
|
@@ -13,4 +12,3 @@ export declare function currentsPayload(series: Map<string, StationSeries>): {
|
|
|
13
12
|
events: CurrentEvent[];
|
|
14
13
|
}[];
|
|
15
14
|
};
|
|
16
|
-
export declare function currentsRouter(getSeries: () => Map<string, StationSeries>): Router;
|
package/dist/routes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 => ({
|
|
@@ -11,9 +11,3 @@ function currentsPayload(series) {
|
|
|
11
11
|
})),
|
|
12
12
|
};
|
|
13
13
|
}
|
|
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.2.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
|
}
|