@aitianyu.cn/tianyu-store
Version:
tianyu storage for nodejs.
84 lines • 2.61 kB
JavaScript
;
/** @format */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionImpl = exports.formatTransactionType = void 0;
const types_1 = require("@aitianyu.cn/types");
const Message_1 = require("../../infra/Message");
const Transaction_1 = require("../../types/Transaction");
function formatTransactionType(type) {
switch (type) {
case Transaction_1.TransactionType.Action:
return "Action";
case Transaction_1.TransactionType.Selector:
return "Selector";
case Transaction_1.TransactionType.Listener:
return "Listener";
case Transaction_1.TransactionType.Subscribe:
return "Subscribe";
}
}
exports.formatTransactionType = formatTransactionType;
class TransactionImpl {
storeId;
dispatchedActions;
selections;
errors;
constructor(storeId) {
this.storeId = storeId;
this.dispatchedActions = [];
this.selections = [];
this.errors = [];
}
getDispatched() {
return this.dispatchedActions.concat();
}
cleanDispatch() {
this.dispatchedActions = [];
}
getSelections() {
return this.selections.concat();
}
cleanSelector() {
this.selections = [];
}
getErrors() {
return this.errors.concat();
}
cleanError() {
this.errors = [];
}
dispatched(actions) {
const actionRec = {
id: (0, types_1.guid)(),
time: new Date(Date.now()),
operations: actions,
};
this.dispatchedActions.push(actionRec);
return actionRec;
}
selected(selector) {
const selectorRec = {
id: (0, types_1.guid)(),
time: new Date(Date.now()),
operations: [selector],
};
this.selections.push(selectorRec);
return selectorRec;
}
error(message, type) {
const errorRecord = {
message: typeof message === "string"
? message
: message instanceof Error
? message.message
: Message_1.MessageBundle.getText("TRANSACTION_ERROR_RECORDING_UNKNOWN_ERROR", formatTransactionType(type)),
type,
time: new Date(Date.now()),
};
types_1.Log.error(errorRecord.message, true);
this.errors.push(errorRecord);
return errorRecord;
}
}
exports.TransactionImpl = TransactionImpl;
//# sourceMappingURL=Transaction.js.map