/** * Type Guards for JSON Deserialization * * This module provides runtime type checking for JSON deserialization of block metadata. * Type guards ensure that JSON data conforms to expected TypeScript interfaces before * constructing objects, maintaining type safety at runtime. * * @module typeGuards * * @example * ```typescript * import { isBlockMetadataJson, parseBlockMetadataJson } from 'brightchain-lib'; * * // Validate JSON data structure * if (isBlockMetadataJson(data)) { * // TypeScript knows data is BlockMetadataJson * const metadata = new BlockMetadata(data.size, data.type, ...); * } * * // Parse and validate JSON string * try { * const data = parseBlockMetadataJson(jsonString); * // data is guaranteed to be BlockMetadataJson * } catch (error) { * // Handle validation error with descriptive message * } * ``` */ /** * JSON representation of BlockMetadata. * This interface defines the expected structure of JSON data * when deserializing BlockMetadata objects. */ export interface BlockMetadataJson { /** Block size in bytes (must be a valid BlockSize enum value) */ size: number; /** Block type (must be a valid BlockType enum value) */ type: number; /** Data type (must be a valid BlockDataType enum value) */ dataType: number; /** Length of data without padding (must be non-negative) */ lengthWithoutPadding: number; /** Date created (ISO 8601 string or Unix timestamp) */ dateCreated: string | number; } /** * JSON representation of EphemeralBlockMetadata. * Extends BlockMetadataJson with creator information. */ export interface EphemeralBlockMetadataJson extends BlockMetadataJson { /** Creator ID (serialized as string) */ creator: string; } /** * Error thrown when JSON validation fails. * Provides descriptive information about which field failed validation. */ export declare class JsonValidationError extends Error { readonly field: string; readonly reason: string; readonly value?: unknown | undefined; constructor(field: string, reason: string, value?: unknown | undefined); } /** * Type guard for BlockMetadataJson. * Validates that an unknown value conforms to the BlockMetadataJson interface. * * @param data - Data to validate * @returns True if data is BlockMetadataJson * @throws JsonValidationError if validation fails with descriptive error */ export declare function isBlockMetadataJson(data: unknown): data is BlockMetadataJson; /** * Type guard for EphemeralBlockMetadataJson. * Validates that an unknown value conforms to the EphemeralBlockMetadataJson interface. * * @param data - Data to validate * @returns True if data is EphemeralBlockMetadataJson * @throws JsonValidationError if validation fails with descriptive error */ export declare function isEphemeralBlockMetadataJson(data: unknown): data is EphemeralBlockMetadataJson; /** * Parse and validate a JSON string as BlockMetadataJson. * Combines JSON parsing with type guard validation. * * @param json - JSON string to parse * @returns Validated BlockMetadataJson object * @throws JsonValidationError if validation fails * @throws SyntaxError if JSON parsing fails */ export declare function parseBlockMetadataJson(json: string): BlockMetadataJson; /** * Parse and validate a JSON string as EphemeralBlockMetadataJson. * Combines JSON parsing with type guard validation. * * @param json - JSON string to parse * @returns Validated EphemeralBlockMetadataJson object * @throws JsonValidationError if validation fails * @throws SyntaxError if JSON parsing fails */ export declare function parseEphemeralBlockMetadataJson(json: string): EphemeralBlockMetadataJson; //# sourceMappingURL=typeGuards.d.ts.map