@cutos/core 4.0.1 → 4.0.4
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/README.md +18 -193
- package/dist/cutos.cjs.js +175 -271
- package/dist/cutos.esm.js +174 -271
- package/package.json +1 -1
- package/types/index.d.ts +77 -19
package/types/index.d.ts
CHANGED
|
@@ -47,6 +47,14 @@ export interface ProviderOptions {
|
|
|
47
47
|
[key: string]: unknown;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
export interface DeviceCapabilityBaseOptions extends CapabilityOptions {
|
|
51
|
+
name?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface DeviceProviderBaseOptions extends ProviderOptions {
|
|
55
|
+
name?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
export interface CallOptions {
|
|
51
59
|
timeout?: number;
|
|
52
60
|
[key: string]: unknown;
|
|
@@ -130,8 +138,6 @@ export class Device {
|
|
|
130
138
|
init<TResult = string>(callback: CutosCallback<TResult>): boolean;
|
|
131
139
|
init<TResult = string>(opts?: DeviceInitOptions | null): Promise<TResult>;
|
|
132
140
|
init<TResult = string>(opts: DeviceInitOptions | null, callback: CutosCallback<TResult>): boolean;
|
|
133
|
-
onStatus(listener: (status: DeviceStatus) => void): void;
|
|
134
|
-
getCurrentStatus(): DeviceStatus | undefined;
|
|
135
141
|
sendCommand<TArgs = unknown, TResult = unknown>(
|
|
136
142
|
command: Command<TArgs>,
|
|
137
143
|
callback: CutosCallback<TResult>
|
|
@@ -146,11 +152,6 @@ export class Device {
|
|
|
146
152
|
command: Command<TArgs>,
|
|
147
153
|
opts?: CallOptions
|
|
148
154
|
): Promise<TResult>;
|
|
149
|
-
onData<TData = unknown>(listener: (data: TData) => void): Unsubscribe;
|
|
150
|
-
offData(listener?: Function | null): void;
|
|
151
|
-
getCurrentData<TData = unknown>(): TData;
|
|
152
|
-
readDeviceInfo<TResult = unknown>(callback: CutosCallback<TResult>): boolean;
|
|
153
|
-
readDeviceInfo<TResult = unknown>(): Promise<TResult>;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
export class Driver {
|
|
@@ -204,6 +205,72 @@ export class Provider {
|
|
|
204
205
|
dispose(): boolean;
|
|
205
206
|
}
|
|
206
207
|
|
|
208
|
+
export class DeviceCapabilityBase<
|
|
209
|
+
TConnectParams = unknown,
|
|
210
|
+
TConnectResult = unknown,
|
|
211
|
+
TDisconnectParams = Record<string, never>,
|
|
212
|
+
TDisconnectResult = unknown,
|
|
213
|
+
TDeviceInfo = unknown,
|
|
214
|
+
TData = unknown,
|
|
215
|
+
TStatus = DeviceStatus,
|
|
216
|
+
TError = CutosError
|
|
217
|
+
> extends Capability {
|
|
218
|
+
constructor(name: string, opts?: DeviceCapabilityBaseOptions);
|
|
219
|
+
init<TResult = string>(callback: CutosCallback<TResult>): boolean;
|
|
220
|
+
init<TResult = string>(opts?: DeviceInitOptions | null): Promise<TResult>;
|
|
221
|
+
init<TResult = string>(opts: DeviceInitOptions | null, callback: CutosCallback<TResult>): boolean;
|
|
222
|
+
connect(params: TConnectParams, callback: CutosCallback<TConnectResult>): boolean;
|
|
223
|
+
connect(params?: TConnectParams, options?: CallOptions | null): Promise<TConnectResult>;
|
|
224
|
+
connect(
|
|
225
|
+
params: TConnectParams,
|
|
226
|
+
options: CallOptions | null,
|
|
227
|
+
callback: CutosCallback<TConnectResult>
|
|
228
|
+
): boolean;
|
|
229
|
+
disconnect(params: TDisconnectParams, callback: CutosCallback<TDisconnectResult>): boolean;
|
|
230
|
+
disconnect(params?: TDisconnectParams, options?: CallOptions | null): Promise<TDisconnectResult>;
|
|
231
|
+
disconnect(
|
|
232
|
+
params: TDisconnectParams,
|
|
233
|
+
options: CallOptions | null,
|
|
234
|
+
callback: CutosCallback<TDisconnectResult>
|
|
235
|
+
): boolean;
|
|
236
|
+
readDeviceInfo(params: Record<string, never>, callback: CutosCallback<TDeviceInfo>): boolean;
|
|
237
|
+
readDeviceInfo(params?: Record<string, never>, options?: CallOptions | null): Promise<TDeviceInfo>;
|
|
238
|
+
readDeviceInfo(
|
|
239
|
+
params: Record<string, never>,
|
|
240
|
+
options: CallOptions | null,
|
|
241
|
+
callback: CutosCallback<TDeviceInfo>
|
|
242
|
+
): boolean;
|
|
243
|
+
onData(listener: (data: TData) => void): Unsubscribe;
|
|
244
|
+
onError(listener: (error: TError) => void): Unsubscribe;
|
|
245
|
+
onStatus(listener: (status: TStatus) => void): Unsubscribe;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export class DeviceProviderBase<
|
|
249
|
+
TConnectParams = unknown,
|
|
250
|
+
TConnectResult = unknown,
|
|
251
|
+
TDisconnectParams = Record<string, never>,
|
|
252
|
+
TDisconnectResult = unknown
|
|
253
|
+
> extends Provider {
|
|
254
|
+
constructor(name: string, opts?: DeviceProviderBaseOptions);
|
|
255
|
+
connect(
|
|
256
|
+
handler: (
|
|
257
|
+
params: TConnectParams,
|
|
258
|
+
context: ProviderContext<TConnectParams>
|
|
259
|
+
) => TConnectResult | Promise<TConnectResult>
|
|
260
|
+
): this;
|
|
261
|
+
disconnect(
|
|
262
|
+
handler: (
|
|
263
|
+
params: TDisconnectParams,
|
|
264
|
+
context: ProviderContext<TDisconnectParams>
|
|
265
|
+
) => TDisconnectResult | Promise<TDisconnectResult>
|
|
266
|
+
): this;
|
|
267
|
+
startBeat(): void;
|
|
268
|
+
setBeatInterval(interval: number): this;
|
|
269
|
+
setStatus(status?: string, info?: unknown): this;
|
|
270
|
+
emitData<TData = unknown>(data: TData): boolean;
|
|
271
|
+
emitError(error: CutosError | Error | unknown): boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
207
274
|
export class Database {
|
|
208
275
|
constructor(db?: string);
|
|
209
276
|
KEY_TYPE_TEXT: "TEXT";
|
|
@@ -290,10 +357,6 @@ export interface CoreAPI {
|
|
|
290
357
|
setVolume<TResult = unknown>(vol: number): Promise<TResult>;
|
|
291
358
|
setHttpProxy<TResult = unknown>(api: string, target: string, callback: CutosCallback<TResult>): boolean;
|
|
292
359
|
setHttpProxy<TResult = unknown>(api: string, target: string): Promise<TResult>;
|
|
293
|
-
capability(name: string, opts?: CapabilityOptions): Capability;
|
|
294
|
-
provider(name: string, opts?: ProviderOptions): Provider;
|
|
295
|
-
device(name: string, opts?: CapabilityOptions): Capability;
|
|
296
|
-
driver(name: string, opts?: ProviderOptions): Provider;
|
|
297
360
|
}
|
|
298
361
|
|
|
299
362
|
export interface CoreDefine {
|
|
@@ -307,6 +370,8 @@ export interface CoreClass {
|
|
|
307
370
|
Database: typeof Database;
|
|
308
371
|
Capability: typeof Capability;
|
|
309
372
|
Provider: typeof Provider;
|
|
373
|
+
DeviceCapabilityBase: typeof DeviceCapabilityBase;
|
|
374
|
+
DeviceProviderBase: typeof DeviceProviderBase;
|
|
310
375
|
CutosError: typeof CutosError;
|
|
311
376
|
}
|
|
312
377
|
|
|
@@ -334,8 +399,6 @@ export interface CutosMock {
|
|
|
334
399
|
install(options?: CutosMockOptions): CutosMock;
|
|
335
400
|
uninstall(): void;
|
|
336
401
|
registerCapability(name: string, definition?: CutosMockCapabilityDefinition): unknown;
|
|
337
|
-
capability(name: string): Capability;
|
|
338
|
-
provider(name: string): Provider;
|
|
339
402
|
isInstalled(): boolean;
|
|
340
403
|
}
|
|
341
404
|
|
|
@@ -348,9 +411,4 @@ export const CutosMock: CutosMock;
|
|
|
348
411
|
export function installCutosMock(options?: CutosMockOptions): CutosMock;
|
|
349
412
|
export function uninstallCutosMock(): void;
|
|
350
413
|
export { CutosError };
|
|
351
|
-
export
|
|
352
|
-
capability(name: string, opts?: CapabilityOptions): Capability;
|
|
353
|
-
provider(name: string, opts?: ProviderOptions): Provider;
|
|
354
|
-
device(name: string, opts?: CapabilityOptions): Capability;
|
|
355
|
-
driver(name: string, opts?: ProviderOptions): Provider;
|
|
356
|
-
};
|
|
414
|
+
export { DeviceCapabilityBase, DeviceProviderBase };
|