import type { ApplogValue } from '../../applog/datom-types.ts' import type { ISchemaAdapter, VMAttributeDef } from '../types.ts' /** * Pattern for creating a schema adapter from a Typia-generated schema. * * Typia is NOT a runtime dependency of @wovin/core, so this adapter * works by accepting the Typia type object directly along with the * attribute definitions (which must be provided separately since * Typia doesn't expose runtime property introspection by default). * * Usage: * ```ts * import typia from 'typia' * import { createTypiaAdapter } from '@wovin/core/viewmodel/adapters/typia' * * interface MyEntity { name: string; age?: number } * * const adapter = createTypiaAdapter( * typia.createValidate(), * 'myEntity', * { * attributes: [ * { name: 'name', atPath: 'myEntity/name', optional: false }, * { name: 'age', atPath: 'myEntity/age', optional: true }, * ], * }, * ) * ``` */ export function createTypiaAdapter>( _typiaValidator: (input: unknown) => { success: boolean; data: T | null; errors?: any[] }, entityPrefix: string, options: { /** Attribute definitions (required for Typia since property introspection is compile-time) */ attributes: VMAttributeDef[] /** Default values */ defaults?: Partial }, ): ISchemaAdapter { return { getAttributeDefs: () => options.attributes, getDefaults: () => (options?.defaults ?? {}) as Partial, getEntityPrefix: () => entityPrefix, createValidator: () => (value: unknown): value is T => { const result = _typiaValidator(value) return result.success }, } }