Skip to content

Commit 75f3643

Browse files
committed
hotfix
1 parent 12860b4 commit 75f3643

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nosqlax",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "NoSQLax is a modern, lightweight JavaScript Object Document Mapper(ODM) library that makes working with CouchDB a breeze. Inspired by CouchDB’s “Relax” philosophy and the chill vibes of Snorlax, NoSQLax takes the hassle out of managing your data, offering a streamlined and intuitive repository pattern to handle CRUD operations effortlessly.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/core/BaseEntity.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ abstract class BaseEntity implements IBaseEntity {
252252
circular: 'ignore'
253253
}
254254
} as const;
255-
const dereferencedSchema2 = await $RefParser.bundle(rawSchema, options);
255+
const dereferencedSchema2 = await $RefParser.dereference(rawSchema, options);
256256

257257
let restructured;
258258

@@ -294,25 +294,26 @@ abstract class BaseEntity implements IBaseEntity {
294294

295295
for (const [schemaProp, schemaDef] of Object.entries(schemaProperties)) {
296296
const propName = reverseMap[schemaProp] || schemaProp;
297-
298-
// Inject definitions into subschema if needed
299-
if (typeof schemaDef === 'object' && schemaDefs) {
300-
(schemaDef as any).definitions = {
301-
...(schemaDef as any).definitions,
302-
...schemaDefs
303-
}
304-
}
305-
297+
306298
// Protect _id and _rev from being overridden
307299
if (propName === '_id' || propName === '_rev') {
308300
continue;
309301
}
310-
311-
const ajvProp = new Ajv({
312-
strict: false
313-
});
314-
const propValidator = ajvProp.compile(schemaDef as object);
315-
302+
303+
// Clone schema and inject definitions to avoid mutation
304+
const enrichedSchemaDef =
305+
typeof schemaDef === 'object' && schemaDefs
306+
? {
307+
...schemaDef,
308+
definitions: {
309+
...(schemaDef as any).definitions,
310+
...schemaDefs
311+
}
312+
}
313+
: schemaDef;
314+
315+
const propValidator = ajv.compile(enrichedSchemaDef as object);
316+
316317
Object.defineProperty(ctor.prototype, propName, {
317318
get() {
318319
return this.__data.get(this)?.[propName];
@@ -322,19 +323,20 @@ abstract class BaseEntity implements IBaseEntity {
322323
if (!this.validators[propName]) {
323324
this.validators[propName] = propValidator;
324325
}
326+
325327
if (!propValidator(value)) {
326328
const errors = (propValidator.errors as ErrorObject[] | null | undefined)
327329
?.map(err => `${err.instancePath} ${err.message}`)
328-
.join(', ');
329-
throw new Error(`Validation failed for "${propName}": ${errors}`);
330+
.join('\n');
331+
throw new Error(`Validation failed for "${propName}":\n${errors}`);
330332
}
331-
333+
332334
const dataStore = this.__data.get(this) || {};
333335
dataStore[propName] = value;
334336
this.__data.set(this, dataStore);
335337
},
336338
enumerable: true,
337-
configurable: false
339+
configurable: true // Allow redefinition if needed
338340
});
339341
}
340342

0 commit comments

Comments
 (0)