@signalk/server-api 2.0.0-beta.3 → 2.0.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/.eslintrc.js ADDED
@@ -0,0 +1,25 @@
1
+ // eslint-disable-next-line no-undef
2
+ module.exports = {
3
+ root: true,
4
+ extends: ['eslint:recommended', 'prettier'],
5
+ parserOptions: {
6
+ ecmaVersion: 2019,
7
+ sourceType: 'module'
8
+ },
9
+ env: {
10
+ node: true,
11
+ es2019: true
12
+ },
13
+ overrides: [
14
+ {
15
+ files: ['**/*.ts'],
16
+ extends: [
17
+ 'eslint:recommended',
18
+ 'plugin:@typescript-eslint/recommended',
19
+ 'prettier'
20
+ ],
21
+ parser: '@typescript-eslint/parser',
22
+ plugins: ['@typescript-eslint']
23
+ }
24
+ ]
25
+ }
@@ -1,13 +1,6 @@
1
1
  export interface AutopilotApi {
2
2
  register: (pluginId: string, provider: AutopilotProvider) => void;
3
3
  unRegister: (pluginId: string) => void;
4
- getStates: () => Promise<[string]>;
5
- setState: (state: string) => Promise<void>;
6
- getModes: () => Promise<[string]>;
7
- setMode: (mode: string) => Promise<void>;
8
- setTarget: (value: number) => Promise<void>;
9
- adjustTarget: (value: number) => Promise<void>;
10
- tack: (port: boolean) => Promise<void>;
11
4
  }
