open-nomad/ui/app/utils/classes/abstract-logger.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

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