/**
 * 请求上下文运行时工具
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get cancelRequestContext () {
        return cancelRequestContext;
    },
    get completeRequestContext () {
        return completeRequestContext;
    },
    get createRequestContext () {
        return createRequestContext;
    },
    get failRequestContext () {
        return failRequestContext;
    },
    get updateRequestContext () {
        return updateRequestContext;
    }
});
function createRequestContext(request, meta = {}) {
    const startTime = Date.now();
    const abortController = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
    return {
        request,
        meta: meta,
        startTime,
        retryCount: 0,
        cancelled: false,
        abortController
    };
}
function updateRequestContext(context, updates) {
    return {
        ...context,
        ...updates,
        meta: {
            ...context.meta,
            ...updates.meta || {}
        }
    };
}
function completeRequestContext(context, response) {
    const endTime = Date.now();
    return updateRequestContext(context, {
        response: response,
        endTime,
        duration: endTime - context.startTime
    });
}
function failRequestContext(context, error) {
    const endTime = Date.now();
    return updateRequestContext(context, {
        error: error,
        endTime,
        duration: endTime - context.startTime
    });
}
function cancelRequestContext(context) {
    if (context.abortController) {
        context.abortController.abort();
    }
    return updateRequestContext(context, {
        cancelled: true
    });
}

//# sourceMappingURL=RequestContext.js.map