lemon-core
Version:
Lemon Serverless Micro-Service Platform
194 lines (193 loc) • 5.44 kB
TypeScript
/// <reference types="node" />
import { CoreServices } from '../core-services';
import 'dotenv/config';
declare const instance: () => any;
export interface TagSet {
[key: string]: string;
}
/**
* type: `HeadObjectResult`
* - some properties of `HeadObjectOutput`
*/
export interface HeadObjectResult {
ContentType: string;
ContentLength: number;
Metadata: ReturnType<typeof instance>['Metadata'];
ETag: string;
LastModified: string;
}
/**
* type: `PutObjectResult`
* - only some properties from origin-result.
*/
export interface PutObjectResult {
Location: string;
Bucket: string;
Key: string;
/**
* An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL.
*/
ETag: string;
/**
* Size of the body in bytes.
*/
ContentLength?: number;
/**
* A standard MIME type describing the format of the object data.
*/
ContentType?: string;
/**
* A map of metadata to store with the object in S3.
*/
Metadata?: ReturnType<typeof instance>['Metadata'];
}
/**
* type: `GetObjectResult`
* - only some properties from origin-result.
*/
export interface GetObjectResult {
/**
* Size of the body in bytes.
*/
ContentLength?: number;
/**
* A standard MIME type describing the format of the object data.
*/
ContentType?: string;
/**
* A map of metadata to store with the object in S3.
*/
Metadata: ReturnType<typeof instance>['Metadata'];
/**
* Object data.
*/
Body?: Body;
/**
* An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL.
*/
ETag: string;
/**
* The number of tags, if any, on the object.
*/
TagCount?: number;
}
/**
* type: `ListObjectResult`
* - only some properties from origin-result.
*/
export interface ListObjectResult {
/** list of object infor */
Contents: ReturnType<typeof instance>['BlobItem'];
/** limit of each request */
MaxKeys: number;
/** total key-count read */
KeyCount: number;
/** flag to have more */
IsTruncated?: boolean;
/** valid only if truncated, and has more */
NextContinuationToken?: string;
/** internal error-string */
error?: string;
}
export interface CoreBlobService extends CoreServices {
bucket: (target?: string) => string;
putObject: (body: string, key?: string, metadata?: ReturnType<typeof instance>['Metadata'], tags?: TagSet) => Promise<PutObjectResult>;
getObject: (key: string) => Promise<any>;
getDecodedObject: (key: string) => Promise<any>;
getObjectTagging: (key: string) => Promise<TagSet>;
deleteObject: (key: string) => Promise<void>;
}
/**
* main service implement.
*/
export declare class BlobService implements CoreBlobService {
/**
* environ name to use `bucket`
*/
static ENV_BLOB_NAME: string;
/**
* default `bucket` name
*/
static DEF_BLOB_BUCKET: string;
/**
* get name of this
*/
name: () => string;
/**
* hello
*/
hello: () => string;
/**
* get target endpoint by name.
*/
bucket: (target?: string) => string;
/**
* get azure sdk for blob
*/
instance: () => Promise<{
storageClient: any;
blobServiceClient: any;
resourceGroupName: string;
Metadata: any;
BlobItem: any;
}>;
/**
* retrieve metadata without returning the object
*
* @param {string} key
* @return metadata object / null if not exists
*/
headObject: (key: string) => Promise<HeadObjectResult>;
/**
* get a file from Blob Container
*
* @param {string} key
*/
getObject: (key: string) => Promise<any>;
/**
* return decoded Object from Blob Container file.
*
* @param {string} key ex) 'hello-0001.json' , 'dist/hello-0001.json
*/
getDecodedObject: <T = object>(key: string) => Promise<T>;
/**
* get tag-set of object
*
* @param {string} key
*/
getObjectTagging: (key: string) => Promise<any>;
/**
* delete object from Blob Container
*
* @param {string} key
*/
deleteObject: (key: string) => Promise<void>;
/**
* list objects in Blob Container
*/
listObjects: (options?: {
/** keys that begin with the specified prefix. */
prefix?: string;
/** use to group keys */
delimiter?: string;
/** maximum number of keys returned in single request (default 10, max 1000) */
limit?: number;
/** flag to read all keys (each request contains `limit`) */
unlimited?: boolean;
/** same as NextContinuationToken */
nextToken?: string;
/** (optional) flag to throw error if error, or see `.error` in result */
throwable?: boolean;
}) => Promise<any>;
/**
* upload a file to Blob Container
*
*
* @param {string|Buffer} content content body
* @param {string} key (optional) S3 key to put
* @param {Metadata} metadata (optional) metadata to store
* @param {object} tags (optional) tag set
*/
putObject: (content: string | Buffer, key?: string, metadata?: ReturnType<typeof instance>['Metadata'], tags?: TagSet) => Promise<any>;
}
export {};