forked from dexie/Dexie.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So that each db has its own versions of Table, Collection etc and addons only extend the prototypes bound to the db and not globally.
- Loading branch information
1 parent
f7bb2aa
commit 91b5eef
Showing
38 changed files
with
563 additions
and
567 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import { ThenShortcut } from "./then-shortcut"; | ||
import { IndexableType, IndexableTypeArray } from "./indexable-type"; | ||
import { IDBValidKey, IndexableTypeArray } from "./indexeddb"; | ||
import { WhereClause } from "./where-clause"; | ||
import Promise from "./promise-extended"; | ||
import { PromiseExtended } from "./promise-extended"; | ||
import { Database } from "./database"; | ||
|
||
export interface Collection<T=any, TKey extends IndexableType=any> { | ||
export interface Collection<T=any, TKey extends IDBValidKey=IDBValidKey> { | ||
//db: Database; | ||
and(filter: (x: T) => boolean): Collection<T, TKey>; | ||
clone(props?: Object): Collection<T, TKey>; | ||
count(): Promise<number>; | ||
count<R>(thenShortcut: ThenShortcut<number, R>): Promise<R>; | ||
count(): PromiseExtended<number>; | ||
count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>; | ||
distinct(): Collection<T, TKey>; | ||
each(callback: (obj: T, cursor: {key: IndexableType, primaryKey: TKey}) => any): Promise<void>; | ||
eachKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: TKey}) => any): Promise<void>; | ||
eachPrimaryKey(callback: (key: TKey, cursor: {key: IndexableType, primaryKey: TKey}) => any): Promise<void>; | ||
eachUniqueKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: TKey}) => any): Promise<void>; | ||
each(callback: (obj: T, cursor: {key: IDBValidKey, primaryKey: TKey}) => any): PromiseExtended<void>; | ||
eachKey(callback: (key: IDBValidKey, cursor: {key: IDBValidKey, primaryKey: TKey}) => any): PromiseExtended<void>; | ||
eachPrimaryKey(callback: (key: TKey, cursor: {key: IDBValidKey, primaryKey: TKey}) => any): PromiseExtended<void>; | ||
eachUniqueKey(callback: (key: IDBValidKey, cursor: {key: IDBValidKey, primaryKey: TKey}) => any): PromiseExtended<void>; | ||
filter(filter: (x: T) => boolean): Collection<T, TKey>; | ||
first(): Promise<T | undefined>; | ||
first<R>(thenShortcut: ThenShortcut<T | undefined, R>): Promise<R>; | ||
keys(): Promise<IndexableTypeArray>; | ||
keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): Promise<R>; | ||
primaryKeys(): Promise<TKey[]>; | ||
primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): Promise<R>; | ||
last(): Promise<T | undefined>; | ||
last<R>(thenShortcut: ThenShortcut<T | undefined, R>): Promise<R>; | ||
first(): PromiseExtended<T | undefined>; | ||
first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>; | ||
keys(): PromiseExtended<IndexableTypeArray>; | ||
keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>; | ||
primaryKeys(): PromiseExtended<TKey[]>; | ||
primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>; | ||
last(): PromiseExtended<T | undefined>; | ||
last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>; | ||
limit(n: number): Collection<T, TKey>; | ||
offset(n: number): Collection<T, TKey>; | ||
or(indexOrPrimayKey: string): WhereClause<T, TKey>; | ||
raw(): Collection<T, TKey>; | ||
reverse(): Collection<T, TKey>; | ||
sortBy(keyPath: string): Promise<T[]>; | ||
sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>) : Promise<R>; | ||
toArray(): Promise<Array<T>>; | ||
toArray<R>(thenShortcut: ThenShortcut<T[], R>) : Promise<R>; | ||
uniqueKeys(): Promise<IndexableTypeArray>; | ||
uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): Promise<R>; | ||
sortBy(keyPath: string): PromiseExtended<T[]>; | ||
sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>) : PromiseExtended<R>; | ||
toArray(): PromiseExtended<Array<T>>; | ||
toArray<R>(thenShortcut: ThenShortcut<T[], R>) : PromiseExtended<R>; | ||
uniqueKeys(): PromiseExtended<IndexableTypeArray>; | ||
uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>; | ||
until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey>; | ||
// Mutating methods | ||
delete(): Promise<number>; | ||
modify(changeCallback: (obj: T, ctx:{value: T}) => void): Promise<number>; | ||
modify(changes: { [keyPath: string]: any } ): Promise<number>; | ||
delete(): PromiseExtended<number>; | ||
modify(changeCallback: (obj: T, ctx:{value: T}) => void): PromiseExtended<number>; | ||
modify(changes: { [keyPath: string]: any } ): PromiseExtended<number>; | ||
} |
This file contains 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,31 @@ | ||
import { Table } from "./table"; | ||
import { IDBValidKey } from "./indexeddb"; | ||
import { TransactionMode } from "./transaction-mode"; | ||
import { PromiseExtended } from "./promise-extended"; | ||
import { WhereClause } from "./where-clause"; | ||
import { Collection } from "./collection"; | ||
|
||
export interface Database { | ||
readonly name: string; | ||
readonly tables: Table[]; | ||
|
||
table<T=any, TKey extends IDBValidKey=IDBValidKey>(tableName: string): Table<T, TKey>; | ||
|
||
transaction<U>(mode: TransactionMode, table: Table<any, any>, scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
transaction<U>(mode: TransactionMode, table: Table<any, any>, table2: Table<any, any>, scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
transaction<U>(mode: TransactionMode, table: Table<any, any>, table2: Table<any, any>, table3: Table<any, any>, scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
transaction<U>(mode: TransactionMode, table: Table<any, any>, table2: Table<any, any>, table3: Table<any, any>, table4: Table<any,any>, scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
transaction<U>(mode: TransactionMode, table: Table<any, any>, table2: Table<any, any>, table3: Table<any, any>, table4: Table<any,any>, table5: Table<any,any>, scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
transaction<U>(mode: TransactionMode, tables: Table<any, any>[], scope: () => PromiseLike<U> | U): PromiseExtended<U>; | ||
|
||
// Make it possible to touch physical class constructors where they reside - as properties on db instance. | ||
// For example, checking if (x instanceof db.Table). Can't do (x instanceof Dexie.Table because it's just a virtual interface) | ||
Table : {prototype: Table}; | ||
WhereClause: {prototype: WhereClause}; | ||
Collection: {prototype: Collection}; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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,11 @@ | ||
import { DexieEvent } from "./dexie-event"; | ||
import { DexieEventSet } from "./dexie-event-set"; | ||
|
||
export interface TransactionEvents extends DexieEventSet { | ||
(eventName: 'complete', subscriber: () => any): void; | ||
(eventName: 'abort', subscriber: () => any): void; | ||
(eventName: 'error', subscriber: (error:any) => any): void; | ||
complete: DexieEvent; | ||
abort: DexieEvent; | ||
error: DexieEvent; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { Dexie } from "./dexie"; | ||
import { Table } from "./table"; | ||
import { Database } from "./database"; | ||
import { IDBValidKey } from "./indexeddb"; | ||
import { TransactionEvents } from "./transaction-events"; | ||
|
||
export interface Transaction { | ||
//db: Database; | ||
active: boolean; | ||
db: Dexie; | ||
mode: string; | ||
idbtrans: IDBTransaction; | ||
tables: { [type: string]: Table<any, any> }; | ||
storeNames: Array<string>; | ||
on: TransactionEvents; | ||
abort(): void; | ||
table(tableName: string): Table<any, any>; | ||
table<T>(tableName: string): Table<T, any>; | ||
table<T, Key>(tableName: string): Table<T, Key>; | ||
table<T, Key extends IDBValidKey>(tableName: string): Table<T, Key>; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { IndexableType, IndexableTypeArray, IndexableTypeArrayReadonly } from "../types/indexable-type"; | ||
import { IDBValidKey, IndexableTypeArray, IndexableTypeArrayReadonly } from "./indexeddb"; | ||
import { Collection } from "./collection"; | ||
|
||
export interface WhereClause<T=any, Key extends IndexableType=any> { | ||
above(key: IndexableType): Collection<T, Key>; | ||
aboveOrEqual(key: IndexableType): Collection<T, Key>; | ||
anyOf(keys: IndexableTypeArrayReadonly): Collection<T, Key>; | ||
anyOf(...keys: IndexableTypeArray): Collection<T, Key>; | ||
anyOfIgnoreCase(keys: string[]): Collection<T, Key>; | ||
anyOfIgnoreCase(...keys: string[]): Collection<T, Key>; | ||
below(key: IndexableType): Collection<T, Key>; | ||
belowOrEqual(key: IndexableType): Collection<T, Key>; | ||
between(lower: IndexableType, upper: IndexableType, includeLower?: boolean, includeUpper?: boolean): Collection<T, Key>; | ||
equals(key: IndexableType): Collection<T, Key>; | ||
equalsIgnoreCase(key: string): Collection<T, Key>; | ||
inAnyRange(ranges: Array<IndexableTypeArrayReadonly>): Collection<T, Key>; | ||
startsWith(key: string): Collection<T, Key>; | ||
startsWithAnyOf(prefixes: string[]): Collection<T, Key>; | ||
startsWithAnyOf(...prefixes: string[]): Collection<T, Key>; | ||
startsWithIgnoreCase(key: string): Collection<T, Key>; | ||
startsWithAnyOfIgnoreCase(prefixes: string[]): Collection<T, Key>; | ||
startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection<T, Key>; | ||
noneOf(keys: Array<IndexableType>): Collection<T, Key>; | ||
notEqual(key: IndexableType): Collection<T, Key>; | ||
export interface WhereClause<T=any, TKey extends IDBValidKey=IDBValidKey> { | ||
above(key: IDBValidKey): Collection<T, TKey>; | ||
aboveOrEqual(key: IDBValidKey): Collection<T, TKey>; | ||
anyOf(keys: IndexableTypeArrayReadonly): Collection<T, TKey>; | ||
anyOf(...keys: IndexableTypeArray): Collection<T, TKey>; | ||
anyOfIgnoreCase(keys: string[]): Collection<T, TKey>; | ||
anyOfIgnoreCase(...keys: string[]): Collection<T, TKey>; | ||
below(key: IDBValidKey): Collection<T, TKey>; | ||
belowOrEqual(key: IDBValidKey): Collection<T, TKey>; | ||
between(lower: IDBValidKey, upper: IDBValidKey, includeLower?: boolean, includeUpper?: boolean): Collection<T, TKey>; | ||
equals(key: IDBValidKey): Collection<T, TKey>; | ||
equalsIgnoreCase(key: string): Collection<T, TKey>; | ||
inAnyRange(ranges: Array<IndexableTypeArrayReadonly>): Collection<T, TKey>; | ||
startsWith(key: string): Collection<T, TKey>; | ||
startsWithAnyOf(prefixes: string[]): Collection<T, TKey>; | ||
startsWithAnyOf(...prefixes: string[]): Collection<T, TKey>; | ||
startsWithIgnoreCase(key: string): Collection<T, TKey>; | ||
startsWithAnyOfIgnoreCase(prefixes: string[]): Collection<T, TKey>; | ||
startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection<T, TKey>; | ||
noneOf(keys: Array<IDBValidKey>): Collection<T, TKey>; | ||
notEqual(key: IDBValidKey): Collection<T, TKey>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.