in src/twin.ts [94:120]
constructor(device: DeviceIdentity | string, registryClient: Registry) {
/*Codes_SRS_NODE_IOTHUB_TWIN_16_002: [The `Twin(device, registryClient)` constructor shall throw a `ReferenceError` if `device` is falsy.]*/
if (device === null || device === undefined || device === '') throw new ReferenceError('\'device\' cannot be \'' + device + '\'');
/*Codes_SRS_NODE_IOTHUB_TWIN_16_003: [The `Twin(device, registryClient)` constructor shall throw a `ReferenceError` if `registryClient` is falsy.]*/
if (!registryClient) throw new ReferenceError('\'registryClient\' cannot be \'' + registryClient + '\'');
if (typeof (device) === 'string') {
/*Codes_SRS_NODE_IOTHUB_TWIN_16_001: [The `Twin(device, registryClient)` constructor shall initialize an empty instance of a `Twin` object and set the `deviceId` base property to the `device` argument if it is a `string`.]*/
this.deviceId = device;
} else {
if (!device.deviceId) {
/*Codes_SRS_NODE_IOTHUB_TWIN_16_007: [The `Twin(device, registryClient)` constructor shall throw an `ArgumentError` if `device` is an object and does not have a `deviceId` property.]*/
throw new errors.ArgumentError('\'device\' must have a deviceId property');
} else {
/*Codes_SRS_NODE_IOTHUB_TWIN_16_006: [The `Twin(device, registryClient)` constructor shall initialize an empty instance of a `Twin` object and set the properties of the created object to the properties described in the `device` argument if it's an `object`.]*/
_.merge(this, device);
}
}
/*Codes_SRS_NODE_IOTHUB_TWIN_16_005: [The `Twin(device, registryClient)` constructor shall set the `Twin.etag` to `*`.]*/
this.etag = this.etag || '*';
this.tags = this.tags || {};
this.properties = _.assign({ desired: {} }, this.properties);
this._registry = registryClient;
}