@dataset.sh/client
Version:
TypeScript client library for dataset.sh - A powerful dataset management system supporting both local and remote storage with seamless transfer capabilities.
63 lines • 2.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteDataset = void 0;
const RemoteDatasetVersion_1 = require("./RemoteDatasetVersion");
class RemoteDataset {
constructor(client, namespace, datasetName) {
this.client = client;
this.namespace = namespace;
this.datasetName = datasetName;
// Initialize endpoints object
this.endpoints = {
listVersions: (page, limit) => this.client.endpoints.listVersions(this.namespace, this.datasetName, page, limit),
downloadVersion: (version) => this.client.endpoints.downloadVersion(this.namespace, this.datasetName, version),
listTags: () => this.client.endpoints.listTags(this.namespace, this.datasetName),
resolveTag: (tag) => this.client.endpoints.resolveTag(this.namespace, this.datasetName, tag),
setTag: (tag) => this.client.endpoints.setTag(this.namespace, this.datasetName, tag),
downloadByTag: (tag) => this.client.endpoints.downloadByTag(this.namespace, this.datasetName, tag),
};
}
async versions(page, limit) {
const result = await this.client.listVersions(this.namespace, this.datasetName, page, limit);
return result.versions.map(v => new RemoteDatasetVersion_1.RemoteDatasetVersion(this.client, this.namespace, this.datasetName, v.version));
}
version(versionId) {
return new RemoteDatasetVersion_1.RemoteDatasetVersion(this.client, this.namespace, this.datasetName, versionId);
}
async tags() {
const result = await this.client.listTags(this.namespace, this.datasetName);
const tags = new Map();
for (const tag of result.tags) {
tags.set(tag.tag, tag.version);
}
return tags;
}
async tag(tagName) {
const resolveResult = await this.client.resolveTag(this.namespace, this.datasetName, tagName);
if (!resolveResult.exists) {
return null;
}
return new RemoteDatasetVersion_1.RemoteDatasetVersion(this.client, this.namespace, this.datasetName, resolveResult.version);
}
async latest() {
return this.tag('latest');
}
async resolveTag(tagName) {
const result = await this.client.resolveTag(this.namespace, this.datasetName, tagName);
return result.exists ? result.version : null;
}
async setTag(tagName, versionId) {
await this.client.setTag(this.namespace, this.datasetName, tagName, versionId);
}
getNamespace() {
return this.namespace;
}
getDatasetName() {
return this.datasetName;
}
getFullName() {
return `${this.namespace}/${this.datasetName}`;
}
}
exports.RemoteDataset = RemoteDataset;
//# sourceMappingURL=RemoteDataset.js.map