From 50f6a38cdac889f1c4a27d292c52d3ae5b2bc06f Mon Sep 17 00:00:00 2001 From: Alexandro Date: Tue, 15 Nov 2016 19:37:46 +0700 Subject: [PATCH] add types for typescript's projects --- package.json | 3 ++- types.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 types.d.ts diff --git a/package.json b/package.json index ed042aa..ebcd383 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "lokka", "version": "1.7.0", "description": "Simple JavaScript client for GraphQL", + "types": "types.d.ts", "repository": { "type": "git", "url": "https://github.com/kadirahq/lokka.git" @@ -42,4 +43,4 @@ "babel-runtime": "6.x.x", "uuid": "2.x.x" } -} +} \ No newline at end of file diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000..b522d6e --- /dev/null +++ b/types.d.ts @@ -0,0 +1,38 @@ +declare namespace Lokka { + export type QL = string; + export interface ITransport { + send(rawQuery: string, variables: { [index: string]: any }, operationName: string); + } + export interface IConfig { + transport: ITransport; + } + export interface IVars { [index: string]: any } + export type IFragment = string; + export interface IWatchHandler { + (err, payload: T): any; + } + export interface IStop { + (): void; + } + export interface ICacheConfig { + cacheExpirationTimeout?: number; + } + export interface ICache { + getItemPayload(query: QL, vars?: IVars): T; + setItemPayload(query: QL, vars: IVars, payload: T): void; + fireError(query: QL, vars: IVars, error): void; + removeItem(query: QL, vars?: IVars): void; + getItem(query: QL, vars?: IVars): T; + } + export class Lokka { + constructor(config: IConfig); + query(query: QL, vars?: IVars): Promise; + mutate(query: QL, vars?: IVars): Promise; + watchQuery(query: QL, handler?: IWatchHandler): IStop; + watchQuery(query: QL, vars?: IVars, handler?: IWatchHandler): IStop; + createFragment(fragment: QL): IFragment; + refetchQuery(query: QL, vars?: IVars): void; + cache: ICache; + } +} +export = Lokka \ No newline at end of file