dataply 0.0.26-alpha.8 → 0.0.26-alpha.9

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/dist/cjs/index.js CHANGED
@@ -5002,8 +5002,6 @@ var BPTreePureSync = class {
5002
5002
  comparator;
5003
5003
  option;
5004
5004
  _cachedRegexp = /* @__PURE__ */ new Map();
5005
- _ctx;
5006
- _ops;
5007
5005
  _verifierMap;
5008
5006
  _searchConfigs;
5009
5007
  constructor(strategy, comparator, option) {
@@ -5017,7 +5015,7 @@ var BPTreePureSync = class {
5017
5015
  _ensureValues(v) {
5018
5016
  return Array.isArray(v) ? v : [v];
5019
5017
  }
5020
- _createOps() {
5018
+ _createReadOps() {
5021
5019
  const strategy = this.strategy;
5022
5020
  return {
5023
5021
  getNode(id) {
@@ -5084,16 +5082,35 @@ var BPTreePureSync = class {
5084
5082
  }
5085
5083
  return { ops, flush };
5086
5084
  }
5085
+ _readCtx() {
5086
+ const head = this.strategy.readHead();
5087
+ if (head === null) {
5088
+ throw new Error("Tree not initialized. Call init() first.");
5089
+ }
5090
+ return { rootId: head.root, order: head.order };
5091
+ }
5092
+ _createCtx() {
5093
+ const strategy = this.strategy;
5094
+ const head = strategy.readHead();
5095
+ if (head === null) {
5096
+ throw new Error("Tree not initialized. Call init() first.");
5097
+ }
5098
+ return {
5099
+ rootId: head.root,
5100
+ order: head.order,
5101
+ headData: () => strategy.head.data
5102
+ };
5103
+ }
5087
5104
  init() {
5088
5105
  const { ops, flush } = this._createBufferedOps();
5089
- this._ctx = {
5106
+ const ctx = {
5090
5107
  rootId: "",
5091
5108
  order: this.strategy.order,
5092
5109
  headData: () => this.strategy.head.data
5093
5110
  };
5094
5111
  initOp(
5095
5112
  ops,
5096
- this._ctx,
5113
+ ctx,
5097
5114
  this.strategy.order,
5098
5115
  this.strategy.head,
5099
5116
  (head) => {
@@ -5101,19 +5118,18 @@ var BPTreePureSync = class {
5101
5118
  }
5102
5119
  );
5103
5120
  flush();
5104
- this._ops = this._createOps();
5105
5121
  }
5106
5122
  /**
5107
5123
  * Returns the ID of the root node.
5108
5124
  */
5109
5125
  getRootId() {
5110
- return this._ctx.rootId;
5126
+ return this._readCtx().rootId;
5111
5127
  }
5112
5128
  /**
5113
5129
  * Returns the order of the B+Tree.
5114
5130
  */
5115
5131
  getOrder() {
5116
- return this._ctx.order;
5132
+ return this._readCtx().order;
5117
5133
  }
5118
5134
  /**
5119
5135
  * Verified if the value satisfies the condition.
@@ -5130,15 +5146,18 @@ var BPTreePureSync = class {
5130
5146
  }
5131
5147
  // ─── Query ───────────────────────────────────────────────────────
5132
5148
  get(key) {
5133
- return getOp(this._ops, this._ctx.rootId, key);
5149
+ const { rootId } = this._readCtx();
5150
+ return getOp(this._createReadOps(), rootId, key);
5134
5151
  }
5135
5152
  exists(key, value) {
5136
- return existsOp(this._ops, this._ctx.rootId, key, value, this.comparator);
5153
+ const { rootId } = this._readCtx();
5154
+ return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
5137
5155
  }
5138
5156
  *keysStream(condition, options) {
5157
+ const { rootId } = this._readCtx();
5139
5158
  yield* keysStreamOp(
5140
- this._ops,
5141
- this._ctx.rootId,
5159
+ this._createReadOps(),
5160
+ rootId,
5142
5161
  condition,
5143
5162
  this.comparator,
5144
5163
  this._verifierMap,
@@ -5148,9 +5167,10 @@ var BPTreePureSync = class {
5148
5167
  );
5149
5168
  }
5150
5169
  *whereStream(condition, options) {
5170
+ const { rootId } = this._readCtx();
5151
5171
  yield* whereStreamOp(
5152
- this._ops,
5153
- this._ctx.rootId,
5172
+ this._createReadOps(),
5173
+ rootId,
5154
5174
  condition,
5155
5175
  this.comparator,
5156
5176
  this._verifierMap,
@@ -5176,27 +5196,31 @@ var BPTreePureSync = class {
5176
5196
  // ─── Mutation ────────────────────────────────────────────────────
5177
5197
  insert(key, value) {
5178
5198
  const { ops, flush } = this._createBufferedOps();
5179
- insertOp(ops, this._ctx, key, value, this.comparator);
5199
+ const ctx = this._createCtx();
5200
+ insertOp(ops, ctx, key, value, this.comparator);
5180
5201
  flush();
5181
5202
  }
5182
5203
  delete(key, value) {
5183
5204
  const { ops, flush } = this._createBufferedOps();
5184
- deleteOp(ops, this._ctx, key, this.comparator, value);
5205
+ const ctx = this._createCtx();
5206
+ deleteOp(ops, ctx, key, this.comparator, value);
5185
5207
  flush();
5186
5208
  }
5187
5209
  batchInsert(entries) {
5188
5210
  const { ops, flush } = this._createBufferedOps();
5189
- batchInsertOp(ops, this._ctx, entries, this.comparator);
5211
+ const ctx = this._createCtx();
5212
+ batchInsertOp(ops, ctx, entries, this.comparator);
5190
5213
  flush();
5191
5214
  }
5192
5215
  bulkLoad(entries) {
5193
5216
  const { ops, flush } = this._createBufferedOps();
5194
- bulkLoadOp(ops, this._ctx, entries, this.comparator);
5217
+ const ctx = this._createCtx();
5218
+ bulkLoadOp(ops, ctx, entries, this.comparator);
5195
5219
  flush();
5196
5220
  }
5197
5221
  // ─── Head Data ───────────────────────────────────────────────────
5198
5222
  getHeadData() {
5199
- const head = this._ops.readHead();
5223
+ const head = this.strategy.readHead();
5200
5224
  if (head === null) {
5201
5225
  throw new Error("Head not found");
5202
5226
  }
@@ -5224,8 +5248,6 @@ var BPTreePureAsync = class {
5224
5248
  option;
5225
5249
  lock = new Ryoiki2();
5226
5250
  _cachedRegexp = /* @__PURE__ */ new Map();
5227
- _ctx;
5228
- _ops;
5229
5251
  _verifierMap;
5230
5252
  _searchConfigs;
5231
5253
  constructor(strategy, comparator, option) {
@@ -5239,7 +5261,7 @@ var BPTreePureAsync = class {
5239
5261
  _ensureValues(v) {
5240
5262
  return Array.isArray(v) ? v : [v];
5241
5263
  }
5242
- _createOps() {
5264
+ _createReadOps() {
5243
5265
  const strategy = this.strategy;
5244
5266
  return {
5245
5267
  async getNode(id) {
@@ -5306,6 +5328,25 @@ var BPTreePureAsync = class {
5306
5328
  }
5307
5329
  return { ops, flush };
5308
5330
  }
5331
+ async _readCtx() {
5332
+ const head = await this.strategy.readHead();
5333
+ if (head === null) {
5334
+ throw new Error("Tree not initialized. Call init() first.");
5335
+ }
5336
+ return { rootId: head.root, order: head.order };
5337
+ }
5338
+ async _createCtx() {
5339
+ const strategy = this.strategy;
5340
+ const head = await strategy.readHead();
5341
+ if (head === null) {
5342
+ throw new Error("Tree not initialized. Call init() first.");
5343
+ }
5344
+ return {
5345
+ rootId: head.root,
5346
+ order: head.order,
5347
+ headData: () => strategy.head.data
5348
+ };
5349
+ }
5309
5350
  async writeLock(fn) {
5310
5351
  let lockId;
5311
5352
  return this.lock.writeLock(async (_lockId) => {
@@ -5318,14 +5359,14 @@ var BPTreePureAsync = class {
5318
5359
  async init() {
5319
5360
  return this.writeLock(async () => {
5320
5361
  const { ops, flush } = this._createBufferedOps();
5321
- this._ctx = {
5362
+ const ctx = {
5322
5363
  rootId: "",
5323
5364
  order: this.strategy.order,
5324
5365
  headData: () => this.strategy.head.data
5325
5366
  };
5326
5367
  await initOpAsync(
5327
5368
  ops,
5328
- this._ctx,
5369
+ ctx,
5329
5370
  this.strategy.order,
5330
5371
  this.strategy.head,
5331
5372
  (head) => {
@@ -5333,14 +5374,13 @@ var BPTreePureAsync = class {
5333
5374
  }
5334
5375
  );
5335
5376
  await flush();
5336
- this._ops = this._createOps();
5337
5377
  });
5338
5378
  }
5339
- getRootId() {
5340
- return this._ctx.rootId;
5379
+ async getRootId() {
5380
+ return (await this._readCtx()).rootId;
5341
5381
  }
5342
- getOrder() {
5343
- return this._ctx.order;
5382
+ async getOrder() {
5383
+ return (await this._readCtx()).order;
5344
5384
  }
5345
5385
  verify(nodeValue, condition) {
5346
5386
  for (const key in condition) {
@@ -5352,18 +5392,21 @@ var BPTreePureAsync = class {
5352
5392
  }
5353
5393
  // ─── Query ───────────────────────────────────────────────────────
5354
5394
  async get(key) {
5355
- return getOpAsync(this._ops, this._ctx.rootId, key);
5395
+ const { rootId } = await this._readCtx();
5396
+ return getOpAsync(this._createReadOps(), rootId, key);
5356
5397
  }
5357
5398
  async exists(key, value) {
5358
- return existsOpAsync(this._ops, this._ctx.rootId, key, value, this.comparator);
5399
+ const { rootId } = await this._readCtx();
5400
+ return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
5359
5401
  }
5360
5402
  async *keysStream(condition, options) {
5361
5403
  let lockId;
5362
5404
  try {
5363
5405
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5406
+ const { rootId } = await this._readCtx();
5364
5407
  yield* keysStreamOpAsync(
5365
- this._ops,
5366
- this._ctx.rootId,
5408
+ this._createReadOps(),
5409
+ rootId,
5367
5410
  condition,
5368
5411
  this.comparator,
5369
5412
  this._verifierMap,
@@ -5379,9 +5422,10 @@ var BPTreePureAsync = class {
5379
5422
  let lockId;
5380
5423
  try {
5381
5424
  lockId = await this.lock.readLock([0, 0.1], async (id) => id);
5425
+ const { rootId } = await this._readCtx();
5382
5426
  yield* whereStreamOpAsync(
5383
- this._ops,
5384
- this._ctx.rootId,
5427
+ this._createReadOps(),
5428
+ rootId,
5385
5429
  condition,
5386
5430
  this.comparator,
5387
5431
  this._verifierMap,
@@ -5411,34 +5455,38 @@ var BPTreePureAsync = class {
5411
5455
  async insert(key, value) {
5412
5456
  return this.writeLock(async () => {
5413
5457
  const { ops, flush } = this._createBufferedOps();
5414
- await insertOpAsync(ops, this._ctx, key, value, this.comparator);
5458
+ const ctx = await this._createCtx();
5459
+ await insertOpAsync(ops, ctx, key, value, this.comparator);
5415
5460
  await flush();
5416
5461
  });
5417
5462
  }
5418
5463
  async delete(key, value) {
5419
5464
  return this.writeLock(async () => {
5420
5465
  const { ops, flush } = this._createBufferedOps();
5421
- await deleteOpAsync(ops, this._ctx, key, this.comparator, value);
5466
+ const ctx = await this._createCtx();
5467
+ await deleteOpAsync(ops, ctx, key, this.comparator, value);
5422
5468
  await flush();
5423
5469
  });
5424
5470
  }
5425
5471
  async batchInsert(entries) {
5426
5472
  return this.writeLock(async () => {
5427
5473
  const { ops, flush } = this._createBufferedOps();
5428
- await batchInsertOpAsync(ops, this._ctx, entries, this.comparator);
5474
+ const ctx = await this._createCtx();
5475
+ await batchInsertOpAsync(ops, ctx, entries, this.comparator);
5429
5476
  await flush();
5430
5477
  });
5431
5478
  }
5432
5479
  async bulkLoad(entries) {
5433
5480
  return this.writeLock(async () => {
5434
5481
  const { ops, flush } = this._createBufferedOps();
5435
- await bulkLoadOpAsync(ops, this._ctx, entries, this.comparator);
5482
+ const ctx = await this._createCtx();
5483
+ await bulkLoadOpAsync(ops, ctx, entries, this.comparator);
5436
5484
  await flush();
5437
5485
  });
5438
5486
  }
5439
5487
  // ─── Head Data ───────────────────────────────────────────────────
5440
5488
  async getHeadData() {
5441
- const head = await this._ops.readHead();
5489
+ const head = await this.strategy.readHead();
5442
5490
  if (head === null) throw new Error("Head not found");
5443
5491
  return head.data;
5444
5492
  }
@@ -11672,15 +11720,6 @@ var Dataply = class {
11672
11720
  get options() {
11673
11721
  return this.api.options;
11674
11722
  }
11675
- /**
11676
- * Creates a transaction.
11677
- * The created transaction object can be used to add or modify data.
11678
- * A transaction must be terminated by calling either `commit` or `rollback`.
11679
- * @returns Transaction object
11680
- */
11681
- createTransaction() {
11682
- return this.api.createTransaction();
11683
- }
11684
11723
  /**
11685
11724
  * Runs a write callback within a transaction context.
11686
11725
  */
@@ -12,13 +12,6 @@ export declare class Dataply {
12
12
  * @returns Options used to open the dataply.
13
13
  */
14
14
  get options(): Required<DataplyOptions>;
15
- /**
16
- * Creates a transaction.
17
- * The created transaction object can be used to add or modify data.
18
- * A transaction must be terminated by calling either `commit` or `rollback`.
19
- * @returns Transaction object
20
- */
21
- protected createTransaction(): Transaction;
22
15
  /**
23
16
  * Runs a write callback within a transaction context.
24
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataply",
3
- "version": "0.0.26-alpha.8",
3
+ "version": "0.0.26-alpha.9",
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.1"
52
+ "serializable-bptree": "^9.0.2"
53
53
  }
54
54
  }