UNPKG

@lcap/asl

Version:

NetEase Application Specific Language

262 lines 8.5 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityIndex = void 0; const decorators_1 = require("../decorators"); const __1 = require(".."); const data_1 = require("../../service/data"); /** * 实体索引类 */ class EntityIndex extends __1.Vertex { /** * @param source 需要合并的部分参数 */ constructor(source) { super(); /** * 概念类型 */ this.level = __1.LEVEL_ENUM.entityIndex; /** * Id */ this.id = undefined; /** * 名称 */ this.name = undefined; /** * 是否唯一 */ this.unique = undefined; /** * 字段引用 */ this.propertyIds = []; /** * 描述 */ this.description = undefined; /** * 父级 Id */ this.entityId = undefined; /** * 父级引用 */ this.root = undefined; source && this.assign(source); } /** * 添加实体索引 */ async create(none, actionOptions) { __1.config.defaultApp?.emit('saving', true); const body = this.toJSON(); body._posIndex = this.root.indexList.indexOf(this); __1.utils.logger.debug('添加实体索引', body); const result = await data_1.entityService.addIndex({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EntityIndex.create', operationDesc: actionOptions?.actionDesc || `添加实体"${this.root.name}"索引"${this.name}"`, }, body, }); this.deepPick(result, ['id', '_posIndex']); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); return this; } /** * 删除实体索引 */ async delete(none, actionOptions) { __1.config.defaultApp?.emit('saving', true); try { if (this.id) { await data_1.entityService.deleteIndex({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EntityIndex.delete', operationDesc: actionOptions?.actionDesc || `删除实体"${this.root.name}"索引"${this.name}"`, }, query: { id: this.id, }, }); } const index = this.root.indexList.indexOf(this); ~index && this.root.indexList.splice(index, 1); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); } catch (err) { __1.config.defaultApp?.emit('saved'); throw err; } } /** * 修改实体索引 */ async update(none, actionOptions, then) { __1.config.defaultApp?.emit('saving', true); const body = this.toJSON(); __1.utils.logger.debug('修改实体索引', body); try { const result = await data_1.entityService.updateIndex({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EntityIndex.update', operationDesc: actionOptions?.actionDesc || `修改实体"${this.root.name}"索引"${this.name}"`, }, body, }); await then?.(); await __1.config.defaultApp?.history.load(); } catch (err) { } __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.root.name}"的索引"${oldName}"的名称为"${name}"`, }); } /** * 设置实体索引标题 * @param label 标题 */ async setPropertyIds(propertyIds) { this.assign({ propertyIds }); await this.update(undefined, { actionDesc: `设置实体"${this.root.name}"的索引"${this.name}"的字段`, }); } /** * 设置实体索引描述 * @param description 描述 */ async setUnique(unique) { this.assign({ unique }); await this.update(undefined, { actionDesc: `设置实体"${this.root.name}"的索引"${this.name}"的唯一性为"${unique}"`, }); } /** * 设置实体索引描述 * @param description 描述 */ async setDescription(description) { this.assign({ description }); await this.update(undefined, { actionDesc: `设置实体"${this.root.name}"的索引"${this.name}"的描述为"${description}"`, }); } /** * 移动位置 * @param index 目标位置 */ async moveTo(index, oldIndex) { const indexList = this.root.indexList; if (oldIndex === undefined) oldIndex = indexList.indexOf(this); indexList.splice(oldIndex, 1); indexList.splice(index, 0, this); await data_1.entityService.moveIndex({ headers: { appId: __1.config.defaultApp?.id, operationAction: null, operationDesc: null, }, query: { id: this.id, targetIndex: index, }, }); } /** * 上移实体索引 */ moveUp() { const indexList = this.root.indexList; const oldIndex = indexList.indexOf(this); if (oldIndex === 0) return; return this.moveTo(oldIndex - 1, oldIndex); } /** * 索引下移 */ moveDown() { const indexList = this.root.indexList; const oldIndex = indexList.indexOf(this); if (oldIndex === indexList.length - 1) return; return this.moveTo(oldIndex + 1, oldIndex); } } __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "level", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "id", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "name", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "unique", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "propertyIds", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "description", void 0); __decorate([ decorators_1.immutable() ], EntityIndex.prototype, "entityId", void 0); __decorate([ decorators_1.circular(), decorators_1.immutable() ], EntityIndex.prototype, "root", void 0); __decorate([ decorators_1.action('添加实体索引') ], EntityIndex.prototype, "create", null); __decorate([ decorators_1.action('删除实体索引') ], EntityIndex.prototype, "delete", null); __decorate([ decorators_1.action('设置实体索引名称') ], EntityIndex.prototype, "setName", null); __decorate([ decorators_1.action('设置实体索引字段') ], EntityIndex.prototype, "setPropertyIds", null); __decorate([ decorators_1.action('设置实体索引描述') ], EntityIndex.prototype, "setUnique", null); __decorate([ decorators_1.action('设置实体索引描述') ], EntityIndex.prototype, "setDescription", null); __decorate([ decorators_1.action('上移实体索引') ], EntityIndex.prototype, "moveUp", null); __decorate([ decorators_1.action('下移实体索引') ], EntityIndex.prototype, "moveDown", null); exports.EntityIndex = EntityIndex; //# sourceMappingURL=EntityIndex.js.map