mappersmith
Advanced tools
Comparing version 2.38.0 to 2.38.1
@@ -8,16 +8,19 @@ "use strict"; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
/** | ||
* Adds started_at, ended_at and duration headers to the response | ||
*/ | ||
var DurationMiddleware = function DurationMiddleware() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
mockRequest = _ref.mockRequest; | ||
var DurationMiddleware = function DurationMiddleware(_ref) { | ||
var mockRequest = _ref.mockRequest; | ||
return { | ||
prepareRequest: function prepareRequest(next) { | ||
if (mockRequest) { | ||
return next(); | ||
} | ||
return _asyncToGenerator(function* () { | ||
if (mockRequest) { | ||
return next(); | ||
} | ||
return next().then(function (request) { | ||
var request = yield next(); | ||
return request.enhance({ | ||
@@ -28,8 +31,9 @@ headers: { | ||
}); | ||
}); | ||
})(); | ||
}, | ||
response: function response(next) { | ||
return next().then(function (response) { | ||
return _asyncToGenerator(function* () { | ||
var response = yield next(); | ||
var endedAt = Date.now(); | ||
var startedAt = response.request().headers()['x-started-at']; | ||
var startedAt = response.request().header('x-started-at'); | ||
return response.enhance({ | ||
@@ -42,3 +46,3 @@ headers: { | ||
}); | ||
}); | ||
})(); | ||
} | ||
@@ -45,0 +49,0 @@ }; |
{ | ||
"name": "mappersmith", | ||
"version": "2.38.0", | ||
"version": "2.38.1", | ||
"description": "It is a lightweight rest client for node.js and the browser", | ||
@@ -5,0 +5,0 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>", |
@@ -57,3 +57,3 @@ import { MethodDescriptor } from './method-descriptor'; | ||
*/ | ||
header(name: string): Primitive; | ||
header<T extends string | number | boolean>(name: string): T | undefined; | ||
body(): object | Primitive | NestedParam | NestedParamArray | null | undefined; | ||
@@ -60,0 +60,0 @@ auth(): Auth; |
@@ -231,3 +231,9 @@ "use strict"; | ||
value: function header(name) { | ||
return this.headers()[name.toLowerCase()]; | ||
var key = name.toLowerCase(); | ||
if (key in this.headers()) { | ||
return this.headers()[key]; | ||
} | ||
return undefined; | ||
} | ||
@@ -234,0 +240,0 @@ }, { |
@@ -26,3 +26,3 @@ import { Request } from './request'; | ||
timeElapsed: number | null; | ||
constructor(originalRequest: Request, responseStatus: number, responseData?: string, responseHeaders?: Headers, errors?: Array<Error | string>); | ||
constructor(originalRequest: Request, responseStatus: number, responseData?: string | null, responseHeaders?: Headers, errors?: Array<Error | string>); | ||
request(): Request; | ||
@@ -29,0 +29,0 @@ status(): number; |
@@ -67,3 +67,3 @@ "use strict"; | ||
this.responseStatus = responseStatus; | ||
this.responseData = responseData !== undefined ? responseData : null; | ||
this.responseData = responseData !== null && responseData !== void 0 ? responseData : null; | ||
this.responseHeaders = responseHeaders || {}; | ||
@@ -193,3 +193,3 @@ this.errors = errors || []; | ||
var enhancedResponse = new Response(this.request(), extras.status || this.status(), extras.rawData || this.rawData() || undefined, mergedHeaders, extras.error ? [].concat(_toConsumableArray(this.errors), [extras.error]) : _toConsumableArray(this.errors)); | ||
var enhancedResponse = new Response(this.request(), extras.status || this.status(), extras.rawData || this.rawData(), mergedHeaders, extras.error ? [].concat(_toConsumableArray(this.errors), [extras.error]) : _toConsumableArray(this.errors)); | ||
enhancedResponse.timeElapsed = this.timeElapsed; | ||
@@ -196,0 +196,0 @@ return enhancedResponse; |
import { Client } from '../client-builder' | ||
import { Request } from '../request' | ||
import { Headers, Params } from '../types' | ||
import { Response, ParsedJSON } from '../response' | ||
export { requestFactory, RequestFactoryArgs } from './request-factory' | ||
export { responseFactory, ResponseFactoryArgs } from './response-factory' | ||
@@ -68,34 +69,2 @@ export interface MockAssert { | ||
export interface ResponseFactoryArgs<T> { | ||
method?: string | ||
host?: string | ||
path?: string | ||
status?: number | ||
data?: T | string | ||
headers?: Record<string, string | number | boolean> | ||
errors?: Array<Error | string> | ||
} | ||
export function responseFactory<T extends ParsedJSON>(args?: ResponseFactoryArgs<T>): Response<T> | ||
type Primitive = string | number | boolean | ||
interface Auth { | ||
readonly [key: string]: Primitive | ||
} | ||
export interface RequestFactoryArgs { | ||
// MethodDescriptorParams | ||
method?: string | ||
host?: string | ||
path?: string | ||
// RequestParams | ||
auth?: Auth | ||
body?: object | string | ||
headers?: Headers | ||
params?: Params | ||
timeout?: number | ||
[param: string]: object | Primitive | undefined | null | ||
} | ||
export function requestFactory(args?: RequestFactoryArgs): Request | ||
export const m: TestMatchFunctions |
import { Request } from '../request'; | ||
import { RequestParams } from '../types'; | ||
interface RequestFactoryArgs extends RequestParams { | ||
export interface RequestFactoryArgs extends RequestParams { | ||
method?: string; | ||
@@ -12,2 +12,1 @@ path?: string; | ||
export declare const requestFactory: ({ method, host, path, auth, body, headers, params, timeout, ...rest }?: RequestFactoryArgs) => Request; | ||
export {}; |
import { Response } from '../response'; | ||
import { Request } from '../request'; | ||
import type { Headers } from '../types'; | ||
interface ResponseFactoryArgs { | ||
export interface ResponseFactoryArgs { | ||
method?: string; | ||
host?: string; | ||
path?: string; | ||
request?: Request; | ||
status?: number; | ||
@@ -16,3 +18,2 @@ data?: string | Record<string, unknown>; | ||
*/ | ||
export declare const responseFactory: ({ method, host, path, status, data, headers, errors, }?: ResponseFactoryArgs) => Response<import("../response").ParsedJSON>; | ||
export {}; | ||
export declare const responseFactory: ({ method, host, path, request, status, data, headers, errors, }?: ResponseFactoryArgs) => Response<import("../response").ParsedJSON>; |
@@ -30,2 +30,8 @@ "use strict"; | ||
path = _ref$path === void 0 ? '/path' : _ref$path, | ||
_ref$request = _ref.request, | ||
request = _ref$request === void 0 ? (0, _requestFactory.requestFactory)({ | ||
method: method, | ||
host: host, | ||
path: path | ||
}) : _ref$request, | ||
_ref$status = _ref.status, | ||
@@ -40,7 +46,2 @@ status = _ref$status === void 0 ? 200 : _ref$status, | ||
var request = (0, _requestFactory.requestFactory)({ | ||
method: method, | ||
host: host, | ||
path: path | ||
}); | ||
var responseData; | ||
@@ -47,0 +48,0 @@ var contentType; |
@@ -11,3 +11,3 @@ "use strict"; | ||
var clone = function clone(obj) { | ||
if ((0, _index.isObject)(obj)) { | ||
if ((0, _index.isPlainObject)(obj)) { | ||
return cloneObject(obj); | ||
@@ -14,0 +14,0 @@ } else if (Array.isArray(obj)) { |
@@ -1,1 +0,1 @@ | ||
{"version":"2.38.0"} | ||
{"version":"2.38.1"} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
233032
4086