@eleven-am/pondsocket 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.eslintrc.js +28 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/pondsocket.iml +12 -0
  4. package/LICENSE +674 -0
  5. package/base.d.ts +1 -0
  6. package/base.js +17 -0
  7. package/client.d.ts +1 -0
  8. package/client.js +17 -0
  9. package/index.d.ts +1 -0
  10. package/index.js +17 -0
  11. package/jest.config.js +11 -0
  12. package/package.json +48 -0
  13. package/pondBase/baseClass.d.ts +37 -0
  14. package/pondBase/baseClass.js +111 -0
  15. package/pondBase/baseClass.test.js +73 -0
  16. package/pondBase/enums.d.ts +9 -0
  17. package/pondBase/enums.js +14 -0
  18. package/pondBase/index.d.ts +6 -0
  19. package/pondBase/index.js +22 -0
  20. package/pondBase/pondBase.d.ts +41 -0
  21. package/pondBase/pondBase.js +60 -0
  22. package/pondBase/pondBase.test.js +101 -0
  23. package/pondBase/pubSub.d.ts +73 -0
  24. package/pondBase/pubSub.js +138 -0
  25. package/pondBase/pubSub.test.js +309 -0
  26. package/pondBase/simpleBase.d.ts +131 -0
  27. package/pondBase/simpleBase.js +211 -0
  28. package/pondBase/simpleBase.test.js +153 -0
  29. package/pondBase/types.d.ts +2 -0
  30. package/pondBase/types.js +2 -0
  31. package/pondClient/channel.d.ts +66 -0
  32. package/pondClient/channel.js +152 -0
  33. package/pondClient/index.d.ts +2 -0
  34. package/pondClient/index.js +18 -0
  35. package/pondClient/socket.d.ts +42 -0
  36. package/pondClient/socket.js +116 -0
  37. package/pondSocket/channel.d.ts +134 -0
  38. package/pondSocket/channel.js +287 -0
  39. package/pondSocket/channel.test.js +377 -0
  40. package/pondSocket/channelMiddleWare.d.ts +26 -0
  41. package/pondSocket/channelMiddleWare.js +36 -0
  42. package/pondSocket/endpoint.d.ts +90 -0
  43. package/pondSocket/endpoint.js +323 -0
  44. package/pondSocket/endpoint.test.js +513 -0
  45. package/pondSocket/enums.d.ts +19 -0
  46. package/pondSocket/enums.js +25 -0
  47. package/pondSocket/index.d.ts +7 -0
  48. package/pondSocket/index.js +23 -0
  49. package/pondSocket/pondChannel.d.ts +79 -0
  50. package/pondSocket/pondChannel.js +219 -0
  51. package/pondSocket/pondChannel.test.js +430 -0
  52. package/pondSocket/pondResponse.d.ts +25 -0
  53. package/pondSocket/pondResponse.js +120 -0
  54. package/pondSocket/pondSocket.d.ts +47 -0
  55. package/pondSocket/pondSocket.js +94 -0
  56. package/pondSocket/server.test.js +136 -0
  57. package/pondSocket/socketMiddleWare.d.ts +6 -0
  58. package/pondSocket/socketMiddleWare.js +32 -0
  59. package/pondSocket/types.d.ts +74 -0
  60. package/pondSocket/types.js +2 -0
  61. package/socket.d.ts +1 -0
  62. package/socket.js +17 -0
  63. package/tsconfig.eslint.json +5 -0
  64. package/tsconfig.json +90 -0
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EndpointResponse = exports.PondChannelResponse = exports.ChannelResponse = exports.PondResponse = void 0;
4
+ const enums_1 = require("./enums");
5
+ class PondResponse {
6
+ }
7
+ exports.PondResponse = PondResponse;
8
+ class ChannelResponse extends PondResponse {
9
+ constructor(clientId, channel, resolver) {
10
+ super();
11
+ this._clientId = clientId;
12
+ this._channel = channel;
13
+ this._resolver = resolver;
14
+ this._hasExecuted = false;
15
+ }
16
+ get hasExecuted() {
17
+ return this._hasExecuted;
18
+ }
19
+ accept(assigns) {
20
+ if (this._hasExecuted)
21
+ throw new Error('Response has already been sent');
22
+ this._hasExecuted = true;
23
+ if (assigns) {
24
+ if (Object.values(enums_1.PondSenders).includes(this._clientId))
25
+ throw new Error('Cannot accept a message sent by the server');
26
+ this._channel.updateUser(this._clientId, assigns.presence || {}, assigns.assigns || {});
27
+ this._channel.data = assigns.channelData || {};
28
+ }
29
+ this._resolver(false);
30
+ }
31
+ reject(message, errorCode) {
32
+ if (this._hasExecuted)
33
+ throw new Error('Response has already been sent');
34
+ this._hasExecuted = true;
35
+ message = message || 'Message rejected';
36
+ errorCode = errorCode || 403;
37
+ if (Object.values(enums_1.PondSenders).includes(this._clientId))
38
+ throw new Error('Cannot reject a message sent by the server');
39
+ this._channel.respondToClient('error', { message: message, code: errorCode }, this._clientId, enums_1.ServerActions.ERROR);
40
+ this._resolver(true);
41
+ }
42
+ send(event, payload, assigns) {
43
+ if (this._hasExecuted)
44
+ throw new Error('Response has already been sent');
45
+ this._hasExecuted = true;
46
+ if (Object.values(enums_1.PondSenders).includes(this._clientId))
47
+ throw new Error('Cannot reply to a message sent by the server');
48
+ if (assigns) {
49
+ this._channel.updateUser(this._clientId, assigns.presence || {}, assigns.assigns || {});
50
+ this._channel.data = assigns.channelData || {};
51
+ }
52
+ this._channel.respondToClient(event, payload, this._clientId);
53
+ this._resolver(false);
54
+ }
55
+ }
56
+ exports.ChannelResponse = ChannelResponse;
57
+ class PondChannelResponse extends PondResponse {
58
+ constructor(user, handler) {
59
+ super();
60
+ this._handler = handler;
61
+ this._user = user;
62
+ this._executed = false;
63
+ }
64
+ get isResolved() {
65
+ return this._executed;
66
+ }
67
+ accept(assigns) {
68
+ if (this._executed)
69
+ throw new Error('Response has already been sent');
70
+ this._executed = true;
71
+ const newAssigns = this._mergeAssigns(assigns);
72
+ this._handler(newAssigns);
73
+ }
74
+ reject(message, errorCode) {
75
+ if (this._executed)
76
+ throw new Error('Response has already been sent');
77
+ this._executed = true;
78
+ const newMessage = {
79
+ action: enums_1.ServerActions.ERROR,
80
+ event: "JOIN_REQUEST_ERROR",
81
+ channelName: enums_1.PondSenders.POND_CHANNEL,
82
+ payload: {
83
+ message: message || 'Unauthorized join request',
84
+ code: errorCode || 403,
85
+ }
86
+ };
87
+ this._user.socket.send(JSON.stringify(newMessage));
88
+ }
89
+ send(event, payload, assigns) {
90
+ if (this._executed)
91
+ throw new Error('Response has already been sent');
92
+ this._executed = true;
93
+ const newAssigns = this._mergeAssigns(assigns);
94
+ this._handler(newAssigns, { event: event, payload: payload });
95
+ }
96
+ _mergeAssigns(assigns) {
97
+ return {
98
+ presence: (assigns === null || assigns === void 0 ? void 0 : assigns.presence) || {},
99
+ channelData: (assigns === null || assigns === void 0 ? void 0 : assigns.channelData) || {},
100
+ assigns: Object.assign({}, this._user.assigns, (assigns === null || assigns === void 0 ? void 0 : assigns.assigns) || {}),
101
+ };
102
+ }
103
+ }
104
+ exports.PondChannelResponse = PondChannelResponse;
105
+ class EndpointResponse extends PondResponse {
106
+ constructor(handler) {
107
+ super();
108
+ this._handler = handler;
109
+ }
110
+ accept(assigns) {
111
+ this._handler((assigns === null || assigns === void 0 ? void 0 : assigns.assigns) || {}, {});
112
+ }
113
+ reject(message, errorCode) {
114
+ this._handler({}, { error: { message: message || 'Message rejected', code: errorCode || 403 } });
115
+ }
116
+ send(event, payload, assigns) {
117
+ this._handler((assigns === null || assigns === void 0 ? void 0 : assigns.assigns) || {}, { message: { event: event, payload: payload } });
118
+ }
119
+ }
120
+ exports.EndpointResponse = EndpointResponse;
@@ -0,0 +1,47 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import {IncomingMessage, Server as HTTPServer} from "http";
5
+ import {WebSocketServer} from "ws";
6
+ import {BaseClass, PondPath} from "../pondBase";
7
+ import {Endpoint, EndpointHandler} from "./endpoint";
8
+ import internal from "stream";
9
+ import {NextFunction} from "./socketMiddleWare";
10
+
11
+ export declare class PondSocket extends BaseClass {
12
+
13
+ constructor(server?: HTTPServer, socketServer?: WebSocketServer);
14
+
15
+ /**
16
+ * @desc Specifies the port to listen on
17
+ * @param port - the port to listen on
18
+ * @param callback - the callback to call when the server is listening
19
+ */
20
+ listen(port: number, callback: (port?: number) => void): HTTPServer<typeof IncomingMessage, typeof import("http").ServerResponse>;
21
+
22
+ /**
23
+ * @desc adds a middleware to the server
24
+ * @param middleware - the middleware to add
25
+ */
26
+ useOnUpgrade(middleware: (req: IncomingMessage, socket: internal.Duplex, head: Buffer, next: NextFunction) => void): void;
27
+
28
+ /**
29
+ * @desc Accepts a new socket upgrade request on the provided endpoint using the handler function to authenticate the socket
30
+ * @param path - the pattern to accept || can also be a regex
31
+ * @param handler - the handler function to authenticate the socket
32
+ *
33
+ * @example
34
+ * const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
35
+ * const { query } = parse(req.url || '');
36
+ * const { token } = query;
37
+ * if (!token)
38
+ * return res.reject("No token provided");
39
+ * res.accept({
40
+ * assign: {
41
+ * token
42
+ * }
43
+ * });
44
+ * })
45
+ */
46
+ createEndpoint(path: PondPath, handler: EndpointHandler): Endpoint;
47
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PondSocket = void 0;
4
+ const http_1 = require("http");
5
+ const ws_1 = require("ws");
6
+ const pondBase_1 = require("../pondBase");
7
+ const endpoint_1 = require("./endpoint");
8
+ const socketMiddleWare_1 = require("./socketMiddleWare");
9
+ class PondSocket extends pondBase_1.BaseClass {
10
+ constructor(server, socketServer) {
11
+ super();
12
+ this._server = server || new http_1.Server();
13
+ this._socketServer = socketServer || new ws_1.WebSocketServer({ noServer: true });
14
+ this._socketChain = new socketMiddleWare_1.SocketMiddleWare(this._server);
15
+ this._init();
16
+ }
17
+ /**
18
+ * @desc Specifies the port to listen on
19
+ * @param port - the port to listen on
20
+ * @param callback - the callback to call when the server is listening
21
+ */
22
+ listen(port, callback) {
23
+ return this._server.listen(port, callback);
24
+ }
25
+ /**
26
+ * @desc adds a middleware to the server
27
+ * @param middleware - the middleware to add
28
+ */
29
+ useOnUpgrade(middleware) {
30
+ this._socketChain.use(middleware);
31
+ }
32
+ /**
33
+ * @desc Accepts a new socket upgrade request on the provided endpoint using the handler function to authenticate the socket
34
+ * @param path - the pattern to accept || can also be a regex
35
+ * @param handler - the handler function to authenticate the socket
36
+ *
37
+ * @example
38
+ * const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
39
+ * const { query } = parse(req.url || '');
40
+ * const { token } = query;
41
+ * if (!token)
42
+ * return res.reject("No token provided");
43
+ * res.accept({
44
+ * assign: {
45
+ * token
46
+ * }
47
+ * });
48
+ * })
49
+ */
50
+ createEndpoint(path, handler) {
51
+ const endpoint = new endpoint_1.Endpoint(this._socketServer, handler);
52
+ this._socketChain.use((req, socket, head, next) => {
53
+ const address = req.url || "";
54
+ const dataEndpoint = this.generateEventRequest(path, address);
55
+ if (!dataEndpoint)
56
+ return next();
57
+ endpoint.authoriseConnection(req, socket, head, dataEndpoint);
58
+ });
59
+ return endpoint;
60
+ }
61
+ /**
62
+ * @desc Makes sure that every client is still connected to the pond
63
+ * @param server - WebSocket server
64
+ */
65
+ _pingClients(server) {
66
+ server.on("connection", (ws) => {
67
+ ws.isAlive = true;
68
+ ws.on("pong", () => {
69
+ ws.isAlive = true;
70
+ });
71
+ });
72
+ const interval = setInterval(() => {
73
+ server.clients.forEach((ws) => {
74
+ if (ws.isAlive === false)
75
+ return ws.terminate();
76
+ ws.isAlive = false;
77
+ ws.ping();
78
+ });
79
+ }, 30 * 1000);
80
+ server.on("close", () => clearInterval(interval));
81
+ }
82
+ /**
83
+ * @desc Initializes the server
84
+ */
85
+ _init() {
86
+ this._server.on("error", (error) => {
87
+ throw new Error(error.message);
88
+ });
89
+ this._server.on("listening", () => {
90
+ this._pingClients(this._socketServer);
91
+ });
92
+ }
93
+ }
94
+ exports.PondSocket = PondSocket;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const endpoint_1 = require("./endpoint");
7
+ const pondSocket_1 = require("./pondSocket");
8
+ const superwstest_1 = __importDefault(require("superwstest"));
9
+ const enums_1 = require("./enums");
10
+ const http_1 = require("http");
11
+ const ws_1 = require("ws");
12
+ describe('server', () => {
13
+ it('should be defined', () => {
14
+ expect(pondSocket_1.PondSocket).toBeDefined();
15
+ });
16
+ it('should be instantiable', () => {
17
+ expect(new pondSocket_1.PondSocket()).toBeInstanceOf(pondSocket_1.PondSocket);
18
+ });
19
+ it('should ba able to create its own server and websocket server if none is provided', () => {
20
+ const socket = new pondSocket_1.PondSocket();
21
+ expect(socket['_server']).toBeDefined();
22
+ expect(socket['_socketServer']).toBeDefined();
23
+ });
24
+ it('should take a server and websocket server if provided', () => {
25
+ const server = (0, http_1.createServer)();
26
+ const socketServer = new ws_1.Server({ noServer: true });
27
+ const socket = new pondSocket_1.PondSocket(server, socketServer);
28
+ expect(socket['_server']).toBe(server);
29
+ expect(socket['_socketServer']).toBe(socketServer);
30
+ });
31
+ it('should be able to listen on a port', () => {
32
+ const socket = new pondSocket_1.PondSocket();
33
+ expect(socket.listen(3001, () => {
34
+ console.log('socket');
35
+ })).toBeDefined();
36
+ socket['_server'].close();
37
+ });
38
+ it('should be able to create an endpoint', () => {
39
+ const socket = new pondSocket_1.PondSocket();
40
+ const endpoint = socket.createEndpoint('/api/socket', () => {
41
+ console.log('socket');
42
+ });
43
+ expect(endpoint).toBeInstanceOf(endpoint_1.Endpoint);
44
+ expect(endpoint['_handler']).toEqual(expect.any(Function));
45
+ });
46
+ it('should be able to create multiple endpoints', () => {
47
+ const server = (0, http_1.createServer)();
48
+ const socketServer = new ws_1.Server({ noServer: true });
49
+ const socket = new pondSocket_1.PondSocket(server, socketServer);
50
+ const endpoint = socket.createEndpoint('/api/socket', () => {
51
+ console.log('socket');
52
+ });
53
+ const endpoint2 = socket.createEndpoint('/api/socket2', () => {
54
+ console.log('socket2');
55
+ });
56
+ expect(endpoint).toBeInstanceOf(endpoint_1.Endpoint);
57
+ expect(endpoint['_handler']).toEqual(expect.any(Function));
58
+ expect(endpoint2).toBeInstanceOf(endpoint_1.Endpoint);
59
+ expect(endpoint2['_handler']).toEqual(expect.any(Function));
60
+ });
61
+ it('should be able to reject a socket', () => {
62
+ const server = (0, http_1.createServer)();
63
+ const socketServer = new ws_1.Server({ noServer: true });
64
+ const socket = new pondSocket_1.PondSocket(server, socketServer);
65
+ const socketClient = {
66
+ write: jest.fn(),
67
+ destroy: jest.fn(),
68
+ };
69
+ socket.listen(3001, () => {
70
+ console.log('server listening');
71
+ });
72
+ server.emit('upgrade', {}, socketClient);
73
+ server.close();
74
+ // these functions are called because there is no endpoint to accept the socket
75
+ expect(socketClient.write).toHaveBeenCalled();
76
+ expect(socketClient.destroy).toHaveBeenCalled();
77
+ });
78
+ it('should be able to accept a socket if a handler is provided', async () => {
79
+ const socket = new pondSocket_1.PondSocket();
80
+ const server = socket.listen(3001, () => {
81
+ console.log('server listening');
82
+ });
83
+ expect(server).toBeDefined();
84
+ socket.createEndpoint('/api/hello', () => {
85
+ console.log('server listening');
86
+ });
87
+ socket.createEndpoint('/api/:path', (req, res) => {
88
+ expect(req.params.path).toBe('socket');
89
+ res.accept();
90
+ });
91
+ await (0, superwstest_1.default)(server)
92
+ .ws('/api/socket')
93
+ .expectUpgrade(res => expect(res.statusCode).toBe(101))
94
+ .close()
95
+ .expectClosed();
96
+ server.close();
97
+ });
98
+ it('should be able to reject a socket if the handler rejects', async () => {
99
+ const socket = new pondSocket_1.PondSocket();
100
+ const server = socket.listen(3001, () => {
101
+ console.log('server listening');
102
+ });
103
+ expect(server).toBeDefined();
104
+ socket.createEndpoint('/api/:path', (req, res) => {
105
+ expect(req.params.path).toBe('socket');
106
+ res.reject();
107
+ });
108
+ await (0, superwstest_1.default)(server)
109
+ .ws('/api/socket')
110
+ .expectConnectionError();
111
+ server.close();
112
+ });
113
+ it('should be able to send a message after connection', async () => {
114
+ const socket = new pondSocket_1.PondSocket();
115
+ const server = socket.listen(3001, () => {
116
+ console.log('server listening');
117
+ });
118
+ expect(server).toBeDefined();
119
+ socket.createEndpoint('/api/:path', (req, res) => {
120
+ expect(req.params.path).toBe('socket');
121
+ res.send('testEvent', { test: 'test' });
122
+ });
123
+ await (0, superwstest_1.default)(server)
124
+ .ws('/api/socket')
125
+ .expectUpgrade(res => expect(res.statusCode).toBe(101))
126
+ .expectJson({
127
+ action: enums_1.ServerActions.MESSAGE,
128
+ event: 'testEvent',
129
+ channelName: 'SERVER',
130
+ payload: { test: 'test' },
131
+ })
132
+ .close()
133
+ .expectClosed();
134
+ server.close();
135
+ });
136
+ });
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+
5
+ export declare type NextFunction = () => void;
6
+
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SocketMiddleWare = void 0;
4
+ class SocketMiddleWare {
5
+ constructor(server) {
6
+ this.middleware = [];
7
+ this._server = server;
8
+ this._initMiddleware();
9
+ }
10
+ use(middleware) {
11
+ this.middleware.push(middleware);
12
+ }
13
+ _execute(req, socket, head) {
14
+ const temp = this.middleware.concat();
15
+ const next = () => {
16
+ const middleware = temp.shift();
17
+ if (middleware)
18
+ middleware(req, socket, head, next);
19
+ else {
20
+ socket.write('HTTP/1.1 400 Bad Request\r\n\r');
21
+ socket.destroy();
22
+ }
23
+ };
24
+ next();
25
+ }
26
+ _initMiddleware() {
27
+ this._server.on('upgrade', (req, socket, head) => {
28
+ this._execute(req, socket, head);
29
+ });
30
+ }
31
+ }
32
+ exports.SocketMiddleWare = SocketMiddleWare;
@@ -0,0 +1,74 @@
1
+ /// <reference types="node" />
2
+ import { default_t, ResponsePicker } from "../pondBase";
3
+ import { ClientActions, ServerActions } from "./enums";
4
+ import { WebSocket } from "ws";
5
+ import { IncomingHttpHeaders } from "http";
6
+ export interface NewUser {
7
+ client: Omit<SocketCache, 'assigns' | 'socket'>;
8
+ assigns: PondAssigns;
9
+ presence: PondPresence;
10
+ channelData: PondChannelData;
11
+ }
12
+ export declare type PondAssigns = default_t;
13
+ export declare type PondPresence = default_t;
14
+ export declare type PondChannelData = default_t;
15
+ export declare type PondMessage = default_t;
16
+ export declare type ServerMessage = {
17
+ action: ServerActions;
18
+ channelName: string;
19
+ payload: default_t;
20
+ event: string;
21
+ };
22
+ export interface SocketCache {
23
+ clientId: string;
24
+ socket: WebSocket;
25
+ assigns: PondAssigns;
26
+ }
27
+ export interface IncomingConnection {
28
+ clientId: string;
29
+ params: default_t<string>;
30
+ query: default_t<string>;
31
+ headers: IncomingHttpHeaders;
32
+ address: string;
33
+ }
34
+ export interface IncomingJoinMessage {
35
+ clientId: string;
36
+ channelName: string;
37
+ clientAssigns: PondAssigns;
38
+ joinParams: default_t;
39
+ params: default_t<string>;
40
+ query: default_t<string>;
41
+ }
42
+ export interface IncomingChannelMessage {
43
+ channelName: string;
44
+ event: string;
45
+ message: default_t;
46
+ client: {
47
+ clientId: string;
48
+ clientAssigns: PondAssigns;
49
+ clientPresence: PondPresence;
50
+ };
51
+ params: default_t<string>;
52
+ query: default_t<string>;
53
+ }
54
+ export interface PondResponseAssigns {
55
+ assigns?: PondAssigns;
56
+ presence?: PondPresence;
57
+ channelData?: PondChannelData;
58
+ }
59
+ export declare type ClientMessage = {
60
+ action: ClientActions;
61
+ channelName: string;
62
+ event: string;
63
+ payload: default_t;
64
+ addresses?: string[];
65
+ };
66
+ export declare type SendResponse<T = ResponsePicker.CHANNEL> = T extends ResponsePicker.CHANNEL ? Required<PondResponseAssigns> : T extends ResponsePicker.POND ? Required<Omit<PondResponseAssigns, 'presence' | 'channelData'>> : never;
67
+ export interface ResponseResolver<T = ResponsePicker.CHANNEL> {
68
+ assigns: SendResponse<T>;
69
+ message?: {
70
+ event: string;
71
+ payload: PondMessage;
72
+ };
73
+ error?: string;
74
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/socket.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './pondSocket';
package/socket.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./pondSocket"), exports);
@@ -0,0 +1,5 @@
1
+ {
2
+ "include": [
3
+ ".eslintrc.js"
4
+ ]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Basic Options */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ "target": "es2019",
8
+ /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
9
+ "module": "commonjs",
10
+ /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
11
+ // "lib": [], /* Specify library files to be included in the compilation. */
12
+ // "allowJs": true, /* Allow javascript files to be compiled. */
13
+ // "checkJs": true, /* Report errors in .js files. */
14
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
15
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
16
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
17
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
18
+ // "outFile": "./", /* Concatenate and emit output to single file. */
19
+ // "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
20
+ // "composite": true, /* Enable project compilation */
21
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
22
+ // "removeComments": true, /* Do not emit comments to output. */
23
+ // "noEmit": true, /* Do not emit outputs. */
24
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
25
+ "downlevelIteration": true,
26
+ /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
27
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
28
+
29
+ /* Strict Type-Checking Options */
30
+ "strict": true,
31
+ /* Enable all strict type-checking options. */
32
+ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
33
+ "strictNullChecks": true, /* Enable strict null checks. */
34
+ "strictFunctionTypes": true, /* Enable strict checking of function types. */
35
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
36
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
37
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
38
+ "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
39
+
40
+ /* Additional Checks */
41
+ "noUnusedLocals": true, /* Report errors on unused locals. */
42
+ "noUnusedParameters": true, /* Report errors on unused parameters. */
43
+ "noImplicitReturns": false, /* Report error when not all code paths in function return a value. */
44
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
45
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
46
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
47
+ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
48
+
49
+ /* Module Resolution Options */
50
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
51
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
52
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
53
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
54
+ // "typeRoots": [], /* List of folders to include type definitions from. */
55
+ // "types": [], /* Type declaration files to be included in compilation. */
56
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
57
+ "esModuleInterop": true,
58
+ /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
59
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
60
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
61
+
62
+ /* Source Map Options */
63
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
64
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
66
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
67
+
68
+ /* Experimental Options */
69
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
70
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
71
+
72
+ /* Advanced Options */
73
+ "skipLibCheck": true,
74
+ /* Skip type checking of declaration files. */
75
+ "forceConsistentCasingInFileNames": true,
76
+ "composite": true,
77
+ "rootDir": "./src",
78
+ "outDir": "./bin",
79
+ "declarationDir": "./types",
80
+ /* Disallow inconsistently-cased references to the same file. */
81
+ "lib": [
82
+ "dom",
83
+ "es5",
84
+ "scripthost",
85
+ "es2015.generator"
86
+ ]
87
+ },
88
+ "include": ["src/", ".eslintrc.js", "jest.config.js"],
89
+ "exclude": ["!src/"]
90
+ }