localdb-ces6q 0.0.4 → 0.0.5
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/LocalDB.d.ts +2 -2
- package/LocalDB.js +19 -19
- package/package.json +2 -1
package/LocalDB.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
import { BTree } from 'bplustree-mq4uj/btree.js';
|
1
2
|
import { Debounce } from 'util-3gcvv/class/Debounce.js';
|
2
|
-
import { SortedArray } from 'util-3gcvv/class/SortedArray.js';
|
3
3
|
import { LocalDBState } from './LocalDBState.js';
|
4
4
|
import type { KeyOf } from 'util-3gcvv/types/types.js';
|
5
5
|
import type { Collection, Collections, CollectionsChange, CollectionsChangeMap, ColListener, DBListener, DocListener, FieldListener, ICollectionConfig, ICollectionsConfig, ICollectionsFields, IDBOperation, IDBOperationHistoryItem, IDBQuery, IDBTxOptions, IDocument } from './types.js';
|
@@ -13,7 +13,7 @@ export declare class LocalDB<CollectionTypes extends Record<string, IDocument>>
|
|
13
13
|
[ColName in KeyOf<CollectionTypes>]: Debounce<() => void>;
|
14
14
|
};
|
15
15
|
protected _indexes: {
|
16
|
-
[ColName in KeyOf<CollectionTypes>]: Record<string,
|
16
|
+
[ColName in KeyOf<CollectionTypes>]: Record<string, BTree<CollectionTypes[ColName], CollectionTypes[ColName]>>;
|
17
17
|
};
|
18
18
|
protected _txChangedFields: CollectionsChangeMap<CollectionTypes>;
|
19
19
|
protected _txChanges: CollectionsChange<CollectionTypes>;
|
package/LocalDB.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
import { BTree } from 'bplustree-mq4uj/btree.js';
|
1
2
|
import { Debounce } from 'util-3gcvv/class/Debounce.js';
|
2
|
-
import { SortedArray } from 'util-3gcvv/class/SortedArray.js';
|
3
3
|
import { deepEqual } from 'util-3gcvv/deepEqual.js';
|
4
4
|
import { objectEmpty, objectKeys } from 'util-3gcvv/object.js';
|
5
5
|
import { randomString } from 'util-3gcvv/string.js';
|
@@ -57,7 +57,7 @@ export class LocalDB {
|
|
57
57
|
for (let col in this._indexes) {
|
58
58
|
const indexes = this._indexes[col];
|
59
59
|
for (let name in indexes) {
|
60
|
-
indexes[name].
|
60
|
+
indexes[name].clear();
|
61
61
|
}
|
62
62
|
}
|
63
63
|
this._indexes = {};
|
@@ -135,7 +135,7 @@ export class LocalDB {
|
|
135
135
|
if (!comparator) {
|
136
136
|
throw new Error(`Comparator must be set to index ${col}/${field}`);
|
137
137
|
}
|
138
|
-
fieldIndexes[field] = new
|
138
|
+
fieldIndexes[field] = new BTree(docs.map((d) => [d, d]), (a, b) => comparator(a[field], b[field]));
|
139
139
|
}
|
140
140
|
}
|
141
141
|
this._indexes[col] = fieldIndexes;
|
@@ -287,7 +287,7 @@ export class LocalDB {
|
|
287
287
|
if (!(index in col)) {
|
288
288
|
throw new Error(`index ${colName}/${index} not found`);
|
289
289
|
}
|
290
|
-
return col[index].
|
290
|
+
return col[index].valuesArray();
|
291
291
|
}
|
292
292
|
query({ collection, orderBy, limit, startAfter, startAt, endAfter, endAt, }) {
|
293
293
|
const col = this._indexes[collection];
|
@@ -296,7 +296,7 @@ export class LocalDB {
|
|
296
296
|
}
|
297
297
|
const index = col[orderBy];
|
298
298
|
// TODO
|
299
|
-
return index.
|
299
|
+
return index.valuesArray();
|
300
300
|
}
|
301
301
|
//
|
302
302
|
// Set / Update
|
@@ -353,12 +353,12 @@ export class LocalDB {
|
|
353
353
|
// update indexes
|
354
354
|
const indexes = this._indexes[colName];
|
355
355
|
for (let indexName in indexes) {
|
356
|
-
indexes[indexName].
|
356
|
+
indexes[indexName].set(next, next, true);
|
357
357
|
}
|
358
358
|
this._txRollbacks.push(() => {
|
359
359
|
const indexes = this._indexes[colName];
|
360
360
|
for (let indexName in indexes) {
|
361
|
-
indexes[indexName].
|
361
|
+
indexes[indexName].delete(next);
|
362
362
|
}
|
363
363
|
});
|
364
364
|
// update undo history
|
@@ -556,14 +556,14 @@ export class LocalDB {
|
|
556
556
|
// update indexes
|
557
557
|
const indexes = this._indexes[colName];
|
558
558
|
for (let indexName in indexes) {
|
559
|
-
indexes[indexName].
|
560
|
-
indexes[indexName].
|
559
|
+
indexes[indexName].delete(prev);
|
560
|
+
indexes[indexName].set(next, next, true);
|
561
561
|
}
|
562
562
|
this._txRollbacks.push(() => {
|
563
563
|
const indexes = this._indexes[colName];
|
564
564
|
for (let indexName in indexes) {
|
565
|
-
indexes[indexName].
|
566
|
-
indexes[indexName].
|
565
|
+
indexes[indexName].delete(next);
|
566
|
+
indexes[indexName].set(prev, prev, true);
|
567
567
|
}
|
568
568
|
});
|
569
569
|
// update undo history
|
@@ -652,14 +652,14 @@ export class LocalDB {
|
|
652
652
|
// update indexes
|
653
653
|
const indexes = this._indexes[colName];
|
654
654
|
for (let indexName in indexes) {
|
655
|
-
indexes[indexName].
|
656
|
-
indexes[indexName].
|
655
|
+
indexes[indexName].deleteKeys(prevDocs);
|
656
|
+
indexes[indexName].setPairs(nextDocs.map((doc) => [doc, doc]), true);
|
657
657
|
}
|
658
658
|
this._txRollbacks.push(() => {
|
659
659
|
const indexes = this._indexes[colName];
|
660
660
|
for (let indexName in indexes) {
|
661
|
-
indexes[indexName].
|
662
|
-
indexes[indexName].
|
661
|
+
indexes[indexName].deleteKeys(nextDocs);
|
662
|
+
indexes[indexName].setPairs(prevDocs.map((doc) => [doc, doc]), true);
|
663
663
|
}
|
664
664
|
});
|
665
665
|
// update undo history
|
@@ -715,12 +715,12 @@ export class LocalDB {
|
|
715
715
|
// update indexes
|
716
716
|
const indexes = this._indexes[colName];
|
717
717
|
for (let indexName in indexes) {
|
718
|
-
indexes[indexName].
|
718
|
+
indexes[indexName].delete(prev);
|
719
719
|
}
|
720
720
|
this._txRollbacks.push(() => {
|
721
721
|
const indexes = this._indexes[colName];
|
722
722
|
for (let indexName in indexes) {
|
723
|
-
indexes[indexName].
|
723
|
+
indexes[indexName].set(prev, prev, true);
|
724
724
|
}
|
725
725
|
});
|
726
726
|
// update undo history
|
@@ -786,12 +786,12 @@ export class LocalDB {
|
|
786
786
|
// update indexes
|
787
787
|
const indexes = this._indexes[colName];
|
788
788
|
for (let indexName in indexes) {
|
789
|
-
indexes[indexName].
|
789
|
+
indexes[indexName].deleteKeys(prevDocs);
|
790
790
|
}
|
791
791
|
this._txRollbacks.push(() => {
|
792
792
|
const indexes = this._indexes[colName];
|
793
793
|
for (let indexName in indexes) {
|
794
|
-
indexes[indexName].
|
794
|
+
indexes[indexName].setPairs(prevDocs.map((d) => [d, d]), true);
|
795
795
|
}
|
796
796
|
});
|
797
797
|
// update undo history
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "localdb-ces6q",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.5",
|
4
4
|
"description": "TypeScript ECMAScript Module Library Template",
|
5
5
|
"type": "module",
|
6
6
|
"module": "dist/index.js",
|
@@ -26,6 +26,7 @@
|
|
26
26
|
},
|
27
27
|
"homepage": "https://github.com/joonhocho/localdb#readme",
|
28
28
|
"dependencies": {
|
29
|
+
"bplustree-mq4uj": "^0.0.2",
|
29
30
|
"util-3gcvv": "^0.4.7"
|
30
31
|
},
|
31
32
|
"devDependencies": {
|