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]);