From b4a204772dce0c2c4d4d07303a8640edeb326991 Mon Sep 17 00:00:00 2001 From: Eric Kelly Date: Tue, 21 Jul 2015 21:16:13 -0400 Subject: [PATCH] Update `Ember.deprecate` & `Ember.warn` calls to include required options --- packages/ember-data/lib/adapters/errors.js | 2 +- packages/ember-data/lib/main.js | 2 +- .../lib/serializers/embedded-records-mixin.js | 9 +++--- .../lib/serializers/rest-serializer.js | 10 +++++-- packages/ember-data/lib/system/adapter.js | 4 +-- .../ember-data/lib/system/container-proxy.js | 6 ++-- .../lib/system/relationships/belongs-to.js | 15 ++++++++-- .../lib/system/relationships/ext.js | 9 ++++-- .../relationships/state/relationship.js | 5 +++- packages/ember-data/lib/system/store.js | 29 +++++++++++-------- 10 files changed, 62 insertions(+), 29 deletions(-) diff --git a/packages/ember-data/lib/adapters/errors.js b/packages/ember-data/lib/adapters/errors.js index c9b9df5ff72..b803094e073 100644 --- a/packages/ember-data/lib/adapters/errors.js +++ b/packages/ember-data/lib/adapters/errors.js @@ -79,7 +79,7 @@ AdapterError.prototype = Object.create(EmberError.prototype); */ export function InvalidError(errors) { if (!Ember.isArray(errors)) { - Ember.deprecate('`InvalidError` expects json-api formatted errors.'); + Ember.deprecate('`InvalidError` expects json-api formatted errors.', false, { id: 'ds.errors.invalid-error-expects-json-api-format', until: '3.0.0' }); errors = errorsHashToArray(errors); } AdapterError.call(this, errors, 'The adapter rejected the commit because it was invalid'); diff --git a/packages/ember-data/lib/main.js b/packages/ember-data/lib/main.js index 2654bb93d10..c730e016b70 100644 --- a/packages/ember-data/lib/main.js +++ b/packages/ember-data/lib/main.js @@ -158,7 +158,7 @@ var _FixtureAdapter = FixtureAdapter; Object.defineProperty(DS, 'FixtureAdapter', { get: function() { if (_FixtureAdapter === FixtureAdapter) { - Ember.deprecate('DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master'); + Ember.deprecate('DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master', false, { id: 'ds.adapter.fixture-adapter-deprecated', until: '3.0.0' }); } return _FixtureAdapter; }, diff --git a/packages/ember-data/lib/serializers/embedded-records-mixin.js b/packages/ember-data/lib/serializers/embedded-records-mixin.js index 234d8c06b6d..c42b1d97777 100644 --- a/packages/ember-data/lib/serializers/embedded-records-mixin.js +++ b/packages/ember-data/lib/serializers/embedded-records-mixin.js @@ -315,10 +315,11 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({ key = this.keyForAttribute(attr, 'serialize'); hasMany = snapshot.hasMany(attr); - Ember.warn("The embedded relationship '" + key + "' is undefined for '" + - snapshot.modelName + - "' with id '" + snapshot.id + - "'. Please include it in your original payload.", Ember.typeOf(hasMany) !== 'undefined'); + Ember.warn( + `The embedded relationship '${key}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`, + Ember.typeOf(hasMany) !== 'undefined', + { id: 'ds.serializer.embedded-relationship-undefined', until: '3.0.0' } + ); json[key] = Ember.A(hasMany).map((embeddedSnapshot) => { var embeddedJson = embeddedSnapshot.record.serialize({ includeId: true }); diff --git a/packages/ember-data/lib/serializers/rest-serializer.js b/packages/ember-data/lib/serializers/rest-serializer.js index 768bdcd1f8e..1524bc5d7ca 100644 --- a/packages/ember-data/lib/serializers/rest-serializer.js +++ b/packages/ember-data/lib/serializers/rest-serializer.js @@ -216,7 +216,10 @@ var RESTSerializer = JSONSerializer.extend({ var typeName = this.modelNameFromPayloadKey(modelName); if (!store.modelFactoryFor(typeName)) { - Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false); + Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false, { + id: 'ds.serializer.model-for-key-missing', + until: '3.0.0' + }); continue; } @@ -334,7 +337,10 @@ var RESTSerializer = JSONSerializer.extend({ for (var prop in payload) { var modelName = this.modelNameFromPayloadKey(prop); if (!store.modelFactoryFor(modelName)) { - Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false); + Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false, { + id: 'ds.serializer.model-for-key-missing', + until: '3.0.0' + }); continue; } var type = store.modelFor(modelName); diff --git a/packages/ember-data/lib/system/adapter.js b/packages/ember-data/lib/system/adapter.js index 98c5f7bbd91..2386fd600d0 100644 --- a/packages/ember-data/lib/system/adapter.js +++ b/packages/ember-data/lib/system/adapter.js @@ -483,7 +483,7 @@ var Adapter = Ember.Object.extend({ */ shouldReloadAll: function(store, snapshotRecordArray) { var modelName = snapshotRecordArray.type.modelName; - Ember.deprecate(`The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "${modelName}" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.`); + Ember.deprecate(`The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "${modelName}" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.`, false, { id: 'ds.adapter.should-reload-all-default-behavior', until: '3.0.0' }); return true; }, @@ -504,7 +504,7 @@ var Adapter = Ember.Object.extend({ @return {Boolean} */ shouldBackgroundReloadRecord: function(store, snapshot) { - Ember.deprecate('The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false.'); + Ember.deprecate('The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false.', false, { id: 'ds.adapter.should-background-reload-record-default-behavior', until: '3.0.0' }); return false; }, diff --git a/packages/ember-data/lib/system/container-proxy.js b/packages/ember-data/lib/system/container-proxy.js index 02b5dedb255..701053a8b07 100644 --- a/packages/ember-data/lib/system/container-proxy.js +++ b/packages/ember-data/lib/system/container-proxy.js @@ -28,8 +28,10 @@ ContainerProxy.prototype.registerAlias = function(source, dest, preLookup) { ContainerProxy.prototype.registerDeprecation = function(deprecated, valid) { var preLookupCallback = function() { - Ember.deprecate("You tried to look up '" + deprecated + "', " + - "but this has been deprecated in favor of '" + valid + "'.", false); + Ember.deprecate(`You tried to look up '${deprecated}', but this has been deprecated in favor of '${valid}'.`, false, { + id: 'ds.store.deprecated-lookup', + until: '3.0.0' + }); }; return this.registerAlias(deprecated, valid, preLookupCallback); diff --git a/packages/ember-data/lib/system/relationships/belongs-to.js b/packages/ember-data/lib/system/relationships/belongs-to.js index d052b4ee14b..0cb1bf6e352 100644 --- a/packages/ember-data/lib/system/relationships/belongs-to.js +++ b/packages/ember-data/lib/system/relationships/belongs-to.js @@ -101,8 +101,19 @@ function belongsTo(modelName, options) { return Ember.computed({ get: function(key) { - Ember.warn('You provided a serialize option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.Serializer and it\'s implementations http://emberjs.com/api/data/classes/DS.Serializer.html', !opts.hasOwnProperty('serialize')); - Ember.warn('You provided an embedded option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html', !opts.hasOwnProperty('embedded')); + if (opts.hasOwnProperty('serialize')) { + Ember.warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, { + id: 'ds.model.serialize-option-in-belongs-to', + until: '3.0.0' + }); + } + + if (opts.hasOwnProperty('embedded')) { + Ember.warn(`You provided an embedded option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html`, false, { + id: 'ds.model.embedded-option-in-belongs-to', + until: '3.0.0' + }); + } return this._internalModel._relationships.get(key).getRecord(); }, diff --git a/packages/ember-data/lib/system/relationships/ext.js b/packages/ember-data/lib/system/relationships/ext.js index a740cad4952..1605909a83f 100644 --- a/packages/ember-data/lib/system/relationships/ext.js +++ b/packages/ember-data/lib/system/relationships/ext.js @@ -243,8 +243,6 @@ Model.reopenClass({ var inverseName, inverseKind, inverse; - Ember.warn("Detected a reflexive relationship by the name of '" + name + "' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.", options.inverse || propertyMeta.type !== propertyMeta.parentType.modelName); - //If inverse is specified manually, return the inverse if (options.inverse) { inverseName = options.inverse; @@ -256,6 +254,13 @@ Model.reopenClass({ inverseKind = inverse.kind; } else { //No inverse was specified manually, we need to use a heuristic to guess one + if (propertyMeta.type === propertyMeta.parentType.modelName) { + Ember.warn(`Detected a reflexive relationship by the name of '${name}' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.`, false, { + id: 'ds.model.reflexive-relationship-without-inverse', + until: '3.0.0' + }); + } + var possibleRelationships = findPossibleInverses(this, inverseType); if (possibleRelationships.length === 0) { return null; } diff --git a/packages/ember-data/lib/system/relationships/state/relationship.js b/packages/ember-data/lib/system/relationships/state/relationship.js index 6b3a8682948..aece97f7f4c 100644 --- a/packages/ember-data/lib/system/relationships/state/relationship.js +++ b/packages/ember-data/lib/system/relationships/state/relationship.js @@ -183,7 +183,10 @@ Relationship.prototype = { }, updateLink: function(link) { - Ember.warn("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the association is not an async relationship.", this.isAsync); + Ember.warn(`You have pushed a record of type '${this.record.type.modelName}' with '${this.key}' as a link, but the association is not an async relationship.`, this.isAsync, { + id: 'ds.store.push-link-for-sync-relationship', + until: '3.0.0' + }); Ember.assert("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the value of that link is not a string.", typeof link === 'string' || link === null); if (link !== this.link) { this.link = link; diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 5c77608ba02..8debf3633fd 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -662,7 +662,10 @@ Store = Service.extend({ resolvedRecords = Ember.A(resolvedRecords); var missingRecords = requestedRecords.reject((record) => resolvedRecords.contains(record)); if (missingRecords.length) { - Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false); + Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false, { + id: 'ds.store.missing-records-from-adapter', + until: '3.0.0' + }); } rejectRecords(missingRecords); }; @@ -1168,7 +1171,9 @@ Store = Service.extend({ if (!Ember.ENV.ENABLE_DS_FILTER) { Ember.deprecate('The filter API will be moved into a plugin soon. To enable store.filter using an environment flag, or to use an alternative, you can visit the ember-data-filter addon page', false, { - url: 'https://github.com/ember-data/ember-data-filter' + url: 'https://github.com/ember-data/ember-data-filter', + id: 'ds.store.filter-deprecated', + until: '3.0.0' }); } @@ -1622,7 +1627,8 @@ Store = Service.extend({ })) + ". Make sure they've been defined in your model.", Object.keys(data).filter((key) => { return !(key === 'id' || key === 'links' || get(type, 'fields').has(key) || key.match(/Type$/)); - }).length === 0 + }).length === 0, + { id: 'ds.store.unknown-keys-in-payload', until: '3.0.0' } ); } @@ -1839,12 +1845,11 @@ Store = Service.extend({ adapterFor: function(modelOrClass) { var modelName; - Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelOrClass === 'string'); - - if (typeof modelOrClass !== 'string') { - modelName = modelOrClass.modelName; - } else { + if (typeof modelOrClass === 'string') { modelName = modelOrClass; + } else { + Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, false, { id: 'ds.store.passing-classes-deprecated', until: '3.0.0' }); + modelName = modelOrClass.modelName; } return this.lookupAdapter(modelName); @@ -1882,11 +1887,11 @@ Store = Service.extend({ serializerFor: function(modelOrClass) { var modelName; - Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelOrClass)}`, typeof modelOrClass === 'string'); - if (typeof modelOrClass !== 'string') { - modelName = modelOrClass.modelName; - } else { + if (typeof modelOrClass === 'string') { modelName = modelOrClass; + } else { + Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, false, { id: 'ds.store.passing-classes-deprecated', until: '3.0.0' }); + modelName = modelOrClass.modelName; } var fallbacks = [