mvcc-api 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/cjs/index.cjs +8 -4
- package/dist/esm/index.mjs +8 -4
- package/dist/types/core/base/Transaction.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,6 +102,22 @@ const result = await tx.commit()
|
|
|
102
102
|
await root.commit() // Persist to storage
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
> [!CAUTION]
|
|
106
|
+
> **Immutability and Reference Types**
|
|
107
|
+
>
|
|
108
|
+
> When using `write(key, value)` with reference types (objects, arrays), you MUST provide a **copy** of the value (Copy-on-Write).
|
|
109
|
+
> Since `mvcc-api` stores the value in an internal buffer, modifying the original object/array after calling `write()` but before `commit()` will affect the data in the transaction.
|
|
110
|
+
>
|
|
111
|
+
> ```typescript
|
|
112
|
+
> // ❌ Wrong: Modifying original object
|
|
113
|
+
> const data = { count: 1 }
|
|
114
|
+
> tx.write('key', data)
|
|
115
|
+
> data.count = 2 // Internal buffer also changes!
|
|
116
|
+
>
|
|
117
|
+
> // ✅ Correct: Pass a copy
|
|
118
|
+
> tx.write('key', { ...data })
|
|
119
|
+
> ```
|
|
120
|
+
|
|
105
121
|
## Visibility Rules
|
|
106
122
|
|
|
107
123
|
```mermaid
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -121,7 +121,11 @@ var MVCCTransaction = class {
|
|
|
121
121
|
this.createdKeys.delete(key);
|
|
122
122
|
this.keyVersions.set(key, this.localVersion);
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Returns the entries that will be created, updated, and deleted by this transaction.
|
|
126
|
+
* @returns An object containing arrays of created, updated, and deleted entries.
|
|
127
|
+
*/
|
|
128
|
+
getResultEntries() {
|
|
125
129
|
const created = [];
|
|
126
130
|
const updated = [];
|
|
127
131
|
for (const [key, data] of this.writeBuffer.entries()) {
|
|
@@ -147,7 +151,7 @@ var MVCCTransaction = class {
|
|
|
147
151
|
* @returns The result object with success, created, updated, and deleted keys.
|
|
148
152
|
*/
|
|
149
153
|
rollback() {
|
|
150
|
-
const { created, updated, deleted } = this.
|
|
154
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
151
155
|
this.writeBuffer.clear();
|
|
152
156
|
this.deleteBuffer.clear();
|
|
153
157
|
this.createdKeys.clear();
|
|
@@ -242,7 +246,7 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
|
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
248
|
commit(label) {
|
|
245
|
-
const { created, updated, deleted } = this.
|
|
249
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
246
250
|
if (this.committed) {
|
|
247
251
|
return {
|
|
248
252
|
label,
|
|
@@ -872,7 +876,7 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
|
872
876
|
}
|
|
873
877
|
}
|
|
874
878
|
async commit(label) {
|
|
875
|
-
const { created, updated, deleted } = this.
|
|
879
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
876
880
|
if (this.committed) {
|
|
877
881
|
return {
|
|
878
882
|
label,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -90,7 +90,11 @@ var MVCCTransaction = class {
|
|
|
90
90
|
this.createdKeys.delete(key);
|
|
91
91
|
this.keyVersions.set(key, this.localVersion);
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Returns the entries that will be created, updated, and deleted by this transaction.
|
|
95
|
+
* @returns An object containing arrays of created, updated, and deleted entries.
|
|
96
|
+
*/
|
|
97
|
+
getResultEntries() {
|
|
94
98
|
const created = [];
|
|
95
99
|
const updated = [];
|
|
96
100
|
for (const [key, data] of this.writeBuffer.entries()) {
|
|
@@ -116,7 +120,7 @@ var MVCCTransaction = class {
|
|
|
116
120
|
* @returns The result object with success, created, updated, and deleted keys.
|
|
117
121
|
*/
|
|
118
122
|
rollback() {
|
|
119
|
-
const { created, updated, deleted } = this.
|
|
123
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
120
124
|
this.writeBuffer.clear();
|
|
121
125
|
this.deleteBuffer.clear();
|
|
122
126
|
this.createdKeys.clear();
|
|
@@ -211,7 +215,7 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
|
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
commit(label) {
|
|
214
|
-
const { created, updated, deleted } = this.
|
|
218
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
215
219
|
if (this.committed) {
|
|
216
220
|
return {
|
|
217
221
|
label,
|
|
@@ -841,7 +845,7 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
|
841
845
|
}
|
|
842
846
|
}
|
|
843
847
|
async commit(label) {
|
|
844
|
-
const { created, updated, deleted } = this.
|
|
848
|
+
const { created, updated, deleted } = this.getResultEntries();
|
|
845
849
|
if (this.committed) {
|
|
846
850
|
return {
|
|
847
851
|
label,
|
|
@@ -66,7 +66,11 @@ export declare abstract class MVCCTransaction<S extends MVCCStrategy<K, T>, K, T
|
|
|
66
66
|
protected _bufferCreate(key: K, value: T): void;
|
|
67
67
|
protected _bufferWrite(key: K, value: T): void;
|
|
68
68
|
protected _bufferDelete(key: K): void;
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Returns the entries that will be created, updated, and deleted by this transaction.
|
|
71
|
+
* @returns An object containing arrays of created, updated, and deleted entries.
|
|
72
|
+
*/
|
|
73
|
+
getResultEntries(): {
|
|
70
74
|
created: TransactionEntry<K, T>[];
|
|
71
75
|
updated: TransactionEntry<K, T>[];
|
|
72
76
|
deleted: TransactionEntry<K, T>[];
|