Class ServiceObject

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.

Inheritance

EventEmitter > ServiceObject

Package

@google-cloud/common

Constructors

(constructor)(config)

constructor(config: ServiceObjectConfig);

Constructs a new instance of the ServiceObject class

Parameter
NameDescription
config ServiceObjectConfig

Properties

baseUrl

baseUrl?: string;

id

id?: string;

interceptors

interceptors: Interceptor[];

metadata

metadata: Metadata;

methods

protected methods: Methods;

parent

parent: ServiceObjectParent;

pollIntervalMs

pollIntervalMs?: number;

projectId

projectId?: string;

Methods

create(options)

create(options?: CreateOptions): Promise<CreateResponse<T>>;

Create the object.

Parameter
NameDescription
options CreateOptions

Configuration object.

Returns
TypeDescription
Promise<CreateResponse<T>>

create(options, callback)

create(options: CreateOptions, callback: CreateCallback<T>): void;
Parameters
NameDescription
options CreateOptions
callback CreateCallback<T>
Returns
TypeDescription
void

create(callback)

create(callback: CreateCallback<T>): void;
Parameter
NameDescription
callback CreateCallback<T>
Returns
TypeDescription
void

delete(options)

delete(options?: DeleteOptions): Promise<[r.Response]>;

Delete the object.

Parameter
NameDescription
options DeleteOptions
Returns
TypeDescription
Promise<[r.Response]>

delete(options, callback)

delete(options: DeleteOptions, callback: DeleteCallback): void;
Parameters
NameDescription
options DeleteOptions
callback DeleteCallback
Returns
TypeDescription
void

delete(callback)

delete(callback: DeleteCallback): void;
Parameter
NameDescription
callback DeleteCallback
Returns
TypeDescription
void

exists(options)

exists(options?: ExistsOptions): Promise<[boolean]>;

Check if the object exists.

Parameter
NameDescription
options ExistsOptions
Returns
TypeDescription
Promise<[boolean]>

exists(options, callback)

exists(options: ExistsOptions, callback: ExistsCallback): void;
Parameters
NameDescription
options ExistsOptions
callback ExistsCallback
Returns
TypeDescription
void

exists(callback)

exists(callback: ExistsCallback): void;
Parameter
NameDescription
callback ExistsCallback
Returns
TypeDescription
void

get(options)

get(options?: GetOrCreateOptions): Promise<GetResponse<T>>;

Get the object if it exists. Optionally have the object created if an options object is provided with autoCreate: true.

Parameter
NameDescription
options GetOrCreateOptions

The configuration object that will be used to create the object if necessary.

Returns
TypeDescription
Promise<GetResponse<T>>

get(callback)

get(callback: InstanceResponseCallback<T>): void;
Parameter
NameDescription
callback InstanceResponseCallback<T>
Returns
TypeDescription
void

get(options, callback)

get(options: GetOrCreateOptions, callback: InstanceResponseCallback<T>): void;
Parameters
NameDescription
options GetOrCreateOptions
callback InstanceResponseCallback<T>
Returns
TypeDescription
void

getMetadata(options)

getMetadata(options?: GetMetadataOptions): Promise<MetadataResponse>;

Get the metadata of this object.

Parameter
NameDescription
options GetMetadataOptions
Returns
TypeDescription
Promise<MetadataResponse>

getMetadata(options, callback)

getMetadata(options: GetMetadataOptions, callback: MetadataCallback): void;
Parameters
NameDescription
options GetMetadataOptions
callback MetadataCallback
Returns
TypeDescription
void

getMetadata(callback)

getMetadata(callback: MetadataCallback): void;
Parameter
NameDescription
callback MetadataCallback
Returns
TypeDescription
void

getRequestInterceptors()

getRequestInterceptors(): Function[];

Return the user's custom request interceptors.

Returns
TypeDescription
Function[]

request(reqOpts)

request(reqOpts: DecorateRequestOptions): Promise<RequestResponse>;

Make an authenticated API request.

Parameter
NameDescription
reqOpts DecorateRequestOptions

Request options that are passed to request.

Returns
TypeDescription
Promise<RequestResponse>

request(reqOpts, callback)

request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
Parameters
NameDescription
reqOpts DecorateRequestOptions
callback BodyResponseCallback
Returns
TypeDescription
void

requestStream(reqOpts)

requestStream(reqOpts: DecorateRequestOptions): r.Request;

Make an authenticated API request.

Parameter
NameDescription
reqOpts DecorateRequestOptions

Request options that are passed to request.

Returns
TypeDescription
r.Request

setMetadata(metadata, options)

setMetadata(metadata: Metadata, options?: SetMetadataOptions): Promise<SetMetadataResponse>;

Set the metadata for this object.

Parameters
NameDescription
metadata Metadata

The metadata to set on this object.

options SetMetadataOptions

Configuration options.

Returns
TypeDescription
Promise<SetMetadataResponse>

setMetadata(metadata, callback)

setMetadata(metadata: Metadata, callback: MetadataCallback): void;
Parameters
NameDescription
metadata Metadata
callback MetadataCallback
Returns
TypeDescription
void

setMetadata(metadata, options, callback)

setMetadata(metadata: Metadata, options: SetMetadataOptions, callback: MetadataCallback): void;
Parameters
NameDescription
metadata Metadata
options SetMetadataOptions
callback MetadataCallback
Returns
TypeDescription
void