mvcc-api 1.2.4 → 1.2.6
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 +12 -10
- package/dist/cjs/index.cjs +24 -2
- package/dist/esm/index.mjs +24 -2
- package/dist/types/index.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ It easily and powerfully solves complex concurrency problems that are difficult
|
|
|
34
34
|
* Business logic and storage logic can be perfectly separated.
|
|
35
35
|
|
|
36
36
|
4. **Improved Development Productivity**
|
|
37
|
-
* No need to write complex synchronization code yourself; write safe code with just intuitive `api.read()`, `api.write()`, and `commit()`.
|
|
37
|
+
* No need to write complex synchronization code yourself; write safe code with just intuitive `api.read()`, `api.write()`, and `api.commit()`.
|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
SyncMVCCTransaction,
|
|
55
55
|
AsyncMVCCStrategy,
|
|
56
56
|
AsyncMVCCTransaction
|
|
57
|
-
} from 'https://cdn.jsdelivr.net/npm/mvcc-api@
|
|
57
|
+
} from 'https://cdn.jsdelivr.net/npm/mvcc-api@1/+esm'
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## Usage
|
|
@@ -136,8 +136,9 @@ const child = parent.createNested()
|
|
|
136
136
|
parent.write('shared', 'parent') // Parent modifies after child creation
|
|
137
137
|
child.write('shared', 'child') // Child modifies same key
|
|
138
138
|
|
|
139
|
-
const result = child.commit()
|
|
139
|
+
const result = child.commit('It should fail')
|
|
140
140
|
if (!result.success) {
|
|
141
|
+
console.log(result.label) // "It should fail"
|
|
141
142
|
console.log(result.error) // "Commit conflict: Key 'shared' was modified..."
|
|
142
143
|
}
|
|
143
144
|
```
|
|
@@ -189,13 +190,13 @@ const bResult = b.commit()
|
|
|
189
190
|
|
|
190
191
|
| Method | Description | Return Value |
|
|
191
192
|
| :--- | :--- | :--- |
|
|
192
|
-
| `create(key, value)` | Create new key-value | `this` |
|
|
193
|
-
| `write(key, value)` | Update existing key | `this` |
|
|
194
|
-
| `delete(key)` | Delete key | `this` |
|
|
195
|
-
| `read(key)` | Read value | `T \| null` |
|
|
196
|
-
| `exists(key)` | Check if key exists | `boolean` |
|
|
197
|
-
| `commit()` | Apply changes | `TransactionResult<K, T>` |
|
|
198
|
-
| `rollback()` | Discard changes | `TransactionResult<K, T>` |
|
|
193
|
+
| `create(key: K, value: T)` | Create new key-value | `this` |
|
|
194
|
+
| `write(key: K, value: T)` | Update existing key | `this` |
|
|
195
|
+
| `delete(key: K)` | Delete key | `this` |
|
|
196
|
+
| `read(key: K)` | Read value | `T \| null` |
|
|
197
|
+
| `exists(key: K)` | Check if key exists | `boolean` |
|
|
198
|
+
| `commit(label?: string)` | Apply changes | `TransactionResult<K, T>` |
|
|
199
|
+
| `rollback(label?: string)` | Discard changes | `TransactionResult<K, T>` |
|
|
199
200
|
| `createNested()` | Create child transaction | `MVCCTransaction` |
|
|
200
201
|
|
|
201
202
|
### `TransactionResult<K, T>`
|
|
@@ -206,6 +207,7 @@ type TransactionConflict<K, T> = { key: K, parent: T, child: T }
|
|
|
206
207
|
|
|
207
208
|
{
|
|
208
209
|
success: boolean // Success status
|
|
210
|
+
label?: string // Label of the transaction
|
|
209
211
|
error?: string // Error message on failure (e.g. conflict)
|
|
210
212
|
conflict?: TransactionConflict<K, T> // Conflict information on failure
|
|
211
213
|
created: TransactionEntry[] // Keys and values created via create()
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
AsyncMVCCStrategy: () => AsyncMVCCStrategy,
|
|
24
24
|
AsyncMVCCTransaction: () => AsyncMVCCTransaction,
|
|
25
|
+
MVCCStrategy: () => MVCCStrategy,
|
|
26
|
+
MVCCTransaction: () => MVCCTransaction,
|
|
25
27
|
SyncMVCCStrategy: () => SyncMVCCStrategy,
|
|
26
28
|
SyncMVCCTransaction: () => SyncMVCCTransaction
|
|
27
29
|
});
|
|
@@ -445,7 +447,17 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
|
|
|
445
447
|
break;
|
|
446
448
|
}
|
|
447
449
|
}
|
|
448
|
-
if (!targetVerObj
|
|
450
|
+
if (!targetVerObj) {
|
|
451
|
+
if (nextVerObj) {
|
|
452
|
+
const cached2 = this.deletedCache.get(key);
|
|
453
|
+
if (cached2) {
|
|
454
|
+
const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
|
|
455
|
+
if (match) return match.value;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
if (!targetVerObj.exists) return null;
|
|
449
461
|
if (!nextVerObj) {
|
|
450
462
|
return strategy.read(key);
|
|
451
463
|
}
|
|
@@ -1067,7 +1079,17 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
|
1067
1079
|
break;
|
|
1068
1080
|
}
|
|
1069
1081
|
}
|
|
1070
|
-
if (!targetVerObj
|
|
1082
|
+
if (!targetVerObj) {
|
|
1083
|
+
if (nextVerObj) {
|
|
1084
|
+
const cached2 = this.deletedCache.get(key);
|
|
1085
|
+
if (cached2) {
|
|
1086
|
+
const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
|
|
1087
|
+
if (match) return match.value;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return null;
|
|
1091
|
+
}
|
|
1092
|
+
if (!targetVerObj.exists) return null;
|
|
1071
1093
|
if (!nextVerObj) {
|
|
1072
1094
|
return strategy.read(key);
|
|
1073
1095
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -416,7 +416,17 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
|
|
|
416
416
|
break;
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
if (!targetVerObj
|
|
419
|
+
if (!targetVerObj) {
|
|
420
|
+
if (nextVerObj) {
|
|
421
|
+
const cached2 = this.deletedCache.get(key);
|
|
422
|
+
if (cached2) {
|
|
423
|
+
const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
|
|
424
|
+
if (match) return match.value;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
if (!targetVerObj.exists) return null;
|
|
420
430
|
if (!nextVerObj) {
|
|
421
431
|
return strategy.read(key);
|
|
422
432
|
}
|
|
@@ -1038,7 +1048,17 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
|
1038
1048
|
break;
|
|
1039
1049
|
}
|
|
1040
1050
|
}
|
|
1041
|
-
if (!targetVerObj
|
|
1051
|
+
if (!targetVerObj) {
|
|
1052
|
+
if (nextVerObj) {
|
|
1053
|
+
const cached2 = this.deletedCache.get(key);
|
|
1054
|
+
if (cached2) {
|
|
1055
|
+
const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
|
|
1056
|
+
if (match) return match.value;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return null;
|
|
1060
|
+
}
|
|
1061
|
+
if (!targetVerObj.exists) return null;
|
|
1042
1062
|
if (!nextVerObj) {
|
|
1043
1063
|
return strategy.read(key);
|
|
1044
1064
|
}
|
|
@@ -1105,6 +1125,8 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
|
1105
1125
|
export {
|
|
1106
1126
|
AsyncMVCCStrategy,
|
|
1107
1127
|
AsyncMVCCTransaction,
|
|
1128
|
+
MVCCStrategy,
|
|
1129
|
+
MVCCTransaction,
|
|
1108
1130
|
SyncMVCCStrategy,
|
|
1109
1131
|
SyncMVCCTransaction
|
|
1110
1132
|
};
|
package/dist/types/index.d.ts
CHANGED