serializable-bptree 7.0.1 → 7.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.
@@ -1858,12 +1858,21 @@ var BPTreeSyncTransaction = class extends BPTreeSyncBase {
1858
1858
  }
1859
1859
  /**
1860
1860
  * Rolls back the transaction by clearing all buffered changes.
1861
- * Internal use only.
1861
+ * If cleanup is `true`, it also clears the transaction nodes.
1862
+ * @param cleanup Whether to clear the transaction nodes.
1863
+ * @returns The IDs of nodes that were created in this transaction.
1862
1864
  */
1863
- rollback() {
1865
+ rollback(cleanup = true) {
1866
+ const createdIds = Array.from(this.createdInTx);
1864
1867
  this.txNodes.clear();
1865
1868
  this.dirtyIds.clear();
1866
1869
  this.createdInTx.clear();
1870
+ if (cleanup) {
1871
+ for (const id of createdIds) {
1872
+ this.realBaseStrategy.delete(id);
1873
+ }
1874
+ }
1875
+ return createdIds;
1867
1876
  }
1868
1877
  // Override to do nothing, as transaction handles its own commits
1869
1878
  commitHeadBuffer() {
@@ -2993,12 +3002,21 @@ var BPTreeAsyncTransaction = class extends BPTreeAsyncBase {
2993
3002
  }
2994
3003
  /**
2995
3004
  * Rolls back the transaction by clearing all buffered changes.
2996
- * Internal use only.
3005
+ * If cleanup is `true`, it also clears the transaction nodes.
3006
+ * @param cleanup Whether to clear the transaction nodes.
3007
+ * @returns The IDs of nodes that were created in this transaction.
2997
3008
  */
2998
- async rollback() {
3009
+ async rollback(cleanup = true) {
3010
+ const createdIds = Array.from(this.createdInTx);
2999
3011
  this.txNodes.clear();
3000
3012
  this.dirtyIds.clear();
3001
3013
  this.createdInTx.clear();
3014
+ if (cleanup) {
3015
+ for (const id of createdIds) {
3016
+ await this.realBaseStrategy.delete(id);
3017
+ }
3018
+ }
3019
+ return createdIds;
3002
3020
  }
3003
3021
  async readLock(fn) {
3004
3022
  return await fn();
@@ -1822,12 +1822,21 @@ var BPTreeSyncTransaction = class extends BPTreeSyncBase {
1822
1822
  }
1823
1823
  /**
1824
1824
  * Rolls back the transaction by clearing all buffered changes.
1825
- * Internal use only.
1825
+ * If cleanup is `true`, it also clears the transaction nodes.
1826
+ * @param cleanup Whether to clear the transaction nodes.
1827
+ * @returns The IDs of nodes that were created in this transaction.
1826
1828
  */
1827
- rollback() {
1829
+ rollback(cleanup = true) {
1830
+ const createdIds = Array.from(this.createdInTx);
1828
1831
  this.txNodes.clear();
1829
1832
  this.dirtyIds.clear();
1830
1833
  this.createdInTx.clear();
1834
+ if (cleanup) {
1835
+ for (const id of createdIds) {
1836
+ this.realBaseStrategy.delete(id);
1837
+ }
1838
+ }
1839
+ return createdIds;
1831
1840
  }
1832
1841
  // Override to do nothing, as transaction handles its own commits
1833
1842
  commitHeadBuffer() {
@@ -2957,12 +2966,21 @@ var BPTreeAsyncTransaction = class extends BPTreeAsyncBase {
2957
2966
  }
2958
2967
  /**
2959
2968
  * Rolls back the transaction by clearing all buffered changes.
2960
- * Internal use only.
2969
+ * If cleanup is `true`, it also clears the transaction nodes.
2970
+ * @param cleanup Whether to clear the transaction nodes.
2971
+ * @returns The IDs of nodes that were created in this transaction.
2961
2972
  */
2962
- async rollback() {
2973
+ async rollback(cleanup = true) {
2974
+ const createdIds = Array.from(this.createdInTx);
2963
2975
  this.txNodes.clear();
2964
2976
  this.dirtyIds.clear();
2965
2977
  this.createdInTx.clear();
2978
+ if (cleanup) {
2979
+ for (const id of createdIds) {
2980
+ await this.realBaseStrategy.delete(id);
2981
+ }
2982
+ }
2983
+ return createdIds;
2966
2984
  }
2967
2985
  async readLock(fn) {
2968
2986
  return await fn();
@@ -33,9 +33,11 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeAsyncBase<K, V>
33
33
  commit(): Promise<BPTreeTransactionResult>;
34
34
  /**
35
35
  * Rolls back the transaction by clearing all buffered changes.
36
- * Internal use only.
36
+ * If cleanup is `true`, it also clears the transaction nodes.
37
+ * @param cleanup Whether to clear the transaction nodes.
38
+ * @returns The IDs of nodes that were created in this transaction.
37
39
  */
38
- protected rollback(): Promise<void>;
40
+ rollback(cleanup?: boolean): Promise<string[]>;
39
41
  protected readLock<T>(fn: () => Promise<T>): Promise<T>;
40
42
  protected writeLock<T>(fn: () => Promise<T>): Promise<T>;
41
43
  protected commitHeadBuffer(): Promise<void>;
@@ -33,9 +33,11 @@ export declare class BPTreeSyncTransaction<K, V> extends BPTreeSyncBase<K, V> {
33
33
  commit(): BPTreeTransactionResult;
34
34
  /**
35
35
  * Rolls back the transaction by clearing all buffered changes.
36
- * Internal use only.
36
+ * If cleanup is `true`, it also clears the transaction nodes.
37
+ * @param cleanup Whether to clear the transaction nodes.
38
+ * @returns The IDs of nodes that were created in this transaction.
37
39
  */
38
- protected rollback(): void;
40
+ rollback(cleanup?: boolean): string[];
39
41
  protected commitHeadBuffer(): void;
40
42
  protected commitNodeCreateBuffer(): void;
41
43
  protected commitNodeUpdateBuffer(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "7.0.1",
3
+ "version": "7.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",