diff --git a/__tests__/servers/socket.ts b/__tests__/servers/socket.ts index 49ba49f..067c3a4 100644 --- a/__tests__/servers/socket.ts +++ b/__tests__/servers/socket.ts @@ -21,7 +21,7 @@ let client2Details = { id: null }; const makeSocketRequest = async ( thisClient, message = "", - delimiter = "\r\n" + delimiter = "\r\n", ): Promise => { let data = ""; let response; @@ -97,18 +97,18 @@ describe("Server: Socket", () => { const response = await makeSocketRequest(client, "status"); expect(response).toBeInstanceOf(Object); expect(response.id).toEqual( - `test-server-${process.env.JEST_WORKER_ID || 0}` + `test-server-${process.env.JEST_WORKER_ID || 0}`, ); }); test("stringified JSON can also be sent as actions", async () => { const response = await makeSocketRequest( client, - JSON.stringify({ action: "status", params: { something: "else" } }) + JSON.stringify({ action: "status", params: { something: "else" } }), ); expect(response).toBeInstanceOf(Object); expect(response.id).toEqual( - `test-server-${process.env.JEST_WORKER_ID || 0}` + `test-server-${process.env.JEST_WORKER_ID || 0}`, ); }); @@ -133,7 +133,7 @@ describe("Server: Socket", () => { const response = await makeSocketRequest(client, JSON.stringify(msg)); expect(response.cacheTestResults.loadResp.key).toEqual( - "cacheTest_" + msg.params.key + "cacheTest_" + msg.params.key, ); expect(response.cacheTestResults.loadResp.value).toEqual(msg.params.value); }); @@ -167,14 +167,14 @@ describe("Server: Socket", () => { await makeSocketRequest(client, "paramDelete key"); const response = await makeSocketRequest(client, "cacheTest"); expect(response.error).toEqual( - "key is a required parameter for this action" + "key is a required parameter for this action", ); }); test("a new param can be added and viewed", async () => { const response = await makeSocketRequest( client, - "paramAdd key=socketTestKey" + "paramAdd key=socketTestKey", ); expect(response.status).toEqual("OK"); const viewResponse = await makeSocketRequest(client, "paramView key"); @@ -201,13 +201,13 @@ describe("Server: Socket", () => { const response = await makeSocketRequest(client, "cacheTest"); expect(response.error).toBeUndefined(); expect(response.cacheTestResults.loadResp.key).toEqual( - "cacheTest_socketTestKey" + "cacheTest_socketTestKey", ); expect(response.cacheTestResults.loadResp.value).toEqual("abc123"); const responseAgain = await makeSocketRequest(client, "cacheTest"); expect(responseAgain.cacheTestResults.loadResp.key).toEqual( - "cacheTest_socketTestKey" + "cacheTest_socketTestKey", ); expect(responseAgain.cacheTestResults.loadResp.value).toEqual("abc123"); }); @@ -215,10 +215,13 @@ describe("Server: Socket", () => { test("only params sent in a JSON block are used", async () => { const response = await makeSocketRequest( client, - JSON.stringify({ action: "cacheTest", params: { key: "someOtherValue" } }) + JSON.stringify({ + action: "cacheTest", + params: { key: "someOtherValue" }, + }), ); expect(response.error).toEqual( - "value is a required parameter for this action" + "value is a required parameter for this action", ); }); @@ -241,7 +244,7 @@ describe("Server: Socket", () => { JSON.stringify({ action: "randomNumber", params: { messageId: "abc123" }, - }) + }), ); expect(response.messageId).toEqual("abc123"); }); @@ -294,7 +297,7 @@ describe("Server: Socket", () => { const response = responses[i]; if (i === "0") { expect(response.error).toEqual( - "you have too many pending requests" + "you have too many pending requests", ); } else { expect(response.error).toBeUndefined(); @@ -393,7 +396,7 @@ describe("Server: Socket", () => { expect(response.status).toEqual("OK"); const responseAgain = await makeSocketRequest( client, - "roomView otherRoom" + "roomView otherRoom", ); expect(responseAgain.data.room).toEqual("otherRoom"); expect(responseAgain.data.membersCount).toEqual(1); @@ -421,7 +424,7 @@ describe("Server: Socket", () => { await api.chatRoom.broadcast( {}, room, - `I have entered the room: ${connection.id}` + `I have entered the room: ${connection.id}`, ); }, }); @@ -432,7 +435,7 @@ describe("Server: Socket", () => { await api.chatRoom.broadcast( {}, room, - `I have left the room: ${connection.id}` + `I have left the room: ${connection.id}`, ); }, }); @@ -453,7 +456,7 @@ describe("Server: Socket", () => { makeSocketRequest(client2, "roomAdd otherRoom"); const response = await makeSocketRequest(client, ""); expect(response.message).toEqual( - "I have entered the room: " + client2Details.id + "I have entered the room: " + client2Details.id, ); expect(response.from.toString()).toEqual("0"); }); @@ -462,7 +465,7 @@ describe("Server: Socket", () => { makeSocketRequest(client2, "roomLeave defaultRoom\r\n"); const response = await makeSocketRequest(client, ""); expect(response.message).toEqual( - "I have left the room: " + client2Details.id + "I have left the room: " + client2Details.id, ); expect(response.from.toString()).toEqual("0"); }); @@ -496,7 +499,7 @@ describe("Server: Socket", () => { await makeSocketRequest(client2, "roomAdd defaultRoom"); const response = await makeSocketRequest( client2, - "roomView defaultRoom" + "roomView defaultRoom", ); expect(response.data.room).toEqual("defaultRoom"); for (const key in response.data.members) { @@ -546,7 +549,7 @@ describe("Server: Socket", () => { await makeSocketRequest(client2, "roomAdd defaultRoom"); const response = await makeSocketRequest( client2, - "roomView defaultRoom" + "roomView defaultRoom", ); expect(response.data.room).toEqual("defaultRoom"); for (const key in response.data.members) { @@ -565,7 +568,7 @@ describe("Server: Socket", () => { test("server can disconnect a client", async () => { const response = await makeSocketRequest(client, "status"); expect(response.id).toEqual( - `test-server-${process.env.JEST_WORKER_ID || 0}` + `test-server-${process.env.JEST_WORKER_ID || 0}`, ); expect(client.readable).toEqual(true); expect(client.writable).toEqual(true); diff --git a/package-lock.json b/package-lock.json index 5d96dcd..4353547 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@types/node": "^20.2.5", "actionhero": "^29.0.0", "jest": "^27.1.0", - "prettier": "^2.3.2", + "prettier": "^3.0.3", "ts-jest": "^27.0.5", "ts-node-dev": "^2.0.0", "typescript": "^4.4.2" @@ -4233,15 +4233,15 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" @@ -8801,9 +8801,9 @@ "dev": true }, "prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", "dev": true }, "pretty-format": { diff --git a/package.json b/package.json index 5932834..9468d71 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@types/node": "^20.2.5", "actionhero": "^29.0.0", "jest": "^27.1.0", - "prettier": "^2.3.2", + "prettier": "^3.0.3", "ts-jest": "^27.0.5", "ts-node-dev": "^2.0.0", "typescript": "^4.4.2" diff --git a/src/actions/status.ts b/src/actions/status.ts index ce5ed21..562de2f 100644 --- a/src/actions/status.ts +++ b/src/actions/status.ts @@ -14,9 +14,9 @@ enum StatusMessages { const packageJSON = JSON.parse( fs .readFileSync( - path.normalize(path.join(__dirname, "..", "..", "package.json")) + path.normalize(path.join(__dirname, "..", "..", "package.json")), ) - .toString() + .toString(), ); export class Status extends Action { diff --git a/src/config/api.ts b/src/config/api.ts index 9aa18a7..8fc471b 100644 --- a/src/config/api.ts +++ b/src/config/api.ts @@ -16,7 +16,7 @@ export const DEFAULT = { const packageJSON: PackageJson = JSON.parse( fs .readFileSync(path.join(__dirname, "..", "..", "package.json")) - .toString() + .toString(), ); return { diff --git a/src/config/errors.ts b/src/config/errors.ts index f8f2c8e..3c93e81 100644 --- a/src/config/errors.ts +++ b/src/config/errors.ts @@ -63,7 +63,7 @@ export const DEFAULT = { // When a params for an action is invalid invalidParams: ( data: ActionProcessor, - validationErrors: Array + validationErrors: Array, ) => { if (validationErrors.length >= 0) return validationErrors[0]; return "validation error"; @@ -100,7 +100,7 @@ export const DEFAULT = { // an error to the client. Response can be edited here, status codes changed, etc. async genericError( data: ActionProcessor, - error: NodeJS.ErrnoException + error: NodeJS.ErrnoException, ) { return error; }, diff --git a/src/config/logger.ts b/src/config/logger.ts index 56b8048..c6496ed 100644 --- a/src/config/logger.ts +++ b/src/config/logger.ts @@ -63,7 +63,7 @@ function buildConsoleLogger(level = "info") { return `${info.timestamp} - ${info.level}: ${ info.message } ${stringifyExtraMessagePropertiesForConsole(info)}`; - }) + }), ), level, levels: winston.config.syslog.levels, @@ -78,7 +78,7 @@ function buildFileLogger(path: string, level = "info", maxFiles?: number) { return winston.createLogger({ format: winston.format.combine( winston.format.timestamp(), - winston.format.json() + winston.format.json(), ), level, levels: winston.config.syslog.levels, @@ -93,7 +93,7 @@ function buildFileLogger(path: string, level = "info", maxFiles?: number) { } function stringifyExtraMessagePropertiesForConsole( - info: winston.Logform.TransformableInfo + info: winston.Logform.TransformableInfo, ) { const skippedProperties = ["message", "timestamp", "level"]; let response = ""; diff --git a/src/config/redis.ts b/src/config/redis.ts index 55433a8..c43d85e 100644 --- a/src/config/redis.ts +++ b/src/config/redis.ts @@ -43,7 +43,7 @@ export const DEFAULT = { retryStrategy: (times: number) => { if (times === 1) { console.error( - "Unable to connect to Redis - please check your Redis config!" + "Unable to connect to Redis - please check your Redis config!", ); return 5000; } diff --git a/src/servers/socket.ts b/src/servers/socket.ts index b84540c..1da37e0 100644 --- a/src/servers/socket.ts +++ b/src/servers/socket.ts @@ -44,20 +44,20 @@ export class SocketServer extends Server { this.config.serverOptions, (rawConnection) => { this.handleConnection(rawConnection); - } + }, ); } else { this.server = tls.createServer( this.config.serverOptions, (rawConnection) => { this.handleConnection(rawConnection); - } + }, ); } this.server.on("error", (error: NodeJS.ErrnoException) => { throw new Error( - `Cannot start socket server @ ${this.config.bindIP}:${this.config.port} => ${error.message}` + `Cannot start socket server @ ${this.config.bindIP}:${this.config.port} => ${error.message}`, ); }); @@ -84,7 +84,7 @@ export class SocketServer extends Server { async sendMessage( connection: Connection, message: Record, - messageId: string | number + messageId: string | number, ) { if (message.error) { message.error = config.errors.serializers.servers @@ -111,7 +111,7 @@ export class SocketServer extends Server { async goodbye(connection: Connection) { try { connection.rawConnection.end( - JSON.stringify({ status: "Bye", context: "api" }) + "\r\n" + JSON.stringify({ status: "Bye", context: "api" }) + "\r\n", ); } catch (e) { console.log(e); @@ -121,7 +121,7 @@ export class SocketServer extends Server { async sendFile( connection: Connection, error: NodeJS.ErrnoException, - fileStream: any + fileStream: any, ) { if (error) { this.sendMessage(connection, error, connection.messageId); @@ -164,7 +164,7 @@ export class SocketServer extends Server { ) { const data = connection.rawConnection.socketDataString.slice( 0, - index + index, ); connection.rawConnection.socketDataString = connection.rawConnection.socketDataString.slice(index + d.length); @@ -206,7 +206,7 @@ export class SocketServer extends Server { error: error, context: "response", }, - null + null, ); } } @@ -234,13 +234,13 @@ export class SocketServer extends Server { return this.sendMessage( connection, { status: "OK", context: "response", data: data }, - connection.messageId + connection.messageId, ); } catch (error) { return this.sendMessage( connection, { error: error, context: "response" }, - connection.messageId + connection.messageId, ); } } @@ -295,7 +295,7 @@ export class SocketServer extends Server { if (!connection.rawConnection.shutDownTimer) { connection.rawConnection.shutDownTimer = setTimeout( connection.destroy, - this.attributes.pendingShutdownWaitLimit + this.attributes.pendingShutdownWaitLimit, ); } } @@ -304,7 +304,7 @@ export class SocketServer extends Server { if (pendingConnections > 0) { this.log( `waiting on shutdown, there are still ${pendingConnections} connected clients waiting on a response`, - "notice" + "notice", ); await new Promise((resolve) => { setTimeout(resolve, 1000);