serializable-bptree 9.0.2 → 9.0.3
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.cjs +38 -29
- package/dist/esm/index.mjs +38 -29
- package/dist/types/BPTreePureAsync.d.ts +3 -2
- package/dist/types/BPTreePureSync.d.ts +2 -10
- package/dist/types/base/BPTreeTransaction.d.ts +5 -0
- package/dist/types/transaction/BPTreeAsyncTransaction.d.ts +1 -0
- package/dist/types/transaction/BPTreeSyncTransaction.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3236,6 +3236,9 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
3236
3236
|
this._verifierMapCached = createVerifierMap(this.comparator, this._cachedRegexp, ensureValues);
|
|
3237
3237
|
this._searchConfigsCached = createSearchConfigs(this.comparator, ensureValues);
|
|
3238
3238
|
}
|
|
3239
|
+
getRootNode() {
|
|
3240
|
+
return this.getNode(this.rootId);
|
|
3241
|
+
}
|
|
3239
3242
|
// ─── Legacy protected methods (delegating to ops) ────────────────
|
|
3240
3243
|
getNode(id) {
|
|
3241
3244
|
return this._ops.getNode(id);
|
|
@@ -4674,6 +4677,9 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
4674
4677
|
this.lock.writeUnlock(lockId);
|
|
4675
4678
|
});
|
|
4676
4679
|
}
|
|
4680
|
+
async getRootNode() {
|
|
4681
|
+
return this.getNode(this.rootId);
|
|
4682
|
+
}
|
|
4677
4683
|
// ─── Legacy protected methods (delegating to ops) ────────────────
|
|
4678
4684
|
async getNode(id) {
|
|
4679
4685
|
return this._ops.getNode(id);
|
|
@@ -5107,21 +5113,18 @@ var BPTreePureSync = class {
|
|
|
5107
5113
|
);
|
|
5108
5114
|
flush();
|
|
5109
5115
|
}
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5116
|
+
getRootNode() {
|
|
5117
|
+
const ctx = this._readCtx();
|
|
5118
|
+
return this.strategy.read(ctx.rootId);
|
|
5119
|
+
}
|
|
5113
5120
|
getRootId() {
|
|
5114
|
-
|
|
5121
|
+
const ctx = this._readCtx();
|
|
5122
|
+
return ctx.rootId;
|
|
5115
5123
|
}
|
|
5116
|
-
/**
|
|
5117
|
-
* Returns the order of the B+Tree.
|
|
5118
|
-
*/
|
|
5119
5124
|
getOrder() {
|
|
5120
|
-
|
|
5125
|
+
const ctx = this._readCtx();
|
|
5126
|
+
return ctx.order;
|
|
5121
5127
|
}
|
|
5122
|
-
/**
|
|
5123
|
-
* Verified if the value satisfies the condition.
|
|
5124
|
-
*/
|
|
5125
5128
|
verify(nodeValue, condition) {
|
|
5126
5129
|
for (const key in condition) {
|
|
5127
5130
|
const verifyFn = this._verifierMap[key];
|
|
@@ -5134,18 +5137,18 @@ var BPTreePureSync = class {
|
|
|
5134
5137
|
}
|
|
5135
5138
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5136
5139
|
get(key) {
|
|
5137
|
-
const
|
|
5138
|
-
return getOp(this._createReadOps(), rootId, key);
|
|
5140
|
+
const ctx = this._readCtx();
|
|
5141
|
+
return getOp(this._createReadOps(), ctx.rootId, key);
|
|
5139
5142
|
}
|
|
5140
5143
|
exists(key, value) {
|
|
5141
|
-
const
|
|
5142
|
-
return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5144
|
+
const ctx = this._readCtx();
|
|
5145
|
+
return existsOp(this._createReadOps(), ctx.rootId, key, value, this.comparator);
|
|
5143
5146
|
}
|
|
5144
5147
|
*keysStream(condition, options) {
|
|
5145
|
-
const
|
|
5148
|
+
const ctx = this._readCtx();
|
|
5146
5149
|
yield* keysStreamOp(
|
|
5147
5150
|
this._createReadOps(),
|
|
5148
|
-
rootId,
|
|
5151
|
+
ctx.rootId,
|
|
5149
5152
|
condition,
|
|
5150
5153
|
this.comparator,
|
|
5151
5154
|
this._verifierMap,
|
|
@@ -5155,10 +5158,10 @@ var BPTreePureSync = class {
|
|
|
5155
5158
|
);
|
|
5156
5159
|
}
|
|
5157
5160
|
*whereStream(condition, options) {
|
|
5158
|
-
const
|
|
5161
|
+
const ctx = this._readCtx();
|
|
5159
5162
|
yield* whereStreamOp(
|
|
5160
5163
|
this._createReadOps(),
|
|
5161
|
-
rootId,
|
|
5164
|
+
ctx.rootId,
|
|
5162
5165
|
condition,
|
|
5163
5166
|
this.comparator,
|
|
5164
5167
|
this._verifierMap,
|
|
@@ -5366,11 +5369,17 @@ var BPTreePureAsync = class {
|
|
|
5366
5369
|
await flush();
|
|
5367
5370
|
});
|
|
5368
5371
|
}
|
|
5372
|
+
async getRootNode() {
|
|
5373
|
+
const ctx = await this._readCtx();
|
|
5374
|
+
return await this.strategy.read(ctx.rootId);
|
|
5375
|
+
}
|
|
5369
5376
|
async getRootId() {
|
|
5370
|
-
|
|
5377
|
+
const ctx = await this._readCtx();
|
|
5378
|
+
return ctx.rootId;
|
|
5371
5379
|
}
|
|
5372
5380
|
async getOrder() {
|
|
5373
|
-
|
|
5381
|
+
const ctx = await this._readCtx();
|
|
5382
|
+
return ctx.order;
|
|
5374
5383
|
}
|
|
5375
5384
|
verify(nodeValue, condition) {
|
|
5376
5385
|
for (const key in condition) {
|
|
@@ -5382,21 +5391,21 @@ var BPTreePureAsync = class {
|
|
|
5382
5391
|
}
|
|
5383
5392
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5384
5393
|
async get(key) {
|
|
5385
|
-
const
|
|
5386
|
-
return getOpAsync(this._createReadOps(), rootId, key);
|
|
5394
|
+
const ctx = await this._readCtx();
|
|
5395
|
+
return getOpAsync(this._createReadOps(), ctx.rootId, key);
|
|
5387
5396
|
}
|
|
5388
5397
|
async exists(key, value) {
|
|
5389
|
-
const
|
|
5390
|
-
return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5398
|
+
const ctx = await this._readCtx();
|
|
5399
|
+
return existsOpAsync(this._createReadOps(), ctx.rootId, key, value, this.comparator);
|
|
5391
5400
|
}
|
|
5392
5401
|
async *keysStream(condition, options) {
|
|
5393
5402
|
let lockId;
|
|
5394
5403
|
try {
|
|
5395
5404
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5396
|
-
const
|
|
5405
|
+
const ctx = await this._readCtx();
|
|
5397
5406
|
yield* keysStreamOpAsync(
|
|
5398
5407
|
this._createReadOps(),
|
|
5399
|
-
rootId,
|
|
5408
|
+
ctx.rootId,
|
|
5400
5409
|
condition,
|
|
5401
5410
|
this.comparator,
|
|
5402
5411
|
this._verifierMap,
|
|
@@ -5412,10 +5421,10 @@ var BPTreePureAsync = class {
|
|
|
5412
5421
|
let lockId;
|
|
5413
5422
|
try {
|
|
5414
5423
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5415
|
-
const
|
|
5424
|
+
const ctx = await this._readCtx();
|
|
5416
5425
|
yield* whereStreamOpAsync(
|
|
5417
5426
|
this._createReadOps(),
|
|
5418
|
-
rootId,
|
|
5427
|
+
ctx.rootId,
|
|
5419
5428
|
condition,
|
|
5420
5429
|
this.comparator,
|
|
5421
5430
|
this._verifierMap,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3198,6 +3198,9 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
3198
3198
|
this._verifierMapCached = createVerifierMap(this.comparator, this._cachedRegexp, ensureValues);
|
|
3199
3199
|
this._searchConfigsCached = createSearchConfigs(this.comparator, ensureValues);
|
|
3200
3200
|
}
|
|
3201
|
+
getRootNode() {
|
|
3202
|
+
return this.getNode(this.rootId);
|
|
3203
|
+
}
|
|
3201
3204
|
// ─── Legacy protected methods (delegating to ops) ────────────────
|
|
3202
3205
|
getNode(id) {
|
|
3203
3206
|
return this._ops.getNode(id);
|
|
@@ -4636,6 +4639,9 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
4636
4639
|
this.lock.writeUnlock(lockId);
|
|
4637
4640
|
});
|
|
4638
4641
|
}
|
|
4642
|
+
async getRootNode() {
|
|
4643
|
+
return this.getNode(this.rootId);
|
|
4644
|
+
}
|
|
4639
4645
|
// ─── Legacy protected methods (delegating to ops) ────────────────
|
|
4640
4646
|
async getNode(id) {
|
|
4641
4647
|
return this._ops.getNode(id);
|
|
@@ -5069,21 +5075,18 @@ var BPTreePureSync = class {
|
|
|
5069
5075
|
);
|
|
5070
5076
|
flush();
|
|
5071
5077
|
}
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5078
|
+
getRootNode() {
|
|
5079
|
+
const ctx = this._readCtx();
|
|
5080
|
+
return this.strategy.read(ctx.rootId);
|
|
5081
|
+
}
|
|
5075
5082
|
getRootId() {
|
|
5076
|
-
|
|
5083
|
+
const ctx = this._readCtx();
|
|
5084
|
+
return ctx.rootId;
|
|
5077
5085
|
}
|
|
5078
|
-
/**
|
|
5079
|
-
* Returns the order of the B+Tree.
|
|
5080
|
-
*/
|
|
5081
5086
|
getOrder() {
|
|
5082
|
-
|
|
5087
|
+
const ctx = this._readCtx();
|
|
5088
|
+
return ctx.order;
|
|
5083
5089
|
}
|
|
5084
|
-
/**
|
|
5085
|
-
* Verified if the value satisfies the condition.
|
|
5086
|
-
*/
|
|
5087
5090
|
verify(nodeValue, condition) {
|
|
5088
5091
|
for (const key in condition) {
|
|
5089
5092
|
const verifyFn = this._verifierMap[key];
|
|
@@ -5096,18 +5099,18 @@ var BPTreePureSync = class {
|
|
|
5096
5099
|
}
|
|
5097
5100
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5098
5101
|
get(key) {
|
|
5099
|
-
const
|
|
5100
|
-
return getOp(this._createReadOps(), rootId, key);
|
|
5102
|
+
const ctx = this._readCtx();
|
|
5103
|
+
return getOp(this._createReadOps(), ctx.rootId, key);
|
|
5101
5104
|
}
|
|
5102
5105
|
exists(key, value) {
|
|
5103
|
-
const
|
|
5104
|
-
return existsOp(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5106
|
+
const ctx = this._readCtx();
|
|
5107
|
+
return existsOp(this._createReadOps(), ctx.rootId, key, value, this.comparator);
|
|
5105
5108
|
}
|
|
5106
5109
|
*keysStream(condition, options) {
|
|
5107
|
-
const
|
|
5110
|
+
const ctx = this._readCtx();
|
|
5108
5111
|
yield* keysStreamOp(
|
|
5109
5112
|
this._createReadOps(),
|
|
5110
|
-
rootId,
|
|
5113
|
+
ctx.rootId,
|
|
5111
5114
|
condition,
|
|
5112
5115
|
this.comparator,
|
|
5113
5116
|
this._verifierMap,
|
|
@@ -5117,10 +5120,10 @@ var BPTreePureSync = class {
|
|
|
5117
5120
|
);
|
|
5118
5121
|
}
|
|
5119
5122
|
*whereStream(condition, options) {
|
|
5120
|
-
const
|
|
5123
|
+
const ctx = this._readCtx();
|
|
5121
5124
|
yield* whereStreamOp(
|
|
5122
5125
|
this._createReadOps(),
|
|
5123
|
-
rootId,
|
|
5126
|
+
ctx.rootId,
|
|
5124
5127
|
condition,
|
|
5125
5128
|
this.comparator,
|
|
5126
5129
|
this._verifierMap,
|
|
@@ -5328,11 +5331,17 @@ var BPTreePureAsync = class {
|
|
|
5328
5331
|
await flush();
|
|
5329
5332
|
});
|
|
5330
5333
|
}
|
|
5334
|
+
async getRootNode() {
|
|
5335
|
+
const ctx = await this._readCtx();
|
|
5336
|
+
return await this.strategy.read(ctx.rootId);
|
|
5337
|
+
}
|
|
5331
5338
|
async getRootId() {
|
|
5332
|
-
|
|
5339
|
+
const ctx = await this._readCtx();
|
|
5340
|
+
return ctx.rootId;
|
|
5333
5341
|
}
|
|
5334
5342
|
async getOrder() {
|
|
5335
|
-
|
|
5343
|
+
const ctx = await this._readCtx();
|
|
5344
|
+
return ctx.order;
|
|
5336
5345
|
}
|
|
5337
5346
|
verify(nodeValue, condition) {
|
|
5338
5347
|
for (const key in condition) {
|
|
@@ -5344,21 +5353,21 @@ var BPTreePureAsync = class {
|
|
|
5344
5353
|
}
|
|
5345
5354
|
// ─── Query ───────────────────────────────────────────────────────
|
|
5346
5355
|
async get(key) {
|
|
5347
|
-
const
|
|
5348
|
-
return getOpAsync(this._createReadOps(), rootId, key);
|
|
5356
|
+
const ctx = await this._readCtx();
|
|
5357
|
+
return getOpAsync(this._createReadOps(), ctx.rootId, key);
|
|
5349
5358
|
}
|
|
5350
5359
|
async exists(key, value) {
|
|
5351
|
-
const
|
|
5352
|
-
return existsOpAsync(this._createReadOps(), rootId, key, value, this.comparator);
|
|
5360
|
+
const ctx = await this._readCtx();
|
|
5361
|
+
return existsOpAsync(this._createReadOps(), ctx.rootId, key, value, this.comparator);
|
|
5353
5362
|
}
|
|
5354
5363
|
async *keysStream(condition, options) {
|
|
5355
5364
|
let lockId;
|
|
5356
5365
|
try {
|
|
5357
5366
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5358
|
-
const
|
|
5367
|
+
const ctx = await this._readCtx();
|
|
5359
5368
|
yield* keysStreamOpAsync(
|
|
5360
5369
|
this._createReadOps(),
|
|
5361
|
-
rootId,
|
|
5370
|
+
ctx.rootId,
|
|
5362
5371
|
condition,
|
|
5363
5372
|
this.comparator,
|
|
5364
5373
|
this._verifierMap,
|
|
@@ -5374,10 +5383,10 @@ var BPTreePureAsync = class {
|
|
|
5374
5383
|
let lockId;
|
|
5375
5384
|
try {
|
|
5376
5385
|
lockId = await this.lock.readLock([0, 0.1], async (id) => id);
|
|
5377
|
-
const
|
|
5386
|
+
const ctx = await this._readCtx();
|
|
5378
5387
|
yield* whereStreamOpAsync(
|
|
5379
5388
|
this._createReadOps(),
|
|
5380
|
-
rootId,
|
|
5389
|
+
ctx.rootId,
|
|
5381
5390
|
condition,
|
|
5382
5391
|
this.comparator,
|
|
5383
5392
|
this._verifierMap,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, SerializableData } from './types';
|
|
1
|
+
import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, BPTreeUnknownNode, SerializableData } from './types';
|
|
2
|
+
import { Ryoiki } from 'ryoiki';
|
|
2
3
|
import { SerializeStrategyAsync } from './SerializeStrategyAsync';
|
|
3
4
|
import { ValueComparator } from './base/ValueComparator';
|
|
4
5
|
import { BPTreeTransaction } from './base/BPTreeTransaction';
|
|
5
|
-
import { Ryoiki } from 'ryoiki';
|
|
6
6
|
export declare class BPTreePureAsync<K, V> {
|
|
7
7
|
protected readonly strategy: SerializeStrategyAsync<K, V>;
|
|
8
8
|
protected readonly comparator: ValueComparator<V>;
|
|
@@ -19,6 +19,7 @@ export declare class BPTreePureAsync<K, V> {
|
|
|
19
19
|
private _createCtx;
|
|
20
20
|
protected writeLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
21
21
|
init(): Promise<void>;
|
|
22
|
+
getRootNode(): Promise<BPTreeUnknownNode<K, V>>;
|
|
22
23
|
getRootId(): Promise<string>;
|
|
23
24
|
getOrder(): Promise<number>;
|
|
24
25
|
verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, SerializableData } from './types';
|
|
1
|
+
import type { BPTreeCondition, BPTreeConstructorOption, BPTreePair, BPTreeSearchOption, BPTreeUnknownNode, SerializableData } from './types';
|
|
2
2
|
import { SerializeStrategySync } from './SerializeStrategySync';
|
|
3
3
|
import { ValueComparator } from './base/ValueComparator';
|
|
4
4
|
import { BPTreeTransaction } from './base/BPTreeTransaction';
|
|
@@ -16,17 +16,9 @@ export declare class BPTreePureSync<K, V> {
|
|
|
16
16
|
private _readCtx;
|
|
17
17
|
private _createCtx;
|
|
18
18
|
init(): void;
|
|
19
|
-
|
|
20
|
-
* Returns the ID of the root node.
|
|
21
|
-
*/
|
|
19
|
+
getRootNode(): BPTreeUnknownNode<K, V>;
|
|
22
20
|
getRootId(): string;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the order of the B+Tree.
|
|
25
|
-
*/
|
|
26
21
|
getOrder(): number;
|
|
27
|
-
/**
|
|
28
|
-
* Verified if the value satisfies the condition.
|
|
29
|
-
*/
|
|
30
22
|
verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
|
|
31
23
|
get(key: K): V | undefined;
|
|
32
24
|
exists(key: K, value: V): boolean;
|
|
@@ -57,6 +57,11 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
57
57
|
* @returns An array of keys that are in conflict. Empty array if no conflicts.
|
|
58
58
|
*/
|
|
59
59
|
static CheckConflicts<K, V>(transactions: BPTreeTransaction<K, V>[]): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Returns the root node of the B+Tree.
|
|
62
|
+
* @returns The root node.
|
|
63
|
+
*/
|
|
64
|
+
abstract getRootNode(): Deferred<BPTreeUnknownNode<K, V>>;
|
|
60
65
|
/**
|
|
61
66
|
* Returns the ID of the root node.
|
|
62
67
|
* @returns The root node ID.
|
|
@@ -20,6 +20,7 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeTransaction<K, V
|
|
|
20
20
|
constructor(rootTx: BPTreeAsyncTransaction<K, V> | null, mvccRoot: AsyncBPTreeMVCC<K, V>, mvcc: AsyncBPTreeMVCC<K, V>, strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
21
21
|
private _initAlgoContext;
|
|
22
22
|
protected writeLock<T>(id: number, fn: () => Promise<T>): Promise<T>;
|
|
23
|
+
getRootNode(): Promise<BPTreeUnknownNode<K, V>>;
|
|
23
24
|
protected getNode(id: string): Promise<BPTreeUnknownNode<K, V>>;
|
|
24
25
|
protected _createNode(leaf: boolean, keys: string[] | K[][], values: V[], parent?: string | null, next?: string | null, prev?: string | null): Promise<BPTreeUnknownNode<K, V>>;
|
|
25
26
|
protected _updateNode(node: BPTreeUnknownNode<K, V>): Promise<void>;
|
|
@@ -17,6 +17,7 @@ export declare class BPTreeSyncTransaction<K, V> extends BPTreeTransaction<K, V>
|
|
|
17
17
|
private _searchConfigsCached;
|
|
18
18
|
constructor(rootTx: BPTreeSyncTransaction<K, V>, mvccRoot: SyncBPTreeMVCC<K, V>, mvcc: SyncBPTreeMVCC<K, V>, strategy: SerializeStrategySync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
19
19
|
private _initAlgoContext;
|
|
20
|
+
getRootNode(): BPTreeUnknownNode<K, V>;
|
|
20
21
|
protected getNode(id: string): BPTreeUnknownNode<K, V>;
|
|
21
22
|
protected _createNode(leaf: boolean, keys: string[] | K[][], values: V[], parent?: string | null, next?: string | null, prev?: string | null): BPTreeUnknownNode<K, V>;
|
|
22
23
|
protected _updateNode(node: BPTreeUnknownNode<K, V>): void;
|