Skip to content

Commit

Permalink
Merge pull request #40 from fabrix-app/v1.6
Browse files Browse the repository at this point in the history
[feat] parent proto extension
  • Loading branch information
scott-wyatt authored Apr 16, 2019
2 parents 4a23cd7 + e40d1fb commit cf2fec6
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/SequelizeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ export class SequelizeResolver extends FabrixResolver {
}
}

/**
*
*/
bulkUpdate(values: any, records: any, options = {}) {
if (this._sequelizeModel) {
return this._sequelizeModel.bulkUpdate(values, records, options)
}
}

/**
*
*/
Expand Down
6 changes: 4 additions & 2 deletions lib/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ export const Transformer = {
},

/**
* Get the prototypes of a model
* Get the prototypes of a model and it's parent
*/
getModelPrototypes: (model) => {
return Object.getPrototypeOf(model)
const sup = model.__proto__ ? Object.getPrototypeOf(model.__proto__) : {}
const props = Object.getPrototypeOf(model)
return {...sup, ...props}
},

/**
Expand Down
2 changes: 1 addition & 1 deletion 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": "@fabrix/spool-sequelize",
"version": "1.6.10",
"version": "1.6.11",
"description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const smokesignals = require('smokesignals')
const testModel = require('./testmodel')
const testModel2 = require('./testmodel2')
const testModel3 = require('./testmodel3')
const testModelExtend = require('./testmodelExtend')
const testModelExtend2 = require('./testmodelExtend2')

const SequelizeResolver = require('../../dist/index').SequelizeResolver

Expand Down Expand Up @@ -200,7 +202,9 @@ const App = {
},
testModel,
testModel2,
testModel3
testModel3,
testModelExtend,
testModelExtend2
}
},
config: {
Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/testmodelExtend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Model = require('@fabrix/fabrix/dist/common').FabrixModel
const SequelizeResolver = require('../../dist/index').SequelizeResolver

const TestResolver = class TestResolver extends SequelizeResolver {

}

module.exports = TestExtend = class TestExtend extends Model {
static config(app, Sequelize) {
return {
options: {}
}
}

static schema(app, Sequelize) {
return {
name: {type: Sequelize.STRING, allowNull: false}
}
}

static get resolver () {
return TestResolver
}

classLevelMethod() {
return 'foo'
}
}

TestExtend.prototype.instanceLevelMethod = function() {
return 'bar'
}
TestExtend.prototype.superLevelMethod = function() {
return 'baf'
}
32 changes: 32 additions & 0 deletions test/fixtures/testmodelExtend2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const TestExtend = require('./testmodelExtend')
const SequelizeResolver = require('../../dist/index').SequelizeResolver

const TestResolver = class TestResolver extends SequelizeResolver {

}

module.exports = TestExtend2 = class TestExtend2 extends TestExtend {
static config(app, Sequelize) {
return {
options: {}
}
}

static schema(app, Sequelize) {
return {
name: {type: Sequelize.STRING, allowNull: false}
}
}

static get resolver () {
return TestResolver
}

classLevelMethod() {
return 'foo'
}
}
TestExtend2.prototype.instanceLevelMethod = TestExtend.prototype.instanceLevelMethod
TestExtend2.prototype.nextInstanceLevelMethod = function() {
return 'baz'
}
21 changes: 21 additions & 0 deletions test/integrations/spool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ describe('Spool', () => {
done()
})


it('should access an inherited instanceLevelMethod', (done) => {
const instance = global.app.models.testModelExtend2.build({name: 'test'})
assert.equal(instance.nextInstanceLevelMethod(), 'baz')
assert.equal(instance.instanceLevelMethod(), 'bar')
assert.equal(instance.superLevelMethod(), 'baf')
assert.ok(instance.app)
assert.ok(instance.app.config.get('main'))
done()
})

it('should save an instance', (done) => {
const instance = global.app.models.testModel.build({name: 'test'})
instance.save().then(i => {
Expand Down Expand Up @@ -133,6 +144,16 @@ describe('Spool', () => {
done(err)
})
})
// TODO ENABLE IN Sequelize 5.0
it.skip('should bulk create instances', (done) => {
const instance = global.app.models.testModel.bulkUpdate({name: 'test'}, { name: 'test' })
.then(i => {
done()
})
.catch(err => {
done(err)
})
})

it('should count instances', (done) => {
const instance = global.app.models.testModel.count({where: {name: 'test'}})
Expand Down

0 comments on commit cf2fec6

Please sign in to comment.