UNPKG

@octopusx/ndk

Version:

octopus x sdk to connect to the octopusx grids and services

259 lines (258 loc) 11.1 kB
"use strict"; var __awaiter = (this && this.__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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const requests_1 = require("../utils/requests"); class Data { constructor(options) { this.options = options; this.options.url = process.env.OCX_DATA_BASE_URL || process.env.VUE_APP_OCX_DATA_BASE_URL; } initData(payload) { return { "OCX Schema": this.options.version, "OCXType": "Request", "OCXComponent": "OCXData", "OCXPayload": payload }; } setUp(domainId) { return __awaiter(this, void 0, void 0, function* () { const body = { domain_id: domainId }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `setup`; // return this.initData(body); return requests_1.default(`POST`, url, requestOptions); }); } createHost(data) { return __awaiter(this, void 0, void 0, function* () { const body = { host_data: data }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `host/create`; return requests_1.default(`POST`, url, requestOptions); }); } getHosts() { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign({}, this.options); const url = `host/retrieve`; return requests_1.default(`GET`, url, requestOptions); }); } updateHost(hostId, data) { return __awaiter(this, void 0, void 0, function* () { const body = { host_id: hostId, host_data: data }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `host/update`; return requests_1.default(`POST`, url, requestOptions); }); } deleteHost(hostId) { return __awaiter(this, void 0, void 0, function* () { const body = { host_id: hostId, }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `host/delete`; return requests_1.default(`POST`, url, requestOptions); }); } createField(data, tableName) { return __awaiter(this, void 0, void 0, function* () { const body = { table_name: tableName, field_data: data }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `field/create`; return requests_1.default(`POST`, url, requestOptions); }); } updateField(fieldId, data) { return __awaiter(this, void 0, void 0, function* () { const body = { field_id: fieldId, field_data: data }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `field/update`; return requests_1.default(`POST`, url, requestOptions); }); } deleteField(fieldId) { return __awaiter(this, void 0, void 0, function* () { const body = { field_id: fieldId, }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `field/delete`; return requests_1.default(`POST`, url, requestOptions); }); } getFields(tableId) { return __awaiter(this, void 0, void 0, function* () { const body = { table_id: tableId }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `field/retrieve`; return requests_1.default(`POST`, url, requestOptions); }); } createTable(data) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) }); const url = `table/create`; return requests_1.default(`POST`, url, requestOptions); }); } updateTable(tableId, data) { return __awaiter(this, void 0, void 0, function* () { const body = { table_id: tableId, table_data: { table_name: data.table_name, visibility: data.visibility } }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `table/update`; return requests_1.default(`POST`, url, requestOptions); }); } deleteTable(tableId) { return __awaiter(this, void 0, void 0, function* () { const body = { table_id: tableId, }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `table/delete`; return requests_1.default(`POST`, url, requestOptions); }); } getTables() { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign({}, this.options); const url = `table/retrieve`; return requests_1.default(`GET`, url, requestOptions); }); } updateQuery(data) { return __awaiter(this, void 0, void 0, function* () { const queryBody = { "table_name": data.table_name, "where": [ { "column": data.query, "operation": "=", "value": data.value } ], "data": data.queryPayload, "order": { "column": data.query, "operation": "asc" }, "count": null }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(queryBody) }); const url = `query/update`; return requests_1.default(`POST`, url, requestOptions); }); } fetchAllQuery(data) { return __awaiter(this, void 0, void 0, function* () { const queryBody = { "table_name": data.table_name, "where": [], "joins": [], "reverse_joins": [], "order": { "column": data.query, "operation": "asc" }, "count": null, "pagination": null }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(queryBody) }); const url = `query/retrieve`; return requests_1.default(`POST`, url, requestOptions); }); } urlGridLoad(data) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) }); const url = `gridloader/load-url`; return requests_1.default(`POST`, url, requestOptions); }); } fileGridLoad(data) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) }); const url = `gridloader/load-csv`; return requests_1.default(`POST`, url, requestOptions); }); } asyncGridCsvAndJsonLoad(data) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) }); const url = `gridloader/load-data-async`; return requests_1.default(`POST`, url, requestOptions); }); } createGenerate(tableId, fileType) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData({ id: tableId, type: fileType }) }); const url = `table/generate-example-file`; return requests_1.default(`POST`, url, requestOptions); }); } createDataConnection(data) { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) }); const url = `datapoint/create`; return requests_1.default(`POST`, url, requestOptions); }); } fetchDataConnections() { return __awaiter(this, void 0, void 0, function* () { const requestOptions = Object.assign({}, this.options); const url = `datapoint/retrieve`; return requests_1.default(`POST`, url, requestOptions); }); } fetchSingleDataConnection(connectionId) { return __awaiter(this, void 0, void 0, function* () { const body = { id: connectionId }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `datapoint/retrieveone`; return requests_1.default(`POST`, url, requestOptions); }); } updateDataConnection(connectionId, payload) { return __awaiter(this, void 0, void 0, function* () { const body = Object.assign({ id: connectionId }, payload); const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `datapoint/update`; return requests_1.default(`POST`, url, requestOptions); }); } deleteDataConnection(connectionId) { return __awaiter(this, void 0, void 0, function* () { const body = { id: connectionId, }; const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(body) }); const url = `datapoint/delete`; return requests_1.default(`POST`, url, requestOptions); }); } } exports.default = Data;