masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
228 stars 67 forks source link

fix: Adds support to export.default from es6 models definitions #235

Closed ignacio-badiola closed 3 years ago

ignacio-badiola commented 3 years ago

WHY are these changes introduced?

Currently, the package allows to define models only for es5 modules:

module.exports = {
    fields:{
        name    : "text",
        surname : "text",
        age     : "int",
        created : "timestamp"
    },
    key:["name"]
}

Need to support es6 usage as well:

exports default {
    fields:{
        name    : "text",
        surname : "text",
        age     : "int",
        created : "timestamp"
    },
    key:["name"]
}

This means that now models can be written on typescript and transpiled to js,

Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
    fields:{
        name    : "text",
        surname : "text",
        age     : "int",
        created : "timestamp"
    },
    key:["name"]
};

When the package tries to load models like the last one, fields cannot be found because is one level deep than expected and the following error will be displayed: Unhandled rejection apollo.model.validator.invalidschema: Schema must contain a non-empty "fields" map object

WHAT is this pull request doing?

Adds support to es6 models definition by setting the modelSchema at the expected level.