diff options
Diffstat (limited to 'packages/idb-bridge')
-rw-r--r-- | packages/idb-bridge/package.json | 13 | ||||
-rw-r--r-- | packages/idb-bridge/src/index.ts | 47 | ||||
-rw-r--r-- | packages/idb-bridge/src/tree/b+tree.ts | 105 | ||||
-rw-r--r-- | packages/idb-bridge/src/util/FakeEventTarget.ts | 2 | ||||
-rw-r--r-- | packages/idb-bridge/src/util/normalizeKeyPath.ts | 2 | ||||
-rw-r--r-- | packages/idb-bridge/tsconfig.json | 4 |
6 files changed, 90 insertions, 83 deletions
diff --git a/packages/idb-bridge/package.json b/packages/idb-bridge/package.json index 51e69143a..a8872a191 100644 --- a/packages/idb-bridge/package.json +++ b/packages/idb-bridge/package.json @@ -16,20 +16,25 @@ "clean": "rimraf dist lib tsconfig.tsbuildinfo", "pretty": "prettier --write src" }, + "exports": { + ".": { + "default": "./lib/index.js" + } + }, "devDependencies": { "@rollup/plugin-commonjs": "^22.0.2", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", - "@types/node": "^17.0.17", - "ava": "^4.0.1", + "@types/node": "^18.8.5", + "ava": "^4.3.3", "esm": "^3.2.25", "prettier": "^2.5.1", "rimraf": "^3.0.2", "rollup": "^2.79.0", - "typescript": "^4.8.2" + "typescript": "^4.8.4" }, "dependencies": { - "tslib": "^2.3.1" + "tslib": "^2.4.0" }, "ava": { "require": [ diff --git a/packages/idb-bridge/src/index.ts b/packages/idb-bridge/src/index.ts index 50642e67b..fc99b2ccd 100644 --- a/packages/idb-bridge/src/index.ts +++ b/packages/idb-bridge/src/index.ts @@ -1,26 +1,17 @@ import { + Backend, + DatabaseConnection, DatabaseTransaction, - RecordGetResponse, + IndexProperties, + ObjectStoreProperties, RecordGetRequest, - Schema, - Backend, + RecordGetResponse, RecordStoreRequest, RecordStoreResponse, - DatabaseConnection, - ObjectStoreProperties, - StoreLevel, ResultLevel, - IndexProperties, -} from "./backend-interface"; -import { Listener } from "./util/FakeEventTarget"; -import { - DatabaseDump, - ObjectStoreDump, - IndexRecord, - ObjectStoreRecord, - MemoryBackendDump, -} from "./MemoryBackend"; -import { Event, IDBKeyRange } from "./idbtypes"; + Schema, + StoreLevel, +} from "./backend-interface.js"; import { BridgeIDBCursor, BridgeIDBDatabase, @@ -34,8 +25,21 @@ import { BridgeIDBVersionChangeEvent, DatabaseList, RequestObj, -} from "./bridge-idb"; +} from "./bridge-idb.js"; +import { Event } from "./idbtypes.js"; +import { + DatabaseDump, + IndexRecord, + MemoryBackendDump, + ObjectStoreDump, + ObjectStoreRecord, +} from "./MemoryBackend.js"; +import { Listener } from "./util/FakeEventTarget.js"; +export * from "./idbtypes.js"; +export { MemoryBackend } from "./MemoryBackend.js"; +export type { AccessStats } from "./MemoryBackend.js"; +export * from "./util/structuredClone.js"; export { BridgeIDBCursor, BridgeIDBDatabase, @@ -71,9 +75,6 @@ export type { Listener, }; -export { MemoryBackend } from "./MemoryBackend"; -export type { AccessStats } from "./MemoryBackend"; - // globalThis polyfill, see https://mathiasbynens.be/notes/globalthis (function () { if (typeof globalThis === "object") return; @@ -123,7 +124,3 @@ export function shimIndexedDB(factory: BridgeIDBFactory): void { g.IDBTransaction = BridgeIDBTransaction; g.IDBVersionChangeEvent = BridgeIDBVersionChangeEvent; } - -export * from "./idbtypes"; - -export * from "./util/structuredClone"; diff --git a/packages/idb-bridge/src/tree/b+tree.ts b/packages/idb-bridge/src/tree/b+tree.ts index fa0823526..c51360d70 100644 --- a/packages/idb-bridge/src/tree/b+tree.ts +++ b/packages/idb-bridge/src/tree/b+tree.ts @@ -1,22 +1,22 @@ // B+ tree by David Piepgrass. License: MIT -import { ISortedMap, ISortedMapF } from "./interfaces"; +import { ISortedMap, ISortedMapF } from "./interfaces.js"; export type { - ISetSource, - ISetSink, - ISet, - ISetF, - ISortedSetSource, - ISortedSet, - ISortedSetF, - IMapSource, - IMapSink, IMap, IMapF, - ISortedMapSource, + IMapSink, + IMapSource, + ISet, + ISetF, + ISetSink, + ISetSource, ISortedMap, ISortedMapF, -} from "./interfaces"; + ISortedMapSource, + ISortedSet, + ISortedSetF, + ISortedSetSource, +} from "./interfaces.js"; export type EditRangeResult<V, R = number> = { value?: V; @@ -59,15 +59,15 @@ export type DefaultComparable = | undefined | (number | string)[] | { - valueOf: () => - | number - | string - | Date - | boolean - | null - | undefined - | (number | string)[]; - }; + valueOf: () => + | number + | string + | Date + | boolean + | null + | undefined + | (number | string)[]; + }; /** * Compares DefaultComparables to form a strict partial ordering. @@ -216,7 +216,8 @@ export function simpleComparator(a: any, b: any): number { * @author David Piepgrass */ export default class BTree<K = any, V = any> - implements ISortedMapF<K, V>, ISortedMap<K, V> { + implements ISortedMapF<K, V>, ISortedMap<K, V> +{ private _root: BNode<K, V> = EmptyLeaf as BNode<K, V>; _size: number = 0; _maxNodeSize: number; @@ -242,7 +243,7 @@ export default class BTree<K = any, V = any> ) { this._maxNodeSize = maxNodeSize! >= 4 ? Math.min(maxNodeSize!, 256) : 32; this._compare = - compare || ((defaultComparator as any) as (a: K, b: K) => number); + compare || (defaultComparator as any as (a: K, b: K) => number); if (entries) this.setPairs(entries); } @@ -463,7 +464,7 @@ export default class BTree<K = any, V = any> nu.editAll((k, v, i) => { return (tmp.value = callback(v, k, i)), tmp as any; }); - return (nu as any) as BTree<K, R>; + return nu as any as BTree<K, R>; } /** Performs a reduce operation like the `reduce` method of `Array`. @@ -534,7 +535,7 @@ export default class BTree<K = any, V = any> : leaf.indexOf(lowestKey, 0, this._compare) - 1; return iterator<[K, V]>(() => { - jump: for (; ;) { + jump: for (;;) { switch (state) { case 0: if (++i < leaf.keys.length) @@ -550,7 +551,7 @@ export default class BTree<K = any, V = any> state = 2; case 2: // Advance to the next leaf node - for (var level = -1; ;) { + for (var level = -1; ; ) { if (++level >= nodequeue.length) { state = 3; continue jump; @@ -558,9 +559,9 @@ export default class BTree<K = any, V = any> if (++nodeindex[level] < nodequeue[level].length) break; } for (; level > 0; level--) { - nodequeue[level - 1] = (nodequeue[level][ - nodeindex[level] - ] as BNodeInternal<K, V>).children; + nodequeue[level - 1] = ( + nodequeue[level][nodeindex[level]] as BNodeInternal<K, V> + ).children; nodeindex[level - 1] = 0; } leaf = nodequeue[0][nodeindex[0]]; @@ -606,7 +607,7 @@ export default class BTree<K = any, V = any> var state = reusedArray !== undefined ? 1 : 0; return iterator<[K, V]>(() => { - jump: for (; ;) { + jump: for (;;) { switch (state) { case 0: if (--i >= 0) @@ -622,7 +623,7 @@ export default class BTree<K = any, V = any> state = 2; case 2: // Advance to the next leaf node - for (var level = -1; ;) { + for (var level = -1; ; ) { if (++level >= nodequeue.length) { state = 3; continue jump; @@ -630,9 +631,9 @@ export default class BTree<K = any, V = any> if (--nodeindex[level] >= 0) break; } for (; level > 0; level--) { - nodequeue[level - 1] = (nodequeue[level][ - nodeindex[level] - ] as BNodeInternal<K, V>).children; + nodequeue[level - 1] = ( + nodequeue[level][nodeindex[level]] as BNodeInternal<K, V> + ).children; nodeindex[level - 1] = nodequeue[level - 1].length - 1; } leaf = nodequeue[0][nodeindex[0]]; @@ -763,7 +764,7 @@ export default class BTree<K = any, V = any> thisLeaf.values[thisLevelIndices[thisLevelIndices.length - 1]]; const valOther = otherLeaf.values[ - otherLevelIndices[otherLevelIndices.length - 1] + otherLevelIndices[otherLevelIndices.length - 1] ]; if (!Object.is(valThis, valOther)) { const result = different( @@ -782,7 +783,7 @@ export default class BTree<K = any, V = any> if (otherLeaf && onlyOther) { const otherVal = otherLeaf.values[ - otherLevelIndices[otherLevelIndices.length - 1] + otherLevelIndices[otherLevelIndices.length - 1] ]; const result = onlyOther(otherCursor.currentKey, otherVal); if (result && result.break) return result.break; @@ -918,9 +919,10 @@ export default class BTree<K = any, V = any> levelIndexWalkBack + 1, ); // Move to new internal node - cursor.currentKey = internalSpine[levelIndexWalkBack][ - --levelIndices[levelIndexWalkBack] - ].maxKey(); + cursor.currentKey = + internalSpine[levelIndexWalkBack][ + --levelIndices[levelIndexWalkBack] + ].maxKey(); return true; } levelIndexWalkBack--; @@ -930,7 +932,7 @@ export default class BTree<K = any, V = any> } else { // Move to new leaf value const valueIndex = --levelIndices[levelsLength - 1]; - cursor.currentKey = ((leaf as unknown) as BNode<K, V>).keys[valueIndex]; + cursor.currentKey = (leaf as unknown as BNode<K, V>).keys[valueIndex]; return true; } } else { @@ -1119,7 +1121,7 @@ export default class BTree<K = any, V = any> * avoid creating a new array on every iteration. */ nextHigherPair(key: K | undefined, reusedArray?: [K, V]): [K, V] | undefined { - reusedArray = reusedArray || (([] as unknown) as [K, V]); + reusedArray = reusedArray || ([] as unknown as [K, V]); if (key === undefined) { return this._root.minPair(reusedArray); } @@ -1146,7 +1148,7 @@ export default class BTree<K = any, V = any> * avoid creating a new array each time you call this method. */ nextLowerPair(key: K | undefined, reusedArray?: [K, V]): [K, V] | undefined { - reusedArray = reusedArray || (([] as unknown) as [K, V]); + reusedArray = reusedArray || ([] as unknown as [K, V]); if (key === undefined) { return this._root.maxPair(reusedArray); } @@ -1178,7 +1180,7 @@ export default class BTree<K = any, V = any> key, this._compare, true, - reusedArray || (([] as unknown) as [K, V]), + reusedArray || ([] as unknown as [K, V]), ); } @@ -1194,7 +1196,7 @@ export default class BTree<K = any, V = any> key, this._compare, true, - reusedArray || (([] as unknown) as [K, V]), + reusedArray || ([] as unknown as [K, V]), ); } @@ -1345,7 +1347,7 @@ export default class BTree<K = any, V = any> this._root = root = root.keys.length === 0 ? EmptyLeaf - : ((root as any) as BNodeInternal<K, V>).children[0]; + : (root as any as BNodeInternal<K, V>).children[0]; } } @@ -1390,7 +1392,7 @@ export default class BTree<K = any, V = any> height++; node = node.isLeaf ? undefined - : ((node as unknown) as BNodeInternal<K, V>).children[0]; + : (node as unknown as BNodeInternal<K, V>).children[0]; } return height; } @@ -1405,9 +1407,12 @@ export default class BTree<K = any, V = any> var t = this as any; // Note: all other mutators ultimately call set() or editRange() // so we don't need to override those others. - t.clear = t.set = t.editRange = function () { - throw new Error("Attempted to modify a frozen BTree"); - }; + t.clear = + t.set = + t.editRange = + function () { + throw new Error("Attempted to modify a frozen BTree"); + }; } /** Ensures mutations are allowed, reversing the effect of freeze(). */ @@ -2191,7 +2196,7 @@ class BNodeInternal<K, V> extends BNode<K, V> { this.keys.push.apply(this.keys, rhs.keys); this.children.push.apply( this.children, - ((rhs as any) as BNodeInternal<K, V>).children, + (rhs as any as BNodeInternal<K, V>).children, ); // If our children are themselves almost empty due to a mass-delete, // they may need to be merged too (but only the oldLength-1 and its diff --git a/packages/idb-bridge/src/util/FakeEventTarget.ts b/packages/idb-bridge/src/util/FakeEventTarget.ts index 7ff220711..79f57cce3 100644 --- a/packages/idb-bridge/src/util/FakeEventTarget.ts +++ b/packages/idb-bridge/src/util/FakeEventTarget.ts @@ -21,7 +21,7 @@ import { Event, EventListenerOrEventListenerObject, EventListener, -} from "../idbtypes"; +} from "../idbtypes.js"; type EventTypeProp = | "onabort" diff --git a/packages/idb-bridge/src/util/normalizeKeyPath.ts b/packages/idb-bridge/src/util/normalizeKeyPath.ts index 4e194b2d1..b79f54fd1 100644 --- a/packages/idb-bridge/src/util/normalizeKeyPath.ts +++ b/packages/idb-bridge/src/util/normalizeKeyPath.ts @@ -15,7 +15,7 @@ permissions and limitations under the License. */ -import { IDBKeyPath } from "../idbtypes"; +import { IDBKeyPath } from "../idbtypes.js"; export function normalizeKeyPath( keyPath: IDBKeyPath | IDBKeyPath[], diff --git a/packages/idb-bridge/tsconfig.json b/packages/idb-bridge/tsconfig.json index 4f730e1c5..e09681c55 100644 --- a/packages/idb-bridge/tsconfig.json +++ b/packages/idb-bridge/tsconfig.json @@ -2,8 +2,8 @@ "compilerOptions": { "composite": true, "lib": ["es6"], - "module": "ESNext", - "moduleResolution": "node", + "module": "ES2020", + "moduleResolution": "Node16", "target": "ES6", "allowJs": true, "noImplicitAny": true, |