/*
* 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 { SDKValidationError } from "./errors/sdkvalidationerror.js";
import {
NetworkIdentifier,
NetworkIdentifier$inboundSchema,
NetworkIdentifier$Outbound,
NetworkIdentifier$outboundSchema,
} from "./networkidentifier.js";
import {
PartialBlockIdentifier,
PartialBlockIdentifier$inboundSchema,
PartialBlockIdentifier$Outbound,
PartialBlockIdentifier$outboundSchema,
} from "./partialblockidentifier.js";
/**
* A BlockRequest is utilized to make a block request on the /block endpoint.
*/
export type BlockRequest = {
/**
* The network_identifier specifies which network a particular object is associated with.
*/
networkIdentifier: NetworkIdentifier;
/**
* When fetching data by BlockIdentifier, it may be possible to only specify the index or hash. If neither property is specified, it is assumed that the client is making a request at the current block.
*/
blockIdentifier: PartialBlockIdentifier;
};
/** @internal */
export const BlockRequest$inboundSchema: z.ZodType<
BlockRequest,
z.ZodTypeDef,
unknown
> = z.object({
network_identifier: NetworkIdentifier$inboundSchema,
block_identifier: PartialBlockIdentifier$inboundSchema,
}).transform((v) => {
return remap$(v, {
"network_identifier": "networkIdentifier",
"block_identifier": "blockIdentifier",
});
});
/** @internal */
export type BlockRequest$Outbound = {
network_identifier: NetworkIdentifier$Outbound;
block_identifier: PartialBlockIdentifier$Outbound;
};
/** @internal */
export const BlockRequest$outboundSchema: z.ZodType<
BlockRequest$Outbound,
z.ZodTypeDef,
BlockRequest
> = z.object({
networkIdentifier: NetworkIdentifier$outboundSchema,
blockIdentifier: PartialBlockIdentifier$outboundSchema,
}).transform((v) => {
return remap$(v, {
networkIdentifier: "network_identifier",
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 BlockRequest$ {
/** @deprecated use `BlockRequest$inboundSchema` instead. */
export const inboundSchema = BlockRequest$inboundSchema;
/** @deprecated use `BlockRequest$outboundSchema` instead. */
export const outboundSchema = BlockRequest$outboundSchema;
/** @deprecated use `BlockRequest$Outbound` instead. */
export type Outbound = BlockRequest$Outbound;
}
export function blockRequestToJSON(blockRequest: BlockRequest): string {
return JSON.stringify(BlockRequest$outboundSchema.parse(blockRequest));
}
export function blockRequestFromJSON(
jsonString: string,
): SafeParseResult<BlockRequest, SDKValidationError> {
return safeParse(
jsonString,
(x) => BlockRequest$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'BlockRequest' from JSON`,
);
}