@cutos/core 4.0.2 → 4.0.5

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/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,73 @@ 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
+ TDeviceInfo = unknown
254
+ > extends Provider {
255
+ constructor(name: string, opts?: DeviceProviderBaseOptions);
256
+ connect(
257
+ params: TConnectParams,
258
+ context?: ProviderContext<TConnectParams>
259
+ ): TConnectResult | Promise<TConnectResult>;
260
+ disconnect(
261
+ params: TDisconnectParams,
262
+ context?: ProviderContext<TDisconnectParams>
263
+ ): TDisconnectResult | Promise<TDisconnectResult>;
264
+ readDeviceInfo(
265
+ params: Record<string, never>,
266
+ context?: ProviderContext<Record<string, never>>
267
+ ): TDeviceInfo | Promise<TDeviceInfo>;
268
+ startBeat(): void;
269
+ setBeatInterval(interval: number): this;
270
+ setStatus(status?: string, info?: unknown): this;
271
+ emitData<TData = unknown>(data: TData): boolean;
272
+ emitError(error: CutosError | Error | unknown): boolean;
273
+ }
274
+
207
275
  export class Database {
208
276
  constructor(db?: string);
209
277
  KEY_TYPE_TEXT: "TEXT";
@@ -290,10 +358,6 @@ export interface CoreAPI {
290
358
  setVolume<TResult = unknown>(vol: number): Promise<TResult>;
291
359
  setHttpProxy<TResult = unknown>(api: string, target: string, callback: CutosCallback<TResult>): boolean;
292
360
  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
361
  }
298
362
 
299
363
  export interface CoreDefine {
@@ -307,6 +371,8 @@ export interface CoreClass {
307
371
  Database: typeof Database;
308
372
  Capability: typeof Capability;
309
373
  Provider: typeof Provider;
374
+ DeviceCapabilityBase: typeof DeviceCapabilityBase;
375
+ DeviceProviderBase: typeof DeviceProviderBase;
310
376
  CutosError: typeof CutosError;
311
377
  }
312
378
 
@@ -334,8 +400,6 @@ export interface CutosMock {
334
400
  install(options?: CutosMockOptions): CutosMock;
335
401
  uninstall(): void;
336
402
  registerCapability(name: string, definition?: CutosMockCapabilityDefinition): unknown;
337
- capability(name: string): Capability;
338
- provider(name: string): Provider;
339
403
  isInstalled(): boolean;
340
404
  }
341
405
 
@@ -348,9 +412,4 @@ export const CutosMock: CutosMock;
348
412
  export function installCutosMock(options?: CutosMockOptions): CutosMock;
349
413
  export function uninstallCutosMock(): void;
350
414
  export { CutosError };
351
- export const cutos: {
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
- };
415
+ export { DeviceCapabilityBase, DeviceProviderBase };