UNPKG

@aitianyu.cn/tianyu-store

Version:
79 lines 3.69 kB
"use strict"; /** @format */ Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyActionInstances = exports.verifyInstanceIdMatchStoreTypeOrParentStoreType = exports.verifyInstanceSameAncestor = exports.getStoreTypeMatchedInstanceId = void 0; const InstanceIdImpl_1 = require("../impl/InstanceIdImpl"); const Message_1 = require("../../infra/Message"); const Defs_1 = require("../../types/Defs"); const Action_1 = require("../../types/Action"); function getStoreTypeMatchedInstanceId(storeType, instanceId) { if (instanceId.storeType === storeType) { return instanceId; } const instancePair = instanceId.structure(); let index = instancePair.length - 1; for (; index >= 0; --index) { if (instancePair[index].storeType === storeType) { break; } } if (index < 0) { throw new Error(Message_1.MessageBundle.getText("RUNNING_STORE_TYPE_INSTANCE_NOT_MATCH", storeType, instanceId.toString())); } return new InstanceIdImpl_1.InstanceIdImpl(instancePair.slice(0, index + 1)); } exports.getStoreTypeMatchedInstanceId = getStoreTypeMatchedInstanceId; function verifyInstanceSameAncestor(...s) { if (s.length === 0) { return ""; } const first = s[0]; let other = s[0]; const differentAncestor = s.some((value) => { other = value; return first.entity !== value.entity; }); if (differentAncestor) { // to throw error when the two instance belongs to different ancestor throw new Error(Message_1.MessageBundle.getText("DISPATCHING_ACTIONS_DIFFERENT_ANCESTOR", first.entity, other.entity)); } return first.entity; } exports.verifyInstanceSameAncestor = verifyInstanceSameAncestor; function verifyInstanceIdMatchStoreTypeOrParentStoreType(storeType, instanceId) { if (!instanceId.isValid()) { return false; } let instance = instanceId; while (!InstanceIdImpl_1.InstanceIdImpl.isAncestor(instance)) { if (instance.storeType === storeType) { return true; } instance = instance.parent; } return storeType === Defs_1.TIANYU_STORE_INSTANCE_BASE_ENTITY_STORE_TYPE; } exports.verifyInstanceIdMatchStoreTypeOrParentStoreType = verifyInstanceIdMatchStoreTypeOrParentStoreType; function verifyActionInstances(s) { const actionCount = s.length; const instanceIds = s.map((value) => { if (!value.instanceId.isValid()) { // throw an error when redo undo operation is not atom throw new Error(Message_1.MessageBundle.getText("DISPATCHING_INSTANCE_ID_NOT_VALID", value.action, value.instanceId.toString())); } if (actionCount > 1 && (value.actionType === Action_1.ActionType.REDO || value.actionType === Action_1.ActionType.UNDO)) { // throw an error when redo undo operation is not atom throw new Error(Message_1.MessageBundle.getText("DISPATCHING_REDO_UNDO_NOT_ATOM", value.action)); } if (actionCount > 1 && InstanceIdImpl_1.InstanceIdImpl.isAncestor(value.instanceId) && (value.actionType === Action_1.ActionType.CREATE || value.actionType === Action_1.ActionType.DESTROY)) { // throw an error when create or destroy an entity is not atom throw new Error(Message_1.MessageBundle.getText("DISPATCHING_SYSTEM_LIFECYCLE_NOT_ATOM", value.action)); } return value.instanceId; }); return verifyInstanceSameAncestor(...instanceIds); } exports.verifyActionInstances = verifyActionInstances; //# sourceMappingURL=InstanceProcessor.js.map