import { sha256base58 } from '@basemaps/config';
export class SourceTracer {
    constructor() {
        this.requests = [];
    }
    /** Reset the request tracer */
    reset() {
        this.requests = [];
    }
    /** Override the fetchByte function to trace all requests for this source  */
    trace(source) {
        const originFetch = source.fetchBytes;
        source.fetchBytes = async (offset, length) => {
            const request = { source: source.uri, offset, length };
            const traceId = sha256base58(`${request.source}:${request.offset}:${request.length}`);
            request.id = traceId;
            this.requests.push(request);
            const startTime = Date.now();
            const ret = await originFetch.apply(source, [offset, length]);
            request.duration = Date.now() - startTime;
            return ret;
        };
    }
}
export const St = new SourceTracer();
//# sourceMappingURL=source.tracer.js.map