@@ -107,17 +107,18 @@ abstract class BaseEntity implements IBaseEntity {
107107
108108 static type : string ;
109109 static schemaOrSchemaId : string | object ;
110+ static ajvOptions : any = { } ;
111+
110112 private __data : WeakMap < any , Record < string , any > > = new WeakMap ( ) ;
111113 private validators : Record < string , ValidateFunction > = { } ;
112114
113-
114115 // Index signature to allow dynamic properties
115116 [ key : string ] : any ; // This allows dynamic fields to be assigned to the instance
116117
117118 // Map from entity attributes to document fields, type is implicitly handled
118119 static fieldMap : Record < string , string > = { type : "type" } ; // Default fieldMap, type is implicitly required
119120
120- constructor ( data : { _id ?: string ; _rev ?: string ; [ key : string ] : any } = { } ) {
121+ constructor ( data : { _id ?: string ; _rev ?: string ; [ key : string ] : any } = { } , ajvOptions : any = { } ) {
121122 this . _id = data . _id ;
122123 this . _rev = data . _rev ;
123124 this . __data . set ( this , { } ) ;
@@ -129,7 +130,8 @@ abstract class BaseEntity implements IBaseEntity {
129130 return ;
130131 }
131132
132- const ajv = new Ajv ( { } ) ;
133+ const ajvOptionsCtor = ctor . ajvOptions || { } ;
134+ const ajv = new Ajv ( ajvOptionsCtor ) ;
133135 let schema : any ;
134136
135137 if ( typeof ctor . schemaOrSchemaId === 'string' ) {
@@ -158,7 +160,7 @@ abstract class BaseEntity implements IBaseEntity {
158160 }
159161
160162 // compile to dereference the schema
161- const validator = ajv . compile ( rawSchema ) ;
163+ const validator = ajv . compile ( rawSchema ) ;
162164 const resolvedSchema = validator . schema as AnySchemaObject ;
163165 restructureSchemaFromFieldMap ( rawSchema , fieldMap ) ;
164166
0 commit comments