cloud-ide-model-schema
Version:
Pachage for schema management of Cloud IDEsys LMS
233 lines (232 loc) • 15 kB
JavaScript
"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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringInterpolation = void 0;
function stringInterpolation(variables, body, data) {
return __awaiter(this, void 0, void 0, function () {
var bodyArray, replacedBody, _a, bodyArray_1, bodyArray_1_1, body_row, body_row_init, row_count, variable_array, spilited_variable_array, i, _b, body_row_init_1, body_row_init_1_1, body_row_init_row, replacedRow, index, row_array, _c, row_array_1, row_array_1_1, row_splited, updated_row, row_data, variable, variable_array_index, array_data_path, array_data_path, e_1_1, e_2_1, e_3_1;
var _d, e_3, _e, _f, _g, e_2, _h, _j, _k, e_1, _l, _m;
var _o, _p, _q;
return __generator(this, function (_r) {
switch (_r.label) {
case 0:
bodyArray = body.split("//");
replacedBody = [];
_r.label = 1;
case 1:
_r.trys.push([1, 29, 30, 35]);
_a = true, bodyArray_1 = __asyncValues(bodyArray);
_r.label = 2;
case 2: return [4 /*yield*/, bodyArray_1.next()];
case 3:
if (!(bodyArray_1_1 = _r.sent(), _d = bodyArray_1_1.done, !_d)) return [3 /*break*/, 28];
_f = bodyArray_1_1.value;
_a = false;
body_row = _f;
body_row_init = [body_row];
if (body_row.includes('[')) {
body_row_init = [];
row_count = 0;
variable_array = body_row.slice(1, (body_row === null || body_row === void 0 ? void 0 : body_row.indexOf(']')));
if (variable_array === null || variable_array === void 0 ? void 0 : variable_array.includes("-")) {
spilited_variable_array = variable_array === null || variable_array === void 0 ? void 0 : variable_array.split("-");
if ((spilited_variable_array === null || spilited_variable_array === void 0 ? void 0 : spilited_variable_array.length) == 2) {
row_count = (_o = data[spilited_variable_array[0]][spilited_variable_array[1]]) === null || _o === void 0 ? void 0 : _o.length;
}
}
else {
row_count = (_p = data[variable_array]) === null || _p === void 0 ? void 0 : _p.length;
}
for (i = 0; i < row_count; i++) {
body_row_init.push("[" + i + "]" + body_row.slice(((body_row === null || body_row === void 0 ? void 0 : body_row.indexOf(']')) + 1)));
}
}
_r.label = 4;
case 4:
_r.trys.push([4, 21, 22, 27]);
_b = true, body_row_init_1 = (e_2 = void 0, __asyncValues(body_row_init));
_r.label = 5;
case 5: return [4 /*yield*/, body_row_init_1.next()];
case 6:
if (!(body_row_init_1_1 = _r.sent(), _g = body_row_init_1_1.done, !_g)) return [3 /*break*/, 20];
_j = body_row_init_1_1.value;
_b = false;
body_row_init_row = _j;
replacedRow = [];
index = 0;
if (body_row_init_row === null || body_row_init_row === void 0 ? void 0 : body_row_init_row.includes("[")) {
index = parseInt(body_row_init_row === null || body_row_init_row === void 0 ? void 0 : body_row_init_row.slice(1, ((body_row_init_row === null || body_row_init_row === void 0 ? void 0 : body_row_init_row.indexOf(']')) + 1)));
body_row_init_row = body_row_init_row === null || body_row_init_row === void 0 ? void 0 : body_row_init_row.slice((body_row_init_row === null || body_row_init_row === void 0 ? void 0 : body_row_init_row.indexOf(']')) + 1);
}
row_array = body_row_init_row.split("\\");
_r.label = 7;
case 7:
_r.trys.push([7, 12, 13, 18]);
_c = true, row_array_1 = (e_1 = void 0, __asyncValues(row_array));
_r.label = 8;
case 8: return [4 /*yield*/, row_array_1.next()];
case 9:
if (!(row_array_1_1 = _r.sent(), _k = row_array_1_1.done, !_k)) return [3 /*break*/, 11];
_m = row_array_1_1.value;
_c = false;
row_splited = _m;
updated_row = row_splited;
if ((updated_row === null || updated_row === void 0 ? void 0 : updated_row.length) > 2) {
row_data = data;
if (updated_row[0] == "{" && updated_row[(updated_row === null || updated_row === void 0 ? void 0 : updated_row.length) - 1] == "}") {
variable = variables[updated_row.slice(1, ((updated_row === null || updated_row === void 0 ? void 0 : updated_row.length) - 1))];
if (variable === null || variable === void 0 ? void 0 : variable.includes("~")) {
variable_array_index = variable === null || variable === void 0 ? void 0 : variable.split("~");
if ((_q = variable_array_index[0]) === null || _q === void 0 ? void 0 : _q.includes("-")) {
array_data_path = variable_array_index[0].split("-");
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 2) {
row_data = row_data[array_data_path[0]][array_data_path[1]][index];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 3) {
row_data = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]][index];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 4) {
row_data = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]][array_data_path[3]][index];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 5) {
row_data = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]][array_data_path[3]][array_data_path[4]][index];
}
}
else {
row_data = row_data[variable];
}
variable = variable_array_index[1];
}
if (variable === null || variable === void 0 ? void 0 : variable.includes("-")) {
array_data_path = variable.split("-");
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 2) {
updated_row = row_data[array_data_path[0]][array_data_path[1]];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 3) {
updated_row = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 4) {
updated_row = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]][array_data_path[3]];
}
if ((array_data_path === null || array_data_path === void 0 ? void 0 : array_data_path.length) == 5) {
updated_row = row_data[array_data_path[0]][array_data_path[1]][array_data_path[2]][array_data_path[3]][array_data_path[4]];
}
}
else {
updated_row = row_data[variable];
}
}
}
replacedRow.push(updated_row);
_r.label = 10;
case 10:
_c = true;
return [3 /*break*/, 8];
case 11: return [3 /*break*/, 18];
case 12:
e_1_1 = _r.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 18];
case 13:
_r.trys.push([13, , 16, 17]);
if (!(!_c && !_k && (_l = row_array_1.return))) return [3 /*break*/, 15];
return [4 /*yield*/, _l.call(row_array_1)];
case 14:
_r.sent();
_r.label = 15;
case 15: return [3 /*break*/, 17];
case 16:
if (e_1) throw e_1.error;
return [7 /*endfinally*/];
case 17: return [7 /*endfinally*/];
case 18:
replacedBody.push(replacedRow === null || replacedRow === void 0 ? void 0 : replacedRow.join(""));
_r.label = 19;
case 19:
_b = true;
return [3 /*break*/, 5];
case 20: return [3 /*break*/, 27];
case 21:
e_2_1 = _r.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 27];
case 22:
_r.trys.push([22, , 25, 26]);
if (!(!_b && !_g && (_h = body_row_init_1.return))) return [3 /*break*/, 24];
return [4 /*yield*/, _h.call(body_row_init_1)];
case 23:
_r.sent();
_r.label = 24;
case 24: return [3 /*break*/, 26];
case 25:
if (e_2) throw e_2.error;
return [7 /*endfinally*/];
case 26: return [7 /*endfinally*/];
case 27:
_a = true;
return [3 /*break*/, 2];
case 28: return [3 /*break*/, 35];
case 29:
e_3_1 = _r.sent();
e_3 = { error: e_3_1 };
return [3 /*break*/, 35];
case 30:
_r.trys.push([30, , 33, 34]);
if (!(!_a && !_d && (_e = bodyArray_1.return))) return [3 /*break*/, 32];
return [4 /*yield*/, _e.call(bodyArray_1)];
case 31:
_r.sent();
_r.label = 32;
case 32: return [3 /*break*/, 34];
case 33:
if (e_3) throw e_3.error;
return [7 /*endfinally*/];
case 34: return [7 /*endfinally*/];
case 35: return [2 /*return*/, replacedBody.join("")];
}
});
});
}
exports.stringInterpolation = stringInterpolation;