M .babelrc +3 -2
@@ 1,10 1,11 @@
{
"sourceMap": "inline",
"presets": [
- "latest", "stage-1"
+ "@babel/preset-env"
],
"plugins": [
- "transform-decorators-legacy"
+ ["@babel/plugin-proposal-decorators", { "legacy": true }],
+ "@babel/plugin-proposal-class-properties"
]
}
M package.json +10 -10
@@ 3,6 3,7 @@
"description": "This is an experimental model toolkit for web applications. It's meant to allow for a model that is closer to the Domain Model pattern.",
"homepage": "https://bitbucket.org/ged/bailiwick#readme",
"version": "0.2.3",
+ "browserslist": "> 0.25%, not dead",
"scripts": {
"build": "babel src --out-dir ./dist",
"prepublish": "yarn build",
@@ 40,18 41,17 @@
},
"main": "dist/index",
"devDependencies": {
- "babel-cli": "^6.24.0",
- "babel-core": "^6.24.0",
- "babel-eslint": "^7.2.1",
- "babel-plugin-transform-decorators-legacy": "^1.3.4",
- "babel-plugin-transform-runtime": "^6.23.0",
- "babel-polyfill": "^6.23.0",
- "babel-preset-es2015": "^6.24.0",
- "babel-preset-latest": "^6.24.0",
- "babel-preset-stage-1": "^6.22.0",
+ "@babel/cli": "^7.0.0",
+ "@babel/core": "^7.8.4",
+ "@babel/plugin-proposal-class-properties": "^7.8.3",
+ "@babel/plugin-proposal-decorators": "^7.8.3",
+ "@babel/preset-env": "^7.8.4",
+ "@babel/register": "^7.8.3",
+ "babel-eslint": "^10.0.3",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
- "eslint": "^3.18.0",
+ "core-js": "^3.6.4",
+ "eslint": "^6.8.0",
"eslint-plugin-babel": "^4.1.1",
"isomorphic-fetch": "^2.2.1",
"mocha": "^3.2.0",
M scripts/mocha_runner.js +1 -2
@@ 1,8 1,7 @@
/* -*- javascript -*- */
"use strict";
-require('babel-core/register');
-require('babel-polyfill');
+require('@babel/register');
process.on('unhandledRejection', function (error) {
console.error('Unhandled Promise Rejection:');
M spec/associations.spec.js +1 -1
@@ 33,7 33,7 @@ describe( 'Associations', () => {
sandbox = null;
beforeEach( () => {
- logger.outputTo( console );
+ // logger.outputTo( console );
sandbox = sinon.sandbox.create();
chai.use( sinonChai );
M spec/model.spec.js +4 -24
@@ 47,6 47,7 @@ describe( 'Model class', () => {
beforeEach( () => {
sandbox = sinon.sandbox.create();
+ // logger.outputTo( console );
User.datastore = new NullDatastore();
@@ 57,6 58,7 @@ describe( 'Model class', () => {
afterEach( () => {
+ logger.reset();
sandbox.restore();
});
@@ 271,7 273,7 @@ describe( 'Model class', () => {
sandbox.stub( User.datastore, 'remove' ).
resolves( Object.assign(data, {removed_at: removedDate}) );
return expect( user.delete() ).to.be.fulfilled.
- then( () => {
+ then( user => {
expect( User.datastore.remove ).to.have.been.calledOnce;
expect( user.removed_at ).to.eq( removedDate );
});
@@ 306,6 308,7 @@ describe( 'Model class', () => {
return expect( user.validate() ).to.be.fulfilled;
} );
+
it( 'returns a Promise that rejects if the object is not valid', () => {
user.firstName = 'Nate'; // No Nates allowed
user.lastName = null; // missing
@@ 337,29 340,6 @@ describe( 'Model class', () => {
} );
} );
-
- describe( 'deleting', () => {
-
- it( "deletes the object if the object has an id", () => {
- let data = { id: 1234, firstName: "Morty", email: "morty@rm.co" };
- let user = new User( data );
-
- user.email = "mortimer@rm.co";
-
- return expect( user.delete() ).to.be.fulfilled.then( () => {
- expect( user.email ).to.equal( "mortimer@rm.co" );
- } );
-
- });
-
-
- it( "resolves if the object does not have an id", () => {
- let user = new User();
-
- expect( user.delete.bind( user ) ).to.throw(/Cannot delete an object with no id/);
- });
-
- });
} );
M spec/null-datastore.spec.js +7 -3
@@ 23,10 23,14 @@ describe( 'Null Datastore class', () =>
beforeEach( () => {
+ // logger.outputTo( console );
chai.use( chaiAsPromised );
datastore = new NullDatastore();
});
+ afterEach( () => {
+ logger.reset();
+ });
describe( 'get', () => {
@@ 199,11 203,11 @@ describe( 'Null Datastore class', () =>
it( 'can remove the data for an existing object', () => {
let objId = ids[ 1 ];
return expect( datastore.remove(User, objId) ).
- to.eventually.be.true.
+ to.eventually.deep.equal( objects[1] ).
then( () => {
expect( datastore.get(User, objId) ).
to.be.rejectedWith( `No such User ID=${objId}` );
- });
+ });
});
@@ 213,7 217,7 @@ describe( 'Null Datastore class', () =>
logger.debug( `Non-existent ID = ${nonexistentId}` );
return expect( datastore.remove(User, nonexistentId) ).
- to.eventually.be.false;
+ to.eventually.be.undefined;
});
});
M src/model.js +9 -12
@@ 287,27 287,24 @@ export class Model {
* result.
*/
delete() {
- let dirtyData = {};
- for ( let field of this[ DIRTY_FIELDS ] ) {
- dirtyData[ field ] = this[ DATA ][ field ];
- }
-
if ( this.id ) {
return this.validate().
then( () => {
- this[ DATASTORE ].remove( this.constructor, this.id, dirtyData );
+ return this[ DATASTORE ].remove( this.constructor, this.id );
}).
then( deletedData => {
- logger.debug( "Updating ", this, " with results from deletion." );
- Object.assign( this[ DATA ], deletedData );
- this[ NEW_OBJECT ] = true;
- this[ DIRTY_FIELDS ].clear();
- this.defineAttributes( this[ DATA ] );
+ if ( deletedData ) {
+ logger.debug( "Updating ", this, " with results from deletion: ", deletedData );
+ Object.assign( this[ DATA ], deletedData );
+ this[ NEW_OBJECT ] = true;
+ this[ DIRTY_FIELDS ].clear();
+ this.defineAttributes( this[ DATA ] );
+ }
return this;
});
} else {
- throw new Error( "Cannot delete an object with no id" );
+ return Promise.resolve( null );
}
}
M src/null-datastore.js +1 -4
@@ 216,15 216,12 @@ export class NullDatastore extends Datas
* @method remove
* @param {Class} type the collection to remove the object from
* @param {Integer} id the ID of the object to remove
- * @param {Object} data the object data to store
*
* @returns {Promise} the promise that resolves to `true` if the object existed
* or `false` if it did not.
*/
- remove( type, id, data ) {
+ remove( type, id ) {
let collection = this.getCollectionForType( type );
- collection.set( id, data );
-
let current = collection.get( id );
collection.delete( id );