diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-10 14:37:20 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-10 14:37:20 +0530 |
commit | 5f8714091aac80144be118fa6427d65222e7509c (patch) | |
tree | a897f42a894b299a78a44e8d9b96a2a9a8342d0c | |
parent | 6990b3b5ec09ed5c1cc9d3eab4c5f8ad31d351ff (diff) |
use API extractor for cleaner package separation
26 files changed, 656 insertions, 122 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 36724f883..0a134958d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,5 +41,6 @@ "prebuilt": true, "src/i18n/*.po": true }, - "search.collapseResults": "auto" + "search.collapseResults": "auto", + "files.associations": { "api-extractor.json": "jsonc" } }
\ No newline at end of file diff --git a/packages/idb-bridge/api-extractor.json b/packages/idb-bridge/api-extractor.json new file mode 100644 index 000000000..f57d81d8c --- /dev/null +++ b/packages/idb-bridge/api-extractor.json @@ -0,0 +1,131 @@ +/**
+ * Config file for API Extractor. For more info, please visit: https://api-extractor.com
+ */
+{
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
+
+ /**
+ * (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
+ * analyzes the symbols exported by this module.
+ *
+ * The file extension must be ".d.ts" and not ".ts".
+ *
+ * The path is resolved relative to the folder of the config file that contains the setting; to change this,
+ * prepend a folder token such as "<projectFolder>".
+ *
+ * SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
+ */
+ "mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
+
+ /**
+ * A list of NPM package names whose exports should be treated as part of this package.
+ *
+ * For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
+ * and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
+ * of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
+ * imports library2. To avoid this, we can specify:
+ *
+ * "bundledPackages": [ "library2" ],
+ *
+ * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
+ * local files for library1.
+ */
+ "bundledPackages": [],
+
+ /**
+ * Configures how the API report file (*.api.md) will be generated.
+ */
+ "apiReport": {
+ /**
+ * (REQUIRED) Whether to generate an API report.
+ */
+ "enabled": false
+ },
+
+ /**
+ * Configures how the doc model file (*.api.json) will be generated.
+ */
+ "docModel": {
+ /**
+ * (REQUIRED) Whether to generate a doc model file.
+ */
+ "enabled": false
+ },
+
+ /**
+ * Configures how the .d.ts rollup file will be generated.
+ */
+ "dtsRollup": {
+ /**
+ * (REQUIRED) Whether to generate the .d.ts rollup file.
+ */
+ "enabled": true
+ },
+
+ /**
+ * Configures how the tsdoc-metadata.json file will be generated.
+ */
+ "tsdocMetadata": {
+ /**
+ * Whether to generate the tsdoc-metadata.json file.
+ *
+ * DEFAULT VALUE: true
+ */
+ "enabled": false
+ },
+
+ /**
+ * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
+ * will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
+ * To use the OS's default newline kind, specify "os".
+ *
+ * DEFAULT VALUE: "crlf"
+ */
+ "newlineKind": "lf",
+
+ /**
+ * Configures how API Extractor reports error and warning messages produced during analysis.
+ *
+ * There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
+ */
+ "messages": {
+ /**
+ * Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
+ * the input .d.ts files.
+ *
+ * TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
+ *
+ * DEFAULT VALUE: A single "default" entry with logLevel=warning.
+ */
+ "compilerMessageReporting": {
+ /**
+ * Configures the default routing for messages that don't match an explicit rule in this table.
+ */
+ "default": {
+ "logLevel": "warning"
+ }
+ },
+
+ /**
+ * Configures handling of messages reported by API Extractor during its analysis.
+ *
+ * API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
+ *
+ * DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
+ */
+ "extractorMessageReporting": {
+ "default": {
+ "logLevel": "warning"
+ }
+ },
+
+ /**
+ * Configures handling of messages reported by the TSDoc parser when analyzing code comments.
+ */
+ "tsdocMessageReporting": {
+ "default": {
+ "logLevel": "warning"
+ }
+ }
+ }
+}
diff --git a/packages/idb-bridge/package.json b/packages/idb-bridge/package.json index b2c22921f..cf9ce409c 100644 --- a/packages/idb-bridge/package.json +++ b/packages/idb-bridge/package.json @@ -4,17 +4,18 @@ "description": "IndexedDB implementation that uses SQLite3 as storage", "main": "./dist/idb-bridge.js", "module": "./lib/index.js", - "types": "./lib/index.d.ts", + "types": "./dist/idb-bridge.d.ts", "author": "Florian Dold", "license": "AGPL-3.0-or-later", "private": false, "scripts": { "test": "tsc && ava", - "compile": "tsc && rollup -c", - "clean": "rimraf dist lib", + "compile": "tsc && rollup -c && api-extractor run", + "clean": "rimraf dist lib tsconfig.tsbuildinfo", "pretty": "prettier --config ../../.prettierrc --write src" }, "devDependencies": { + "@microsoft/api-extractor": "^7.9.3", "@rollup/plugin-typescript": "^5.0.2", "ava": "^3.10.1", "esm": "^3.2.25", @@ -27,6 +28,8 @@ "tslib": "^2.0.0" }, "ava": { - "require": ["esm"] + "require": [ + "esm" + ] } } diff --git a/packages/idb-bridge/src/BridgeIDBCursor.ts b/packages/idb-bridge/src/BridgeIDBCursor.ts index a85f41f2b..a18c0bebc 100644 --- a/packages/idb-bridge/src/BridgeIDBCursor.ts +++ b/packages/idb-bridge/src/BridgeIDBCursor.ts @@ -46,6 +46,8 @@ import { BridgeIDBFactory } from "./BridgeIDBFactory"; /** * http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#cursor + * + * @public */ export class BridgeIDBCursor { _request: BridgeIDBRequest | undefined; diff --git a/packages/idb-bridge/src/BridgeIDBDatabase.ts b/packages/idb-bridge/src/BridgeIDBDatabase.ts index a22ad5400..ffd897f9c 100644 --- a/packages/idb-bridge/src/BridgeIDBDatabase.ts +++ b/packages/idb-bridge/src/BridgeIDBDatabase.ts @@ -33,6 +33,7 @@ import { Schema, DatabaseTransaction, } from "./backend-interface"; +import { BridgeIDBObjectStore } from "./BridgeIDBObjectStore"; /** * Ensure that an active version change transaction is currently running. @@ -62,6 +63,7 @@ const confirmActiveVersionchangeTransaction = (database: BridgeIDBDatabase) => { }; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-interface +/** @public */ export class BridgeIDBDatabase extends FakeEventTarget { _closePending = false; _closed = false; @@ -120,7 +122,7 @@ export class BridgeIDBDatabase extends FakeEventTarget { public createObjectStore( name: string, options: { autoIncrement?: boolean; keyPath?: KeyPath } | null = {}, - ) { + ): BridgeIDBObjectStore { if (name === undefined) { throw new TypeError(); } diff --git a/packages/idb-bridge/src/BridgeIDBFactory.ts b/packages/idb-bridge/src/BridgeIDBFactory.ts index 7002222d8..7954cdd99 100644 --- a/packages/idb-bridge/src/BridgeIDBFactory.ts +++ b/packages/idb-bridge/src/BridgeIDBFactory.ts @@ -25,8 +25,10 @@ import FakeEvent from "./util/FakeEvent"; import { Backend, DatabaseConnection } from "./backend-interface"; import queueTask from "./util/queueTask"; -type DatabaseList = Array<{ name: string; version: number }>; +/** @public */ +export type DatabaseList = Array<{ name: string; version: number }>; +/** @public */ export class BridgeIDBFactory { public cmp = compareKeys; private backend: Backend; diff --git a/packages/idb-bridge/src/BridgeIDBIndex.ts b/packages/idb-bridge/src/BridgeIDBIndex.ts index 3c1b39435..9b214a234 100644 --- a/packages/idb-bridge/src/BridgeIDBIndex.ts +++ b/packages/idb-bridge/src/BridgeIDBIndex.ts @@ -51,6 +51,7 @@ const confirmActiveTransaction = ( }; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#idl-def-IDBIndex +/** @public */ export class BridgeIDBIndex { objectStore: BridgeIDBObjectStore; diff --git a/packages/idb-bridge/src/BridgeIDBKeyRange.ts b/packages/idb-bridge/src/BridgeIDBKeyRange.ts index 43f59fb14..d2eaa2d1b 100644 --- a/packages/idb-bridge/src/BridgeIDBKeyRange.ts +++ b/packages/idb-bridge/src/BridgeIDBKeyRange.ts @@ -21,6 +21,7 @@ import { Key } from "./util/types"; import valueToKey from "./util/valueToKey"; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#range-concept +/** @public */ export class BridgeIDBKeyRange { public static only(value: Key) { if (arguments.length === 0) { diff --git a/packages/idb-bridge/src/BridgeIDBObjectStore.ts b/packages/idb-bridge/src/BridgeIDBObjectStore.ts index a32c29275..06bd0f590 100644 --- a/packages/idb-bridge/src/BridgeIDBObjectStore.ts +++ b/packages/idb-bridge/src/BridgeIDBObjectStore.ts @@ -43,10 +43,14 @@ import { RecordGetRequest, ResultLevel, StoreLevel, + Schema, + Backend, + DatabaseConnection, } from "./backend-interface"; import { BridgeIDBFactory } from "./BridgeIDBFactory"; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#object-store +/** @public */ export class BridgeIDBObjectStore { _indexesCache: Map<string, BridgeIDBIndex> = new Map(); @@ -68,7 +72,7 @@ export class BridgeIDBObjectStore { _name: string; - get _schema() { + get _schema(): Schema { return this.transaction.db._schema; } @@ -83,11 +87,11 @@ export class BridgeIDBObjectStore { return this._name; } - get _backend() { + get _backend(): Backend { return this.transaction.db._backend; } - get _backendConnection() { + get _backendConnection(): DatabaseConnection { return this.transaction.db._backendConnection; } diff --git a/packages/idb-bridge/src/BridgeIDBOpenDBRequest.ts b/packages/idb-bridge/src/BridgeIDBOpenDBRequest.ts index 71a6495e5..306edcb7d 100644 --- a/packages/idb-bridge/src/BridgeIDBOpenDBRequest.ts +++ b/packages/idb-bridge/src/BridgeIDBOpenDBRequest.ts @@ -16,11 +16,12 @@ */ import { BridgeIDBRequest } from "./BridgeIDBRequest"; -import { EventCallback } from "./util/types"; +import { EventListener } from "./idbtypes"; +/** @public */ export class BridgeIDBOpenDBRequest extends BridgeIDBRequest { - public onupgradeneeded: EventCallback | null = null; - public onblocked: EventCallback | null = null; + public onupgradeneeded: EventListener | null = null; + public onblocked: EventListener | null = null; constructor() { super(); diff --git a/packages/idb-bridge/src/BridgeIDBRequest.ts b/packages/idb-bridge/src/BridgeIDBRequest.ts index 3ed2f9244..4800a0582 100644 --- a/packages/idb-bridge/src/BridgeIDBRequest.ts +++ b/packages/idb-bridge/src/BridgeIDBRequest.ts @@ -21,17 +21,18 @@ import { BridgeIDBObjectStore } from "./BridgeIDBObjectStore"; import { BridgeIDBTransaction } from "./BridgeIDBTransaction"; import { InvalidStateError } from "./util/errors"; import FakeEventTarget from "./util/FakeEventTarget"; -import { EventCallback } from "./util/types"; import FakeEvent from "./util/FakeEvent"; +import { EventListener } from "./idbtypes"; +/** @public */ export class BridgeIDBRequest extends FakeEventTarget { _result: any = null; _error: Error | null | undefined = null; source: BridgeFIBCursor | BridgeIDBIndex | BridgeIDBObjectStore | null = null; transaction: BridgeIDBTransaction | null = null; readyState: "done" | "pending" = "pending"; - onsuccess: EventCallback | null = null; - onerror: EventCallback | null = null; + onsuccess: EventListener | null = null; + onerror: EventListener | null = null; get error() { if (this.readyState === "pending") { diff --git a/packages/idb-bridge/src/BridgeIDBTransaction.ts b/packages/idb-bridge/src/BridgeIDBTransaction.ts index 56a4d59ef..d49ae515f 100644 --- a/packages/idb-bridge/src/BridgeIDBTransaction.ts +++ b/packages/idb-bridge/src/BridgeIDBTransaction.ts @@ -11,7 +11,6 @@ import fakeDOMStringList from "./util/fakeDOMStringList"; import FakeEvent from "./util/FakeEvent"; import FakeEventTarget from "./util/FakeEventTarget"; import { - EventCallback, FakeDOMStringList, RequestObj, TransactionMode, @@ -20,8 +19,10 @@ import queueTask from "./util/queueTask"; import openPromise from "./util/openPromise"; import { DatabaseTransaction, Backend } from "./backend-interface"; import { BridgeIDBFactory } from "./BridgeIDBFactory"; +import { EventListener } from "./idbtypes"; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#transaction +/** @public */ export class BridgeIDBTransaction extends FakeEventTarget { public _state: "active" | "inactive" | "committing" | "finished" = "active"; public _started = false; @@ -33,9 +34,9 @@ export class BridgeIDBTransaction extends FakeEventTarget { public mode: TransactionMode; public db: BridgeIDBDatabase; public error: Error | null = null; - public onabort: EventCallback | null = null; - public oncomplete: EventCallback | null = null; - public onerror: EventCallback | null = null; + public onabort: EventListener | null = null; + public oncomplete: EventListener | null = null; + public onerror: EventListener | null = null; private _waitPromise: Promise<void>; private _resolveWait: () => void; diff --git a/packages/idb-bridge/src/MemoryBackend.ts b/packages/idb-bridge/src/MemoryBackend.ts index c5fac41a9..e8aec766e 100644 --- a/packages/idb-bridge/src/MemoryBackend.ts +++ b/packages/idb-bridge/src/MemoryBackend.ts @@ -36,7 +36,7 @@ import { } from "./util/errors"; import BTree, { ISortedMapF } from "./tree/b+tree"; import compareKeys from "./util/cmp"; -import { Key, Value, KeyPath } from "./util/types"; +import { Key, Value, KeyPath, TransactionMode } from "./util/types"; import { StoreKeyResult, makeStoreKeyValue } from "./util/makeStoreKeyValue"; import getIndexKeys from "./util/getIndexKeys"; import openPromise from "./util/openPromise"; @@ -89,24 +89,28 @@ interface Database { connectionCookie: string | undefined; } -interface IndexDump { +/** @public */ +export interface IndexDump { name: string; records: IndexRecord[]; } -interface ObjectStoreDump { +/** @public */ +export interface ObjectStoreDump { name: string; keyGenerator: number; records: ObjectStoreRecord[]; indexes: { [name: string]: IndexDump }; } -interface DatabaseDump { +/** @public */ +export interface DatabaseDump { schema: Schema; objectStores: { [name: string]: ObjectStoreDump }; } -interface MemoryBackendDump { +/** @public */ +export interface MemoryBackendDump { databases: { [name: string]: DatabaseDump }; } @@ -132,12 +136,14 @@ interface Connection { objectStoreMap: { [currentName: string]: ObjectStoreMapEntry }; } -interface IndexRecord { +/** @public */ +export interface IndexRecord { indexKey: Key; primaryKeys: Key[]; } -interface ObjectStoreRecord { +/** @public */ +export interface ObjectStoreRecord { primaryKey: Key; value: Value; } @@ -210,6 +216,8 @@ function furthestKey( /** * Primitive in-memory backend. + * + * @public */ export class MemoryBackend implements Backend { private databases: { [name: string]: Database } = {}; @@ -471,7 +479,7 @@ export class MemoryBackend implements Backend { async beginTransaction( conn: DatabaseConnection, objectStores: string[], - mode: import("./util/types").TransactionMode, + mode: TransactionMode, ): Promise<DatabaseTransaction> { if (this.enableTracing) { console.log(`TRACING: beginTransaction`); @@ -781,7 +789,7 @@ export class MemoryBackend implements Backend { btx: DatabaseTransaction, indexName: string, objectStoreName: string, - keyPath: import("./util/types").KeyPath, + keyPath: KeyPath, multiEntry: boolean, unique: boolean, ): void { diff --git a/packages/idb-bridge/src/backend-interface.ts b/packages/idb-bridge/src/backend-interface.ts index 3617d21bc..4d1f107ba 100644 --- a/packages/idb-bridge/src/backend-interface.ts +++ b/packages/idb-bridge/src/backend-interface.ts @@ -24,44 +24,52 @@ import { } from "./util/types"; import { BridgeIDBKeyRange } from "./BridgeIDBKeyRange"; +/** @public */ export interface ObjectStoreProperties { keyPath: KeyPath | null; autoIncrement: boolean; indexes: { [nameame: string]: IndexProperties }; } +/** @public */ export interface IndexProperties { keyPath: KeyPath; multiEntry: boolean; unique: boolean; } +/** @public */ export interface Schema { databaseName: string; databaseVersion: number; objectStores: { [name: string]: ObjectStoreProperties }; } +/** @public */ export interface DatabaseConnection { connectionCookie: string; } +/** @public */ export interface DatabaseTransaction { transactionCookie: string; } +/** @public */ export enum ResultLevel { OnlyCount, OnlyKeys, Full, } +/** @public */ export enum StoreLevel { NoOverwrite, AllowOverwrite, UpdateExisting, } +/** @public */ export interface RecordGetRequest { direction: BridgeIDBCursorDirection; objectStoreName: string; @@ -104,6 +112,7 @@ export interface RecordGetRequest { resultLevel: ResultLevel; } +/** @public */ export interface RecordGetResponse { values: Value[] | undefined; indexKeys: Key[] | undefined; @@ -111,6 +120,7 @@ export interface RecordGetResponse { count: number; } +/** @public */ export interface RecordStoreRequest { objectStoreName: string; value: Value; @@ -118,6 +128,7 @@ export interface RecordStoreRequest { storeLevel: StoreLevel; } +/** @public */ export interface RecordStoreResponse { /** * Key that the record was stored under in the object store. @@ -125,6 +136,7 @@ export interface RecordStoreResponse { key: Key; } +/** @public */ export interface Backend { getDatabases(): Promise<BridgeIDBDatabaseInfo[]>; diff --git a/packages/idb-bridge/src/idbtypes.ts b/packages/idb-bridge/src/idbtypes.ts index 53f93d451..4ab2b6f3b 100644 --- a/packages/idb-bridge/src/idbtypes.ts +++ b/packages/idb-bridge/src/idbtypes.ts @@ -19,32 +19,58 @@ and limitations under the License. * Instead of ambient types, we export type declarations. */ +/** + * @public + */ export type IDBKeyPath = string; +/** + * @public + */ export interface EventListener { (evt: Event): void; } +/** + * @public + */ export interface EventListenerObject { handleEvent(evt: Event): void; } +/** + * @public + */ export interface EventListenerOptions { capture?: boolean; } +/** + * @public + */ export interface AddEventListenerOptions extends EventListenerOptions { once?: boolean; passive?: boolean; } +/** + * @public + */ export type IDBTransactionMode = "readonly" | "readwrite" | "versionchange"; +/** + * @public + */ export type EventListenerOrEventListenerObject = | EventListener | EventListenerObject; -/** EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them. */ +/** + * EventTarget is a DOM interface implemented by objects that can receive + * events and may have listeners for them. + * + * @public + */ export interface EventTarget { /** * Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. @@ -78,7 +104,11 @@ export interface EventTarget { ): void; } -/** An event which takes place in the DOM. */ +/** + * An event which takes place in the DOM. + * + * @public + */ export interface Event { /** * Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise. @@ -110,7 +140,9 @@ export interface Event { */ readonly isTrusted: boolean; returnValue: boolean; - /** @deprecated */ + /** + * @deprecated use target instead + */ readonly srcElement: EventTarget | null; /** * Returns the object to which event is dispatched (its target). @@ -147,7 +179,11 @@ export interface Event { readonly NONE: number; } -/** A type returned by some APIs which contains a list of DOMString (strings). */ +/** + * A type returned by some APIs which contains a list of DOMString (strings). + * + * @public + */ export interface DOMStringList { /** * Returns the number of strings in strings. @@ -164,31 +200,57 @@ export interface DOMStringList { [index: number]: string; } +/** + * @public + */ export type BufferSource = ArrayBufferView | ArrayBuffer; +/** + * @public + */ export type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey; +/** + * @public + */ export interface IDBIndexParameters { multiEntry?: boolean; unique?: boolean; } +/** + * @public + */ export interface IDBObjectStoreParameters { autoIncrement?: boolean; keyPath?: string | string[] | null; } +/** + * @public + */ export interface EventInit { bubbles?: boolean; cancelable?: boolean; composed?: boolean; } +/** + * @public + */ export interface IDBArrayKey extends Array<IDBValidKey> {} +/** + * @public + */ export type IDBCursorDirection = "next" | "nextunique" | "prev" | "prevunique"; -/** This IndexedDB API interface represents a cursor for traversing or iterating over multiple records in a database. */ +/** + * This IndexedDB API interface represents a cursor for traversing or + * iterating over multiple records in a database. + * + * @public + */ export interface IDBCursor { /** * Returns the direction ("next", "nextunique", "prev" or "prevunique") of the cursor. @@ -234,7 +296,13 @@ export interface IDBCursor { update(value: any): IDBRequest<IDBValidKey>; } -/** This IndexedDB API interface represents a cursor for traversing or iterating over multiple records in a database. It is the same as the IDBCursor, except that it includes the value property. */ +/** + * This IndexedDB API interface represents a cursor for traversing or + * iterating over multiple records in a database. It is the same as the + * IDBCursor, except that it includes the value property. + * + * @public + */ export interface IDBCursorWithValue extends IDBCursor { /** * Returns the cursor's current value. @@ -242,6 +310,9 @@ export interface IDBCursorWithValue extends IDBCursor { readonly value: any; } +/** + * @public + */ export interface IDBDatabaseEventMap { abort: Event; close: Event; @@ -249,7 +320,14 @@ export interface IDBDatabaseEventMap { versionchange: IDBVersionChangeEvent; } -/** This IndexedDB API interface provides a connection to a database; you can use an IDBDatabase object to open a transaction on your database then create, manipulate, and delete objects (data) in that database. The interface provides the only way to get and manage versions of the database. */ +/** + * This IndexedDB API interface provides a connection to a database; you can + * use an IDBDatabase object to open a transaction on your database then + * create, manipulate, and delete objects (data) in that database. The + * interface provides the only way to get and manage versions of the database. + * + * @public + */ export interface IDBDatabase extends EventTarget { /** * Returns the name of the database. @@ -317,7 +395,9 @@ export interface IDBDatabase extends EventTarget { ): void; } -/** In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app (view example live.) */ +/** + * @public + */ export interface IDBFactory { /** * Compares two values as keys. Returns -1 if key1 precedes key2, 1 if key2 precedes key1, and 0 if the keys are equal. @@ -326,16 +406,28 @@ export interface IDBFactory { */ cmp(first: any, second: any): number; /** - * Attempts to delete the named database. If the database already exists and there are open connections that don't close in response to a versionchange event, the request will be blocked until all they close. If the request is successful request's result will be null. + * Attempts to delete the named database. If the database already exists and + * there are open connections that don't close in response to a versionchange + * event, the request will be blocked until all they close. If the request is + * successful request's result will be null. */ deleteDatabase(name: string): IDBOpenDBRequest; /** - * Attempts to open a connection to the named database with the current version, or 1 if it does not already exist. If the request is successful request's result will be the connection. + * Attempts to open a connection to the named database with the current + * version, or 1 if it does not already exist. If the request is successful + * request's result will be the connection. */ open(name: string, version?: number): IDBOpenDBRequest; } -/** IDBIndex interface of the IndexedDB API provides asynchronous access to an index in a database. An index is a kind of object store for looking up records in another object store, called the referenced object store. You use this interface to retrieve data. */ +/** + * IDBIndex interface of the IndexedDB API provides asynchronous access to an + * index in a database. An index is a kind of object store for looking up + * records in another object store, called the referenced object store. You use + * this interface to retrieve data. + * + * @public + */ export interface IDBIndex { readonly keyPath: string | string[]; readonly multiEntry: boolean; @@ -404,7 +496,15 @@ export interface IDBIndex { ): IDBRequest<IDBCursor | null>; } -/** A key range can be a single value or a range with upper and lower bounds or endpoints. If the key range has both upper and lower bounds, then it is bounded; if it has no bounds, it is unbounded. A bounded key range can either be open (the endpoints are excluded) or closed (the endpoints are included). To retrieve all keys within a certain range, you can use the following code constructs: */ +/** + * A key range can be a single value or a range with upper and lower bounds or + * endpoints. If the key range has both upper and lower bounds, then it is + * bounded; if it has no bounds, it is unbounded. A bounded key range can + * either be open (the endpoints are excluded) or closed (the endpoints are + * included). + * + * @public + */ export interface IDBKeyRange { /** * Returns lower bound, or undefined if none. @@ -428,7 +528,9 @@ export interface IDBKeyRange { includes(key: any): boolean; } -/** This example shows a variety of different uses of object stores, from updating the data structure with IDBObjectStore.createIndex inside an onupgradeneeded function, to adding a new item to our object store with IDBObjectStore.add. For a full working example, see our To-do Notifications app (view example live.) */ +/** + * @public + */ export interface IDBObjectStore { /** * Returns true if the store has a key generator, and false otherwise. @@ -555,12 +657,19 @@ export interface IDBObjectStore { put(value: any, key?: IDBValidKey): IDBRequest<IDBValidKey>; } +/** + * @public + */ export interface IDBOpenDBRequestEventMap extends IDBRequestEventMap { blocked: Event; upgradeneeded: IDBVersionChangeEvent; } -/** Also inherits methods from its parents IDBRequest and EventTarget. */ +/** + * Also inherits methods from its parents IDBRequest and EventTarget. + * + * @public + */ export interface IDBOpenDBRequest extends IDBRequest<IDBDatabase> { onblocked: ((this: IDBOpenDBRequest, ev: Event) => any) | null; onupgradeneeded: @@ -588,14 +697,25 @@ export interface IDBOpenDBRequest extends IDBRequest<IDBDatabase> { ): void; } +/** + * @public + */ export type IDBRequestReadyState = "done" | "pending"; +/** + * @public + */ export interface IDBRequestEventMap { error: Event; success: Event; } -/** An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API. */ +/** + * An abnormal event (called an exception) which occurs as a result of calling + * a method or accessing a property of a web API. + * + * @public + */ export interface DOMException { readonly code: number; readonly message: string; @@ -627,7 +747,14 @@ export interface DOMException { readonly WRONG_DOCUMENT_ERR: number; } -/** The request object does not initially contain any information about the result of the operation, but once information becomes available, an event is fired on the request, and the information becomes available through the properties of the IDBRequest instance. */ +/** + * The request object does not initially contain any information about the + * result of the operation, but once information becomes available, an event is + * fired on the request, and the information becomes available through the + * properties of the IDBRequest instance. + * + * @public + */ export interface IDBRequest<T = any> extends EventTarget { /** * When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws a "InvalidStateError" DOMException if the request is still pending. @@ -673,12 +800,18 @@ export interface IDBRequest<T = any> extends EventTarget { ): void; } +/** + * @public + */ export interface IDBTransactionEventMap { abort: Event; complete: Event; error: Event; } +/** + * @public + */ export interface IDBTransaction extends EventTarget { /** * Returns the transaction's connection. @@ -729,7 +862,13 @@ export interface IDBTransaction extends EventTarget { ): void; } -/** This IndexedDB API interface indicates that the version of the database has changed, as the result of an IDBOpenDBRequest.onupgradeneeded event handler function. */ +/** + * This IndexedDB API interface indicates that the version of the database has + * changed, as the result of an IDBOpenDBRequest.onupgradeneeded event handler + * function. + * + * @public + */ export interface IDBVersionChangeEvent extends Event { readonly newVersion: number | null; readonly oldVersion: number; diff --git a/packages/idb-bridge/src/index.ts b/packages/idb-bridge/src/index.ts index 8f19c9a31..a07803763 100644 --- a/packages/idb-bridge/src/index.ts +++ b/packages/idb-bridge/src/index.ts @@ -1,4 +1,4 @@ -import { BridgeIDBFactory } from "./BridgeIDBFactory"; +import { BridgeIDBFactory, DatabaseList } from "./BridgeIDBFactory"; import { BridgeIDBCursor } from "./BridgeIDBCursor"; import { BridgeIDBIndex } from "./BridgeIDBIndex"; import { BridgeIDBDatabase } from "./BridgeIDBDatabase"; @@ -8,8 +8,81 @@ import { BridgeIDBOpenDBRequest } from "./BridgeIDBOpenDBRequest"; import { BridgeIDBRequest } from "./BridgeIDBRequest"; import { BridgeIDBTransaction } from "./BridgeIDBTransaction"; import { BridgeIDBVersionChangeEvent } from "./BridgeIDBVersionChangeEvent"; +import { + Value, + CursorSource, + CursorRange, + BridgeIDBCursorDirection, + Key, + KeyPath, + TransactionMode, + FakeDOMStringList, + RequestObj, + BridgeIDBDatabaseInfo, + EventType, +} from "./util/types"; +import { + DatabaseTransaction, + RecordGetResponse, + RecordGetRequest, + Schema, + Backend, + RecordStoreRequest, + RecordStoreResponse, + DatabaseConnection, + ObjectStoreProperties, + StoreLevel, + ResultLevel, + IndexProperties, +} from "./backend-interface"; +import FakeEventTarget, { Listener } from "./util/FakeEventTarget"; +import { DatabaseDump, ObjectStoreDump, IndexDump, IndexRecord, ObjectStoreRecord, MemoryBackendDump } from "./MemoryBackend"; +import { Event } from "./idbtypes"; -export { BridgeIDBFactory, BridgeIDBCursor }; +export { + BridgeIDBCursor, + BridgeIDBCursorDirection, + BridgeIDBDatabase, + BridgeIDBDatabaseInfo, + BridgeIDBFactory, + BridgeIDBIndex, + BridgeIDBKeyRange, + BridgeIDBObjectStore, + BridgeIDBOpenDBRequest, + BridgeIDBRequest, + BridgeIDBTransaction, + Value, + CursorSource, + CursorRange, + Key, + DatabaseTransaction, + RecordGetRequest, + RecordGetResponse, + KeyPath, + Schema, + Backend, + TransactionMode, + DatabaseList, + RecordStoreRequest, + RecordStoreResponse, + FakeEventTarget, + DatabaseConnection, + FakeDOMStringList, + ObjectStoreProperties, + RequestObj, + StoreLevel, + ResultLevel, + DatabaseDump, + ObjectStoreDump, + IndexDump, + IndexRecord, + ObjectStoreRecord, + EventType, + IndexProperties, + MemoryBackendDump, + Event, + Listener, +}; export { MemoryBackend } from "./MemoryBackend"; @@ -31,6 +104,8 @@ export { MemoryBackend } from "./MemoryBackend"; /** * Populate the global name space such that the given IndexedDB factory is made * available globally. + * + * @public */ export function shimIndexedDB(factory: BridgeIDBFactory): void { // @ts-ignore: shimming @@ -59,5 +134,4 @@ export function shimIndexedDB(factory: BridgeIDBFactory): void { globalThis.IDBVersionChangeEvent = BridgeIDBVersionChangeEvent; } -import * as idbtypes from "./idbtypes"; -export type { idbtypes }; +export * from "./idbtypes"; diff --git a/packages/idb-bridge/src/util/FakeEvent.ts b/packages/idb-bridge/src/util/FakeEvent.ts index 4457498f6..207607886 100644 --- a/packages/idb-bridge/src/util/FakeEvent.ts +++ b/packages/idb-bridge/src/util/FakeEvent.ts @@ -16,8 +16,9 @@ import FakeEventTarget from "./FakeEventTarget"; import { EventType } from "./types"; +import { Event, EventTarget } from "../idbtypes"; -export class Event { +export class FakeEvent implements Event { public eventPath: FakeEventTarget[] = []; public type: EventType; @@ -57,6 +58,18 @@ export class Event { this.cancelable = eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false; } + cancelBubble: boolean = false; + composed: boolean = false; + returnValue: boolean = false; + get srcElement(): EventTarget | null { + return this.target; + } + composedPath(): EventTarget[] { + throw new Error("Method not implemented."); + } + initEvent(type: string, bubbles?: boolean | undefined, cancelable?: boolean | undefined): void { + throw new Error("Method not implemented."); + } public preventDefault() { if (this.cancelable) { @@ -74,4 +87,4 @@ export class Event { } } -export default Event; +export default FakeEvent; diff --git a/packages/idb-bridge/src/util/FakeEventTarget.ts b/packages/idb-bridge/src/util/FakeEventTarget.ts index 291eaca7d..da5a5466a 100644 --- a/packages/idb-bridge/src/util/FakeEventTarget.ts +++ b/packages/idb-bridge/src/util/FakeEventTarget.ts @@ -16,7 +16,8 @@ import { InvalidStateError } from "./errors"; import FakeEvent from "./FakeEvent"; -import { EventCallback, EventType } from "./types"; +import { EventType } from "./types"; +import { EventTarget, Event, EventListenerOrEventListenerObject, EventListener } from "../idbtypes"; type EventTypeProp = | "onabort" @@ -27,8 +28,9 @@ type EventTypeProp = | "onupgradeneeded" | "onversionchange"; -interface Listener { - callback: EventCallback; +/** @public */ +export interface Listener { + callback: EventListenerOrEventListenerObject; capture: boolean; type: EventType; } @@ -86,35 +88,44 @@ const invokeEventListeners = (event: FakeEvent, obj: FakeEventTarget) => { } }; -abstract class FakeEventTarget { +/** @public */ +abstract class FakeEventTarget implements EventTarget { public readonly listeners: Listener[] = []; // These will be overridden in individual subclasses and made not readonly - public readonly onabort: EventCallback | null | undefined; - public readonly onblocked: EventCallback | null | undefined; - public readonly oncomplete: EventCallback | null | undefined; - public readonly onerror: EventCallback | null | undefined; - public readonly onsuccess: EventCallback | null | undefined; - public readonly onupgradeneeded: EventCallback | null | undefined; - public readonly onversionchange: EventCallback | null | undefined; + public readonly onabort: EventListener | null | undefined; + public readonly onblocked: EventListener | null | undefined; + public readonly oncomplete: EventListener | null | undefined; + public readonly onerror: EventListener | null | undefined; + public readonly onsuccess: EventListener | null | undefined; + public readonly onupgradeneeded: EventListener | null | undefined; + public readonly onversionchange: EventListener | null | undefined; static enableTracing: boolean = false; public addEventListener( type: EventType, - callback: EventCallback, + listener: EventListenerOrEventListenerObject | null, capture = false, ) { - this.listeners.push({ - callback, - capture, - type, - }); + if (typeof listener === "function") { + this.listeners.push({ + callback: listener, + capture, + type, + }); + } else if (typeof listener === "object" && listener != null) { + this.listeners.push({ + callback: (e: Event) => listener.handleEvent(e), + capture, + type, + }); + } } public removeEventListener( type: EventType, - callback: EventCallback, + callback: EventListenerOrEventListenerObject, capture = false, ) { const i = this.listeners.findIndex((listener) => { @@ -129,17 +140,21 @@ abstract class FakeEventTarget { } // http://www.w3.org/TR/dom/#dispatching-events - public dispatchEvent(event: FakeEvent) { + public dispatchEvent(event: Event): boolean { + if (!(event instanceof FakeEvent)) { + throw Error("dispatchEvent only works with FakeEvent"); + } + const fe = event as FakeEvent; if (event.dispatched || !event.initialized) { throw new InvalidStateError("The object is in an invalid state."); } - event.isTrusted = false; + fe.isTrusted = false; - event.dispatched = true; - event.target = this; + fe.dispatched = true; + fe.target = this; // NOT SURE WHEN THIS SHOULD BE SET event.eventPath = []; - event.eventPhase = event.CAPTURING_PHASE; + fe.eventPhase = event.CAPTURING_PHASE; if (FakeEventTarget.enableTracing) { console.log( `dispatching '${event.type}' event along path with ${event.eventPath.length} elements`, @@ -151,15 +166,15 @@ abstract class FakeEventTarget { } } - event.eventPhase = event.AT_TARGET; + fe.eventPhase = event.AT_TARGET; if (!event.propagationStopped) { - invokeEventListeners(event, event.target); + invokeEventListeners(event, fe.target); } if (event.bubbles) { - event.eventPath.reverse(); - event.eventPhase = event.BUBBLING_PHASE; - if (event.eventPath.length === 0 && event.type === "error") { + fe.eventPath.reverse(); + fe.eventPhase = event.BUBBLING_PHASE; + if (fe.eventPath.length === 0 && event.type === "error") { console.error("Unhandled error event: ", event.target); } for (const obj of event.eventPath) { @@ -169,9 +184,9 @@ abstract class FakeEventTarget { } } - event.dispatched = false; - event.eventPhase = event.NONE; - event.currentTarget = null; + fe.dispatched = false; + fe.eventPhase = event.NONE; + fe.currentTarget = null; if (event.canceled) { return false; diff --git a/packages/idb-bridge/src/util/types.ts b/packages/idb-bridge/src/util/types.ts index b0142b0d8..b07f5ad00 100644 --- a/packages/idb-bridge/src/util/types.ts +++ b/packages/idb-bridge/src/util/types.ts @@ -18,16 +18,10 @@ import { BridgeIDBRequest } from "../BridgeIDBRequest"; import { BridgeIDBKeyRange } from "../BridgeIDBKeyRange"; import { BridgeIDBIndex } from "../BridgeIDBIndex"; -import { Event } from "../util/FakeEvent"; import { BridgeIDBObjectStore } from "../BridgeIDBObjectStore"; +import { Event } from "../idbtypes"; -interface EventInCallback extends Event { - target: any; - error: Error | null; -} - -export type EventCallback = (event: EventInCallback) => void; - +/** @public */ export type EventType = | "abort" | "blocked" @@ -37,39 +31,52 @@ export type EventType = | "upgradeneeded" | "versionchange"; +/** @public */ export type CursorSource = BridgeIDBIndex | BridgeIDBObjectStore; +/** @public */ export interface FakeDOMStringList extends Array<string> { contains: (value: string) => boolean; item: (i: number) => string | undefined; } +/** + * @public + */ export type BridgeIDBCursorDirection = | "next" | "nextunique" | "prev" | "prevunique"; +/** @public */ export type KeyPath = string | string[]; +/** @public */ export type Key = any; +/** @public */ export type CursorRange = Key | BridgeIDBKeyRange | undefined; +/** @public */ export type Value = any; +/** @public */ export interface Record { key: Key; value: Key | Value; // For indexes, will be Key. For object stores, will be Value. } +/** @public */ export type TransactionMode = "readonly" | "readwrite" | "versionchange"; +/** @public */ export interface BridgeIDBDatabaseInfo { name: string; version: number; } +/** @public */ export interface RequestObj { operation: () => Promise<any>; request?: BridgeIDBRequest | undefined; diff --git a/packages/idb-bridge/tsconfig.json b/packages/idb-bridge/tsconfig.json index 6e41df65d..a385e964a 100644 --- a/packages/idb-bridge/tsconfig.json +++ b/packages/idb-bridge/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitAny": true, "outDir": "lib", "declaration": true, + "declarationMap": true, "noEmitOnError": true, "strict": true, "incremental": true, diff --git a/packages/taler-wallet-core/package.json b/packages/taler-wallet-core/package.json index 68bf45d0a..981504e4c 100644 --- a/packages/taler-wallet-core/package.json +++ b/packages/taler-wallet-core/package.json @@ -31,6 +31,7 @@ "types": "./lib/index.d.ts", "devDependencies": { "@ava/typescript": "^1.1.1", + "@microsoft/api-extractor": "^7.9.3", "@typescript-eslint/eslint-plugin": "^3.6.1", "@typescript-eslint/parser": "^3.6.1", "ava": "^3.10.1", diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index a6eeb1205..f4d0b911e 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1,6 +1,6 @@ import { Stores } from "./types/dbTypes"; import { openDatabase, Database, Store, Index } from "./util/query"; -import type { idbtypes } from "idb-bridge"; +import { IDBFactory, IDBDatabase } from "idb-bridge"; /** * Name of the Taler database. The name includes the @@ -24,11 +24,11 @@ export const WALLET_DB_MINOR_VERSION = 1; * to the taler wallet db. */ export function openTalerDatabase( - idbFactory: idbtypes.IDBFactory, + idbFactory: IDBFactory, onVersionChange: () => void, -): Promise<idbtypes.IDBDatabase> { +): Promise<IDBDatabase> { const onUpgradeNeeded = ( - db: idbtypes.IDBDatabase, + db: IDBDatabase, oldVersion: number, newVersion: number, ): void => { @@ -61,6 +61,6 @@ export function openTalerDatabase( ); } -export function deleteTalerDatabase(idbFactory: idbtypes.IDBFactory): void { +export function deleteTalerDatabase(idbFactory: IDBFactory): void { Database.deleteDatabase(idbFactory, TALER_DB_NAME); } diff --git a/packages/taler-wallet-core/src/types/dbTypes.ts b/packages/taler-wallet-core/src/types/dbTypes.ts index 3e1fdfe25..26cf6915d 100644 --- a/packages/taler-wallet-core/src/types/dbTypes.ts +++ b/packages/taler-wallet-core/src/types/dbTypes.ts @@ -44,7 +44,7 @@ import { } from "./ReserveTransaction"; import { Timestamp, Duration, getTimestampNow } from "../util/time"; import { PayCoinSelection, PayCostInfo } from "../operations/pay"; -import { idbtypes } from "idb-bridge"; +import { IDBKeyPath } from "idb-bridge"; export enum ReserveRecordStatus { /** @@ -1666,7 +1666,7 @@ class DenominationsStore extends Store<DenominationRecord> { constructor() { // cast needed because of bug in type annotations super("denominations", { - keyPath: (["exchangeBaseUrl", "denomPub"] as any) as idbtypes.IDBKeyPath, + keyPath: (["exchangeBaseUrl", "denomPub"] as any) as IDBKeyPath, }); } diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 53359752e..f6e689f49 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -24,7 +24,17 @@ * Imports. */ import { openPromise } from "./promiseUtils"; -import type { idbtypes } from "idb-bridge"; +import { + IDBObjectStoreParameters, + IDBRequest, + IDBTransaction, + IDBValidKey, + IDBDatabase, + IDBFactory, + IDBVersionChangeEvent, + Event, + IDBCursor, +} from "idb-bridge"; /** * Exception that should be thrown by client code to abort a transaction. @@ -37,7 +47,7 @@ export const TransactionAbort = Symbol("transaction_abort"); export class Store<T> { constructor( public name: string, - public storeParams?: idbtypes.IDBObjectStoreParameters, + public storeParams?: IDBObjectStoreParameters, public validator?: (v: T) => T, ) {} } @@ -55,7 +65,7 @@ export interface IndexOptions { multiEntry?: boolean; } -function requestToPromise(req: idbtypes.IDBRequest): Promise<any> { +function requestToPromise(req: IDBRequest): Promise<any> { const stack = Error("Failed request was started here."); return new Promise((resolve, reject) => { req.onsuccess = () => { @@ -69,7 +79,7 @@ function requestToPromise(req: idbtypes.IDBRequest): Promise<any> { }); } -function transactionToPromise(tx: idbtypes.IDBTransaction): Promise<void> { +function transactionToPromise(tx: IDBTransaction): Promise<void> { const stack = Error("Failed transaction was started here."); return new Promise((resolve, reject) => { tx.onabort = () => { @@ -86,7 +96,7 @@ function transactionToPromise(tx: idbtypes.IDBTransaction): Promise<void> { } function applyMutation<T>( - req: idbtypes.IDBRequest, + req: IDBRequest, f: (x: T) => T | undefined, ): Promise<void> { return new Promise((resolve, reject) => { @@ -96,7 +106,7 @@ function applyMutation<T>( const val = cursor.value; const modVal = f(val); if (modVal !== undefined && modVal !== null) { - const req2: idbtypes.IDBRequest = cursor.update(modVal); + const req2: IDBRequest = cursor.update(modVal); req2.onerror = () => { reject(req2.error); }; @@ -132,7 +142,7 @@ class ResultStream<T> { private gotCursorEnd = false; private awaitingResult = false; - constructor(private req: idbtypes.IDBRequest) { + constructor(private req: IDBRequest) { this.awaitingResult = true; let p = openPromise<void>(); this.currentPromise = p.promise; @@ -224,7 +234,7 @@ class ResultStream<T> { return { hasValue: false }; } if (!this.awaitingResult) { - const cursor: idbtypes.IDBCursor | undefined = this.req.result; + const cursor: IDBCursor | undefined = this.req.result; if (!cursor) { throw Error("assertion failed"); } @@ -244,7 +254,7 @@ class ResultStream<T> { } export class TransactionHandle { - constructor(private tx: idbtypes.IDBTransaction) {} + constructor(private tx: IDBTransaction) {} put<T>(store: Store<T>, value: T, key?: any): Promise<any> { const req = this.tx.objectStore(store.name).put(value, key); @@ -261,7 +271,7 @@ export class TransactionHandle { return requestToPromise(req); } - getIndexed<S extends idbtypes.IDBValidKey, T>( + getIndexed<S extends IDBValidKey, T>( index: Index<S, T>, key: any, ): Promise<T | undefined> { @@ -277,7 +287,7 @@ export class TransactionHandle { return new ResultStream<T>(req); } - iterIndexed<S extends idbtypes.IDBValidKey, T>( + iterIndexed<S extends IDBValidKey, T>( index: Index<S, T>, key?: any, ): ResultStream<T> { @@ -304,7 +314,7 @@ export class TransactionHandle { } function runWithTransaction<T>( - db: idbtypes.IDBDatabase, + db: IDBDatabase, stores: Store<any>[], f: (t: TransactionHandle) => Promise<T>, mode: "readonly" | "readwrite", @@ -367,7 +377,7 @@ function runWithTransaction<T>( /** * Definition of an index. */ -export class Index<S extends idbtypes.IDBValidKey, T> { +export class Index<S extends IDBValidKey, T> { /** * Name of the store that this index is associated with. */ @@ -404,24 +414,24 @@ export class Index<S extends idbtypes.IDBValidKey, T> { * to the taler wallet db. */ export function openDatabase( - idbFactory: idbtypes.IDBFactory, + idbFactory: IDBFactory, databaseName: string, databaseVersion: number, onVersionChange: () => void, onUpgradeNeeded: ( - db: idbtypes.IDBDatabase, + db: IDBDatabase, oldVersion: number, newVersion: number, ) => void, -): Promise<idbtypes.IDBDatabase> { - return new Promise<idbtypes.IDBDatabase>((resolve, reject) => { +): Promise<IDBDatabase> { + return new Promise<IDBDatabase>((resolve, reject) => { const req = idbFactory.open(databaseName, databaseVersion); req.onerror = (e) => { console.log("taler database error", e); reject(new Error("database error")); }; req.onsuccess = (e) => { - req.result.onversionchange = (evt: idbtypes.IDBVersionChangeEvent) => { + req.result.onversionchange = (evt: IDBVersionChangeEvent) => { console.log( `handling live db version change from ${evt.oldVersion} to ${evt.newVersion}`, ); @@ -442,9 +452,9 @@ export function openDatabase( } export class Database { - constructor(private db: idbtypes.IDBDatabase) {} + constructor(private db: IDBDatabase) {} - static deleteDatabase(idbFactory: idbtypes.IDBFactory, dbName: string): void { + static deleteDatabase(idbFactory: IDBFactory, dbName: string): void { idbFactory.deleteDatabase(dbName); } @@ -468,7 +478,7 @@ export class Database { dump.stores[name] = storeDump; tx.objectStore(name) .openCursor() - .addEventListener("success", (e: idbtypes.Event) => { + .addEventListener("success", (e: Event) => { const cursor = (e.target as any).result; if (cursor) { storeDump[cursor.key] = cursor.value; @@ -512,7 +522,7 @@ export class Database { return v; } - async getIndexed<S extends idbtypes.IDBValidKey, T>( + async getIndexed<S extends IDBValidKey, T>( index: Index<S, T>, key: any, ): Promise<T | undefined> { @@ -548,7 +558,7 @@ export class Database { return new ResultStream<T>(req); } - iterIndex<S extends idbtypes.IDBValidKey, T>( + iterIndex<S extends IDBValidKey, T>( index: Index<S, T>, query?: any, ): ResultStream<T> { diff --git a/packages/taler-wallet-core/tsconfig.json b/packages/taler-wallet-core/tsconfig.json index 07e8ab0bf..e3bfd31a7 100644 --- a/packages/taler-wallet-core/tsconfig.json +++ b/packages/taler-wallet-core/tsconfig.json @@ -28,5 +28,5 @@ "path": "../idb-bridge/" } ], - "include": ["src/**/*"] + "include": ["src/**/*"], } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b33728098..d8ff6bb22 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ importers: '@types/node': 14.0.27 tslib: 2.0.0 devDependencies: + '@microsoft/api-extractor': 7.9.3 '@rollup/plugin-typescript': 5.0.2_d508d998c8e6588bf77175f7541372d0 ava: 3.11.0 esm: 3.2.25 @@ -13,6 +14,7 @@ importers: rollup: 2.23.0 typescript: 3.9.7 specifiers: + '@microsoft/api-extractor': ^7.9.3 '@rollup/plugin-typescript': ^5.0.2 '@types/node': ^14.0.27 ava: ^3.10.1 @@ -121,6 +123,7 @@ importers: tslib: 2.0.0 devDependencies: '@ava/typescript': 1.1.1 + '@microsoft/api-extractor': 7.9.3 '@typescript-eslint/eslint-plugin': 3.7.1_98f5354ad0bbc327ab4925c12674a6b1 '@typescript-eslint/parser': 3.7.1_eslint@7.6.0+typescript@3.9.7 ava: 3.11.0 @@ -147,6 +150,7 @@ importers: typescript: 3.9.7 specifiers: '@ava/typescript': ^1.1.1 + '@microsoft/api-extractor': ^7.9.3 '@types/node': ^14.0.27 '@typescript-eslint/eslint-plugin': ^3.6.1 '@typescript-eslint/parser': ^3.6.1 @@ -436,6 +440,33 @@ packages: node: '>=8' resolution: integrity: sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== + /@microsoft/api-extractor-model/7.8.13: + dependencies: + '@microsoft/tsdoc': 0.12.19 + '@rushstack/node-core-library': 3.26.1 + dev: true + resolution: + integrity: sha512-SspJ84pZEZfF5jcVkwtdmgpnxjwMwJxQkK+v868jF6Ue/rJZ7WV/+qFB76gxLXNPsnVhF/xdS8s4AWXL0ePN8g== + /@microsoft/api-extractor/7.9.3: + dependencies: + '@microsoft/api-extractor-model': 7.8.13 + '@microsoft/tsdoc': 0.12.19 + '@rushstack/node-core-library': 3.26.1 + '@rushstack/ts-command-line': 4.4.6 + colors: 1.2.5 + lodash: 4.17.19 + resolve: 1.17.0 + semver: 7.3.2 + source-map: 0.6.1 + typescript: 3.9.7 + dev: true + hasBin: true + resolution: + integrity: sha512-8NXXmL+RhkHbL84lyFcjtqm6/IJxcGCckm2bIQFTyRjH4atshvpkuYy/IsTuRSuQ6XHEPa6QNze8IwEhhV5zPA== + /@microsoft/tsdoc/0.12.19: + dev: true + resolution: + integrity: sha512-IpgPxHrNxZiMNUSXqR1l/gePKPkfAmIKoDRP9hp7OwjU29ZR8WCJsOJ8iBKgw0Qk+pFwR+8Y1cy8ImLY6e9m4A== /@nodelib/fs.scandir/2.1.3: dependencies: '@nodelib/fs.stat': 2.0.3 @@ -542,6 +573,26 @@ packages: rollup: ^1.20.0||^2.0.0 resolution: integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== + /@rushstack/node-core-library/3.26.1: + dependencies: + '@types/node': 10.17.13 + colors: 1.2.5 + fs-extra: 7.0.1 + jju: 1.4.0 + semver: 7.3.2 + timsort: 0.3.0 + z-schema: 3.18.4 + dev: true + resolution: + integrity: sha512-N2wewcrJS2Jut73qxi711D1OXVKd9+8YmCllcjxEN++88qqqxCQVnn6Iu9ydu79Frm5rV8p/zvHOLCeUm/mLOQ== + /@rushstack/ts-command-line/4.4.6: + dependencies: + '@types/argparse': 1.0.38 + argparse: 1.0.10 + colors: 1.2.5 + dev: true + resolution: + integrity: sha512-ue3p2m773Yea/s4Ef2Q3gEyLd9T0NDjXCl+PlodGTrJHgxoiRwbROSWHAdYJL/LceGWa6Biqizu9qxUDEWFweQ== /@sindresorhus/is/0.14.0: dev: true engines: @@ -556,6 +607,10 @@ packages: node: '>=6' resolution: integrity: sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA== + /@types/argparse/1.0.38: + dev: true + resolution: + integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA== /@types/cheerio/0.22.21: dependencies: '@types/node': 14.0.27 @@ -631,6 +686,10 @@ packages: dev: true resolution: integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== + /@types/node/10.17.13: + dev: true + resolution: + integrity: sha512-pMCcqU2zT4TjqYFrWtYHKal7Sl30Ims6ulZ4UFXxI4xbtQqK/qqKwkDoBFCfooRqqmRu9vY3xaJRwxSh673aYg== /@types/node/11.15.20: dev: false resolution: @@ -1413,6 +1472,12 @@ packages: dev: true resolution: integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + /colors/1.2.5: + dev: true + engines: + node: '>=0.1.90' + resolution: + integrity: sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg== /commander/2.20.3: dev: true resolution: @@ -2312,6 +2377,16 @@ packages: dev: true resolution: integrity: sha512-Xu2Qh8yqYuDhQGOhD5iJGninErSfI9A3FrriD3tjUgV5VbJFeH8vfgZ9HnC6jWN80QDVNQK5vmxRAmEAp7Mevw== + /fs-extra/7.0.1: + dependencies: + graceful-fs: 4.2.4 + jsonfile: 4.0.0 + universalify: 0.1.2 + dev: true + engines: + node: '>=6 <7 || >=8' + resolution: + integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== /fs-extra/8.1.0: dependencies: graceful-fs: 4.2.4 @@ -2962,6 +3037,10 @@ packages: node: '>= 10.14.2' resolution: integrity: sha512-+XcGMMJDTeEGncRb5M5Zq9P7K4sQ1sirhjdOxsN1462h6lFo9w59bl2LVQmdGEEeU3m+maZCkS2Tcc9SfCHO4A== + /jju/1.4.0: + dev: true + resolution: + integrity: sha1-o6vicYryQaKykE+EpiWXDzia4yo= /js-string-escape/1.0.1: dev: true engines: @@ -3128,6 +3207,10 @@ packages: dev: true resolution: integrity: sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= + /lodash.get/4.4.2: + dev: true + resolution: + integrity: sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= /lodash.isequal/4.5.0: dev: true resolution: @@ -4538,6 +4621,10 @@ packages: node: '>=4' resolution: integrity: sha1-mcW/VZWJZq9tBtg73zgA3IL67F0= + /timsort/0.3.0: + dev: true + resolution: + integrity: sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q= /to-fast-properties/2.0.0: dev: true engines: @@ -4755,6 +4842,12 @@ packages: dev: true resolution: integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== + /validator/8.2.0: + dev: true + engines: + node: '>= 0.10' + resolution: + integrity: sha512-Yw5wW34fSv5spzTXNkokD6S6/Oq92d8q/t14TqsS3fAiA1RYnxSFSIZ+CY3n6PGGRCq5HhJTSepQvFUS2QUDxA== /wcwidth/1.0.1: dependencies: defaults: 1.0.3 @@ -4872,3 +4965,14 @@ packages: node: '>=6' resolution: integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== + /z-schema/3.18.4: + dependencies: + lodash.get: 4.4.2 + lodash.isequal: 4.5.0 + validator: 8.2.0 + dev: true + hasBin: true + optionalDependencies: + commander: 2.20.3 + resolution: + integrity: sha512-DUOKC/IhbkdLKKiV89gw9DUauTV8U/8yJl1sjf6MtDmzevLKOF2duNJ495S3MFVjqZarr+qNGCPbkg4mu4PpLw== |