diff --git a/common/core/src/authentication_provider.ts b/common/core/src/authentication_provider.ts index dea78fa15..1fe90df7b 100644 --- a/common/core/src/authentication_provider.ts +++ b/common/core/src/authentication_provider.ts @@ -24,5 +24,6 @@ export enum AuthenticationType { */ export interface AuthenticationProvider { type: AuthenticationType; - getDeviceCredentials(callback?: Callback): Promise | void; + getDeviceCredentials(callback: Callback): void; + getDeviceCredentials(): Promise; } diff --git a/common/core/src/promise_utils.ts b/common/core/src/promise_utils.ts index 4ff25b8be..bdefcc3df 100644 --- a/common/core/src/promise_utils.ts +++ b/common/core/src/promise_utils.ts @@ -69,6 +69,8 @@ export type HttpResponseCallback = TripleValueCallback; * const param = 42; * callbackToPromise((_callback) => foo(param, _callback)).then(result => { console.log(result); }, error => { console.error(error); }); */ +export function callbackToPromise(callBackOperation: (callback: Callback) => void, userCallback: Callback): void; +export function callbackToPromise(callBackOperation: (callback: Callback) => void): Promise; export function callbackToPromise(callBackOperation: (callback: Callback) => void, userCallback?: Callback): Promise | void { if (userCallback) { if (!(typeof userCallback === 'function')) { @@ -115,6 +117,8 @@ export function callbackToPromise(callBackOperation: (callback: Callbac * const param = 42; * errorCallbackToPromise((_callback) => foo(param, _callback)).then(_ => { }, err => { console.log(err); }); */ +export function errorCallbackToPromise(callBackOperation: (callback: ErrorCallback) => void, userCallback: ErrorCallback): void; +export function errorCallbackToPromise(callBackOperation: (callback: ErrorCallback) => void): Promise; export function errorCallbackToPromise(callBackOperation: (callback: ErrorCallback) => void, userCallback?: ErrorCallback): Promise | void { return callbackToPromise(callBackOperation, userCallback); } @@ -142,6 +146,8 @@ export function errorCallbackToPromise(callBackOperation: (callback: ErrorCallba * const param = 42; * noErrorCallbackToPromise((_callback) => foo(param, _callback)).then(result => { console.log(result); }, err => { console.log("it never rejects"); }); */ +export function noErrorCallbackToPromise(callBackOperation: (callback: NoErrorCallback) => void, userCallback: NoErrorCallback): void; +export function noErrorCallbackToPromise(callBackOperation: (callback: NoErrorCallback) => void): Promise; export function noErrorCallbackToPromise(callBackOperation: (callback: NoErrorCallback) => void, userCallback?: NoErrorCallback): Promise | void { if (userCallback) { if (!(typeof userCallback === 'function')) { @@ -188,6 +194,13 @@ export function noErrorCallbackToPromise(callBackOperation: (callback: * const param = 42; * doubleValueCallbackToPromise((_callback) => foo(param, _callback), pack).then(result => { console.log(result); }, err => { console.error(error); }); */ +export function doubleValueCallbackToPromise( + callBackOperation: (callback: DoubleValueCallback) => void, + packResults: (result1: TResult1, result2: TResult2) => TPromiseResult, + userCallback: DoubleValueCallback): void; +export function doubleValueCallbackToPromise( + callBackOperation: (callback: DoubleValueCallback) => void, + packResults: (result1: TResult1, result2: TResult2) => TPromiseResult): Promise; export function doubleValueCallbackToPromise( callBackOperation: (callback: DoubleValueCallback) => void, packResults: (result1: TResult1, result2: TResult2) => TPromiseResult, @@ -249,6 +262,13 @@ export function doubleValueCallbackToPromise * const param = 42; * tripleValueCallbackToPromise((_callback) => foo(param, _callback), pack).then(result => { console.log(result); }, err => { console.error(error); }); */ +export function tripleValueCallbackToPromise( + callbackOperation: (callback: TripleValueCallback) => void, + packResults: (result1: TResult1, result2: TResult2) => TPromiseResult, + userCallback: TripleValueCallback): void; +export function tripleValueCallbackToPromise( + callbackOperation: (callback: TripleValueCallback) => void, + packResults: (result1: TResult1, result2: TResult2) => TPromiseResult, ): Promise; export function tripleValueCallbackToPromise( callbackOperation: (callback: TripleValueCallback) => void, packResults: (result1: TResult1, result2: TResult2) => TPromiseResult, @@ -288,6 +308,10 @@ export function tripleValueCallbackToPromise * @returns {Promise | void} Promise with result of TResult type or void if user's callback provided * @template TResult - Type of the response body result. */ +export function httpCallbackToPromise( + callbackOperation: (callback: HttpResponseCallback) => void, callback: HttpResponseCallback): void; +export function httpCallbackToPromise( + callbackOperation: (callback: HttpResponseCallback) => void): Promise>; export function httpCallbackToPromise( callbackOperation: (callback: HttpResponseCallback) => void, callback?: HttpResponseCallback): Promise> | void { diff --git a/device/core/src/blob_upload/blob_upload_client.ts b/device/core/src/blob_upload/blob_upload_client.ts index 7edaa8862..07b13c46e 100644 --- a/device/core/src/blob_upload/blob_upload_client.ts +++ b/device/core/src/blob_upload/blob_upload_client.ts @@ -27,15 +27,18 @@ export interface UploadParams { * @private */ export interface FileUpload { - getBlobSharedAccessSignature(blobName: string, done?: Callback): void; + getBlobSharedAccessSignature(blobName: string, done: Callback): void; + getBlobSharedAccessSignature(blobName: string): Promise; notifyUploadComplete(correlationId: string, uploadResult: BlobUploadResult, done: (err?: Error) => void): void; + notifyUploadComplete(correlationId: string, uploadResult: BlobUploadResult): Promise; } /** * @private */ export interface BlobUploader { - uploadToBlob(uploadParams: UploadParams, stream: Stream, streamLength: number, done?: TripleValueCallback): void; + uploadToBlob(uploadParams: UploadParams, stream: Stream, streamLength: number, done: TripleValueCallback): void; + uploadToBlob(uploadParams: UploadParams, stream: Stream, streamLength: number): Promise; } /** @@ -43,6 +46,7 @@ export interface BlobUploader { */ export interface BlobUpload { uploadToBlob(blobName: string, stream: Stream, streamLength: number, done: (err?: Error) => void): void; + uploadToBlob(blobName: string, stream: Stream, streamLength: number): Promise; } /** @@ -65,6 +69,8 @@ export class BlobUploadClient implements BlobUpload { this._blobUploader = blobUploader ? blobUploader : new DefaultBlobUploader(); } + uploadToBlob(blobName: string, stream: Stream, streamLength: number, done: ErrorCallback): void; + uploadToBlob(blobName: string, stream: Stream, streamLength: number): Promise; uploadToBlob(blobName: string, stream: Stream, streamLength: number, done?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { /*Codes_SRS_NODE_DEVICE_BLOB_UPLOAD_CLIENT_16_004: [`uploadToBlob` shall obtain a blob SAS token using the IoT Hub service file upload API endpoint.]*/ diff --git a/device/core/src/blob_upload/blob_uploader.ts b/device/core/src/blob_upload/blob_uploader.ts index e9ee97fc0..d69ab5e6a 100644 --- a/device/core/src/blob_upload/blob_uploader.ts +++ b/device/core/src/blob_upload/blob_uploader.ts @@ -46,6 +46,8 @@ export class BlobUploader implements BlobUploaderInterface { } } + uploadToBlob(blobInfo: UploadParams, stream: Stream, streamLength: number, done: TripleValueCallback): void; + uploadToBlob(blobInfo: UploadParams, stream: Stream, streamLength: number): Promise<{ body: any, result: BlobResponse }>; uploadToBlob(blobInfo: UploadParams, stream: Stream, streamLength: number, done?: TripleValueCallback): Promise<{ body: any, result: BlobResponse }> | void { tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_DEVICE_BLOB_UPLOAD_16_001: [`uploadToBlob` shall throw a `ReferenceError` if `blobInfo` is falsy.]*/ diff --git a/device/core/src/blob_upload/file_upload_api.ts b/device/core/src/blob_upload/file_upload_api.ts index 95da7a271..f8f294cc0 100644 --- a/device/core/src/blob_upload/file_upload_api.ts +++ b/device/core/src/blob_upload/file_upload_api.ts @@ -37,6 +37,8 @@ export class FileUploadApi implements FileUploadInterface { this.http = httpTransport ? httpTransport : new DefaultHttpTransport(); } + getBlobSharedAccessSignature(blobName: string, done: Callback): void; + getBlobSharedAccessSignature(blobName: string): Promise; getBlobSharedAccessSignature(blobName: string, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_FILE_UPLOAD_ENDPOINT_16_004: [`getBlobSharedAccessSignature` shall throw a `ReferenceError` if `blobName` is falsy.]*/ @@ -93,6 +95,8 @@ export class FileUploadApi implements FileUploadInterface { }, done); } + notifyUploadComplete(correlationId: string, uploadResult: BlobUploadResult, done: ErrorCallback): void; + notifyUploadComplete(correlationId: string, uploadResult: BlobUploadResult): Promise; notifyUploadComplete(correlationId: string, uploadResult: BlobUploadResult, done?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { /*Codes_SRS_NODE_FILE_UPLOAD_ENDPOINT_16_010: [`notifyUploadComplete` shall throw a `ReferenceError` if `correlationId` is falsy.]*/ diff --git a/device/core/src/device_client.ts b/device/core/src/device_client.ts index 4d1ab1930..b071c66cc 100644 --- a/device/core/src/device_client.ts +++ b/device/core/src/device_client.ts @@ -99,6 +99,8 @@ export class Client extends InternalClient { * @param {Callback} [closeCallback] Optional function to call once the transport is disconnected and the client closed. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + close(closeCallback: Callback): void; + close(): Promise; close(closeCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { this._transport.removeListener('disconnect', this._deviceDisconnectHandler); @@ -127,6 +129,8 @@ export class Client extends InternalClient { * * @throws {ReferenceException} If blobName or stream or streamLength is falsy. */ + uploadToBlob(blobName: string, stream: Stream, streamLength: number, callback: ErrorCallback): void; + uploadToBlob(blobName: string, stream: Stream, streamLength: number): Promise; uploadToBlob(blobName: string, stream: Stream, streamLength: number, callback?: ErrorCallback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_DEVICE_CLIENT_16_037: [The `uploadToBlob` method shall throw a `ReferenceError` if `blobName` is falsy.]*/ @@ -186,7 +190,7 @@ export class Client extends InternalClient { * * @returns {module:azure-iot-device.Client} */ - static fromConnectionString(connStr: string, transportCtor: any): any { + static fromConnectionString(connStr: string, transportCtor: any): Client { /*Codes_SRS_NODE_DEVICE_CLIENT_05_003: [The fromConnectionString method shall throw ReferenceError if the connStr argument is falsy.]*/ if (!connStr) throw new ReferenceError('connStr is \'' + connStr + '\''); @@ -225,7 +229,7 @@ export class Client extends InternalClient { * * @returns {module:azure-iothub.Client} */ - static fromSharedAccessSignature(sharedAccessSignature: string, transportCtor: any): any { + static fromSharedAccessSignature(sharedAccessSignature: string, transportCtor: any): Client { /*Codes_SRS_NODE_DEVICE_CLIENT_16_029: [The fromSharedAccessSignature method shall throw a ReferenceError if the sharedAccessSignature argument is falsy.] */ if (!sharedAccessSignature) throw new ReferenceError('sharedAccessSignature is \'' + sharedAccessSignature + '\''); @@ -242,7 +246,7 @@ export class Client extends InternalClient { * @param authenticationProvider Object used to obtain the authentication parameters for the IoT hub. * @param transportCtor Transport protocol used to connect to IoT hub. */ - static fromAuthenticationProvider(authenticationProvider: AuthenticationProvider, transportCtor: any): any { + static fromAuthenticationProvider(authenticationProvider: AuthenticationProvider, transportCtor: any): Client { /*Codes_SRS_NODE_DEVICE_CLIENT_16_089: [The `fromAuthenticationProvider` method shall throw a `ReferenceError` if the `authenticationProvider` argument is falsy.]*/ if (!authenticationProvider) { throw new ReferenceError('authenticationMethod cannot be \'' + authenticationProvider + '\''); diff --git a/device/core/src/device_method/device_method_response.ts b/device/core/src/device_method/device_method_response.ts index 34eb11bd4..3f8323db2 100644 --- a/device/core/src/device_method/device_method_response.ts +++ b/device/core/src/device_method/device_method_response.ts @@ -75,6 +75,9 @@ export class DeviceMethodResponse { * service in a previous call to it. This method * should be called only once. */ + send(status: number, payload: any, done: ErrorCallback): void; + send(status: number, done: ErrorCallback): void; + send(status: number, payload?: any): Promise; send(status: number, payload?: any | ErrorCallback, done?: ErrorCallback): Promise | void { if (typeof (payload) === 'function') { if (done !== undefined) { diff --git a/device/core/src/device_method/method_client.ts b/device/core/src/device_method/method_client.ts index 798b9c59c..66ae4ff83 100644 --- a/device/core/src/device_method/method_client.ts +++ b/device/core/src/device_method/method_client.ts @@ -26,6 +26,8 @@ export class MethodClient { }; } + invokeMethod(deviceId: string, moduleId: string, methodParams: MethodParams, callback: MethodCallback): void; + invokeMethod(deviceId: string, moduleId: string, methodParams: MethodParams): Promise; invokeMethod(deviceId: string, moduleId: string, methodParams: MethodParams, callback?: MethodCallback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_DEVICE_METHOD_CLIENT_16_006: [The `invokeMethod` method shall get the latest credentials by calling `getDeviceCredentials` on the `AuthenticationProvider` object.]*/ diff --git a/device/core/src/internal_client.ts b/device/core/src/internal_client.ts index c15a79ba8..3da85eeb6 100644 --- a/device/core/src/internal_client.ts +++ b/device/core/src/internal_client.ts @@ -122,7 +122,7 @@ export abstract class InternalClient extends EventEmitter { err - null response - a transport-specific response object]*/ - updateSharedAccessSignature(sharedAccessSignature: string, updateSasCallback?: (err?: Error, result?: results.SharedAccessSignatureUpdated) => void): void { + updateSharedAccessSignature(sharedAccessSignature: string, updateSasCallback?: Callback): void { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_031: [The updateSharedAccessSignature method shall throw a ReferenceError if the sharedAccessSignature parameter is falsy.]*/ if (!sharedAccessSignature) throw new ReferenceError('sharedAccessSignature is falsy'); @@ -137,6 +137,8 @@ export abstract class InternalClient extends EventEmitter { }); } + open(openCallback: Callback): void; + open(): Promise; open(openCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); @@ -149,6 +151,8 @@ export abstract class InternalClient extends EventEmitter { }, openCallback); } + sendEvent(message: Message, sendEventCallback: Callback): void; + sendEvent(message: Message): Promise; sendEvent(message: Message, sendEventCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); @@ -161,6 +165,8 @@ export abstract class InternalClient extends EventEmitter { }, sendEventCallback); } + sendEventBatch(messages: Message[], sendEventBatchCallback: Callback): void; + sendEventBatch(messages: Message[]): Promise; sendEventBatch(messages: Message[], sendEventBatchCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); @@ -173,6 +179,8 @@ export abstract class InternalClient extends EventEmitter { }, sendEventBatchCallback); } + close(closeCallback: Callback): void; + close(): Promise; close(closeCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { this._closeTransport((err, result) => { @@ -181,6 +189,8 @@ export abstract class InternalClient extends EventEmitter { }, closeCallback); } + setTransportOptions(options: any, done: Callback): void; + setTransportOptions(options: any): Promise; setTransportOptions(options: any, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_024: [The ‘setTransportOptions’ method shall throw a ‘ReferenceError’ if the options object is falsy] */ @@ -214,6 +224,8 @@ export abstract class InternalClient extends EventEmitter { * @param [done] The optional callback to call once the options have been set. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + setOptions(options: DeviceClientOptions, done: Callback): void; + setOptions(options: DeviceClientOptions): Promise; setOptions(options: DeviceClientOptions, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_042: [The `setOptions` method shall throw a `ReferenceError` if the options object is falsy.]*/ @@ -239,6 +251,8 @@ export abstract class InternalClient extends EventEmitter { }, done); } + complete(message: Message, completeCallback: Callback): void; + complete(message: Message): Promise; complete(message: Message, completeCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_016: [The ‘complete’ method shall throw a ReferenceError if the ‘message’ parameter is falsy.] */ @@ -253,6 +267,8 @@ export abstract class InternalClient extends EventEmitter { }, completeCallback); } + reject(message: Message, rejectCallback: Callback): void; + reject(message: Message): Promise; reject(message: Message, rejectCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_018: [The reject method shall throw a ReferenceError if the ‘message’ parameter is falsy.] */ @@ -266,6 +282,8 @@ export abstract class InternalClient extends EventEmitter { }, rejectCallback); } + abandon(message: Message, abandonCallback: Callback): void; + abandon(message: Message): Promise; abandon(message: Message, abandonCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_017: [The abandon method shall throw a ReferenceError if the ‘message’ parameter is falsy.] */ @@ -280,7 +298,9 @@ export abstract class InternalClient extends EventEmitter { }, abandonCallback); } - getTwin(done: Callback): Promise | void { + getTwin(done: Callback): void; + getTwin(): Promise; + getTwin(done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_INTERNAL_CLIENT_16_094: [If this is the first call to `getTwin` the method shall instantiate a new `Twin` object and pass it the transport currently in use.]*/ if (!this._twin) { diff --git a/device/core/src/module_client.ts b/device/core/src/module_client.ts index 40b83437d..136ed0788 100644 --- a/device/core/src/module_client.ts +++ b/device/core/src/module_client.ts @@ -102,6 +102,8 @@ export class ModuleClient extends InternalClient { * @param [callback] Optional function to call when the operation has been queued. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + sendOutputEvent(outputName: string, message: Message, callback: Callback): void; + sendOutputEvent(outputName: string, message: Message): Promise; sendOutputEvent(outputName: string, message: Message, callback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); @@ -123,7 +125,9 @@ export class ModuleClient extends InternalClient { * @param [callback] Function to call when the operations have been queued. * @returns {Promise | void} Optional promise if no callback function was passed, void otherwise. */ - sendOutputEventBatch(outputName: string, messages: Message[], callback: Callback): Promise | void { + sendOutputEventBatch(outputName: string, messages: Message[], callback: Callback): void; + sendOutputEventBatch(outputName: string, messages: Message[]): Promise; + sendOutputEventBatch(outputName: string, messages: Message[], callback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); retryOp.retry((opCallback) => { @@ -145,6 +149,8 @@ export class ModuleClient extends InternalClient { * @param [closeCallback] Optional function to call once the transport is disconnected and the client closed. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + close(closeCallback: Callback): void; + close(): Promise; close(closeCallback?: Callback): Promise | void { return callbackToPromise((_callback) => { this._transport.removeListener('disconnect', this._moduleDisconnectHandler); @@ -195,14 +201,16 @@ export class ModuleClient extends InternalClient { */ invokeMethod(deviceId: string, methodParams: MethodParams, callback: Callback): void; invokeMethod(deviceId: string, moduleId: string, methodParams: MethodParams, callback: Callback): void; - invokeMethod(deviceId: string, moduleIdOrMethodParams: string | MethodParams, methodParamsOrCallback: MethodParams | Callback, callback?: Callback): Promise | void { + invokeMethod(deviceId: string, methodParams: MethodParams): Promise; + invokeMethod(deviceId: string, moduleId: string, methodParams: MethodParams): Promise; + invokeMethod(deviceId: string, moduleIdOrMethodParams: string | MethodParams, methodParamsOrCallback?: MethodParams | Callback, callback?: Callback): Promise | void { if (callback) { return this._invokeMethod(deviceId, moduleIdOrMethodParams as string, methodParamsOrCallback as MethodParams, callback); } else if (typeof methodParamsOrCallback === 'function') { return this._invokeMethod(deviceId, moduleIdOrMethodParams as MethodParams, methodParamsOrCallback as Callback); } - return callbackToPromise((_callback) => this._invokeMethod(deviceId, methodParamsOrCallback as any, methodParamsOrCallback as MethodParams, _callback)); + return callbackToPromise((_callback) => this._invokeMethod(deviceId, moduleIdOrMethodParams as any, methodParamsOrCallback as MethodParams, _callback)); } /** @@ -221,6 +229,8 @@ export class ModuleClient extends InternalClient { * @param [done] Optional callback to call once the options have been set. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + setOptions(options: DeviceClientOptions, done: Callback): void; + setOptions(options: DeviceClientOptions): Promise; setOptions(options: DeviceClientOptions, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_MODULE_CLIENT_16_098: [The `setOptions` method shall call the `setOptions` method with the `options` argument on the `MethodClient` object of the `ModuleClient`.]*/ @@ -303,7 +313,7 @@ export class ModuleClient extends InternalClient { * * @returns {module:azure-iothub.Client} */ - static fromSharedAccessSignature(sharedAccessSignature: string, transportCtor: any): any { + static fromSharedAccessSignature(sharedAccessSignature: string, transportCtor: any): ModuleClient { /*Codes_SRS_NODE_MODULE_CLIENT_16_029: [The fromSharedAccessSignature method shall throw a ReferenceError if the sharedAccessSignature argument is falsy.] */ if (!sharedAccessSignature) throw new ReferenceError('sharedAccessSignature is \'' + sharedAccessSignature + '\''); @@ -319,7 +329,7 @@ export class ModuleClient extends InternalClient { * @param authenticationProvider Object used to obtain the authentication parameters for the IoT hub. * @param transportCtor Transport protocol used to connect to IoT hub. */ - static fromAuthenticationProvider(authenticationProvider: AuthenticationProvider, transportCtor: any): any { + static fromAuthenticationProvider(authenticationProvider: AuthenticationProvider, transportCtor: any): ModuleClient { /*Codes_SRS_NODE_MODULE_CLIENT_16_089: [The `fromAuthenticationProvider` method shall throw a `ReferenceError` if the `authenticationProvider` argument is falsy.]*/ if (!authenticationProvider) { throw new ReferenceError('authenticationMethod cannot be \'' + authenticationProvider + '\''); @@ -353,6 +363,8 @@ export class ModuleClient extends InternalClient { * error occurs while creating the client. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + static fromEnvironment(transportCtor: any, callback: Callback): void; + static fromEnvironment(transportCtor: any): Promise; static fromEnvironment(transportCtor: any, callback?: Callback): Promise | void { return callbackToPromise((_callback) => { // Codes_SRS_NODE_MODULE_CLIENT_13_033: [ The fromEnvironment method shall throw a ReferenceError if the callback argument is falsy or is not a function. ] diff --git a/device/core/src/sak_authentication_provider.ts b/device/core/src/sak_authentication_provider.ts index 8ea85d8f3..c35c9c4fb 100644 --- a/device/core/src/sak_authentication_provider.ts +++ b/device/core/src/sak_authentication_provider.ts @@ -50,6 +50,8 @@ export class SharedAccessKeyAuthenticationProvider extends EventEmitter implemen * @param [callback] optional function that will be called with either an error or a set of device credentials that can be used to authenticate with the IoT hub. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + getDeviceCredentials(callback: Callback): void; + getDeviceCredentials(): Promise; getDeviceCredentials(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { if (this._shouldRenewToken()) { diff --git a/device/core/src/sas_authentication_provider.ts b/device/core/src/sas_authentication_provider.ts index 768b28097..8b9157497 100644 --- a/device/core/src/sas_authentication_provider.ts +++ b/device/core/src/sas_authentication_provider.ts @@ -36,6 +36,8 @@ export class SharedAccessSignatureAuthenticationProvider extends EventEmitter im * @param [callback] optional function that will be called with either an error or a set of device credentials that can be used to authenticate with the IoT hub. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + getDeviceCredentials(callback: Callback): void; + getDeviceCredentials(): Promise; getDeviceCredentials(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_SAS_AUTHENTICATION_PROVIDER_16_002: [The `getDeviceCredentials` method shall call its callback with a `null` error parameter and the stored `credentials` object containing the current device credentials.]*/ diff --git a/device/core/src/twin.ts b/device/core/src/twin.ts index 18a70f33c..0b3543926 100644 --- a/device/core/src/twin.ts +++ b/device/core/src/twin.ts @@ -79,6 +79,8 @@ export class Twin extends EventEmitter { * @param [callback] optional function that shall be called back with either the twin or an error if the transport fails to retrieve the twin. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + get(callback: Callback): void; + get(): Promise; get(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { const retryOp = new RetryOperation(this._retryPolicy, this._maxOperationTimeout); diff --git a/device/core/src/utils.ts b/device/core/src/utils.ts index e8c0ccf63..485ba5e96 100644 --- a/device/core/src/utils.ts +++ b/device/core/src/utils.ts @@ -9,6 +9,8 @@ import { NoErrorCallback, noErrorCallbackToPromise } from 'azure-iot-common'; // tslint:disable-next-line:no-var-requires const packageJson = require('../package.json'); +export function getUserAgentString(done: NoErrorCallback): void; +export function getUserAgentString(): Promise; export function getUserAgentString(done?: NoErrorCallback): Promise | void { return noErrorCallbackToPromise((_callback) => { /*Codes_SRS_NODE_DEVICE_UTILS_18_001: [`getUserAgentString` shall call `getAgentPlatformString` to get the platform string.]*/ diff --git a/device/core/src/x509_authentication_provider.ts b/device/core/src/x509_authentication_provider.ts index 0a11a7a46..315259d54 100644 --- a/device/core/src/x509_authentication_provider.ts +++ b/device/core/src/x509_authentication_provider.ts @@ -28,6 +28,8 @@ export class X509AuthenticationProvider implements AuthenticationProvider { * @param [callback] optional function that will be called with either an error or a set of device credentials that can be used to authenticate with the IoT hub. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + getDeviceCredentials(callback: Callback): void; + getDeviceCredentials(): Promise; getDeviceCredentials(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_X509_AUTHENTICATION_PROVIDER_16_002: [The `getDeviceCredentials` method shall call its callback with a `null` error object and the stored device credentials as a second argument.]*/ diff --git a/provisioning/device/src/polling_state_machine.ts b/provisioning/device/src/polling_state_machine.ts index 50440cf0b..150f07ba7 100644 --- a/provisioning/device/src/polling_state_machine.ts +++ b/provisioning/device/src/polling_state_machine.ts @@ -237,13 +237,17 @@ export class PollingStateMachine extends EventEmitter { }); } - register(request: RegistrationRequest, callback: Callback): Promise | void { + register(request: RegistrationRequest, callback: Callback): void; + register(request: RegistrationRequest): Promise; + register(request: RegistrationRequest, callback?: Callback): Promise | void { return callbackToPromise((_callback) => { debug('register called for registrationId "' + request.registrationId + '"'); this._fsm.handle('register', request, _callback); }, callback); } + cancel(callback: ErrorCallback): void; + cancel(): Promise; cancel(callback?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { debug('cancel called'); @@ -251,6 +255,8 @@ export class PollingStateMachine extends EventEmitter { }, callback); } + disconnect(callback: ErrorCallback): void; + disconnect(): Promise; disconnect(callback?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { debug('disconnect called'); diff --git a/provisioning/device/src/tpm_registration.ts b/provisioning/device/src/tpm_registration.ts index f54a13ea7..0d75b0266 100644 --- a/provisioning/device/src/tpm_registration.ts +++ b/provisioning/device/src/tpm_registration.ts @@ -224,6 +224,8 @@ export class TpmRegistration extends EventEmitter implements RegistrationClient } + register(callback: Callback): void; + register(): Promise; register(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { let registrationInfo: TpmRegistrationInfo = { @@ -240,6 +242,8 @@ export class TpmRegistration extends EventEmitter implements RegistrationClient }, callback); } + cancel(callback: ErrorCallback): void; + cancel(): Promise; cancel(callback?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { this._fsm.handle('cancel', _callback); diff --git a/provisioning/device/src/x509_registration.ts b/provisioning/device/src/x509_registration.ts index f6a4729d1..dc5c96c1b 100644 --- a/provisioning/device/src/x509_registration.ts +++ b/provisioning/device/src/x509_registration.ts @@ -37,6 +37,8 @@ export class X509Registration implements RegistrationClient { * @param [callback] optional function called when registration is complete. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + register(callback: Callback): void; + register(): Promise; register(callback?: Callback): Promise | void { return callbackToPromise((_callback) => { @@ -81,6 +83,8 @@ export class X509Registration implements RegistrationClient { * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ /* Codes_SRS_NODE_DPS_X509_REGISTRATION_18_003: [ `cancel` shall call `endSession` on the transport object. ] */ + cancel(callback: ErrorCallback): void; + cancel(): Promise; cancel(callback?: ErrorCallback): Promise | void { return errorCallbackToPromise((_callback) => { this._transport.cancel(_callback); diff --git a/provisioning/service/src/provisioningserviceclient.ts b/provisioning/service/src/provisioningserviceclient.ts index 63b4a5316..134cb5805 100644 --- a/provisioning/service/src/provisioningserviceclient.ts +++ b/provisioning/service/src/provisioningserviceclient.ts @@ -46,6 +46,8 @@ export class ProvisioningServiceClient { * @param {function} [callback] Invoked upon completion of the operation. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + public createOrUpdateIndividualEnrollment(enrollment: IndividualEnrollment, callback: HttpResponseCallback): void; + public createOrUpdateIndividualEnrollment(enrollment: IndividualEnrollment): Promise>; public createOrUpdateIndividualEnrollment(enrollment: IndividualEnrollment, callback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._createOrUpdate(this._enrollmentsPrefix, enrollment, _callback); @@ -60,6 +62,10 @@ export class ProvisioningServiceClient { * @param {function} [deleteCallback] Invoked upon completion of the operation. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + public deleteIndividualEnrollment(enrollmentOrId: string | IndividualEnrollment, etag: string, deleteCallback: ErrorCallback): void; + public deleteIndividualEnrollment(enrollmentOrId: string | IndividualEnrollment, deleteCallback: ErrorCallback): void; + public deleteIndividualEnrollment(enrollmentOrId: string | IndividualEnrollment, etagOr: string): Promise; + public deleteIndividualEnrollment(enrollmentOrId: string | IndividualEnrollment): Promise; public deleteIndividualEnrollment(enrollmentOrId: string | IndividualEnrollment, etagOrCallback?: string | ErrorCallback, deleteCallback?: ErrorCallback): Promise | void { if (deleteCallback && !(typeof deleteCallback === 'function')) { throw new ArgumentError('Callback has to be a Function'); @@ -82,6 +88,8 @@ export class ProvisioningServiceClient { * @param {function} [getCallback] Invoked upon completion of the operation. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + public getIndividualEnrollment(id: string, getCallback: HttpResponseCallback): void; + public getIndividualEnrollment(id: string): Promise>; public getIndividualEnrollment(id: string, getCallback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._get(this._enrollmentsPrefix, id, _callback); @@ -105,6 +113,8 @@ export class ProvisioningServiceClient { * @param {function} [callback] Invoked upon completion of the operation. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + public getDeviceRegistrationState(id: string, callback: HttpResponseCallback): void; + public getDeviceRegistrationState(id: string): Promise>; public getDeviceRegistrationState(id: string, callback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._get(this._registrationsPrefix, id, _callback); @@ -118,6 +128,8 @@ export class ProvisioningServiceClient { * @param {function} [callback] Invoked upon completion of the operation. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + public createOrUpdateEnrollmentGroup(enrollmentGroup: EnrollmentGroup, callback: HttpResponseCallback): void; + public createOrUpdateEnrollmentGroup(enrollmentGroup: EnrollmentGroup): Promise>; public createOrUpdateEnrollmentGroup(enrollmentGroup: EnrollmentGroup, callback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._createOrUpdate(this._enrollmentGroupsPrefix, enrollmentGroup, _callback); @@ -132,6 +144,10 @@ export class ProvisioningServiceClient { * @param {function} [deleteCallback] Invoked upon completion of the operation. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + public deleteEnrollmentGroup(enrollmentGroupOrId: string | EnrollmentGroup, etag: string, deleteCallback: ErrorCallback): void; + public deleteEnrollmentGroup(enrollmentGroupOrId: string | EnrollmentGroup, deleteCallback: ErrorCallback): void; + public deleteEnrollmentGroup(enrollmentGroupOrId: string | EnrollmentGroup, etag: string): Promise; + public deleteEnrollmentGroup(enrollmentGroupOrId: string | EnrollmentGroup): Promise; public deleteEnrollmentGroup(enrollmentGroupOrId: string | EnrollmentGroup, etagOrCallback?: string | ErrorCallback, deleteCallback?: ErrorCallback): Promise | void { if (deleteCallback && !(typeof deleteCallback === 'function')) { throw new ArgumentError('Callback has to be a Function'); @@ -154,6 +170,8 @@ export class ProvisioningServiceClient { * @param {function} [getCallback] Invoked upon completion of the operation. * @returns {ResultWithHttpResponse | void} Promise if no callback function was passed, void otherwise. */ + public getEnrollmentGroup(id: string, getCallback: HttpResponseCallback): void; + public getEnrollmentGroup(id: string): Promise>; public getEnrollmentGroup(id: string, getCallback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._get(this._enrollmentGroupsPrefix, id, _callback); @@ -190,6 +208,8 @@ export class ProvisioningServiceClient { * @param {object} bulkEnrollmentOperation An object that specifies the single kind of CRUD operations on the array of IndividualEnrollment objects that are also part of the object. * @param {function} callback Invoked upon completion of the operation. */ + public runBulkEnrollmentOperation(bulkEnrollmentOperation: BulkEnrollmentOperation, callback: HttpResponseCallback): void; + public runBulkEnrollmentOperation(bulkEnrollmentOperation: BulkEnrollmentOperation): Promise>; public runBulkEnrollmentOperation(bulkEnrollmentOperation: BulkEnrollmentOperation, callback?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_038: [The `runBulkEnrollmentOperation` method shall throw `ReferenceError` if the `bulkEnrollmentOperation` argument is falsy.] */ @@ -232,6 +252,10 @@ export class ProvisioningServiceClient { * @param {function} [deleteCallback] Invoked upon completion of the operation. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + public deleteDeviceRegistrationState(idOrRegistrationState: string | DeviceRegistrationState, etag: string, deleteCallback: ErrorCallback): void; + public deleteDeviceRegistrationState(idOrRegistrationState: string | DeviceRegistrationState, deleteCallback: ErrorCallback): void; + public deleteDeviceRegistrationState(idOrRegistrationState: string | DeviceRegistrationState, etagOrCallback: string): Promise; + public deleteDeviceRegistrationState(idOrRegistrationState: string | DeviceRegistrationState): Promise; public deleteDeviceRegistrationState(idOrRegistrationState: string | DeviceRegistrationState, etagOrCallback?: string | ErrorCallback, deleteCallback?: ErrorCallback): Promise | void { if (deleteCallback && !(typeof deleteCallback === 'function')) { throw new ArgumentError('Callback has to be a Function'); diff --git a/provisioning/service/src/query.ts b/provisioning/service/src/query.ts index 69c2d6790..9c116397f 100644 --- a/provisioning/service/src/query.ts +++ b/provisioning/service/src/query.ts @@ -51,7 +51,11 @@ export class Query { * the results of the query. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ - next(continuationTokenOrCallback: string | QueryCallback, done?: QueryCallback): Promise> | void { + next(done: QueryCallback): void; + next(continuationToken: string, done: QueryCallback): void; + next(): Promise>; + next(continuationToken: string): Promise>; + next(continuationTokenOrCallback?: string | QueryCallback, done?: QueryCallback): Promise> | void { const callback = done || ((typeof continuationTokenOrCallback === 'function') ? continuationTokenOrCallback : undefined); return httpCallbackToPromise((_callback) => { diff --git a/service/src/amqp.ts b/service/src/amqp.ts index 5137862b9..83734b459 100644 --- a/service/src/amqp.ts +++ b/service/src/amqp.ts @@ -417,6 +417,8 @@ export class Amqp extends EventEmitter implements Client.Transport { * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_019: [The `connect` method shall call the `connect` method of the base AMQP transport and translate its result to the caller into a transport-agnostic object.]*/ + connect(done: Callback): void; + connect(): Promise; connect(done?: Callback): Promise | void { return callbackToPromise((_callback) => { this._fsm.handle('connect', (err) => { @@ -437,6 +439,8 @@ export class Amqp extends EventEmitter implements Client.Transport { * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_020: [** The `disconnect` method shall call the `disconnect` method of the base AMQP transport and translate its result to the caller into a transport-agnostic object.]*/ + disconnect(done: Callback): void; + disconnect(): Promise; disconnect(done?: Callback): Promise | void { return callbackToPromise((_callback) => { this._fsm.handle('disconnect', (err) => { @@ -461,6 +465,8 @@ export class Amqp extends EventEmitter implements Client.Transport { */ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_002: [The send method shall construct an AMQP request using the message passed in argument as the body of the message.]*/ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_003: [The message generated by the send method should have its “to” field set to "/devices/(uriEncode)/messages/devicebound".]*/ + send(deviceId: string, message: Message, done: IncomingMessageCallback): void; + send(deviceId: string, message: Message): Promise>; send(deviceId: string, message: Message, done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { const deviceEndpoint = endpoint.deviceMessagePath(encodeURIComponent(deviceId)); @@ -478,6 +484,8 @@ export class Amqp extends EventEmitter implements Client.Transport { * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_013: [The `getFeedbackReceiver` method shall request an `AmqpReceiver` object from the base AMQP transport for the `/messages/serviceBound/feedback` endpoint.]*/ + getFeedbackReceiver(done: IncomingMessageCallback): void; + getFeedbackReceiver(): Promise>; getFeedbackReceiver(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { this._fsm.handle('getFeedbackReceiver', handleResult('AMQP Transport: Could not get feedback receiver', _callback)); @@ -492,6 +500,8 @@ export class Amqp extends EventEmitter implements Client.Transport { * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ /*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_016: [The `getFeedbackReceiver` method shall request an `AmqpReceiver` object from the base AMQP transport for the `/messages/serviceBound/filenotifications` endpoint.]*/ + getFileNotificationReceiver(done: IncomingMessageCallback): void; + getFileNotificationReceiver(): Promise>; getFileNotificationReceiver(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { this._fsm.handle('getFileNotificationReceiver', handleResult('AMQP Transport: Could not get file notification receiver', _callback)); @@ -505,6 +515,8 @@ export class Amqp extends EventEmitter implements Client.Transport { * @param [callback] Optional function called when the callback has been successfully called. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + updateSharedAccessSignature(sharedAccessSignature: string, callback: Callback): void; + updateSharedAccessSignature(sharedAccessSignature: string): Promise; updateSharedAccessSignature(sharedAccessSignature: string, callback?: Callback): Promise | void { return callbackToPromise((_callback) => { if (!sharedAccessSignature) { diff --git a/service/src/client.ts b/service/src/client.ts index 301458d22..961a6b8d4 100644 --- a/service/src/client.ts +++ b/service/src/client.ts @@ -65,6 +65,8 @@ export class Client extends EventEmitter { * completed successfully. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + open(done: IncomingMessageCallback): void; + open(): Promise>; open(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_CLIENT_05_008: [The open method shall open a connection to the IoT Hub that was identified when the Client object was created (e.g., in Client.fromConnectionString).]*/ @@ -100,6 +102,8 @@ export class Client extends EventEmitter { * completed successfully. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + close(done: IncomingMessageCallback): void; + close(): Promise>; close(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_CLIENT_05_021: [The close method shall close the connection.]*/ @@ -138,6 +142,8 @@ export class Client extends EventEmitter { * * @throws {ReferenceError} If `deviceId` or `message` is null, undefined or empty. */ + send(deviceId: string, message: Message | Message.BufferConvertible, done: IncomingMessageCallback): void; + send(deviceId: string, message: Message | Message.BufferConvertible): Promise>; send(deviceId: string, message: Message | Message.BufferConvertible, done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_CLIENT_05_013: [The send method shall throw ReferenceError if the deviceId or message arguments are falsy.]*/ @@ -245,6 +251,8 @@ export class Client extends EventEmitter { */ invokeDeviceMethod(deviceId: string, methodParams: DeviceMethodParams, done?: IncomingMessageCallback): void; invokeDeviceMethod(deviceId: string, moduleId: string, methodParams: DeviceMethodParams, done?: IncomingMessageCallback): void; + invokeDeviceMethod(deviceId: string, methodParams: DeviceMethodParams): Promise>; + invokeDeviceMethod(deviceId: string, moduleId: string, methodParams: DeviceMethodParams): Promise>; invokeDeviceMethod(deviceId: string, moduleIdOrMethodParams: string | DeviceMethodParams, methodParamsOrDone?: DeviceMethodParams | IncomingMessageCallback, done?: IncomingMessageCallback): Promise> | void { const callback = done || ((typeof methodParamsOrDone === 'function') ? methodParamsOrDone as IncomingMessageCallback : undefined); if (callback) { @@ -265,6 +273,8 @@ export class Client extends EventEmitter { * AmqpReceiver object. * @returns {ResultWithIncomingMessage | void} Promise if no callback function was passed, void otherwise. */ + getFeedbackReceiver(done: IncomingMessageCallback): void; + getFeedbackReceiver(): Promise>; getFeedbackReceiver(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_CLIENT_05_027: [When the `getFeedbackReceiver` method completes, the callback function (indicated by the `done` argument) shall be invoked with the following arguments: @@ -301,6 +311,8 @@ export class Client extends EventEmitter { * AmqpReceiver object. * @returns {ResultWithIncomingMessage | void} Promise if no callback function was passed, void otherwise. */ + getFileNotificationReceiver(done: IncomingMessageCallback): void; + getFileNotificationReceiver(): Promise>; getFileNotificationReceiver(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_CLIENT_16_001: [When the `getFileNotificationReceiver` method completes, the callback function (indicated by the `done` argument) shall be invoked with the following arguments: diff --git a/service/src/device_method.ts b/service/src/device_method.ts index 97f372e9c..341ef058b 100644 --- a/service/src/device_method.ts +++ b/service/src/device_method.ts @@ -60,6 +60,8 @@ export class DeviceMethod { * debugging. * @returns {Promise<{ device?: any, response?: any }> | void} Promise if no callback function was passed, void otherwise. */ + invokeOn(deviceId: string, done: TripleValueCallback): void; + invokeOn(deviceId: string): Promise<{ device?: any, response?: any }>; invokeOn(deviceId: string, done?: TripleValueCallback): Promise<{ device?: any, response?: any }> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_DEVICE_METHOD_16_008: [The `invokeOn` method shall throw a `ReferenceError` if `deviceId` is `null`, `undefined` or an empty string.]*/ @@ -105,6 +107,8 @@ export class DeviceMethod { * debugging. * @returns {Promise<{ device?: any, response?: any }> | void} Promise if no callback function was passed, void otherwise. */ + invokeOnModule(deviceId: string, moduleId: string, done: TripleValueCallback): void; + invokeOnModule(deviceId: string, moduleId: string): Promise<{ device?: any, response?: any }>; invokeOnModule(deviceId: string, moduleId: string, done?: TripleValueCallback): Promise<{ device?: any, response?: any }> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_DEVICE_METHOD_18_001: [The `invokeOnModule` method shall throw a `ReferenceError` if `deviceId` or `moduleId` is falsy. ]*/ diff --git a/service/src/job_client.ts b/service/src/job_client.ts index 7c1012ca7..fd5647cdf 100644 --- a/service/src/job_client.ts +++ b/service/src/job_client.ts @@ -68,6 +68,8 @@ export class JobClient { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + getJob(jobId: string | number, done: TripleValueCallback): void; + getJob(jobId: string | number): Promise; getJob(jobId: string | number, done?: TripleValueCallback): Promise | void { /*Codes_SRS_NODE_JOB_CLIENT_16_006: [The `getJob` method shall throw a `ReferenceError` if `jobId` is `null`, `undefined` or an empty string.]*/ return tripleValueCallbackToPromise((_callback) => { @@ -110,6 +112,8 @@ export class JobClient { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + cancelJob(jobId: string | number, done: TripleValueCallback): void; + cancelJob(jobId: string | number): Promise; cancelJob(jobId: string | number, done?: TripleValueCallback): Promise | void { /*Codes_SRS_NODE_JOB_CLIENT_16_008: [The `cancelJob` method shall throw a `ReferenceError` if `jobId` is `null`, `undefined` or an empty string.]*/ return tripleValueCallbackToPromise((_callback) => { @@ -152,6 +156,12 @@ export class JobClient { * @throws {ReferenceError} If methodParams.methodName is falsy. * @throws {TypeError} If the callback is not the last parameter */ + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date, maxExecutionTimeInSeconds: number, done: TripleValueCallback): void; + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date, done: TripleValueCallback): void; + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, done: TripleValueCallback): void; + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date, maxExecutionTimeInSeconds: number): Promise; + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime: Date): Promise; + scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams): Promise; scheduleDeviceMethod(jobId: string | number, queryCondition: string, methodParams: DeviceMethodParams, jobStartTime?: Date | TripleValueCallback, maxExecutionTimeInSeconds?: number | TripleValueCallback, done?: TripleValueCallback): Promise | void { const callback = (typeof jobStartTime === 'function') ? jobStartTime as TripleValueCallback : ((typeof maxExecutionTimeInSeconds === 'function') ? maxExecutionTimeInSeconds as TripleValueCallback : done); @@ -253,6 +263,12 @@ export class JobClient { * @throws {ReferenceError} If one or more of the jobId, queryCondition or patch arguments are falsy. * @throws {TypeError} If the callback is not the last parameter */ + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date, maxExecutionTimeInSeconds: number, done: TripleValueCallback): void; + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date, done: TripleValueCallback): void; + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, done: TripleValueCallback): void; + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date, maxExecutionTimeInSeconds?: number | TripleValueCallback): Promise; + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime: Date): Promise; + scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any): Promise; scheduleTwinUpdate(jobId: string | number, queryCondition: string, patch: any, jobStartTime?: Date | TripleValueCallback, maxExecutionTimeInSeconds?: number | TripleValueCallback, done?: TripleValueCallback): Promise | void { const callback = (typeof jobStartTime === 'function') ? jobStartTime as TripleValueCallback : ((typeof maxExecutionTimeInSeconds === 'function') ? maxExecutionTimeInSeconds as TripleValueCallback : done); diff --git a/service/src/query.ts b/service/src/query.ts index f93f2ce72..f778e02e3 100644 --- a/service/src/query.ts +++ b/service/src/query.ts @@ -51,7 +51,11 @@ export class Query { * the results of the query. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ - next(continuationTokenOrCallback: string | IncomingMessageCallback, done?: IncomingMessageCallback): Promise> | void { + next(continuationToken: string, done: IncomingMessageCallback): void; + next(done: IncomingMessageCallback): void; + next(continuationToken: string): Promise>; + next(): Promise>; + next(continuationTokenOrCallback?: string | IncomingMessageCallback, done?: IncomingMessageCallback): Promise> | void { let actualContinuationToken = this.continuationToken; let actualCallback: IncomingMessageCallback; /*Codes_SRS_NODE_SERVICE_QUERY_16_016: [If `continuationToken` is a function and `done` is undefined the `next` method shall assume that `continuationToken` is actually the callback and us it as such (see requirements associated with the `done` parameter)]*/ @@ -91,7 +95,11 @@ export class Query { * the results of the query. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ - nextAsTwin(continuationToken: string | IncomingMessageCallback, done?: IncomingMessageCallback): Promise> | void { + nextAsTwin(continuationToken: string, done: IncomingMessageCallback): void; + nextAsTwin(done: IncomingMessageCallback): void; + nextAsTwin(continuationToken: string): Promise>; + nextAsTwin(): Promise>; + nextAsTwin(continuationToken?: string | IncomingMessageCallback, done?: IncomingMessageCallback): Promise> | void { /*Codes_SRS_NODE_SERVICE_QUERY_16_016: [If `continuationToken` is a function and `_callback` is undefined the `next` method shall assume that `continuationToken` is actually the callback and us it as such (see requirements associated with the `done` parameter)]*/ if (typeof continuationToken === 'function' && !done) { done = continuationToken; @@ -99,7 +107,7 @@ export class Query { } return tripleValueCallbackToPromise((_callback) => { - let ct = continuationToken || this.continuationToken; + let ct = continuationToken as string || this.continuationToken; this.next(ct, (err, result, response) => { if (err) { diff --git a/service/src/registry.ts b/service/src/registry.ts index 45a3ae137..2501173cf 100644 --- a/service/src/registry.ts +++ b/service/src/registry.ts @@ -72,6 +72,8 @@ export class Registry { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + create(deviceInfo: Registry.DeviceDescription, done: HttpResponseCallback): void; + create(deviceInfo: Registry.DeviceDescription): Promise>; create(deviceInfo: Registry.DeviceDescription, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { if (!deviceInfo) { @@ -125,6 +127,8 @@ export class Registry { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + update(deviceInfo: Registry.DeviceDescription, done: HttpResponseCallback): void; + update(deviceInfo: Registry.DeviceDescription): Promise>; update(deviceInfo: Registry.DeviceDescription, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { if (!deviceInfo) { @@ -176,6 +180,8 @@ export class Registry { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + get(deviceId: string, done: HttpResponseCallback): void; + get(deviceId: string): Promise>; get(deviceId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_05_006: [The get method shall throw ReferenceError if the supplied deviceId is falsy.]*/ @@ -215,6 +221,8 @@ export class Registry { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + list(done: HttpResponseCallback): void; + list(): Promise>; list(done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_029: [The `list` method shall construct an HTTP request using information supplied by the caller, as follows: @@ -248,6 +256,8 @@ export class Registry { * debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + delete(deviceId: string, done: HttpResponseCallback): void; + delete(deviceId: string): Promise>; delete(deviceId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_07_007: [The delete method shall throw ReferenceError if the supplied deviceId is falsy.]*/ @@ -286,6 +296,8 @@ export class Registry { * for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + addDevices(devices: Registry.DeviceDescription[], done: HttpResponseCallback): void; + addDevices(devices: Registry.DeviceDescription[]): Promise>; addDevices(devices: Registry.DeviceDescription[], done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._processBulkDevices(devices, 'create', null, null, null, _callback); @@ -310,6 +322,8 @@ export class Registry { * for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + updateDevices(devices: Registry.DeviceDescription[], forceUpdate: boolean, done: HttpResponseCallback): void; + updateDevices(devices: Registry.DeviceDescription[], forceUpdate: boolean): Promise>; updateDevices(devices: Registry.DeviceDescription[], forceUpdate: boolean, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._processBulkDevices(devices, null, forceUpdate, 'Update', 'UpdateIfMatchETag', _callback); @@ -334,6 +348,8 @@ export class Registry { * for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + removeDevices(devices: Registry.DeviceDescription[], forceRemove: boolean, done: HttpResponseCallback): void; + removeDevices(devices: Registry.DeviceDescription[], forceRemove: boolean): Promise>; removeDevices(devices: Registry.DeviceDescription[], forceRemove: boolean, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { this._processBulkDevices(devices, null, forceRemove, 'Delete', 'DeleteIfMatchETag', _callback); @@ -349,6 +365,8 @@ export class Registry { * an error happened, (null otherwise) and the job status that can be used to track progress of the devices import. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + importDevicesFromBlob(inputBlobContainerUri: string, outputBlobContainerUri: string, done: Callback): void; + importDevicesFromBlob(inputBlobContainerUri: string, outputBlobContainerUri: string): Promise; importDevicesFromBlob(inputBlobContainerUri: string, outputBlobContainerUri: string, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /* Codes_SRS_NODE_IOTHUB_REGISTRY_16_001: [A ReferenceError shall be thrown if importBlobContainerUri is falsy] */ @@ -392,6 +410,8 @@ export class Registry { * an error happened, (null otherwise) and the job status that can be used to track progress of the devices export. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + exportDevicesToBlob(outputBlobContainerUri: string, excludeKeys: boolean, done: Callback): void; + exportDevicesToBlob(outputBlobContainerUri: string, excludeKeys: boolean): Promise; exportDevicesToBlob(outputBlobContainerUri: string, excludeKeys: boolean, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /* Codes_SRS_NODE_IOTHUB_REGISTRY_16_004: [A ReferenceError shall be thrown if outputBlobContainerUri is falsy] */ @@ -431,6 +451,8 @@ export class Registry { * (null otherwise) and the list of past jobs as an argument. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + listJobs(done: HttpResponseCallback): void; + listJobs(): Promise>; listJobs(done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_037: [The `listJobs` method shall construct an HTTP request using information supplied by the caller, as follows: @@ -453,7 +475,9 @@ export class Registry { * (null otherwise) and the status of the job whose identifier was passed as an argument. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ - getJob(jobId: string, done: Callback): Promise | void { + getJob(jobId: string, done: Callback): void; + getJob(jobId: string): Promise; + getJob(jobId: string, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_006: [A ReferenceError shall be thrown if jobId is falsy] */ if (!jobId) throw new ReferenceError('jobId cannot be falsy'); @@ -477,6 +501,8 @@ export class Registry { * (null otherwise) and the (cancelled) status of the job whose identifier was passed as an argument. * @returns {Promise | void} Promise if no callback function was passed, void otherwise. */ + cancelJob(jobId: string, done: Callback): void; + cancelJob(jobId: string): Promise; cancelJob(jobId: string, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_012: [A ReferenceError shall be thrown if the jobId is falsy] */ @@ -501,6 +527,8 @@ export class Registry { * the device twin instance. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + getTwin(deviceId: string, done: HttpResponseCallback): void; + getTwin(deviceId: string): Promise>; getTwin(deviceId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_019: [The `getTwin` method shall throw a `ReferenceError` if the `deviceId` parameter is falsy.]*/ @@ -534,6 +562,8 @@ export class Registry { * @throws {ReferenceError} If the deviceId, moduleId, or done argument is falsy. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + getModuleTwin(deviceId: string, moduleId: string, done: HttpResponseCallback): void; + getModuleTwin(deviceId: string, moduleId: string): Promise>; getModuleTwin(deviceId: string, moduleId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_001: [The `getModuleTwin` method shall throw a `ReferenceError` exception if `deviceId`, `moduleId`, or `done` is falsy. ]*/ @@ -570,6 +600,8 @@ export class Registry { * the device twin instance. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + updateTwin(deviceId: string, patch: any, etag: string, done: HttpResponseCallback): void; + updateTwin(deviceId: string, patch: any, etag: string): Promise>; updateTwin(deviceId: string, patch: any, etag: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_16_044: [The `updateTwin` method shall throw a `ReferenceError` if the `deviceId` argument is `undefined`, `null` or an empty string.]*/ @@ -620,6 +652,8 @@ export class Registry { * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. * @throws {ReferenceError} If the deviceId, moduleId, patch, etag, or done argument is falsy. */ + updateModuleTwin(deviceId: string, moduleId: string, patch: any, etag: string, done: HttpResponseCallback): void; + updateModuleTwin(deviceId: string, moduleId: string, patch: any, etag: string): Promise>; updateModuleTwin(deviceId: string, moduleId: string, patch: any, etag: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_004: [The `updateModuleTwin` method shall throw a `ReferenceError` exception if `deviceId`, `moduleId`, `patch`, `etag`,or `done` is falsy. ]*/ @@ -684,6 +718,8 @@ export class Registry { * the device registry statistics. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + getRegistryStatistics(done: HttpResponseCallback): void; + getRegistryStatistics(): Promise>; getRegistryStatistics(done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { const path = '/statistics/devices' + endpoint.versionQueryString(); @@ -708,6 +744,8 @@ export class Registry { * @throws {ReferenceError} The configuration or done parameter is falsy. * @throws {ArgumentError} The configuration object is missing the id property */ + addConfiguration(configuration: Configuration, done: HttpResponseCallback): void; + addConfiguration(configuration: Configuration): Promise>; addConfiguration(configuration: Configuration, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_007: [The `addConfiguration` method shall throw a `ReferenceError` exception if `configuration` or `done` is falsy. ]*/ @@ -749,6 +787,8 @@ export class Registry { * * @throws {ReferenceError} The configurationId or done argument is falsy */ + getConfiguration(configurationId: string, done: HttpResponseCallback): void; + getConfiguration(configurationId: string): Promise>; getConfiguration(configurationId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_011: [The `getConfiguration` method shall throw a `ReferenceError` exception if `configurationId` is falsy. ]*/ @@ -777,6 +817,8 @@ export class Registry { * * @throws {ReferenceError} The done argument is falsy */ + getConfigurations(done: HttpResponseCallback): void; + getConfigurations(): Promise>; getConfigurations(done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_014: [The `getConfigurations` method shall construct an HTTP request using information supplied by the caller, as follows: @@ -860,8 +902,10 @@ export class Registry { * object is missing an id property. */ updateConfiguration(configuration: Configuration, done: HttpResponseCallback): void; - updateConfiguration(configuration: Configuration, forceUpdate: boolean, done?: HttpResponseCallback): void; - updateConfiguration(configuration: Configuration, forceUpdateOrDone: boolean | HttpResponseCallback, done?: HttpResponseCallback): Promise> | void { + updateConfiguration(configuration: Configuration, forceUpdate: boolean, done: HttpResponseCallback): void; + updateConfiguration(configuration: Configuration, forceUpdate: boolean): Promise>; + updateConfiguration(configuration: Configuration): Promise>; + updateConfiguration(configuration: Configuration, forceUpdateOrDone?: boolean | HttpResponseCallback, done?: HttpResponseCallback): Promise> | void { const callback = done || ((typeof forceUpdateOrDone === 'function') ? forceUpdateOrDone : undefined); if (callback) { @@ -886,6 +930,8 @@ export class Registry { * * @throws {ReferenceError} The configurationId or done argument is falsy */ + removeConfiguration(configurationId: string, done: HttpResponseCallback): void; + removeConfiguration(configurationId: string): Promise>; removeConfiguration(configurationId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_022: [The `removeConfiguration` method shall throw a `ReferenceError` exception if `configurationId` or `done` is falsy. ]*/ @@ -920,6 +966,8 @@ export class Registry { * * @throws {ReferenceError} If the deviceId, content, or done argument is falsy. */ + applyConfigurationContentOnDevice(deviceId: string, content: ConfigurationContent, done: HttpResponseCallback): void; + applyConfigurationContentOnDevice(deviceId: string, content: ConfigurationContent): Promise>; applyConfigurationContentOnDevice(deviceId: string, content: ConfigurationContent, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_024: [The `applyConfigurationContentOnDevice` method shall throw a `ReferenceError` exception if `deviceId`, `content`, or `done` is falsy. ]*/ @@ -961,6 +1009,8 @@ export class Registry { * @throws {ReferenceError} If the module or done argument is falsy. * @throws {ArgumentError} If the module object is missing a deviceId or moduleId value. */ + addModule(module: Module, done: HttpResponseCallback): void; + addModule(module: Module): Promise>; addModule(module: Module, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_026: [The `addModule` method shall throw a `ReferenceError` exception if `module` or `done` is falsy. ]*/ @@ -1003,6 +1053,8 @@ export class Registry { * * @throws {ReferenceError} If the deviceId or done argument is falsy. */ + getModulesOnDevice(deviceId: string, done: HttpResponseCallback): void; + getModulesOnDevice(deviceId: string): Promise>; getModulesOnDevice(deviceId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_029: [The `getModulesOnDevice` method shall throw a `ReferenceError` exception if `deviceId` or `done` is falsy. ]*/ @@ -1032,6 +1084,8 @@ export class Registry { * * @throws {ReferenceError} If the deviceId, moduleId, or done argument is falsy. */ + getModule(deviceId: string, moduleId: string, done: HttpResponseCallback): void; + getModule(deviceId: string, moduleId: string): Promise>; getModule(deviceId: string, moduleId: string, done?: HttpResponseCallback): Promise> | void { return httpCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_REGISTRY_18_031: [The `getModule` method shall throw a `ReferenceError` exception if `deviceId`, `moduleId`, or `done` is falsy. ]*/ @@ -1120,7 +1174,9 @@ export class Registry { */ updateModule(module: Module, done: TripleValueCallback): void; updateModule(module: Module, forceUpdate: boolean, done: HttpResponseCallback): void; - updateModule(module: Module, forceUpdateOrDone: boolean | HttpResponseCallback, done?: HttpResponseCallback): Promise> | void { + updateModule(module: Module, forceUpdate: boolean): Promise>; + updateModule(module: Module): Promise>; + updateModule(module: Module, forceUpdateOrDone?: boolean | HttpResponseCallback, done?: HttpResponseCallback): Promise> | void { const callback = done || ((typeof forceUpdateOrDone === 'function') ? forceUpdateOrDone : undefined); if (callback) { @@ -1197,7 +1253,9 @@ export class Registry { */ removeModule(module: Module, done: TripleValueCallback): void; removeModule(deviceId: string, moduleId: string, done: TripleValueCallback): void; - removeModule(moduleOrDeviceId: Module | string, doneOrModuleId: HttpResponseCallback | string, done?: HttpResponseCallback): Promise> | void { + removeModule(moduleOrDeviceId: Module | string, moduleId: string): Promise>; + removeModule(moduleOrDeviceId: Module | string): Promise>; + removeModule(moduleOrDeviceId: Module | string, doneOrModuleId?: HttpResponseCallback | string, done?: HttpResponseCallback): Promise> | void { const callback = done || ((typeof doneOrModuleId === 'function') ? doneOrModuleId : undefined); if (callback) { diff --git a/service/src/service_receiver.ts b/service/src/service_receiver.ts index 59fd48e94..e6fc5f335 100644 --- a/service/src/service_receiver.ts +++ b/service/src/service_receiver.ts @@ -27,6 +27,8 @@ export class ServiceReceiver extends EventEmitter implements Client.ServiceRecei }); } + complete(message: Message, done: Callback): void; + complete(message: Message): Promise; complete(message: Message, done?: Callback): Promise | void { return callbackToPromise((_callback) => { /*Codes_SRS_NODE_SERVICE_RECEIVER_16_003: [The `complete` method shall call the `complete` method on the `ReceiverLink` object and pass it the `AmqpMessage` stored within the `transportObj` property of the `Message` object as well as the `done` callback passed as argument.]*/ @@ -34,6 +36,8 @@ export class ServiceReceiver extends EventEmitter implements Client.ServiceRecei }, done); } + abandon(message: Message, done: Callback): void; + abandon(message: Message): Promise; abandon(message: Message, done?: Callback): Promise | void { /*Codes_SRS_NODE_SERVICE_RECEIVER_16_004: [The `abandon` method shall call the `abandon` method on the `ReceiverLink` object and pass it the `AmqpMessage` stored within the `transportObj` property of the `Message` object as well as the `done` callback passed as argument.]*/ return callbackToPromise((_callback) => { @@ -41,6 +45,8 @@ export class ServiceReceiver extends EventEmitter implements Client.ServiceRecei }, done); } + reject(message: Message, done: Callback): void; + reject(message: Message): Promise; reject(message: Message, done?: Callback): Promise | void { /*Codes_SRS_NODE_SERVICE_RECEIVER_16_005: [The `reject` method shall call the `reject` method on the `ReceiverLink` object and pass it the `AmqpMessage` stored within the `transportObj` property of the `Message` object as well as the `done` callback passed as argument.]*/ return callbackToPromise((_callback) => { @@ -48,7 +54,9 @@ export class ServiceReceiver extends EventEmitter implements Client.ServiceRecei }, done); } - detach(callback: ErrorCallback): Promise | void { + detach(callback: ErrorCallback): void; + detach(): Promise; + detach(callback?: ErrorCallback): Promise | void { /*Codes_SRS_NODE_SERVICE_RECEIVER_16_008: [The `detach` method shall call the `detach` method on the `ReceiverLink` object and pass it its `callback` argument.]*/ return errorCallbackToPromise((_callback) => { this._receiver.detach(_callback); diff --git a/service/src/twin.ts b/service/src/twin.ts index 294742c46..c0e9250bf 100644 --- a/service/src/twin.ts +++ b/service/src/twin.ts @@ -125,6 +125,8 @@ export class Twin implements TwinData { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + get(done: IncomingMessageCallback): void; + get(): Promise>; get(done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_TWIN_16_020: [If `this.moduleId` is falsy, the `get` method shall call the `getTwin` method of the `Registry` instance stored in `_registry` property with the following parameters: @@ -171,6 +173,8 @@ export class Twin implements TwinData { * object useful for logging or debugging. * @returns {Promise> | void} Promise if no callback function was passed, void otherwise. */ + update(patch: any, done: IncomingMessageCallback): void; + update(patch: any): Promise>; update(patch: any, done?: IncomingMessageCallback): Promise> | void { return tripleValueCallbackToPromise((_callback) => { /*Codes_SRS_NODE_IOTHUB_TWIN_16_019: [If `this.moduleId` is falsy, The `update` method shall call the `updateTwin` method of the `Registry` instance stored in `_registry` property with the following parameters: