Major ToolSocket Refactor#7
Merged
dangond-ptc merged 22 commits intomainfrom Apr 11, 2024
Merged
Conversation
Contributor
Author
|
Question: Do we need to support earlier versions of Node? As far as I can tell, no one uses |
hobinjk-ptc
approved these changes
Apr 9, 2024
| // Method-style request handling | ||
| socket.on('post', (route, body, res, binaryData) => { | ||
| if(route === "/") { | ||
| console.log(body) // "hello" |
|
|
||
| // Event-style request handling (Cannot send responses) | ||
| socket.on('/', (body, binary) => { | ||
| console.log(body) // "hello" |
| const messageBuffer = encoder.encode(JSON.stringify(this.message)); | ||
| const messageLengthBuffer = intToByte(messageBuffer.length); | ||
| const binaryDataBuffer = this.binaryData ? new Uint8Array(this.binaryData) : null; | ||
| // Apologies for the terrible naming in this block, but this keeps the following line cleaner by hiding the ternary operator |
Contributor
There was a problem hiding this comment.
you have NOTHING to apologize for!!!
| } | ||
|
|
||
| if (!MESSAGE_BUNDLE_SCHEMA.validate(messageBundle.message)) { | ||
| console.warn('message schema validation failed, dropping', messageBundle.message, MESSAGE_BUNDLE_SCHEMA.failedValidator); |
Contributor
There was a problem hiding this comment.
very nice improvement in transparency!
| * frameCount - Number of binary buffers that will be sent following this message | ||
| */ | ||
| constructor(origin, network, method, route, body, id) { | ||
| // These parameters are impossible to read in code, use the getters and setters |
Contributor
|
oh and feel free to replace the test node version matrix with [16, 18, 20] |
benptc
approved these changes
Apr 9, 2024
benptc
left a comment
There was a problem hiding this comment.
I read through everything line by line and I have no critiques to give – fantastic work! I never really understood how toolsocket works, but now it's easily readable 🥇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toolSocket.socket.socket. Ever.cbSub,objBin, orpackageData.index.js.ToolSocketMessagehave getters/setters with legible names. No moreobjBin.oorobjBin.f.Array, aUint8Array, or anArrayBuffer.Schemasare now built-up from individualSchemaValidators, which cleans up validation logic.maximumfor a validator when they meantmax-length.2.0.0.New Classes
ToolSocketMessage- The underlying WebSocket message format.ToolSocketResponse- An object that can be used to send a response to an incoming message.MessageBundle- An object that stores the message body (ToolSocketMessage) and associated binary data if present.BinaryBuffer- A helper object used for processing incoming binary data that has been split across multiple messages.Schema- An object that offers utilities for parsing URLs/routes and validating object data formats.SchemaValidator- An object used in the construction of Schemas that defines how URL/route/object properties will be validated.