|
|
@ -1,4 +1,4 @@ |
|
|
|
import type { DebugCmd } from "./debug/debugApi"; |
|
|
|
import type { OperationCmd } from "./globalCmd/globalCmd"; |
|
|
|
|
|
|
|
let _lastTimestamp = 0; |
|
|
|
export function generateTxnNo() { |
|
|
@ -17,27 +17,27 @@ export function generateTxnNo() { |
|
|
|
} |
|
|
|
|
|
|
|
type DebugCmdRecord = { |
|
|
|
category: 'debug'; |
|
|
|
command: DebugCmd; |
|
|
|
params: Record<string, any> |
|
|
|
} |
|
|
|
category: "debug"; |
|
|
|
command: OperationCmd; |
|
|
|
params: Record<string, any>; |
|
|
|
}; |
|
|
|
|
|
|
|
type TxnRecord = DebugCmdRecord // | xxxRecord
|
|
|
|
type TxnRecord = DebugCmdRecord; // | xxxRecord
|
|
|
|
|
|
|
|
const txnCmdMap: Record<string, TxnRecord> = {}; |
|
|
|
|
|
|
|
export function addTxnRecord(val: TxnRecord) { |
|
|
|
const txn = generateTxnNo().toString(); |
|
|
|
txnCmdMap[txn] = val; |
|
|
|
return txn |
|
|
|
return txn; |
|
|
|
} |
|
|
|
|
|
|
|
export function getTxnRecord(txn: string, category: TxnRecord['category']) { |
|
|
|
export function getTxnRecord(txn: string, category: TxnRecord["category"]) { |
|
|
|
const record = txnCmdMap[txn]; |
|
|
|
// 只有属于指定category时,才返回,且返回后删除记录,节约内存
|
|
|
|
if (record.category === category) { |
|
|
|
delete txnCmdMap[txn]; |
|
|
|
return record |
|
|
|
return record; |
|
|
|
} |
|
|
|
return undefined |
|
|
|
return undefined; |
|
|
|
} |