From cbdecbbb3bd3d8caea12054641265ad62c52abfe Mon Sep 17 00:00:00 2001 From: Julien Rousseau Date: Tue, 5 Dec 2023 13:34:30 -0500 Subject: [PATCH] changed generic schemas to factories --- index.ts | 1 + package.json | 2 +- src/auth/index.ts | 1 - src/{auth => }/schemas.ts | 29 +++++++++++++---------------- 4 files changed, 15 insertions(+), 18 deletions(-) rename src/{auth => }/schemas.ts (51%) diff --git a/index.ts b/index.ts index 3a9d2ef..4e5a5ce 100644 --- a/index.ts +++ b/index.ts @@ -9,6 +9,7 @@ import { toText } from "./src/http.js"; import { ping } from "./src/ping.js"; export * from "./src/auth/index.js"; +export * from "./src/schemas.js"; export async function action(options: WebhookRunOptions) { // Block Emitter diff --git a/package.json b/package.json index 66322ea..d487019 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.7.4", + "version": "0.7.5", "name": "substreams-sink-webhook", "description": "Substreams Sink Webhook", "type": "module", diff --git a/src/auth/index.ts b/src/auth/index.ts index 38d0116..413f94f 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -1,3 +1,2 @@ export * from "./cached.js"; export * from "./ed25519.js"; -export * from "./schemas.js"; diff --git a/src/auth/schemas.ts b/src/schemas.ts similarity index 51% rename from src/auth/schemas.ts rename to src/schemas.ts index 3713aa9..1739de6 100644 --- a/src/auth/schemas.ts +++ b/src/schemas.ts @@ -1,5 +1,3 @@ -import { DatabaseChanges } from "@substreams/sink-database-changes/zod"; -import { EntityChanges } from "@substreams/sink-entity-changes/zod"; import z from "zod"; export const boolean = z @@ -24,18 +22,17 @@ export const ManifestSchema = z.object({ }); export type Manifest = z.infer; -export const PingBody = z.object({ message: z.literal("PING") }); -export const PayloadBody = z.object({ - cursor: z.string(), - session: z.object({ - traceId: z.string(), - resolvedStartBlock: z.number(), - }), - clock: ClockSchema, - manifest: ManifestSchema, - data: z.union([EntityChanges, DatabaseChanges, z.unknown()]), -}); -export type PayloadBody = z.infer; +export const makePayloadBody = (dataSchema: S) => + z.object({ + cursor: z.string(), + session: z.object({ + traceId: z.string(), + resolvedStartBlock: z.number(), + }), + clock: ClockSchema, + manifest: ManifestSchema, + data: dataSchema, + }); -export const BodySchema = z.union([PingBody, PayloadBody]); -export type BodySchema = z.infer; +export const PingBody = z.object({ message: z.literal("PING") }); +export const makeBodySchema = (payloadSchema: S) => z.union([PingBody, payloadSchema]);