Passing a Schema to an RPC Function in TypeScript

how to pass a schema to an RPC function?
right now I've a function that given a tablename it retrieves the items but the problem is that in order to check the returned json I've to pass the schema, what is the correct way to do so?

export class ItemsList extends S.TaggedRequest<ItemsList>()("ItemsList", {
  failure: S.String,
  success: S.Union(Crates, Skins, Stickers),
  payload: { tableName: S.String, schema: S.Union(Crates, Skins, Stickers) },
}) {}

export const GetItemsMarketHashNames = Rpc.effect(
  ItemsList,
  ({ tableName, schema }) =>
    E.gen(function* () {
      const db = yield* Surrealdb;
      const items = yield* db.getItems(tableName, ["id", "market_hash_name"])
        .pipe(
          E.andThen(S.decodeUnknown(schema)),
        );
      return items;
    }).pipe(E.either, E.andThen(Either.mapLeft((e) => String(e)))),
);
Was this page helpful?