mvcc-api 1.2.4 → 1.2.5

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 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@7/+esm'
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()
@@ -445,7 +445,17 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
445
445
  break;
446
446
  }
447
447
  }
448
- if (!targetVerObj || !targetVerObj.exists) return null;
448
+ if (!targetVerObj) {
449
+ if (nextVerObj) {
450
+ const cached2 = this.deletedCache.get(key);
451
+ if (cached2) {
452
+ const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
453
+ if (match) return match.value;
454
+ }
455
+ }
456
+ return null;
457
+ }
458
+ if (!targetVerObj.exists) return null;
449
459
  if (!nextVerObj) {
450
460
  return strategy.read(key);
451
461
  }
@@ -1067,7 +1077,17 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
1067
1077
  break;
1068
1078
  }
1069
1079
  }
1070
- if (!targetVerObj || !targetVerObj.exists) return null;
1080
+ if (!targetVerObj) {
1081
+ if (nextVerObj) {
1082
+ const cached2 = this.deletedCache.get(key);
1083
+ if (cached2) {
1084
+ const match = cached2.find((c) => c.deletedAtVersion === nextVerObj.version);
1085
+ if (match) return match.value;
1086
+ }
1087
+ }
1088
+ return null;
1089
+ }
1090
+ if (!targetVerObj.exists) return null;
1071
1091
  if (!nextVerObj) {
1072
1092
  return strategy.read(key);
1073
1093
  }
@@ -416,7 +416,17 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
416
416
  break;
417
417
  }
418
418
  }
419
- if (!targetVerObj || !targetVerObj.exists) return null;
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 || !targetVerObj.exists) return null;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mvcc-api",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Multiversion Concurrency Control (MVCC) API for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",