serializable-bptree 8.0.0 → 8.0.2

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.
@@ -180,7 +180,11 @@ var MVCCTransaction = class {
180
180
  this.createdKeys.delete(key);
181
181
  this.keyVersions.set(key, this.localVersion);
182
182
  }
183
- _getResultEntries() {
183
+ /**
184
+ * Returns the entries that will be created, updated, and deleted by this transaction.
185
+ * @returns An object containing arrays of created, updated, and deleted entries.
186
+ */
187
+ getResultEntries() {
184
188
  const created = [];
185
189
  const updated = [];
186
190
  for (const [key, data] of this.writeBuffer.entries()) {
@@ -206,7 +210,7 @@ var MVCCTransaction = class {
206
210
  * @returns The result object with success, created, updated, and deleted keys.
207
211
  */
208
212
  rollback() {
209
- const { created, updated, deleted } = this._getResultEntries();
213
+ const { created, updated, deleted } = this.getResultEntries();
210
214
  this.writeBuffer.clear();
211
215
  this.deleteBuffer.clear();
212
216
  this.createdKeys.clear();
@@ -297,7 +301,7 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
297
301
  }
298
302
  }
299
303
  commit(label) {
300
- const { created, updated, deleted } = this._getResultEntries();
304
+ const { created, updated, deleted } = this.getResultEntries();
301
305
  if (this.committed) {
302
306
  return {
303
307
  label,
@@ -921,7 +925,7 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
921
925
  }
922
926
  }
923
927
  async commit(label) {
924
- const { created, updated, deleted } = this._getResultEntries();
928
+ const { created, updated, deleted } = this.getResultEntries();
925
929
  if (this.committed) {
926
930
  return {
927
931
  label,
@@ -1773,6 +1777,13 @@ var BPTreeTransaction = class _BPTreeTransaction {
1773
1777
  const i = v.length - 1;
1774
1778
  return [...v].sort((a, b) => this.comparator.primaryAsc(a, b))[i];
1775
1779
  }
1780
+ /**
1781
+ * Returns the result entries of the transaction.
1782
+ * @returns Returns the node entries that will be created, updated, and deleted by this transaction.
1783
+ */
1784
+ getResultEntries() {
1785
+ return this.mvcc.getResultEntries();
1786
+ }
1776
1787
  /**
1777
1788
  * Clears all cached nodes.
1778
1789
  * This method is useful for freeing up memory when the tree is no longer needed.
@@ -1820,7 +1831,7 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
1820
1831
  return node;
1821
1832
  }
1822
1833
  _updateNode(node) {
1823
- this.mvcc.write(node.id, JSON.parse(JSON.stringify(node)));
1834
+ this.mvcc.write(node.id, node);
1824
1835
  this.nodes.set(node.id, node);
1825
1836
  }
1826
1837
  _deleteNode(node) {
@@ -2655,7 +2666,7 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
2655
2666
  return node;
2656
2667
  }
2657
2668
  async _updateNode(node) {
2658
- await this.mvcc.write(node.id, JSON.parse(JSON.stringify(node)));
2669
+ await this.mvcc.write(node.id, node);
2659
2670
  this.nodes.set(node.id, node);
2660
2671
  }
2661
2672
  async _deleteNode(node) {
@@ -144,7 +144,11 @@ var MVCCTransaction = class {
144
144
  this.createdKeys.delete(key);
145
145
  this.keyVersions.set(key, this.localVersion);
146
146
  }
147
- _getResultEntries() {
147
+ /**
148
+ * Returns the entries that will be created, updated, and deleted by this transaction.
149
+ * @returns An object containing arrays of created, updated, and deleted entries.
150
+ */
151
+ getResultEntries() {
148
152
  const created = [];
149
153
  const updated = [];
150
154
  for (const [key, data] of this.writeBuffer.entries()) {
@@ -170,7 +174,7 @@ var MVCCTransaction = class {
170
174
  * @returns The result object with success, created, updated, and deleted keys.
171
175
  */
172
176
  rollback() {
173
- const { created, updated, deleted } = this._getResultEntries();
177
+ const { created, updated, deleted } = this.getResultEntries();
174
178
  this.writeBuffer.clear();
175
179
  this.deleteBuffer.clear();
176
180
  this.createdKeys.clear();
@@ -261,7 +265,7 @@ var SyncMVCCTransaction = class _SyncMVCCTransaction extends MVCCTransaction {
261
265
  }
262
266
  }
263
267
  commit(label) {
264
- const { created, updated, deleted } = this._getResultEntries();
268
+ const { created, updated, deleted } = this.getResultEntries();
265
269
  if (this.committed) {
266
270
  return {
267
271
  label,
@@ -885,7 +889,7 @@ var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
885
889
  }
886
890
  }
887
891
  async commit(label) {
888
- const { created, updated, deleted } = this._getResultEntries();
892
+ const { created, updated, deleted } = this.getResultEntries();
889
893
  if (this.committed) {
890
894
  return {
891
895
  label,
@@ -1737,6 +1741,13 @@ var BPTreeTransaction = class _BPTreeTransaction {
1737
1741
  const i = v.length - 1;
1738
1742
  return [...v].sort((a, b) => this.comparator.primaryAsc(a, b))[i];
1739
1743
  }
1744
+ /**
1745
+ * Returns the result entries of the transaction.
1746
+ * @returns Returns the node entries that will be created, updated, and deleted by this transaction.
1747
+ */
1748
+ getResultEntries() {
1749
+ return this.mvcc.getResultEntries();
1750
+ }
1740
1751
  /**
1741
1752
  * Clears all cached nodes.
1742
1753
  * This method is useful for freeing up memory when the tree is no longer needed.
@@ -1784,7 +1795,7 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
1784
1795
  return node;
1785
1796
  }
1786
1797
  _updateNode(node) {
1787
- this.mvcc.write(node.id, JSON.parse(JSON.stringify(node)));
1798
+ this.mvcc.write(node.id, node);
1788
1799
  this.nodes.set(node.id, node);
1789
1800
  }
1790
1801
  _deleteNode(node) {
@@ -2619,7 +2630,7 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
2619
2630
  return node;
2620
2631
  }
2621
2632
  async _updateNode(node) {
2622
- await this.mvcc.write(node.id, JSON.parse(JSON.stringify(node)));
2633
+ await this.mvcc.write(node.id, node);
2623
2634
  this.nodes.set(node.id, node);
2624
2635
  }
2625
2636
  async _deleteNode(node) {
@@ -1,6 +1,6 @@
1
+ import type { TransactionEntry, TransactionResult } from 'mvcc-api';
1
2
  import type { BPTreeCondition, BPTreeConstructorOption, BPTreeUnknownNode, Deferred, BPTreeLeafNode, BPTreeNodeKey, BPTreePair, SerializableData, BPTreeNode, BPTreeMVCC } from '../types';
2
3
  import { LRUMap } from 'cache-entanglement';
3
- import { TransactionResult } from 'mvcc-api';
4
4
  import { ValueComparator } from './ValueComparator';
5
5
  import { SerializeStrategy } from './SerializeStrategy';
6
6
  export declare abstract class BPTreeTransaction<K, V> {
@@ -160,6 +160,15 @@ export declare abstract class BPTreeTransaction<K, V> {
160
160
  protected highestValue(v: V[]): V;
161
161
  protected lowestPrimaryValue(v: V[]): V;
162
162
  protected highestPrimaryValue(v: V[]): V;
163
+ /**
164
+ * Returns the result entries of the transaction.
165
+ * @returns Returns the node entries that will be created, updated, and deleted by this transaction.
166
+ */
167
+ getResultEntries(): {
168
+ created: TransactionEntry<string, BPTreeNode<K, V>>[];
169
+ updated: TransactionEntry<string, BPTreeNode<K, V>>[];
170
+ deleted: TransactionEntry<string, BPTreeNode<K, V>>[];
171
+ };
163
172
  /**
164
173
  * Clears all cached nodes.
165
174
  * This method is useful for freeing up memory when the tree is no longer needed.
@@ -1,5 +1,5 @@
1
+ import type { TransactionResult } from 'mvcc-api';
1
2
  import type { AsyncBPTreeMVCC, BPTreeCondition, BPTreeConstructorOption, BPTreeLeafNode, BPTreeNode, BPTreeNodeKey, BPTreePair, BPTreeUnknownNode, SerializableData, SerializeStrategyHead } from '../types';
2
- import { TransactionResult } from 'mvcc-api';
3
3
  import { BPTreeTransaction } from '../base/BPTreeTransaction';
4
4
  import { SerializeStrategyAsync } from '../SerializeStrategyAsync';
5
5
  import { ValueComparator } from '../base/ValueComparator';
@@ -1,5 +1,5 @@
1
+ import type { TransactionResult } from 'mvcc-api';
1
2
  import type { BPTreeCondition, BPTreeConstructorOption, BPTreeLeafNode, BPTreeNode, BPTreeNodeKey, BPTreePair, BPTreeUnknownNode, SerializableData, SerializeStrategyHead, SyncBPTreeMVCC } from '../types';
2
- import { TransactionResult } from 'mvcc-api';
3
3
  import { BPTreeTransaction } from '../base/BPTreeTransaction';
4
4
  import { SerializeStrategySync } from '../SerializeStrategySync';
5
5
  import { ValueComparator } from '../base/ValueComparator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "cache-entanglement": "^1.7.1",
47
- "mvcc-api": "^1.2.8",
47
+ "mvcc-api": "^1.2.9",
48
48
  "ryoiki": "^1.2.0"
49
49
  }
50
50
  }