forked from thingweb/wot-typescript-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
172 lines (141 loc) · 5.06 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
export as namespace WoT;
export default WoT;
declare let WoT : WoTFactory;
export interface WoTFactory {
/**
* Discover Things
*
* @param discoveryType identifier of the type of discovery (e.g. local or repository)
*/
discover(discoveryType: string, filter: Object): Promise<ConsumedThing>;
/**
* consume a thing description by URI and return a client representation object
* @param uri URI of a thing description
*/
consumeDescriptionUri(uri: string): Promise<ConsumedThing>;
/**
* consume a thing description from an object and return a client representation object
*
* @param thingDescription a thing description
*/
consumeDescription(thingDescription: Object): Promise<ConsumedThing>;
/**
* create a new Thing
*
* @param name name/identifier of the thing to be created
*/
createThing(name: string): Promise<DynamicThing>;
/**
* create a new Thing based on a thing description, given by a URI
*
* @param uri URI of a thing description to be used as "template"
*/
createFromDescriptionUri(uri: string): Promise<ExposedThing>;
/**
* create a new Thing based on a thing description, given by an object
*
* @param thingDescription a thing description to be used as "template"
*/
createFromDescription(thingDescription: Object): Promise<ExposedThing>;
}
export interface ConsumedThing {
/** name of the Thing */
name: string
/** invokes an action on the target thing
* @param actionName Name of the action to invoke
* @param parameter optional json object to supply parameters
*/
invokeAction(actionName: string, parameter?: any): Promise<any>
/**
* Set a given property
* @param Name of the property
* @param newValue value to be set
*/
setProperty(propertyName: string, newValue: any): Promise<any>
/**
* Read a given property
* @param propertyName Name of the property
*/
getProperty(propertyName: string): Promise<any>
addListener(eventName: string, listener: (event: Event) => void): ConsumedThing
removeListener(eventName: string, listener: (event: Event) => void): ConsumedThing
removeAllListeners(eventName: string): ConsumedThing
/**
* Retrive the thing description for this object
*/
getDescription(): Object
}
export interface ExposedThing {
/** name of the Thing */
name: string
/** invokes an action on the target thing
* @param actionName Name of the action to invoke
* @param parameter optional json object to supply parameters
*/
invokeAction(actionName: string, parameter?: any): Promise<any>
/**
* Set a given property
* @param Name of the property
* @param newValue value to be set
*/
setProperty(propertyName: string, newValue: any): Promise<any>
/**
* Read a given property
* @param propertyName Name of the property
*/
getProperty(propertyName: string): Promise<any>
/**
* Emit event to all listeners
*/
emitEvent(event: Event): void
addListener(eventName: string, listener: (event: Event) => void): ExposedThing
removeListener(eventName: string, listener: (event: Event) => void): ExposedThing
removeAllListeners(eventName: string): ExposedThing
/**
* register a handler for an action
* @param actionName Name of the action
* @param cb callback to be called when the action gets invoked, optionally is supplied a parameter
*/
onInvokeAction(actionName: string, cb: (param?: any) => any): ExposedThing
/**
* register a handler for value updates on the property
* @param propertyName Name of the property
* @param cb callback to be called when value changes; signature (newValue,oldValue)
*/
onUpdateProperty(propertyName: string, cb: (newValue: any, oldValue?: any) => void): ExposedThing
/**
* Retrive the thing description for this object
*/
getDescription(): Object
}
export interface DynamicThing extends ExposedThing {
/**
* declare a new property for the thing
* @param propertyName Name of the property
* @param valueType type specification of the value (JSON schema)
*/
addProperty(propertyName: string, valueType: Object): DynamicThing
/**
* declare a new action for the thing
* @param actionName Name of the action
* @param inputType type specification of the parameter (optional, JSON schema)
* @param outputType type specification of the return value (optional, JSON schema)
*/
addAction(actionName: string, inputType?: Object, outputType?: Object): DynamicThing
/**
* declare a new eventsource for the thing
*/
addEvent(eventName: string): DynamicThing
/**
* remove a property from the thing
*/
removeProperty(propertyName: string): boolean
/**
* remove an action from the thing
*/
removeAction(actionName: string): boolean
/**
* remove an event from the thing
*/
removeEvent(eventName: string): boolean
}