Implement AXIS parity UI and execution baseline
This commit is contained in:
@@ -25,10 +25,13 @@ function dataHash(data) {
|
||||
}
|
||||
|
||||
export class WorkspaceJournal {
|
||||
constructor(storage = new MemoryStorage(), { projectId = "default", schemaVersion = 1 } = {}) {
|
||||
constructor(storage = new MemoryStorage(), { projectId = "default", schemaVersion = 1, maxRecords = 4096, maxBytes = 64 * 1024 * 1024 } = {}) {
|
||||
if (!Number.isSafeInteger(maxRecords) || maxRecords < 2 || !Number.isSafeInteger(maxBytes) || maxBytes < 1) throw new Error("workspace_journal_quota_invalid");
|
||||
this.storage = storage;
|
||||
this.projectId = projectId;
|
||||
this.schemaVersion = schemaVersion;
|
||||
this.maxRecords = maxRecords;
|
||||
this.maxBytes = maxBytes;
|
||||
}
|
||||
|
||||
records() {
|
||||
@@ -42,6 +45,8 @@ export class WorkspaceJournal {
|
||||
prepare(operationId, changes) {
|
||||
if (typeof operationId !== "string" || operationId.length === 0) throw new Error("operation_id_invalid");
|
||||
if (!Array.isArray(changes) || changes.length === 0) throw new Error("workspace_changes_empty");
|
||||
if (changes.length > 256) throw new Error("workspace_change_capacity");
|
||||
if (this.records().length + 2 > this.maxRecords) throw new Error("workspace_journal_quota");
|
||||
const existing = this.records().find((record) => record.operation_id === operationId && record.kind === "commit");
|
||||
if (existing) throw new Error("operation_already_committed");
|
||||
const normalized = changes.map((change) => {
|
||||
@@ -49,6 +54,8 @@ export class WorkspaceJournal {
|
||||
const data = change.data;
|
||||
return { path, data, data_hash: dataHash(data) };
|
||||
}).sort((left, right) => left.path.localeCompare(right.path));
|
||||
const normalizedBytes = normalized.reduce((total, change) => total + new TextEncoder().encode(change.data).byteLength, 0);
|
||||
if (normalizedBytes > this.maxBytes) throw new Error("workspace_journal_quota");
|
||||
const commitSeq = this.nextSequence();
|
||||
const record = {
|
||||
schema: JOURNAL_SCHEMA,
|
||||
|
||||
Reference in New Issue
Block a user