Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const docsEqual = function(actual, expected) {
assert.equal(actual.length, expected.length);
for (let i = 0; i < actual.size; i++) {
assert.equal(actual[i].ref.id, expected[i].ref.id);
assert.deepStrictEqual(actual[i].data(), expected[i].data());
assert.ok(is.string(expected[i].createTime));
assert.ok(is.string(expected[i].updateTime));
}
};
/**
function endAt(before, value) {
let cursor = {
endAt: {
values: [],
},
};
if (before) {
cursor.endAt.before = true;
}
let values = [].slice.call(arguments, 1);
for (value of values) {
if (is.string(value)) {
cursor.endAt.values.push({
stringValue: value,
});
} else {
cursor.endAt.values.push(value);
}
}
return cursor;
}
deleteRecords(records, callback) {
records = arrify(records);
if (is.string(records[0])) {
this.deleteRecordsByType_(records, callback);
return;
}
this.createChange(
{
delete: records,
},
callback);
}
/**
setFunctionName(functionName?: string) {
this.context.reportLocation.functionName = (is.string(functionName)
? functionName
: '')!;
return this;
}
Filter.convertToRegExpString = function(regex) {
if (is.regexp(regex)) {
return regex.toString().replace(/^\/|\/$/g, '');
}
if (is.array(regex)) {
return '(' + regex.join('|') + ')';
}
if (is.string(regex)) {
return regex;
}
if (is.number(regex)) {
return regex.toString();
}
throw new TypeError('Can\'t convert to RegExp String from unknown type.');
};
testPermissions(permissions: string|string[], gaxOpts, callback?) {
if (!is.array(permissions) && !is.string(permissions)) {
throw new Error('Permissions are required.');
}
if (is.fn(gaxOpts)) {
callback = gaxOpts;
gaxOpts = null;
}
const reqOpts = {
resource: this.id,
permissions: arrify(permissions),
};
this.request(
{
client: 'SubscriberClient',
method: 'testIamPermissions',
reqOpts: reqOpts,
gaxOpts: gaxOpts,
} else if (hasReportMode) {
this._determineReportMode();
}
if (this.isReportingEnabled() && !this.getShouldReportErrorsToAPI()) {
this._logger.warn(
[
'The stackdriver error reporting client is configured to report errors',
'if and only if the NODE_ENV environment variable is set to "production".',
'Errors will not be reported. To have errors always reported, regardless of the',
'value of NODE_ENV, set the reportMode configuration option to "always".',
].join(' ')
);
}
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!;
createSnapshot(name, gaxOpts, callback) {
if (!is.string(name)) {
throw new Error('A name is required to create a snapshot.');
}
if (is.fn(gaxOpts)) {
callback = gaxOpts;
gaxOpts = {};
}
const snapshot = this.snapshot(name);
const reqOpts = {
name: snapshot.name,
subscription: this.name,
};
this.request(
{
client: 'SubscriberClient',
method: 'createSnapshot',
reqOpts,
function replaceProjectIdToken(value, projectId) {
if (is.array(value)) {
value = value.map(function(val) {
return replaceProjectIdToken(val, projectId);
});
}
if (is.object(value) && is.fn(value.hasOwnProperty)) {
for (var opt in value) {
if (value.hasOwnProperty(opt)) {
value[opt] = replaceProjectIdToken(value[opt], projectId);
}
}
}
if (is.string(value) && value.indexOf('{{projectId}}') > -1) {
if (!projectId) {
throw util.missingProjectIdError;
}
value = value.replace(/{{projectId}}/g, projectId);
}
return value;
}
function replaceProjectIdToken(value, projectId) {
if (is.array(value)) {
value = value.map(function(val) {
return replaceProjectIdToken(val, projectId);
});
}
if (is.object(value) && is.fn(value.hasOwnProperty)) {
for (var opt in value) {
if (value.hasOwnProperty(opt)) {
value[opt] = replaceProjectIdToken(value[opt], projectId);
}
}
}
if (is.string(value) && value.indexOf('{{projectId}}') > -1) {
if (!projectId || projectId === '{{projectId}}') {
throw util.missingProjectIdError;
}
value = value.replace(/{{projectId}}/g, projectId);
}
return value;
}