2017-12-15 21:39:18 +00:00
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
import Mixin from '@ember/object/mixin';
|
|
|
|
import { computed } from '@ember/object';
|
2019-10-15 18:32:58 +00:00
|
|
|
import { computed as overridable } from 'ember-overridable-computed';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
2018-07-06 20:38:57 +00:00
|
|
|
import queryString from 'query-string';
|
2017-11-21 01:09:28 +00:00
|
|
|
|
2017-11-21 23:05:28 +00:00
|
|
|
const MAX_OUTPUT_LENGTH = 50000;
|
2017-11-21 01:09:28 +00:00
|
|
|
|
2020-06-09 21:03:28 +00:00
|
|
|
// eslint-disable-next-line ember/no-new-mixins
|
2017-11-21 01:09:28 +00:00
|
|
|
export default Mixin.create({
|
|
|
|
url: '',
|
2019-10-15 18:32:58 +00:00
|
|
|
params: overridable(() => ({})),
|
2017-11-21 01:09:28 +00:00
|
|
|
logFetch() {
|
2017-12-15 21:39:18 +00:00
|
|
|
assert('Loggers need a logFetch method, which should have an interface like window.fetch');
|
2017-11-21 01:09:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
endOffset: null,
|
|
|
|
|
|
|
|
offsetParams: computed('endOffset', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const endOffset = this.endOffset;
|
2017-11-21 01:09:28 +00:00
|
|
|
return endOffset
|
|
|
|
? { origin: 'start', offset: endOffset }
|
2017-11-21 23:05:28 +00:00
|
|
|
: { origin: 'end', offset: MAX_OUTPUT_LENGTH };
|
2017-11-21 01:09:28 +00:00
|
|
|
}),
|
|
|
|
|
2019-10-15 18:32:58 +00:00
|
|
|
additionalParams: overridable(() => ({})),
|
2017-11-21 01:09:28 +00:00
|
|
|
|
|
|
|
fullUrl: computed('url', 'params', 'offsetParams', 'additionalParams', function() {
|
|
|
|
const queryParams = queryString.stringify(
|
2019-03-26 07:46:44 +00:00
|
|
|
assign({}, this.params, this.offsetParams, this.additionalParams)
|
2017-11-21 01:09:28 +00:00
|
|
|
);
|
2019-03-26 07:46:44 +00:00
|
|
|
return `${this.url}?${queryParams}`;
|
2017-11-21 01:09:28 +00:00
|
|
|
}),
|
|
|
|
});
|