Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 1, 2020
1 parent e6c1c79 commit 01a0164
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 72 deletions.
15 changes: 8 additions & 7 deletions packages/adapter/addon/-private/build-url-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { camelize } from '@ember/string';

import { pluralize } from 'ember-inflector';

type Dict<T> = import('@ember-data/store/-private/ts-interfaces/utils').Dict<T>;
type Snapshot = import('@ember-data/store/-private/system/snapshot').default;
type SnapshotRecordArray = import('@ember-data/store/-private/system/snapshot-record-array').default;

Expand Down Expand Up @@ -60,11 +61,11 @@ export default Mixin.create({
*/
buildURL(
modelName: string,
id: string | string[] | Record<string, any> | null,
id: string | string[] | Dict<unknown> | null,
snapshot: Snapshot | Snapshot[] | SnapshotRecordArray | null,
requestType: string = '',
query = {}
) {
): string {
switch (requestType) {
case 'findRecord':
return this.urlForFindRecord(id, modelName, snapshot);
Expand Down Expand Up @@ -98,7 +99,7 @@ export default Mixin.create({
@param {String} id
@return {String} url
*/
_buildURL(modelName: string, id: string): string {
_buildURL(modelName: string | null | undefined, id: string | null | undefined): string {
let path;
let url: string[] = [];
let host = get(this, 'host');
Expand Down Expand Up @@ -204,7 +205,7 @@ export default Mixin.create({
@param {String} modelName
@return {String} url
*/
urlForQuery(query: Record<string, any>, modelName: string): string {
urlForQuery(query: Dict<any>, modelName: string): string {
return this._buildURL(modelName);
},

Expand All @@ -229,7 +230,7 @@ export default Mixin.create({
@param {String} modelName
@return {String} url
*/
urlForQueryRecord(query: Record<string, any>, modelName: string): string {
urlForQueryRecord(query: Dict<any>, modelName: string): string {
return this._buildURL(modelName);
},

Expand Down Expand Up @@ -336,7 +337,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForCreateRecord(modelName, snapshot) {
urlForCreateRecord(modelName: string, snapshot: Snapshot) {
return this._buildURL(modelName);
},

Expand Down Expand Up @@ -397,7 +398,7 @@ export default Mixin.create({
@param {String} parentURL
@return {String} urlPrefix
*/
urlPrefix(path: string, parentURL: string): string {
urlPrefix(path: string | null | undefined, parentURL: string): string {
let host = get(this, 'host');
let namespace = get(this, 'namespace');

Expand Down
46 changes: 23 additions & 23 deletions packages/adapter/addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { warn } from '@ember/debug';
import EmberObject from '@ember/object';
import { DEBUG } from '@glimmer/env';

import { Promise } from 'rsvp';

Expand Down Expand Up @@ -123,9 +123,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
findRecord(store: Store, type: ShimModelClass, id: string, snapshot: Snapshot) {
warn('You subclassed the Adapter class but missing a findRecord override', false, {
id: 'adapter.missing-find-record',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a findRecord override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -161,9 +161,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
findAll(store: Store, type: ShimModelClass, neverSet, snapshotRecordArray: SnapshotRecordArray) {
warn('You subclassed the Adapter class but missing a findAll override', false, {
id: 'adapter.missing-find-all',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a findAll override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -200,9 +200,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
query(store: Store, type: ShimModelClass, query): Promise<unknown> {
warn('You subclassed the Adapter class but missing a query override', false, {
id: 'adapter.missing-query',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a query override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -245,9 +245,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
queryRecord(store: Store, type: ShimModelClass, query, adapterOptions) {
warn('You subclassed the Adapter class but missing a queryRecord override', false, {
id: 'adapter.missing-query-record',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a queryRecord override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -354,9 +354,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
createRecord(store: Store, type: ShimModelClass, snapshot: Snapshot) {
warn('You subclassed the Adapter class but missing a createRecord override', false, {
id: 'adapter.missing-create-record',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a createRecord override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -412,9 +412,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
updateRecord(store: Store, type: ShimModelClass, snapshot: Snapshot) {
warn('You subclassed the Adapter class but missing a updateRecord override', false, {
id: 'adapter.missing-update-record',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a updateRecord override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -462,9 +462,9 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
*/
deleteRecord(store: Store, type: ShimModelClass, snapshot: Snapshot) {
warn('You subclassed the Adapter class but missing a deleteRecord override', false, {
id: 'adapter.missing-delete-record',
});
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a deleteRecord override');
}

return Promise.resolve();
}
Expand Down Expand Up @@ -638,7 +638,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@param {SnapshotRecordArray} snapshotRecordArray
@return {Boolean}
*/
shouldReloadAll(store: Store, snapshotRecordArray) {
shouldReloadAll(store: Store, snapshotRecordArray: SnapshotRecordArray) {
return !snapshotRecordArray.length;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/adapter/addon/json-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { pluralize } from 'ember-inflector';
import { serializeIntoHash } from './-private';
import RESTAdapter from './rest';

type Dict<T> = import('@ember-data/store/-private/ts-interfaces/utils').Dict<T>;
type ShimModelClass = import('@ember-data/store/-private/system/model/shim-model-class').default;
type Store = import('@ember-data/store/-private/system/core-store').default;
type Snapshot = import('@ember-data/store/-private/system/snapshot').default;
Expand Down Expand Up @@ -160,7 +161,7 @@ class JSONAPIAdapter extends RESTAdapter {
@param {Object} options
@return {Object}
*/
ajaxOptions(url: string, type: string, options = {}) {
ajaxOptions(url: string, type: string, options: Dict<any> = {}) {
let hash = super.ajaxOptions(url, type, options);

hash.headers['Accept'] = hash.headers['Accept'] || 'application/vnd.api+json';
Expand Down
Loading

0 comments on commit 01a0164

Please sign in to comment.