diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68f96d3..bbda8ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,14 +7,13 @@ on: - master pull_request: {} - concurrency: group: ci-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: test: - name: "Tests" + name: 'Tests' runs-on: ubuntu-latest timeout-minutes: 10 @@ -33,7 +32,7 @@ jobs: run: yarn test:ember floating: - name: "Floating Dependencies" + name: 'Floating Dependencies' runs-on: ubuntu-latest timeout-minutes: 10 @@ -50,7 +49,7 @@ jobs: try-scenarios: name: ${{ matrix.try-scenario }} - needs: "test" + needs: 'test' runs-on: ubuntu-latest timeout-minutes: 10 @@ -67,7 +66,7 @@ jobs: - ember-lts-4.8 - ember-4.11 - ember-lts-4.12 - - ember-release + # - ember-release # - ember-beta # - ember-canary - embroider-safe diff --git a/addon/adapters/base.js b/addon/adapters/base.js index 46903b9..18f2473 100644 --- a/addon/adapters/base.js +++ b/addon/adapters/base.js @@ -1,8 +1,9 @@ -import RSVP from 'rsvp'; +import JSONAPIAdapter from '@ember-data/adapter/json-api'; +import { get } from '@ember/object'; import { run } from '@ember/runloop'; import { isEmpty, typeOf } from '@ember/utils'; -import { computed, get } from '@ember/object'; -import JSONAPIAdapter from '@ember-data/adapter/json-api'; +import RSVP from 'rsvp'; + import { importData, exportData, @@ -12,43 +13,43 @@ import { _buildKey } from 'ember-local-storage/helpers/storage'; // Ember data ships with ember-inflector import { singularize, pluralize } from 'ember-inflector'; -export default JSONAPIAdapter.extend({ - _debug: false, - _indices: computed(function () { - return {}; - }), - coalesceFindRequests: false, +export default class BaseAdapter extends JSONAPIAdapter { + constructor() { + super(...arguments); + + this._indices = {}; + } - // TODO: v2.0 - What are the defaults now? What versions to support? - isNewSerializerAPI: true, + _debug = false; + coalesceFindRequests = false; - // TODO: v2.0 - Can we deprecate or remove that? What are the defaults now? What versions to support? // Reload behavior shouldReloadRecord() { return true; - }, + } shouldReloadAll() { return true; - }, + } shouldBackgroundReloadRecord() { return true; - }, + } shouldBackgroundReloadAll() { return true; - }, + } generateIdForRecord() { return Math.random().toString(32).slice(2).substr(0, 8); - }, + } - // Import & Export + // Import importData(store, content, options) { return importData(store, content, options); - }, + } + // Export exportData(store, types, options) { return exportData(store, types, options); - }, + } // Relationship sugar createRecord(store, type, snapshot) { @@ -64,8 +65,8 @@ export default JSONAPIAdapter.extend({ } }); - return this._super.apply(this, arguments); - }, + return super.createRecord(...arguments); + } deleteRecord(store, type, snapshot) { snapshot.eachRelationship(function (name, relationship) { @@ -88,51 +89,21 @@ export default JSONAPIAdapter.extend({ } }); - return this._super.apply(this, arguments); - }, - - // Polyfill queryRecord - queryRecord(store, type, query) { - let records = this._super.apply(this, arguments); - - if (!records) { - var url = this.buildURL(type.modelName, null, null, 'queryRecord', query); + return super.deleteRecord(...arguments); + } - // TODO: Document why this is needed or remove it! - if (this.sortQueryParams) { - query = this.sortQueryParams(query); - } - - records = this.ajax(url, 'GET', { data: query }); - } + queryRecord() { + let records = super.queryRecord(...arguments); return records.then(function (result) { return { data: result.data[0] || null }; }); - }, + } - // TODO: v2.0 - What are the defaults now? What versions to support? // Delegate to _handleStorageRequest ajax() { return this._handleStorageRequest.apply(this, arguments); - }, - - // Delegate to _handleStorageRequest - makeRequest(request) { - return this._handleStorageRequest(request.url, request.method, { - data: request.data, - }); - }, - - // Work arround ds-improved-ajax Feature Flag - _makeRequest() { - return this.makeRequest.apply(this, arguments); - }, - - // Remove the ajax() deprecation warning - _hasCustomizedAjax() { - return false; - }, + } // Delegate to _handle${type}Request _handleStorageRequest(url, type, options = {}) { @@ -149,7 +120,7 @@ export default JSONAPIAdapter.extend({ run(null, reject, `There is nothing to handle _handle${type}Request`); } }, 'DS: LocalStorageAdapter#_handleStorageRequest ' + type + ' to ' + url); - }, + } _handleGETRequest(url, query) { const { type, id } = this._urlParts(url); @@ -180,7 +151,7 @@ export default JSONAPIAdapter.extend({ } return records; - }, + } _handlePOSTRequest(url, record) { const { type, id } = record.data; @@ -190,7 +161,7 @@ export default JSONAPIAdapter.extend({ get(this, '_storage')[storageKey] = JSON.stringify(record.data); return null; - }, + } _handlePATCHRequest(url, record) { const { type, id } = record.data; @@ -200,7 +171,7 @@ export default JSONAPIAdapter.extend({ get(this, '_storage')[storageKey] = JSON.stringify(record.data); return null; - }, + } _handleDELETERequest(url) { const { type, id } = this._urlParts(url); @@ -210,7 +181,7 @@ export default JSONAPIAdapter.extend({ delete get(this, '_storage')[storageKey]; return null; - }, + } // TODO: Extract into utility functions in private/query.js _queryFilter(data, serializer, query = {}) { @@ -288,15 +259,16 @@ export default JSONAPIAdapter.extend({ }); } } - }, + } + // TODO: Extract into utility function _matches(recordValue, queryValue) { if (typeOf(queryValue) === 'regexp') { return queryValue.test(recordValue); } return recordValue === queryValue; - }, + } _urlParts(url) { const parts = url.split('/'); @@ -316,27 +288,27 @@ export default JSONAPIAdapter.extend({ type: type, id: id, }; - }, + } _storageKey(type, id) { return _buildKey(this, type + '-' + id); - }, + } // Should be overwriten // Signature: _getIndex(type) - _getIndex() {}, + _getIndex() {} _indexHasKey(type, id) { return this._getIndex(type).indexOf(id) !== -1; - }, + } _addToIndex(type, id) { if (!this._indexHasKey(type, id)) { this._getIndex(type).addObject(id); } - }, + } _removeFromIndex(type, id) { this._getIndex(type).removeObject(id); - }, -}); + } +} diff --git a/addon/adapters/local.js b/addon/adapters/local.js index 0248778..57c22a3 100644 --- a/addon/adapters/local.js +++ b/addon/adapters/local.js @@ -4,8 +4,8 @@ import { getStorage, _buildKey } from '../helpers/storage'; import StorageArray from '../local/array'; import { getOwner } from '@ember/application'; -export default BaseAdapter.extend({ - _storage: getStorage('local'), +export default class LocalStorageAdapter extends BaseAdapter { + _storage = getStorage('local'); _getIndex(type) { const indices = get(this, '_indices'); @@ -19,5 +19,5 @@ export default BaseAdapter.extend({ } return indices[type]; - }, -}); + } +} diff --git a/addon/adapters/session.js b/addon/adapters/session.js index 2d9cddd..6ced423 100644 --- a/addon/adapters/session.js +++ b/addon/adapters/session.js @@ -4,8 +4,8 @@ import { getStorage, _buildKey } from '../helpers/storage'; import StorageArray from '../session/array'; import { getOwner } from '@ember/application'; -export default BaseAdapter.extend({ - _storage: getStorage('session'), +export default class SessionStorageAdapter extends BaseAdapter { + _storage = getStorage('session'); _getIndex(type) { const indices = get(this, '_indices'); @@ -19,5 +19,5 @@ export default BaseAdapter.extend({ } return indices[type]; - }, -}); + } +} diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js index df865ff..13a1106 100644 --- a/addon/serializers/serializer.js +++ b/addon/serializers/serializer.js @@ -1,17 +1,13 @@ import JSONAPISerializer from '@ember-data/serializer/json-api'; -export default JSONAPISerializer.extend({ +export default class Serializer extends JSONAPISerializer { shouldSerializeHasMany() { return true; - }, + } serializeBelongsTo() { this._fixSerializeBelongsTo(...arguments); - }, - - serializeHasMany() { - this._fixSerializeHasMany(...arguments); - }, + } _fixSerializeBelongsTo(snapshot, json, relationship) { let key = relationship.key; @@ -43,7 +39,11 @@ export default JSONAPISerializer.extend({ json.relationships[payloadKey] = { data }; } } - }, + } + + serializeHasMany() { + this._fixSerializeHasMany(...arguments); + } _fixSerializeHasMany(snapshot, json, relationship) { let key = relationship.key; @@ -78,5 +78,5 @@ export default JSONAPISerializer.extend({ json.relationships[payloadKey] = { data }; } } - }, -}); + } +} diff --git a/config/ember-try.js b/config/ember-try.js index 936b322..1f53d82 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -100,6 +100,8 @@ module.exports = async function () { 'ember-auto-import': '^2.2.0', 'ember-data': 'latest', 'ember-source': await getChannelURL('release'), + 'ember-resolver': '10.0.0', + '@ember/string': '3.0.1', }, }, },