=========== @e-mc/cloud =========== - **npm** i *@e-mc/cloud* Interface ========= .. highlight:: typescript .. code-block:: :caption: `View Source `_ :emphasize-lines: 46,57 import type { IHost, IScopeOrigin } from "./index"; import type { ExternalAsset } from "./asset"; import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload } from "./cloud"; import type { ClientDbConstructor, IClientDb } from "./core"; import type { BatchQueryResult, QueryResult } from "./db"; import type { LogMessageOptions } from "./logger"; import type { CloudAuthSettings, CloudModule, CloudServiceOptions, CloudSettings, DbCoerceSettings } from "./settings"; interface ICloud extends IClientDb { module: CloudModule; readonly uploaded: string[]; readonly downloaded: string[]; createBucket(service: string, credential: unknown, bucket: string, acl?: unknown, options?: unknown): Promise; createBucket(service: string, credential: unknown, bucket: string, publicRead?: boolean): Promise; setBucketPolicy(service: string, credential: unknown, bucket: string, options: unknown): Promise; setBucketTagging(service: string, credential: unknown, bucket: string, options: unknown): Promise; setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise; deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise; uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: ((value: string) => Promise | void)): Promise; downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: ((value: Buffer | string | null) => Promise | void)): Promise; getStorage(action: CloudFunctions, data: CloudStorage[] | undefined): CloudStorage | undefined; hasStorage(action: CloudFunctions, storage: CloudStorage): CloudStorageUpload | false; getDatabaseRows(item: CloudDatabase, ignoreErrors: boolean, sessionKey?: string): Promise; getDatabaseRows(item: CloudDatabase, sessionKey?: string): Promise; getDatabaseBatchRows(batch: CloudDatabase[], ignoreErrors: boolean, sessionKey?: string): Promise; getDatabaseBatchRows(batch: CloudDatabase[], sessionKey?: string): Promise; hasCredential(feature: CloudFeatures, data: CloudService, credential?: unknown): boolean; getCredential(item: CloudService, unused?: boolean): PlainObject; getSettings(service: string): Record | undefined; settingsOf(service: string, name: "coerce", component: keyof DbCoerceSettings): unknown; settingsOf(service: string, name: "auth", component: keyof CloudAuthSettings): unknown; getUploadHandler(service: string, credential: unknown): (...args: unknown[]) => void; getDownloadHandler(service: string, credential: unknown): (...args: unknown[]) => void; resolveService(service: string, folder?: string): string; get settings(): CloudSettings; } interface CloudConstructor extends ClientDbConstructor { LOG_CLOUD_FAIL: LogMessageOptions; LOG_CLOUD_COMMAND: LogMessageOptions; LOG_CLOUD_WARN: LogMessageOptions; LOG_CLOUD_UPLOAD: LogMessageOptions; LOG_CLOUD_DOWNLOAD: LogMessageOptions; LOG_CLOUD_DELETE: LogMessageOptions; LOG_CLOUD_DELAYED: LogMessageOptions; finalize(this: IHost, instance: ICloud): Promise; uploadAsset(state: IScopeOrigin, file: ExternalAsset, options: UploadAssetOptions): Promise[]; uploadAsset(state: IScopeOrigin, file: ExternalAsset, ignoreProcess: boolean): Promise[]; uploadAsset(state: IScopeOrigin, file: ExternalAsset, contentType?: string, ignoreProcess?: boolean): Promise[]; sanitizeAssets(assets: ExternalAsset[]): ExternalAsset[]; readonly prototype: ICloud; new(module?: CloudModule, database?: CloudDatabase[], ...args: unknown[]): ICloud; } interface ICloudServiceClient { CLOUD_SERVICE_NAME: string; CLOUD_UPLOAD_DISK?: boolean; CLOUD_UPLOAD_STREAM?: boolean; CLOUD_UPLOAD_CHUNK?: boolean; CLOUD_DOWNLOAD_CHUNK?: boolean; validateStorage?(credential: unknown, data?: CloudService): boolean; validateDatabase?(credential: unknown, data?: CloudService): boolean; createStorageClient?(this: IModule, credential: unknown, service?: string): unknown; createDatabaseClient?(this: IModule, credential: unknown, data?: CloudService): unknown; createBucket?(this: IModule, credential: unknown, bucket: string, publicRead?: boolean, service?: string, sdk?: string): Promise; createBucketV2?(this: IModule, credential: unknown, bucket: string, acl?: unknown, options?: unknown, service?: string, sdk?: string): Promise; setBucketPolicy?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise; setBucketTagging?(this: IModule, credential: unknown, bucket: string, options: unknown, service?: string, sdk?: string): Promise; setBucketWebsite?(this: IModule, credential: unknown, bucket: string, options: BucketWebsiteOptions, service?: string, sdk?: string): Promise; deleteObjects?(this: IModule, credential: unknown, bucket: string, service?: string, sdk?: string, recursive?: boolean): Promise; deleteObjectsV2?(this: IModule, credential: unknown, bucket: string, recursive?: boolean, service?: string, sdk?: string): Promise; executeQuery?(this: ICloud, credential: unknown, data: CloudDatabase, sessionKey?: string): Promise; executeBatchQuery?(this: ICloud, credential: unknown, batch: CloudDatabase[], sessionKey?: string): Promise; } .. versionadded:: 0.10.0 - *CloudConstructor* method **finalize** return value was modified to :target:`Promise`. .. versionadded:: 0.9.0 - *ICloud* method **setBucketTagging** was created. - *ICloudServiceClient* global **CLOUD_UPLOAD_DISK** replaced *CLOUD_UPLOAD_FROMDISK*. .. versionremoved:: 0.9.0 - *ICloudServiceClient* global **CLOUD_UPLOAD_FROMDISK** was renamed. Settings ======== .. code-block:: :caption: `View JSON `_ import type { PermittedDirectories } from "./core"; import type { CloudServiceOptions, DbSourceOptions, PurgeComponent } from "./settings"; interface CloudModule { // handler: "@e-mc/cloud"; extensions?: string[]; atlas?: CloudStoredCredentials; aws?: CloudStoredCredentials; "aws-v3"?: CloudStoredCredentials; azure?: CloudStoredCredentials; // az gcp?: CloudStoredCredentials; // gcloud ibm?: CloudStoredCredentials; oci?: CloudStoredCredentials; minio?: CloudStoredCredentials; settings?: { broadcast_id?: string | string[]; users?: Record>; cache_dir?: string; session_expires?: number; user_key?: Record; imports?: StringMap; purge?: PurgeComponent; atlas?: CloudServiceOptions; aws?: CloudServiceOptions; "aws-v3"?: CloudServiceOptions; azure?: CloudServiceOptions; gcp?: CloudServiceOptions; ibm?: CloudServiceOptions; oci?: CloudServiceOptions; minio?: CloudServiceOptions; }; permission?: PermittedDirectories; } type CloudStoredCredentials = Record>; Example usage ------------- .. code-block:: javascript :caption: Using @pi-r/aws const Cloud = require("@e-mc/cloud"); const instance = new Cloud({ aws: { main: { accessKeyId: "**********", secretAccessKey: "**********" } }, "aws-v3": { main: { credentials: { accessKeyId: "**********", secretAccessKey: "**********", region: "ap-northeast-1" } } } }); // instance.host = new Host(); instance.init(); const options = { contentType: "application/tar", acl: "authenticated-read", chunkSize: "8mb", overwrite: false, // Default tags: { key_1: "value", key_2: "value" } }; Promise.all([ // nodejs-001/archive.tar instance.uploadObject("aws", "main", "nodejs-001", options, "/tmp/archive.tar"), // nodejs-001/2024/01-01.tar instance.uploadObject("aws", "main", "nodejs-001", { ...options, publicRead: true, pathname: "2024", filename: "01-01.tar" }, "/tmp/archive.tar"), // nodejs-001/archive_1.tar instance.uploadObject("aws", { accessKeyId: "*****", secretAccessKey: "*****" }, "nodejs-001", { overwrite: false }, "/tmp/archive.tar") ]); const rows = await instance.getDatabaseRows({ service: "aws-v3", credential: "main", table: "demo", key: { id: 1 } }); References ========== - https://www.unpkg.com/@e-mc/types/lib/asset.d.ts - https://www.unpkg.com/@e-mc/types/lib/cloud.d.ts - https://www.unpkg.com/@e-mc/types/lib/core.d.ts - https://www.unpkg.com/@e-mc/types/lib/db.d.ts - https://www.unpkg.com/@e-mc/types/lib/logger.d.ts - https://www.unpkg.com/@e-mc/types/lib/settings.d.ts