scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Support of cross-modules Schema definitions? #24

Open mgcrea opened 8 years ago

mgcrea commented 8 years ago

I have a specific need of supporting schema (camo's Document) definitions accross modules:

With a basic schema:

import {Document} from 'camo';

export default class User extends Document {
  constructor() {
    super();
    this.name = String;
    this.breed = String;
  }
}

Required from another module:

const uri = 'mongodb://127.0.0.1:27017/core';
log.info('Connecting to database uri="%s"...', uri);
connect(uri).then(db => {
  log.info('Connected to database uri="%s"', uri);
  return;
})
.then(() => {
  log.debug('creating...');
  const lassie = User.create({
    name: 'Lassie'
  });
  log.debug('saving...', lassie);
  return lassie.save().then((l) => {
    log.debug(l.id);
  });
})
.then(() => {
  return User.loadOne({name: 'Lassie'}).then((l) => {
    log.debug('Got Lassie!');
    log.debug('Her unique ID is', l.id);
  });
});

With latest version, this currently hangs on User.create.

More specifically, it looks like that it is this line that do hang:

super();

Which is compiled by babel 6 to something like:

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(User).call(this));

Any idea where this could come from or where should I look into?