UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

66 lines (65 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Glossaries = void 0; const errors_1 = require("./errors"); class Glossaries { constructor(client) { this.client = client; this.pollingInterval = 2000; } async list() { return await this.client.get("/glossaries"); } async create(name) { return await this.client.post("/glossaries", { name }); } async get(id) { try { return await this.client.get(`/glossaries/${id}`); } catch (e) { if (e instanceof errors_1.LaraApiError && e.statusCode === 404) { return null; } throw e; } } async delete(id) { return await this.client.delete(`/glossaries/${id}`); } async update(id, name) { return await this.client.put(`/glossaries/${id}`, { name }); } async importCsv(id, csv, gzip = false) { return await this.client.post(`/glossaries/${id}/import`, { compression: gzip ? "gzip" : undefined }, { csv }); } async getImportStatus(id) { return await this.client.get(`/glossaries/imports/${id}`); } async waitForImport(gImport, updateCallback, maxWaitTime) { const start = Date.now(); while (gImport.progress < 1.0) { if (maxWaitTime && Date.now() - start > maxWaitTime) throw new errors_1.TimeoutError(); await new Promise((resolve) => setTimeout(resolve, this.pollingInterval)); gImport = await this.getImportStatus(gImport.id); if (updateCallback) updateCallback(gImport); } return gImport; } async counts(id) { return await this.client.get(`/glossaries/${id}/counts`); } async export(id, contentType, source) { return await this.client.get(`/glossaries/${id}/export`, { content_type: contentType, source }); } } exports.Glossaries = Glossaries;