Skip to content

Commit

Permalink
changed generic schemas to factories
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienR1 committed Dec 5, 2023
1 parent b90b679 commit cbdecbb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.7.4",
"version": "0.7.5",
"name": "substreams-sink-webhook",
"description": "Substreams Sink Webhook",
"type": "module",
Expand Down
1 change: 0 additions & 1 deletion src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./cached.js";
export * from "./ed25519.js";
export * from "./schemas.js";
29 changes: 13 additions & 16 deletions src/auth/schemas.ts → src/schemas.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,18 +22,17 @@ export const ManifestSchema = z.object({
});
export type Manifest = z.infer<typeof ManifestSchema>;

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<typeof PayloadBody>;
export const makePayloadBody = <S extends z.Schema>(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<typeof BodySchema>;
export const PingBody = z.object({ message: z.literal("PING") });
export const makeBodySchema = <S extends z.Schema>(payloadSchema: S) => z.union([PingBody, payloadSchema]);

0 comments on commit cbdecbb

Please sign in to comment.