@google-cloud/spanner
Version:
Cloud Spanner Client Library for Node.js
95 lines • 3.97 kB
JavaScript
/**
* Copyright 2024 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDatabaseNotFoundError = isDatabaseNotFoundError;
exports.isInstanceNotFoundError = isInstanceNotFoundError;
exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
exports.toArray = toArray;
const google_gax_1 = require("google-gax");
/**
* Checks whether the given error is a 'Database not found' error.
* @param {Error} error The error to check.
* @return {boolean} True if the error is a 'Database not found' error, and otherwise false.
*/
function isDatabaseNotFoundError(error) {
return (error !== undefined &&
error.code === google_gax_1.grpc.status.NOT_FOUND &&
error.message.includes('Database not found'));
}
/**
* Checks whether the given error is an 'Instance not found' error.
* @param {Error} error The error to check.
* @return {boolean} True if the error is an 'Instance not found' error, and otherwise false.
*/
function isInstanceNotFoundError(error) {
return (error !== undefined &&
error.code === google_gax_1.grpc.status.NOT_FOUND &&
error.message.includes('Instance not found'));
}
/**
* Checks whether the given error is a 'Could not load the default credentials' error.
* @param {Error} error The error to check.
* @return {boolean} True if the error is a 'Could not load the default credentials' error, and otherwise false.
*/
function isDefaultCredentialsNotSetError(error) {
return (error !== undefined &&
error.message.includes('Could not load the default credentials'));
}
/**
* Checks whether the given error is an 'Unable to detect a Project Id in the current environment' error.
* @param {Error} error The error to check.
* @return {boolean} True if the error is an 'Unable to detect a Project Id in the current environment' error, and otherwise false.
*/
function isProjectIdNotSetInEnvironmentError(error) {
return (error !== undefined &&
error.message.includes('Unable to detect a Project Id in the current environment'));
}
/**
* Checks whether the given error is a 'Create session permission' error.
* @param {Error} error The error to check.
* @return {boolean} True if the error is a 'Create session permission' error, and otherwise false.
*/
function isCreateSessionPermissionError(error) {
return (error !== undefined &&
error.code === google_gax_1.grpc.status.PERMISSION_DENIED &&
error.message.includes('spanner.sessions.create'));
}
/**
* Converts any value into an array. Acts as a replacement for `arrify`.
* If the value is null or undefined, returns an empty array.
* If the value is already an array, returns is unchanges.
* Otherwise, wraps the value in a new array.
* @param value The value to convert into an array.
* @returns An array containing the value, or an empty array.
*/
function toArray(value) {
if (value === null || value === undefined) {
return [];
}
if (Array.isArray(value)) {
return value;
}
if (typeof value === 'string') {
return [value];
}
if (typeof value[Symbol.iterator] === 'function') {
return [...value];
}
return [value];
}
//# sourceMappingURL=helper.js.map
;