Skip to content

Commit

Permalink
Typings Fixes (#835)
Browse files Browse the repository at this point in the history
* fix return types for `.fetch()` and `.watch()`, export additional types

Fixes #834

* add `.hasAuthToken()` and `.authEndpoint()`
  • Loading branch information
marshall007 authored and deontologician committed Sep 21, 2016
1 parent 4b72b87 commit a11ac62
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,49 @@
import { Observable } from 'rxjs';

declare namespace hz {

interface Feed {
watch (options?: { rawChanges: boolean }): Observable<any>;
fetch (): Observable<any>;
}

type Bound = 'open' | 'closed';
type Direction = 'ascending' | 'descending';
type Primitive = boolean | number | string | Date;
type IdValue = Primitive | Primitive[] | { id: Primitive };
type WriteOp = Object | Object[];

interface TermBase {
watch (options?: { rawChanges: boolean }): TermBase;
fetch (): TermBase;

findAll (...values: IdValue[]): TermBase;
interface TermBase extends Feed {
find (value: IdValue): TermBase;
findAll (...values: IdValue[]): TermBase;

order (fields: string[], direction?: Direction): TermBase;
limit (size: Number): TermBase;
above (spec: any, bound?: Bound): TermBase;
below (spec: any, bound?: Bound): TermBase;
}

type WriteOp = Object | Object[];

interface Collection extends TermBase {
store (docs: WriteOp): Observable<any>;
upsert (docs: WriteOp): Observable<any>;
insert (docs: WriteOp): Observable<any>;
replace (docs: WriteOp): Observable<any>;
update (docs: WriteOp): Observable<any>;

remove (docs: IdValue): Observable<any>;
remove (docs: IdValue[]): Observable<any>;
removeAll (docs: IdValue[]): Observable<any>;
}

interface User extends TermBase {}
interface User extends Feed {}

interface HorizonInstance {
(name: string): Collection;

currentUser (): User;

hasAuthToken (): boolean;
authEndpoint (name: string): Observable<string>;

aggregate (aggs: any): TermBase;
model (fn: Function): TermBase;

Expand Down Expand Up @@ -70,5 +76,11 @@ declare namespace hz {
}
}

export type HorizonOptions = hz.HorizonOptions;
export type HorizonInstance = hz.HorizonInstance;
export type TermBase = hz.TermBase;
export type Collection = hz.Collection;
export type User = hz.User;

declare var Horizon: hz.Horizon;
export default Horizon;

0 comments on commit a11ac62

Please sign in to comment.