UNPKG

flydrive-azure

Version:
126 lines (125 loc) 5.47 kB
import { type Readable } from 'node:stream'; import { type DriveFile, type DriveDirectory } from 'flydrive'; import type { WriteOptions, DriverContract, ObjectMetaData, ObjectVisibility, SignedURLOptions } from 'flydrive/types'; import { type BlobDownloadToBufferOptions, type BlobExistsOptions, BlobServiceClient, type BlockBlobUploadOptions } from '@azure/storage-blob'; import { type AzureStorageDriverConfig, CannotCopyFileException, CannotDeleteFileException, CannotGetMetaDataException, CannotMoveFileException, CannotSetMetaDataException, CannotWriteFileException, FileNotFoundException, MethodNotImplementedException } from './types.js'; export declare class AzureDriver implements DriverContract { private readonly config; /** * Reference to the Azure storage instance */ adapter: BlobServiceClient; /** * Constructor * @param {AzureStorageDriverConfig} config - The configuration for the Azure storage driver */ constructor(config: AzureStorageDriverConfig); private getBlockBlobClient; /** * Return a boolean value indicating if the file exists * or not. */ exists(key: string, optoins?: BlobExistsOptions): Promise<boolean>; /** * Return the file contents as a UTF-8 string. Throw an exception * if the file is missing. */ get(key: string, options?: BlobDownloadToBufferOptions): Promise<string>; /** * Return the file contents as a Readable stream. Throw an exception * if the file is missing. */ getStream(key: string, options?: BlobDownloadToBufferOptions): Promise<Readable>; /** * Return the file contents as a Uint8Array. Throw an exception * if the file is missing. */ getBytes(key: string, options?: BlobDownloadToBufferOptions): Promise<Uint8Array>; /** * Return metadata of the file. Throw an exception * if the file is missing. */ getMetaData(key: string): Promise<ObjectMetaData>; /** * Return visibility of the file. Infer visibility from the initial * config, when the driver does not support the concept of visibility. */ getVisibility(key: string): Promise<ObjectVisibility>; /** * Return the public URL of the file. Throw an exception when the driver * does not support generating URLs. */ getUrl(key: string): Promise<string>; /** * Return the signed URL to serve a private file. Throw exception * when the driver does not support generating URLs. */ getSignedUrl(key: string, options?: SignedURLOptions): Promise<string>; /** * Generate a signed URL for a blob. * @param blockBlobClient - The block blob client to generate the URL for. * @param options - The options for the signed URL. * @returns The signed URL. */ private generateBlobSASURL; /** * Update the visibility of the file. Result in a NOOP * when the driver does not support the concept of * visibility. */ setVisibility(key: string, visibility: ObjectVisibility): Promise<void>; /** * Update the visibility of the file. Result in a NOOP * when the driver does not support the concept of * getting signed upload url. */ getSignedUploadUrl(key: string, options?: SignedURLOptions): Promise<string>; /** * Create a new file or update an existing file. The contents * will be a UTF-8 string or "Uint8Array". */ put(key: string, contents: string | Uint8Array, options?: BlockBlobUploadOptions): Promise<void>; /** * Create a new file or update an existing file. The contents * will be a Readable stream. */ putStream(key: string, contents: Readable, options?: BlockBlobUploadOptions): Promise<void>; /** * Copy the existing file to the destination. Make sure the new file * has the same visibility as the existing file. It might require * manually fetching the visibility of the "source" file. */ copy(source: string, destination: string, options?: WriteOptions): Promise<void>; /** * Move the existing file to the destination. Make sure the new file * has the same visibility as the existing file. It might require * manually fetching the visibility of the "source" file. */ move(source: string, destination: string, options?: WriteOptions): Promise<void>; /** * Delete an existing file. Do not throw an error if the * file is already missing */ delete(key: string): Promise<void>; /** * Delete all files inside a folder. Do not throw an error * if the folder does not exist or is empty. */ deleteAll(prefix: string): Promise<void>; /** * List all files from a given folder or the root of the storage. * Do not throw an error if the request folder does not exist. */ listAll(prefix: string, options?: { recursive?: boolean; paginationToken?: string; }): Promise<{ paginationToken?: string; objects: Iterable<DriveFile | DriveDirectory>; }>; } export declare function AzureService(config: AzureStorageDriverConfig): { type: 'provider'; resolver: () => Promise<() => AzureDriver>; }; export { type AzureStorageDriverConfig, CannotCopyFileException, CannotDeleteFileException, CannotGetMetaDataException, CannotMoveFileException, CannotSetMetaDataException, CannotWriteFileException, FileNotFoundException, MethodNotImplementedException };