Skip to content

Commit 6d5501c

Browse files
author
Michael
committed
2.0.0: types & structure.
1 parent 3dc9d43 commit 6d5501c

16 files changed

+195
-86
lines changed

dist/src/SHA1.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _default: (str1: string) => string;
2+
export default _default;

dist/src/WS.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import "./types";
2+
declare class WebSocketClient implements wsc.WebSocketClient {
3+
private open;
4+
private ws;
5+
private forcibly_closed;
6+
private reconnect_timeout;
7+
private queue;
8+
private messages;
9+
private onReadyQueue;
10+
private onCloseQueue;
11+
private config;
12+
private init_flush;
13+
private log;
14+
private connect;
15+
readonly socket: any;
16+
ready(): Promise<{}>;
17+
on(event_name: string, handler: (data: any) => any, predicate?: (data: any) => boolean): void;
18+
close(): wsc.AsyncErrCode;
19+
send(message_data: any, opts?: wsc.SendOptions): wsc.AsyncErrCode;
20+
constructor(user_config?: wsc.UserConfig);
21+
}
22+
export default WebSocketClient;

dist/src/connectLib.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./types";
2+
declare const connectLib: (ff: any) => any;
3+
export default connectLib;

dist/src/types.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
declare namespace wsc {
2+
/** Stuff that in use by this lib. */
3+
interface Socket {
4+
readyState: number;
5+
send(...any: any[]): void;
6+
close(): void;
7+
addEventListener(event: string, handler: ((event: any) => any), ...any: any[]): void;
8+
}
9+
type AsyncErrCode = Promise<number | null | {}>;
10+
type EventHandler = (e: any) => void;
11+
type DataPipe = (message: any) => any;
12+
type DataType = 'json' | 'string';
13+
interface Config {
14+
data_type: DataType;
15+
log(event: string, time?: number, message?: any): void;
16+
log(event: string, message?: any): void;
17+
timer: boolean;
18+
url: string;
19+
timeout: number;
20+
reconnect: number;
21+
lazy: boolean;
22+
socket: Socket;
23+
adapter: (host: string, protocols?: string[]) => Socket;
24+
encode: (key: string, message: any, config: Config) => any;
25+
decode: (rawMessage: any) => {
26+
[id_or_data_key: string]: string;
27+
};
28+
protocols: string[];
29+
pipes: DataPipe[];
30+
server: {
31+
id_key: string;
32+
data_key: string;
33+
};
34+
}
35+
type UserConfig = Partial<Config>;
36+
interface SendOptions {
37+
top: any;
38+
data_type: DataType;
39+
}
40+
class WebSocketClient {
41+
on(event_name: string, handler: (event: string) => void, predicate?: (event: string) => boolean): void;
42+
close(): Promise<void | {}>;
43+
send(user_message: any, opts: wsc.SendOptions): AsyncErrCode;
44+
constructor(user_config: wsc.UserConfig);
45+
}
46+
}

dist/src/utils.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./types";
2+
declare const add_event: (o: wsc.Socket, e: string, handler: wsc.EventHandler) => void;
3+
declare const once: (fn: Function) => (...args: any) => any;
4+
export { add_event, once, };

dist/ws.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ws.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 64 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"Easy",
2020
"realtime",
2121
"Middleware",
22+
"JSON",
2223
"Data",
2324
"transport",
2425
"API",
@@ -34,15 +35,15 @@
3435
},
3536
"scripts": {
3637
"lint": "./node_modules/.bin/tslint 'src/**/*.ts'",
37-
"test": "npm run test:compile && npm run test:exec",
38+
"test": "npm run prod:es && npm run test:compile && npm run test:exec",
3839
"test:compile": "./node_modules/.bin/tsc -p ./test/",
39-
"test:exec": "npm run prod:es && ./node_modules/.bin/ava ./test/dist/test/src/index.js",
40-
"dev": "rollup --watch -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:development",
41-
"prod:cjs": "rollup -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:cjs",
42-
"prod:es": "rollup -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:es",
40+
"test:exec": "./node_modules/.bin/ava ./test/dist/test/src/index.js",
41+
"dev": "rollup --watch -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:development",
42+
"prod:cjs": "rollup -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:cjs",
43+
"prod:es": "rollup -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:es",
4344
"prod": "npm run prod:es && npm run prod:cjs"
4445
},
45-
"version": "1.1.3",
46+
"version": "2.0.0",
4647
"devDependencies": {
4748
"@types/node": "^8.0.58",
4849
"@types/ramda": "^0.25.8",
@@ -51,6 +52,7 @@
5152
"axios": "^0.17.1",
5253
"express": "^4.16.2",
5354
"ramda": "^0.25.0",
55+
"randomatic": "^3.1.1",
5456
"rollup": "^0.52.1",
5557
"rollup-plugin-alias": "^1.4.0",
5658
"rollup-plugin-commonjs": "^8.2.6",
@@ -63,5 +65,5 @@
6365
"uglify-es": "^3.3.9",
6466
"ws": "^3.3.2"
6567
},
66-
"types": "./index.d.ts"
68+
"types": "./dist/src/WS.d.ts"
6769
}

src/rollup.config.js renamed to rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
commonjs(),
1818
typescript({
1919
typescript: require("typescript"),
20-
tsconfig: "./src/tsconfig.json",
20+
tsconfig: "./tsconfig.json",
2121
tsconfigOverride: {
2222
compilerOptions: {
2323
sourceMap: false,

0 commit comments

Comments
 (0)