UNPKG

wiremock-mapper

Version:
167 lines 6.39 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestBuilderImpl = void 0; var match_builder_1 = require("../../lib/builders/match_builder"); var url_match_builder_1 = require("../../lib/builders/url_match_builder"); var RequestBuilderImpl = /** @class */ (function () { function RequestBuilderImpl() { var _this = this; this.request = {}; this.urlMatchBuilder = new url_match_builder_1.UrlMatchBuilder(this); this.toJSON = function () { return (__assign(__assign({}, _this.request), _this.urlMatchBuilder.toJSON())); }; } RequestBuilderImpl.prototype.clone = function () { var clone = new RequestBuilderImpl(); clone.request = __assign(__assign({}, this.request), { headers: this.request.headers ? __assign({}, this.request.headers) : undefined, cookies: this.request.cookies ? __assign({}, this.request.cookies) : undefined, queryParameters: this.request.queryParameters ? __assign({}, this.request.queryParameters) : undefined, bodyPatterns: this.request.bodyPatterns ? __spreadArray([], this.request.bodyPatterns, true) : undefined, basicAuthCredentials: this.request.basicAuthCredentials ? __assign({}, this.request.basicAuthCredentials) : undefined }); clone.urlMatchBuilder = this.urlMatchBuilder.clone(clone); return clone; }; Object.defineProperty(RequestBuilderImpl.prototype, "isADelete", { get: function () { this.request.method = 'DELETE'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAGet", { get: function () { this.request.method = 'GET'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAHead", { get: function () { this.request.method = 'HEAD'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAnOptions", { get: function () { this.request.method = 'OPTIONS'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAnyVerb", { get: function () { this.request.method = 'ANY'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAPost", { get: function () { this.request.method = 'POST'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isAPut", { get: function () { this.request.method = 'PUT'; return this; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "isATrace", { get: function () { this.request.method = 'TRACE'; return this; }, enumerable: false, configurable: true }); RequestBuilderImpl.prototype.withBasicAuth = function (username, password) { this.request.basicAuthCredentials = { username: username, password: password }; return this; }; Object.defineProperty(RequestBuilderImpl.prototype, "withBody", { get: function () { if (!this.request.bodyPatterns) { this.request.bodyPatterns = []; } var matchBuilder = new match_builder_1.MatchBuilder(this); this.request.bodyPatterns.push(matchBuilder); return matchBuilder; }, enumerable: false, configurable: true }); RequestBuilderImpl.prototype.withCookie = function (key) { if (!this.request.cookies) { this.request.cookies = {}; } var matchBuilder = new match_builder_1.MatchBuilder(this); this.request.cookies[key] = matchBuilder; return matchBuilder; }; RequestBuilderImpl.prototype.withHeader = function (key) { if (!this.request.headers) { this.request.headers = {}; } var matchBuilder = new match_builder_1.MatchBuilder(this); this.request.headers[key] = matchBuilder; return matchBuilder; }; RequestBuilderImpl.prototype.withQueryParam = function (key) { if (!this.request.queryParameters) { this.request.queryParameters = {}; } var matchBuilder = new match_builder_1.MatchBuilder(this); this.request.queryParameters[key] = matchBuilder; return matchBuilder; }; Object.defineProperty(RequestBuilderImpl.prototype, "withUrl", { get: function () { this.urlMatchBuilder = new url_match_builder_1.UrlMatchBuilder(this); return this.urlMatchBuilder; }, enumerable: false, configurable: true }); Object.defineProperty(RequestBuilderImpl.prototype, "withUrlPath", { get: function () { this.urlMatchBuilder = new url_match_builder_1.UrlMatchBuilder(this, true); return this.urlMatchBuilder; }, enumerable: false, configurable: true }); return RequestBuilderImpl; }()); exports.RequestBuilderImpl = RequestBuilderImpl; //# sourceMappingURL=request_builder.js.map