-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
412 additions
and
268 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,5 +1,13 @@ | ||
{ | ||
"parser": "babylon", | ||
"printWidth": 100, | ||
"trailingComma": "all" | ||
"trailingComma": "all", | ||
"overrides": [ | ||
{ | ||
"files": "*.ts", | ||
"options": { | ||
"parser": "typescript" | ||
} | ||
} | ||
] | ||
} |
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,41 @@ | ||
declare module '@nozbe/watermelondb/Collection' { | ||
import { Database, Model, Query, RecordId, TableName, TableSchema } from '@nozbe/watermelondb' | ||
import { Condition } from '@nozbe/watermelondb/QueryDescription' | ||
import { Class } from '@nozbe/watermelondb/utils/common' | ||
import { Observable, Subject } from 'rxjs' | ||
|
||
export interface CollectionChange<Record extends Model> { | ||
record: Record | ||
isDestroyed: boolean | ||
} | ||
|
||
export default class Collection<Record extends Model> { | ||
public database: Database | ||
|
||
public modelClass: Class<Record> | ||
|
||
public changes: Subject<CollectionChange<Record>> | ||
|
||
public table: TableName<Record> | ||
|
||
public schema: TableSchema | ||
|
||
public constructor(database: Database, ModelClass: Class<Record>) | ||
|
||
public find(id: RecordId): Promise<Record> | ||
|
||
public findAndObserve(id: RecordId): Observable<Record> | ||
|
||
public query(...conditions: Condition[]): Query<Record> | ||
|
||
public create(recordBuilder?: (record: Record) => void): Promise<Record> | ||
|
||
public prepareCreate(recordBuilder?: (record: Record) => void): Record | ||
|
||
public fetchQuery(query: Query<Record>): Promise<Record[]> | ||
|
||
public fetchCount(query: Query<Record>): Promise<number> | ||
|
||
public unsafeClearCache(): void | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
declare module '@nozbe/watermelondb/Database/CollectionMap' { | ||
import { Collection, Database, Model, TableName } from '@nozbe/watermelondb' | ||
import { Class } from '@nozbe/watermelondb/utils/common' | ||
|
||
export default class CollectionMap { | ||
public map: { [tableName: string]: Collection<any> } | ||
|
||
public constructor(database: Database, modelClasses: Array<Class<Model>>) | ||
|
||
public get<T extends Model>(tableName: TableName<T>): Collection<T> | ||
} | ||
} |
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 @@ | ||
declare module '@nozbe/watermelondb/Database' { | ||
import { AppSchema, CollectionMap, DatabaseAdapter, Model, TableName } from '@nozbe/watermelondb' | ||
import { CollectionChange } from '@nozbe/watermelondb/Collection' | ||
import { Class } from '@nozbe/watermelondb/utils/common' | ||
import { Observable } from 'rxjs' | ||
|
||
export interface ActionInterface { | ||
subAction<T>(action: () => Promise<T>): Promise<T> | ||
} | ||
|
||
export default class Database { | ||
public adapter: DatabaseAdapter | ||
|
||
public schema: AppSchema | ||
|
||
public collections: CollectionMap | ||
|
||
public constructor(options: { adapter: DatabaseAdapter; modelClasses: Array<Class<Model>> }) | ||
|
||
public batch(...records: Model[]): Promise<void> | ||
|
||
// FIXME: action<T>(work: ActionInterface => Promise<T>, description?: string): Promise<T> | ||
public action<T>(work: any, description?: string): Promise<T> | ||
|
||
public withChangesForTables( | ||
tables: Array<TableName<any>>, | ||
): Observable<CollectionChange<any> | null> | ||
|
||
public unsafeResetDatabase(): Promise<void> | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
declare module '@nozbe/watermelondb/DatabaseProvider' { | ||
import * as React from 'react' | ||
import Database from '@nozbe/watermelondb/Database' | ||
|
||
export interface DatabaseProviderProps { | ||
children?: React.ReactChild // only one child is allowed, goes through React.Children.only | ||
database: Database | ||
} | ||
|
||
export const DatabaseProviderComponent: React.ComponentClass<DatabaseProviderProps> | ||
|
||
/** | ||
* HOC | ||
* https://gist.github.com/thehappybug/88342c122cfb1df9f14c9a10fb4926e4 | ||
*/ | ||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | ||
export function withDatabase<P extends { database?: Database }, R = Omit<P, 'database'>>( | ||
Component: React.ComponentType<P> | React.FunctionComponent<P>, | ||
): React.FunctionComponent<R> | ||
|
||
export default DatabaseProviderComponent | ||
} |
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,14 @@ | ||
declare module '@nozbe/watermelondb/Model/helper' { | ||
import { Model } from '@nozbe/watermelondb' | ||
|
||
export const hasUpdatedAt: (obj: Object) => boolean | ||
|
||
export const createTimestampsFor: ( | ||
model: Model, | ||
) => { | ||
created_at: Date | ||
updated_at: Date | ||
} | ||
|
||
export function addToRawSet(rawSet: string | void, value: string): string | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
declare module '@nozbe/watermelondb/Model' { | ||
import { ColumnName, TableName, Collection } from '@nozbe/watermelondb' | ||
import { Observable } from 'rxjs' | ||
|
||
export type RecordId = string | ||
|
||
export type SyncStatus = 'synced' | 'created' | 'updated' | 'deleted' | ||
|
||
export interface BelongsToAssociation { | ||
type: 'belongs_to' | ||
key: ColumnName | ||
} | ||
export interface HasManyAssociation { | ||
type: 'has_many' | ||
foreignKey: ColumnName | ||
} | ||
export type AssociationInfo = BelongsToAssociation | HasManyAssociation | ||
export interface Associations { | ||
[tableName: string]: AssociationInfo | ||
} | ||
|
||
export function associations( | ||
...associationList: Array<[TableName<any>, AssociationInfo]> | ||
): Associations | ||
|
||
export default class Model { | ||
// FIXME: How to correctly point to a static this? | ||
public static table: TableName<Model> | ||
|
||
public static associations: Associations | ||
|
||
public id: RecordId | ||
|
||
public syncStatus: SyncStatus | ||
|
||
public update(recordUpdater?: (this: this) => void): Promise<void> | ||
|
||
public prepareUpdate(recordUpdater?: (this: this) => void): this | ||
|
||
public markAsDeleted(): Promise<void> | ||
|
||
public destroyPermanently(): Promise<void> | ||
|
||
public observe(): Observable<this> | ||
|
||
public batch(...records: Readonly<[Model]>): Promise<void> | ||
|
||
public subAction<T>(action: () => Promise<T>): Promise<T> | ||
|
||
public collection: Collection<this> | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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.