fix export types (#271)

* fix export types

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update kittycad lib

* fix wasm

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
Jess Frazelle
2023-08-18 08:12:32 -07:00
committed by GitHub
parent aa24b9d6bd
commit 108827075d
12 changed files with 1228 additions and 56 deletions

View File

@ -8,7 +8,7 @@
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.13",
"@kittycad/lib": "^0.0.27",
"@kittycad/lib": "^0.0.28",
"@react-hook/resize-observer": "^1.2.6",
"@tauri-apps/api": "^1.3.0",
"@testing-library/jest-dom": "^5.14.1",

View File

@ -409,7 +409,6 @@ export function App() {
window: { x, y },
},
cmd_id: newCmdId,
file_id: fileId,
})
} else {
debounceSocketSend({
@ -419,7 +418,6 @@ export function App() {
selected_at_window: { x, y },
},
cmd_id: newCmdId,
file_id: fileId,
})
}
}

View File

@ -7,7 +7,7 @@ import { ActionButton } from '../components/ActionButton'
import { faCheck } from '@fortawesome/free-solid-svg-icons'
type SketchModeCmd = Extract<
EngineCommand['cmd'],
Extract<EngineCommand, { type: 'modeling_cmd_req' }>['cmd'],
{ type: 'default_camera_enable_sketch_mode' }
>
@ -22,6 +22,7 @@ export const DebugPanel = ({ className, ...props }: CollapsiblePanelProps) => {
y_axis: { x: 0, y: 1, z: 0 },
distance_to_plane: 100,
ortho: true,
animated: true, // TODO #273 get prefers reduced motion from CSS
})
if (!sketchModeCmd) return null
return (
@ -79,7 +80,6 @@ export const DebugPanel = ({ className, ...props }: CollapsiblePanelProps) => {
type: 'modeling_cmd_req',
cmd: sketchModeCmd,
cmd_id: uuidv4(),
file_id: uuidv4(),
})
}}
className="hover:border-succeed-50"

View File

@ -76,7 +76,6 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => {
format: values,
},
cmd_id: uuidv4(),
file_id: uuidv4(),
})
closeModal()

View File

@ -79,7 +79,6 @@ export const Stream = ({ className = '' }) => {
window: { x, y },
},
cmd_id: newId,
file_id: fileId,
})
setIsMouseDownInStream(true)
@ -100,7 +99,6 @@ export const Stream = ({ className = '' }) => {
window: { x: 0, y: zoom + e.deltaY },
},
cmd_id: uuidv4(),
file_id: uuidv4(),
})
setZoom(zoom + e.deltaY)
@ -130,7 +128,6 @@ export const Stream = ({ className = '' }) => {
window: { x, y },
},
cmd_id: newCmdId,
file_id: fileId,
})
setIsMouseDownInStream(false)
@ -143,7 +140,6 @@ export const Stream = ({ className = '' }) => {
selected_at_window: { x, y },
},
cmd_id: uuidv4(),
file_id: fileId,
})
}
setDidDragInStream(false)

View File

