import { Builder, Ref } from '../core/index.js'; import { Type } from '../reflection/type.js'; import { SerializerBuildContext, SerializerBuildContextOptions } from './context.js'; import { HandlerRegistry } from './registry.js'; import type { Serializer } from './serializer.js'; /** * Options passed at runtime to serialization/deserialization functions. */ export interface SerializationOptions { /** * Which groups to include. If a property is not assigned to * a given group, it will be excluded. * Use an empty array to include only non-grouped properties. */ groups?: string[]; /** * Which groups to exclude. If a property is assigned to at least * one given group, it will be excluded. * Use an empty array to exclude only non-grouped properties. */ groupsExclude?: string[]; /** * Enable loose type coercion (default: true). * When true, allows string-to-number, string-to-boolean conversions, etc. */ loosely?: boolean; } /** * Build-time options that are baked into specialized functions. * When set, the corresponding runtime checks are eliminated. */ export interface BuildOptions { /** * Loose mode baked in at build time. * When defined, no runtime check is needed - use this value directly. */ looseBaked?: boolean; /** * Groups to include, baked in at build time. * When defined, group filtering is done at build time (properties excluded from generated code). */ groupsBaked?: string[]; /** * Groups to exclude, baked in at build time. * When defined, group filtering is done at build time. */ groupsExcludeBaked?: string[]; } /** * Check if a property with given groups should be serialized based on options. * Handles undefined/null options gracefully (returns true = allowed). */ export declare function isGroupAllowed(options: SerializationOptions | undefined | null, groupNames: string[]): boolean; /** * Build-specific options extending serializer context options. */ export interface JsonBuildContextOptions extends SerializerBuildContextOptions { validation?: 'strict' | 'loose' | 'fast'; collectErrors?: boolean; rejectUnknownKeys?: boolean; inUnionContext?: boolean; collectUnionMemberErrors?: boolean; skipNaN?: boolean; buildOptions?: BuildOptions; } /** * Build context for JSON/object JIT serialization code generation. * * Extends SerializerBuildContext with JSON-specific functionality: * - Direction (serialize/deserialize/validate) * - Validation mode and error collection * - SerializationOptions reference */ export declare class JsonBuildContext extends SerializerBuildContext { /** The serializer instance */ readonly serializer: Serializer; /** Options ref (bound with nullish coalescing by caller) */ readonly optionsRef: Ref; /** Validation mode: strict, loose, fast (pure && chain), or undefined */ readonly validation: 'strict' | 'loose' | 'fast' | undefined; /** Whether to collect validation errors (for buildTypeGuard with error collection) */ readonly collectErrors: boolean; /** Whether to reject unknown object keys (for strict type guards) */ readonly rejectUnknownKeys: boolean; /** Whether currently checking union members (skip error-adding in post-hook) */ readonly inUnionContext: boolean; /** Whether to collect errors during union member checks (for #577 error filtering) */ readonly collectUnionMemberErrors: boolean; /** Whether to skip NaN checks on numbers (for weak/fastest mode) */ readonly skipNaN: boolean; /** Build-time baked options - when set, eliminate runtime checks */ readonly buildOptions: BuildOptions; constructor(direction: 'serialize' | 'deserialize' | 'validate', serializer: Serializer, b: Builder, optionsRef: Ref, registry: HandlerRegistry, options?: JsonBuildContextOptions); /** * Get the direction including 'validate' for JsonBuildContext-specific logic. * This returns the actual direction passed to the constructor. */ get actualDirection(): 'serialize' | 'deserialize' | 'validate'; /** * Check if loose mode is enabled. * If looseBaked is defined, returns a literal (no runtime check). * Otherwise returns runtime check: options.loosely !== false */ isLoose(): Ref; /** * Check if type can have circular data at runtime. */ hasCircularReference(type: Type): boolean; /** * Throw a serialization error. */ throw_(type: Type, value: Ref, message?: string): void; /** * Store an external value for use in generated code. */ extern(value: T): Ref; /** * Fork state for a property. */ forProperty(name: string): JsonBuildContext; /** * Fork state for an array/tuple index. * * IMPORTANT: Uses fresh fnCache AND fresh typeStack because forIndex is called * inside b.map() callbacks, which create a new JavaScript scope. Variables * declared inside map callbacks are not visible outside, so: * - fnCache must be fresh to avoid variable scope leakage * - typeStack must be fresh because types "in progress" in the outer scope * should not be considered mutual recursion inside the map callback */ forIndex(index: Ref): JsonBuildContext; /** * Fork state for an object key (index signature iteration). * * Unlike forIndex, this keeps the SAME typeStack and fnCache because forKey is used * inside b.forIn() which generates a plain for...in loop (not a new JS scope). * Variables declared in the outer scope are accessible inside the loop body. */ forKey(key: Ref): JsonBuildContext; /** * Fork state for a different registry. */ forRegistry(registry: HandlerRegistry): JsonBuildContext; /** * Fork state for checking a union member. * Error collection is suppressed so that failing members don't add errors. * The union handler itself will add ONE error if all members fail. */ forUnionMember(): JsonBuildContext; /** * Build an extracted function call for a type. * Implements the abstract method from SerializerBuildContext. * * @param isMutualRecursion - If true, this is a recursive reference to a type * currently being built (typeStack.has(type) was true). In this case, fnCache * reuse is safe because we're guaranteed to be on the same code path. * If false, this is depth-based extraction and fnCache reuse is NOT safe * because different code paths might trigger this. */ buildExtractedCall(type: Type, input: Ref, isMutualRecursion: boolean): Ref; /** * Build a type inline without extraction. * Overrides the protected method from SerializerBuildContext to expose it for buildExtractedCall. */ buildInline(type: Type, input: Ref): Ref; } export declare type __ΩSerializationOptions = any[]; export declare type __ΩBuildOptions = any[]; export declare type __ΩJsonBuildContextOptions = any[];