Skip to content

Commit

Permalink
Hot fix (#53)
Browse files Browse the repository at this point in the history
* 1.4.1

* 1.4.2

* not flex and empty schema parsing error fixed

* Update package-lock.json
  • Loading branch information
saracalihan committed Jan 2, 2023
1 parent b6d1d7c commit 00ba668
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class Model {
constructor(schema: Object, keyPrefix = 'object', modelOption?: ModelOptions) {
this.schema = schema;
this.keyPrefix = keyPrefix;
this.flexSchema = modelOption?.flexSchema;
this.flexSchema = modelOption?.flexSchema ? modelOption?.flexSchema : false;

if (!this.flexSchema && Object.keys(schema).length === 0) {
throw new Error('Only flex schema can be empty! Set the "modelOption.flexSchema" to "true"');
}

if (!modelOption?.keyUnique) {
this.keyUnique = undefined;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metronom",
"version": "1.4.0",
"version": "1.4.1",
"description": "Easy to use Redis ORM based on node-redis",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe('Model.constructor()', () => {
expect(error.message).toBe('createdAt keyUnique must be in to schema!');
}
});
test('client should get error when pass empty schema to not flex model', () => {
try {
new Model({},'users',{
flexSchema: false,
});
} catch (error) {
expect(error.message).toBe('Only flex schema can be empty! Set the "modelOption.flexSchema" to "true"');
}
});
});

describe('model.create()', () => {
Expand Down

0 comments on commit 00ba668

Please sign in to comment.