diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 4e175a6c871..cef4d14939c 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -29,7 +29,6 @@ import { promiseArray, promiseObject } from './promise-proxies'; import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './store/common'; import { normalizeResponseHelper } from './store/serializer-response'; -import { serializerForAdapter } from './store/serializers'; import recordDataFor from './record-data-for'; import FetchManager, { SaveOp } from './fetch-manager'; @@ -3342,14 +3341,14 @@ abstract class CoreStore extends Service { // no model specific serializer or application serializer, check for the `defaultSerializer` // property defined on the adapter - if (DEBUG) { - deprecate('deprecate adapter.serializer and adapter.defaultSerializer fallbacks', false, { - id: 'ember-data:default-serializers', - until: '4.0', - }); - } let adapter = this.adapterFor(modelName); let serializerName = get(adapter, 'defaultSerializer'); + + deprecate('deprecate adapter.serializer and adapter.defaultSerializer fallbacks', !serializerName, { + id: 'ember-data:default-serializers', + until: '4.0', + }); + serializer = serializerName ? _serializerCache[serializerName] || owner.lookup(`serializer:${serializerName}`) : undefined; @@ -3383,12 +3382,6 @@ abstract class CoreStore extends Service { // final fallback, no model specific serializer, no application serializer, no // `serializer` property on store: use json-api serializer - if (DEBUG) { - deprecate('deprecate -default serializer fallback in store.serializerFor', false, { - id: 'ember-data:default-serializers', - until: '4.0', - }); - } serializer = _serializerCache['-default'] || owner.lookup('serializer:-default'); if (DEBUG && HAS_SERIALIZER_PACKAGE && serializer === undefined) { const JSONSerializer = require('@ember-data/serializer/json').default; @@ -3398,6 +3391,11 @@ abstract class CoreStore extends Service { serializer && deprecateTestRegistration('serializer', '-default'); } + deprecate('deprecate -default serializer fallback in store.serializerFor', !serializer, { + id: 'ember-data:default-serializers', + until: '4.0', + }); + assert( `No serializer was found for '${modelName}' and no 'application' serializer was found as a fallback`, serializer !== undefined @@ -3491,12 +3489,14 @@ defineProperty( CoreStore.prototype, 'defaultAdapter', computed('adapter', function() { - if (DEBUG) { - deprecate('deprecate store.defaultAdapter (-json-api) and the -json-api adapter fallback behavior', false, { + deprecate( + 'deprecate store.adapter, store.defaultAdapter (-json-api) and the -json-api adapter fallback behavior', + false, + { id: 'ember-data:default-adapter', until: '4.0', - }); - } + } + ); let adapter = this.adapter || '-json-api'; assert( @@ -3521,7 +3521,7 @@ function _commit(adapter, store, operation, snapshot) { ); let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot)); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let label = `DS: Extract and notify about ${operation} completion of ${internalModel}`; assert( diff --git a/packages/store/addon/-private/system/fetch-manager.ts b/packages/store/addon/-private/system/fetch-manager.ts index 4d0e0e559b6..415a5f1f3f4 100644 --- a/packages/store/addon/-private/system/fetch-manager.ts +++ b/packages/store/addon/-private/system/fetch-manager.ts @@ -5,7 +5,6 @@ import { assert, warn, inspect } from '@ember/debug'; import Snapshot from './snapshot'; import { guardDestroyedStore, _guard, _bind, _objectIsAlive } from './store/common'; import { normalizeResponseHelper } from './store/serializer-response'; -import { serializerForAdapter } from './store/serializers'; import { InvalidError } from '@ember-data/adapter/error'; import coerceId from './coerce-id'; import { A } from '@ember/array'; @@ -115,7 +114,7 @@ export default class FetchManager { ); let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot)); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let label = `DS: Extract and notify about ${operation} completion of ${internalModel}`; assert( @@ -262,7 +261,7 @@ export default class FetchManager { `You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`, !!payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(this._store, adapter, modelName); + let serializer = this._store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, this._store, klass, adapterPayload, id, 'findRecord'); assert( `Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`, @@ -379,7 +378,7 @@ export default class FetchManager { `You made a 'findMany' request for '${modelName}' records with ids '[${ids}]', but the adapter's response did not have any data`, !!payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany'); return payload; }, diff --git a/packages/store/addon/-private/system/model/model.js b/packages/store/addon/-private/system/model/model.js index 82b630c7762..694ef5761d2 100644 --- a/packages/store/addon/-private/system/model/model.js +++ b/packages/store/addon/-private/system/model/model.js @@ -623,12 +623,10 @@ const Model = EmberObject.extend(DeprecatedEvented, { */ toJSON(options) { // container is for lazy transform lookups - if (DEBUG) { - deprecate('deprecate toJSON', false, { - id: 'ember-data:model.toJSON', - until: '4.0', - }); - } + deprecate('deprecate toJSON', false, { + id: 'ember-data:model.toJSON', + until: '4.0', + }); let serializer = this._internalModel.store.serializerFor('-default'); let snapshot = this._internalModel.createSnapshot(); diff --git a/packages/store/addon/-private/system/store/finders.js b/packages/store/addon/-private/system/store/finders.js index e617bbff31d..1f887c4b6cf 100644 --- a/packages/store/addon/-private/system/store/finders.js +++ b/packages/store/addon/-private/system/store/finders.js @@ -8,7 +8,6 @@ import coerceId from '../coerce-id'; import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './common'; import { normalizeResponseHelper } from './serializer-response'; -import { serializerForAdapter } from './serializers'; import { assign } from '@ember/polyfills'; import { IDENTIFIERS } from '@ember-data/canary-features'; import { REQUEST_SERVICE } from '@ember-data/canary-features'; @@ -45,7 +44,7 @@ export function _find(adapter, store, modelClass, id, internalModel, options) { `You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, id, 'findRecord'); assert( `Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`, @@ -97,7 +96,7 @@ export function _findMany(adapter, store, modelName, ids, internalModels, option `You made a 'findMany' request for '${modelName}' records with ids '[${ids}]', but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany'); return store._push(payload); }, @@ -280,7 +279,7 @@ export function _findHasMany(adapter, store, internalModel, link, relationship, `You made a 'findHasMany' request for a ${internalModel.modelName}'s '${relationship.key}' relationship, using link '${link}' , but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(store, adapter, relationship.type); + let serializer = store.serializerFor(relationship.type); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany'); syncRelationshipDataFromLink(store, payload, internalModel, relationship); @@ -305,7 +304,7 @@ export function _findBelongsTo(adapter, store, internalModel, link, relationship return promise.then( adapterPayload => { - let serializer = serializerForAdapter(store, adapter, relationship.type); + let serializer = store.serializerFor(relationship.type); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo'); if (!payload.data) { @@ -336,7 +335,7 @@ export function _findAll(adapter, store, modelName, options) { `You made a 'findAll' request for '${modelName}' records, but the adapter's response did not have any data`, payloadIsNotBlank(adapterPayload) ); - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findAll'); store._push(payload); @@ -360,7 +359,7 @@ export function _query(adapter, store, modelName, query, recordArray, options) { return promise.then( adapterPayload => { - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'query'); let internalModels = store._push(payload); @@ -395,7 +394,7 @@ export function _queryRecord(adapter, store, modelName, query, options) { return promise.then( adapterPayload => { - let serializer = serializerForAdapter(store, adapter, modelName); + let serializer = store.serializerFor(modelName); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'queryRecord'); assert( diff --git a/packages/store/addon/-private/system/store/serializers.js b/packages/store/addon/-private/system/store/serializers.js deleted file mode 100644 index d6269870e81..00000000000 --- a/packages/store/addon/-private/system/store/serializers.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - @module @ember-data/store -*/ - -export function serializerForAdapter(store, adapter, modelName) { - let serializer = adapter.serializer; - - if (serializer === undefined) { - serializer = store.serializerFor(modelName); - } - - return serializer; -}