Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var encodeHelper = function(val) {
if (is.string(val)) {
return {
stringValue: val,
};
}
if (is.boolean(val)) {
return {
booleanValue: val,
};
}
if (is.integer(val)) {
return {
integerValue: val,
};
}
// Integers are handled above, the remaining numbers are treated as doubles
if (is.number(val)) {
return {
doubleValue: val,
};
}
if (is.date(val)) {
encodeValue_(value: {}) {
let convertedValue;
if (is.null(value)) {
convertedValue = {
nullValue: 0,
};
} else if (is.number(value)) {
convertedValue = {
numberValue: value,
};
} else if (is.string(value)) {
convertedValue = {
stringValue: value,
};
} else if (is.boolean(value)) {
convertedValue = {
boolValue: value,
};
} else if (Buffer.isBuffer(value)) {
convertedValue = {
blobValue: value,
};
} else if (is.object(value)) {
if (this.seenObjects.has(value)) {
// Circular reference.
if (!this.removeCircular) {
throw new Error(
[
'This object contains a circular reference. To automatically',
'remove it, set the `removeCircular` option to true.',
].join(' ')
ObjectToStructConverter.prototype.encodeValue_ = function(value) {
var convertedValue;
if (is.null(value)) {
convertedValue = {
nullValue: 0
};
} else if (is.number(value)) {
convertedValue = {
numberValue: value
};
} else if (is.string(value)) {
convertedValue = {
stringValue: value
};
} else if (is.boolean(value)) {
convertedValue = {
boolValue: value
};
} else if (Buffer.isBuffer(value)) {
convertedValue = {
blobValue: value
};
} else if (is.object(value)) {
if (this.seenObjects.has(value)) {
// Circular reference.
if (!this.removeCircular) {
throw new Error([
'This object contains a circular reference. To automatically',
'remove it, set the `removeCircular` option to true.'
].join(' '));
}
return bot.getWebHookInfo().then(resp => {
assert.ok(is.object(resp));
assert.ok(is.boolean(resp.has_custom_certificate));
assert.ok(is.number(resp.pending_update_count));
});
});
if (is.string(this._givenConfiguration.key)) {
this._key = this._givenConfiguration.key!;
} else if (has(this._givenConfiguration, 'key')) {
throw new Error('config.key must be a string');
}
if (is.string(this._givenConfiguration.keyFilename)) {
this.keyFilename = this._givenConfiguration.keyFilename!;
} else if (has(this._givenConfiguration, 'keyFilename')) {
throw new Error('config.keyFilename must be a string');
}
if (is.object(this._givenConfiguration.credentials)) {
this.credentials = this._givenConfiguration.credentials!;
} else if (has(this._givenConfiguration, 'credentials')) {
throw new Error('config.credentials must be a valid credentials object');
}
if (is.boolean(this._givenConfiguration.reportUnhandledRejections)) {
this._reportUnhandledRejections = this._givenConfiguration.reportUnhandledRejections!;
} else if (has(this._givenConfiguration, 'reportUnhandledRejections')) {
throw new Error('config.reportUnhandledRejections must be a boolean');
}
}
/**
static formatAppProfile_(options) {
const appProfile: any = {};
if (options.routing) {
if (options.routing === 'any') {
appProfile.multiClusterRoutingUseAny = {};
} else if (options.routing instanceof Cluster) {
appProfile.singleClusterRouting = {
clusterId: options.routing.id,
};
if (is.boolean(options.allowTransactionalWrites)) {
appProfile.singleClusterRouting.allowTransactionalWrites =
options.allowTransactionalWrites;
}
} else {
throw new Error(
'An app profile routing policy can only contain "any" or a `Cluster`.'
);
}
}
if (is.string(options.description)) {
appProfile.description = options.description;
}
return appProfile;
}
function encodeValue(value) {
var valueProto = {};
if (is.boolean(value)) {
valueProto.booleanValue = value;
return valueProto;
}
if (is.nil(value)) {
valueProto.nullValue = 0;
return valueProto;
}
if (is.number(value)) {
if (value % 1 === 0) {
value = new entity.Int(value);
} else {
value = new entity.Double(value);
}
}
callback = options;
options = {};
}
if (!options.routing) {
throw new Error('An app profile must contain a routing policy.');
}
const appProfile = AppProfile.formatAppProfile_(options);
const reqOpts: any = {
parent: this.name,
appProfileId: id,
appProfile,
};
if (is.boolean(options.ignoreWarnings)) {
reqOpts.ignoreWarnings = options.ignoreWarnings;
}
this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
method: 'createAppProfile',
reqOpts,
gaxOpts: options.gaxOptions,
},
(...args) => {
if (args[1]) {
args.splice(1, 0, this.appProfile(id));
}
callback(...args);
reqOpts.appProfile.name = this.name;
const fieldsForMask = [
'description',
'singleClusterRouting',
'multiClusterRoutingUseAny',
'allowTransactionalWrites',
];
fieldsForMask.forEach(field => {
if (reqOpts.appProfile[field]) {
reqOpts.updateMask.paths.push(snakeCase(field));
}
});
if (is.boolean(metadata.ignoreWarnings)) {
reqOpts.ignoreWarnings = metadata.ignoreWarnings;
}
this.bigtable.request(
{
client: 'BigtableInstanceAdminClient',
method: 'updateAppProfile',
reqOpts,
gaxOpts: gaxOptions,
},
callback
);
}
}