dataply 0.0.26-alpha.1 → 0.0.26-alpha.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.js +243 -45
- package/dist/types/index.d.ts +2 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -49,6 +49,8 @@ __export(src_exports, {
|
|
|
49
49
|
IndexPageManager: () => IndexPageManager,
|
|
50
50
|
InvertedWeakMap: () => InvertedWeakMap,
|
|
51
51
|
LRUMap: () => LRUMap2,
|
|
52
|
+
Logger: () => Logger,
|
|
53
|
+
LoggerManager: () => LoggerManager,
|
|
52
54
|
MVCCStrategy: () => MVCCStrategy2,
|
|
53
55
|
MVCCTransaction: () => MVCCTransaction2,
|
|
54
56
|
MetadataPageManager: () => MetadataPageManager,
|
|
@@ -1954,30 +1956,22 @@ var BPTreeTransaction = class _BPTreeTransaction {
|
|
|
1954
1956
|
*/
|
|
1955
1957
|
_insertValueIntoLeaf(leaf, key, value) {
|
|
1956
1958
|
if (leaf.values.length) {
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
if (
|
|
1960
|
-
|
|
1961
|
-
return false;
|
|
1962
|
-
}
|
|
1963
|
-
leaf.keys[i].push(key);
|
|
1964
|
-
return true;
|
|
1965
|
-
} else if (this.comparator.isLower(value, nValue)) {
|
|
1966
|
-
leaf.values.splice(i, 0, value);
|
|
1967
|
-
leaf.keys.splice(i, 0, [key]);
|
|
1968
|
-
return true;
|
|
1969
|
-
} else if (i + 1 === leaf.values.length) {
|
|
1970
|
-
leaf.values.push(value);
|
|
1971
|
-
leaf.keys.push([key]);
|
|
1972
|
-
return true;
|
|
1959
|
+
const { index, found } = this._binarySearchValues(leaf.values, value);
|
|
1960
|
+
if (found) {
|
|
1961
|
+
if (leaf.keys[index].includes(key)) {
|
|
1962
|
+
return false;
|
|
1973
1963
|
}
|
|
1964
|
+
leaf.keys[index].push(key);
|
|
1965
|
+
return true;
|
|
1974
1966
|
}
|
|
1967
|
+
leaf.values.splice(index, 0, value);
|
|
1968
|
+
leaf.keys.splice(index, 0, [key]);
|
|
1969
|
+
return true;
|
|
1975
1970
|
} else {
|
|
1976
1971
|
leaf.values = [value];
|
|
1977
1972
|
leaf.keys = [[key]];
|
|
1978
1973
|
return true;
|
|
1979
1974
|
}
|
|
1980
|
-
return false;
|
|
1981
1975
|
}
|
|
1982
1976
|
_cloneNode(node) {
|
|
1983
1977
|
return JSON.parse(JSON.stringify(node));
|
|
@@ -2268,12 +2262,8 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2268
2262
|
const midValue = parentNode.values[mid];
|
|
2269
2263
|
parentNode.values = parentNode.values.slice(0, mid);
|
|
2270
2264
|
parentNode.keys = parentNode.keys.slice(0, mid + 1);
|
|
2271
|
-
for (
|
|
2272
|
-
const
|
|
2273
|
-
n.parent = parentNode.id;
|
|
2274
|
-
this._updateNode(n);
|
|
2275
|
-
}
|
|
2276
|
-
for (const k of newSiblingNodeRecursive.keys) {
|
|
2265
|
+
for (let i = 0, len = newSiblingNodeRecursive.keys.length; i < len; i++) {
|
|
2266
|
+
const k = newSiblingNodeRecursive.keys[i];
|
|
2277
2267
|
const n = this._cloneNode(this.getNode(k));
|
|
2278
2268
|
n.parent = newSiblingNodeRecursive.id;
|
|
2279
2269
|
this._updateNode(n);
|
|
@@ -2355,7 +2345,7 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2355
2345
|
for (let i = 0; i < len; i++) {
|
|
2356
2346
|
const nValue = node.values[i];
|
|
2357
2347
|
const keys = node.keys[i];
|
|
2358
|
-
for (let j = 0,
|
|
2348
|
+
for (let j = 0, len2 = keys.length; j < len2; j++) {
|
|
2359
2349
|
yield [keys[j], nValue];
|
|
2360
2350
|
}
|
|
2361
2351
|
}
|
|
@@ -2434,7 +2424,7 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2434
2424
|
while (true) {
|
|
2435
2425
|
for (let i = 0, len = node.values.length; i < len; i++) {
|
|
2436
2426
|
const keys = node.keys[i];
|
|
2437
|
-
for (let j = 0,
|
|
2427
|
+
for (let j = 0, len2 = keys.length; j < len2; j++) {
|
|
2438
2428
|
if (keys[j] === key) {
|
|
2439
2429
|
return node.values[i];
|
|
2440
2430
|
}
|
|
@@ -2543,8 +2533,16 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2543
2533
|
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
2544
2534
|
let currentLeaf = null;
|
|
2545
2535
|
let modified = false;
|
|
2546
|
-
|
|
2547
|
-
|
|
2536
|
+
let cachedLeafId = null;
|
|
2537
|
+
let cachedLeafMaxValue = null;
|
|
2538
|
+
for (let i = 0, len = sorted.length; i < len; i++) {
|
|
2539
|
+
const [key, value] = sorted[i];
|
|
2540
|
+
let targetLeaf;
|
|
2541
|
+
if (cachedLeafId !== null && cachedLeafMaxValue !== null && currentLeaf !== null && (this.comparator.isLower(value, cachedLeafMaxValue) || this.comparator.isSame(value, cachedLeafMaxValue))) {
|
|
2542
|
+
targetLeaf = currentLeaf;
|
|
2543
|
+
} else {
|
|
2544
|
+
targetLeaf = this.locateLeaf(value);
|
|
2545
|
+
}
|
|
2548
2546
|
if (currentLeaf !== null && currentLeaf.id === targetLeaf.id) {
|
|
2549
2547
|
} else {
|
|
2550
2548
|
if (currentLeaf !== null && modified) {
|
|
@@ -2553,8 +2551,10 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2553
2551
|
currentLeaf = this._cloneNode(targetLeaf);
|
|
2554
2552
|
modified = false;
|
|
2555
2553
|
}
|
|
2554
|
+
cachedLeafId = currentLeaf.id;
|
|
2556
2555
|
const changed = this._insertValueIntoLeaf(currentLeaf, key, value);
|
|
2557
2556
|
modified = modified || changed;
|
|
2557
|
+
cachedLeafMaxValue = currentLeaf.values[currentLeaf.values.length - 1];
|
|
2558
2558
|
if (currentLeaf.values.length === this.order) {
|
|
2559
2559
|
this._updateNode(currentLeaf);
|
|
2560
2560
|
let after = this._createNode(
|
|
@@ -2575,6 +2575,8 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2575
2575
|
this._updateNode(after);
|
|
2576
2576
|
this._insertInParent(currentLeaf, after.values[0], after);
|
|
2577
2577
|
currentLeaf = null;
|
|
2578
|
+
cachedLeafId = null;
|
|
2579
|
+
cachedLeafMaxValue = null;
|
|
2578
2580
|
modified = false;
|
|
2579
2581
|
}
|
|
2580
2582
|
}
|
|
@@ -2582,6 +2584,85 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2582
2584
|
this._updateNode(currentLeaf);
|
|
2583
2585
|
}
|
|
2584
2586
|
}
|
|
2587
|
+
bulkLoad(entries) {
|
|
2588
|
+
if (entries.length === 0) return;
|
|
2589
|
+
const root = this.getNode(this.rootId);
|
|
2590
|
+
if (!root.leaf || root.values.length > 0) {
|
|
2591
|
+
throw new Error("bulkLoad can only be called on an empty tree. Use batchInsert for non-empty trees.");
|
|
2592
|
+
}
|
|
2593
|
+
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
2594
|
+
const grouped = [];
|
|
2595
|
+
for (let i = 0, len = sorted.length; i < len; i++) {
|
|
2596
|
+
const [key, value] = sorted[i];
|
|
2597
|
+
const last = grouped[grouped.length - 1];
|
|
2598
|
+
if (last && this.comparator.isSame(last.value, value)) {
|
|
2599
|
+
if (!last.keys.includes(key)) {
|
|
2600
|
+
last.keys.push(key);
|
|
2601
|
+
}
|
|
2602
|
+
} else {
|
|
2603
|
+
grouped.push({ keys: [key], value });
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
this._deleteNode(root);
|
|
2607
|
+
const maxLeafSize = this.order - 1;
|
|
2608
|
+
const leaves = [];
|
|
2609
|
+
for (let i = 0, len = grouped.length; i < len; i += maxLeafSize) {
|
|
2610
|
+
const chunk = grouped.slice(i, i + maxLeafSize);
|
|
2611
|
+
const leafKeys = chunk.map((g) => g.keys);
|
|
2612
|
+
const leafValues = chunk.map((g) => g.value);
|
|
2613
|
+
const leaf = this._createNode(
|
|
2614
|
+
true,
|
|
2615
|
+
leafKeys,
|
|
2616
|
+
leafValues,
|
|
2617
|
+
null,
|
|
2618
|
+
null,
|
|
2619
|
+
null
|
|
2620
|
+
);
|
|
2621
|
+
leaves.push(leaf);
|
|
2622
|
+
}
|
|
2623
|
+
for (let i = 0, len = leaves.length; i < len; i++) {
|
|
2624
|
+
if (i > 0) {
|
|
2625
|
+
leaves[i].prev = leaves[i - 1].id;
|
|
2626
|
+
}
|
|
2627
|
+
if (i < len - 1) {
|
|
2628
|
+
leaves[i].next = leaves[i + 1].id;
|
|
2629
|
+
}
|
|
2630
|
+
this._updateNode(leaves[i]);
|
|
2631
|
+
}
|
|
2632
|
+
let currentLevel = leaves;
|
|
2633
|
+
while (currentLevel.length > 1) {
|
|
2634
|
+
const nextLevel = [];
|
|
2635
|
+
for (let i = 0, len = currentLevel.length; i < len; i += this.order) {
|
|
2636
|
+
const children = currentLevel.slice(i, i + this.order);
|
|
2637
|
+
const childIds = children.map((c) => c.id);
|
|
2638
|
+
const separators = [];
|
|
2639
|
+
for (let j = 1, len2 = children.length; j < len2; j++) {
|
|
2640
|
+
separators.push(children[j].values[0]);
|
|
2641
|
+
}
|
|
2642
|
+
const internalNode = this._createNode(
|
|
2643
|
+
false,
|
|
2644
|
+
childIds,
|
|
2645
|
+
separators,
|
|
2646
|
+
null,
|
|
2647
|
+
null,
|
|
2648
|
+
null
|
|
2649
|
+
);
|
|
2650
|
+
for (let j = 0, len2 = children.length; j < len2; j++) {
|
|
2651
|
+
const child = children[j];
|
|
2652
|
+
child.parent = internalNode.id;
|
|
2653
|
+
this._updateNode(child);
|
|
2654
|
+
}
|
|
2655
|
+
nextLevel.push(internalNode);
|
|
2656
|
+
}
|
|
2657
|
+
currentLevel = nextLevel;
|
|
2658
|
+
}
|
|
2659
|
+
const newRoot = currentLevel[0];
|
|
2660
|
+
this._writeHead({
|
|
2661
|
+
root: newRoot.id,
|
|
2662
|
+
order: this.order,
|
|
2663
|
+
data: this.strategy.head.data
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2585
2666
|
_deleteEntry(node, key) {
|
|
2586
2667
|
if (!node.leaf) {
|
|
2587
2668
|
let keyIndex = -1;
|
|
@@ -2685,7 +2766,8 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2685
2766
|
siblingNode.values.push(...node.values);
|
|
2686
2767
|
if (!siblingNode.leaf) {
|
|
2687
2768
|
const keys = siblingNode.keys;
|
|
2688
|
-
for (
|
|
2769
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
2770
|
+
const key2 = keys[i];
|
|
2689
2771
|
const node2 = this._cloneNode(this.getNode(key2));
|
|
2690
2772
|
node2.parent = siblingNode.id;
|
|
2691
2773
|
this._updateNode(node2);
|
|
@@ -2753,21 +2835,24 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2753
2835
|
this._updateNode(siblingNode);
|
|
2754
2836
|
}
|
|
2755
2837
|
if (!siblingNode.leaf) {
|
|
2756
|
-
for (
|
|
2838
|
+
for (let i = 0, len = siblingNode.keys.length; i < len; i++) {
|
|
2839
|
+
const key2 = siblingNode.keys[i];
|
|
2757
2840
|
const n = this._cloneNode(this.getNode(key2));
|
|
2758
2841
|
n.parent = siblingNode.id;
|
|
2759
2842
|
this._updateNode(n);
|
|
2760
2843
|
}
|
|
2761
2844
|
}
|
|
2762
2845
|
if (!node.leaf) {
|
|
2763
|
-
for (
|
|
2846
|
+
for (let i = 0, len = node.keys.length; i < len; i++) {
|
|
2847
|
+
const key2 = node.keys[i];
|
|
2764
2848
|
const n = this._cloneNode(this.getNode(key2));
|
|
2765
2849
|
n.parent = node.id;
|
|
2766
2850
|
this._updateNode(n);
|
|
2767
2851
|
}
|
|
2768
2852
|
}
|
|
2769
2853
|
if (!parentNode.leaf) {
|
|
2770
|
-
for (
|
|
2854
|
+
for (let i = 0, len = parentNode.keys.length; i < len; i++) {
|
|
2855
|
+
const key2 = parentNode.keys[i];
|
|
2771
2856
|
const n = this._cloneNode(this.getNode(key2));
|
|
2772
2857
|
n.parent = parentNode.id;
|
|
2773
2858
|
this._updateNode(n);
|
|
@@ -2941,6 +3026,14 @@ var BPTreeSync = class extends BPTreeSyncTransaction {
|
|
|
2941
3026
|
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
2942
3027
|
}
|
|
2943
3028
|
}
|
|
3029
|
+
bulkLoad(entries) {
|
|
3030
|
+
const tx = this.createTransaction();
|
|
3031
|
+
tx.bulkLoad(entries);
|
|
3032
|
+
const result = tx.commit();
|
|
3033
|
+
if (!result.success) {
|
|
3034
|
+
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
2944
3037
|
};
|
|
2945
3038
|
var Ryoiki2 = class _Ryoiki2 {
|
|
2946
3039
|
readings;
|
|
@@ -3354,12 +3447,8 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3354
3447
|
const midValue = parentNode.values[mid];
|
|
3355
3448
|
parentNode.values = parentNode.values.slice(0, mid);
|
|
3356
3449
|
parentNode.keys = parentNode.keys.slice(0, mid + 1);
|
|
3357
|
-
for (
|
|
3358
|
-
const
|
|
3359
|
-
n.parent = parentNode.id;
|
|
3360
|
-
await this._updateNode(n);
|
|
3361
|
-
}
|
|
3362
|
-
for (const k of newSiblingNodeRecursive.keys) {
|
|
3450
|
+
for (let i = 0, len = newSiblingNodeRecursive.keys.length; i < len; i++) {
|
|
3451
|
+
const k = newSiblingNodeRecursive.keys[i];
|
|
3363
3452
|
const n = this._cloneNode(await this.getNode(k));
|
|
3364
3453
|
n.parent = newSiblingNodeRecursive.id;
|
|
3365
3454
|
await this._updateNode(n);
|
|
@@ -3451,7 +3540,7 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3451
3540
|
for (let i = 0; i < len; i++) {
|
|
3452
3541
|
const nValue = node.values[i];
|
|
3453
3542
|
const keys = node.keys[i];
|
|
3454
|
-
for (let j = 0,
|
|
3543
|
+
for (let j = 0, len2 = keys.length; j < len2; j++) {
|
|
3455
3544
|
yield [keys[j], nValue];
|
|
3456
3545
|
}
|
|
3457
3546
|
}
|
|
@@ -3529,7 +3618,7 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3529
3618
|
while (true) {
|
|
3530
3619
|
for (let i = 0, len = node.values.length; i < len; i++) {
|
|
3531
3620
|
const keys = node.keys[i];
|
|
3532
|
-
for (let j = 0,
|
|
3621
|
+
for (let j = 0, len2 = keys.length; j < len2; j++) {
|
|
3533
3622
|
if (keys[j] === key) {
|
|
3534
3623
|
return node.values[i];
|
|
3535
3624
|
}
|
|
@@ -3641,8 +3730,16 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3641
3730
|
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
3642
3731
|
let currentLeaf = null;
|
|
3643
3732
|
let modified = false;
|
|
3644
|
-
|
|
3645
|
-
|
|
3733
|
+
let cachedLeafId = null;
|
|
3734
|
+
let cachedLeafMaxValue = null;
|
|
3735
|
+
for (let i = 0, len = sorted.length; i < len; i++) {
|
|
3736
|
+
const [key, value] = sorted[i];
|
|
3737
|
+
let targetLeaf;
|
|
3738
|
+
if (cachedLeafId !== null && cachedLeafMaxValue !== null && currentLeaf !== null && (this.comparator.isLower(value, cachedLeafMaxValue) || this.comparator.isSame(value, cachedLeafMaxValue))) {
|
|
3739
|
+
targetLeaf = currentLeaf;
|
|
3740
|
+
} else {
|
|
3741
|
+
targetLeaf = await this.locateLeaf(value);
|
|
3742
|
+
}
|
|
3646
3743
|
if (currentLeaf !== null && currentLeaf.id === targetLeaf.id) {
|
|
3647
3744
|
} else {
|
|
3648
3745
|
if (currentLeaf !== null && modified) {
|
|
@@ -3651,8 +3748,10 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3651
3748
|
currentLeaf = this._cloneNode(targetLeaf);
|
|
3652
3749
|
modified = false;
|
|
3653
3750
|
}
|
|
3751
|
+
cachedLeafId = currentLeaf.id;
|
|
3654
3752
|
const changed = this._insertValueIntoLeaf(currentLeaf, key, value);
|
|
3655
3753
|
modified = modified || changed;
|
|
3754
|
+
cachedLeafMaxValue = currentLeaf.values[currentLeaf.values.length - 1];
|
|
3656
3755
|
if (currentLeaf.values.length === this.order) {
|
|
3657
3756
|
await this._updateNode(currentLeaf);
|
|
3658
3757
|
let after = await this._createNode(
|
|
@@ -3673,6 +3772,8 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3673
3772
|
await this._updateNode(after);
|
|
3674
3773
|
await this._insertInParent(currentLeaf, after.values[0], after);
|
|
3675
3774
|
currentLeaf = null;
|
|
3775
|
+
cachedLeafId = null;
|
|
3776
|
+
cachedLeafMaxValue = null;
|
|
3676
3777
|
modified = false;
|
|
3677
3778
|
}
|
|
3678
3779
|
}
|
|
@@ -3681,6 +3782,87 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3681
3782
|
}
|
|
3682
3783
|
});
|
|
3683
3784
|
}
|
|
3785
|
+
async bulkLoad(entries) {
|
|
3786
|
+
if (entries.length === 0) return;
|
|
3787
|
+
return this.writeLock(0, async () => {
|
|
3788
|
+
const root = await this.getNode(this.rootId);
|
|
3789
|
+
if (!root.leaf || root.values.length > 0) {
|
|
3790
|
+
throw new Error("bulkLoad can only be called on an empty tree. Use batchInsert for non-empty trees.");
|
|
3791
|
+
}
|
|
3792
|
+
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
3793
|
+
const grouped = [];
|
|
3794
|
+
for (let i = 0, len = sorted.length; i < len; i++) {
|
|
3795
|
+
const [key, value] = sorted[i];
|
|
3796
|
+
const last = grouped[grouped.length - 1];
|
|
3797
|
+
if (last && this.comparator.isSame(last.value, value)) {
|
|
3798
|
+
if (!last.keys.includes(key)) {
|
|
3799
|
+
last.keys.push(key);
|
|
3800
|
+
}
|
|
3801
|
+
} else {
|
|
3802
|
+
grouped.push({ keys: [key], value });
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
await this._deleteNode(root);
|
|
3806
|
+
const maxLeafSize = this.order - 1;
|
|
3807
|
+
const leaves = [];
|
|
3808
|
+
for (let i = 0, len = grouped.length; i < len; i += maxLeafSize) {
|
|
3809
|
+
const chunk = grouped.slice(i, i + maxLeafSize);
|
|
3810
|
+
const leafKeys = chunk.map((g) => g.keys);
|
|
3811
|
+
const leafValues = chunk.map((g) => g.value);
|
|
3812
|
+
const leaf = await this._createNode(
|
|
3813
|
+
true,
|
|
3814
|
+
leafKeys,
|
|
3815
|
+
leafValues,
|
|
3816
|
+
null,
|
|
3817
|
+
null,
|
|
3818
|
+
null
|
|
3819
|
+
);
|
|
3820
|
+
leaves.push(leaf);
|
|
3821
|
+
}
|
|
3822
|
+
for (let i = 0, len = leaves.length; i < len; i++) {
|
|
3823
|
+
if (i > 0) {
|
|
3824
|
+
leaves[i].prev = leaves[i - 1].id;
|
|
3825
|
+
}
|
|
3826
|
+
if (i < len - 1) {
|
|
3827
|
+
leaves[i].next = leaves[i + 1].id;
|
|
3828
|
+
}
|
|
3829
|
+
await this._updateNode(leaves[i]);
|
|
3830
|
+
}
|
|
3831
|
+
let currentLevel = leaves;
|
|
3832
|
+
while (currentLevel.length > 1) {
|
|
3833
|
+
const nextLevel = [];
|
|
3834
|
+
for (let i = 0, len = currentLevel.length; i < len; i += this.order) {
|
|
3835
|
+
const children = currentLevel.slice(i, i + this.order);
|
|
3836
|
+
const childIds = children.map((c) => c.id);
|
|
3837
|
+
const separators = [];
|
|
3838
|
+
for (let j = 1, len2 = children.length; j < len2; j++) {
|
|
3839
|
+
separators.push(children[j].values[0]);
|
|
3840
|
+
}
|
|
3841
|
+
const internalNode = await this._createNode(
|
|
3842
|
+
false,
|
|
3843
|
+
childIds,
|
|
3844
|
+
separators,
|
|
3845
|
+
null,
|
|
3846
|
+
null,
|
|
3847
|
+
null
|
|
3848
|
+
);
|
|
3849
|
+
for (let j = 0, len2 = children.length; j < len2; j++) {
|
|
3850
|
+
const child = children[j];
|
|
3851
|
+
child.parent = internalNode.id;
|
|
3852
|
+
await this._updateNode(child);
|
|
3853
|
+
}
|
|
3854
|
+
nextLevel.push(internalNode);
|
|
3855
|
+
}
|
|
3856
|
+
currentLevel = nextLevel;
|
|
3857
|
+
}
|
|
3858
|
+
const newRoot = currentLevel[0];
|
|
3859
|
+
await this._writeHead({
|
|
3860
|
+
root: newRoot.id,
|
|
3861
|
+
order: this.order,
|
|
3862
|
+
data: this.strategy.head.data
|
|
3863
|
+
});
|
|
3864
|
+
});
|
|
3865
|
+
}
|
|
3684
3866
|
async _deleteEntry(node, key) {
|
|
3685
3867
|
if (!node.leaf) {
|
|
3686
3868
|
let keyIndex = -1;
|
|
@@ -3784,7 +3966,8 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3784
3966
|
siblingNode.values.push(...node.values);
|
|
3785
3967
|
if (!siblingNode.leaf) {
|
|
3786
3968
|
const keys = siblingNode.keys;
|
|
3787
|
-
for (
|
|
3969
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
3970
|
+
const key2 = keys[i];
|
|
3788
3971
|
const node2 = this._cloneNode(await this.getNode(key2));
|
|
3789
3972
|
node2.parent = siblingNode.id;
|
|
3790
3973
|
await this._updateNode(node2);
|
|
@@ -3852,21 +4035,24 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3852
4035
|
await this._updateNode(siblingNode);
|
|
3853
4036
|
}
|
|
3854
4037
|
if (!siblingNode.leaf) {
|
|
3855
|
-
for (
|
|
4038
|
+
for (let i = 0, len = siblingNode.keys.length; i < len; i++) {
|
|
4039
|
+
const key2 = siblingNode.keys[i];
|
|
3856
4040
|
const n = this._cloneNode(await this.getNode(key2));
|
|
3857
4041
|
n.parent = siblingNode.id;
|
|
3858
4042
|
await this._updateNode(n);
|
|
3859
4043
|
}
|
|
3860
4044
|
}
|
|
3861
4045
|
if (!node.leaf) {
|
|
3862
|
-
for (
|
|
4046
|
+
for (let i = 0, len = node.keys.length; i < len; i++) {
|
|
4047
|
+
const key2 = node.keys[i];
|
|
3863
4048
|
const n = this._cloneNode(await this.getNode(key2));
|
|
3864
4049
|
n.parent = node.id;
|
|
3865
4050
|
await this._updateNode(n);
|
|
3866
4051
|
}
|
|
3867
4052
|
}
|
|
3868
4053
|
if (!parentNode.leaf) {
|
|
3869
|
-
for (
|
|
4054
|
+
for (let i = 0, len = parentNode.keys.length; i < len; i++) {
|
|
4055
|
+
const key2 = parentNode.keys[i];
|
|
3870
4056
|
const n = this._cloneNode(await this.getNode(key2));
|
|
3871
4057
|
n.parent = parentNode.id;
|
|
3872
4058
|
await this._updateNode(n);
|
|
@@ -4048,6 +4234,16 @@ var BPTreeAsync = class extends BPTreeAsyncTransaction {
|
|
|
4048
4234
|
}
|
|
4049
4235
|
});
|
|
4050
4236
|
}
|
|
4237
|
+
async bulkLoad(entries) {
|
|
4238
|
+
return this.writeLock(1, async () => {
|
|
4239
|
+
const tx = await this.createTransaction();
|
|
4240
|
+
await tx.bulkLoad(entries);
|
|
4241
|
+
const result = await tx.commit();
|
|
4242
|
+
if (!result.success) {
|
|
4243
|
+
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
4244
|
+
}
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4051
4247
|
};
|
|
4052
4248
|
var SerializeStrategy = class {
|
|
4053
4249
|
order;
|
|
@@ -10528,6 +10724,8 @@ var GlobalTransaction = class {
|
|
|
10528
10724
|
IndexPageManager,
|
|
10529
10725
|
InvertedWeakMap,
|
|
10530
10726
|
LRUMap,
|
|
10727
|
+
Logger,
|
|
10728
|
+
LoggerManager,
|
|
10531
10729
|
MVCCStrategy,
|
|
10532
10730
|
MVCCTransaction,
|
|
10533
10731
|
MetadataPageManager,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ export * from 'serializable-bptree';
|
|
|
2
2
|
export * from 'ryoiki';
|
|
3
3
|
export * from 'cache-entanglement';
|
|
4
4
|
export * from 'mvcc-api';
|
|
5
|
-
export type { DataplyOptions } from './types';
|
|
5
|
+
export type { DataplyOptions, LogLevel } from './types';
|
|
6
6
|
export * from './core/Page';
|
|
7
7
|
export { Dataply } from './core/Dataply';
|
|
8
8
|
export { DataplyAPI } from './core/DataplyAPI';
|
|
9
9
|
export { Transaction } from './core/transaction/Transaction';
|
|
10
10
|
export { GlobalTransaction } from './core/transaction/GlobalTransaction';
|
|
11
|
+
export { Logger, LoggerManager } from './core/Logger';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataply",
|
|
3
|
-
"version": "0.0.26-alpha.
|
|
3
|
+
"version": "0.0.26-alpha.3",
|
|
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.5",
|
|
51
51
|
"ryoiki": "^1.2.0",
|
|
52
|
-
"serializable-bptree": "^8.
|
|
52
|
+
"serializable-bptree": "^8.4.0"
|
|
53
53
|
}
|
|
54
54
|
}
|