@ -32,15 +32,11 @@ interface CursorSelectionsArgs {
idBasedSelections: { type: string; id: string }[]
}
type _EngineCommand = Models['ModelingCmdReq_type']
export type EngineCommand = Models['WebSocketMessages_type']
// TODO extending this type to add the type property is a work around
// see https://github.com/KittyCAD/api-deux/issues/1096
export interface EngineCommand extends _EngineCommand {
type: 'modeling_cmd_req'
}
type OkResponse = Models['OkModelingCmdResponse_type']
type WSResponse = Models['OkModelingCmdResponse_type']
type WebSocketResponse = Models['WebSocketResponses_type']
export class EngineCommandManager {
artifactMap: ArtifactMap = {}
@ -113,13 +109,19 @@ export class EngineCommandManager {
) {
console.warn('something went wrong: ', event.data)
} else {
const message = JSON.parse(event.data)
if (message.type === 'sdp_answer') {
const message: WebSocketResponse = JSON.parse(event.data)
if (
message.type === 'sdp_answer' &&
message.answer.type !== 'unspecified'
) {
this.pc?.setRemoteDescription(
new RTCSessionDescription(message.answer)
new RTCSessionDescription({
type: message.answer.type,
sdp: message.answer.sdp,
})
)
} else if (message.type === 'trickle_ice') {
this.pc?.addIceCandidate(message.candidate)
this.pc?.addIceCandidate(message.candidate as RTCIceCandidateInit)
} else if (message.type === 'ice_server_info' && this.pc) {
console.log('received ice_server_info')
if (message.ice_servers.length > 0) {
@ -193,7 +195,7 @@ export class EngineCommandManager {
console.log('lossy data channel error')
})
this.lossyDataChannel.addEventListener('message', (event) => {
const result: WSResponse = JSON.parse(event.data)
const result: OkResponse = JSON.parse(event.data)
if (
result.type === 'highlight_set_entity' &&
result.sequence &&
@ -204,11 +206,11 @@ export class EngineCommandManager {
}
})
})
} else if (message.cmd_id) {
} else if (message.type === 'modeling') {
const id = message.cmd_id
const command = this.artifactMap[id]
if (message?.result?.ok) {
const result: WSResponse = message.result.ok
if ('ok' in message.result) {
const result: OkResponse = message.result.ok
if (result.type === 'select_with_point') {
if (result.entity_id) {
this.onClickCallback({
@ -280,7 +282,6 @@ export class EngineCommandManager {
type: 'select_clear',
},
cmd_id: uuidv4(),
file_id: uuidv4(),
})
this.sendSceneCommand({
type: 'modeling_cmd_req',
@ -289,7 +290,6 @@ export class EngineCommandManager {
entities: selections.idBasedSelections.map((s) => s.id),
},
cmd_id: uuidv4(),
file_id: uuidv4(),
})
}
sendSceneCommand(command: EngineCommand) {
@ -297,6 +297,7 @@ export class EngineCommandManager {
console.log('socket not ready')
return
}
if (command.type !== 'modeling_cmd_req') return
const cmd = command.cmd
if (cmd.type === 'camera_drag_move' && this.lossyDataChannel) {
cmd.sequence = this.outSequence

View File

@ -1,4 +1,3 @@
import { v4 as uuidv4 } from 'uuid'
import { InternalFn } from './stdTypes'
import {
ExtrudeGroup,
@ -49,7 +48,6 @@ export const extrude: InternalFn = (
cap: true,
},
cmd_id: id,
file_id: uuidv4(),
},
})

View File

@ -22,7 +22,6 @@ import {
import { GuiModes, toolTips, TooTip } from '../../useStore'
import { splitPathAtPipeExpression } from '../modifyAst'
import { generateUuidFromHashSeed } from '../../lib/uuid'
import { v4 as uuidv4 } from 'uuid'
import {
SketchLineHelper,
@ -282,7 +281,6 @@ export const line: SketchLineHelper = {
},
},
cmd_id: id,
file_id: uuidv4(),
},
})
const currentPath: Path = {
@ -1575,7 +1573,6 @@ export const close: InternalFn = (
path_id: sketchGroup.id,
},
cmd_id: id,
file_id: uuidv4(),
},
})
@ -1639,7 +1636,6 @@ export const startSketchAt: InternalFn = (
type: 'start_path',
},
cmd_id: pathId,
file_id: uuidv4(),
},
})
engineCommandManager.sendSceneCommand({
@ -1654,7 +1650,6 @@ export const startSketchAt: InternalFn = (
},
},
cmd_id: id,
file_id: uuidv4(),
})
const currentPath: Path = {
type: 'base',

1201
src/wasm-lib/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ anyhow = "1.0.75"
backtrace = "0.3"
bincode = "1.3.3"
gloo-utils = "0.2.0"
kittycad = { version = "0.2.15", default-features = false, features = ["js"] }
lazy_static = "1.4.0"
regex = "1.7.1"
serde = {version = "1.0.152", features = ["derive"] }

View File

@ -1,18 +1,17 @@
//! Functions for exported files from the server.
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
/// A file that has been exported from the server.
#[derive(Debug, Deserialize, Serialize)]
pub struct File {
pub name: String,
pub contents: Vec<u8>,
}
#[wasm_bindgen]
pub fn deserialize_files(data: Vec<u8>) -> Result<JsValue, JsError> {
let files: Vec<File> = bincode::deserialize(&data)?;
let ws_resp: kittycad::types::WebSocketResponses = bincode::deserialize(&data)?;
Ok(serde_wasm_bindgen::to_value(&files)?)
if let kittycad::types::WebSocketResponses::Export { files } = ws_resp {
return Ok(serde_wasm_bindgen::to_value(&files)?);
}
Err(JsError::new(&format!(
"Invalid response type, got: {:?}",
ws_resp
)))
}

View File

@ -1747,10 +1747,10 @@
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
"@kittycad/lib@^0.0.27":
version "0.0.27"
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.27.tgz#6619494e365b6dfe1e400835d52b56a5d5128caa"
integrity sha512-oRISiGJghEVm9hUs8y8ZYGRw4HFDkvK51E71ADKrNp+Mtmrzwjzt2sEj0C3yBQ8kKjeUiCeJU2EHSf2kYfD9bw==
"@kittycad/lib@^0.0.28":
version "0.0.28"
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.28.tgz#a40d67544bf2eb5571855114a75d8cb0eb9ec189"
integrity sha512-T5Lnu7qoB3bc4OMD3s4khPas+VkNKrMllpkvCzKrx7XXrelDCZOd21xALwEzbzOPMUdtp2SBd6nuJKMH/N2aOA==
dependencies:
node-fetch "3.3.2"
openapi-types "^12.0.0"