// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Storage Batch Operations API Client for Deno * ============================================ * * * * Docs: https://cloud.google.com/storage/docs/batch-operations/overview * Source: https://googleapis.deno.dev/v1/storagebatchoperations:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; export class StorageBatchOperations { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://storagebatchoperations.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Gets information about a location. * * @param name Resource name for the location. */ async projectsLocationsGet(name: string): Promise<Location> { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Location; } /** * Cancels a batch job. * * @param name Required. The `name` of the job to cancel. Format: projects/{project_id}/locations/global/jobs/{job_id}. */ async projectsLocationsJobsCancel(name: string, req: CancelJobRequest): Promise<CancelJobResponse> { const url = new URL(`${this.#baseUrl}v1/${ name }:cancel`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as CancelJobResponse; } /** * Creates a batch job. * * @param parent Required. Value for parent. */ async projectsLocationsJobsCreate(parent: string, req: Job, opts: ProjectsLocationsJobsCreateOptions = {}): Promise<Operation> { const url = new URL(`${this.#baseUrl}v1/${ parent }/jobs`); if (opts.jobId !== undefined) { url.searchParams.append("jobId", String(opts.jobId)); } if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Operation; } /** * Deletes a batch job. * * @param name Required. The `name` of the job to delete. Format: projects/{project_id}/locations/global/jobs/{job_id} . */ async projectsLocationsJobsDelete(name: string, opts: ProjectsLocationsJobsDeleteOptions = {}): Promise<Empty> { const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Gets a batch job. * * @param name Required. `name` of the job to retrieve. Format: projects/{project_id}/locations/global/jobs/{job_id} . */ async projectsLocationsJobsGet(name: string): Promise<Job> { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Job; } /** * Lists Jobs in a given project. * * @param parent Required. Format: projects/{project_id}/locations/global. */ async projectsLocationsJobsList(parent: string, opts: ProjectsLocationsJobsListOptions = {}): Promise<ListJobsResponse> { const url = new URL(`${this.#baseUrl}v1/${ parent }/jobs`); if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.orderBy !== undefined) { url.searchParams.append("orderBy", String(opts.orderBy)); } if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListJobsResponse; } /** * Lists information about the supported locations for this service. * * @param name The resource that owns the locations collection, if applicable. */ async projectsLocationsList(name: string, opts: ProjectsLocationsListOptions = {}): Promise<ListLocationsResponse> { const url = new URL(`${this.#baseUrl}v1/${ name }/locations`); if (opts.extraLocationTypes !== undefined) { url.searchParams.append("extraLocationTypes", String(opts.extraLocationTypes)); } if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListLocationsResponse; } /** * Starts asynchronous cancellation on a long-running operation. The server * makes a best effort to cancel the operation, but success is not guaranteed. * If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or * other methods to check whether the cancellation succeeded or whether the * operation completed despite cancellation. On successful cancellation, the * operation is not deleted; instead, it becomes an operation with an * Operation.error value with a google.rpc.Status.code of `1`, corresponding * to `Code.CANCELLED`. * * @param name The name of the operation resource to be cancelled. */ async projectsLocationsOperationsCancel(name: string, req: CancelOperationRequest): Promise<Empty> { const url = new URL(`${this.#baseUrl}v1/${ name }:cancel`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Empty; } /** * Deletes a long-running operation. This method indicates that the client is * no longer interested in the operation result. It does not cancel the * operation. If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. * * @param name The name of the operation resource to be deleted. */ async projectsLocationsOperationsDelete(name: string): Promise<Empty> { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Gets the latest state of a long-running operation. Clients can use this * method to poll the operation result at intervals as recommended by the API * service. * * @param name The name of the operation resource. */ async projectsLocationsOperationsGet(name: string): Promise<Operation> { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Operation; } /** * Lists operations that match the specified filter in the request. If the * server doesn't support this method, it returns `UNIMPLEMENTED`. * * @param name The name of the operation's parent resource. */ async projectsLocationsOperationsList(name: string, opts: ProjectsLocationsOperationsListOptions = {}): Promise<ListOperationsResponse> { const url = new URL(`${this.#baseUrl}v1/${ name }/operations`); if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListOperationsResponse; } } /** * Describes configuration of a single bucket and its objects to be * transformed. */ export interface Bucket { /** * Required. Bucket name for the objects to be transformed. */ bucket?: string; /** * Specifies objects in a manifest file. */ manifest?: Manifest; /** * Specifies objects matching a prefix set. */ prefixList?: PrefixList; } /** * Describes list of buckets and their objects to be transformed. */ export interface BucketList { /** * Required. List of buckets and their objects to be transformed. Currently, * only one bucket configuration is supported. If multiple buckets are * specified, an error will be returned. */ buckets?: Bucket[]; } /** * Message for Job to Cancel */ export interface CancelJobRequest { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID in case you need to retry your request. Requests with same * `request_id` will be ignored for at least 60 minutes since the first * request. The request ID must be a valid UUID with the exception that zero * UUID is not supported (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Message for response to cancel Job. */ export interface CancelJobResponse { } /** * The request message for Operations.CancelOperation. */ export interface CancelOperationRequest { } /** * Describes details about the progress of the job. */ export interface Counters { /** * Output only. Number of objects failed. */ readonly failedObjectCount?: bigint; /** * Output only. Number of objects completed. */ readonly succeededObjectCount?: bigint; /** * Output only. Number of objects listed. */ readonly totalObjectCount?: bigint; } /** * Describes options to delete an object. */ export interface DeleteObject { /** * Required. Controls deletion behavior when versioning is enabled for the * object's bucket. If true both live and noncurrent objects will be * permanently deleted. Otherwise live objects in versioned buckets will * become noncurrent and objects that were already noncurrent will be skipped. * This setting doesn't have any impact on the Soft Delete feature. All * objects deleted by this service can be be restored for the duration of the * Soft Delete retention duration if enabled. If enabled and the manifest * doesn't specify an object's generation, a GetObjectMetadata call (a Class B * operation) will be made to determine the live object generation. */ permanentObjectDeletionEnabled?: boolean; } /** * A generic empty message that you can re-use to avoid defining duplicated * empty messages in your APIs. A typical example is to use it as the request or * the response type of an API method. For instance: service Foo { rpc * Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } */ export interface Empty { } /** * An entry describing an error that has occurred. */ export interface ErrorLogEntry { /** * Optional. Output only. At most 5 error log entries are recorded for a * given error code for a job. */ readonly errorDetails?: string[]; /** * Required. Output only. Object URL. e.g. gs://my_bucket/object.txt */ readonly objectUri?: string; } /** * A summary of errors by error code, plus a count and sample error log * entries. */ export interface ErrorSummary { /** * Required. The canonical error code. */ errorCode?: | "OK" | "CANCELLED" | "UNKNOWN" | "INVALID_ARGUMENT" | "DEADLINE_EXCEEDED" | "NOT_FOUND" | "ALREADY_EXISTS" | "PERMISSION_DENIED" | "UNAUTHENTICATED" | "RESOURCE_EXHAUSTED" | "FAILED_PRECONDITION" | "ABORTED" | "OUT_OF_RANGE" | "UNIMPLEMENTED" | "INTERNAL" | "UNAVAILABLE" | "DATA_LOSS"; /** * Required. Number of errors encountered per `error_code`. */ errorCount?: bigint; /** * Required. Sample error logs. */ errorLogEntries?: ErrorLogEntry[]; } function serializeErrorSummary(data: any): ErrorSummary { return { ...data, errorCount: data["errorCount"] !== undefined ? String(data["errorCount"]) : undefined, }; } function deserializeErrorSummary(data: any): ErrorSummary { return { ...data, errorCount: data["errorCount"] !== undefined ? BigInt(data["errorCount"]) : undefined, }; } /** * The Storage Batch Operations Job description. */ export interface Job { /** * Specifies a list of buckets and their objects to be transformed. */ bucketList?: BucketList; /** * Output only. The time that the job was completed. */ readonly completeTime?: Date; /** * Output only. Information about the progress of the job. */ readonly counters?: Counters; /** * Output only. The time that the job was created. */ readonly createTime?: Date; /** * Delete objects. */ deleteObject?: DeleteObject; /** * Optional. A description provided by the user for the job. Its max length * is 1024 bytes when Unicode-encoded. */ description?: string; /** * Output only. Summarizes errors encountered with sample error log entries. */ readonly errorSummaries?: ErrorSummary[]; /** * Optional. Logging configuration. */ loggingConfig?: LoggingConfig; /** * Identifier. The resource name of the Job. job_id is unique within the * project, that is either set by the customer or defined by the service. * Format: projects/{project}/locations/global/jobs/{job_id} . For example: * "projects/123456/locations/global/jobs/job01". */ name?: string; /** * Updates object metadata. Allows updating fixed-key and custom metadata and * fixed-key metadata i.e. Cache-Control, Content-Disposition, * Content-Encoding, Content-Language, Content-Type, Custom-Time. */ putMetadata?: PutMetadata; /** * Changes object hold status. */ putObjectHold?: PutObjectHold; /** * Rewrite the object and updates metadata like KMS key. */ rewriteObject?: RewriteObject; /** * Output only. The time that the job was scheduled. */ readonly scheduleTime?: Date; /** * Output only. State of the job. */ readonly state?: | "STATE_UNSPECIFIED" | "RUNNING" | "SUCCEEDED" | "CANCELED" | "FAILED"; } /** * Message for response to listing Jobs */ export interface ListJobsResponse { /** * A list of storage batch jobs. */ jobs?: Job[]; /** * A token identifying a page of results. */ nextPageToken?: string; /** * Locations that could not be reached. */ unreachable?: string[]; } /** * The response message for Locations.ListLocations. */ export interface ListLocationsResponse { /** * A list of locations that matches the specified filter in the request. */ locations?: Location[]; /** * The standard List next-page token. */ nextPageToken?: string; } /** * The response message for Operations.ListOperations. */ export interface ListOperationsResponse { /** * The standard List next-page token. */ nextPageToken?: string; /** * A list of operations that matches the specified filter in the request. */ operations?: Operation[]; } /** * A resource that represents a Google Cloud location. */ export interface Location { /** * The friendly name for this location, typically a nearby city name. For * example, "Tokyo". */ displayName?: string; /** * Cross-service attributes for the location. For example * {"cloud.googleapis.com/region": "us-east1"} */ labels?: { [key: string]: string }; /** * The canonical id for this location. For example: `"us-east1"`. */ locationId?: string; /** * Service-specific metadata. For example the available capacity at the given * location. */ metadata?: { [key: string]: any }; /** * Resource name for the location, which may vary between implementations. * For example: `"projects/example-project/locations/us-east1"` */ name?: string; } /** * Specifies the Cloud Logging behavior. */ export interface LoggingConfig { /** * Required. Specifies the actions to be logged. */ logActions?: | "LOGGABLE_ACTION_UNSPECIFIED" | "TRANSFORM"[]; /** * Required. States in which Action are logged.If empty, no logs are * generated. */ logActionStates?: | "LOGGABLE_ACTION_STATE_UNSPECIFIED" | "SUCCEEDED" | "FAILED"[]; } /** * Describes list of objects to be transformed. */ export interface Manifest { /** * Required. `manifest_location` must contain the manifest source file that * is a CSV file in a Google Cloud Storage bucket. Each row in the file must * include the object details i.e. BucketId and Name. Generation may * optionally be specified. When it is not specified the live object is acted * upon. `manifest_location` should either be 1) An absolute path to the * object in the format of `gs://bucket_name/path/file_name.csv`. 2) An * absolute path with a single wildcard character in the file name, for * example `gs://bucket_name/path/file_name*.csv`. If manifest location is * specified with a wildcard, objects in all manifest files matching the * pattern will be acted upon. */ manifestLocation?: string; } /** * This resource represents a long-running operation that is the result of a * network API call. */ export interface Operation { /** * If the value is `false`, it means the operation is still in progress. If * `true`, the operation is completed, and either `error` or `response` is * available. */ done?: boolean; /** * The error result of the operation in case of failure or cancellation. */ error?: Status; /** * Service-specific metadata associated with the operation. It typically * contains progress information and common metadata such as create time. Some * services might not provide such metadata. Any method that returns a * long-running operation should document the metadata type, if any. */ metadata?: { [key: string]: any }; /** * The server-assigned name, which is only unique within the same service * that originally returns it. If you use the default HTTP mapping, the `name` * should be a resource name ending with `operations/{unique_id}`. */ name?: string; /** * The normal, successful response of the operation. If the original method * returns no data on success, such as `Delete`, the response is * `google.protobuf.Empty`. If the original method is standard * `Get`/`Create`/`Update`, the response should be the resource. For other * methods, the response should have the type `XxxResponse`, where `Xxx` is * the original method name. For example, if the original method name is * `TakeSnapshot()`, the inferred response type is `TakeSnapshotResponse`. */ response?: { [key: string]: any }; } /** * Represents the metadata of the long-running operation. */ export interface OperationMetadata { /** * Output only. API version used to start the operation. */ readonly apiVersion?: string; /** * Output only. The time the operation was created. */ readonly createTime?: Date; /** * Output only. The time the operation finished running. */ readonly endTime?: Date; /** * Output only. The Job associated with the operation. */ readonly job?: Job; /** * Output only. The unique operation resource name. Format: * projects/{project}/locations/global/operations/{operation}. */ readonly operation?: string; /** * Output only. Identifies whether the user has requested cancellation of the * operation. Operations that have been cancelled successfully have * google.longrunning.Operation.error value with a google.rpc.Status.code of * 1, corresponding to `Code.CANCELLED`. */ readonly requestedCancellation?: boolean; } /** * Describes prefixes of objects to be transformed. */ export interface PrefixList { /** * Optional. Include prefixes of the objects to be transformed. * Supports * full object name * Supports prefix of the object name * Wildcards are not * supported * Supports empty string for all objects in a bucket. */ includedObjectPrefixes?: string[]; } /** * Additional options for StorageBatchOperations#projectsLocationsJobsCreate. */ export interface ProjectsLocationsJobsCreateOptions { /** * Required. The optional `job_id` for this Job . If not specified, an id is * generated. `job_id` should be no more than 128 characters and must include * only characters available in DNS names, as defined by RFC-1123. */ jobId?: string; /** * Optional. An optional request ID to identify requests. Specify a unique * request ID in case you need to retry your request. Requests with same * `request_id` will be ignored for at least 60 minutes since the first * request. The request ID must be a valid UUID with the exception that zero * UUID is not supported (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for StorageBatchOperations#projectsLocationsJobsDelete. */ export interface ProjectsLocationsJobsDeleteOptions { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID in case you need to retry your request. Requests with same * `request_id` will be ignored for at least 60 minutes since the first * request. The request ID must be a valid UUID with the exception that zero * UUID is not supported (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for StorageBatchOperations#projectsLocationsJobsList. */ export interface ProjectsLocationsJobsListOptions { /** * Optional. Filters results as defined by https://google.aip.dev/160. */ filter?: string; /** * Optional. Field to sort by. Supported fields are name, create_time. */ orderBy?: string; /** * Optional. The list page size. default page size is 100. */ pageSize?: number; /** * Optional. The list page token. */ pageToken?: string; } /** * Additional options for StorageBatchOperations#projectsLocationsList. */ export interface ProjectsLocationsListOptions { /** * Optional. A list of extra location types that should be used as conditions * for controlling the visibility of the locations. */ extraLocationTypes?: string; /** * A filter to narrow down results to a preferred subset. The filtering * language accepts strings like `"displayName=tokyo"`, and is documented in * more detail in [AIP-160](https://google.aip.dev/160). */ filter?: string; /** * The maximum number of results to return. If not set, the service selects a * default. */ pageSize?: number; /** * A page token received from the `next_page_token` field in the response. * Send that page token to receive the subsequent page. */ pageToken?: string; } /** * Additional options for * StorageBatchOperations#projectsLocationsOperationsList. */ export interface ProjectsLocationsOperationsListOptions { /** * The standard list filter. */ filter?: string; /** * The standard list page size. */ pageSize?: number; /** * The standard list page token. */ pageToken?: string; } /** * Describes options for object metadata update. */ export interface PutMetadata { /** * Optional. Updates objects Cache-Control fixed metadata. Unset values will * be ignored. Set empty values to clear the metadata. Additionally, the value * for Custom-Time cannot decrease. Refer to documentation in * https://cloud.google.com/storage/docs/metadata#caching_data. */ cacheControl?: string; /** * Optional. Updates objects Content-Disposition fixed metadata. Unset values * will be ignored. Set empty values to clear the metadata. Refer * https://cloud.google.com/storage/docs/metadata#content-disposition for * additional documentation. */ contentDisposition?: string; /** * Optional. Updates objects Content-Encoding fixed metadata. Unset values * will be ignored. Set empty values to clear the metadata. Refer to * documentation in * https://cloud.google.com/storage/docs/metadata#content-encoding. */ contentEncoding?: string; /** * Optional. Updates objects Content-Language fixed metadata. Refer to ISO * 639-1 language codes for typical values of this metadata. Max length 100 * characters. Unset values will be ignored. Set empty values to clear the * metadata. Refer to documentation in * https://cloud.google.com/storage/docs/metadata#content-language. */ contentLanguage?: string; /** * Optional. Updates objects Content-Type fixed metadata. Unset values will * be ignored. Set empty values to clear the metadata. Refer to documentation * in https://cloud.google.com/storage/docs/metadata#content-type */ contentType?: string; /** * Optional. Updates objects custom metadata. Adds or sets individual custom * metadata key value pairs on objects. Keys that are set with empty custom * metadata values will have its value cleared. Existing custom metadata not * specified with this flag is not changed. Refer to documentation in * https://cloud.google.com/storage/docs/metadata#custom-metadata */ customMetadata?: { [key: string]: string }; /** * Optional. Updates objects Custom-Time fixed metadata. Unset values will be * ignored. Set empty values to clear the metadata. Refer to documentation in * https://cloud.google.com/storage/docs/metadata#custom-time. */ customTime?: string; } /** * Describes options to update object hold. */ export interface PutObjectHold { /** * Required. Updates object event based holds state. When object event based * hold is set, object cannot be deleted or replaced. Resets object's time in * the bucket for the purposes of the retention period. */ eventBasedHold?: | "HOLD_STATUS_UNSPECIFIED" | "SET" | "UNSET"; /** * Required. Updates object temporary holds state. When object temporary hold * is set, object cannot be deleted or replaced. */ temporaryHold?: | "HOLD_STATUS_UNSPECIFIED" | "SET" | "UNSET"; } /** * Describes options for object rewrite. */ export interface RewriteObject { /** * Required. Resource name of the Cloud KMS key that will be used to encrypt * the object. The Cloud KMS key must be located in same location as the * object. Refer to * https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys#add-object-key * for additional documentation. Format: * projects/{project}/locations/{location}/keyRings/{keyring}/cryptoKeys/{key} * For example: * "projects/123456/locations/us-central1/keyRings/my-keyring/cryptoKeys/my-key". * The object will be rewritten and set with the specified KMS key. */ kmsKey?: string; } /** * The `Status` type defines a logical error model that is suitable for * different programming environments, including REST APIs and RPC APIs. It is * used by [gRPC](https://github.com/grpc). Each `Status` message contains three * pieces of data: error code, error message, and error details. You can find * out more about this error model and how to work with it in the [API Design * Guide](https://cloud.google.com/apis/design/errors). */ export interface Status { /** * The status code, which should be an enum value of google.rpc.Code. */ code?: number; /** * A list of messages that carry the error details. There is a common set of * message types for APIs to use. */ details?: { [key: string]: any }[]; /** * A developer-facing error message, which should be in English. Any * user-facing error message should be localized and sent in the * google.rpc.Status.details field, or localized by the client. */ message?: string; }