/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../lib/primitives.js";
import { safeParse } from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import {
BlockEventType,
BlockEventType$inboundSchema,
BlockEventType$outboundSchema,
} from "./blockeventtype.js";
import {
BlockIdentifier,
BlockIdentifier$inboundSchema,
BlockIdentifier$Outbound,
BlockIdentifier$outboundSchema,
} from "./blockidentifier.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
/**
* BlockEvent represents the addition or removal of a BlockIdentifier from storage. Streaming BlockEvents allows lightweight clients to update their own state without needing to implement their own syncing logic.
*/
export type BlockEvent = {
/**
* sequence is the unique identifier of a BlockEvent within the context of a NetworkIdentifier.
*/
sequence: number;
/**
* The block_identifier uniquely identifies a block in a particular network.
*/
blockIdentifier: BlockIdentifier;
/**
* BlockEventType determines if a BlockEvent represents the addition or removal of a block.
*/
type: BlockEventType;
};
/** @internal */
export const BlockEvent$inboundSchema: z.ZodType<
BlockEvent,
z.ZodTypeDef,
unknown
> = z.object({
sequence: z.number().int(),
block_identifier: BlockIdentifier$inboundSchema,
type: BlockEventType$inboundSchema,
}).transform((v) => {
return remap$(v, {
"block_identifier": "blockIdentifier",
});
});
/** @internal */
export type BlockEvent$Outbound = {
sequence: number;
block_identifier: BlockIdentifier$Outbound;
type: string;
};
/** @internal */
export const BlockEvent$outboundSchema: z.ZodType<
BlockEvent$Outbound,
z.ZodTypeDef,
BlockEvent
> = z.object({
sequence: z.number().int(),
blockIdentifier: BlockIdentifier$outboundSchema,
type: BlockEventType$outboundSchema,
}).transform((v) => {
return remap$(v, {
blockIdentifier: "block_identifier",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace BlockEvent$ {
/** @deprecated use `BlockEvent$inboundSchema` instead. */
export const inboundSchema = BlockEvent$inboundSchema;
/** @deprecated use `BlockEvent$outboundSchema` instead. */
export const outboundSchema = BlockEvent$outboundSchema;
/** @deprecated use `BlockEvent$Outbound` instead. */
export type Outbound = BlockEvent$Outbound;
}
export function blockEventToJSON(blockEvent: BlockEvent): string {
return JSON.stringify(BlockEvent$outboundSchema.parse(blockEvent));
}
export function blockEventFromJSON(
jsonString: string,
): SafeParseResult<BlockEvent, SDKValidationError> {
return safeParse(
jsonString,
(x) => BlockEvent$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'BlockEvent' from JSON`,
);
}