UNPKG

@lcap/asl

Version:

NetEase Application Specific Language

259 lines 9.55 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProcessParam = void 0; const decorators_1 = require("../decorators"); const __1 = require(".."); const dataTypeUtils_1 = require("../data/dataTypeUtils"); const basicTypes_1 = require("../data/basicTypes"); const common_1 = require("../../service/common"); const process_1 = __importDefault(require("../../service/process")); /** * 流程输入参数 */ class ProcessParam extends __1.Param { /** * @param source 需要合并的部分参数 */ constructor(source) { super(); /** * 概念类型 */ this.level = __1.LEVEL_ENUM.processParam; /** * 流程 Id */ this.parentId = undefined; /** * 视图 */ this.process = undefined; /** * 默认值 * 按 JSON string 处理 * - string: 666 -> '666' * - string: true -> 'true' * - number: 666 -> 666 * - boolean: true -> true */ this.defaultValue = undefined; source && this.assign(source); } genCode() { return `ID_${this.process.id}.ID_${this.id}`; } /** * 添加流程输入参数 */ async create(none, actionOptions) { __1.config.defaultApp?.emit('saving'); this.assign({ loading: true, editing: false }); const body = this.toJSON(); const result = await process_1.default.addProcessVal({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'ProcessParam.create', operationDesc: actionOptions?.actionDesc || `添加流程"${this.process.name}"输入参数"${this.name}"`, }, body, }); this.assign(ProcessParam.from(result, this.process)); this.updateInterface(); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); return this; } /** * 删除流程输入参数 */ async delete(none, actionOptions) { if (this.id) { __1.config.defaultApp?.emit('saving'); const body = this.toJSON(); await process_1.default.deleteProcessVal({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'ProcessParam.delete', operationDesc: actionOptions?.actionDesc || `删除流程"${this.process.name}"输入参数"${this.name}"`, }, body, }); const index = this.process.params.indexOf(this); ~index && this.process.params.splice(index, 1); this.destroy(); this.updateInterface(); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); } } /** * 修改流程输入参数 */ async update(none, actionOptions, then) { __1.config.defaultApp?.emit('saving'); const body = this.toJSON(); const result = await process_1.default.updateProcessVal({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'ProcessParam.update', operationDesc: actionOptions?.actionDesc || `修改流程"${this.process.name}"输入参数"${this.name}"`, }, body, }); this.assign(ProcessParam.from(result, this.process)); this.updateInterface(); await then?.(); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); return this; } /** * 设置流程输入参数名称 * @param name 名称 */ async setName(name) { const oldName = this.name; this.assign({ name }); await this.update(undefined, { actionDesc: `设置流程"${this.process.name}"的输入参数"${oldName}"的名称为"${name}"`, }); } /** * 设置流程输入参数描述 * @param description 描述 */ async setDescription(description) { this.assign({ description }); await this.update(undefined, { actionDesc: `设置流程"${this.process.name}"的输入参数"${this.name}"的描述为"${description}"`, }); } /** * 设置流程输入参数的数据类型 * @param $ref 数据类型 */ async setDataType(schema) { // 用于update失败后还原数据 const originalData = { schema: Object.assign({}, this.schema), defaultValue: this.defaultValue, }; Object.assign(this.schema, { $ref: undefined, type: undefined, format: undefined, typeInstantiation: undefined, }); Object.assign(this.schema, schema); this.assign({ defaultValue: basicTypes_1.getBasicTypeDefaultValue() }); try { await this.update(undefined, { actionDesc: `设置流程"${this.process.name}"的输入参数"${this.name}"的数据类型为"${this.schema.typeKey}"`, }); this.genSchemaChildren(); this.process.checkType(); } catch (err) { this.assign(originalData); __1.config.defaultApp?.emit('saved'); throw err; } } /** * 设置流程输入参数的默认值 * @param defaultValue 默认值 */ async setDefaultValue(defaultValue) { this.assign({ defaultValue }); await this.update(undefined, { actionDesc: `设置流程"${this.process.name}"的输入参数"${this.name}"的默认值为"${defaultValue}"`, }); } /** * 查找schema 顶点被引用的流程输入参数顶点列表 */ async getSchemaUsage() { if (this.schema) { const schemaId = this.schema.type === 'genericType' ? this.id : this.schema.id; const result = await common_1.schemaService.getSchemaUsage({ query: { schemaId, valSource: 'process_param', }, }); return result; } } /** * 流程接口会自动根据输入输出参数变更,更新流程接口的输入输出 */ async updateInterface() { const { launchProcessInterface } = this.process; if (launchProcessInterface) { const ifce = await process_1.default.getInterface({ path: { id: launchProcessInterface.id } }); const { logic } = launchProcessInterface; const oldParams = logic?.params || []; const newParams = (ifce?.logic?.params || []).map((param) => { const existParam = oldParams.find((oldParam) => oldParam.id === param.id); if (existParam) { existParam.assign(__1.Param.from(param, logic)); return existParam; } return __1.Param.from(param, logic); }); logic.assign({ params: newParams }); } } /** * 从后端 JSON 生成规范的 ProcessParam 对象 */ static from(source, process) { dataTypeUtils_1.convert2RefType(source.schema); source.process = process; source.code = `ID_${process.id}.ID_${source.id}`; source.parentId = process.id; const processParam = new ProcessParam(source); processParam.genSchemaChildren(); return processParam; } } __decorate([ decorators_1.immutable() ], ProcessParam.prototype, "level", void 0); __decorate([ decorators_1.immutable() ], ProcessParam.prototype, "parentId", void 0); __decorate([ decorators_1.excludedInJSON(), decorators_1.immutable() ], ProcessParam.prototype, "process", void 0); __decorate([ decorators_1.action('添加流程输入参数') ], ProcessParam.prototype, "create", null); __decorate([ decorators_1.action('删除流程输入参数') ], ProcessParam.prototype, "delete", null); __decorate([ decorators_1.action('设置流程输入参数名称') ], ProcessParam.prototype, "setName", null); __decorate([ decorators_1.action('设置流程输入参数描述') ], ProcessParam.prototype, "setDescription", null); __decorate([ decorators_1.action('设置流程输入参数的数据类型') ], ProcessParam.prototype, "setDataType", null); __decorate([ decorators_1.action('设置流程输入参数的默认值') ], ProcessParam.prototype, "setDefaultValue", null); exports.ProcessParam = ProcessParam; exports.default = ProcessParam; //# sourceMappingURL=ProcessParam.js.map