@gatling.io/http
Version: 
Gatling JS is a JavaScript/TypeScript interface for the [Gatling load testing tool](https://gatling.io/).
98 lines (97 loc) • 5.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sse = void 0;
const core_1 = require("@gatling.io/core");
const jvm_types_1 = require("@gatling.io/jvm-types");
const request_1 = require("./request");
const wrapUntypedCondition = (_underlying) => ({
    then: (...thenChecks) => wrapSseMessageCheck(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const wrapTypedCondition = (_underlying) => ({
    then: (...thenChecks) => wrapSseMessageCheck(_underlying.then(thenChecks.map((cb) => cb._underlying)))
});
const wrapSseMessageCheck = (_underlying) => ({
    _underlying,
    matching: (...newMatchConditions) => wrapSseMessageCheck(_underlying.matching(newMatchConditions.map((cb) => cb._underlying))),
    check: (...checks) => wrapSseMessageCheck(_underlying.check(checks.map((cb) => cb._underlying))),
    checkIf: (condition) => {
        if (typeof condition === "string") {
            return wrapUntypedCondition(_underlying.checkIf(condition));
        }
        else if (typeof condition === "function") {
            if (condition.length === 1) {
                return wrapUntypedCondition(_underlying.checkIf((0, core_1.underlyingSessionTo)(condition)));
            }
            else if (condition.length === 2) {
                return wrapTypedCondition(_underlying.checkIf((0, core_1.underlyingXWithSessionTo)(condition)));
            }
        }
        throw Error(`checkIf() called with invalid argument ${condition}`);
    }
});
const wrapSseAwaitActionBuilderOn = (jvmOn, wrap) => ({
    on: (...checks) => wrap(jvmOn.on(checks.map((c) => c._underlying)))
});
const sseAwaitActionBuilderImpl = (jvmBuilder, wrap) => ({
    await: (timeout) => {
        if (typeof timeout === "string") {
            return wrapSseAwaitActionBuilderOn(jvmBuilder.await(timeout), wrap);
        }
        else if (typeof timeout === "function") {
            return wrapSseAwaitActionBuilderOn(jvmBuilder.await((0, core_1.underlyingSessionToDuration)(timeout)), wrap);
        }
        else if ((0, core_1.isDuration)(timeout)) {
            return wrapSseAwaitActionBuilderOn(jvmBuilder.await((0, core_1.toJvmDuration)(timeout)), wrap);
        }
        throw Error(`await() called with invalid argument ${timeout}`);
    }
});
const wrapSseConnectActionBuilder = (_underlying) => ({
    _underlying,
    ...(0, request_1.requestActionBuilderImpl)(_underlying, wrapSseConnectActionBuilder),
    ...(0, request_1.requestWithBodyActionBuilderImpl)(_underlying, wrapSseConnectActionBuilder),
    ...sseAwaitActionBuilderImpl(_underlying, wrapSseConnectActionBuilder)
});
const wrapSseSetCheckActionBuilder = (_underlying) => ({
    _underlying,
    ...sseAwaitActionBuilderImpl(_underlying, wrapSseSetCheckActionBuilder)
});
const wrapSse = (jvmSse) => ({
    sseName: (sseName) => wrapSse(typeof sseName === "function" ? jvmSse.sseName((0, core_1.underlyingSessionTo)(sseName)) : jvmSse.sseName(sseName)),
    get: (url) => wrapSseConnectActionBuilder(typeof url === "function" ? jvmSse.get((0, core_1.underlyingSessionTo)(url)) : jvmSse.get(url)),
    post: (url) => wrapSseConnectActionBuilder(typeof url === "function" ? jvmSse.post((0, core_1.underlyingSessionTo)(url)) : jvmSse.post(url)),
    setCheck: () => wrapSseSetCheckActionBuilder(jvmSse.setCheck()),
    close: () => (0, core_1.wrapActionBuilder)(jvmSse.close())
});
const sseApply = (name, sseName) => {
    // Handle overloading
    const jvmSse = typeof sseName === "undefined" ? jvm_types_1.HttpDsl.sse(name) : jvm_types_1.HttpDsl.sse(name, sseName);
    return wrapSse(jvmSse);
};
const jvmSsePrefix = jvm_types_1.Sse$Prefix.INSTANCE;
const ssePrefix = {
    checkMessage: (name) => wrapSseMessageCheck(jvmSsePrefix.checkMessage(name)),
    processUnmatchedMessages: (arg0, arg1) => {
        if (arg1 !== undefined) {
            // arg1 is the SseProcessUnmatchedMessagesCallback if it is defined
            // arg0 is the sseName
            const f = arg1;
            if (typeof arg0 === "string") {
                const sseName = arg0;
                return (0, core_1.wrapActionBuilder)(jvmSsePrefix.processUnmatchedMessages(sseName, (0, core_1.underlyingXWithSessionToSession)(f)));
            }
            else if (typeof arg0 === "function") {
                const sseName = arg0;
                return (0, core_1.wrapActionBuilder)(jvmSsePrefix.processUnmatchedMessages((0, core_1.underlyingSessionTo)(sseName), (0, core_1.underlyingXWithSessionToSession)(f)));
            }
        }
        else if (typeof arg0 === "function") {
            // arg0 is the SseProcessUnmatchedMessagesCallback is arg1 is undefined
            const f = arg0;
            return (0, core_1.wrapActionBuilder)(jvmSsePrefix.processUnmatchedMessages((0, core_1.underlyingXWithSessionToSession)(f)));
        }
        throw Error(`processUnmatchedMessages() called with invalid arguments ${arg0}, ${arg1}`);
    }
};
// FIXME Sse.Apply && Prefix?
exports.sse = Object.assign(sseApply, ssePrefix);