Skip to content

Commit 1c7a47b

Browse files
authored
Update json-schema-to-typescript and ajv. (#94)
1 parent 47c1e6c commit 1c7a47b

File tree

6 files changed

+121
-45
lines changed

6 files changed

+121
-45
lines changed

package-lock.json

Lines changed: 94 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/WebThingsIO/gateway-addon-node/issues"
2222
},
2323
"dependencies": {
24-
"ajv": "^6.12.6",
24+
"ajv": "^7.0.3",
2525
"sqlite3": "^4.2.0",
2626
"ws": "^7.4.2"
2727
},
@@ -33,7 +33,7 @@
3333
"@typescript-eslint/parser": "^4.14.1",
3434
"babel-eslint": "^10.1.0",
3535
"eslint": "^7.18.0",
36-
"json-schema-to-typescript": "^9.1.1",
36+
"json-schema-to-typescript": "^10.1.3",
3737
"typescript": "^4.1.3"
3838
},
3939
"files": [

src/action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Device} from './device';
10-
import {ActionDescription, Input} from './schema';
10+
import {ActionDescription, Any} from './schema';
1111
import {timestamp} from './utils';
1212

1313
/**
@@ -26,7 +26,7 @@ export class Action {
2626

2727
private name: string;
2828

29-
private input?: Input;
29+
private input?: Any;
3030

3131
/**
3232
* Initialize the object.
@@ -36,7 +36,7 @@ export class Action {
3636
* @param {String} name Name of the action
3737
* @param {unknown} input Any action inputs
3838
*/
39-
constructor(id: string, device: Device, name: string, input?: Input) {
39+
constructor(id: string, device: Device, name: string, input?: Any) {
4040
this.id = id;
4141
this.device = device;
4242
this.name = name;
@@ -51,7 +51,7 @@ export class Action {
5151
return this.name;
5252
}
5353

54-
getInput(): Input | undefined {
54+
getInput(): Any | undefined {
5555
return this.input;
5656
}
5757

src/addon-manager-proxy.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import {PluginClient} from './plugin-client';
2020
import {Property} from './property';
2121
import {MessageType} from './message-type';
2222
import {EventEmitter} from 'events';
23-
import {AdapterPairingPromptNotificationMessageData, AdapterRemoveDeviceRequest,
23+
import {
24+
AdapterPairingPromptNotificationMessageData,
25+
AdapterRemoveDeviceRequest,
2426
AdapterStartPairingCommand,
2527
AdapterUnpairingPromptNotificationMessageData,
28+
Any,
2629
APIHandlerAPIRequest,
2730
APIHandlerUnloadRequest,
2831
DeviceRemoveActionRequest,
@@ -39,8 +42,8 @@ import {AdapterPairingPromptNotificationMessageData, AdapterRemoveDeviceRequest,
3942
NotifierAddedNotification,
4043
OutletNotifyRequest,
4144
Preferences,
42-
PropertyValue,
43-
UserProfile} from './schema';
45+
UserProfile,
46+
} from './schema';
4447

4548
interface MockAdapter {
4649
clearState(): Promise<void>;
@@ -744,7 +747,7 @@ export class AddonManagerProxy extends EventEmitter {
744747
* @method sendPropertyChangedNotification
745748
* Sends a propertyChanged notification to the gateway.
746749
*/
747-
sendPropertyChangedNotification(property: Property<PropertyValue>): void {
750+
sendPropertyChangedNotification(property: Property<Any>): void {
748751
this.pluginClient.sendNotification(
749752
MessageType.DEVICE_PROPERTY_CHANGED_NOTIFICATION,
750753
{

src/device.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import {Property} from './property';
1515
import {Event} from './event';
1616
import {
1717
Action as ActionSchema,
18+
Any,
1819
Event as EventSchema,
1920
Device as DeviceSchema,
2021
Property as PropertySchema,
2122
Link,
22-
Input,
23-
PropertyValue,
2423
} from './schema';
2524

2625
const ajv = new Ajv();
@@ -40,7 +39,7 @@ export class Device {
4039

4140
private description = '';
4241

43-
private properties = new Map<string, Property<PropertyValue>>();
42+
private properties = new Map<string, Property<Any>>();
4443

4544
private actions = new Map<string, ActionSchema>();
4645

@@ -218,19 +217,19 @@ export class Device {
218217
return propDescs;
219218
}
220219

221-
findProperty(propertyName: string): Property<PropertyValue> | undefined {
220+
findProperty(propertyName: string): Property<Any> | undefined {
222221
return this.properties.get(propertyName);
223222
}
224223

225-
addProperty(property: Property<PropertyValue>): void {
224+
addProperty(property: Property<Any>): void {
226225
this.properties.set(property.getName(), property);
227226
}
228227

229228
/**
230229
* @method getProperty
231230
* @returns a promise which resolves to the retrieved value.
232231
*/
233-
getProperty(propertyName: string): Promise<PropertyValue> {
232+
getProperty(propertyName: string): Promise<Any> {
234233
return new Promise((resolve, reject) => {
235234
const property = this.findProperty(propertyName);
236235
if (property) {
@@ -247,7 +246,7 @@ export class Device {
247246
return this.properties.has(propertyName);
248247
}
249248

250-
notifyPropertyChanged(property: Property<PropertyValue>): void {
249+
notifyPropertyChanged(property: Property<Any>): void {
251250
this.adapter.getManager().sendPropertyChangedNotification(property);
252251
}
253252

@@ -270,7 +269,7 @@ export class Device {
270269
* @note it is possible that the updated value doesn't match
271270
* the value passed in.
272271
*/
273-
setProperty(propertyName: string, value: PropertyValue): Promise<PropertyValue> {
272+
setProperty(propertyName: string, value: Any): Promise<Any> {
274273
const property = this.findProperty(propertyName);
275274
if (property) {
276275
return property.setValue(value);
@@ -287,7 +286,7 @@ export class Device {
287286
* @method requestAction
288287
* @returns a promise which resolves when the action has been requested.
289288
*/
290-
requestAction(actionId: string, actionName: string, input: Input): Promise<void> {
289+
requestAction(actionId: string, actionName: string, input: Any): Promise<void> {
291290
return new Promise((resolve, reject) => {
292291
if (!this.actions.has(actionName)) {
293292
reject(`Action "${actionName}" not found`);

0 commit comments

Comments
 (0)