@n1k1t/mock-server
Version:
The ultimate toolkit to intercept, transform, and simulate HTTP/WS traffic with type-safe expectations
62 lines • 2.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operator_1 = require("../models/operator");
const utils_1 = require("../utils");
class IfExpectationOperator extends operator_1.ExpectationOperator {
constructor() {
super(...arguments);
this.compiled = {
condition: (() => {
const extracted = this.extractNestedSchema(this.command.$condition);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
...(this.command.$then && {
then: (() => {
const extracted = this.extractNestedSchema(this.command.$then);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
}),
...(this.command.$else && {
else: (() => {
const extracted = this.extractNestedSchema(this.command.$else);
if (!extracted) {
return null;
}
const Operator = this.operators[extracted.key];
return new Operator(this.operators, extracted.nested);
})(),
}),
};
}
get tags() {
return (0, utils_1.mergeMetaTags)([
this.compiled.condition?.tags ?? {},
this.compiled.then?.tags ?? {},
this.compiled.else?.tags ?? {},
]);
}
async match(context) {
const matched = await this.compiled.condition?.match(context) ?? false;
const result = matched
? await this.compiled.then?.match(context)
: await this.compiled.else?.match(context);
return result ?? false;
}
async manipulate(context) {
const result = await this.compiled.condition?.match(context) ?? false;
result
? await this.compiled.then?.manipulate(context)
: await this.compiled.else?.manipulate(context);
return context;
}
}
exports.default = IfExpectationOperator;
//# sourceMappingURL=if.operator.js.map