@ -8,7 +8,6 @@ interface BaseSchemaData<RepresentedT, ReferenceT extends string> {
schema : unknown ,
schema : unknown ,
key : ReferenceT ,
key : ReferenceT ,
definition : { [ key in ReferenceT ] : unknown }
definition : { [ key in ReferenceT ] : unknown }
referenced ? : { [ key in ReferenceT ] : RepresentedT }
reference : { "ref" : ReferenceT } ,
reference : { "ref" : ReferenceT } ,
validate : ValidateFunction < RepresentedT >
validate : ValidateFunction < RepresentedT >
requiredReferences : AnyReferenceList
requiredReferences : AnyReferenceList
@ -19,14 +18,13 @@ export interface SchemaData<RepresentedT, ReferenceT extends string, ReferencesT
schema : JTDSchemaType < RepresentedT , DefinitionsT > ,
schema : JTDSchemaType < RepresentedT , DefinitionsT > ,
key : ReferenceT ,
key : ReferenceT ,
definition : { [ key in ReferenceT ] : JTDSchemaType < RepresentedT , DefinitionsT > }
definition : { [ key in ReferenceT ] : JTDSchemaType < RepresentedT , DefinitionsT > }
referenced ? : { [ key in ReferenceT ] : RepresentedT }
reference : { "ref" : ReferenceT } ,
reference : { "ref" : ReferenceT } ,
validate : ValidateFunction < RepresentedT >
validate : ValidateFunction < RepresentedT >
requiredReferences : ReferencesT
requiredReferences : ReferencesT
}
}
export type AnySchemaData = BaseSchemaData < unknown , string >
export type AnySchemaDataFor < RepresentedT > = BaseSchemaData < RepresentedT , string >
export type AnySchemaDataFor < RepresentedT > = BaseSchemaData < RepresentedT , string >
export type AnySchemaData = AnySchemaDataFor < unknown >
export type AnyReferenceList = AnySchemaData [ ]
export type AnyReferenceList = AnySchemaData [ ]
export type AnyDefinitions = Record < string , unknown >
export type AnyDefinitions = Record < string , unknown >
@ -35,19 +33,16 @@ export type Value<DataT extends AnySchemaData> = Exclude<DataT["value"], undefin
export type Definition < DataT extends AnySchemaData > = Exclude < DataT [ " definition " ] , undefined >
export type Definition < DataT extends AnySchemaData > = Exclude < DataT [ " definition " ] , undefined >
export type Reference < DataT extends AnySchemaData > = Exclude < DataT [ " reference " ] , undefined >
export type Reference < DataT extends AnySchemaData > = Exclude < DataT [ " reference " ] , undefined >
export type ReferenceKey < DataT extends AnySchemaData > = Exclude < DataT [ " key " ] , undefined >
export type ReferenceKey < DataT extends AnySchemaData > = Exclude < DataT [ " key " ] , undefined >
export type Referenced < DataT extends AnySchemaData > = Exclude < DataT [ " referenced " ] , undefined >
export type ReferencedSchemaMap < ReferencesT extends AnyReferenceList > = {
export type ReferencedSchemaMap < ReferencesT extends AnyReferenceList > = {
[ Property in keyof ReferencesT as ReferencesT [ Property ] extends AnySchemaData ? ReferenceKey < ReferencesT [ Property ] > : never ] : ReferencesT [ Property ] extends AnySchemaData ? ReferencesT [ Property ] : never
[ Property in keyof ReferencesT as ReferencesT [ Property ] extends AnySchemaData ? ReferenceKey < ReferencesT [ Property ] > : never ] : ReferencesT [ Property ] extends AnySchemaData ? ReferencesT [ Property ] : never
}
}
export type ReferencedSchema < ReferencesT extends AnyReferenceList > = ReferencedSchemaMap < ReferencesT > [ keyof ReferencedSchemaMap < ReferencesT > ]
export type ReferencedSchema < ReferencesT extends AnyReferenceList > = ReferencedSchemaMap < ReferencesT > [ keyof ReferencedSchemaMap < ReferencesT > ]
export type ReferencedDefinitions < ReferencesT extends AnyReferenceList > = {
[ Property in keyof ReferencedSchemaMap < ReferencesT > ] ? : Definition < ReferencedSchemaMap < ReferencesT > [ Property ] >
}
export type ReferencedTypes < ReferencesT extends AnyReferenceList > = {
export type ReferencedTypes < ReferencesT extends AnyReferenceList > = {
[ Property in keyof ReferencedSchemaMap < ReferencesT > ] ? : Value < ReferencedSchemaMap < ReferencesT > [ Property ] >
[ Property in keyof ReferencedSchemaMap < ReferencesT > ] ? : Value < ReferencedSchemaMap < ReferencesT > [ Property ] >
}
}
// TODO: Add a test for a circular definition (i.e., an object that contains a reference to itself, for recursive objects like trees) in both one- and two-object loops
export function schema <
export function schema <
RepresentedT ,
RepresentedT ,
KeyT extends string ,
KeyT extends string ,