- Notifications
You must be signed in to change notification settings - Fork1.3k
Add builtin indexeddb from flow into environment#4590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Add builtin indexeddb from flow into environment
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit9a26761a45b448ee0c4abdf69439f0af61ed81bc
There are no files selected for viewing
142 changes: 142 additions & 0 deletionsdefinitions/environments/indexeddb/flow_v0.261.x-/indexeddb.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // Implemented by window & worker | ||
| declare interface IDBEnvironment { | ||
| indexedDB: IDBFactory; | ||
| } | ||
| type IDBDirection = 'next' | 'nextunique' | 'prev' | 'prevunique'; | ||
| type IDBTransactionDurability = 'default' | 'relaxed' | 'strict'; | ||
| // Implemented by window.indexedDB & worker.indexedDB | ||
| declare interface IDBFactory { | ||
| open(name: string, version?: number): IDBOpenDBRequest; | ||
| deleteDatabase(name: string): IDBOpenDBRequest; | ||
| /** | ||
| * Firefox introduced this method in its May 2024 release, | ||
| * having lagged behind other major browsers for several years. | ||
| * As of June 2024, previous versions of Firefox still account for 1.65% of global usage. | ||
| * For more details, see https://caniuse.com/mdn-api_idbfactory_databases | ||
| */ | ||
| databases?: () => Promise<Array<IDBDatabaseInfo>>; | ||
| cmp(a: any, b: any): -1|0|1; | ||
| } | ||
| declare interface IDBDatabaseInfo { | ||
| name: string; | ||
| version: number; | ||
| } | ||
| declare interface IDBRequest extends EventTarget { | ||
| result: IDBObjectStore; | ||
| error: Error; | ||
| source: ?(IDBIndex | IDBObjectStore | IDBCursor); | ||
| transaction: IDBTransaction; | ||
| readyState: 'pending'|'done'; | ||
| onerror: (err: any) => mixed; | ||
| onsuccess: (e: any) => mixed; | ||
| } | ||
| declare interface IDBOpenDBRequest extends IDBRequest { | ||
| onblocked: (e: any) => mixed; | ||
| onupgradeneeded: (e: any) => mixed; | ||
| } | ||
| declare interface IDBTransactionOptions { | ||
| durability?: IDBTransactionDurability; | ||
| } | ||
| declare interface IDBDatabase extends EventTarget { | ||
| close(): void; | ||
| createObjectStore(name: string, options?: { | ||
| keyPath?: ?(string|string[]), | ||
| autoIncrement?: boolean, | ||
| ... | ||
| }): IDBObjectStore; | ||
| deleteObjectStore(name: string): void; | ||
| transaction( | ||
| storeNames: string | string[] | DOMStringList, | ||
| mode?: 'readonly' | 'readwrite' | 'versionchange', | ||
| options?: IDBTransactionOptions | ||
| ): IDBTransaction; | ||
| name: string; | ||
| version: number; | ||
| objectStoreNames: DOMStringList; | ||
| onabort: (e: any) => mixed; | ||
| onclose: (e: any) => mixed; | ||
| onerror: (e: any) => mixed; | ||
| onversionchange: (e: any) => mixed; | ||
| } | ||
| declare interface IDBTransaction extends EventTarget { | ||
| abort(): void; | ||
| db: IDBDatabase; | ||
| +durability: IDBTransactionDurability; | ||
| error: Error; | ||
| mode: 'readonly'|'readwrite'|'versionchange'; | ||
| name: string; | ||
| objectStore(name: string): IDBObjectStore; | ||
| onabort: (e: any) => mixed; | ||
| oncomplete: (e: any) => mixed; | ||
| onerror: (e: any) => mixed; | ||
| } | ||
| declare interface IDBObjectStore { | ||
| add(value: any, key?: any): IDBRequest; | ||
| autoIncrement: boolean; | ||
| clear(): IDBRequest; | ||
| createIndex(indexName: string, keyPath: string|string[], optionalParameter?: { | ||
| unique?: boolean, | ||
| multiEntry?: boolean, | ||
| ... | ||
| }): IDBIndex; | ||
| count(keyRange?: any|IDBKeyRange): IDBRequest; | ||
| delete(key: any): IDBRequest; | ||
| deleteIndex(indexName: string): void; | ||
| get(key: any): IDBRequest; | ||
| index(indexName: string): IDBIndex; | ||
| indexNames: string[]; | ||
| name: string; | ||
| keyPath: any; | ||
| openCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; | ||
| openKeyCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; | ||
| put(value: any, key?: any): IDBRequest; | ||
| transaction : IDBTransaction; | ||
| } | ||
| declare interface IDBIndex extends EventTarget { | ||
| count(key?: any|IDBKeyRange): IDBRequest; | ||
| get(key: any|IDBKeyRange): IDBRequest; | ||
| getKey(key: any|IDBKeyRange): IDBRequest; | ||
| openCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; | ||
| openKeyCursor(range?: any|IDBKeyRange, direction?: IDBDirection): IDBRequest; | ||
| name: string; | ||
| objectStore: IDBObjectStore; | ||
| keyPath: any; | ||
| multiEntry: boolean; | ||
| unique: boolean; | ||
| } | ||
| declare interface IDBKeyRange { | ||
| bound(lower: any, upper: any, lowerOpen?: boolean, upperOpen?: boolean): IDBKeyRange; | ||
| only(value: any): IDBKeyRange; | ||
| lowerBound(bound: any, open?: boolean): IDBKeyRange; | ||
| upperBound(bound: any, open?: boolean): IDBKeyRange; | ||
| lower: any; | ||
| upper: any; | ||
| lowerOpen: boolean; | ||
| upperOpen: boolean; | ||
| } | ||
| declare interface IDBCursor { | ||
| advance(count: number): void; | ||
| continue(key?: any): void; | ||
| delete(): IDBRequest; | ||
| update(newValue: any): IDBRequest; | ||
| source: IDBObjectStore|IDBIndex; | ||
| direction: IDBDirection; | ||
| key: any; | ||
| primaryKey: any; | ||
| } | ||
| declare interface IDBCursorWithValue extends IDBCursor { | ||
| value: any; | ||
| } |
27 changes: 27 additions & 0 deletionsdefinitions/environments/indexeddb/flow_v0.261.x-/test_indexeddb.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // @flow | ||
| declare var indexedDB: IDBFactory; | ||
| if (indexedDB.databases) { | ||
| indexedDB.databases().then(databases => { | ||
| databases.forEach(db => console.log(db)) | ||
| }); | ||
| } | ||
| const openRequest = indexedDB.open('dbName', 1); | ||
| openRequest.onsuccess = function (e) { | ||
| const db = e.target.result as IDBDatabase; | ||
| const storeName = 'storeName'; | ||
| const transaction = db.transaction(storeName, 'readonly', {durability: 'relaxed'}); | ||
| // $FlowExpectedError[prop-missing] | ||
| transaction.objectStore(storeName).getAll(); | ||
| // $FlowExpectedError[prop-missing] | ||
| transaction.objectStore(storeName).getAll('q'); | ||
| // $FlowExpectedError[prop-missing] | ||
| transaction.objectStore(storeName).getAll(undefined, 3); | ||
| // $FlowExpectedError[prop-missing] | ||
| transaction.objectStore(storeName).getAll('q', 3); | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.