diff --git a/packages/ember-data/lib/adapters.js b/packages/ember-data/lib/adapters.js index 4ad9bb43a6a..1f183d01049 100644 --- a/packages/ember-data/lib/adapters.js +++ b/packages/ember-data/lib/adapters.js @@ -2,12 +2,10 @@ @module ember-data */ -import FixtureAdapter from "ember-data/adapters/fixture-adapter"; import JSONAPIAdapter from "ember-data/adapters/json-api-adapter"; import RESTAdapter from "ember-data/adapters/rest-adapter"; export { - FixtureAdapter, JSONAPIAdapter, RESTAdapter }; diff --git a/packages/ember-data/lib/adapters/fixture-adapter.js b/packages/ember-data/lib/adapters/fixture-adapter.js deleted file mode 100644 index c0f6bc95faf..00000000000 --- a/packages/ember-data/lib/adapters/fixture-adapter.js +++ /dev/null @@ -1,319 +0,0 @@ -/** - @module ember-data -*/ -var get = Ember.get; -var fmt = Ember.String.fmt; - -var counter = 0; - -import Adapter from "ember-data/system/adapter"; - -/** - `DS.FixtureAdapter` is an adapter that loads records from memory. - It's primarily used for development and testing. You can also use - `DS.FixtureAdapter` while working on the API but is not ready to - integrate yet. It is a fully functioning adapter. All CRUD methods - are implemented. You can also implement query logic that a remote - system would do. It's possible to develop your entire application - with `DS.FixtureAdapter`. - - For information on how to use the `FixtureAdapter` in your - application please see the [FixtureAdapter - guide](/guides/models/the-fixture-adapter/). - - @class FixtureAdapter - @namespace DS - @extends DS.Adapter -*/ -export default Adapter.extend({ - // by default, fixtures are already in normalized form - serializer: null, - // The fixture adapter does not support coalesceFindRequests - coalesceFindRequests: false, - - /** - If `simulateRemoteResponse` is `true` the `FixtureAdapter` will - wait a number of milliseconds before resolving promises with the - fixture values. The wait time can be configured via the `latency` - property. - - @property simulateRemoteResponse - @type {Boolean} - @default true - */ - simulateRemoteResponse: true, - - /** - By default the `FixtureAdapter` will simulate a wait of the - `latency` milliseconds before resolving promises with the fixture - values. This behavior can be turned off via the - `simulateRemoteResponse` property. - - @property latency - @type {Number} - @default 50 - */ - latency: 50, - - /** - Implement this method in order to provide data associated with a type - - @method fixturesForType - @param {DS.Model} typeClass - @return {Array} - */ - fixturesForType: function(typeClass) { - if (typeClass.FIXTURES) { - return typeClass.FIXTURES.map((fixture) => { - var fixtureIdType = typeof fixture.id; - if (fixtureIdType !== "number" && fixtureIdType !== "string") { - throw new Error(fmt('the id property must be defined as a number or string for fixture %@', [fixture])); - } - fixture.id = fixture.id + ''; - return fixture; - }); - } - return null; - }, - - /** - Implement this method in order to query fixtures data - - @method queryFixtures - @param {Array} fixtures - @param {Object} query - @param {DS.Model} typeClass - @return {(Promise|Array)} - */ - queryFixtures: function(fixtures, query, typeClass) { - Ember.assert('Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.'); - }, - - /** - @method updateFixtures - @param {DS.Model} typeClass - @param {Array} fixture - */ - updateFixtures: function(typeClass, fixture) { - if (!typeClass.FIXTURES) { - typeClass.FIXTURES = []; - } - - var fixtures = typeClass.FIXTURES; - - this.deleteLoadedFixture(typeClass, fixture); - - fixtures.push(fixture); - }, - - /** - Implement this method in order to provide json for CRUD methods - - @method mockJSON - @param {DS.Store} store - @param {DS.Model} typeClass - @param {DS.Snapshot} snapshot - */ - mockJSON: function(store, typeClass, snapshot) { - return store.serializerFor(snapshot.modelName).serialize(snapshot, { includeId: true }); - }, - - /** - @method generateIdForRecord - @param {DS.Store} store - @return {String} id - */ - generateIdForRecord: function(store) { - return "fixture-" + counter++; - }, - - /** - @method find - @param {DS.Store} store - @param {DS.Model} typeClass - @param {String} id - @param {DS.Snapshot} snapshot - @return {Promise} promise - */ - find: function(store, typeClass, id, snapshot) { - var fixtures = this.fixturesForType(typeClass); - var fixture; - - Ember.assert("Unable to find fixtures for model type "+typeClass.toString() +". If you're defining your fixtures using `Model.FIXTURES = ...`, please change it to `Model.reopenClass({ FIXTURES: ... })`.", fixtures); - - if (fixtures) { - fixture = Ember.A(fixtures).findBy('id', id); - } - - if (fixture) { - return this.simulateRemoteCall(() => fixture); - } - }, - - /** - @method findMany - @param {DS.Store} store - @param {DS.Model} typeClass - @param {Array} ids - @param {Array} snapshots - @return {Promise} promise - */ - findMany: function(store, typeClass, ids, snapshots) { - var fixtures = this.fixturesForType(typeClass); - - Ember.assert("Unable to find fixtures for model type "+typeClass.toString(), fixtures); - - if (fixtures) { - fixtures = fixtures.filter((item) => ids.indexOf(item.id) !== -1); - } - - if (fixtures) { - return this.simulateRemoteCall(() => fixtures); - } - }, - - /** - @private - @method findAll - @param {DS.Store} store - @param {DS.Model} typeClass - @return {Promise} promise - */ - findAll: function(store, typeClass) { - var fixtures = this.fixturesForType(typeClass); - - Ember.assert("Unable to find fixtures for model type "+typeClass.toString(), fixtures); - - return this.simulateRemoteCall(() => fixtures); - }, - - /** - @private - @method findQuery - @param {DS.Store} store - @param {DS.Model} typeClass - @param {Object} query - @param {DS.AdapterPopulatedRecordArray} array - @return {Promise} promise - */ - findQuery: function(store, typeClass, query, array) { - var fixtures = this.fixturesForType(typeClass); - - Ember.assert("Unable to find fixtures for model type " + typeClass.toString(), fixtures); - - fixtures = this.queryFixtures(fixtures, query, typeClass); - - if (fixtures) { - return this.simulateRemoteCall(() => fixtures); - } - }, - - /** - @method createRecord - @param {DS.Store} store - @param {DS.Model} typeClass - @param {DS.Snapshot} snapshot - @return {Promise} promise - */ - createRecord: function(store, typeClass, snapshot) { - var fixture = this.mockJSON(store, typeClass, snapshot); - - this.updateFixtures(typeClass, fixture); - - return this.simulateRemoteCall(() => fixture); - }, - - /** - @method updateRecord - @param {DS.Store} store - @param {DS.Model} typeClass - @param {DS.Snapshot} snapshot - @return {Promise} promise - */ - updateRecord: function(store, typeClass, snapshot) { - var fixture = this.mockJSON(store, typeClass, snapshot); - - this.updateFixtures(typeClass, fixture); - - return this.simulateRemoteCall(() => fixture); - }, - - /** - @method deleteRecord - @param {DS.Store} store - @param {DS.Model} typeClass - @param {DS.Snapshot} snapshot - @return {Promise} promise - */ - deleteRecord: function(store, typeClass, snapshot) { - this.deleteLoadedFixture(typeClass, snapshot); - - return this.simulateRemoteCall(() => null); - }, - - /* - @method deleteLoadedFixture - @private - @param typeClass - @param snapshot - */ - deleteLoadedFixture: function(typeClass, snapshot) { - var existingFixture = this.findExistingFixture(typeClass, snapshot); - - if (existingFixture) { - var index = typeClass.FIXTURES.indexOf(existingFixture); - typeClass.FIXTURES.splice(index, 1); - return true; - } - }, - - /* - @method findExistingFixture - @private - @param typeClass - @param snapshot - */ - findExistingFixture: function(typeClass, snapshot) { - var fixtures = this.fixturesForType(typeClass); - var id = snapshot.id; - - return this.findFixtureById(fixtures, id); - }, - - /* - @method findFixtureById - @private - @param fixtures - @param id - */ - findFixtureById: function(fixtures, id) { - return Ember.A(fixtures).find((r) => { - if (''+get(r, 'id') === ''+id) { - return true; - } else { - return false; - } - }); - }, - - /* - @method simulateRemoteCall - @private - @param callback - @param context - */ - simulateRemoteCall: function(callback, context) { - var adapter = this; - - return new Ember.RSVP.Promise((resolve) => { - var value = Ember.copy(callback.call(context), true); - if (get(adapter, 'simulateRemoteResponse')) { - // Schedule with setTimeout - Ember.run.later(() => resolve(value), get(adapter, 'latency')); - } else { - // Asynchronous, but at the of the runloop with zero latency - Ember.run.schedule('actions', null, () => resolve(value)); - } - }, "DS: FixtureAdapter#simulateRemoteCall"); - } -}); diff --git a/packages/ember-data/lib/main.js b/packages/ember-data/lib/main.js index d9941960fe4..66cd76d463f 100644 --- a/packages/ember-data/lib/main.js +++ b/packages/ember-data/lib/main.js @@ -57,7 +57,6 @@ import { import ManyArray from "ember-data/system/many-array"; import RecordArrayManager from "ember-data/system/record-array-manager"; import { - FixtureAdapter, JSONAPIAdapter, RESTAdapter } from "ember-data/adapters"; @@ -153,23 +152,6 @@ Object.defineProperty(DS, 'normalizeModelName', { value: normalizeModelName }); -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', false, { - id: 'ds.adapter.fixture-adapter-deprecated', - until: '2.0.0' - }); - } - return _FixtureAdapter; - }, - set: function(FixtureAdapter) { - _FixtureAdapter = FixtureAdapter; - } -}); - Ember.lookup.DS = DS; export default DS;