Skip to content

Commit

Permalink
Run jarn lint:js:fix with plugin:prettier/recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmanuel committed Sep 4, 2022
1 parent e2f2909 commit 8263618
Show file tree
Hide file tree
Showing 59 changed files with 1,100 additions and 1,005 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:ember/recommended',
// 'plugin:prettier/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true
browser: true,
},
rules: {
'ember/avoid-leaking-state-in-ember-objects': 'off',
Expand Down
124 changes: 59 additions & 65 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,75 @@ import { _buildKey } from '../helpers/storage';

const getKeys = Object.keys || keys;

const {
JSONAPIAdapter
} = DS;
const { JSONAPIAdapter } = DS;

// Ember data ships with ember-inflector
import { singularize, pluralize } from 'ember-inflector';

export default JSONAPIAdapter.extend(ImportExportMixin, {
_debug: false,
_indices: computed(function() { return {}; }),
_indices: computed(function () {
return {};
}),
coalesceFindRequests: false,

// TODO: v2.0 - What are the defaults now? What versions to support?
isNewSerializerAPI: true,

// 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; },
shouldReloadRecord() {
return true;
},
shouldReloadAll() {
return true;
},
shouldBackgroundReloadRecord() {
return true;
},
shouldBackgroundReloadAll() {
return true;
},

generateIdForRecord() {
return Math.random().toString(32).slice(2).substr(0, 8);
},

// Relationship sugar
createRecord(store, type, snapshot) {
snapshot.eachRelationship(function(name, relationship) {
const {
kind,
options
} = relationship;
snapshot.eachRelationship(function (name, relationship) {
const { kind, options } = relationship;

if (kind === 'belongsTo' && options.autoSave) {
snapshot.record.get(name)
.then(function(record) {
if (record) {
record.save();
}
});
snapshot.record.get(name).then(function (record) {
if (record) {
record.save();
}
});
}
});

return this._super.apply(this, arguments);
},

deleteRecord(store, type, snapshot) {
snapshot.eachRelationship(function(name, relationship) {
const {
kind,
options
} = relationship;
snapshot.eachRelationship(function (name, relationship) {
const { kind, options } = relationship;

if (kind === 'hasMany' && options.dependent === 'destroy') {
snapshot.record.get(name)
.then(function(records) {
records.forEach(function(record) {
record.destroyRecord();
});
snapshot.record.get(name).then(function (records) {
records.forEach(function (record) {
record.destroyRecord();
});
});
}

if (kind === 'belongsTo' && options.autoSave) {
snapshot.record.get(name)
.then(function(record) {
if (record) {
record.save();
}
});
snapshot.record.get(name).then(function (record) {
if (record) {
record.save();
}
});
}
});

Expand All @@ -100,10 +99,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
records = this.ajax(url, 'GET', { data: query });
}

return records
.then(function(result) {
return {data: result.data[0] || null};
});
return records.then(function (result) {
return { data: result.data[0] || null };
});
},

// TODO: v2.0 - What are the defaults now? What versions to support?
Expand All @@ -114,11 +112,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

// Delegate to _handleStorageRequest
makeRequest(request) {
return this._handleStorageRequest(
request.url,
request.method,
{ data: request.data }
);
return this._handleStorageRequest(request.url, request.method, {
data: request.data,
});
},

// Work arround ds-improved-ajax Feature Flag
Expand All @@ -141,13 +137,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
const handler = this[`_handle${type}Request`];
if (handler) {
const data = handler.call(this, url, options.data);
run(null, resolve, {data: data});
run(null, resolve, { data: data });
} else {
run(
null,
reject,
`There is nothing to handle _handle${type}Request`
);
run(null, reject, `There is nothing to handle _handle${type}Request`);
}
}, 'DS: LocalStorageAdapter#_handleStorageRequest ' + type + ' to ' + url);
},
Expand All @@ -159,16 +151,16 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

if (id) {
if (!storage[storageKey]) {
throw this.handleResponse(404, {}, "Not found", { url, method: 'GET' });
throw this.handleResponse(404, {}, 'Not found', { url, method: 'GET' });
}
return JSON.parse(storage[storageKey]);
}

const records = this._getIndex(type)
.filter(function(storageKey) {
.filter(function (storageKey) {
return storage[storageKey];
})
.map(function(storageKey) {
.map(function (storageKey) {
return JSON.parse(storage[storageKey]);
});

Expand Down Expand Up @@ -257,18 +249,21 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
} else if (queryType === 'array') {
// belongsTo
if (dataType === 'object') {
const queryMessage = query.map(function(item) {
return getKeys(item).map(function(key) {
return key + ': ' + item[key];
});
}).join(', ');
const queryMessage = query
.map(function (item) {
return getKeys(item).map(function (key) {
return key + ': ' + item[key];
});
})
.join(', ');

throw new Error(
'You can not provide an array with a belongsTo relation. ' +
'Query: ' + queryMessage
'Query: ' +
queryMessage
);

// hasMany
// hasMany
} else {
return query.every((queryValue) => {
return this._queryFilter(data, serializer, queryValue);
Expand All @@ -279,7 +274,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
if (dataType === 'object') {
return this._matches(data.id, query);

// hasMany
// hasMany
} else {
return data.some((record) => {
return this._queryFilter(record, serializer, query);
Expand Down Expand Up @@ -312,7 +307,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

return {
type: type,
id: id
id: id,
};
},

Expand All @@ -322,8 +317,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

// Should be overwriten
// Signature: _getIndex(type)
_getIndex() {
},
_getIndex() {},

_indexHasKey(type, id) {
return this._getIndex(type).indexOf(id) !== -1;
Expand All @@ -337,5 +331,5 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

_removeFromIndex(type, id) {
this._getIndex(type).removeObject(id);
}
},
});
6 changes: 2 additions & 4 deletions addon/adapters/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray
.extend({ _storageKey: storageKey })
.create();
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}

return indices[type];
}
},
});
6 changes: 2 additions & 4 deletions addon/adapters/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray
.extend({ _storageKey: storageKey })
.create();
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}

return indices[type];
}
},
});
61 changes: 35 additions & 26 deletions addon/helpers/import-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { A } from '@ember/array';

export function importData(store, content, options) {
// merge defaults
options = Object.assign({
json: true,
truncate: true
}, options || {});
options = Object.assign(
{
json: true,
truncate: true,
},
options || {}
);

let truncateTypes = A(), reloadTypes = A();
let truncateTypes = A(),
reloadTypes = A();

content = options.json ? JSON.parse(content) : content;

Expand Down Expand Up @@ -42,38 +46,43 @@ export function importData(store, content, options) {
reloadTypes.addObject(singularize(record.type));

return adapter._handleStorageRequest(null, 'POST', {
data: {data: record}
data: { data: record },
});
});

return all(promises)
.then(function() {
// reload from store
reloadTypes.forEach(function(type) {
store.findAll(type);
});
return all(promises).then(function () {
// reload from store
reloadTypes.forEach(function (type) {
store.findAll(type);
});
});
}

export function exportData(store, types, options) {
// merge defaults
options = Object.assign({
json: true,
download: false,
filename: 'ember-data.json'
}, options || {});
options = Object.assign(
{
json: true,
download: false,
filename: 'ember-data.json',
},
options || {}
);

let json, data;

// collect data
data = types.reduce((records, type) => {
const adapter = store.adapterFor(singularize(type));
const url = adapter.buildURL(type);
const exportData = adapter._handleGETRequest(url);

records.data = records.data.concat(exportData);
return records;
}, {data: []});
data = types.reduce(
(records, type) => {
const adapter = store.adapterFor(singularize(type));
const url = adapter.buildURL(type);
const exportData = adapter._handleGETRequest(url);

records.data = records.data.concat(exportData);
return records;
},
{ data: [] }
);

if (options.json || options.download) {
json = JSON.stringify(data);
Expand All @@ -85,7 +94,7 @@ export function exportData(store, types, options) {

if (options.download) {
window.saveAs(
new Blob([json], {type: 'application/json;charset=utf-8'}),
new Blob([json], { type: 'application/json;charset=utf-8' }),
options.filename
);
}
Expand Down
Loading

0 comments on commit 8263618

Please sign in to comment.