dataply 0.0.26-alpha.12 → 0.0.26-alpha.14

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.
Files changed (2) hide show
  1. package/dist/cjs/index.js +30 -56
  2. package/package.json +2 -2
package/dist/cjs/index.js CHANGED
@@ -2977,27 +2977,12 @@ var BPTreeTransaction = class _BPTreeTransaction {
2977
2977
  static CheckConflicts(transactions) {
2978
2978
  return MVCCTransaction.CheckConflicts(transactions.map((tx) => tx.mvcc));
2979
2979
  }
2980
- /**
2981
- * Returns the ID of the root node.
2982
- * @returns The root node ID.
2983
- */
2984
2980
  getRootId() {
2985
2981
  return this.rootId;
2986
2982
  }
2987
- /**
2988
- * Returns the order of the B+Tree.
2989
- * @returns The order of the tree.
2990
- */
2991
2983
  getOrder() {
2992
2984
  return this.order;
2993
2985
  }
2994
- /**
2995
- * Verified if the value satisfies the condition.
2996
- *
2997
- * @param nodeValue The value to verify.
2998
- * @param condition The condition to verify against.
2999
- * @returns Returns true if the value satisfies the condition.
3000
- */
3001
2986
  verify(nodeValue, condition) {
3002
2987
  for (const key in condition) {
3003
2988
  const verify2 = this.verifierMap[key];
@@ -5265,14 +5250,10 @@ var BPTreePureAsync = class {
5265
5250
  }
5266
5251
  _createReadOps() {
5267
5252
  const strategy = this.strategy;
5268
- const readBuffer = /* @__PURE__ */ new Map();
5253
+ let headBuffer = null;
5269
5254
  return {
5270
5255
  async getNode(id) {
5271
- const buffered = readBuffer.get(id);
5272
- if (buffered) return buffered;
5273
- const node = await strategy.read(id);
5274
- readBuffer.set(id, node);
5275
- return node;
5256
+ return await strategy.read(id);
5276
5257
  },
5277
5258
  async createNode(leaf, keys, values, parent = null, next = null, prev = null) {
5278
5259
  const id = await strategy.id(leaf);
@@ -5284,15 +5265,17 @@ var BPTreePureAsync = class {
5284
5265
  async deleteNode() {
5285
5266
  },
5286
5267
  async readHead() {
5287
- return await strategy.readHead();
5268
+ if (headBuffer) return headBuffer;
5269
+ headBuffer = await strategy.readHead();
5270
+ return headBuffer;
5288
5271
  },
5289
- async writeHead() {
5272
+ async writeHead(head) {
5273
+ headBuffer = head;
5290
5274
  }
5291
5275
  };
5292
5276
  }
5293
5277
  _createBufferedOps() {
5294
5278
  const strategy = this.strategy;
5295
- const readBuffer = /* @__PURE__ */ new Map();
5296
5279
  const writeBuffer = /* @__PURE__ */ new Map();
5297
5280
  const deleteBuffer = /* @__PURE__ */ new Set();
5298
5281
  let headBuffer = null;
@@ -5300,11 +5283,7 @@ var BPTreePureAsync = class {
5300
5283
  async getNode(id) {
5301
5284
  const buffered = writeBuffer.get(id);
5302
5285
  if (buffered) return buffered;
5303
- const read = readBuffer.get(id);
5304
- if (read) return read;
5305
- const node = await strategy.read(id);
5306
- readBuffer.set(id, node);
5307
- return node;
5286
+ return await strategy.read(id);
5308
5287
  },
5309
5288
  async createNode(leaf, keys, values, parent = null, next = null, prev = null) {
5310
5289
  const id = await strategy.id(leaf);
@@ -5321,7 +5300,8 @@ var BPTreePureAsync = class {
5321
5300
  },
5322
5301
  async readHead() {
5323
5302
  if (headBuffer) return headBuffer;
5324
- return await strategy.readHead();
5303
+ headBuffer = await strategy.readHead();
5304
+ return headBuffer;
5325
5305
  },
5326
5306
  async writeHead(head) {
5327
5307
  headBuffer = head;
@@ -5337,7 +5317,6 @@ var BPTreePureAsync = class {
5337
5317
  if (headBuffer) {
5338
5318
  await strategy.writeHead(headBuffer);
5339
5319
  }
5340
- readBuffer.clear();
5341
5320
  writeBuffer.clear();
5342
5321
  deleteBuffer.clear();
5343
5322
  headBuffer = null;
@@ -10974,11 +10953,6 @@ var RowTableEngine = class {
10974
10953
  }
10975
10954
  };
10976
10955
 
10977
- // src/utils/catchPromise.ts
10978
- async function catchPromise(promise) {
10979
- return promise.then((res) => [void 0, res]).catch((reason) => [reason]);
10980
- }
10981
-
10982
10956
  // src/core/transaction/LockManager.ts
10983
10957
  var LockManager = class {
10984
10958
  lock;
@@ -11514,41 +11488,41 @@ var DataplyAPI = class {
11514
11488
  const release = await this.acquireWriteLock();
11515
11489
  const internalTx = this.createTransaction();
11516
11490
  internalTx.__setWriteLockRelease(release);
11517
- const [error2, result2] = await catchPromise(this.txContext.run(internalTx, () => callback(internalTx)));
11518
- if (error2) {
11491
+ try {
11492
+ const result = await this.txContext.run(internalTx, () => callback(internalTx));
11493
+ await internalTx.commit();
11494
+ return result;
11495
+ } catch (error) {
11519
11496
  await internalTx.rollback();
11520
- throw error2;
11497
+ throw error;
11521
11498
  }
11522
- await internalTx.commit();
11523
- return result2;
11524
11499
  }
11525
11500
  if (!tx.__hasWriteLockRelease()) {
11526
11501
  const release = await this.acquireWriteLock();
11527
11502
  tx.__setWriteLockRelease(release);
11528
11503
  }
11529
- const [error, result] = await catchPromise(this.txContext.run(tx, () => callback(tx)));
11530
- if (error) {
11531
- throw error;
11504
+ if (this.txContext.get() === tx) {
11505
+ return callback(tx);
11532
11506
  }
11533
- return result;
11507
+ return this.txContext.run(tx, () => callback(tx));
11534
11508
  }
11535
11509
  async withReadTransaction(callback, tx) {
11536
11510
  this.logger.debug("Running with read transaction");
11537
- const isInternalTx = !tx;
11538
11511
  if (!tx) {
11539
- tx = this.createTransaction();
11540
- }
11541
- const [error, result] = await catchPromise(this.txContext.run(tx, () => callback(tx)));
11542
- if (error) {
11543
- if (isInternalTx) {
11544
- await tx.rollback();
11512
+ const internalTx = this.createTransaction();
11513
+ try {
11514
+ const result = await this.txContext.run(internalTx, () => callback(internalTx));
11515
+ await internalTx.commit();
11516
+ return result;
11517
+ } catch (error) {
11518
+ await internalTx.rollback();
11519
+ throw error;
11545
11520
  }
11546
- throw error;
11547
11521
  }
11548
- if (isInternalTx) {
11549
- await tx.commit();
11522
+ if (this.txContext.get() === tx) {
11523
+ return callback(tx);
11550
11524
  }
11551
- return result;
11525
+ return this.txContext.run(tx, () => callback(tx));
11552
11526
  }
11553
11527
  /**
11554
11528
  * Runs a generator callback function within a transaction context.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataply",
3
- "version": "0.0.26-alpha.12",
3
+ "version": "0.0.26-alpha.14",
4
4
  "description": "A lightweight storage engine for Node.js with support for MVCC, WAL.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",
@@ -49,6 +49,6 @@
49
49
  "hookall": "^2.2.0",
50
50
  "mvcc-api": "^1.3.7",
51
51
  "ryoiki": "^1.2.0",
52
- "serializable-bptree": "^9.0.4-alpha.1"
52
+ "serializable-bptree": "^9.0.4-alpha.2"
53
53
  }
54
54
  }