Skip to content

Commit

Permalink
feat(fjage.js): add support for generating typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Oct 30, 2023
1 parent 8146edc commit 82cd6fd
Show file tree
Hide file tree
Showing 6 changed files with 534 additions and 10 deletions.
57 changes: 48 additions & 9 deletions gateways/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion gateways/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"devDependencies": {
"@babel/eslint-parser": "^7.22.10",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/node": "^20.8.9",
"documentation": "^13.2.5",
"eslint": "^8.47.0",
"jasmine": "^4.6.0",
"node-static": "^0.7.11",
"puppeteer": "^14.3.0",
"rollup": "^2.79.1",
"rollup-plugin-terser": "^7.0.2"
"rollup-plugin-terser": "^7.0.2",
"typescript": "^5.2.2"
},
"dependencies": {
"browser-or-node": "^2.1.1"
Expand Down
21 changes: 21 additions & 0 deletions gateways/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "dist",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": true
}
}
61 changes: 61 additions & 0 deletions gateways/js/types/TCPConnector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @class
* @ignore
*/
export default class TCPconnector {
/**
* Create an TCPConnector to connect to a fjage master over TCP
* @param {Object} opts
* @param {String} [opts.hostname='localhost'] - ip address/hostname of the master container to connect to
* @param {number} opts.port - port number of the master container to connect to
*/
constructor(opts?: {
hostname?: string;
port: number;
});
url: URL;
_buf: string;
pendingOnOpen: any[];
connListeners: any[];
_sendConnEvent(val: any): void;
_sockInit(host: any, port: any): void;
_sockSetup(host: any, port: any): void;
sock: any;
_sockReconnect(): void;
_firstReConn: boolean;
_onSockOpen(): void;
_processSockData(s: any): void;
toString(): string;
/**
* Write a string to the connector
* @param {string} s - string to be written out of the connector to the master
* @return {boolean} - true if connect was able to write or queue the string to the underlying socket
*/
write(s: string): boolean;
/**
* Set a callback for receiving incoming strings from the connector
* @param {TCPConnector~ReadCallback} cb - callback that is called when the connector gets a string
*/
setReadCallback(cb: any): void;
_onSockRx: any;
/**
* @callback TCPConnector~ReadCallback
* @ignore
* @param {string} s - incoming message string
*/
/**
* Add listener for connection events
* @param {function} listener - a listener callback that is called when the connection is opened/closed
*/
addConnectionListener(listener: Function): void;
/**
* Remove listener for connection events
* @param {function} listener - remove the listener for connection
* @return {boolean} - true if the listner was removed successfully
*/
removeConnectionListener(listener: Function): boolean;
/**
* Close the connector
*/
close(): void;
}
68 changes: 68 additions & 0 deletions gateways/js/types/WSConnector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @class
* @ignore
*/
export default class WSConnector {
/**
* Create an WSConnector to connect to a fjage master over WebSockets
* @param {Object} opts
* @param {string} opts.hostname - hostname/ip address of the master container to connect to
* @param {number} opts.port - port number of the master container to connect to
* @param {string} opts.pathname - path of the master container to connect to
* @param {boolean} opts.keepAlive - try to reconnect if the connection is lost
* @param {number} [opts.reconnectTime=5000] - time before reconnection is attempted after an error
*/
constructor(opts?: {
hostname: string;
port: number;
pathname: string;
keepAlive: boolean;
reconnectTime?: number;
});
url: URL;
_reconnectTime: number;
_keepAlive: boolean;
debug: any;
_firstConn: boolean;
_firstReConn: boolean;
pendingOnOpen: any[];
connListeners: any[];
_sendConnEvent(val: any): void;
_websockSetup(url: any): void;
sock: WebSocket;
_websockReconnect(): void;
_onWebsockOpen(): void;
toString(): string;
/**
* Write a string to the connector
* @param {string} s - string to be written out of the connector to the master
*/
write(s: string): boolean;
/**
* Set a callback for receiving incoming strings from the connector
* @param {WSConnector~ReadCallback} cb - callback that is called when the connector gets a string
* @ignore
*/
setReadCallback(cb: any): void;
_onWebsockRx: any;
/**
* @callback WSConnector~ReadCallback
* @ignore
* @param {string} s - incoming message string
*/
/**
* Add listener for connection events
* @param {function} listener - a listener callback that is called when the connection is opened/closed
*/
addConnectionListener(listener: Function): void;
/**
* Remove listener for connection events
* @param {function} listener - remove the listener for connection
* @return {boolean} - true if the listner was removed successfully
*/
removeConnectionListener(listener: Function): boolean;
/**
* Close the connector
*/
close(): void;
}
Loading

0 comments on commit 82cd6fd

Please sign in to comment.