Skip to content

Commit

Permalink
Adding all type definitions to main zulip-js project, updated babel t…
Browse files Browse the repository at this point in the history
…o copy type definition files to lib/ in build script
  • Loading branch information
tcarrio committed Jan 4, 2020
1 parent 43892b8 commit fbc43f3
Show file tree
Hide file tree
Showing 17 changed files with 1,012 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"sinon": "^7.5.0"
},
"scripts": {
"build": "babel -d lib/ src/",
"build": "babel -D -d lib/ src/",
"prepare": "npm run build",
"prepublish": "npm run build",
"lint": "eslint src test examples",
Expand Down
9 changes: 9 additions & 0 deletions src/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Config } from "./zuliprc";
import { ZulipSuccessResponse, ZulipErrorResponse } from "./types";

export function api(
baseUrl: string,
config: Config,
method: any,
params: any
): Promise<ZulipSuccessResponse | ZulipErrorResponse>;
7 changes: 7 additions & 0 deletions src/helper.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fetch from "isomorphic-fetch";
import FormData from "isomorphic-form-data";

export {
fetch,
FormData,
}
60 changes: 60 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Config } from "./zuliprc";
import { AccountsClient } from "./resources/accounts";
import { StreamsClient } from "./resources/streams";
import { QueuesClient } from "./resources/queues";
import { EventsClient } from "./resources/events";
import { UsersClient } from "./resources/users";
import { EmojisClient } from "./resources/emojis";
import { TypingClient } from "./resources/typing";
import { ReactionsClient } from "./resources/reactions";
import { ServerClient } from "./resources/server";
import { FiltersClient } from "./resources/filters";
import { MessagesClient } from "./resources/messages";

export type HttpMethod =
| "GET"
| "HEAD"
| "POST"
| "PUT"
| "DELETE"
| "TRACE"
| "OPTIONS"
| "CONNECT"
| "PATCH";

export interface Params {
[key: string]: any;
[key: number]: any;
}

export interface ZuliprcConfig {
zuliprc: string;
}

export interface ZulipClient {
config: Config;
callEndpoint: typeof callEndpoint;
accounts: AccountsClient;
streams: StreamsClient;
messages: MessagesClient;
queues: QueuesClient;
events: EventsClient;
users: UsersClient;
emojis: EmojisClient;
typing: TypingClient;
reactions: ReactionsClient;
server: ServerClient;
filters: FiltersClient;
}

export type InitialConfig = ZuliprcConfig | Pick<Config, "realm">;

export function getCallEndpoint(config: Config): typeof callEndpoint;

export function callEndpoint(endpoint: string, method: HttpMethod, params: Params): Promise<unknown>;

export function resources(config: Config): ZulipClient;

export function zulip(initialConfig: Partial<InitialConfig>): Promise<unknown>;

export * from "./types";
13 changes: 13 additions & 0 deletions src/resources/accounts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Config } from "../zuliprc";
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";

export type AccountsClient = RetrieverClient;

// SECTION GET ACCOUNTS
// TODO Find documentation on Get Accounts
export interface GetAccountsParams { }
export type GetAccountsResponse = GetAccountsSuccess | GetAccountsError;
export interface GetAccountsSuccess extends ZulipSuccessResponse { }
export interface GetAccountsError extends ZulipErrorResponse { }

export default function accounts(config: Config): AccountsClient;
42 changes: 42 additions & 0 deletions src/resources/emojis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Config } from "../zuliprc";
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";

export type EmojisClient = RetrieverClient;

// SECTION GET EMOJIS
export interface GetEmojisParams { }

export type GetEmojisResponse = GetEmojisSuccess | GetEmojisError;

export interface GetEmojisSuccess extends ZulipSuccessResponse {
emoji: {
[key: number]: Emoji;
}
}

export interface Emoji {
author: {
email: string;
full_name: string;
id: number;
},
deactivated: boolean;
id: string;
name: string;
source_url: string;
}

export interface GetEmojisError extends ZulipErrorResponse { }

// SECTION UPLOAD EMOJIS
// TODO Find documentation on Get Emojis
export interface UploadEmojisParams { }

export type UploadEmojisResponse = UploadEmojisSuccess | UploadEmojisError;

export interface UploadEmojisSuccess extends ZulipSuccessResponse { }

export interface UploadEmojisError extends ZulipErrorResponse { }


export default function emojis(config: Config): EmojisClient;
48 changes: 48 additions & 0 deletions src/resources/events.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Config } from "../zuliprc";
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";

export type EventsClient = RetrieverClient;

// SECTION GET EVENTS
export interface GetEventsParams {
/** "1375801870:2942" No The ID of a queue that you registered via POST /api/v1/register (see Register a queue). */
queue_id?: string;
/** -1 No The highest event ID in this queue that you've received and wish to acknowledge. See the code for call_on_each_event in the zulip Python module for an example implementation of correctly processing each event exactly once. */
last_event_id?: number;
/** true No Set to true if the client is requesting a nonblocking reply. If not specified, the request will block until either a new event is available or a few minutes have passed, in which case the server will send the client a heartbeat event. Defaults to false. */
dont_block?: boolean;
}

export type GetEventsResponse = GetEventsSuccess | GetEventsError;

export interface GetEventsSuccess extends ZulipSuccessResponse {
events: Event[]
}

export type Event = MessageEvent | any;

export interface MessageEvent {
avatar_url: string;
client: string;
content: string;
content_type: string;
display_recipient: string;
id: number;
recipient_id: number;
sender_email: string;
sender_full_name: string;
sender_id: number;
sender_realm_str: string;
sender_short_name: string;
subject: string;
subject_links: string[],
timestamp: number;
type: string;
}

export interface GetEventsError extends ZulipErrorResponse {
code: string;
queue_id: string;
}

export function events(config: Config): EventsClient;
9 changes: 9 additions & 0 deletions src/resources/filters.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Config } from "../zuliprc";
import { RetrieverClient } from "../types";

export type FiltersClient = RetrieverClient;

// SECTION GET FILTERS FOR REALM
// TODO Find documentation on Get Filters for Realm

export function filters(config: Config): FiltersClient;
Loading

0 comments on commit fbc43f3

Please sign in to comment.