Skip to content

Commit

Permalink
Switch to using Valibot variant schemas rather than union schemas whe…
Browse files Browse the repository at this point in the history
…re appropriate
  • Loading branch information
robknight committed Oct 1, 2024
1 parent a3ae530 commit 694ef6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/client-rpc/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type ParcnetRPCMethodName =
| `pod.${keyof typeof ParcnetRPCSchema.pod}`
| `identity.${keyof typeof ParcnetRPCSchema.identity}`;

export const RPCMessageSchema = v.union([
export const RPCMessageSchema = v.variant("type", [
v.object({
type: v.literal(RPCMessageType.PARCNET_CLIENT_INVOKE),
serial: v.number(),
Expand Down Expand Up @@ -70,7 +70,7 @@ export const RPCMessageSchema = v.union([
})
]);

export const InitializationMessageSchema = v.union([
export const InitializationMessageSchema = v.variant("type", [
v.object({
type: v.literal(InitializationMessageType.PARCNET_CLIENT_CONNECT),
zapp: ZappSchema
Expand Down
11 changes: 7 additions & 4 deletions packages/client-rpc/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Groth16Proof } from "snarkjs";
import * as v from "valibot";
import type { ParcnetRPC } from "./rpc_interfaces.js";

const PODValueSchema = v.union([
const PODValueSchema = v.variant("type", [
v.object({
type: v.literal("string"),
value: v.string()
Expand All @@ -24,7 +24,7 @@ const PODValueSchema = v.union([

const PODEntriesSchema = v.record(v.string(), PODValueSchema);

const DefinedEntrySchema = v.union([
const DefinedEntrySchema = v.variant("type", [
v.object({
type: v.literal("string"),
isMemberOf: v.optional(v.array(PODValueSchema)),
Expand Down Expand Up @@ -66,7 +66,10 @@ const OptionalEntrySchema = v.object({
innerType: DefinedEntrySchema
});

const EntrySchema = v.union([DefinedEntrySchema, OptionalEntrySchema]);
const EntrySchema = v.variant("type", [
DefinedEntrySchema,
OptionalEntrySchema
]);

const PODTupleSchema = v.object({
entries: v.array(v.string()),
Expand Down Expand Up @@ -113,7 +116,7 @@ const PodspecProofRequestSchema = v.object({
watermark: v.optional(PODValueSchema)
});

const ProveResultSchema = v.union([
const ProveResultSchema = v.variant("success", [
v.object({
success: v.literal(true),
// TODO: More specific schemas for these
Expand Down

0 comments on commit 694ef6f

Please sign in to comment.