From 136a99e89662021440709534659bba6d86202072 Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Sun, 4 Sep 2022 22:46:26 +0200 Subject: [PATCH 1/2] Change ember-data import to @ember-data --- .eslintrc.js | 2 +- addon/adapters/base.js | 4 +--- addon/initializers/local-storage-adapter.js | 6 +++--- addon/serializers/serializer.js | 8 +++++--- tests/dummy/app/models/blog/post.js | 4 +--- tests/dummy/app/models/book-publication.js | 4 +--- tests/dummy/app/models/comment.js | 4 +--- tests/dummy/app/models/pet.js | 4 +--- tests/dummy/app/models/post.js | 4 +--- tests/dummy/app/models/project.js | 4 +--- tests/dummy/app/models/task.js | 4 +--- tests/dummy/app/models/user.js | 4 +--- tests/unit/adapters/application-test.js | 6 +++--- tests/unit/models/post-test.js | 8 +++++--- 14 files changed, 26 insertions(+), 40 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f488b51..4d5aa1a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,7 @@ module.exports = { 'ember/no-mixins': 'off', 'ember/no-new-mixins': 'off', 'ember/no-string-prototype-extensions': 'off', - 'ember/use-ember-data-rfc-395-imports': 'off', + // 'ember/use-ember-data-rfc-395-imports': 'off', }, overrides: [ // node files diff --git a/addon/adapters/base.js b/addon/adapters/base.js index 54b19e9..75c4621 100644 --- a/addon/adapters/base.js +++ b/addon/adapters/base.js @@ -3,14 +3,12 @@ import RSVP from 'rsvp'; import { run } from '@ember/runloop'; import { isEmpty, typeOf } from '@ember/utils'; import { computed, get } from '@ember/object'; -import DS from 'ember-data'; +import JSONAPIAdapter from '@ember-data/adapter/json-api'; import ImportExportMixin from '../mixins/adapters/import-export'; import { _buildKey } from '../helpers/storage'; const getKeys = Object.keys || keys; -const { JSONAPIAdapter } = DS; - // Ember data ships with ember-inflector import { singularize, pluralize } from 'ember-inflector'; diff --git a/addon/initializers/local-storage-adapter.js b/addon/initializers/local-storage-adapter.js index dfb1cb9..d1ea4de 100644 --- a/addon/initializers/local-storage-adapter.js +++ b/addon/initializers/local-storage-adapter.js @@ -1,12 +1,12 @@ -import DS from 'ember-data'; +import Store from '@ember-data/store'; import { importData, exportData, } from 'ember-local-storage/helpers/import-export'; export function initialize() { - if (!DS.Store.prototype._emberLocalStoragePatched) { - DS.Store.reopen({ + if (!Store.prototype._emberLocalStoragePatched) { + Store.reopen({ _emberLocalStoragePatched: true, importData: function (json, options) { return importData(this, json, options); diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js index 88754f4..cda28a0 100644 --- a/addon/serializers/serializer.js +++ b/addon/serializers/serializer.js @@ -1,7 +1,9 @@ -import DS from 'ember-data'; - -const { JSONAPISerializer } = DS; +import JSONAPISerializer from '@ember-data/serializer/json-api'; +import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports +// Should be removed +// https://github.com/emberjs/data/pull/5317 +// https://github.com/emberjs/data/pull/5324 const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/); export default JSONAPISerializer.extend({ diff --git a/tests/dummy/app/models/blog/post.js b/tests/dummy/app/models/blog/post.js index 79f1381..4b8af4f 100644 --- a/tests/dummy/app/models/blog/post.js +++ b/tests/dummy/app/models/blog/post.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, belongsTo, hasMany } = DS; +import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/book-publication.js b/tests/dummy/app/models/book-publication.js index 61e9ca3..dd02d97 100644 --- a/tests/dummy/app/models/book-publication.js +++ b/tests/dummy/app/models/book-publication.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, hasMany } = DS; +import Model, { attr, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/comment.js b/tests/dummy/app/models/comment.js index a2efedd..19195f3 100644 --- a/tests/dummy/app/models/comment.js +++ b/tests/dummy/app/models/comment.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, belongsTo } = DS; +import Model, { attr, belongsTo } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/pet.js b/tests/dummy/app/models/pet.js index 47e64a9..7aff595 100644 --- a/tests/dummy/app/models/pet.js +++ b/tests/dummy/app/models/pet.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, hasMany } = DS; +import Model, { attr, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/post.js b/tests/dummy/app/models/post.js index 3751d6f..e8bc0b7 100644 --- a/tests/dummy/app/models/post.js +++ b/tests/dummy/app/models/post.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, belongsTo, hasMany } = DS; +import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/project.js b/tests/dummy/app/models/project.js index d4ddfe3..3a274c0 100644 --- a/tests/dummy/app/models/project.js +++ b/tests/dummy/app/models/project.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, hasMany } = DS; +import Model, { attr, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/task.js b/tests/dummy/app/models/task.js index b4ad983..8719132 100644 --- a/tests/dummy/app/models/task.js +++ b/tests/dummy/app/models/task.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, belongsTo, hasMany } = DS; +import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/dummy/app/models/user.js b/tests/dummy/app/models/user.js index 5f9bc7f..e438f6f 100644 --- a/tests/dummy/app/models/user.js +++ b/tests/dummy/app/models/user.js @@ -1,6 +1,4 @@ -import DS from 'ember-data'; - -const { Model, attr, hasMany } = DS; +import Model, { attr, hasMany } from '@ember-data/model'; export default Model.extend({ name: attr('string'), diff --git a/tests/unit/adapters/application-test.js b/tests/unit/adapters/application-test.js index d774b66..d8e471a 100644 --- a/tests/unit/adapters/application-test.js +++ b/tests/unit/adapters/application-test.js @@ -1,9 +1,9 @@ -import { run } from '@ember/runloop'; -import DS from 'ember-data'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -const { AdapterError, Model, attr } = DS; +import { run } from '@ember/runloop'; +import Model, { attr } from '@ember-data/model'; +import AdapterError from '@ember-data/adapter/error'; let SimpleModel = Model.extend({ prop: attr('string'), diff --git a/tests/unit/models/post-test.js b/tests/unit/models/post-test.js index 972d09d..e2c1665 100644 --- a/tests/unit/models/post-test.js +++ b/tests/unit/models/post-test.js @@ -1,8 +1,10 @@ -import { get } from '@ember/object'; -import { run } from '@ember/runloop'; -import DS from 'ember-data'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; + +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports + import { registerConfigEnvironment, setConfigEnvironment, From 68fab3d1a356b16b0ab0e47f18df921295316724 Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Sun, 4 Sep 2022 23:02:55 +0200 Subject: [PATCH 2/2] Always overwrite serializeBelongsTo and serializeHasMany --- .eslintrc.js | 1 - addon/serializers/serializer.js | 30 +++++------------------------- tests/unit/models/post-test.js | 8 ++------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4d5aa1a..4867cf1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,6 @@ module.exports = { 'ember/no-mixins': 'off', 'ember/no-new-mixins': 'off', 'ember/no-string-prototype-extensions': 'off', - // 'ember/use-ember-data-rfc-395-imports': 'off', }, overrides: [ // node files diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js index cda28a0..df865ff 100644 --- a/addon/serializers/serializer.js +++ b/addon/serializers/serializer.js @@ -1,36 +1,16 @@ import JSONAPISerializer from '@ember-data/serializer/json-api'; -import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports - -// Should be removed -// https://github.com/emberjs/data/pull/5317 -// https://github.com/emberjs/data/pull/5324 -const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/); export default JSONAPISerializer.extend({ - // Serialization behavior - // Can be removed (_shouldSerializeHasMany) removed in ember data 3.0.0 - // https://github.com/emberjs/data/pull/5290 - _shouldSerializeHasMany: function () { - return true; - }, - shouldSerializeHasMany: function () { + shouldSerializeHasMany() { return true; }, - serializeBelongsTo(snapshot, json, relationship) { - if (emberDataVersionOlderThan3Point1) { - this._super.apply(this, arguments); - } else { - this._fixSerializeBelongsTo(snapshot, json, relationship); - } + serializeBelongsTo() { + this._fixSerializeBelongsTo(...arguments); }, - serializeHasMany(snapshot, json, relationship) { - if (emberDataVersionOlderThan3Point1) { - this._super.apply(this, arguments); - } else { - this._fixSerializeHasMany(snapshot, json, relationship); - } + serializeHasMany() { + this._fixSerializeHasMany(...arguments); }, _fixSerializeBelongsTo(snapshot, json, relationship) { diff --git a/tests/unit/models/post-test.js b/tests/unit/models/post-test.js index e2c1665..c7f814b 100644 --- a/tests/unit/models/post-test.js +++ b/tests/unit/models/post-test.js @@ -3,7 +3,6 @@ import { setupTest } from 'ember-qunit'; import { get } from '@ember/object'; import { run } from '@ember/runloop'; -import DS from 'ember-data'; // eslint-disable-line ember/use-ember-data-rfc-395-imports import { registerConfigEnvironment, @@ -196,11 +195,7 @@ module('Unit | Model | post', function (hooks) { store .queryRecord('post', { filter: { name: 'Super Name' } }) .then(function (post) { - if (DS.VERSION.match(/^1\.13\./) || DS.VERSION.match(/^2\.[0|1]\./)) { - assert.deepEqual(post, []); - } else { - assert.equal(post, null); - } + assert.equal(post, null); done(); }) @@ -209,6 +204,7 @@ module('Unit | Model | post', function (hooks) { false, 'queryRecord on empty store throws error: ' + error.message ); + done(); }); });