Skip to content

Commit

Permalink
Fix typings for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
robknight committed Sep 10, 2024
1 parent b8a4315 commit 6a84de7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions packages/app-connector/src/rpc_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RPCMessageType,
SubscriptionUpdateResult
} from "@parcnet/client-rpc";
import { PodspecProofRequest } from "@parcnet/podspec";
import { EntriesSchema, PodspecProofRequest } from "@parcnet/podspec";
import { GPCProof, GPCRevealedClaims } from "@pcd/gpc";
import { EventEmitter } from "eventemitter3";
import { z, ZodFunction, ZodTuple, ZodTypeAny } from "zod";
Expand Down Expand Up @@ -115,7 +115,9 @@ export class ParcnetRPCConnector implements ParcnetRPC, ParcnetEvents {
this.#emitter = new EventEmitter();

this.pod = {
query: async (query: PODQuery): Promise<string[]> => {
query: async <E extends EntriesSchema>(
query: PODQuery<E>
): Promise<string[]> => {
return this.#typedInvoke(
"pod.query",
[query],
Expand All @@ -136,7 +138,9 @@ export class ParcnetRPCConnector implements ParcnetRPC, ParcnetEvents {
ParcnetRPCSchema.shape.pod.shape.delete
);
},
subscribe: async (query: PODQuery): Promise<string> => {
subscribe: async <E extends EntriesSchema>(
query: PODQuery<E>
): Promise<string> => {
return this.#typedInvoke(
"pod.subscribe",
[query],
Expand Down
6 changes: 3 additions & 3 deletions packages/client-rpc/src/rpc_interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GPCBoundConfig, GPCProof, GPCRevealedClaims } from "@pcd/gpc";
* These interfaces are implemented in rpc_client.ts.
*/

export type PODQuery = PODSchema<EntriesSchema>;
export type PODQuery<E extends EntriesSchema> = PODSchema<E>;

export interface SubscriptionUpdateResult {
subscriptionId: string;
Expand Down Expand Up @@ -46,10 +46,10 @@ export interface ParcnetIdentityRPC {

export interface ParcnetPODRPC {
// Returns array of serialized PODs
query: (query: PODQuery) => Promise<string[]>;
query: <E extends EntriesSchema>(query: PODQuery<E>) => Promise<string[]>;
insert: (serializedPod: string) => Promise<void>;
delete: (signature: string) => Promise<void>;
subscribe: (query: PODQuery) => Promise<string>;
subscribe: <E extends EntriesSchema>(query: PODQuery<E>) => Promise<string>;
unsubscribe: (subscriptionId: string) => Promise<void>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/podspec/src/schemas/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type EntriesSchema = Record<string, EntrySchema>;
* Schema for a tuple of entries.
*/
export type EntriesTupleSchema<E extends EntriesSchema> = {
entries: (keyof E)[];
entries: (keyof E & string)[];
isMemberOf?: PODValue[][];
isNotMemberOf?: PODValue[][];
};
2 changes: 1 addition & 1 deletion packages/podspec/src/schemas/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EntriesSchema } from "./entries.js";
* Schema for a tuple of entries.
*/
export type PODTupleSchema<E extends EntriesSchema> = {
entries: (keyof (E & { $signerPublicKey: never }))[];
entries: (keyof (E & { $signerPublicKey: never }) & string)[];
isMemberOf?: PODValue[][];
isNotMemberOf?: PODValue[][];
};
Expand Down

0 comments on commit 6a84de7

Please sign in to comment.