From 46d809eaa419f0bb20e4b41a7cacf9242a5c76d2 Mon Sep 17 00:00:00 2001 From: ptrdu Date: Wed, 21 Nov 2018 17:55:49 +0800 Subject: [PATCH] FIX: export OSS class --- types/ali-oss/Cluster.d.ts | 63 -- types/ali-oss/ImageClient.d.ts | 71 --- types/ali-oss/ali-oss-tests.ts | 46 +- types/ali-oss/index.d.ts | 1039 ++++++++++++++++++-------------- types/ali-oss/tslint.json | 5 +- 5 files changed, 599 insertions(+), 625 deletions(-) delete mode 100644 types/ali-oss/Cluster.d.ts delete mode 100644 types/ali-oss/ImageClient.d.ts diff --git a/types/ali-oss/Cluster.d.ts b/types/ali-oss/Cluster.d.ts deleted file mode 100644 index 60886fca36..0000000000 --- a/types/ali-oss/Cluster.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { - ACLType, - CopyAndPutMetaResult, - CopyObjectOptions, - DeleteMultiOptions, - DeleteMultiResult, - GetObjectOptions, - GetObjectResult, - GetStreamOptions, - GetStreamResult, - HeadObjectOptions, - HeadObjectResult, - ListObjectResult, - ListObjectsQuery, - NormalSuccessResponse, - PutObjectOptions, - PutObjectResult, - PutStreamOptions, - RequestOptions, - SignatureUrlOptions, - UserMeta -} from "./index"; - -export interface ClusterType { - host: string; - accessKeyId: string; - accessKeySecret: string; -} - -export interface ClusterOptions { - clusters: ClusterType[]; - schedule?: string; -} - -export class Cluster { - constructor(options: ClusterOptions) - - list(query: ListObjectsQuery | null, options: RequestOptions): Promise; - - put(name: string, file: any, options?: PutObjectOptions): Promise; - - putStream(name: string, stream: any, options?: PutStreamOptions): Promise<{ name: string, res: NormalSuccessResponse }>; - - head(name: string, options?: HeadObjectOptions): Promise; - - get(name: string, file?: any, options?: GetObjectOptions): Promise; - - getStream(name?: string, options?: GetStreamOptions): Promise; - - delete(name: string, options?: RequestOptions): Promise; - - copy(name: string, sourceName: string, options?: CopyObjectOptions): Promise; - - putMeta(name: string, meta: UserMeta, options: RequestOptions): Promise; - - deleteMulti(names: string[], options?: DeleteMultiOptions): Promise; - - signatureUrl(name: string, options?: SignatureUrlOptions): string; - - putACL(name: string, acl: ACLType, options?: RequestOptions): Promise; - - restore(name: string, options?: RequestOptions): Promise; -} diff --git a/types/ali-oss/ImageClient.d.ts b/types/ali-oss/ImageClient.d.ts deleted file mode 100644 index 850213083c..0000000000 --- a/types/ali-oss/ImageClient.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { NormalSuccessResponse, RequestOptions } from "./index"; - -export interface ImageClientOptions { - imageHost: string; // your image service domain that binding to a OSS bucket - accessKeyId: string; // access key you create on aliyun console website - accessKeySecret: string; // access secret you create - bucket: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first. - region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou - internal?: boolean; // access OSS with aliyun internal network or not, default is false If your servers are running on aliyun too, you can set true to save lot of money. - timeout?: string | number; // instance level timeout for all operations, default is 60s -} - -export interface ImageGetOptions { - timeout?: number; - headers?: object; -} - -export interface StyleData { - Name: string; // style name - Content: string; // style content - CreateTime: string; // style create time - LastModifyTime: string; // style last modify time -} -export class ImageClient { - constructor(options: ImageClientOptions) - - /** - * Get an image from the image channel. - */ - get(name: string, file?: any, options?: ImageGetOptions): Promise<{ content: any, res: NormalSuccessResponse }>; - - /** - * Get an image read stream. - */ - getStream(name: string, options?: ImageGetOptions): Promise<{ stream: any, res: NormalSuccessResponse }>; - - /** - * Get a image exif info by image object name from the image channel. - */ - getExif(name: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; - - /** - * Get a image info and exif info by image object name from the image channel. - */ - getInfo(name: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; - - /** - * todo - */ - putStyle(name: string, style: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; - - /** - * Get a style by name from the image channel. - */ - getStyle(name: string, options?: RequestOptions): Promise<{ data: StyleData, res: NormalSuccessResponse}>; - - /** - * Get all styles from the image channel. - */ - listStyle(options?: RequestOptions): Promise; - - /** - * todo - */ - deleteStyle(styleName: string, options?: RequestOptions): Promise; - - /** - * Create a signature url for directly download. - */ - signatureUrl(name: string, options?: { expires?: string, timeout?: string }): string; -} diff --git a/types/ali-oss/ali-oss-tests.ts b/types/ali-oss/ali-oss-tests.ts index 96f817cca8..b3641eeeb0 100644 --- a/types/ali-oss/ali-oss-tests.ts +++ b/types/ali-oss/ali-oss-tests.ts @@ -1,34 +1,26 @@ -import OSS from "ali-oss"; +import * as OSS from 'ali-oss'; -const client = new OSS({ +const ossOptions: OSS.Options = { accessKeyId: 'your access key', accessKeySecret: 'your access secret', bucket: 'your bucket name', region: 'oss-cn-hangzhou' -}); +}; -const ImageClient = OSS.ImageClient({ - imageHost: 'host', - accessKeySecret: "secret", - accessKeyId: 'id', - bucket: "", - internal: false, - region: "", - timeout: 2000 -}); +const client = new OSS(ossOptions); + +const clusterOptions: OSS.ClusterOptions = { + clusters: [], +}; + +const clusterClient = new OSS.Cluster(clusterOptions); + +const imageOptions: OSS.ImageClientOptions = { + imageHost: 'xxxx', + accessKeyId: 'xxxx', + accessKeySecret: 'xxxx', + bucket: 'xxxx' +}; + +const imageClient = new OSS.ImageClient(imageOptions); -const cluster = OSS.Cluster({ - clusters: [ - { - accessKeyId: 'id', - accessKeySecret: 'secret', - host: "" - }, - { - accessKeyId: 'id', - accessKeySecret: 'secret', - host: "" - }, - ], - schedule: 'masterSlave', -}); diff --git a/types/ali-oss/index.d.ts b/types/ali-oss/index.d.ts index c3fa0dd10b..13f7f56ff9 100644 --- a/types/ali-oss/index.d.ts +++ b/types/ali-oss/index.d.ts @@ -4,442 +4,555 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as ImageClientDefinition from './ImageClient'; -import * as ClusterDefinition from "./Cluster"; +export = OSS; -export * from './ImageClient'; -export * from './Cluster'; +// basic OSS +declare namespace OSS { + interface Options { + accessKeyId: string; // access secret you create + accessKeySecret: string; // access secret you create + stsToken?: string; // used by temporary authorization + bucket?: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first. + endpoint?: string; // oss region domain. It takes priority over region. + region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou. + internal?: boolean; // access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money. + secure?: boolean; // instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol. + timeout?: string | number; // instance level timeout for all operations, default is 60s + } -export interface Options { - accessKeyId: string; // access secret you create - accessKeySecret: string; // access secret you create - stsToken?: string; // used by temporary authorization - bucket?: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first. - endpoint?: string; // oss region domain. It takes priority over region. - region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou. - internal?: boolean; // access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money. - secure?: boolean; // instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol. - timeout?: string | number; // instance level timeout for all operations, default is 60s -} + interface Bucket { + name: string; + region: string; + creationDate: string; + StorageClass: StorageType; + } -export interface Bucket { - name: string; - region: string; - creationDate: string; - StorageClass: StorageType; -} + type StorageType = "Standard" | "IA" | "Archive"; -export type StorageType = "Standard" | "IA" | "Archive"; + type ACLType = "public-read-write" | "public-read" | "and private"; -export type ACLType = "public-read-write" | "public-read" | "and private"; + type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT"; -export type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT"; + interface RequestOptions { + // the operation timeout + timeout?: number; + } -export interface RequestOptions { - // the operation timeout - timeout?: number; -} + type RuleStatusType = "Enabled" | "Disabled"; -export type RuleStatusType = "Enabled" | "Disabled"; + interface LifecycleRule { + id?: string; // rule id, if not set, OSS will auto create it with random string. + prefix: string; // store prefix + status: RuleStatusType; // rule status, allow values: Enabled or Disabled + days?: number | string; // expire after the days + date: string; // expire date, e.g.: 2022-10-11T00:00:00.000Z date and days only set one. + } -export interface LifecycleRule { - id?: string; // rule id, if not set, OSS will auto create it with random string. - prefix: string; // store prefix - status: RuleStatusType; // rule status, allow values: Enabled or Disabled - days?: number | string; // expire after the days - date: string; // expire date, e.g.: 2022-10-11T00:00:00.000Z date and days only set one. -} + interface CORSRule { + allowedOrigin: string | string[]; // configure for Access-Control-Allow-Origin header + allowedMethod: string | string[]; // configure for Access-Control-Allow-Methods header + allowedHeader?: string | string[]; // configure for Access-Control-Allow-Headers header + exposeHeader?: string | string[]; // configure for Access-Control-Expose-Headers header + maxAgeSeconds?: string | string[]; // configure for Access-Control-Max-Age header + } -export interface CORSRule { - allowedOrigin: string | string[]; // configure for Access-Control-Allow-Origin header - allowedMethod: string | string[]; // configure for Access-Control-Allow-Methods header - allowedHeader?: string | string[]; // configure for Access-Control-Allow-Headers header - exposeHeader?: string | string[]; // configure for Access-Control-Expose-Headers header - maxAgeSeconds?: string | string[]; // configure for Access-Control-Max-Age header -} + interface OwnerType { + id: string; + displayName: string; + } -export interface OwnerType { - id: string; - displayName: string; -} + interface ObjectMeta { + name: string; // object name on oss + lastModified: string; // object last modified GMT date, e.g.: 2015-02-19T08:39:44.000Z + etag: string; // object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE" + type: string; // object type, e.g.: Normal + size: number; // object size, e.g.: 344606 + storageClass: StorageType; + owner: OwnerType; + } -export interface ObjectMeta { - name: string; // object name on oss - lastModified: string; // object last modified GMT date, e.g.: 2015-02-19T08:39:44.000Z - etag: string; // object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE" - type: string; // object type, e.g.: Normal - size: number; // object size, e.g.: 344606 - storageClass: StorageType; - owner: OwnerType; -} + interface NormalSuccessResponse { + // response status + status: number; + // response headers + headers: object; // todo the object in detail + // response size + size: number; + // request total use time (ms) + rt: number; + } -export interface NormalSuccessResponse { - // response status - status: number; - // response headers - headers: object; // todo the object in detail - // response size - size: number; - // request total use time (ms) - rt: number; -} + interface UserMeta { + uid: number; + pid: number; + } -export interface UserMeta { - uid: number; - pid: number; -} + interface ObjectCallback { + url: string; // After a file is uploaded successfully, the OSS sends a callback request to this URL. + host?: string; // The host header value for initiating callback requests. + body: string; // The value of the request body when a callback is initiated, for example, key=$(key)&etag=$(etag)&my_var=$(x:my_var). + contentType?: string; // The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value. + customValue?: object; + headers?: object; // extra headers, detail see RFC 2616 + } -export interface ObjectCallback { - url: string; // After a file is uploaded successfully, the OSS sends a callback request to this URL. - host?: string; // The host header value for initiating callback requests. - body: string; // The value of the request body when a callback is initiated, for example, key=$(key)&etag=$(etag)&my_var=$(x:my_var). - contentType?: string; // The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value. - customValue?: object; - headers?: object; // extra headers, detail see RFC 2616 -} + interface ModifyData { + lastModified: string; // object last modified GMT string + etag: string; // object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE" + } -export interface ModifyData { - lastModified: string; // object last modified GMT string - etag: string; // object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE" -} + interface Checkpoint { + file: any; // The file object selected by the user, if the browser is restarted, it needs the user to manually trigger the settings + name: string; // object key + fileSize: number; + partSize: number; + uploadId: string; + doneParts: Array<{ number: number, etag: string }>; + } -export interface Checkpoint { - file: any; // The file object selected by the user, if the browser is restarted, it needs the user to manually trigger the settings - name: string; // object key - fileSize: number; - partSize: number; - uploadId: string; - doneParts: Array<{ number: number, etag: string }>; -} + interface ObjectPart { + PartNumber: number; + LastModified: any; // {Date} Time when a part is uploaded. + ETag: string; + size: number; + } -export interface ObjectPart { - PartNumber: number; - LastModified: any; // {Date} Time when a part is uploaded. - ETag: string; - size: number; -} + interface Upload { + name: string; + uploadId: string; + initiated: any; + } -export interface Upload { - name: string; - uploadId: string; - initiated: any; -} + interface Channel { + Name: string; + Description: string; + Status: string; + LastModified: string; + PublishUrls: string[]; + PlayUrls: string[]; + } -export interface Channel { - Name: string; - Description: string; - Status: string; - LastModified: string; - PublishUrls: string[]; - PlayUrls: string[]; -} - -export interface ChannelHistory { - StartTime: string; // - EndTime: string; - RemoteAddr: string; // the remote addr -} + interface ChannelHistory { + StartTime: string; // + EndTime: string; + RemoteAddr: string; // the remote addr + } // parameters type -export interface ListBucketsQueryType { - prefix?: string; // search buckets using prefix key - marker?: string; // search start from marker, including marker key - 'max-keys'?: string | number; // max buckets, default is 100, limit to 1000 + interface ListBucketsQueryType { + prefix?: string; // search buckets using prefix key + marker?: string; // search start from marker, including marker key + 'max-keys'?: string | number; // max buckets, default is 100, limit to 1000 + } + + interface PutBucketOptions { + timeout: number; + storageClass: StorageType; + } + + interface PutBucketWebsiteConfig { + index: string; // default page, e.g.: index.html + error?: string; // error page, e.g.: 'error.html' + } + + interface ListObjectsQuery { + prefix?: string; // search object using prefix key + marker?: string; // search start from marker, including marker key + delimiter?: string; // delimiter search scope e.g. / only search current dir, not including subdir + 'max-keys': string | number; // max objects, default is 100, limit to 1000 + } + + interface ListObjectResult { + objects: ObjectMeta[]; + prefixes: string[]; + isTruncated: boolean; + nextMarker: string; + res: NormalSuccessResponse; + } + + interface PutObjectOptions { + timeout?: number; // the operation timeout + mime?: string; // custom mime, will send with Content-Type entity header + meta?: UserMeta; // user meta, will send with x-oss-meta- prefix string e.g.: { uid: 123, pid: 110 } + callback: ObjectCallback; + } + + interface PutObjectResult { + name: string; + data: object; + res: NormalSuccessResponse; + } + + interface PutStreamOptions { + contentLength?: number; // the stream length, chunked encoding will be used if absent + timeout: number; // the operation timeout + mime: string; // custom mime, will send with Content-Type entity header + meta: UserMeta; + callback: ObjectCallback; + } + + interface AppendObjectOptions { + position?: string; // specify the position which is the content length of the latest object + timeout?: number; // the operation timeout + mime?: string; // custom mime, will send with Content-Type entity header + meta?: UserMeta; + headers?: object; + } + + interface AppendObjectResult { + name: string; + url: string; // the url of oss + res: NormalSuccessResponse; + nextAppendPosition: string; // the next position + } + + interface HeadObjectOptions { + timeout?: number; + headers?: object; + } + + interface HeadObjectResult { + status: number; // response status, maybe 200 or 304 + meta: UserMeta; + res: NormalSuccessResponse; + } + + interface GetObjectOptions { + timeout?: number; + process?: string; // image process params, will send with x-oss-process e.g.: {process: 'image/resize,w_200'} + headers?: object; + } + + interface GetObjectResult { + content?: any; // file content buffer if file parameter is null or ignore + res: NormalSuccessResponse; + } + + interface GetStreamOptions { + timeout?: number; + process?: string; // image process params, will send with x-oss-process e.g.: {process: 'image/resize,w_200'} + headers?: object; + } + + interface GetStreamResult { + stream?: any; // readable stream instance if response status is not 200, stream will be null. + res: NormalSuccessResponse; + } + + interface CopyObjectOptions { + timeout?: number; + meta?: UserMeta; + headers?: object; + } + + interface CopyAndPutMetaResult { + data: ModifyData; + res: NormalSuccessResponse; + } + + interface DeleteMultiOptions { + quite?: boolean; // quite mode or verbose mode, default is false + timeout?: number; + } + + interface DeleteMultiResult { + deleted?: string[]; // deleted object names list + res: NormalSuccessResponse; + } + + interface ResponseHeaderType { + 'content-type'?: string; + 'content-disposition'?: string; + 'cache-control'?: string; + } + + interface SignatureUrlOptions { + expires?: number; // after expires seconds, the url will become invalid, default is 1800 + method?: HTTPMethods; // the HTTP method, default is 'GET' + 'Content-Type'?: string; // set the request content type + process?: string; + response?: ResponseHeaderType; // set the response headers for download + callback?: ObjectCallback; + } + + interface GetACLResult { + acl: ACLType; + res: NormalSuccessResponse; + } + + interface InitMultipartUploadOptions { + timeout?: number; + mime?: string; // Mime file type + meta?: UserMeta; + headers?: object; + } + + interface InitMultipartUploadResult { + res: { status: number, headers: object, size: number, rt: number }; + bucket: string; // bucket name + name: string; // object name store on OSS + uploadId: string; // upload id, use for uploadPart, completeMultipart + } + + interface UploadPartResult { + name: string; + etag: string; + res: NormalSuccessResponse; + } + + interface CompleteMultipartUploadOptions { + timeout?: number; + callback?: ObjectCallback; + headers?: object; + } + + interface CompleteMultipartUploadResult { + bucket: string; + name: string; + etag: string; + data: object; + res: NormalSuccessResponse; + } + + interface MultipartUploadOptions { + parallel?: number; // the number of parts to be uploaded in parallel + partSize?: number; // the suggested size for each part + progress?: (...args: any[]) => any; // the progress callback called after each successful upload of one part + checkpoint?: Checkpoint; // the checkpoint to resume upload, if this is provided, it will continue the upload from where interrupted, otherwise a new multipart upload will be created. + meta?: UserMeta; + mime?: string; + callback?: ObjectCallback; + headers?: object; + timeout?: number; + copyheaders?: object; // {Object} only uploadPartCopy api used, detail + } + + interface MultipartUploadResult { + bucket: string; + name: string; + etag: string; + data: object; + res: NormalSuccessResponse; + } + + interface MultipartUploadCopyResult { + bucket: string; + name: string; + etag: string; + res: NormalSuccessResponse; + } + + interface MultipartUploadCopySourceData { + sourceKey: string; // the source object name + sourceBucketName: string; // sourceData. the source bucket name + startOffset: number; // data copy start byte offset, e.g: 0 + endOffset: number; // data copy end byte offset, e.g: 102400 + } + + interface ListPartsQuery { + 'max-parts': number; // The maximum part number in the response of the OSS. default value: 1000. + 'part-number-marker': number; // Starting position of a specific list. A part is listed only when the part number is greater than the value of this parameter. + 'encoding-type': string; // Specify the encoding of the returned content and the encoding type. Optional value: url + } + + interface ListPartsResult { + uploadId: string; + bucket: string; + name: string; + PartNumberMarker: number; + nextPartNumberMarker: number; + maxParts: number; + isTruncated: boolean; + parts: ObjectPart[]; + res: NormalSuccessResponse; + } + + interface ListUploadsQuery { + prefix?: string; + 'max-uploads'?: number; + 'key-marker'?: string; + 'upload-id-marker'?: string; + } + + interface ListUploadsResult { + res: NormalSuccessResponse; + bucket: string; + nextKeyMarker: any; + nextUploadIdMarker: any; + isTruncated: boolean; + uploads: Upload[]; + } + + interface PutChannelConf { + Description?: string; + Status?: string; + Target?: { + Type: string, + FragDuration: number, + FragCount: number, + PlaylistName: string + }; + } + + interface PutChannelResult { + publishUrls: string[]; + playUrls: string[]; + res: NormalSuccessResponse; + } + + interface GetChannelResult { + Status: string; + ConnectedTime?: string; + RemoteAddr?: string; + Video?: object; + Audio?: object; + res: NormalSuccessResponse; + } + + interface ListChannelsQuery { + prefix: string; // the channel id prefix (returns channels with this prefix) + marker: string; // the channel id marker (returns channels after this id) + 'max-keys ': number; // max number of channels to return + } + + interface ListChannelsResult { + channels: Channel[]; + nextMarker: string | null; + isTruncated: boolean; + res: NormalSuccessResponse; + } + + interface ChannelHistoryResult { + records: ChannelHistory; + res: NormalSuccessResponse; + } + + interface GetRtmpUrlOptions { + expires?: number; // the expire time in seconds of the url + params?: object; // the additional parameters for url, e.g.: {playlistName: 'play.m3u8'} + timeout?: number; // the operation timeout + } } -export interface PutBucketOptions { - timeout: number; - storageClass: StorageType; +/// cluster +declare namespace OSS { + interface ClusterType { + host: string; + accessKeyId: string; + accessKeySecret: string; + } + + interface ClusterOptions { + clusters: ClusterType[]; + schedule?: string; + } + + class Cluster { + constructor(options: ClusterOptions) + + list(query: ListObjectsQuery | null, options: RequestOptions): Promise; + + put(name: string, file: any, options?: PutObjectOptions): Promise; + + putStream(name: string, stream: any, options?: PutStreamOptions): Promise<{ name: string, res: NormalSuccessResponse }>; + + head(name: string, options?: HeadObjectOptions): Promise; + + get(name: string, file?: any, options?: GetObjectOptions): Promise; + + getStream(name?: string, options?: GetStreamOptions): Promise; + + delete(name: string, options?: RequestOptions): Promise; + + copy(name: string, sourceName: string, options?: CopyObjectOptions): Promise; + + putMeta(name: string, meta: UserMeta, options: RequestOptions): Promise; + + deleteMulti(names: string[], options?: DeleteMultiOptions): Promise; + + signatureUrl(name: string, options?: SignatureUrlOptions): string; + + putACL(name: string, acl: ACLType, options?: RequestOptions): Promise; + + restore(name: string, options?: RequestOptions): Promise; + } } -export interface PutBucketWebsiteConfig { - index: string; // default page, e.g.: index.html - error?: string; // error page, e.g.: 'error.html' +// image +declare namespace OSS { + interface ImageClientOptions { + imageHost: string; // your image service domain that binding to a OSS bucket + accessKeyId: string; // access key you create on aliyun console website + accessKeySecret: string; // access secret you create + bucket: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first. + region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou + internal?: boolean; // access OSS with aliyun internal network or not, default is false If your servers are running on aliyun too, you can set true to save lot of money. + timeout?: string | number; // instance level timeout for all operations, default is 60s + } + + interface ImageGetOptions { + timeout?: number; + headers?: object; + } + + interface StyleData { + Name: string; // style name + Content: string; // style content + CreateTime: string; // style create time + LastModifyTime: string; // style last modify time + } + + class ImageClient { + constructor(options: ImageClientOptions) + + /** + * Get an image from the image channel. + */ + get(name: string, file?: any, options?: ImageGetOptions): Promise<{ content: any, res: NormalSuccessResponse }>; + + /** + * Get an image read stream. + */ + getStream(name: string, options?: ImageGetOptions): Promise<{ stream: any, res: NormalSuccessResponse }>; + + /** + * Get a image exif info by image object name from the image channel. + */ + getExif(name: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; + + /** + * Get a image info and exif info by image object name from the image channel. + */ + getInfo(name: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; + + /** + * todo + */ + putStyle(name: string, style: string, options?: RequestOptions): Promise<{ data: object, res: NormalSuccessResponse }>; + + /** + * Get a style by name from the image channel. + */ + getStyle(name: string, options?: RequestOptions): Promise<{ data: StyleData, res: NormalSuccessResponse}>; + + /** + * Get all styles from the image channel. + */ + listStyle(options?: RequestOptions): Promise; + + /** + * todo + */ + deleteStyle(styleName: string, options?: RequestOptions): Promise; + + /** + * Create a signature url for directly download. + */ + signatureUrl(name: string, options?: { expires?: string, timeout?: string }): string; + } } -export interface ListObjectsQuery { - prefix?: string; // search object using prefix key - marker?: string; // search start from marker, including marker key - delimiter?: string; // delimiter search scope e.g. / only search current dir, not including subdir - 'max-keys': string | number; // max objects, default is 100, limit to 1000 -} - -export interface ListObjectResult { - objects: ObjectMeta[]; - prefixes: string[]; - isTruncated: boolean; - nextMarker: string; - res: NormalSuccessResponse; -} - -export interface PutObjectOptions { - timeout?: number; // the operation timeout - mime?: string; // custom mime, will send with Content-Type entity header - meta?: UserMeta; // user meta, will send with x-oss-meta- prefix string e.g.: { uid: 123, pid: 110 } - callback: ObjectCallback; -} - -export interface PutObjectResult { - name: string; - data: object; - res: NormalSuccessResponse; -} - -export interface PutStreamOptions { - contentLength?: number; // the stream length, chunked encoding will be used if absent - timeout: number; // the operation timeout - mime: string; // custom mime, will send with Content-Type entity header - meta: UserMeta; - callback: ObjectCallback; -} - -export interface AppendObjectOptions { - position?: string; // specify the position which is the content length of the latest object - timeout?: number; // the operation timeout - mime?: string; // custom mime, will send with Content-Type entity header - meta?: UserMeta; - headers?: object; -} - -export interface AppendObjectResult { - name: string; - url: string; // the url of oss - res: NormalSuccessResponse; - nextAppendPosition: string; // the next position -} - -export interface HeadObjectOptions { - timeout?: number; - headers?: object; -} - -export interface HeadObjectResult { - status: number; // response status, maybe 200 or 304 - meta: UserMeta; - res: NormalSuccessResponse; -} - -export interface GetObjectOptions { - timeout?: number; - process?: string; // image process params, will send with x-oss-process e.g.: {process: 'image/resize,w_200'} - headers?: object; -} - -export interface GetObjectResult { - content?: any; // file content buffer if file parameter is null or ignore - res: NormalSuccessResponse; -} - -export interface GetStreamOptions { - timeout?: number; - process?: string; // image process params, will send with x-oss-process e.g.: {process: 'image/resize,w_200'} - headers?: object; -} - -export interface GetStreamResult { - stream?: any; // readable stream instance if response status is not 200, stream will be null. - res: NormalSuccessResponse; -} - -export interface CopyObjectOptions { - timeout?: number; - meta?: UserMeta; - headers?: object; -} - -export interface CopyAndPutMetaResult { - data: ModifyData; - res: NormalSuccessResponse; -} - -export interface DeleteMultiOptions { - quite?: boolean; // quiet mode or verbose mode, default is false - timeout?: number; -} - -export interface DeleteMultiResult { - deleted?: string[]; // deleted object names list - res: NormalSuccessResponse; -} - -export interface ResponseHeaderType { - 'content-type'?: string; - 'content-disposition'?: string; - 'cache-control'?: string; -} - -export interface SignatureUrlOptions { - expires?: number; // after expires seconds, the url will become invalid, default is 1800 - method?: HTTPMethods; // the HTTP method, default is 'GET' - 'Content-Type'?: string; // set the request content type - process?: string; - response?: ResponseHeaderType; // set the response headers for download - callback?: ObjectCallback; -} - -export interface GetACLResult { - acl: ACLType; - res: NormalSuccessResponse; -} - -export interface InitMultipartUploadOptions { - timeout?: number; - mime?: string; // Mime file type - meta?: UserMeta; - headers?: object; -} - -export interface InitMultipartUploadResult { - res: { status: number, headers: object, size: number, rt: number }; - bucket: string; // bucket name - name: string; // object name store on OSS - uploadId: string; // upload id, use for uploadPart, completeMultipart -} - -export interface UploadPartResult { - name: string; - etag: string; - res: NormalSuccessResponse; -} - -export interface CompleteMultipartUploadOptions { - timeout?: number; - callback?: ObjectCallback; - headers?: object; -} - -export interface CompleteMultipartUploadResult { - bucket: string; - name: string; - etag: string; - data: object; - res: NormalSuccessResponse; -} - -export interface MultipartUploadOptions { - parallel?: number; // the number of parts to be uploaded in parallel - partSize?: number; // the suggested size for each part - progress?: (...args: any[]) => any; // the progress callback called after each successful upload of one part - checkpoint?: Checkpoint; // the checkpoint to resume upload, if this is provided, it will continue the upload from where interrupted, otherwise a new multipart upload will be created. - meta?: UserMeta; - mime?: string; - callback?: ObjectCallback; - headers?: object; - timeout?: number; - copyheaders?: object; // {Object} only uploadPartCopy api used, detail -} - -export interface MultipartUploadResult { - bucket: string; - name: string; - etag: string; - data: object; - res: NormalSuccessResponse; -} - -export interface MultipartUploadCopyResult { - bucket: string; - name: string; - etag: string; - res: NormalSuccessResponse; -} - -export interface MultipartUploadCopySourceData { - sourceKey: string; // the source object name - sourceBucketName: string; // sourceData. the source bucket name - startOffset: number; // data copy start byte offset, e.g: 0 - endOffset: number; // data copy end byte offset, e.g: 102400 -} - -export interface ListPartsQuery { - 'max-parts': number; // The maximum part number in the response of the OSS. default value: 1000. - 'part-number-marker': number; // Starting position of a specific list. A part is listed only when the part number is greater than the value of this parameter. - 'encoding-type': string; // Specify the encoding of the returned content and the encoding type. Optional value: url -} - -export interface ListPartsResult { - uploadId: string; - bucket: string; - name: string; - PartNumberMarker: number; - nextPartNumberMarker: number; - maxParts: number; - isTruncated: boolean; - parts: ObjectPart[]; - res: NormalSuccessResponse; -} - -export interface ListUploadsQuery { - prefix?: string; - 'max-uploads'?: number; - 'key-marker'?: string; - 'upload-id-marker'?: string; -} - -export interface ListUploadsResult { - res: NormalSuccessResponse; - bucket: string; - nextKeyMarker: any; - nextUploadIdMarker: any; - isTruncated: boolean; - uploads: Upload[]; -} - -export interface PutChannelConf { - Description?: string; - Status?: string; - Target?: { - Type: string, - FragDuration: number, - FragCount: number, - PlaylistName: string - }; -} - -export interface PutChannelResult { - publishUrls: string[]; - playUrls: string[]; - res: NormalSuccessResponse; -} - -export interface GetChannelResult { - Status: string; - ConnectedTime?: string; - RemoteAddr?: string; - Video?: object; - Audio?: object; - res: NormalSuccessResponse; -} - -export interface ListChannelsQuery { - prefix: string; // the channel id prefix (returns channels with this prefix) - marker: string; // the channel id marker (returns channels after this id) - 'max-keys ': number; // max number of channels to return -} - -export interface ListChannelsResult { - channels: Channel[]; - nextMarker: string | null; - isTruncated: boolean; - res: NormalSuccessResponse; -} - -export interface ChannelHistoryResult { - records: ChannelHistory; - res: NormalSuccessResponse; -} - -export interface GetRtmpUrlOptions { - expires?: number; // the expire time in seconds of the url - params?: object; // the additional parameters for url, e.g.: {playlistName: 'play.m3u8'} - timeout?: number; // the operation timeout -} - -export default class OSS { - // the image client - static ImageClient: (options: ImageClientDefinition.ImageClientOptions) => ImageClientDefinition.ImageClient; - static Cluster: (options: ClusterDefinition.ClusterOptions) => ClusterDefinition.Cluster; - - constructor(options: Options) +declare class OSS { + constructor(options: OSS.Options) /******************************************* the bucket operations *************************************************/ @@ -447,12 +560,12 @@ export default class OSS { /** * List buckets in this account. */ - listBuckets(query: ListBucketsQueryType | null, options?: RequestOptions): Promise; + listBuckets(query: OSS.ListBucketsQueryType | null, options?: OSS.RequestOptions): Promise; /** * Create a new bucket. */ - putBucket(name: string, options?: PutBucketOptions): Promise<{ bucket: string, res: NormalSuccessResponse }>; + putBucket(name: string, options?: OSS.PutBucketOptions): Promise<{ bucket: string, res: OSS.NormalSuccessResponse }>; /** * Use the bucket. @@ -462,7 +575,7 @@ export default class OSS { /** * Delete an empty bucket. */ - deleteBucket(name: string, options?: RequestOptions): Promise; + deleteBucket(name: string, options?: OSS.RequestOptions): Promise; /** * Get bucket information,include CreationDate、ExtranetEndpoint、IntranetEndpoint、Location、Name、StorageClass、 Owner、AccessControlList @@ -478,114 +591,114 @@ export default class OSS { /** * Update the bucket ACL. */ - putBucketACL(name: string, acl: ACLType, options?: RequestOptions): Promise; + putBucketACL(name: string, acl: OSS.ACLType, options?: OSS.RequestOptions): Promise; /** * Get the bucket ACL. * acl - acl settings string */ - getBucketACL(name: string, options?: RequestOptions): Promise<{ acl: string, res: NormalSuccessResponse }>; + getBucketACL(name: string, options?: OSS.RequestOptions): Promise<{ acl: string, res: OSS.NormalSuccessResponse }>; // logging operations /** * Update the bucket logging settings. Log file will create every one hour and name format: -YYYY-mm-DD-HH-MM-SS-UniqueString. */ - putBucketLogging(name: string, prefix?: string, options?: RequestOptions): Promise; + putBucketLogging(name: string, prefix?: string, options?: OSS.RequestOptions): Promise; /** * Get the bucket logging settings. */ - getBucketLogging(name: string, options?: RequestOptions): Promise<{ enable: boolean, prefix: string | null, res: NormalSuccessResponse }>; + getBucketLogging(name: string, options?: OSS.RequestOptions): Promise<{ enable: boolean, prefix: string | null, res: OSS.NormalSuccessResponse }>; /** * Delete the bucket logging settings. */ - deleteBucketLogging(name: string, options?: RequestOptions): Promise; + deleteBucketLogging(name: string, options?: OSS.RequestOptions): Promise; // Website operations /** * Set the bucket as a static website. */ - putBucketWebsite(name: string, config: PutBucketWebsiteConfig): Promise; + putBucketWebsite(name: string, config: OSS.PutBucketWebsiteConfig): Promise; /** * Get the bucket website config. */ - getBucketWebsite(name: string, options?: RequestOptions): Promise<{ index: string, error: string, res: NormalSuccessResponse }>; + getBucketWebsite(name: string, options?: OSS.RequestOptions): Promise<{ index: string, error: string, res: OSS.NormalSuccessResponse }>; /** * Delete the bucket website config. */ - deleteBucketWebsite(name: string, options?: RequestOptions): Promise; + deleteBucketWebsite(name: string, options?: OSS.RequestOptions): Promise; // referer operations /** * Set the bucket request Referer white list. */ - putBucketReferer(name: string, allowEmpty: boolean, referers: string[], options?: RequestOptions): Promise; + putBucketReferer(name: string, allowEmpty: boolean, referers: string[], options?: OSS.RequestOptions): Promise; /** * Get the bucket request Referer white list. */ - getBucketReferer(name: string, options?: RequestOptions): Promise<{ allowEmpty: boolean, referers: string[], res: NormalSuccessResponse }>; + getBucketReferer(name: string, options?: OSS.RequestOptions): Promise<{ allowEmpty: boolean, referers: string[], res: OSS.NormalSuccessResponse }>; /** * Delete the bucket request Referer white list. */ - deleteBucketReferer(name: string, options?: RequestOptions): Promise; + deleteBucketReferer(name: string, options?: OSS.RequestOptions): Promise; // lifecycle operations /** * Set the bucket object lifecycle. */ - putBucketLifecycle(name: string, rules: LifecycleRule[], options?: RequestOptions): Promise; + putBucketLifecycle(name: string, rules: OSS.LifecycleRule[], options?: OSS.RequestOptions): Promise; /** * Get the bucket object lifecycle. */ - getBucketLifecycle(name: string, options?: RequestOptions): Promise<{ rules: LifecycleRule[], res: NormalSuccessResponse }>; + getBucketLifecycle(name: string, options?: OSS.RequestOptions): Promise<{ rules: OSS.LifecycleRule[], res: OSS.NormalSuccessResponse }>; /** * Delete the bucket object lifecycle. */ - deleteBucketLifecycle(name: string, options?: RequestOptions): Promise; + deleteBucketLifecycle(name: string, options?: OSS.RequestOptions): Promise; // CORS operations /** * Set CORS rules of the bucket object */ - putBucketCORS(name: string, rules: CORSRule[], options?: RequestOptions): Promise; + putBucketCORS(name: string, rules: OSS.CORSRule[], options?: OSS.RequestOptions): Promise; /** * Get CORS rules of the bucket object. */ - getBucketCORS(name: string): Promise<{ rules: CORSRule[], res: NormalSuccessResponse }>; + getBucketCORS(name: string): Promise<{ rules: OSS.CORSRule[], res: OSS.NormalSuccessResponse }>; /** * Delete CORS rules of the bucket object. */ - deleteBucketCORS(name: string): Promise; + deleteBucketCORS(name: string): Promise; /********************************************************** Object operations ********************************************/ /** * List objects in the bucket. */ - list(query: ListObjectsQuery | null, options: RequestOptions): Promise; + list(query: OSS.ListObjectsQuery | null, options: OSS.RequestOptions): Promise; /** * Add an object to the bucket. */ - put(name: string, file: any, options?: PutObjectOptions): Promise; + put(name: string, file: any, options?: OSS.PutObjectOptions): Promise; /** * Add a stream object to the bucket. */ - putStream(name: string, stream: any, options?: PutStreamOptions): Promise<{ name: string, res: NormalSuccessResponse }>; + putStream(name: string, stream: any, options?: OSS.PutStreamOptions): Promise<{ name: string, res: OSS.NormalSuccessResponse }>; /** * Append an object to the bucket, it's almost same as put, but it can add content to existing object rather than override it. */ - append(name: string, file: any, options?: AppendObjectOptions): Promise; + append(name: string, file: any, options?: OSS.AppendObjectOptions): Promise; /** * Get the Object url. If provide baseUrl, will use baseUrl instead the default endpoint. @@ -600,67 +713,67 @@ export default class OSS { /** * Head an object and get the meta info. */ - head(name: string, options?: HeadObjectOptions): Promise; + head(name: string, options?: OSS.HeadObjectOptions): Promise; /** * Get an object from the bucket. */ - get(name: string, file?: any, options?: GetObjectOptions): Promise; + get(name: string, file?: any, options?: OSS.GetObjectOptions): Promise; /** * Get an object read stream. */ - getStream(name?: string, options?: GetStreamOptions): Promise; + getStream(name?: string, options?: OSS.GetStreamOptions): Promise; /** * Delete an object from the bucket. */ - delete(name: string, options?: RequestOptions): Promise; + delete(name: string, options?: OSS.RequestOptions): Promise; /** * Copy an object from sourceName to name. */ - copy(name: string, sourceName: string, options?: CopyObjectOptions): Promise; + copy(name: string, sourceName: string, options?: OSS.CopyObjectOptions): Promise; /** * Set an exists object meta. */ - putMeta(name: string, meta: UserMeta, options: RequestOptions): Promise; + putMeta(name: string, meta: OSS.UserMeta, options: OSS.RequestOptions): Promise; /** * Delete multi objects in one request. */ - deleteMulti(names: string[], options?: DeleteMultiOptions): Promise; + deleteMulti(names: string[], options?: OSS.DeleteMultiOptions): Promise; /** * Create a signature url for download or upload object. When you put object with signatureUrl ,you need to pass Content-Type.Please look at the example. */ - signatureUrl(name: string, options?: SignatureUrlOptions): string; + signatureUrl(name: string, options?: OSS.SignatureUrlOptions): string; /** * Set object's ACL. */ - putACL(name: string, acl: ACLType, options?: RequestOptions): Promise; + putACL(name: string, acl: OSS.ACLType, options?: OSS.RequestOptions): Promise; /** * Get object's ACL. */ - getACL(name: string, options?: RequestOptions): Promise; + getACL(name: string, options?: OSS.RequestOptions): Promise; /** * Restore Object. */ - restore(name: string, options?: RequestOptions): Promise; + restore(name: string, options?: OSS.RequestOptions): Promise; /** * multi upload */ - initMultipartUpload(name: string, options?: InitMultipartUploadOptions): Promise; + initMultipartUpload(name: string, options?: OSS.InitMultipartUploadOptions): Promise; /** * After initiating a Multipart Upload event, you can upload data in parts based on the specified object name and Upload ID. */ - uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: RequestOptions): Promise; + uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: OSS.RequestOptions): Promise; /** * Using Upload Part Copy, you can copy data from an existing object and upload a part of the data. @@ -673,7 +786,7 @@ export default class OSS { range: string, sourceData: { sourceKey: string, sourceBucketName: string }, options: { timeout?: number, headers?: object } - ): Promise; + ): Promise; /** * After uploading all data parts, you must call the Complete Multipart Upload API to complete Multipart Upload for the entire file. @@ -682,79 +795,79 @@ export default class OSS { name: string, uploadId: string, parts: Array<{ number: number, etag: string }>, - options?: CompleteMultipartUploadOptions - ): Promise; + options?: OSS.CompleteMultipartUploadOptions + ): Promise; /** * Upload file with OSS multipart. */ - multipartUpload(name: string, file: any, options: MultipartUploadOptions): Promise; + multipartUpload(name: string, file: any, options: OSS.MultipartUploadOptions): Promise; /** * Copy file with OSS multipart. * this function contains head, initMultipartUpload, uploadPartCopy, completeMultipartUpload. * When copying a file larger than 1 GB, you should use the Upload Part Copy method. If you want to copy a file smaller than 1 GB, see Copy Object. */ - multipartUploadCopy(name: string, sourceData: MultipartUploadCopySourceData, options?: MultipartUploadOptions): Promise; + multipartUploadCopy(name: string, sourceData: OSS.MultipartUploadCopySourceData, options?: OSS.MultipartUploadOptions): Promise; /** * The ListParts command can be used to list all successfully uploaded parts mapped to a specific upload ID, i.e.: those not completed and not aborted. */ - listParts(name: string, uploadId: string, query?: ListPartsQuery, options?: RequestOptions): Promise; + listParts(name: string, uploadId: string, query?: OSS.ListPartsQuery, options?: OSS.RequestOptions): Promise; /** * List on-going multipart uploads, i.e.: those not completed and not aborted. */ - listUploads(query: ListUploadsQuery, options?: RequestOptions): Promise; + listUploads(query: OSS.ListUploadsQuery, options?: OSS.RequestOptions): Promise; /** * Abort a multipart upload for object. */ - abortMultipartUpload(name: string, uploadId: string, options?: RequestOptions): Promise; + abortMultipartUpload(name: string, uploadId: string, options?: OSS.RequestOptions): Promise; /************************************************ RTMP Operations *************************************************************/ /** * Create a live channel. */ - putChannel(id: string, conf: PutChannelConf, options?: RequestOptions): Promise; + putChannel(id: string, conf: OSS.PutChannelConf, options?: OSS.RequestOptions): Promise; /** * Get live channel info. */ - getChannel(id: string, options?: RequestOptions): Promise<{ data: PutChannelConf, res: NormalSuccessResponse }>; + getChannel(id: string, options?: OSS.RequestOptions): Promise<{ data: OSS.PutChannelConf, res: OSS.NormalSuccessResponse }>; /** * Delete a live channel. */ - deleteChannel(id: string, options?: RequestOptions): Promise; + deleteChannel(id: string, options?: OSS.RequestOptions): Promise; /** * Change the live channel status. */ - putChannelStatus(id: string, status?: string, options?: RequestOptions): Promise; + putChannelStatus(id: string, status?: string, options?: OSS.RequestOptions): Promise; /** * Get the live channel status. */ - getChannelStatus(id: string, options?: RequestOptions): Promise; + getChannelStatus(id: string, options?: OSS.RequestOptions): Promise; /** * List channels. */ - listChannels(query: ListChannelsQuery, options?: RequestOptions): Promise; + listChannels(query: OSS.ListChannelsQuery, options?: OSS.RequestOptions): Promise; /** * Get the live channel history. */ - getChannelHistory(id: string, options?: RequestOptions): Promise; + getChannelHistory(id: string, options?: OSS.RequestOptions): Promise; /** * Create a VOD playlist for the channel. */ - createVod(id: string, name: string, time: { startTime: number, endTime: number }, options?: RequestOptions): Promise; + createVod(id: string, name: string, time: { startTime: number, endTime: number }, options?: OSS.RequestOptions): Promise; /** * Get signatured rtmp url for publishing. */ - getRtmpUrl(channelId?: string, options?: GetRtmpUrlOptions): string; + getRtmpUrl(channelId?: string, options?: OSS.GetRtmpUrlOptions): string; } diff --git a/types/ali-oss/tslint.json b/types/ali-oss/tslint.json index f93cf8562a..8192d88dd1 100644 --- a/types/ali-oss/tslint.json +++ b/types/ali-oss/tslint.json @@ -1,3 +1,6 @@ { - "extends": "dtslint/dt.json" + "extends": "dtslint/dt.json", + "rules": { + "no-mergeable-namespace": false + } }