UNPKG

@lcap/asl

Version:

NetEase Application Specific Language

197 lines 6.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadVertexIdToName = exports.saveVertexIdToName = exports.getVertexIdToName = exports.loadApisCache = exports.saveApisCache = exports.loadEnumsCache = exports.saveEnumsCache = exports.loadDataTypesCache = exports.saveDataTypesCache = exports.generateDataJson = exports.apisToJson = exports.enumsToJson = exports.dataTypesToJson = void 0; const __1 = require(".."); const webFile_1 = __importDefault(require("../../service/webFile")); const hotReload_1 = require("./hotReload"); function dataTypesToJson() { return __1.dataTypesMap; } exports.dataTypesToJson = dataTypesToJson; function enumsToJson(app) { const enums = app.firstMicroService.data.enums; const enumsJson = {}; enums.forEach((enumTemp) => { enumsJson[enumTemp.name] = enumsJson[enumTemp.name] || {}; const enumItemList = enumTemp.enumItemList; enumItemList.forEach((enumItem) => { enumsJson[enumTemp.name][`${enumItem.value}`] = enumItem.label; }); }); return enumsJson; } exports.enumsToJson = enumsToJson; function apisToJson(app) { const apiJson = {}; app.services.forEach((service) => { service.interfaces.forEach((itface) => { const path = itface.path || ''; apiJson[itface.name] = { url: { path, method: itface.method, }, }; }); if (service.processes) { service.processes.forEach((process) => { const { launchProcessInterface, childShapes } = process; const path = launchProcessInterface.path || ''; apiJson[launchProcessInterface.name] = { url: { path, method: launchProcessInterface.method, }, }; childShapes.forEach((processComp) => { const { type, completeTaskInterface } = processComp; if (type === 'UserTask') { const path = completeTaskInterface.path || ''; apiJson[completeTaskInterface.name] = { url: { path, method: completeTaskInterface.method, }, }; } }); }); } }); return apiJson; } exports.apisToJson = apisToJson; async function generateDataJson(app) { const services = await app.loadServices(); const service = app.firstMicroService; await service.loadStructures(); await service.loadInterfaces(); await service.loadEntities(); return { dataTypes: dataTypesToJson(), enums: enumsToJson(app), apis: apisToJson(app), }; } exports.generateDataJson = generateDataJson; function saveDataTypesCache(app) { const serviceId = app.firstMicroService.id; const path = `dataTypes.json`; const promise = webFile_1.default.saveFile({ body: { serviceId, type: 'cache', path, content: JSON.stringify(dataTypesToJson()), }, }); hotReload_1.saveLastModified(serviceId, path); return promise; } exports.saveDataTypesCache = saveDataTypesCache; async function loadDataTypesCache(serviceId) { const result = await webFile_1.default.loadFile({ query: { serviceId, path: `dataTypes.json`, }, }); return result && JSON.parse(result.content); } exports.loadDataTypesCache = loadDataTypesCache; function saveEnumsCache(app) { const serviceId = app.firstMicroService.id; const path = `enums.json`; const promise = webFile_1.default.saveFile({ body: { serviceId, type: 'cache', path, content: JSON.stringify(enumsToJson(app)), }, }); hotReload_1.saveLastModified(serviceId, path); return promise; } exports.saveEnumsCache = saveEnumsCache; async function loadEnumsCache(serviceId) { const result = await webFile_1.default.loadFile({ query: { serviceId, path: `enums.json`, }, }); return result && JSON.parse(result.content); } exports.loadEnumsCache = loadEnumsCache; function saveApisCache(app) { const serviceId = app.firstMicroService.id; const path = `apis.json`; const promise = webFile_1.default.saveFile({ body: { serviceId, type: 'cache', path, content: JSON.stringify(apisToJson(app)), }, }); hotReload_1.saveLastModified(serviceId, path); return promise; } exports.saveApisCache = saveApisCache; async function loadApisCache(serviceId) { const result = await webFile_1.default.loadFile({ query: { serviceId, path: `apis.json`, }, }); return result && JSON.parse(result.content); } exports.loadApisCache = loadApisCache; function getVertexIdToName() { const res = {}; for (const [id, vertex] of __1.vertexsMap) { res[id] = vertex.name || vertex.value; } return res; } exports.getVertexIdToName = getVertexIdToName; async function saveVertexIdToName(app) { const serviceId = app.firstMicroService.id; const path = `vertexIdToName.json`; // 合并原来的json。原因:如果有页面没有打开,vertexsMap里会没有那些页面的element点 let nameJson = await webFile_1.default.loadFile({ query: { serviceId, path, }, }); nameJson = nameJson && JSON.parse(nameJson.content) || {}; const promise = webFile_1.default.saveFile({ body: { serviceId, type: 'cache', path, content: JSON.stringify(Object.assign(nameJson, getVertexIdToName())), }, }); hotReload_1.saveLastModified(serviceId, path); return promise; } exports.saveVertexIdToName = saveVertexIdToName; async function loadVertexIdToName(app) { const serviceId = app.firstMicroService.id; const result = await webFile_1.default.loadFile({ query: { serviceId, path: `vertexIdToName.json`, }, }); return result && JSON.parse(result.content); } exports.loadVertexIdToName = loadVertexIdToName; //# sourceMappingURL=data.js.map