Bumped knex & bookshelf dependencies (#10404)

refs #9389, refs #9248

- https://github.com/bookshelf/bookshelf/releases/tag/0.14.0
- Bookshelf has fixed it's previous attr handling, see https://github.com/bookshelf/bookshelf/pull/1848
- SQlite3 double slashes was merged into knex and released 👻tgriesser/knex@c746dea
This commit is contained in:
Katharina Irrgang 2019-01-21 21:53:11 +01:00 committed by GitHub
parent d70ec449bc
commit 4acc375fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 122 deletions

View File

@ -14,7 +14,7 @@ _private.normalize = function normalize(options) {
url: `${urlService.utils.urlJoin(apiUrl, 'schedules', 'posts', object.get('id'))}?client_id=${client.get('slug')}&client_secret=${client.get('secret')}`,
extra: {
httpMethod: 'PUT',
oldTime: object.updated('published_at') ? moment(object.updated('published_at')).valueOf() : null
oldTime: object.previous('published_at') ? moment(object.previous('published_at')).valueOf() : null
}
};
};

View File

@ -161,7 +161,7 @@ posts = {
// If previously was not published and now is (or vice versa), signal the change
// @TODO: `statusChanged` get's added for the API headers only. Reconsider this.
post.statusChanged = false;
if (model.updated('status') !== model.get('status')) {
if (model.previous('status') !== model.get('status')) {
post.statusChanged = true;
}

View File

@ -132,9 +132,9 @@ module.exports = {
return models.Post.edit(frame.data.posts[0], frame.options)
.then((model) => {
if (model.get('status') === 'published' ||
model.get('status') === 'draft' && model.updated('status') === 'published') {
model.get('status') === 'draft' && model.previous('status') === 'published') {
this.headers.cacheInvalidate = true;
} else if (model.get('status') === 'draft' && model.updated('status') !== 'published') {
} else if (model.get('status') === 'draft' && model.previous('status') !== 'published') {
this.headers.cacheInvalidate = {
value: urlService.utils.urlFor({
relativeUrl: urlService.utils.urlJoin('/p', model.get('uuid'), '/')

View File

@ -117,8 +117,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
emitChange: function (model, event, options) {
debug(model.tableName, event);
const previousAttributes = model._previousAttributes;
if (!options.transacting) {
return common.events.emit(event, model, options);
}
@ -139,7 +137,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
}
_.each(this.ghostEvents, (ghostEvent) => {
model._previousAttributes = previousAttributes;
common.events.emit(ghostEvent, model, _.omit(options, 'transacting'));
});
@ -227,11 +224,9 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
}
},
onSaving: function onSaving(newObj) {
onSaving: function onSaving() {
// Remove any properties which don't belong on the model
this.attributes = this.pick(this.permittedAttributes());
// Store the previous attributes so we can tell what was updated later
this._updatedAttributes = newObj.previousAttributes();
},
/**
@ -471,27 +466,8 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
return proto.toJSON.call(this, options);
},
// Get attributes that have been updated (values before a .save() call)
updatedAttributes: function updatedAttributes() {
return this._updatedAttributes || {};
},
// Get a specific updated attribute value
updated: function updated(attr) {
return this.updatedAttributes()[attr];
},
/**
* There is difference between `updated` and `previous`:
* Depending on the hook (before or after writing into the db), both fields have a different meaning.
* e.g. onSaving -> before db write (has to use previous)
* onUpdated -> after db write (has to use updated)
*
* hasDateChanged('attr', {beforeWrite: true})
*/
hasDateChanged: function (attr, options) {
options = options || {};
return moment(this.get(attr)).diff(moment(options.beforeWrite ? this.previous(attr) : this.updated(attr))) !== 0;
hasDateChanged: function (attr) {
return moment(this.get(attr)).diff(moment(this.previous(attr))) !== 0;
},
/**
@ -574,7 +550,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
* - Bookshelf updates the model with the new client data via the `set` function
* - Bookshelf uses a simple `isEqual` function from lodash to detect real changes
* - .previous(attr) and .get(attr) returns false obviously
* - internally we use our `hasDateChanged` if we have to compare previous/updated dates
* - internally we use our `hasDateChanged` if we have to compare previous dates
* - but Bookshelf is not in our control for this case
*
* @IMPORTANT

View File

@ -57,7 +57,7 @@ common.events.on('settings.active_timezone.edited', function (settingModel, opti
options = _.merge({}, options, {context: {internal: true}});
var newTimezone = settingModel.attributes.value,
previousTimezone = settingModel._updatedAttributes.value,
previousTimezone = settingModel._previousAttributes.value,
timezoneOffsetDiff = moment.tz(previousTimezone).utcOffset() - moment.tz(newTimezone).utcOffset();
// CASE: TZ was updated, but did not change

View File

@ -72,14 +72,11 @@ Post = ghostBookshelf.Model.extend({
return filteredKeys;
},
emitChange: function emitChange(event, options) {
emitChange: function emitChange(event, options = {}) {
let eventToTrigger;
let resourceType = this.get('page') ? 'page' : 'post';
var resourceType = this.get('page') ? 'page' : 'post';
if (options.useUpdatedAttribute) {
resourceType = this.updated('page') ? 'page' : 'post';
} else if (options.usePreviousAttribute) {
if (options.usePreviousAttribute) {
resourceType = this.previous('page') ? 'page' : 'post';
}
@ -112,26 +109,26 @@ Post = ghostBookshelf.Model.extend({
},
onUpdated: function onUpdated(model, attrs, options) {
model.statusChanging = model.get('status') !== model.updated('status');
model.statusChanging = model.get('status') !== model.previous('status');
model.isPublished = model.get('status') === 'published';
model.isScheduled = model.get('status') === 'scheduled';
model.wasPublished = model.updated('status') === 'published';
model.wasScheduled = model.updated('status') === 'scheduled';
model.resourceTypeChanging = model.get('page') !== model.updated('page');
model.wasPublished = model.previous('status') === 'published';
model.wasScheduled = model.previous('status') === 'scheduled';
model.resourceTypeChanging = model.get('page') !== model.previous('page');
model.publishedAtHasChanged = model.hasDateChanged('published_at');
model.needsReschedule = model.publishedAtHasChanged && model.isScheduled;
// Handle added and deleted for post -> page or page -> post
if (model.resourceTypeChanging) {
if (model.wasPublished) {
model.emitChange('unpublished', Object.assign({useUpdatedAttribute: true}, options));
model.emitChange('unpublished', Object.assign({usePreviousAttribute: true}, options));
}
if (model.wasScheduled) {
model.emitChange('unscheduled', Object.assign({useUpdatedAttribute: true}, options));
model.emitChange('unscheduled', Object.assign({usePreviousAttribute: true}, options));
}
model.emitChange('deleted', Object.assign({useUpdatedAttribute: true}, options));
model.emitChange('deleted', Object.assign({usePreviousAttribute: true}, options));
model.emitChange('added', options);
if (model.isPublished) {
@ -733,8 +730,6 @@ Post = ghostBookshelf.Model.extend({
/**
* ### Edit
* Fetches and saves to Post. See model.Base.edit
*
* @extends ghostBookshelf.Model.edit to handle returning the full object and manage _updatedAttributes
* **See:** [ghostBookshelf.Model.edit](base.js.html#edit)
*/
edit: function edit(data, unfilteredOptions) {
@ -752,7 +747,7 @@ Post = ghostBookshelf.Model.extend({
.then((found) => {
if (found) {
// Pass along the updated attributes for checking status changes
found._updatedAttributes = post._updatedAttributes;
found._previousAttributes = post._previousAttributes;
return found;
}
});

View File

@ -67,7 +67,7 @@ User = ghostBookshelf.Model.extend({
},
onUpdated: function onUpdated(model, response, options) {
model.statusChanging = model.get('status') !== model.updated('status');
model.statusChanging = model.get('status') !== model.previous('status');
model.isActive = _.includes(activeStates, model.get('status'));
if (model.statusChanging) {
@ -953,6 +953,7 @@ User = ghostBookshelf.Model.extend({
var userWithEmail = users.find(function findUser(user) {
return user.get('email').toLowerCase() === email.toLowerCase();
});
if (userWithEmail) {
return userWithEmail;
}

View File

@ -128,7 +128,7 @@ class CollectionRouter extends ParentRouter {
_onTimezoneEdited(settingModel) {
const newTimezone = settingModel.attributes.value,
previousTimezone = settingModel._updatedAttributes.value;
previousTimezone = settingModel._previousAttributes.value;
if (newTimezone === previousTimezone) {
return;

View File

@ -101,7 +101,7 @@ describe('Models: listeners', function () {
eventsToRemember['settings.active_timezone.edited']({
attributes: {value: scope.newTimezone},
_updatedAttributes: {value: scope.oldTimezone}
_previousAttributes: {value: scope.oldTimezone}
});
(function retry() {
@ -158,7 +158,7 @@ describe('Models: listeners', function () {
eventsToRemember['settings.active_timezone.edited']({
attributes: {value: scope.newTimezone},
_updatedAttributes: {value: scope.oldTimezone}
_previousAttributes: {value: scope.oldTimezone}
});
(function retry() {
@ -215,7 +215,7 @@ describe('Models: listeners', function () {
eventsToRemember['settings.active_timezone.edited']({
attributes: {value: scope.newTimezone},
_updatedAttributes: {value: scope.oldTimezone}
_previousAttributes: {value: scope.oldTimezone}
});
(function retry() {
@ -280,7 +280,7 @@ describe('Models: listeners', function () {
eventsToRemember['settings.active_timezone.edited']({
attributes: {value: scope.newTimezone},
_updatedAttributes: {value: scope.oldTimezone}
_previousAttributes: {value: scope.oldTimezone}
});
models.Post.findAll.calledOnce.should.eql(false);
@ -315,7 +315,7 @@ describe('Models: listeners', function () {
it('no scheduled posts', function (done) {
eventsToRemember['settings.active_timezone.edited']({
attributes: {value: scope.newTimezone},
_updatedAttributes: {value: scope.oldTimezone}
_previousAttributes: {value: scope.oldTimezone}
});
models.Post.findAll({context: {internal: true}})

View File

@ -708,7 +708,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
}, _.merge({id: testUtils.DataGenerator.forKnex.posts[3].id}, testUtils.context.editor));
})
.then((post) => {
post.updated('title').should.eql(testUtils.DataGenerator.forKnex.posts[3].title);
post.previous('title').should.eql(testUtils.DataGenerator.forKnex.posts[3].title);
post.get('title').should.eql('change');
events.post.should.eql(['edited']);
@ -742,7 +742,7 @@ describe('Unit: models/post: uses database (@TODO: fix me)', function () {
}, _.merge({id: testUtils.DataGenerator.forKnex.posts[3].id}, testUtils.context.editor));
})
.then((post) => {
post.updated('title').should.eql('change');
post.previous('title').should.eql('change');
post.get('title').should.eql('change');
events.post.should.eql(['edited']);

View File

@ -190,7 +190,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
common.events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'},
_updatedAttributes: {value: 'Europe/London'}
_previousAttributes: {value: 'Europe/London'}
});
collectionRouter.emit.called.should.be.false();
@ -203,7 +203,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
common.events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'},
_updatedAttributes: {value: 'America/Los_Angeles'}
_previousAttributes: {value: 'America/Los_Angeles'}
});
collectionRouter.emit.called.should.be.false();
@ -218,7 +218,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
common.events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'},
_updatedAttributes: {value: 'Europe/London'}
_previousAttributes: {value: 'Europe/London'}
});
collectionRouter.emit.calledOnce.should.be.true();
@ -231,7 +231,7 @@ describe('UNIT - services/routing/CollectionRouter', function () {
common.events.on.args[0][1]({
attributes: {value: 'America/Los_Angeles'},
_updatedAttributes: {value: 'America/Los_Angeles'}
_previousAttributes: {value: 'America/Los_Angeles'}
});
collectionRouter.emit.called.should.be.false();

View File

@ -39,7 +39,7 @@
"bcryptjs": "2.4.3",
"bluebird": "3.5.3",
"body-parser": "1.18.3",
"bookshelf": "0.13.3",
"bookshelf": "0.14.2",
"bookshelf-relations": "0.2.1",
"brute-knex": "3.0.0",
"bson-objectid": "1.2.4",
@ -73,8 +73,8 @@
"jsonpath": "1.0.0",
"jsonwebtoken": "8.4.0",
"keypair": "1.0.1",
"knex": "0.14.6",
"knex-migrator": "3.2.4",
"knex": "0.16.3",
"knex-migrator": "3.2.5",
"lodash": "4.17.11",
"markdown-it": "8.4.2",
"markdown-it-footnote": "3.0.1",

View File

@ -576,17 +576,15 @@ bookshelf-relations@0.2.1:
ghost-ignition "2.9.2"
lodash "4.17.10"
bookshelf@0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/bookshelf/-/bookshelf-0.13.3.tgz#aa73d9159b6cac92830dc1ff37325490c3c6dfba"
bookshelf@0.14.2:
version "0.14.2"
resolved "https://registry.yarnpkg.com/bookshelf/-/bookshelf-0.14.2.tgz#4b50b47a1e3d0265a1bfc118fa2036ad6a7493f2"
dependencies:
babel-runtime "^6.26.0"
bluebird "^3.4.3"
chalk "^2.3.0"
colorette "^1.0.7"
create-error "~0.3.1"
inflection "^1.5.1"
inherits "~2.0.1"
lodash "^4.13.1"
lodash "^4.17.10"
boolbase@~1.0.0:
version "1.0.0"
@ -821,7 +819,7 @@ chalk@2.4.1:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
chalk@2.4.2, chalk@^2.0.0, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2, chalk@~2.4.1:
chalk@2.4.2, chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.1, chalk@^2.4.2, chalk@~2.4.1:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
dependencies:
@ -1010,6 +1008,10 @@ color@^3.1.0:
color-convert "^1.9.1"
color-string "^1.5.2"
colorette@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.0.7.tgz#7adf43c445ee63a541b4a4aef7d13f03df1e0cc0"
colormin@^1.0.5:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colormin/-/colormin-1.1.2.tgz#ea2f7420a72b96881a38aae59ec124a6f7298133"
@ -1356,7 +1358,7 @@ debug@^3.1.0:
dependencies:
ms "^2.1.1"
debug@^4.0.1, debug@^4.1.0:
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
dependencies:
@ -3621,23 +3623,23 @@ klaw@^1.0.0:
optionalDependencies:
graceful-fs "^4.1.9"
knex-migrator@3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/knex-migrator/-/knex-migrator-3.2.4.tgz#913661cd97504ace36d3acd42e5a577f5abad223"
knex-migrator@3.2.5:
version "3.2.5"
resolved "https://registry.yarnpkg.com/knex-migrator/-/knex-migrator-3.2.5.tgz#bf5649f5b3ca55d50d0dd634027863c9e10e408d"
dependencies:
bluebird "^3.4.6"
commander "2.15.1"
bluebird "^3.5.3"
commander "^2.19.0"
compare-ver "^2.0.2"
debug "^2.2.0"
ghost-ignition "2.9.2"
knex "https://github.com/kirrg001/knex/tarball/d979ee6fa9b979e3be6f867dff015fdbc1f574ba"
lodash "^4.16.4"
moment "^2.19.3"
debug "^4.1.1"
ghost-ignition "^2.9.6"
knex "^0.16.3"
lodash "^4.17.11"
moment "^2.23.0"
nconf "^0.10.0"
resolve "1.7.1"
resolve "^1.9.0"
optionalDependencies:
mysql "^2.11.1"
sqlite3 "^4.0.0"
mysql "^2.16.0"
sqlite3 "^4.0.6"
knex@0.14.6:
version "0.14.6"
@ -3662,7 +3664,7 @@ knex@0.14.6:
uuid "^3.2.1"
v8flags "^3.0.2"
knex@^0.16.2:
knex@0.16.3, knex@^0.16.2, knex@^0.16.3:
version "0.16.3"
resolved "https://registry.yarnpkg.com/knex/-/knex-0.16.3.tgz#ca9effd4973655f42b42132b9019b0bc6bd20644"
dependencies:
@ -3684,29 +3686,6 @@ knex@^0.16.2:
uuid "^3.3.2"
v8flags "^3.1.1"
"knex@https://github.com/kirrg001/knex/tarball/d979ee6fa9b979e3be6f867dff015fdbc1f574ba":
version "0.14.6"
resolved "https://github.com/kirrg001/knex/tarball/d979ee6fa9b979e3be6f867dff015fdbc1f574ba#31af3c65702c6d8fd459f5d68f6d0eaee27590a5"
dependencies:
babel-runtime "^6.26.0"
bluebird "^3.5.1"
chalk "2.3.2"
commander "^2.15.1"
debug "3.1.0"
inherits "~2.0.3"
interpret "^1.1.0"
liftoff "2.5.0"
lodash "^4.17.5"
minimist "1.2.0"
mkdirp "^0.5.1"
pg-connection-string "2.0.0"
readable-stream "2.3.6"
safe-buffer "^5.1.1"
tarn "^1.1.4"
tildify "1.2.0"
uuid "^3.2.1"
v8flags "^3.0.2"
lazy-cache@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@ -3915,7 +3894,7 @@ lodash@4.17.10:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
lodash@4.17.11, lodash@^4.13.1, lodash@^4.14.2, lodash@^4.16.4, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0, lodash@^4.7.0, lodash@^4.8.0, lodash@~4.17.10, lodash@~4.17.5:
lodash@4.17.11, lodash@^4.14.2, lodash@^4.16.4, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0, lodash@^4.7.0, lodash@^4.8.0, lodash@~4.17.10, lodash@~4.17.5:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
@ -4295,7 +4274,7 @@ moment-timezone@0.5.23:
dependencies:
moment ">= 2.9.0"
moment@2.23.0, "moment@>= 2.9.0", moment@^2.10.6, moment@^2.15.2, moment@^2.18.1, moment@^2.19.3:
moment@2.23.0, "moment@>= 2.9.0", moment@^2.10.6, moment@^2.15.2, moment@^2.18.1, moment@^2.19.3, moment@^2.23.0:
version "2.23.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.23.0.tgz#759ea491ac97d54bac5ad776996e2a58cc1bc225"
@ -4332,7 +4311,7 @@ mv@~2:
ncp "~2.0.0"
rimraf "~2.4.0"
mysql@2.16.0, mysql@^2.11.1:
mysql@2.16.0, mysql@^2.16.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/mysql/-/mysql-2.16.0.tgz#b23b22ab5de44fc2d5d32bd4f5af6653fc45e2ba"
dependencies:
@ -5611,13 +5590,7 @@ resolve@1.1.x, resolve@~1.1.0:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
resolve@1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
dependencies:
path-parse "^1.0.5"
resolve@^1.1.6, resolve@^1.1.7, resolve@^1.4.0:
resolve@^1.1.6, resolve@^1.1.7, resolve@^1.4.0, resolve@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06"
dependencies:
@ -6095,7 +6068,7 @@ sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
sqlite3@4.0.6, sqlite3@^4.0.0:
sqlite3@4.0.6, sqlite3@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-4.0.6.tgz#e587b583b5acc6cb38d4437dedb2572359c080ad"
dependencies: