77import { RandomJson } from '@jsonjoy.com/json-random' ;
88import { genRandomExample } from '@jsonjoy.com/json-random/lib/examples' ;
99import { s } from '../schema' ;
10- import { t } from '../type' ;
10+ import { ModuleType } from '../type/classes/ModuleType' ;
11+ import type { Type } from '../type' ;
12+
13+ const mod = new ModuleType ( ) ;
14+ export const t = mod . t ;
1115
1216export const randomJson = ( ) => {
1317 return Math . random ( ) < 0.5 ? genRandomExample ( ) : RandomJson . generate ( ) ;
@@ -78,6 +82,18 @@ export const schemaCategories = {
7882 all : allSchemas ,
7983} as const ;
8084
85+ const primitivesModule = new ModuleType ( ) ;
86+ export const primitiveTypes = Object . entries ( primitiveSchemas ) . reduce ( ( acc , [ key , schema ] ) => {
87+ acc [ key ] = primitivesModule . t . import ( schema ) ;
88+ return acc ;
89+ } , { } as Record < string , Type > ) ;
90+
91+ const compositesModule = new ModuleType ( ) ;
92+ export const compositeTypes = Object . entries ( compositeSchemas ) . reduce ( ( acc , [ key , schema ] ) => {
93+ acc [ key ] = compositesModule . t . import ( schema ) ;
94+ return acc ;
95+ } , { } as Record < string , Type > ) ;
96+
8197/**
8298 * User profile schema with nested objects and optional fields
8399 */
@@ -92,7 +108,8 @@ export const User = t
92108 age : t . Number ( { gte : 0 , lte : 150 } ) ,
93109 verified : t . bool ,
94110 } )
95- . opt ( 'avatar' , t . String ( { format : 'ascii' } ) ) ;
111+ . opt ( 'avatar' , t . String ( { format : 'ascii' } ) )
112+ . alias ( 'User' ) . type ;
96113
97114/**
98115 * Product catalog schema with arrays and formatted numbers
@@ -189,7 +206,7 @@ export const Event = t.Object(
189206 t . Key ( 'location' , t . Tuple ( [ t . Number ( { format : 'f64' } ) , t . Number ( { format : 'f64' } ) ] ) ) ,
190207 t . Key ( 'metadata' , t . Map ( t . Or ( t . str , t . num , t . bool ) ) ) ,
191208 t . KeyOpt ( 'sessionId' , t . str ) ,
192- ) ;
209+ ) . alias ( 'Event' ) . type ;
193210
194211/**
195212 * Contact information schema with formatted strings
@@ -287,3 +304,18 @@ export const ComplexNested = t.Object(
287304 } ) ,
288305 ) ,
289306) ;
307+
308+ export const allSerializableTypes = {
309+ ...primitiveTypes ,
310+ ...compositeTypes ,
311+ User,
312+ Product,
313+ BlogPost,
314+ ApiResponse,
315+ FileMetadata,
316+ Configuration,
317+ Event,
318+ ContactInfo,
319+ DatabaseRecord,
320+ ComplexNested,
321+ } as const ;
0 commit comments