@gentrace/core
Version:
Core Gentrace Node.JS library
79 lines (76 loc) • 4.05 kB
JavaScript
import { globalGentraceApiV2 } from './init.mjs';
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/**
* Retrieves datasets from the Gentrace API.
* @async
* @param {Object} [params] - Optional parameters to filter the datasets.
* @param {string} [params.pipelineSlug] - The slug of the pipeline to filter datasets by.
* @param {string} [params.pipelineId] - The ID of the pipeline to filter datasets by.
* @param {boolean} [params.archived] - Filter datasets by archived status.
* @returns {Promise<Array<DatasetV2>>} - A promise that resolves to an array of datasets.
* @throws {Error} - Throws an error if the Gentrace API key is not initialized.
*/
const getDatasets = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
if (!globalGentraceApiV2) {
throw new Error("Gentrace API key not initialized. Call init() first.");
}
if (!(params === null || params === void 0 ? void 0 : params.pipelineSlug) && !(params === null || params === void 0 ? void 0 : params.pipelineId)) {
throw new Error("Either pipelineSlug or pipelineId must be defined.");
}
const response = yield globalGentraceApiV2.v2DatasetsGet(params === null || params === void 0 ? void 0 : params.pipelineSlug, params === null || params === void 0 ? void 0 : params.pipelineId, params === null || params === void 0 ? void 0 : params.archived);
return (_a = response.data.data) !== null && _a !== void 0 ? _a : [];
});
/**
* Creates a new dataset in the Gentrace API.
* @async
* @param {CreateDatasetV2} payload - The dataset creation payload.
* @returns {Promise<DatasetV2>} - A promise that resolves to the created dataset.
* @throws {Error} - Throws an error if the Gentrace API key is not initialized.
*/
const createDataset = (payload) => __awaiter(void 0, void 0, void 0, function* () {
if (!globalGentraceApiV2) {
throw new Error("Gentrace API key not initialized. Call init() first.");
}
const response = yield globalGentraceApiV2.v2DatasetsPost(payload);
return response.data;
});
/**
* Retrieves a single dataset from the Gentrace API.
* @async
* @param {string} id - The ID of the dataset to retrieve.
* @returns {Promise<DatasetV2>} - A promise that resolves to the retrieved dataset.
* @throws {Error} - Throws an error if the Gentrace API key is not initialized.
*/
const getDataset = (id) => __awaiter(void 0, void 0, void 0, function* () {
if (!globalGentraceApiV2) {
throw new Error("Gentrace API key not initialized. Call init() first.");
}
const response = yield globalGentraceApiV2.v2DatasetsIdGet(id);
return response.data;
});
/**
* Updates a dataset in the Gentrace API.
* @async
* @param {string} id - The ID of the dataset to update.
* @param {UpdateDatasetV2} payload - The dataset update payload.
* @returns {Promise<DatasetV2>} - A promise that resolves to the updated dataset.
* @throws {Error} - Throws an error if the Gentrace API key is not initialized.
*/
const updateDataset = (id, payload) => __awaiter(void 0, void 0, void 0, function* () {
if (!globalGentraceApiV2) {
throw new Error("Gentrace API key not initialized. Call init() first.");
}
const response = yield globalGentraceApiV2.v2DatasetsIdPost(id, payload);
return response.data;
});
export { createDataset, getDataset, getDatasets, updateDataset };
//# sourceMappingURL=dataset.mjs.map