refactor: typings and awaitable socket operations#1760
refactor: typings and awaitable socket operations#1760pedrolamas merged 10 commits intofluidd-core:developfrom
Conversation
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase to support awaitable socket operations and isolates Moonraker and Klipper type definitions into dedicated namespaces, improving type safety and enabling promise-based WebSocket communication.
- Introduces
MoonrakerandKlipperglobal namespaces for API-related types - Refactors
socketClient.tsto return promises fromemit()method for awaitable socket calls - Migrates store types from local definitions to centralized namespace types
- Adds comprehensive type definitions for Moonraker API responses and Klipper printer state
Reviewed changes
Copilot reviewed 133 out of 161 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tshelpers.d.ts |
Adds DeepReadonly utility type |
src/typings/moonraker.*.d.ts |
New type definitions for all Moonraker API endpoints and responses |
src/typings/klipper.d.ts |
Comprehensive Klipper printer state and settings types (1759 lines) |
src/typings/vuetify.d.ts |
Component interface definitions for Vuetify components |
src/typings/vue-*.d.ts |
Type declarations for third-party Vue libraries |
src/views/*.vue |
Updated to use new namespace types (Moonraker.Webcam.Entry, Klipper.SettingsState) |
src/util/transform-mesh.ts |
Updated to use Klipper.BedMeshState |
src/store/*/types.ts |
Migrated from local types to centralized namespace types |
src/store/*/mutations.ts |
Updated with proper type annotations using namespace types |
src/store/*/actions.ts |
Updated action parameters to use namespace types, replaced SocketActions.serverWrite with serverDatabasePostItem |
src/plugins/socketClient.ts |
Refactored emit() to return Promise, added request tracking with callbacks, improved error handling |
src/mixins/*.ts |
Updated type imports to use namespace types |
src/components/widgets/toolhead/*.vue |
Updated to use Klipper.SettingsState |
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
| const bounds: BBox = { | ||
| x: { | ||
| min: NaN, | ||
| max: NaN | ||
| min: Number.POSITIVE_INFINITY, | ||
| max: Number.NEGATIVE_INFINITY | ||
| }, | ||
| y: { | ||
| min: NaN, | ||
| max: NaN | ||
| } | ||
| } | ||
|
|
||
| const isFinite = (x: unknown): x is number => Number.isFinite(x) | ||
| let index = 0 | ||
|
|
||
| for (; index < moves.length && !Object.values(bounds).every(isFinite); index++) { | ||
| const move = moves[index] | ||
|
|
||
| if (isFinite(move.x)) { | ||
| bounds.x.min = isFinite(bounds.x.min) ? Math.min(bounds.x.min, move.x) : move.x | ||
| bounds.x.max = isFinite(bounds.x.max) ? Math.max(bounds.x.max, move.x) : move.x | ||
| } | ||
|
|
||
| if (isFinite(move.y)) { | ||
| bounds.y.min = isFinite(bounds.y.min) ? Math.min(bounds.y.min, move.y) : move.y | ||
| bounds.y.max = isFinite(bounds.y.max) ? Math.max(bounds.y.max, move.y) : move.y | ||
| min: Number.POSITIVE_INFINITY, | ||
| max: Number.NEGATIVE_INFINITY | ||
| } | ||
| } | ||
|
|
||
| for (; index < moves.length; index++) { | ||
| for (let index = 0; index < moves.length; index++) { | ||
| const move = moves[index] | ||
|
|
||
| if (isFinite(move.x)) { | ||
| if (move.x != null) { | ||
| bounds.x.min = Math.min(bounds.x.min, move.x) | ||
| bounds.x.max = Math.max(bounds.x.max, move.x) | ||
| } | ||
|
|
||
| if (isFinite(move.y)) { | ||
| if (move.y != null) { | ||
| bounds.y.min = Math.min(bounds.y.min, move.y) | ||
| bounds.y.max = Math.max(bounds.y.max, move.y) | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| return Object.freeze({ | ||
| x: { | ||
| min: isFinite(bounds.x.min) ? bounds.x.min : 0, | ||
| max: isFinite(bounds.x.max) ? bounds.x.max : 0 | ||
| min: Number.isFinite(bounds.x.min) ? bounds.x.min : 0, | ||
| max: Number.isFinite(bounds.x.max) ? bounds.x.max : 0 | ||
| }, | ||
| y: { | ||
| min: isFinite(bounds.y.min) ? bounds.y.min : 0, | ||
| max: isFinite(bounds.y.max) ? bounds.y.max : 0 | ||
| min: Number.isFinite(bounds.y.min) ? bounds.y.min : 0, | ||
| max: Number.isFinite(bounds.y.max) ? bounds.y.max : 0 | ||
| } | ||
| } | ||
| }) |
There was a problem hiding this comment.
The logic has changed significantly. Previously, the code would initialize the bounds values with the first valid move coordinates, then continue from that point. Now it initializes with Infinity/-Infinity and processes all moves. While this approach works, it may be less efficient and the fallback logic at lines 105-111 handles the case where no valid coordinates are found. Verify this is the intended behavior change.
There was a problem hiding this comment.
This is correct, keep as is.
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Major refactor to allow: