@gensx/storage
Version:
Cloud storage, blobs, sqlite, and vector database providers/hooks for GenSX.
76 lines (71 loc) • 2.43 kB
JavaScript
;
/**
* 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
*/
var path = require('path');
var config = require('../utils/config.cjs');
var filesystem = require('./filesystem.cjs');
var remote = require('./remote.cjs');
/**
* 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
: path.join(process.cwd(), ".gensx", "blobs");
this.storage = new filesystem.FileSystemBlobStorage(rootDir, options.defaultPrefix);
}
else {
const { project, environment } = config.getProjectAndEnvironment({
project: options.project,
environment: options.environment,
});
this.storage = new remote.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);
}
}
exports.BlobClient = BlobClient;
//# sourceMappingURL=blobClient.cjs.map