mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge pull request #31135 from crwilcox/remove-google-cloud-storage
Remove google-cloud__storage types as of 2.3.0 as it is now Typescript.
This commit is contained in:
@@ -642,6 +642,12 @@
|
||||
"sourceRepoURL": "https://github.com/jdalrymple/node-gitlab",
|
||||
"asOfVersion": "2.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "Google Cloud Storage",
|
||||
"typingsPackageName": "google-cloud__storage",
|
||||
"sourceRepoURL": "https://github.com/googleapis/nodejs-storage",
|
||||
"asOfVersion": "2.3.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "graphene-pk11",
|
||||
"typingsPackageName": "graphene-pk11",
|
||||
|
||||
@@ -1,592 +0,0 @@
|
||||
// import file system i/o api
|
||||
import * as fs from "fs";
|
||||
|
||||
// import Google Cloud Storage
|
||||
import {
|
||||
Acl,
|
||||
Bucket,
|
||||
Channel,
|
||||
File,
|
||||
ApiResponse,
|
||||
BucketConfig,
|
||||
BucketFileOptions,
|
||||
BucketGetOptions,
|
||||
BucketMetadata,
|
||||
BucketPrivacyOptions,
|
||||
BucketQuery,
|
||||
ChannelConfig,
|
||||
DownloadOptions,
|
||||
FileMetadata,
|
||||
FilePrivateOptions,
|
||||
ReadStreamOptions,
|
||||
ResumableUploadOptions,
|
||||
SignedPolicy,
|
||||
SignedPolicyOptions,
|
||||
SignedUrlConfig,
|
||||
WriteStreamOptions,
|
||||
UploadOptions
|
||||
} from "@google-cloud/storage";
|
||||
import Storage = require("@google-cloud/storage");
|
||||
|
||||
/**
|
||||
* Test the storage service.
|
||||
*/
|
||||
export class TestStorage {
|
||||
// constants
|
||||
static BUCKET_CONFIG: BucketConfig = {
|
||||
multiRegional: true
|
||||
};
|
||||
|
||||
// import Storage class
|
||||
static gcs = new Storage();
|
||||
|
||||
constructor() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/** Returns the bucket. */
|
||||
bucket(name: string): Bucket {
|
||||
return TestStorage.gcs.bucket(name);
|
||||
}
|
||||
|
||||
/** Create a new bucket. */
|
||||
createBucket(name: string, config?: BucketConfig): Promise<[Bucket, ApiResponse]> {
|
||||
// overwrite default values with custom config
|
||||
config = Object.assign(TestStorage.BUCKET_CONFIG, config);
|
||||
|
||||
return TestStorage.gcs.createBucket(name, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for buckets.
|
||||
*/
|
||||
getBuckets(query?: BucketQuery): Promise<[Bucket[]]> {
|
||||
return TestStorage.gcs.getBuckets(query);
|
||||
}
|
||||
}
|
||||
|
||||
/** The bucket API wrapper. */
|
||||
export class TestBucket {
|
||||
// the bucket in the cloud
|
||||
bucket: Bucket;
|
||||
|
||||
/** Create a bucket. */
|
||||
create(config?: BucketConfig): Promise<[Bucket, ApiResponse]> {
|
||||
return this.bucket.create(config);
|
||||
}
|
||||
|
||||
/** Create a channel that will be notified when objects in this bucket changes. */
|
||||
createChannel(id: string, config: ChannelConfig): Promise<[Channel, ApiResponse]> {
|
||||
return this.bucket.createChannel(id, config);
|
||||
}
|
||||
|
||||
/** Delete the bucket. */
|
||||
delete(): Promise<[ApiResponse]> {
|
||||
return this.bucket.delete();
|
||||
}
|
||||
|
||||
/** Iterate over the bucket's files, calling file.delete() on each. */
|
||||
deleteFiles(query?: BucketQuery): Promise<void> {
|
||||
return this.bucket.deleteFiles(query);
|
||||
}
|
||||
|
||||
/** Check if the bucket exists. */
|
||||
exists(): Promise<[boolean]> {
|
||||
return this.bucket.exists();
|
||||
}
|
||||
|
||||
/** Create a File object. */
|
||||
file(name: string, options?: BucketFileOptions): File {
|
||||
return this.bucket.file(name);
|
||||
}
|
||||
|
||||
/** Get a bucket if it exists. */
|
||||
get(options?: BucketGetOptions): Promise<[Bucket, ApiResponse]> {
|
||||
return this.bucket.get(options);
|
||||
}
|
||||
|
||||
/** Get File objects for the files currently in the bucket */
|
||||
getFiles(query?: BucketQuery): Promise<[File[]]> {
|
||||
return this.bucket.getFiles(query);
|
||||
}
|
||||
|
||||
/** Get File objects for the files currently in the bucket as a readable object stream. */
|
||||
getFilesStream(query?: BucketQuery): fs.ReadStream {
|
||||
return this.bucket.getFilesStream(query);
|
||||
}
|
||||
|
||||
/** Get the bucket's metadata. */
|
||||
getMetadata(): Promise<[BucketMetadata, ApiResponse]> {
|
||||
return this.bucket.getMetadata();
|
||||
}
|
||||
|
||||
/** Make the bucket listing private. */
|
||||
makePrivate(options?: BucketPrivacyOptions): Promise<[File[]]> {
|
||||
return this.bucket.makePrivate(options);
|
||||
}
|
||||
|
||||
/** Make the bucket publicly readable. */
|
||||
makePublic(options?: BucketPrivacyOptions): Promise<[File[]]> {
|
||||
return this.bucket.makePublic(options);
|
||||
}
|
||||
|
||||
/** Set the bucket's metadata. */
|
||||
setMetadata(metadata?: BucketMetadata): Promise<[ApiResponse]> {
|
||||
return this.bucket.setMetadata(metadata);
|
||||
}
|
||||
|
||||
/** Upload a file. */
|
||||
upload(localPath: string, options?: UploadOptions): Promise<[File]> {
|
||||
return this.bucket.upload(localPath, options);
|
||||
}
|
||||
}
|
||||
|
||||
/** The file API wrapper. */
|
||||
export class TestFile {
|
||||
// the file in the cloud
|
||||
file: File;
|
||||
|
||||
/**
|
||||
* Copy this file to another file.
|
||||
* By default, this will copy the file to the same bucket, but you can choose to copy it to another
|
||||
* Bucket by providing a Bucket or File object or a URL starting with "gs:// ".
|
||||
*/
|
||||
copy(destination: string | Bucket | File): Promise<[File, ApiResponse]> {
|
||||
return this.file.copy(destination);
|
||||
}
|
||||
|
||||
/** Create a unique resumable upload session URI. This is the first step when performing a resumable upload. */
|
||||
createResumableUpload(options?: ResumableUploadOptions): Promise<[string]> {
|
||||
return this.file.createResumableUpload(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a readable stream to read the contents of the remote file.
|
||||
* It can be piped to a writable stream or listened to for 'data' events to read a file's contents.
|
||||
*/
|
||||
createReadStream(options?: ReadStreamOptions): fs.ReadStream {
|
||||
return this.file.createReadStream(options);
|
||||
}
|
||||
|
||||
/** Create a writable stream to overwrite the contents of the file in your bucket. */
|
||||
createWriteStream(options?: WriteStreamOptions): fs.WriteStream {
|
||||
return this.file.createWriteStream(options);
|
||||
}
|
||||
|
||||
/** Delete the file. */
|
||||
delete(): Promise<[ApiResponse]> {
|
||||
return this.file.delete();
|
||||
}
|
||||
|
||||
/** Convenience method to download a file into memory or to a local destination. */
|
||||
download(options?: DownloadOptions): Promise<[Buffer]> {
|
||||
return this.file.download(options);
|
||||
}
|
||||
|
||||
/** Check if the file exists. */
|
||||
exists(): Promise<[boolean]> {
|
||||
return this.file.exists();
|
||||
}
|
||||
|
||||
/** Get a file object and its metadata if it exists. */
|
||||
get(): Promise<[File, ApiResponse]> {
|
||||
return this.file.get();
|
||||
}
|
||||
|
||||
/** Get the file's metadata. */
|
||||
getMetadata(): Promise<[FileMetadata, ApiResponse]> {
|
||||
return this.file.getMetadata();
|
||||
}
|
||||
|
||||
/** Get a signed policy document to allow a user to upload data with a POST request */
|
||||
getSignedPolicy(options?: SignedPolicyOptions): Promise<[SignedPolicy]> {
|
||||
return this.file.getSignedPolicy(options);
|
||||
}
|
||||
|
||||
/** Get a signed URL to allow limited time access to the file */
|
||||
getSignedUrl(config: SignedUrlConfig): Promise<[string]> {
|
||||
return this.file.getSignedUrl(config);
|
||||
}
|
||||
|
||||
/** Make a file private to the project and remove all other permissions. */
|
||||
makePrivate(options?: FilePrivateOptions): Promise<[ApiResponse]> {
|
||||
return this.file.makePrivate(options);
|
||||
}
|
||||
|
||||
/** Set a file to be publicly readable and maintain all previous permissions. */
|
||||
makePublic(): Promise<[ApiResponse]> {
|
||||
return this.file.makePublic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move this file to another location.
|
||||
* By default, this will move the file to the same bucket, but you can choose to move it to
|
||||
* another Bucket by providing a Bucket or File object or a URL beginning with "gs:// ".
|
||||
*/
|
||||
move(destination: string | Bucket | File): Promise<[File, ApiResponse]> {
|
||||
return this.file.move(destination);
|
||||
}
|
||||
|
||||
/** Write arbitrary data to a file. */
|
||||
save(data: string, options?: WriteStreamOptions): Promise<void> {
|
||||
return this.file.save(data);
|
||||
}
|
||||
|
||||
/** The Storage API allows you to use a custom key for server-side encryption. */
|
||||
setEncryptionKey(encryptionKey: string | Buffer): File {
|
||||
return this.file.setEncryptionKey(encryptionKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the given metadata with the current remote file's metadata.
|
||||
* This will set metadata if it was previously unset or update previously set metadata.
|
||||
* To unset previously set metadata, set its value to null.
|
||||
*/
|
||||
setMetadata(metadata: FileMetadata): Promise<[ApiResponse]> {
|
||||
return this.file.setMetadata(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
const testStorage = new TestStorage().bucket("examplebucketname");
|
||||
|
||||
testStorage.iam.getPolicy();
|
||||
|
||||
testStorage.iam.setPolicy({
|
||||
bindings: [
|
||||
{
|
||||
role: "roles/storage.admin",
|
||||
members: ['serviceAccount:myotherproject@appspot.gserviceaccount.com']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
testStorage.iam.testPermissions('storage.buckets.delete');
|
||||
|
||||
testStorage.iam.testPermissions(['storage.buckets.delete', 'storage.buckets.get']);
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-code_samples
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
|
||||
// Creates a new bucket
|
||||
storage
|
||||
.createBucket(bucketName, {
|
||||
location: 'ASIA',
|
||||
storageClass: 'COLDLINE',
|
||||
})
|
||||
.then(() => {
|
||||
console.log(`Bucket ${bucketName} created.`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/listing-buckets#storage-list-buckets-nodejs
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
// Lists all buckets in the current project
|
||||
storage
|
||||
.getBuckets()
|
||||
.then(results => {
|
||||
const buckets = results[0];
|
||||
|
||||
console.log('Buckets:');
|
||||
buckets.forEach(bucket => {
|
||||
console.log(bucket.name);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/moving-buckets#storage-create-bucket-nodejs
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
|
||||
// Creates a new bucket
|
||||
storage
|
||||
.createBucket(bucketName, {
|
||||
location: 'ASIA',
|
||||
storageClass: 'COLDLINE',
|
||||
})
|
||||
.then(() => {
|
||||
console.log(`Bucket ${bucketName} created.`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/deleting-buckets
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
|
||||
// Deletes the bucket
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.delete()
|
||||
.then(() => {
|
||||
console.log(`Bucket ${bucketName} deleted.`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/uploading-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const filename = 'Local file to upload, e.g. ./local/path/to/file.txt';
|
||||
|
||||
// Uploads a local file to the bucket
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.upload(filename, {
|
||||
// Support for HTTP requests made with `Accept-Encoding: gzip`
|
||||
gzip: true,
|
||||
metadata: {
|
||||
// Enable long-lived HTTP caching headers
|
||||
// Use only if the contents of the file will never change
|
||||
// (If the contents will change, use cacheControl: 'no-cache')
|
||||
cacheControl: 'public, max-age=31536000',
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
console.log(`${filename} uploaded to ${bucketName}.`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/listing-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
|
||||
// Lists files in the bucket
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.getFiles()
|
||||
.then(results => {
|
||||
const files = results[0];
|
||||
|
||||
console.log('Files:');
|
||||
files.forEach(file => {
|
||||
console.log(file.name);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/listing-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const prefix = 'Prefix by which to filter, e.g. public/';
|
||||
const delimiter = 'Delimiter to use, e.g. /';
|
||||
|
||||
/**
|
||||
* This can be used to list all blobs in a "folder", e.g. "public/".
|
||||
*
|
||||
* The delimiter argument can be used to restrict the results to only the
|
||||
* "files" in the given "folder". Without the delimiter, the entire tree under
|
||||
* the prefix is returned. For example, given these blobs:
|
||||
*
|
||||
* /a/1.txt
|
||||
* /a/b/2.txt
|
||||
*
|
||||
* If you just specify prefix = '/a', you'll get back:
|
||||
*
|
||||
* /a/1.txt
|
||||
* /a/b/2.txt
|
||||
*
|
||||
* However, if you specify prefix='/a' and delimiter='/', you'll get back:
|
||||
*
|
||||
* /a/1.txt
|
||||
*/
|
||||
const options = {
|
||||
prefix,
|
||||
delimiter
|
||||
};
|
||||
|
||||
// Lists files in the bucket, filtered by a prefix
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.getFiles(options)
|
||||
.then(results => {
|
||||
const files = results[0];
|
||||
|
||||
console.log('Files:');
|
||||
files.forEach(file => {
|
||||
console.log(file.name);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/downloading-objects#storage-download-object-nodejs
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const srcFilename = 'Remote file to download, e.g. file.txt';
|
||||
const destFilename = 'Local destination for file, e.g. ./local/path/to/file.txt';
|
||||
|
||||
const options = {
|
||||
// The path to which the file should be downloaded, e.g. "./file.txt"
|
||||
destination: destFilename,
|
||||
};
|
||||
|
||||
// Downloads the file
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.file(srcFilename)
|
||||
.download(options)
|
||||
.then(() => {
|
||||
console.log(
|
||||
`gs://${bucketName}/${srcFilename} downloaded to ${destFilename}.`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/renaming-copying-moving-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const srcFilename = 'File to move, e.g. file.txt';
|
||||
const destFilename = 'Destination for file, e.g. moved.txt';
|
||||
|
||||
// Moves the file within the bucket
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.file(srcFilename)
|
||||
.move(destFilename)
|
||||
.then(() => {
|
||||
console.log(
|
||||
`gs://${bucketName}/${srcFilename} moved to gs://${bucketName}/${destFilename}.`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/renaming-copying-moving-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const srcBucketName = 'Name of the source bucket, e.g. my-bucket';
|
||||
const srcFilename = 'Name of the source file, e.g. file.txt';
|
||||
const destBucketName = 'Name of the destination bucket, e.g. my-other-bucket';
|
||||
const destFilename = 'Destination name of file, e.g. file.txt';
|
||||
|
||||
// Copies the file to the other bucket
|
||||
storage
|
||||
.bucket(srcBucketName)
|
||||
.file(srcFilename)
|
||||
.copy(storage.bucket(destBucketName).file(destFilename))
|
||||
.then(() => {
|
||||
console.log(
|
||||
`gs://${srcBucketName}/${srcFilename} copied to gs://${destBucketName}/${destFilename}.`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/viewing-editing-metadata
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const filename = 'File to access, e.g. file.txt';
|
||||
|
||||
// Gets the metadata for the file
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.file(filename)
|
||||
.getMetadata()
|
||||
.then(results => {
|
||||
const metadata = results[0];
|
||||
|
||||
console.log(`File: ${metadata.name}`);
|
||||
console.log(`Bucket: ${metadata.bucket}`);
|
||||
console.log(`Storage class: ${metadata.storageClass}`);
|
||||
console.log(`Self link: ${metadata.selfLink}`);
|
||||
console.log(`ID: ${metadata.id}`);
|
||||
console.log(`Size: ${metadata.size}`);
|
||||
console.log(`Updated: ${metadata.updated}`);
|
||||
console.log(`Generation: ${metadata.generation}`);
|
||||
console.log(`Metageneration: ${metadata.metageneration}`);
|
||||
console.log(`Etag: ${metadata.etag}`);
|
||||
console.log(`Owner: ${metadata.owner}`);
|
||||
console.log(`Component count: ${metadata.component_count}`);
|
||||
console.log(`Crc32c: ${metadata.crc32c}`);
|
||||
console.log(`md5Hash: ${metadata.md5Hash}`);
|
||||
console.log(`Cache-control: ${metadata.cacheControl}`);
|
||||
console.log(`Content-type: ${metadata.contentType}`);
|
||||
console.log(`Content-disposition: ${metadata.contentDisposition}`);
|
||||
console.log(`Content-encoding: ${metadata.contentEncoding}`);
|
||||
console.log(`Content-language: ${metadata.contentLanguage}`);
|
||||
console.log(`Metadata: ${metadata.metadata}`);
|
||||
console.log(`Media link: ${metadata.mediaLink}`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Example from https://cloud.google.com/storage/docs/deleting-objects
|
||||
{
|
||||
// Creates a client
|
||||
const storage = new Storage();
|
||||
|
||||
const bucketName = 'Name of a bucket, e.g. my-bucket';
|
||||
const filename = 'File to delete, e.g. file.txt';
|
||||
|
||||
// Deletes the file from the bucket
|
||||
storage
|
||||
.bucket(bucketName)
|
||||
.file(filename)
|
||||
.delete()
|
||||
.then(() => {
|
||||
console.log(`gs://${bucketName}/${filename} deleted.`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('ERROR:', err);
|
||||
});
|
||||
}
|
||||
-469
@@ -1,469 +0,0 @@
|
||||
// Type definitions for @google-cloud/storage 1.7
|
||||
// Project: https://github.com/googleapis/nodejs-storage
|
||||
// Definitions by: Brian Love <https://github.com/blove>
|
||||
// Nathan Brooker Perry <https://github.com/nbperry>
|
||||
// Matt Welke <https://github.com/welkie>
|
||||
// Futa Ogawa <https://github.com/ogawa0071>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { ReadStream, WriteStream } from "fs";
|
||||
import { CoreOptions } from "request";
|
||||
|
||||
type PromiseLibrary<T> = () => PromiseLike<T>;
|
||||
|
||||
declare namespace Storage {
|
||||
/**
|
||||
* A bucket in the cloud.
|
||||
*/
|
||||
class Bucket {
|
||||
constructor(storage: Storage, name: string);
|
||||
acl: Acl;
|
||||
combine(sources: string[] | File[], destination: string | File): Promise<[File, ApiResponse]>;
|
||||
create(config?: BucketConfig): Promise<[Bucket, ApiResponse]>;
|
||||
createChannel(id: string, config: ChannelConfig): Promise<[Channel, ApiResponse]>;
|
||||
delete(): Promise<[ApiResponse]>;
|
||||
deleteFiles(query?: BucketQuery): Promise<void>;
|
||||
exists(): Promise<[boolean]>;
|
||||
file(name: string, options?: BucketFileOptions): File;
|
||||
get(options?: BucketGetOptions): Promise<[Bucket, ApiResponse]>;
|
||||
getFiles(query?: BucketQuery): Promise<[File[]]>;
|
||||
getFilesStream(query?: BucketQuery): ReadStream;
|
||||
getMetadata(): Promise<[BucketMetadata, ApiResponse]>;
|
||||
id: string;
|
||||
iam: Iam;
|
||||
makePrivate(options?: BucketPrivacyOptions): Promise<[File[]]>;
|
||||
makePublic(options?: BucketPrivacyOptions): Promise<[File[]]>;
|
||||
metadata: BucketMetadata;
|
||||
name: string;
|
||||
setMetadata(metadata?: BucketMetadata): Promise<[ApiResponse]>;
|
||||
upload(localPath: string, options?: UploadOptions): Promise<[File]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bucket configuration.
|
||||
*/
|
||||
interface BucketConfig {
|
||||
coldline?: boolean;
|
||||
dra?: boolean;
|
||||
location?: string;
|
||||
multiRegional?: boolean;
|
||||
nearline?: boolean;
|
||||
regional?: boolean;
|
||||
versioning?: {
|
||||
enabled?: boolean
|
||||
};
|
||||
// Note: This is not documented, but it is used in examples (https://cloud.google.com/nodejs/docs/reference/storage/1.7.x/Storage)
|
||||
storageClass?: 'COLDLINE' | 'DURABLE_REDUCED_AVAILABILITY' | 'MULTI_REGIONAL' | 'NEARLINE' | 'REGIONAL';
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for getting a file.
|
||||
*/
|
||||
interface BucketFileOptions {
|
||||
generation?: string | number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for getting a bucket.
|
||||
*/
|
||||
interface BucketGetOptions {
|
||||
autoCreate?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bucket metadata.
|
||||
*/
|
||||
interface BucketMetadata {
|
||||
etag?: string;
|
||||
id?: string;
|
||||
kind?: string;
|
||||
location?: string;
|
||||
metageneration?: string;
|
||||
name?: string;
|
||||
projectNumber?: string;
|
||||
selfLink?: string;
|
||||
storageClass?: string;
|
||||
timeCreated?: string;
|
||||
updated?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for making the bucket private.
|
||||
*/
|
||||
interface BucketPrivacyOptions {
|
||||
includeFiles?: boolean;
|
||||
force?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query a bucket.
|
||||
*/
|
||||
interface BucketQuery {
|
||||
autoPaginate?: boolean;
|
||||
delimiter?: string;
|
||||
directory?: string;
|
||||
prefix?: string;
|
||||
maxApiCalls?: number;
|
||||
maxResults?: number;
|
||||
pageToken?: string;
|
||||
userProject?: string;
|
||||
versions?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for specifying the content length range.
|
||||
*/
|
||||
interface ContentLengthRange {
|
||||
max?: number;
|
||||
min?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A file in the cloud.
|
||||
*/
|
||||
class File {
|
||||
constructor(bucket: Bucket, name: string, options?: BucketFileOptions);
|
||||
acl: Acl;
|
||||
copy(destination: string | Bucket | File): Promise<[File, ApiResponse]>;
|
||||
createReadStream(options?: ReadStreamOptions): ReadStream;
|
||||
createResumableUpload(options?: ResumableUploadOptions): Promise<[string]>;
|
||||
createWriteStream(options?: WriteStreamOptions): WriteStream;
|
||||
delete(): Promise<[ApiResponse]>;
|
||||
download(options?: DownloadOptions): Promise<[Buffer]>;
|
||||
exists(): Promise<[boolean]>;
|
||||
get(): Promise<[File, ApiResponse]>;
|
||||
getMetadata(): Promise<[FileMetadata, ApiResponse]>;
|
||||
getSignedPolicy(options?: SignedPolicyOptions): Promise<[SignedPolicy]>;
|
||||
getSignedUrl(config: SignedUrlConfig): Promise<[string]>;
|
||||
makePrivate(options?: FilePrivateOptions): Promise<[ApiResponse]>;
|
||||
makePublic(): Promise<[ApiResponse]>;
|
||||
move(destination: string | Bucket | File): Promise<[File, ApiResponse]>;
|
||||
name: string;
|
||||
save(data: string | Buffer, options?: WriteStreamOptions): Promise<void>;
|
||||
setEncryptionKey(encryptionKey: string | Buffer): File;
|
||||
setMetadata(metadata: FileMetadata): Promise<[ApiResponse]>;
|
||||
metadata?: FileMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access controls on the object, containing one or more objectAccessControls Resources.
|
||||
*/
|
||||
interface AclFileMetadata {
|
||||
bucket?: string;
|
||||
domain?: string;
|
||||
email?: string;
|
||||
entity?: string;
|
||||
entityId?: string;
|
||||
etag?: string;
|
||||
generation?: number;
|
||||
id?: string;
|
||||
kind?: string;
|
||||
object?: string;
|
||||
projectTeam?: ProjectTeam;
|
||||
role?: string;
|
||||
selfLink?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The project team associated with the entity, if any.
|
||||
*/
|
||||
interface ProjectTeam {
|
||||
projectNumber?: string;
|
||||
team?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata of customer-supplied encryption key, if the object is encrypted by such a key.
|
||||
*/
|
||||
interface CustomerEncryption {
|
||||
encryptionAlgorithm?: string;
|
||||
keySha256?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* User-defined metadata.
|
||||
*/
|
||||
interface CustomFileMetadata {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The owner of the object. This will always be the uploader of the object.
|
||||
*/
|
||||
interface Owner {
|
||||
entity?: string;
|
||||
entityId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* File metadata.
|
||||
*/
|
||||
interface FileMetadata {
|
||||
acl?: AclFileMetadata[];
|
||||
bucket?: string;
|
||||
cacheControl?: string;
|
||||
componentCount?: number;
|
||||
// Note: this property is accessed in one of the examples
|
||||
component_count?: number;
|
||||
contentDisposition?: string;
|
||||
contentEncoding?: string;
|
||||
contentLanguage?: string;
|
||||
contentType?: string;
|
||||
crc32c?: string;
|
||||
customerEncryption?: CustomerEncryption;
|
||||
etag?: string;
|
||||
generation?: number;
|
||||
id?: string;
|
||||
kind?: string;
|
||||
kmsKeyName?: string;
|
||||
md5Hash?: string;
|
||||
mediaLink?: string;
|
||||
metadata?: CustomFileMetadata;
|
||||
metageneration?: number;
|
||||
name?: string;
|
||||
owner?: Owner;
|
||||
selfLink?: string;
|
||||
size?: null | number;
|
||||
storageClass?: string;
|
||||
timeCreated?: string;
|
||||
timeDeleted?: string;
|
||||
timeStorageClassUpdated?: string;
|
||||
updated?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when setting the file as private.
|
||||
*/
|
||||
interface FilePrivateOptions {
|
||||
strict?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A signed policy allowing a user to upload a file with a POST.
|
||||
*/
|
||||
interface SignedPolicy {
|
||||
base64?: string;
|
||||
signature?: string;
|
||||
string?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when obtaining the signed policy.
|
||||
*/
|
||||
interface SignedPolicyOptions {
|
||||
acl?: string;
|
||||
contentLengthRange?: ContentLengthRange;
|
||||
equals?: string[] | [string[]];
|
||||
expires?: number | string;
|
||||
max?: number;
|
||||
min?: number;
|
||||
startsWith?: string[] | [string[]];
|
||||
successRedirect?: string;
|
||||
successStatus?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when obtaining a temporary signed URL for a file.
|
||||
*/
|
||||
interface SignedUrlConfig {
|
||||
action: string;
|
||||
cname?: string;
|
||||
contentMd5?: string;
|
||||
contentType?: string;
|
||||
expires: any;
|
||||
extensionHeaders?: { [key: string]: string };
|
||||
promptSaveAs?: string;
|
||||
responseDisposition?: string;
|
||||
responseType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when obtaining a resumable upload URI.
|
||||
*/
|
||||
interface ResumableUploadOptions {
|
||||
metadata?: FileMetadata;
|
||||
origin?: string;
|
||||
predefinedAcl?: string;
|
||||
private?: boolean;
|
||||
public?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access control list for storage buckets and files.
|
||||
*/
|
||||
interface Acl extends AclActions {
|
||||
default: AclEntity;
|
||||
owners: AclEntity;
|
||||
readers: AclEntity;
|
||||
writers: AclEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions that can be performed on all ACL entities, including the root Acl.
|
||||
*/
|
||||
interface AclActions {
|
||||
add(options: AclOptions): Promise<[Acl, ApiResponse]>;
|
||||
delete(options: AclOptions): Promise<[Acl, ApiResponse]>;
|
||||
get(options: AclOptions): Promise<[Acl, ApiResponse]>;
|
||||
update(options: AclOptions): Promise<[Acl, ApiResponse]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object of convenience methods to add or delete reader ACL permissions for a given entity.
|
||||
*/
|
||||
interface AclEntity extends AclActions {
|
||||
addAllAuthenticatedUsers(): Promise<[Acl, ApiResponse]>;
|
||||
addAllUsers(): Promise<[Acl, ApiResponse]>;
|
||||
addDomain(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
addGroup(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
addProject(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
addUser(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
deleteAllAuthenticatedUsers(): Promise<[Acl, ApiResponse]>;
|
||||
deleteAllUsers(): Promise<[Acl, ApiResponse]>;
|
||||
deleteDomain(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
deleteGroup(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
deleteProject(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
deleteUser(entity: string): Promise<[Acl, ApiResponse]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACL options.
|
||||
*/
|
||||
interface AclOptions {
|
||||
entity?: string;
|
||||
role?: string;
|
||||
generation?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The response object.
|
||||
*/
|
||||
interface ApiResponse {
|
||||
etag?: string;
|
||||
id?: string;
|
||||
kind?: string;
|
||||
location?: string;
|
||||
metageneration?: string;
|
||||
name?: string;
|
||||
projectNumber?: string;
|
||||
selfLink?: string;
|
||||
storageClass?: string;
|
||||
timeCreated?: string;
|
||||
updated?: string;
|
||||
}
|
||||
|
||||
interface Credentials {
|
||||
client_email?: string;
|
||||
private_key?: string;
|
||||
}
|
||||
|
||||
interface ConfigurationObject {
|
||||
autoRetry?: boolean;
|
||||
credentials?: Credentials;
|
||||
email?: string;
|
||||
keyFilename?: string;
|
||||
maxRetries?: number;
|
||||
projectId?: string;
|
||||
promise?: PromiseLibrary<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options when downloading a file.
|
||||
*/
|
||||
interface DownloadOptions extends ReadStreamOptions {
|
||||
destination?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when reading a file stream.
|
||||
*/
|
||||
interface ReadStreamOptions {
|
||||
end?: number;
|
||||
start?: number;
|
||||
validation?: string | boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when uploading file to bucket.
|
||||
*/
|
||||
interface UploadOptions extends WriteStreamOptions {
|
||||
destination?: string | File;
|
||||
encryptionKey?: string;
|
||||
kmsKeyName?: string;
|
||||
requestOptions?: CoreOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when writing to a file stream.
|
||||
*/
|
||||
interface WriteStreamOptions {
|
||||
contentType?: string;
|
||||
gzip?: string | boolean;
|
||||
metadata?: FileMetadata;
|
||||
offset?: string;
|
||||
predefinedAcl?: string;
|
||||
private?: boolean;
|
||||
public?: boolean;
|
||||
resumable?: boolean;
|
||||
uri?: string;
|
||||
userProject?: string;
|
||||
validation?: string | boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class allows you interact with Google Cloud Storage.
|
||||
*/
|
||||
class Channel {
|
||||
constructor(storage: Storage, id: string, resourceId: string);
|
||||
stop(): Promise<[ApiResponse]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel configuration.
|
||||
*/
|
||||
interface ChannelConfig {
|
||||
address: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class allows you to get Identity Access Management information.
|
||||
*/
|
||||
class Iam {
|
||||
getPolicy(): Promise<IamPolicy>;
|
||||
setPolicy(policy: IamPolicy): Promise<[IamPolicy, ApiResponse]>;
|
||||
testPermissions(permission: string | string[]): Promise<[{[key: string]: boolean}, ApiResponse]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM policy
|
||||
*/
|
||||
interface IamPolicy {
|
||||
bindings: IamBinding[];
|
||||
}
|
||||
|
||||
interface IamBinding {
|
||||
role: string;
|
||||
members: string[];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Storage class allows you interact with Google Cloud Storage.
|
||||
*/
|
||||
declare class Storage {
|
||||
constructor(config?: Storage.ConfigurationObject);
|
||||
acl: Storage.Acl;
|
||||
bucket(name: string | Storage.Bucket): Storage.Bucket;
|
||||
channel(id: string, resourceId: string): Storage.Channel;
|
||||
createBucket(name: string, metadata?: Storage.BucketConfig): Promise<[Storage.Bucket, Storage.ApiResponse]>;
|
||||
getBuckets(query?: Storage.BucketQuery): Promise<[Storage.Bucket[]]>;
|
||||
getBucketsStream(query?: Storage.BucketQuery): Promise<[ReadStream]>;
|
||||
Channel: (storage: Storage, id: string, resourceId: string) => Storage.Channel;
|
||||
File: (bucket: Storage.Bucket, name: string, opts: Storage.BucketFileOptions) => Storage.File;
|
||||
Bucket: (storage: Storage, name: string) => Storage.Bucket;
|
||||
}
|
||||
|
||||
export = Storage;
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"@google-cloud/storage": [
|
||||
"google-cloud__storage"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"google-cloud__storage-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
// TODOs
|
||||
"no-duplicate-imports": false,
|
||||
"prefer-object-spread": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user