From 55673d293166269b3b056c93b3f786ba944ddfad Mon Sep 17 00:00:00 2001 From: avivash Date: Thu, 23 Nov 2023 14:27:08 -0800 Subject: [PATCH] Chore: fix up type mismatches from homestar SDK --- src/lib/rpc.ts | 5 ++-- src/lib/workflows/index.ts | 49 +++++++------------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/lib/rpc.ts b/src/lib/rpc.ts index 3c5552d..a1e4c47 100644 --- a/src/lib/rpc.ts +++ b/src/lib/rpc.ts @@ -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( diff --git a/src/lib/workflows/index.ts b/src/lib/workflows/index.ts index fbb30f6..b1444c7 100644 --- a/src/lib/workflows/index.ts +++ b/src/lib/workflows/index.ts @@ -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' @@ -41,39 +43,10 @@ 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)[] } } @@ -81,10 +54,10 @@ export type Message = { metadata: { name: string replayed: boolean - workflow: Record<'/', string> + workflow: CID } receipt: RawReceipt - receipt_cid: Record<'/', string> + receipt_cid: CID } type RawReceipt = { @@ -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) { @@ -270,9 +242,6 @@ export const handleMessage = async (message: Message): Promise => { 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 => {