-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.d.ts
295 lines (249 loc) · 11.8 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
type DeepPartial<T> = T extends object ? {
[P in keyof T]?: T[P] extends Array<infer I>
? Array<DeepPartial<I>>
: DeepPartial<T[P]>
} : T;
declare namespace WoT {
/**
* Starts the discovery process that will provide {@link ThingDescription}
* objects for Thing Descriptions that match an optional {@link filter}
* argument of type {@link ThingFilter}.
*
* @param filter represents the constraints for discovering Things as key-value pairs
*/
export function discover(filter?: ThingFilter): Promise<ThingDiscoveryProcess>;
/**
* Starts the discovery process that, given a TD Directory {@link url}, will
* provide {@link ThingDescription} objects for Thing Descriptions that
* match an optional {@link filter} argument of type {@link ThingFilter}.
*
* @param url URL pointing to a TD Directory.
* @param filter represents the constraints for discovering Things as key-value pairs
*/
export function exploreDirectory(url: string, filter?: ThingFilter): Promise<ThingDiscoveryProcess>;
/**
* Requests a {@link ThingDescription} from the given {@link url}.
*
* @param url The URL to request the Thing Description from.
*/
export function requestThingDescription(url: string): Promise<ThingDescription>;
/**
* Accepts a ThingDescription and returns a ConsumedThing
* @param td thing description
*/
export function consume(td: ThingDescription): Promise<ConsumedThing>;
/**
* Accepts an init dictionary similar to a ThingDescription.
* It returns a ExposedThing
*
* @param ptd Partial thing description
*/
export function produce(init: ExposedThingInit): Promise<ExposedThing>;
/**
* Dictionary that represents the constraints for discovering Things as key-value pairs.
*/
export interface ThingFilter {
/**
* The fragment field represents a template object used for matching against discovered Things.
*/
fragment?: object;
}
/**
* The ThingDiscovery object is constructed given a filter and provides the properties and methods
* controlling the discovery process.
*/
export interface ThingDiscoveryProcess extends AsyncIterable<ThingDescription> {
filter?: ThingFilter;
done: boolean;
error?: Error;
stop(): void;
}
/**
* WoT provides a unified representation for data exchange between Things, standardized in the Wot Things Description specification.
* In this version of the API, Thing Descriptions is expected to be a parsed JSON object.
*/
export type ThingDescription = import("wot-thing-description-types").ThingDescription;
export type ExposedThingInit = DeepPartial<ThingDescription>;
export type DataSchemaValue = (null | boolean | number | string | object | DataSchemaValue[]);
export type InteractionInput = (ReadableStream | DataSchemaValue);
export interface InteractionOutput {
data?: ReadableStream;
dataUsed: boolean;
form?: Form;
schema?: DataSchema;
arrayBuffer(): Promise<ArrayBuffer>;
value(): Promise<DataSchemaValue>;
}
export interface Subscription {
active:boolean,
stop(options?: InteractionOptions):Promise<void>
}
/**
* The ConsumedThing interface instance represents a client API to operate a Thing.
*/
export interface ConsumedThing {
/**
* Reads a Property value.
* Takes as arguments propertyName and optionally options.
* It returns a Promise that resolves with a Property value represented as an
* InteractionOutput object or rejects on error.
*/
readProperty(propertyName: string, options?: InteractionOptions): Promise<InteractionOutput>;
/**
* Reads all properties of the Thing with one or multiple requests.
* Takes options as optional argument.
* It returns a Promise that resolves with a PropertyMap object that
* maps keys from Property names to values.
*/
readAllProperties(options?: InteractionOptions): Promise<PropertyReadMap>;
/**
* Reads multiple Property values with one or multiple requests.
* Takes as arguments propertyNames and optionally options.
* It returns a Promise that resolves with a PropertyMap object that
* maps keys from propertyNames to values
*/
readMultipleProperties(propertyNames: string[], options?: InteractionOptions): Promise<PropertyReadMap>;
/**
* Writes a single Property.
* Takes as arguments propertyName, value and optionally options.
* It returns a Promise that resolves on success and rejects on failure.
*/
writeProperty(propertyName: string, value: InteractionInput, options?: InteractionOptions): Promise<void>;
/**
* Writes a multiple Property values with one request.
* Takes as arguments properties - as an object with keys being Property names
* and values as Property values - and optionally options.
* It returns a Promise that resolves on success and rejects on failure.
*/
writeMultipleProperties(valueMap: PropertyWriteMap, options?: InteractionOptions): Promise<void>;
/**
* Makes a request for invoking an Action and return the result.
* Takes as arguments actionName, optionally params and optionally options.
* It returns a Promise that resolves with the result of the Action represented
* as an InteractionOutput object, or rejects with an error.
*/
invokeAction(actionName: string, params?: InteractionInput, options?: InteractionOptions): Promise<undefined | InteractionOutput>;
/**
* Makes a request for Property value change notifications.
* Takes as arguments propertyName, listener and optionally options.
* It returns a Promise that resolves on success and rejects on failure.
*/
observeProperty(name: string, listener: WotListener, errorListener?: ErrorListener, options?: InteractionOptions): Promise<Subscription>;
/**
* Makes a request for subscribing to Event notifications.
* Takes as arguments eventName, listener and optionally options.
* It returns a Promise to signal success or failure.
*/
subscribeEvent(name: string, listener: WotListener, errorListener?: ErrorListener, options?: InteractionOptions): Promise<Subscription>;
/**
* Returns the the object that represents the Thing Description.
*/
getThingDescription(): ThingDescription;
}
export interface InteractionOptions {
formIndex?: number;
uriVariables?: object;
data?: any;
}
export type PropertyReadMap = Map<string, InteractionOutput>;
export type PropertyWriteMap = Map<string, InteractionInput>;
export type WotListener = (data: InteractionOutput) => void;
export type ErrorListener = (error: Error) => void;
export interface InteractionData {
data?: ReadableStream;
dataUsed: boolean;
form?: Form;
schema?: DataSchema;
arrayBuffer(): Promise<ArrayBuffer>;
value(): Promise<any>;
}
export type Form = { [key: string]: any; };
export type DataSchema = { [key: string]: any; };
/**
* The ExposedThing interface is the server API to operate the Thing that allows defining request handlers, Property, Action, and Event interactions.
**/
export interface ExposedThing {
/**
* Start serving external requests for the Thing, so that WoT Interactions using Properties, Actions and Events will be possible.
*/
expose(): Promise<void>;
/**
* Stop serving external requests for the Thing and destroy the object. Note that eventual unregistering should be done before invoking this method.
*/
destroy(): Promise<void>;
/**
* Takes name as string argument and handler as argument of type PropertyReadHandler.
* Sets the handler function for reading the specified Property matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setPropertyReadHandler(name: string, handler: PropertyReadHandler): ExposedThing;
/**
* Takes name as string argument and handler as argument of type PropertyWriteHandler.
* Sets the handler function for writing the specified Property matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setPropertyWriteHandler(name: string, handler: PropertyWriteHandler): ExposedThing;
/**
* Takes as arguments name and handler.
* Sets the service handler that defines what to do when a request is received for
* observing the specified Property matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setPropertyObserveHandler(name: string, handler: PropertyReadHandler): ExposedThing;
/**
* Takes as arguments name and handler.
* Sets the service handler that defines what to do when a request is received for
* unobserving the specified Property matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setPropertyUnobserveHandler(name: string, handler: PropertyReadHandler): ExposedThing;
/**
* Takes as arguments name denoting a Property name.
* Triggers emitting a notification to all observers.
*/
emitPropertyChange(name: string): void;
/**
* Takes name as string argument and handler as argument of type ActionHandler.
* Sets the handler function for the specified Action matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setActionHandler(name: string, handler: ActionHandler): ExposedThing;
/**
* Takes as arguments name and handler.
* Sets the handler function that defines what to do when a subscription request
* is received for the specified Event matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setEventSubscribeHandler(name: string, handler: EventSubscriptionHandler): ExposedThing;
/**
* Takes as arguments name and handler.
* Sets the handler function that defines what to do when the specified Event
* matched by name is unsubscribed from.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setEventUnsubscribeHandler(name: string, handler: EventSubscriptionHandler): ExposedThing;
/**
* Takes as arguments name denoting an Event name and optionally data.
* Triggers emitting the Event with optional data.
*/
emitEvent(name: string, data?: InteractionInput): void;
/**
* Returns the the object that represents the Thing Description.
*/
getThingDescription(): ThingDescription;
}
export type PropertyReadHandler = (options?: InteractionOptions) => Promise<InteractionInput>;
export type PropertyWriteHandler = (value: InteractionOutput, options?: InteractionOptions) => Promise<void>;
export type ActionHandler = (params: InteractionOutput, options?: InteractionOptions) => Promise<undefined | InteractionInput>;
export type EventSubscriptionHandler = (options?: InteractionOptions) => Promise<void>;
}
declare module "wot-typescript-definitions" {
export = WoT;
}