UNPKG

@gensx/storage

Version:

Cloud storage, blobs, sqlite, and vector database providers/hooks for GenSX.

74 lines (70 loc) 2.42 kB
/** * Check out the docs at https://www.gensx.com/docs * Find us on Github https://github.com/gensx-inc/gensx * Find us on Discord https://discord.gg/F5BSU8Kc */ import { join } from 'path'; import { getProjectAndEnvironment } from '../utils/config.js'; import { FileSystemBlobStorage } from './filesystem.js'; import { RemoteBlobStorage } from './remote.js'; /** * Client for interacting with blob storage functionality outside of JSX context */ class BlobClient { storage; /** * Create a new BlobClient * @param options Optional configuration properties for the blob storage */ constructor(options = {}) { const kind = options.kind ?? (process.env.GENSX_RUNTIME === "cloud" ? "cloud" : "filesystem"); if (kind === "filesystem") { const rootDir = options.kind === "filesystem" && options.rootDir ? options.rootDir : join(process.cwd(), ".gensx", "blobs"); this.storage = new FileSystemBlobStorage(rootDir, options.defaultPrefix); } else { const { project, environment } = getProjectAndEnvironment({ project: options.project, environment: options.environment, }); this.storage = new RemoteBlobStorage(project, environment, options.defaultPrefix); } } /** * Get a blob * @param key The blob key * @returns A Blob instance for the given key */ getBlob(key) { return this.storage.getBlob(key); } /** * List all blobs with optional filtering and pagination * @param options Optional listing options including prefix, limit, and cursor for pagination * @returns A Promise resolving to the list response containing keys and pagination info */ async listBlobs(options) { return this.storage.listBlobs(options); } /** * Check if a blob exists * @param key The blob key * @returns A Promise resolving to a boolean indicating if the blob exists */ async blobExists(key) { return this.storage.blobExists(key); } /** * Delete a blob * @param key The blob key * @returns A Promise resolving to the result of the delete operation */ async deleteBlob(key) { return this.storage.deleteBlob(key); } } export { BlobClient }; //# sourceMappingURL=blobClient.js.map