@google-cloud/common
- Version 6.0.0
- Published
- 134 kB
- 9 dependencies
- Apache-2.0 license
Install
npm i @google-cloud/common
yarn add @google-cloud/common
pnpm add @google-cloud/common
Overview
Common components for Cloud APIs Node.js Client Libraries
Index
Variables
Classes
Interfaces
Type Aliases
Variables
variable util
const util: Util;
Classes
class ApiError
class ApiError extends Error {}
Custom error type for API errors.
Parameter errorBody
Error object.
constructor
constructor(errorMessage: string);
constructor
constructor(errorBody: GoogleErrorBody);
property code
code?: number;
property errors
errors?: GoogleInnerError[];
property response
response?: r.Response;
method createMultiErrorMessage
static createMultiErrorMessage: ( err: GoogleErrorBody, errors?: GoogleInnerError[]) => string;
Pieces together an error message by combining all unique error messages returned from a single GoogleError
Parameter err
The original error.
Parameter errors
Inner errors, if any.
Returns
{string}
class Operation
class Operation<T = any> extends ServiceObject<T> {}
constructor
constructor(config: ServiceObjectConfig);
An Operation object allows you to interact with APIs that take longer to process things.
module:common/operation
Parameter config
Configuration object.
Parameter
{module:common/service|module:common/serviceObject|module:common/grpcService|module:common/grpcServiceObject} config.parent - The parent object.
property completeListeners
completeListeners: number;
property hasActiveListeners
hasActiveListeners: boolean;
method listenForEvents_
protected listenForEvents_: () => void;
Begin listening for events on the operation. This method keeps track of how many "complete" listeners are registered and removed, making sure polling is handled automatically.
As long as there is one active "complete" listener, the connection is open. When there are no more listeners, the polling stops.
method poll_
protected poll_: (callback: MetadataCallback) => void;
Poll for a status update. Returns null for an incomplete status, and metadata for a complete status.
method promise
promise: () => Promise<unknown>;
Wraps the
complete
anderror
events in a Promise.{Promise}
method startPolling_
protected startPolling_: () => Promise<void>;
Poll
getMetadata
to check the operation's status. This runs a loop to ping the API on an interval.Note: This method is automatically called once a "complete" event handler is registered on the operation.
class Service
class Service {}
constructor
constructor(config: ServiceConfig, options?: ServiceOptions);
Service is a base class, meant to be inherited from by a "service," like BigQuery or Storage.
This handles making authenticated requests by exposing a
makeReq_
function.module:common/service
Parameter config
Configuration object.
Parameter
{string} config.baseUrl - The base URL to make API requests to.
Parameter
{string[]} config.scopes - The scopes required for the request.
Parameter options
[Configuration object](#/docs).
property apiEndpoint
readonly apiEndpoint: string;
property authClient
authClient: GoogleAuth<AuthClient>;
property baseUrl
baseUrl: string;
property interceptors
interceptors: Interceptor[];
property makeAuthenticatedRequest
makeAuthenticatedRequest: MakeAuthenticatedRequest;
property projectId
projectId: string;
property providedUserAgent
providedUserAgent?: string;
property timeout
timeout?: number;
method getProjectId
getProjectId: { (): Promise<string>; (callback: (err: Error, projectId?: string) => void): void;};
Get and update the Service's project ID.
Parameter callback
The callback function.
method getProjectIdAsync
protected getProjectIdAsync: () => Promise<string>;
method getRequestInterceptors
getRequestInterceptors: () => Function[];
Return the user's custom request interceptors.
method request
request: ( reqOpts: DecorateRequestOptions, callback: BodyResponseCallback) => void;
Make an authenticated API request.
Parameter reqOpts
Request options that are passed to
request
.Parameter
{string} reqOpts.uri - A URI relative to the baseUrl.
Parameter callback
The callback function passed to
request
.
method requestStream
requestStream: (reqOpts: DecorateRequestOptions) => r.Request;
Make an authenticated API request.
Parameter reqOpts
Request options that are passed to
request
.Parameter
{string} reqOpts.uri - A URI relative to the baseUrl.
class ServiceObject
class ServiceObject<T = any> extends EventEmitter {}
ServiceObject is a base class, meant to be inherited from by a "service object," like a BigQuery dataset or Storage bucket.
Most of the time, these objects share common functionality; they can be created or deleted, and you can get or set their metadata.
By inheriting from this class, a service object will be extended with these shared behaviors. Note that any method can be overridden when the service object requires specific behavior.
constructor
constructor(config: ServiceObjectConfig);
property baseUrl
baseUrl?: string;
property id
id?: string;
property interceptors
interceptors: Interceptor[];
property metadata
metadata: any;
property methods
protected methods: Methods;
property parent
parent: ServiceObjectParent;
property pollIntervalMs
pollIntervalMs?: number;
property projectId
projectId?: string;
method create
create: { (options?: CreateOptions): Promise<CreateResponse<T>>; (options: CreateOptions, callback: CreateCallback<T>): void; (callback: CreateCallback<T>): void;};
Create the object.
Parameter options
Configuration object.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{object} callback.instance - The instance.
Parameter
{object} callback.apiResponse - The full API response.
method delete
delete: { (options?: DeleteOptions): Promise<[r.Response]>; (options: DeleteOptions, callback: DeleteCallback): void; (callback: DeleteCallback): void;};
Delete the object.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{object} callback.apiResponse - The full API response.
method exists
exists: { (options?: ExistsOptions): Promise<[boolean]>; (options: object, callback: ExistsCallback): void; (callback: ExistsCallback): void;};
Check if the object exists.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{boolean} callback.exists - Whether the object exists or not.
method get
get: { (options?: GetOrCreateOptions): Promise<GetResponse<T>>; (callback: InstanceResponseCallback<T>): void; (options: GetOrCreateOptions, callback: InstanceResponseCallback<T>): void;};
Get the object if it exists. Optionally have the object created if an options object is provided with
autoCreate: true
.Parameter options
The configuration object that will be used to create the object if necessary.
Parameter
{boolean} options.autoCreate - Create the object if it doesn't already exist.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{object} callback.instance - The instance.
Parameter
{object} callback.apiResponse - The full API response.
method getMetadata
getMetadata: { (options?: GetMetadataOptions): Promise<MetadataResponse>; (options: object, callback: MetadataCallback): void; (callback: MetadataCallback): void;};
Get the metadata of this object.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{object} callback.metadata - The metadata for this object.
Parameter
{object} callback.apiResponse - The full API response.
method getRequestInterceptors
getRequestInterceptors: () => Function[];
Return the user's custom request interceptors.
method request
request: { (reqOpts: DecorateRequestOptions): Promise<RequestResponse>; (reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;};
Make an authenticated API request.
Parameter reqOpts
Request options that are passed to
request
.Parameter
{string} reqOpts.uri - A URI relative to the baseUrl.
Parameter callback
The callback function passed to
request
.
method requestStream
requestStream: (reqOpts: DecorateRequestOptions) => r.Request;
Make an authenticated API request.
Parameter reqOpts
Request options that are passed to
request
.Parameter
{string} reqOpts.uri - A URI relative to the baseUrl.
method setMetadata
setMetadata: { ( metadata: Metadata, options?: SetMetadataOptions ): Promise<SetMetadataResponse>; (metadata: any, callback: MetadataCallback): void; (metadata: any, options: object, callback: MetadataCallback): void;};
Set the metadata for this object.
Parameter metadata
The metadata to set on this object.
Parameter options
Configuration options.
Parameter callback
The callback function.
Parameter
{?error} callback.err - An error returned while making this request.
Parameter
{object} callback.apiResponse - The full API response.
Interfaces
interface BodyResponseCallback
interface BodyResponseCallback {}
call signature
(err: Error | ApiError | null, body?: ResponseBody, res?: r.Response): void;
interface DecorateRequestOptions
interface DecorateRequestOptions extends r.CoreOptions {}
property autoPaginate
autoPaginate?: boolean;
property autoPaginateVal
autoPaginateVal?: boolean;
property interceptors_
interceptors_?: Interceptor[];
property maxRetries
maxRetries?: number;
property objectMode
objectMode?: boolean;
property projectId
projectId?: string;
property shouldReturnStream
shouldReturnStream?: boolean;
property uri
uri: string;
interface DeleteCallback
interface DeleteCallback {}
call signature
(err: Error | null, apiResponse?: r.Response): void;
interface ExistsCallback
interface ExistsCallback {}
call signature
(err: Error | null, exists?: boolean): void;
interface GetConfig
interface GetConfig {}
property autoCreate
autoCreate?: boolean;
Create the object if it doesn't already exist.
interface InstanceResponseCallback
interface InstanceResponseCallback<T> {}
call signature
(err: ApiError | null, instance?: T | null, apiResponse?: r.Response): void;
interface Interceptor
interface Interceptor {}
method request
request: (opts: r.Options) => DecorateRequestOptions;
interface Methods
interface Methods {}
index signature
[methodName: string]: | { reqOpts?: r.CoreOptions; } | boolean;
interface ResponseCallback
interface ResponseCallback {}
call signature
(err?: Error | null, apiResponse?: r.Response): void;
interface ServiceConfig
interface ServiceConfig {}
property apiEndpoint
apiEndpoint: string;
The API Endpoint to use when connecting to the service. Example: storage.googleapis.com
property authClient
authClient?: AuthClient | GoogleAuth;
Reuse an existing
AuthClient
orGoogleAuth
client instead of creating a new one.
property baseUrl
baseUrl: string;
The base URL to make API requests to.
property packageJson
packageJson: PackageJson;
property projectIdRequired
projectIdRequired?: boolean;
property scopes
scopes: string[];
The scopes required for the request.
interface ServiceObjectConfig
interface ServiceObjectConfig {}
property baseUrl
baseUrl?: string;
The base URL to make API requests to.
property createMethod
createMethod?: Function;
The method which creates this object.
property id
id?: string;
The identifier of the object. For example, the name of a Storage bucket or Pub/Sub topic.
property methods
methods?: Methods;
A map of each method name that should be inherited.
property parent
parent: ServiceObjectParent;
The parent service instance. For example, an instance of Storage if the object is Bucket.
property pollIntervalMs
pollIntervalMs?: number;
For long running operations, how often should the client poll for completion.
property projectId
projectId?: string;
Override of projectId, used to allow access to resources in another project. For example, a BigQuery dataset in another project to which the user has been granted permission.
interface ServiceObjectParent
interface ServiceObjectParent {}
property interceptors
interceptors: Interceptor[];
method getRequestInterceptors
getRequestInterceptors: () => Function[];
method request
request: ( reqOpts: DecorateRequestOptions, callback: BodyResponseCallback) => void;
method requestStream
requestStream: (reqOpts: DecorateRequestOptions) => r.Request;
interface ServiceOptions
interface ServiceOptions extends Omit<GoogleAuthOptions, 'authClient'> {}
property authClient
authClient?: AuthClient | GoogleAuth;
property email
email?: string;
property interceptors_
interceptors_?: Interceptor[];
property timeout
timeout?: number;
property token
token?: string;
property useAuthWithCustomEndpoint
useAuthWithCustomEndpoint?: boolean;
property userAgent
userAgent?: string;
interface StreamRequestOptions
interface StreamRequestOptions extends DecorateRequestOptions {}
property shouldReturnStream
shouldReturnStream: true;
Type Aliases
type AbortableDuplex
type AbortableDuplex = Duplexify & Abortable;
type Metadata
type Metadata = any;
type MetadataCallback
type MetadataCallback = ( err: Error | null, metadata?: Metadata, apiResponse?: r.Response) => void;
type MetadataResponse
type MetadataResponse = [Metadata, r.Response];
type ResponseBody
type ResponseBody = any;
type SetMetadataResponse
type SetMetadataResponse = [Metadata];
Package Files (5)
Dependencies (9)
Dev Dependencies (25)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@google-cloud/common
.
- Markdown[](https://www.jsdocs.io/package/@google-cloud/common)
- HTML<a href="https://www.jsdocs.io/package/@google-cloud/common"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4282 ms. - Missing or incorrect documentation? Open an issue for this package.