Skip to content

Commit

Permalink
Merge branch 'main' into input-file
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmischka committed Jun 27, 2022
2 parents dfc5868 + e01b577 commit 7fa2d2a
Show file tree
Hide file tree
Showing 12 changed files with 1,280 additions and 712 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"evt": "^1.10.2",
"node-fetch": "^2.0.0",
"superjson": "^1.9.1",
"uuid": "^8.3.2",
"ws": "^8.4.1",
"zod": "^3.13.3"
Expand Down
19 changes: 18 additions & 1 deletion src/classes/IOClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { v4 } from 'uuid'
import { z } from 'zod'
import * as superjson from 'superjson'
import type {
T_IO_RENDER_INPUT,
T_IO_RESPONSE,
Expand Down Expand Up @@ -86,7 +87,16 @@ export class IOClient {
const packed: T_IO_RENDER_INPUT = {
id: v4(),
inputGroupKey,
toRender: components.map(c => c.getRenderInfo()),
toRender: components
.map(c => c.getRenderInfo())
.map(({ props, ...renderInfo }) => {
const { json, meta } = superjson.serialize(props)
return {
...renderInfo,
props: json,
propsMeta: meta,
}
}),
kind: 'RENDER',
}

Expand Down Expand Up @@ -115,6 +125,13 @@ export class IOClient {
throw new Error('Mismatch in return array length')
}

if (result.valuesMeta) {
result.values = superjson.deserialize({
json: result.values,
meta: result.valuesMeta,
})
}

if (result.kind === 'RETURN') {
isReturned = true

Expand Down
2 changes: 2 additions & 0 deletions src/classes/IOComponent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from 'zod'
import { deserialize } from 'superjson'
import {
ioSchema,
resolvesImmediately,
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class IOComponent<MethodName extends T_IO_METHOD_NAMES> {
let parsed: ReturnType<typeof returnSchema.parse>

if (value && typeof value === 'object') {
// TODO: Remove this when all active SDKs support superjson
if (Array.isArray(value)) {
parsed = returnSchema.parse(value.map(v => deserializeDates<any>(v)))
} else {
Expand Down
Loading

0 comments on commit 7fa2d2a

Please sign in to comment.