UNPKG

@gati-framework/types

Version:

Gati Type System - TypeScript-first branded types and schema system

93 lines 2.43 kB
/** * @module serialization * @description GType serialization, deserialization, and fingerprinting */ import type { GType, GTypeSchema } from './gtype.js'; /** * Serialize GType to JSON string * * @param gtype - GType to serialize * @param pretty - Whether to pretty-print JSON * @returns JSON string * * @example * ```typescript * const serialized = serializeGType(myType, true); * console.log(serialized); * ``` */ export declare function serializeGType(gtype: GType | GTypeSchema, pretty?: boolean): string; /** * Deserialize JSON string to GType * Handles version migration automatically * * @param json - JSON string * @returns Parsed GType * @throws {Error} If JSON is invalid or migration fails * * @example * ```typescript * const gtype = deserializeGType(jsonString); * ``` */ export declare function deserializeGType(json: string): GType | GTypeSchema; /** * Generate a stable fingerprint (SHA-256 hash) of a GType * Used for schema comparison and caching * * @param gtype - GType to fingerprint * @returns SHA-256 hash (hex string) * * @example * ```typescript * const hash1 = fingerprint(type1); * const hash2 = fingerprint(type2); * * if (hash1 === hash2) { * console.log('Types are identical'); * } * ``` */ export declare function fingerprint(gtype: GType | GTypeSchema): string; /** * Compare two GTypes for structural equality * More efficient than comparing fingerprints for simple checks * * @param a - First GType * @param b - Second GType * @returns True if types are structurally equal * * @example * ```typescript * if (areGTypesEqual(type1, type2)) { * console.log('Types are equivalent'); * } * ``` */ export declare function areGTypesEqual(a: GType | GTypeSchema, b: GType | GTypeSchema): boolean; /** * Create a deep copy of a GType * * @param gtype - GType to clone * @returns Deep copy */ export declare function cloneGType<T extends GType | GTypeSchema>(gtype: T): T; /** * Validate a GType schema for correctness * * @param gtype - GType to validate * @returns Validation result with errors * * @example * ```typescript * const result = validateGTypeSchema(myType); * if (!result.valid) { * console.error('Schema errors:', result.errors); * } * ``` */ export declare function validateGTypeSchema(gtype: GType | GTypeSchema): { valid: boolean; errors: string[]; }; //# sourceMappingURL=serialization.d.ts.map