From 73094453411388c2efae64910b0de436d22a6c01 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 13 Sep 2019 15:41:40 -0700 Subject: [PATCH 1/8] [CHORE]: Eliminate default injections in favor of re-export --- packages/-ember-data/app/adapters/-default.js | 1 + packages/-ember-data/app/adapters/-json-api.js | 1 + packages/-ember-data/app/adapters/-rest.js | 1 + 3 files changed, 3 insertions(+) create mode 100644 packages/-ember-data/app/adapters/-default.js create mode 100644 packages/-ember-data/app/adapters/-json-api.js create mode 100644 packages/-ember-data/app/adapters/-rest.js diff --git a/packages/-ember-data/app/adapters/-default.js b/packages/-ember-data/app/adapters/-default.js new file mode 100644 index 00000000000..2cbb7cd7057 --- /dev/null +++ b/packages/-ember-data/app/adapters/-default.js @@ -0,0 +1 @@ +export { default } from '@ember-data/adapter/json-api'; diff --git a/packages/-ember-data/app/adapters/-json-api.js b/packages/-ember-data/app/adapters/-json-api.js new file mode 100644 index 00000000000..2cbb7cd7057 --- /dev/null +++ b/packages/-ember-data/app/adapters/-json-api.js @@ -0,0 +1 @@ +export { default } from '@ember-data/adapter/json-api'; diff --git a/packages/-ember-data/app/adapters/-rest.js b/packages/-ember-data/app/adapters/-rest.js new file mode 100644 index 00000000000..0eb4bcda72e --- /dev/null +++ b/packages/-ember-data/app/adapters/-rest.js @@ -0,0 +1 @@ +export { default } from '@ember-data/adapter/rest'; From 7cc11d5bb5c18d7c649d8c8a81987fac3a0a4ff7 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 13 Sep 2019 17:18:16 -0700 Subject: [PATCH 2/8] remove registration in setup container --- packages/-ember-data/addon/setup-container.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/-ember-data/addon/setup-container.js b/packages/-ember-data/addon/setup-container.js index 53598665488..30bf68ccbb6 100644 --- a/packages/-ember-data/addon/setup-container.js +++ b/packages/-ember-data/addon/setup-container.js @@ -28,8 +28,6 @@ function initializeStore(application) { registerOptionsForType.call(application, 'serializer', { singleton: false }); registerOptionsForType.call(application, 'adapter', { singleton: false }); - application.register('adapter:-json-api', JSONAPIAdapter); - if (!hasRegistration(application, 'service:store')) { application.register('service:store', Store); } From 7dde0ca6d11dc783654dfdd640d2918c484b463e Mon Sep 17 00:00:00 2001 From: snewcomer Date: Sat, 14 Sep 2019 00:40:42 -0700 Subject: [PATCH 3/8] add debug blocks --- .../store/addon/-private/system/core-store.ts | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 258c74ebcbd..a34af4d0cf1 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -100,10 +100,10 @@ type PendingSaveItem = { let globalClientIdCounter = 1; const HAS_SERIALIZER_PACKAGE = has('@ember-data/serializer'); +const HAS_ADAPTER_PACKAGE = has('@ember-data/adapter'); -function deprecateTestRegistration(factoryType: 'serializer', factoryName: '-json-api' | '-rest' | '-default'): void; -// TODO add adapter here and deprecate those registrations as well after refactoring them to re-exports -function deprecateTestRegistration(factoryType: 'serializer', factoryName: '-json-api' | '-rest' | '-default'): void { +function deprecateTestRegistration(factoryType: 'serializer' | 'adapter', factoryName: '-json-api' | '-rest' | '-default'): void; +function deprecateTestRegistration(factoryType: 'serializer' | 'adapter', factoryName: '-json-api' | '-rest' | '-default'): void { deprecate( `You looked up the ${factoryType} "${factoryName}" but it was not found. Likely this means you are using a legacy ember-qunit moduleFor helper. Add "needs: ['${factoryType}:${factoryName}']", "integration: true", or refactor to modern syntax to resolve this deprecation.`, false, @@ -3220,6 +3220,27 @@ abstract class CoreStore extends Service { let owner = getOwner(this); adapter = owner.lookup(`adapter:${normalizedModelName}`); + + // in production this is handled by the re-export + if (DEBUG && HAS_ADAPTER_PACKAGE && adapter === undefined) { + if (normalizedModelName === '-json-api') { + const Adapter = require('@ember-data/adapter/json-api').default; + owner.register(`adapter:-json-api`, Adapter); + adapter = owner.lookup(`adapter:-json-api`); + deprecateTestRegistration('adapter', '-json-api'); + } else if (normalizedModelName === '-rest') { + const Adapter = require('@ember-data/adapter/rest').default; + owner.register(`adapter:-rest`, Adapter); + adapter = owner.lookup(`adapter:-rest`); + deprecateTestRegistration('adapter', '-rest'); + } else if (normalizedModelName === '-default') { + const Adapter = require('@ember-data/adapter/json-api').default; + owner.register(`adapter:-default`, Adapter); + adapter = owner.lookup(`adapter:-default`); + adapter && deprecateTestRegistration('adapter', '-default'); + } + } + if (adapter !== undefined) { set(adapter, 'store', this); _adapterCache[normalizedModelName] = adapter; @@ -3239,6 +3260,27 @@ abstract class CoreStore extends Service { // property defined on the store let adapterName = this.adapter || '-json-api'; adapter = adapterName ? _adapterCache[adapterName] || owner.lookup(`adapter:${adapterName}`) : undefined; + + // in production this is handled by the re-export + if (DEBUG && HAS_ADAPTER_PACKAGE && adapter === undefined) { + if (adapterName === '-json-api') { + const Adapter = require('@ember-data/adapter/json-api').default; + owner.register(`adapter:-json-api`, Adapter); + adapter = owner.lookup(`adapter:-json-api`); + deprecateTestRegistration('adapter', '-json-api'); + } else if (adapterName === '-rest') { + const Adapter = require('@ember-data/adapter/rest').default; + owner.register(`adapter:-rest`, Adapter); + adapter = owner.lookup(`adapter:-rest`); + deprecateTestRegistration('adapter', '-rest'); + } else if (adapterName === '-default') { + const Adapter = require('@ember-data/adapter/json-api').default; + owner.register(`adapter:-default`, Adapter); + adapter = owner.lookup(`adapter:-default`); + adapter && deprecateTestRegistration('adapter', '-default'); + } + } + if (adapter !== undefined) { set(adapter, 'store', this); _adapterCache[normalizedModelName] = adapter; @@ -3250,7 +3292,7 @@ abstract class CoreStore extends Service { // `adapter` property on store: use json-api adapter adapter = _adapterCache['-json-api'] || owner.lookup('adapter:-json-api'); assert( - `No adapter was found for '${modelName}' and no 'application', store.adapter = 'adapter-fallback-name', or '-json-api' adapter were found as fallbacks.`, + `No adapter was found for '${modelName}' and no 'application' adapter were found as a fallback.`, adapter !== undefined ); set(adapter, 'store', this); From e0bca0f3ac36f4f6c95298b1658e64dd370df631 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Sun, 15 Sep 2019 22:38:12 -0700 Subject: [PATCH 4/8] Fix tests --- .../integration/store/adapter-for-test.js | 20 +++++++++---------- .../integration/store/serializer-for-test.js | 3 +++ .../store/addon/-private/system/core-store.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/-ember-data/tests/integration/store/adapter-for-test.js b/packages/-ember-data/tests/integration/store/adapter-for-test.js index 0c729ae3896..c41971f83f5 100644 --- a/packages/-ember-data/tests/integration/store/adapter-for-test.js +++ b/packages/-ember-data/tests/integration/store/adapter-for-test.js @@ -26,22 +26,22 @@ module('integration/store - adapterFor', function(hooks) { test('when no adapter is available we throw an error', async function(assert) { let { owner } = this; - /* - ensure our store instance does not specify a fallback - we use an empty string as that would cause `owner.lookup` to blow up if not guarded properly - whereas `null` `undefined` `false` would not. - */ - store.adapter = ''; /* adapter:-json-api is the "last chance" fallback and is - registered automatically. - unregistering it will cause adapterFor to return `undefined`. + the json-api adapter which is re-exported as app/serializers/-default. + here we override to ensure adapterFor will return `undefined`. */ - owner.unregister('adapter:-json-api'); + const lookup = owner.lookup; + owner.lookup = registrationName => { + if (registrationName === 'adapter:-json-api') { + return undefined; + } + return lookup.call(owner, registrationName); + }; assert.expectAssertion(() => { store.adapterFor('person'); - }, /No adapter was found for 'person' and no 'application', store\.adapter = 'adapter-fallback-name', or '-json-api' adapter were found as fallbacks\./); + }, /Assertion Failed: No adapter was found for 'person' and no 'application' adapter was found as a fallback/); }); test('we find and instantiate the application adapter', async function(assert) { diff --git a/packages/-ember-data/tests/integration/store/serializer-for-test.js b/packages/-ember-data/tests/integration/store/serializer-for-test.js index dbcb6f2b806..3ad5127cd86 100644 --- a/packages/-ember-data/tests/integration/store/serializer-for-test.js +++ b/packages/-ember-data/tests/integration/store/serializer-for-test.js @@ -50,6 +50,9 @@ module('integration/store - serializerFor', function(hooks) { if (registrationName === 'serializer:-default') { return undefined; } + if (registrationName === 'serializer:-json-api') { + return undefined; + } return lookup.call(owner, registrationName); }; /* diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index a34af4d0cf1..095367489f0 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -3292,7 +3292,7 @@ abstract class CoreStore extends Service { // `adapter` property on store: use json-api adapter adapter = _adapterCache['-json-api'] || owner.lookup('adapter:-json-api'); assert( - `No adapter was found for '${modelName}' and no 'application' adapter were found as a fallback.`, + `No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`, adapter !== undefined ); set(adapter, 'store', this); From f5946f0f743a24a7fb95c838d5b8cdbd942c305e Mon Sep 17 00:00:00 2001 From: snewcomer Date: Wed, 18 Sep 2019 11:58:36 -0700 Subject: [PATCH 5/8] no need for these defaults --- packages/-ember-data/app/adapters/-default.js | 1 - packages/-ember-data/app/adapters/-rest.js | 1 - 2 files changed, 2 deletions(-) delete mode 100644 packages/-ember-data/app/adapters/-default.js delete mode 100644 packages/-ember-data/app/adapters/-rest.js diff --git a/packages/-ember-data/app/adapters/-default.js b/packages/-ember-data/app/adapters/-default.js deleted file mode 100644 index 2cbb7cd7057..00000000000 --- a/packages/-ember-data/app/adapters/-default.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from '@ember-data/adapter/json-api'; diff --git a/packages/-ember-data/app/adapters/-rest.js b/packages/-ember-data/app/adapters/-rest.js deleted file mode 100644 index 0eb4bcda72e..00000000000 --- a/packages/-ember-data/app/adapters/-rest.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from '@ember-data/adapter/rest'; From d8970416a48ef26471f9efd04f21e4786d0102b0 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Wed, 18 Sep 2019 12:07:03 -0700 Subject: [PATCH 6/8] overload deprecate tests --- packages/-ember-data/addon/setup-container.js | 1 - .../store/addon/-private/system/core-store.ts | 23 ++----------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/packages/-ember-data/addon/setup-container.js b/packages/-ember-data/addon/setup-container.js index 30bf68ccbb6..1ba6f23bd1e 100644 --- a/packages/-ember-data/addon/setup-container.js +++ b/packages/-ember-data/addon/setup-container.js @@ -1,6 +1,5 @@ import { DebugAdapter } from './-private'; import Store from '@ember-data/store'; -import JSONAPIAdapter from '@ember-data/adapter/json-api'; function hasRegistration(application, registrationName) { // fallback our ember-data tests necessary diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 095367489f0..baf782a7d6f 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -102,7 +102,8 @@ let globalClientIdCounter = 1; const HAS_SERIALIZER_PACKAGE = has('@ember-data/serializer'); const HAS_ADAPTER_PACKAGE = has('@ember-data/adapter'); -function deprecateTestRegistration(factoryType: 'serializer' | 'adapter', factoryName: '-json-api' | '-rest' | '-default'): void; +function deprecateTestRegistration(factoryType: 'adapter', factoryName: '-json-api'): void; +function deprecateTestRegistration(factoryType: 'serializer', factoryName: '-json-api' | '-rest' | '-default'): void; function deprecateTestRegistration(factoryType: 'serializer' | 'adapter', factoryName: '-json-api' | '-rest' | '-default'): void { deprecate( `You looked up the ${factoryType} "${factoryName}" but it was not found. Likely this means you are using a legacy ember-qunit moduleFor helper. Add "needs: ['${factoryType}:${factoryName}']", "integration: true", or refactor to modern syntax to resolve this deprecation.`, @@ -3228,16 +3229,6 @@ abstract class CoreStore extends Service { owner.register(`adapter:-json-api`, Adapter); adapter = owner.lookup(`adapter:-json-api`); deprecateTestRegistration('adapter', '-json-api'); - } else if (normalizedModelName === '-rest') { - const Adapter = require('@ember-data/adapter/rest').default; - owner.register(`adapter:-rest`, Adapter); - adapter = owner.lookup(`adapter:-rest`); - deprecateTestRegistration('adapter', '-rest'); - } else if (normalizedModelName === '-default') { - const Adapter = require('@ember-data/adapter/json-api').default; - owner.register(`adapter:-default`, Adapter); - adapter = owner.lookup(`adapter:-default`); - adapter && deprecateTestRegistration('adapter', '-default'); } } @@ -3268,16 +3259,6 @@ abstract class CoreStore extends Service { owner.register(`adapter:-json-api`, Adapter); adapter = owner.lookup(`adapter:-json-api`); deprecateTestRegistration('adapter', '-json-api'); - } else if (adapterName === '-rest') { - const Adapter = require('@ember-data/adapter/rest').default; - owner.register(`adapter:-rest`, Adapter); - adapter = owner.lookup(`adapter:-rest`); - deprecateTestRegistration('adapter', '-rest'); - } else if (adapterName === '-default') { - const Adapter = require('@ember-data/adapter/json-api').default; - owner.register(`adapter:-default`, Adapter); - adapter = owner.lookup(`adapter:-default`); - adapter && deprecateTestRegistration('adapter', '-default'); } } From 623fbb258d6b7d13c189556a5dbf7378ccebb2b1 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Wed, 18 Sep 2019 12:40:06 -0700 Subject: [PATCH 7/8] undo serializer test addition --- .../-ember-data/tests/integration/store/serializer-for-test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/-ember-data/tests/integration/store/serializer-for-test.js b/packages/-ember-data/tests/integration/store/serializer-for-test.js index 3ad5127cd86..dbcb6f2b806 100644 --- a/packages/-ember-data/tests/integration/store/serializer-for-test.js +++ b/packages/-ember-data/tests/integration/store/serializer-for-test.js @@ -50,9 +50,6 @@ module('integration/store - serializerFor', function(hooks) { if (registrationName === 'serializer:-default') { return undefined; } - if (registrationName === 'serializer:-json-api') { - return undefined; - } return lookup.call(owner, registrationName); }; /* From a3ef3a78d9094c215c11db7608030448bb8e29c2 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Wed, 18 Sep 2019 12:45:02 -0700 Subject: [PATCH 8/8] update comment --- .../-ember-data/tests/integration/store/adapter-for-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/-ember-data/tests/integration/store/adapter-for-test.js b/packages/-ember-data/tests/integration/store/adapter-for-test.js index c41971f83f5..a4db1ccd00d 100644 --- a/packages/-ember-data/tests/integration/store/adapter-for-test.js +++ b/packages/-ember-data/tests/integration/store/adapter-for-test.js @@ -28,7 +28,7 @@ module('integration/store - adapterFor', function(hooks) { let { owner } = this; /* adapter:-json-api is the "last chance" fallback and is - the json-api adapter which is re-exported as app/serializers/-default. + the json-api adapter which is re-exported as app/adapters/-json-api. here we override to ensure adapterFor will return `undefined`. */ const lookup = owner.lookup;