Skip to content

Commit

Permalink
Chore: fix up type mismatches from homestar SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
avivash committed Nov 23, 2023
1 parent 60eee8f commit 55673d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/lib/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Homestar as Client } from '@fission-codes/homestar'
import { Homestar } from '@fission-codes/homestar'
import { WebsocketTransport } from '@fission-codes/homestar/transports/ws.js'
import { WebSocket } from 'unws'

import { addNotification } from './notifications'

let homestar
export const getHomestarClient = () => {
let homestar: Client
export const getHomestarClient = (): Client => {
try {
if (!homestar) {
const transport = new WebsocketTransport(
Expand Down
49 changes: 9 additions & 40 deletions src/lib/workflows/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as odd from '@oddjs/odd'
import { workflow as workflowBuilder } from '@fission-codes/homestar/workflow'
import type { MaybeResult } from '@fission-codes/homestar/codecs/types'
import { workflow as workflowBuilder, type BlurInvocation, type CropInvocation, type GrayscaleInvocation, type Rotate90Invocation } from '@fission-codes/homestar/workflow'
import { base64 } from 'iso-base/rfc4648'
import type { CID } from 'multiformats'
import { get as getStore } from 'svelte/store'

import type { Receipt, FunctionOperation, Meta } from '$lib/functions'
Expand Down Expand Up @@ -41,50 +43,21 @@ export type Run = {
receipts: Receipt[]
}

// export type SimplePayload = {
// name: string
// workflow: {
// tasks: SimpleTask[]
// }
// }
// type SimpleTask = {
// name: string
// data: string
// args: number[]
// }

export type Payload = {
name: string
workflow: {
tasks: Task[]
}
}

type Task = {
cause: null
meta: {
memory: number
time: number
}
prf: []
run: {
input: {
args: any
}
nnc: string
op: string
rsc: string
tasks: (BlurInvocation | CropInvocation | GrayscaleInvocation | Rotate90Invocation)[]
}
}

export type Message = {
metadata: {
name: string
replayed: boolean
workflow: Record<'/', string>
workflow: CID
}
receipt: RawReceipt
receipt_cid: Record<'/', string>
receipt_cid: CID
}

type RawReceipt = {
Expand Down Expand Up @@ -217,14 +190,13 @@ export const runWorkflow = async (

await homestar.runWorkflow(
{ ...payloadToRun, name: runName },
async data => {
async (data: MaybeResult) => {
if (data.error) {
// @ts-ignore-next-line
// @ts-expect-error received WorkflowNotificationError from Homestar node
throw new Error(data.error)
}

// @ts-ignore-next-line
await handleMessage(data.result)
await handleMessage(data.result as Message)
}
)
} catch (error) {
Expand Down Expand Up @@ -270,9 +242,6 @@ export const handleMessage = async (message: Message): Promise<void> => {
if (message.receipt !== undefined && message.receipt.meta !== undefined) {
const receipt = parseReceipt(message.receipt)

// // Log receipt
// console.table(receipt)

// Update runs in `workflows` store
workflowsStore.update(state => {
const updatedWorkflows = state.workflows?.map(workflow => {
Expand Down

0 comments on commit 55673d2

Please sign in to comment.