@@ -30,22 +30,10 @@ function createEntityBase(
3030 // Merge user-provided fieldMap with the one extracted from the schema
3131 const mergedFieldMap = {
3232 ...EntityClass . extractFieldMapFromSchema ( schemaOrSchemaId , ajvOptions ) ,
33- ...{ type : fieldMap ? .type }
33+ ...{ type : fieldMap ? fieldMap . type : "type" }
3434 } ;
3535
36- // Initialize the AJV instance with options
37- const ajv = new Ajv ( ajvOptions || { } ) ;
38- let schema : any = schemaOrSchemaId ;
39-
40- // If schemaOrSchemaId is a string (schema ID), fetch the schema
41- if ( typeof schema === "string" ) {
42- schema = ajv . getSchema ( schema ) ?. schema ; // Retrieve the schema
43- if ( ! schema ) {
44- throw new Error ( `Schema with ID ${ schema } not found.` ) ;
45- }
46- }
47-
48- const schemaProperties = schema ?. properties || { } ;
36+
4937
5038 // Create a dynamic subclass of the selected entity class
5139 const DynamicEntityClass = class extends EntityClass {
@@ -55,36 +43,14 @@ function createEntityBase(
5543
5644 [ key : string ] : any ; // This allows dynamic fields to be assigned to the instance
5745
58- constructor ( data : { _id ?: string ; _rev ?: string ; [ key : string ] : any } ) {
59- super ( data ) ;
60-
61- // Initialize properties from schema
62- Object . keys ( schemaProperties ) . forEach ( property => {
63- this . privateData . get ( this ) [ property ] = data [ property ] ;
64- } ) ;
65- }
66-
67-
6846
6947 } ;
7048
7149
7250 // Assign the actual class name to the dynamically created class
7351 Object . defineProperty ( DynamicEntityClass , 'name' , { value : name } ) ;
7452
75- // Dynamically add getters and setters based on schema
76- Object . keys ( schemaProperties ) . forEach ( property => {
77- Object . defineProperty ( DynamicEntityClass . prototype , property , {
78- get ( ) {
79- return this . privateData . get ( this ) [ property ] ; // Retrieve the field value
80- } ,
81- set ( value ) {
82- this . privateData . get ( this ) [ property ] = value ; // Assign value to internal variable
83- } ,
84- enumerable : true ,
85- configurable : true
86- } ) ;
87- } ) ;
53+
8854
8955 // Attach static methods if provided
9056 if ( methods ) {
0 commit comments