12
5
  export interface AutopilotProvider {
13
6
  pilotType: string;
@@ -15,9 +8,13 @@ export interface AutopilotProvider {
15
8
  }
16
9
  export interface AutopilotProviderMethods {
17
10
  pluginId?: string;
18
- getStates: () => Promise<[string]>;
11
+ engage: (enable: boolean) => Promise<void>;
12
+ getConfig: () => Promise<{
13
+ [key: string]: any;
14
+ }>;
15
+ getState: () => Promise<string>;
19
16
  setState: (state: string) => Promise<void>;
20
- getModes: () => Promise<[string]>;
17
+ getMode: () => Promise<string>;
21
18
  setMode: (mode: string) => Promise<void>;
22
19
  setTarget: (value: number) => Promise<void>;
23
20
  adjustTarget: (value: number) => Promise<void>;
@@ -0,0 +1,48 @@
1
+ export interface DeltaSubscription {
2
+ context: string;
3
+ subscribe: Array<{
4
+ path: string;
5
+ period: number;
6
+ format: 'delta' | 'full';
7
+ policy: 'instant' | 'ideal' | 'fixed';
8
+ minPeriod: number;
9
+ }>;
10
+ }
11
+ export interface DeltaMessage {
12
+ updates?: Array<{
13
+ values: Update[];
14
+ }>;
15
+ metas?: Array<{
16
+ values: Meta[];
17
+ }>;
18
+ }
19
+ export interface Update {
20
+ path: string;
21
+ value: object | number | string | null | Notification;
22
+ }
23
+ export interface Notification {
24
+ state: ALARM_STATE;
25
+ method: ALARM_METHOD[];
26
+ message: string;
27
+ }
28
+ export interface Meta {
29
+ path: string;
30
+ value: MetaValue;
31
+ }
32
+ export interface MetaValue {
33
+ description: string;
34
+ units?: string;
35
+ example?: string;
36
+ }
37
+ export declare enum ALARM_STATE {
38
+ nominal = "nominal",
39
+ normal = "normal",
40
+ alert = "alert",
41
+ warn = "warn",
42
+ alarm = "alarm",
43
+ emergency = "emergency"
44
+ }
45
+ export declare enum ALARM_METHOD {
46
+ visual = "visual",
47
+ sound = "sound"
48
+ }
package/dist/deltas.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALARM_METHOD = exports.ALARM_STATE = void 0;
4
+ // Notification attribute types
5
+ var ALARM_STATE;
6
+ (function (ALARM_STATE) {
7
+ ALARM_STATE["nominal"] = "nominal";
8
+ ALARM_STATE["normal"] = "normal";
9
+ ALARM_STATE["alert"] = "alert";
10
+ ALARM_STATE["warn"] = "warn";
11
+ ALARM_STATE["alarm"] = "alarm";
12
+ ALARM_STATE["emergency"] = "emergency";
13
+ })(ALARM_STATE = exports.ALARM_STATE || (exports.ALARM_STATE = {}));
14
+ var ALARM_METHOD;
15
+ (function (ALARM_METHOD) {
16
+ ALARM_METHOD["visual"] = "visual";
17
+ ALARM_METHOD["sound"] = "sound";
18
+ })(ALARM_METHOD = exports.ALARM_METHOD || (exports.ALARM_METHOD = {}));
package/dist/index.d.ts CHANGED
@@ -5,71 +5,24 @@ export interface Position {
5
5
  longitude: number;
6
6
  altitude?: number;
7
7
  }
8
- export { PropertyValue, PropertyValues, PropertyValuesCallback } from './propertyvalues';
9
- export * from './resourcetypes';
10
- export declare type SignalKResourceType = 'routes' | 'waypoints' | 'notes' | 'regions' | 'charts';
11
- export declare const SIGNALKRESOURCETYPES: SignalKResourceType[];
12
- export declare const isSignalKResourceType: (s: string) => boolean;
13
- export declare type ResourceType = SignalKResourceType | string;
14
- export interface ResourcesApi {
15
- register: (pluginId: string, provider: ResourceProvider) => void;
16
- unRegister: (pluginId: string) => void;
17
- listResources: (resType: SignalKResourceType, params: {
18
- [key: string]: any;
19
- }, providerId?: string) => Promise<{
20
- [id: string]: any;
21
- }>;
22
- getResource: (resType: SignalKResourceType, resId: string, providerId?: string) => Promise<object>;
23
- setResource: (resType: SignalKResourceType, resId: string, data: {
24
- [key: string]: any;
25
- }, providerId?: string) => Promise<void>;
26
- deleteResource: (resType: SignalKResourceType, resId: string, providerId?: string) => Promise<void>;
27
- }
28
- export interface ResourceProvider {
29
- type: ResourceType;
30
- methods: ResourceProviderMethods;
31
- }
32
- export interface ResourceProviderMethods {
33
- listResources: (query: {
34
- [key: string]: any;
35
- }) => Promise<{
36
- [id: string]: any;
37
- }>;
38
- getResource: (id: string, property?: string) => Promise<object>;
39
- setResource: (id: string, value: {
40
- [key: string]: any;
41
- }) => Promise<void>;
42
- deleteResource: (id: string) => Promise<void>;
43
- }
44
- export interface ResourceProviderRegistry {
45
- registerResourceProvider: (provider: ResourceProvider) => void;
8
+ export interface ActionResult {
9
+ state: 'COMPLETED' | 'PENDING' | 'FAILED';
10
+ statusCode: number;
11
+ message?: string;
12
+ resultStatus?: number;
46
13
  }
47
- export interface AutopilotApi {
48
- register: (pluginId: string, provider: AutopilotProvider) => void;
49
- unRegister: (pluginId: string) => void;
14
+ export declare enum SKVersion {
15
+ v1 = "v1",
16
+ v2 = "v2"
50
17
  }
51
- export interface AutopilotProvider {
52
- pilotType: string;
53
- methods: AutopilotProviderMethods;
54
- }
55
- export interface AutopilotProviderMethods {
56
- pluginId?: string;
57
- engage: (enable: boolean) => Promise<void>;
58
- getConfig: () => Promise<{
59
- [key: string]: any;
60
- }>;
61
- getState: () => Promise<string>;
62
- setState: (state: string) => Promise<void>;
63
- getMode: () => Promise<string>;
64
- setMode: (mode: string) => Promise<void>;
65
- setTarget: (value: number) => Promise<void>;
66
- adjustTarget: (value: number) => Promise<void>;
67
- tack: (port: boolean) => Promise<void>;
68
- }
69
- export interface AutopilotProviderRegistry {
70
- registerAutopilotProvider: (provider: AutopilotProvider) => void;
71
- }
72
- declare type Unsubscribe = () => {};
18
+ export * from './deltas';
19
+ export * from './resourcetypes';
20
+ export * from './resourcesapi';
21
+ export { ResourceProviderRegistry } from './resourcesapi';
22
+ import { ResourceProviderRegistry } from './resourcesapi';
23
+ export * from './autopilotapi';
24
+ export { PropertyValue, PropertyValues, PropertyValuesCallback } from './propertyvalues';
25
+ type Unsubscribe = () => void;
73
26
  export interface PropertyValuesEmitter {
74
27
  emitPropertyValue: (name: string, value: any) => void;
75
28
  onPropertyValues: (name: string, cb: PropertyValuesCallback) => Unsubscribe;
@@ -105,7 +58,7 @@ export interface Plugin {
105
58
  * in the admin UI
106
59
  * - when a plugin is Enabled in the admin UI
107
60
  */
108
- start: (config: object, restart: (newConfiguration: object) => void) => any;
61
+ start: (config: object, restart: (newConfiguration: object) => void) => void;
109
62
  /**
110
63
  * Called to stop the plugin. Called when the user disables the plugin in the admin UI.
111
64
  */
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,16 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.isSignalKResourceType = exports.SIGNALKRESOURCETYPES = exports.PropertyValues = void 0;
17
+ exports.PropertyValues = exports.SKVersion = void 0;
18
+ var SKVersion;
19
+ (function (SKVersion) {
20
+ SKVersion["v1"] = "v1";
21
+ SKVersion["v2"] = "v2";
22
+ })(SKVersion = exports.SKVersion || (exports.SKVersion = {}));
23
+ __exportStar(require("./deltas"), exports);
24
+ __exportStar(require("./resourcetypes"), exports);
25
+ __exportStar(require("./resourcesapi"), exports);
26
+ __exportStar(require("./autopilotapi"), exports);
14
27
  var propertyvalues_1 = require("./propertyvalues");
15
28
  Object.defineProperty(exports, "PropertyValues", { enumerable: true, get: function () { return propertyvalues_1.PropertyValues; } });
16
- __exportStar(require("./resourcetypes"), exports);
17
- exports.SIGNALKRESOURCETYPES = [
18
- 'routes',
19
- 'waypoints',
20
- 'notes',
21
- 'regions',
22
- 'charts'
23
- ];
24
- var isSignalKResourceType = function (s) { return exports.SIGNALKRESOURCETYPES.includes(s); };
25
- exports.isSignalKResourceType = isSignalKResourceType;
@@ -4,7 +4,7 @@ export interface PropertyValue {
4
4
  name: string;
5
5
  value: any;
6
6
  }
7
- export declare type PropertyValuesCallback = (propValuesHistory: PropertyValue[]) => void;
7
+ export type PropertyValuesCallback = (propValuesHistory: PropertyValue[]) => void;
8
8
  export declare class PropertyValues {
9
9
  private streams;
10
10
  private count;
@@ -15,7 +15,7 @@ var PropertyValues = /** @class */ (function () {
15
15
  };
16
16
  PropertyValues.prototype.emitPropertyValue = function (pv) {
17
17
  if (this.count >= PropertyValues.MAX_VALUES_COUNT) {
18
- throw new Error("Max PropertyValues count " + PropertyValues.MAX_VALUES_COUNT + " exceeded trying to emit " + JSON.stringify(pv));
18
+ throw new Error("Max PropertyValues count ".concat(PropertyValues.MAX_VALUES_COUNT, " exceeded trying to emit ").concat(JSON.stringify(pv)));
19
19
  }
20
20
  this.getStreamTuple(pv.name).bus.push(pv);
21
21
  };
@@ -23,17 +23,18 @@ var PropertyValues = /** @class */ (function () {
23
23
  var _this = this;
24
24
  var streamTuple = this.streams[propName];
25
25
  if (!streamTuple) {
26
- streamTuple = {
27
- bus: new baconjs_1.default.Bus(),
28
- stream: null
29
- };
30
- streamTuple.stream = streamTuple.bus
26
+ var bus = new baconjs_1.default.Bus();
27
+ var stream = bus
31
28
  .scan([], function (acc, v) {
32
29
  acc.push(v);
33
30
  _this.count++;
34
31
  return acc;
35
32
  })
36
33
  .toProperty();
34
+ streamTuple = {
35
+ bus: bus,
36
+ stream: stream
37
+ };
37
38
  streamTuple.stream.subscribe(function () { return ({}); }); // start the stream eagerly
38
39
  streamTuple.bus.push(undefined);
39
40
  this.streams[propName] = streamTuple;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4
- to[j] = from[i];
5
- return to;
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
6
10
  };
7
11
  Object.defineProperty(exports, "__esModule", { value: true });
8
12
  var chai_1 = require("chai");
@@ -19,9 +23,9 @@ var setupTest = function (done, startAt) {
19
23
  var pv = new propertyvalues_1.PropertyValues();
20
24
  var cbCount = 0;
21
25
  var cb = function (values) {
22
- chai_1.expect(values).to.deep.equal(__spreadArray([
26
+ (0, chai_1.expect)(values).to.deep.equal(__spreadArray([
23
27
  undefined
24
- ], testValues.slice(0, startAt + cbCount++)));
28
+ ], testValues.slice(0, startAt + cbCount++), true));
25
29
  if (cbCount === testValues.length) {
26
30
  done();
27
31
  }
@@ -46,11 +50,12 @@ describe('PropertyValues', function () {
46
50
  for (var i = 1; i < propertyvalues_1.PropertyValues.MAX_VALUES_COUNT; i++) {
47
51
  pv.emitPropertyValue(newPropertyValue(i));
48
52
  }
49
- chai_1.expect(function () {
53
+ (0, chai_1.expect)(function () {
50
54
  return pv.emitPropertyValue(newPropertyValue(propertyvalues_1.PropertyValues.MAX_VALUES_COUNT));
51
55
  }).to.throw();
52
56
  });
53
57
  });
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
59
  var newPropertyValue = function (value) { return ({
55
60
  timestamp: Date.now(),
56
61
  setter: 'foobar',
@@ -0,0 +1,37 @@
1
+ export type SignalKResourceType = 'routes' | 'waypoints' | 'notes' | 'regions' | 'charts';
2
+ export declare const SIGNALKRESOURCETYPES: SignalKResourceType[];
3
+ export declare const isSignalKResourceType: (s: string) => boolean;
4
+ export type ResourceType = SignalKResourceType | string;
5
+ export interface ResourcesApi {
6
+ register: (pluginId: string, provider: ResourceProvider) => void;
7
+ unRegister: (pluginId: string) => void;
8
+ listResources: (resType: SignalKResourceType, params: {
9
+ [key: string]: any;
10
+ }, providerId?: string) => Promise<{
11
+ [id: string]: any;
12
+ }>;
13
+ getResource: (resType: SignalKResourceType, resId: string, providerId?: string) => Promise<object>;
14
+ setResource: (resType: SignalKResourceType, resId: string, data: {
15
+ [key: string]: any;
16
+ }, providerId?: string) => Promise<void>;
17
+ deleteResource: (resType: SignalKResourceType, resId: string, providerId?: string) => Promise<void>;
18
+ }
19
+ export interface ResourceProvider {
20
+ type: ResourceType;
21
+ methods: ResourceProviderMethods;
22
+ }
23
+ export interface ResourceProviderMethods {
24
+ listResources: (query: {
25
+ [key: string]: any;
26
+ }) => Promise<{
27
+ [id: string]: any;
28
+ }>;
29
+ getResource: (id: string, property?: string) => Promise<object>;
30
+ setResource: (id: string, value: {
31
+ [key: string]: any;
32
+ }) => Promise<void>;
33
+ deleteResource: (id: string) => Promise<void>;
34
+ }
35
+ export interface ResourceProviderRegistry {
36
+ registerResourceProvider: (provider: ResourceProvider) => void;
37
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSignalKResourceType = exports.SIGNALKRESOURCETYPES = void 0;
4
+ exports.SIGNALKRESOURCETYPES = [
5
+ 'routes',
6
+ 'waypoints',
7
+ 'notes',
8
+ 'regions',
9
+ 'charts'
10
+ ];
11
+ var isSignalKResourceType = function (s) {
12
+ return exports.SIGNALKRESOURCETYPES.includes(s);
13
+ };
14
+ exports.isSignalKResourceType = isSignalKResourceType;
@@ -55,10 +55,10 @@ export interface Chart {
55
55
  bounds?: [[number, number], [number, number]];
56
56
  chartFormat: string;
57
57
  }
58
- export declare type GeoJsonPoint = [number, number, number?];
59
- export declare type GeoJsonLinestring = GeoJsonPoint[];
60
- export declare type GeoJsonPolygon = GeoJsonLinestring[];
61
- export declare type GeoJsonMultiPolygon = GeoJsonPolygon[];
58
+ export type GeoJsonPoint = [number, number, number?];
59
+ export type GeoJsonLinestring = GeoJsonPoint[];
60
+ export type GeoJsonPolygon = GeoJsonLinestring[];
61
+ export type GeoJsonMultiPolygon = GeoJsonPolygon[];
62
62
  interface Polygon {
63
63
  type: 'Feature';
64
64
  geometry: {
package/dist/types.js CHANGED
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/server-api",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0",
4
4
  "description": "signalk-server Typescript API for plugins etc with relevant implementation classes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,11 @@
9
9
  "watch": "tsc --declaration --watch",
10
10
  "prepublishOnly": "npm run build",
11
11
  "typedoc": "typedoc --out docs src",
12
- "test": "mocha --require ts-node/register src/**/*.test.ts"
12
+ "prettier": "prettier -w src/",
13
+ "lint": "eslint -c .eslintrc.js --ext .ts --ext .js --fix src/",
14
+ "format": "npm run prettier && npm run lint",
15
+ "ci-lint": "eslint -c .eslintrc.js --ext .ts --ext .js src/ && prettier --check src/",
16
+ "test": "mocha --require ts-node/register src/**/*.test.ts && npm run ci-lint"
13
17
  },
14
18
  "repository": {
15
19
  "type": "git",
@@ -18,14 +22,19 @@
18
22
  "author": "teppo.kurki@iki.fi",
19
23
  "license": "Apache-2.0",
20
24
  "devDependencies": {
21
- "express": "^4.10.4",
22
25
  "@types/chai": "^4.2.15",
23
26
  "@types/express": "^4.17.1",
24
- "@types/mocha": "^8.2.0",
27
+ "@types/mocha": "^10.0.1",
28
+ "@typescript-eslint/eslint-plugin": "^5.52.0",
29
+ "@typescript-eslint/parser": "^5.52.0",
25
30
  "chai": "^4.3.0",
26
- "mocha": "^8.3.0",
27
- "ts-node": "^9.1.1",
28
- "typedoc": "^0.20.28",
31
+ "eslint": "^8.34.0",
32
+ "eslint-config-prettier": "^8.6.0",
33
+ "express": "^4.10.4",
34
+ "mocha": "^10.2.0",
35
+ "prettier": "^2.8.4",
36
+ "ts-node": "^10.9.1",
37
+ "typedoc": "^0.23.23",
29
38
  "typescript": "^4.1.5"
30
39
  },
31
40
  "peerDependencies": {