Fix tests
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@scure/base": "^1.1.2",
|
||||
"debug": "^4.3.4",
|
||||
"dexie": "^3.2.4",
|
||||
"light-bolt11-decoder": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
87
packages/shared/src/dexie-like.ts
Normal file
87
packages/shared/src/dexie-like.ts
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Dexie proxy type
|
||||
*/
|
||||
export abstract class DexieLike {
|
||||
constructor(name: string) {}
|
||||
version(n: number) {
|
||||
return {
|
||||
stores(schema: object) {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type DexieIndexableTypePart =
|
||||
| string
|
||||
| number
|
||||
| Date
|
||||
| ArrayBuffer
|
||||
| ArrayBufferView
|
||||
| DataView
|
||||
| Array<Array<void>>;
|
||||
export type DexieIndexableTypeArray = Array<DexieIndexableTypePart>;
|
||||
export type DexieIndexableTypeArrayReadonly = ReadonlyArray<DexieIndexableTypePart>;
|
||||
export type DexieIndexableType = DexieIndexableTypePart | DexieIndexableTypeArrayReadonly;
|
||||
|
||||
export interface DexiePromiseExtended<T = any> extends Promise<T> {
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
||||
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
|
||||
): DexiePromiseExtended<TResult1 | TResult2>;
|
||||
catch<TResult = never>(
|
||||
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
|
||||
): DexiePromiseExtended<T | TResult>;
|
||||
catch<TResult = never>(
|
||||
ErrorConstructor: Function,
|
||||
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
|
||||
): DexiePromiseExtended<T | TResult>;
|
||||
catch<TResult = never>(
|
||||
errorName: string,
|
||||
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
|
||||
): DexiePromiseExtended<T | TResult>;
|
||||
finally<U>(onFinally?: () => U | PromiseLike<U>): DexiePromiseExtended<T>;
|
||||
timeout(ms: number, msg?: string): DexiePromiseExtended<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dexie Table<T> like structure
|
||||
*/
|
||||
export interface DexieTableLike<T = any, TKey = DexieIndexableType> {
|
||||
toCollection(): {
|
||||
get primaryKeys(): {
|
||||
(): DexiePromiseExtended<Array<TKey>>;
|
||||
<R>(thenShortcut: DexieThenShortcut<Array<TKey>, R>): DexiePromiseExtended<R>;
|
||||
};
|
||||
};
|
||||
get(key: TKey): DexiePromiseExtended<T | undefined>;
|
||||
bulkGet(keys: Array<TKey>): DexiePromiseExtended<Array<T | undefined>>;
|
||||
put(item: T, key?: TKey): DexiePromiseExtended<TKey>;
|
||||
bulkPut(
|
||||
items: readonly T[],
|
||||
keys?: DexieIndexableTypeArrayReadonly,
|
||||
options?: {
|
||||
allKeys: boolean;
|
||||
},
|
||||
): DexiePromiseExtended<TKey>;
|
||||
clear(): DexiePromiseExtended<void>;
|
||||
where(index: string | string[]): DexieWhereClause<T, TKey>;
|
||||
toArray(): DexiePromiseExtended<Array<T>>;
|
||||
orderBy(index: string | string[]): DexieCollection<T, TKey>;
|
||||
}
|
||||
|
||||
export interface DexieCollection<T = any, TKey = DexieIndexableType> {
|
||||
first(): DexiePromiseExtended<T | undefined>;
|
||||
or(indexOrPrimayKey: string): DexieWhereClause<T, TKey>;
|
||||
toArray(): DexiePromiseExtended<Array<T>>;
|
||||
reverse(): DexieCollection<T, TKey>;
|
||||
sortBy(keyPath: string): DexiePromiseExtended<T[]>;
|
||||
limit(n: number): DexieCollection<T, TKey>;
|
||||
delete(): DexiePromiseExtended<number>;
|
||||
}
|
||||
|
||||
export interface DexieWhereClause<T = any, TKey = DexieIndexableType> {
|
||||
startsWithIgnoreCase(key: string): DexieCollection<T, TKey>;
|
||||
below(key: any): DexieCollection<T, TKey>;
|
||||
between(lower: any, upper: any, includeLower?: boolean, includeUpper?: boolean): DexieCollection<T, TKey>;
|
||||
}
|
||||
|
||||
export type DexieThenShortcut<T, TResult> = (value: T) => TResult | PromiseLike<TResult>;
|
@ -1,6 +1,6 @@
|
||||
import debug from "debug";
|
||||
import { Table } from "dexie";
|
||||
import { unixNowMs, unwrap } from "./utils";
|
||||
import { DexieTableLike } from "./dexie-like";
|
||||
|
||||
type HookFn = () => void;
|
||||
|
||||
@ -19,11 +19,11 @@ export abstract class FeedCache<TCached> {
|
||||
#changed = true;
|
||||
#hits = 0;
|
||||
#miss = 0;
|
||||
protected table?: Table<TCached>;
|
||||
protected table?: DexieTableLike<TCached>;
|
||||
protected onTable: Set<string> = new Set();
|
||||
protected cache: Map<string, TCached> = new Map();
|
||||
|
||||
constructor(name: string, table?: Table<TCached>) {
|
||||
constructor(name: string, table?: DexieTableLike<TCached>) {
|
||||
this.#name = name;
|
||||
this.table = table;
|
||||
setInterval(() => {
|
||||
|
@ -4,3 +4,4 @@ export * from "./utils";
|
||||
export * from "./work-queue";
|
||||
export * from "./feed-cache";
|
||||
export * from "./invoices";
|
||||
export * from "./dexie-like";
|
||||
|
@ -1,11 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "node",
|
||||
"target": "ESNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"noImplicitOverride": true,
|
||||
"module": "CommonJS",
|
||||
"module": "NodeNext",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
@ -13,6 +13,6 @@
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"include": ["src/**/*.ts", "src/.d.ts"],
|
||||
"files": ["src/index.ts"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user