@leyyo/http-mock 1.2.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +396 -4
  2. package/dist/application/index.types.d.ts +64 -8
  3. package/dist/application/mock-application.d.ts +73 -8
  4. package/dist/application/mock-application.js +74 -15
  5. package/dist/application/mock-application.js.map +1 -1
  6. package/dist/{shared → enum}/http-method.js +1 -0
  7. package/dist/enum/http-method.js.map +1 -0
  8. package/dist/{shared → enum}/http-protocol.js +1 -0
  9. package/dist/enum/http-protocol.js.map +1 -0
  10. package/dist/{shared → enum}/index.d.ts +0 -2
  11. package/dist/{shared → enum}/index.js +0 -2
  12. package/dist/enum/index.js.map +1 -0
  13. package/dist/{shared → event}/http-event.d.ts +3 -0
  14. package/dist/{shared → event}/http-event.js +3 -0
  15. package/dist/event/http-event.js.map +1 -0
  16. package/dist/event/index.d.ts +2 -0
  17. package/dist/event/index.js +19 -0
  18. package/dist/event/index.js.map +1 -0
  19. package/dist/{shared → event}/index.types.d.ts +15 -1
  20. package/dist/{shared → event}/index.types.js.map +1 -1
  21. package/dist/http-mock.d.ts +6 -1
  22. package/dist/http-mock.js +11 -0
  23. package/dist/http-mock.js.map +1 -1
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.js +2 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.types.d.ts +26 -4
  28. package/dist/loader.d.ts +2 -0
  29. package/dist/loader.js +64 -0
  30. package/dist/loader.js.map +1 -0
  31. package/dist/request/index.types.d.ts +41 -4
  32. package/dist/request/mock.request.d.ts +137 -11
  33. package/dist/request/mock.request.js +114 -33
  34. package/dist/request/mock.request.js.map +1 -1
  35. package/dist/response/index-types.d.ts +48 -3
  36. package/dist/response/mock-response.d.ts +156 -8
  37. package/dist/response/mock-response.js +115 -15
  38. package/dist/response/mock-response.js.map +1 -1
  39. package/package.json +6 -6
  40. package/dist/shared/http-event.js.map +0 -1
  41. package/dist/shared/http-method.js.map +0 -1
  42. package/dist/shared/http-protocol.js.map +0 -1
  43. package/dist/shared/index.js.map +0 -1
  44. /package/dist/{shared → enum}/http-method.d.ts +0 -0
  45. /package/dist/{shared → enum}/http-protocol.d.ts +0 -0
  46. /package/dist/{shared → event}/index.types.js +0 -0
@@ -1,23 +1,60 @@
1
- import type { Request } from "express";
2
- import type { ResponseData } from "../response";
3
- import type { Arr } from "@leyyo/common";
4
- import type { HttpCookies, HttpData, HttpHeaders, HttpMethod, HttpParams, HttpQuery } from "../shared";
1
+ import { Request } from "express";
2
+ import { ResponseData } from "../response";
3
+ import { Arr } from "@leyyo/common";
4
+ import { HttpCookies, HttpData, HttpHeaders, HttpParams, HttpQuery } from "../event";
5
+ import { HttpMethod } from "../enum";
5
6
  export interface RequestLocal {
6
7
  }
7
8
  export type RequestBody = Arr | HttpData | string | unknown;
8
9
  export type RequestErrorCallback = (error?: Error) => void;
10
+ /**
11
+ * It's used for bulk http calls
12
+ * */
9
13
  export interface MockServiceRequest<B extends RequestBody = RequestBody> {
14
+ /**
15
+ * Http method
16
+ * */
10
17
  method: HttpMethod;
18
+ /**
19
+ * Local path
20
+ * */
11
21
  url: string;
22
+ /**
23
+ * Request payload
24
+ * */
12
25
  body?: B;
26
+ /**
27
+ * Custom headers
28
+ * */
13
29
  headers?: HttpHeaders;
30
+ /**
31
+ * Client cookies
32
+ * */
14
33
  cookies?: HttpCookies;
34
+ /**
35
+ * Server cookies
36
+ * */
15
37
  signedCookies?: HttpCookies;
16
38
  }
39
+ /**
40
+ * Http mock request, it extends express request
41
+ * */
17
42
  export interface MockRequestLike<B extends RequestBody = RequestBody, L extends RequestLocal = RequestLocal> extends Request<HttpParams, B, ResponseData, HttpQuery, L> {
43
+ /**
44
+ * Indicates that it's fake/mock request
45
+ * */
18
46
  readonly isFake?: boolean;
47
+ /**
48
+ * Temporary local storage
49
+ * */
19
50
  readonly locals?: L;
51
+ /**
52
+ * Get query parameter
53
+ * */
20
54
  param(name: string, defaultValue?: any): string;
55
+ /**
56
+ * Custom properties
57
+ * */
21
58
  [another: string]: unknown;
22
59
  }
23
60
  export interface PipeOption {
@@ -1,123 +1,249 @@
1
- import type { Application, MediaType, NextFunction, Request, Response } from "express";
2
- import type { Socket } from "net";
3
- import type { IncomingHttpHeaders } from "http";
4
- import type RangeParser from "range-parser";
5
- import type { MockRequestLike, MockServiceRequest, PipeOption, RequestBody, RequestErrorCallback, RequestLocal } from "./index.types";
6
- import type { _StreamAbort, _StreamBool, _StreamCompose, _StreamGeneric, _StreamIterator, _StreamReduce, _StreamVoid, HttpCookies, HttpMethod, HttpParams, HttpProtocol, HttpQuery, HttpStatus } from "../shared";
7
- import { HttpEvent } from '../shared';
8
- import type { Dict, Fnc, OneOrMore } from "@leyyo/common";
9
- import type { ArrayOptions, Readable } from "node:stream";
1
+ import { Application, MediaType, NextFunction, Request, Response } from "express";
2
+ import { Socket } from "net";
3
+ import { IncomingHttpHeaders } from "http";
4
+ import RangeParser from "range-parser";
5
+ import { MockRequestLike, MockServiceRequest, PipeOption, RequestBody, RequestErrorCallback, RequestLocal } from "./index.types";
6
+ import { _StreamAbort, _StreamBool, _StreamCompose, _StreamGeneric, _StreamIterator, _StreamReduce, _StreamVoid, HttpCookies, HttpEvent, HttpParams, HttpQuery } from "../event";
7
+ import { Dict, Fnc, HttpStatus, OneOrMore } from "@leyyo/common";
8
+ import { ArrayOptions, Readable } from "node:stream";
9
+ import { HttpMethod, HttpProtocol } from "../enum";
10
10
  export declare class MockRequest<B extends RequestBody = RequestBody, L extends RequestLocal = RequestLocal> extends HttpEvent<Request> implements MockRequestLike<B, L> {
11
+ /** @inheritDoc */
11
12
  readonly isFake: boolean;
13
+ /** @inheritDoc */
12
14
  readonly locals: L;
15
+ /** @inheritDoc */
13
16
  [another: string]: unknown;
14
- static setFirstOrigin(origin: Request): void;
15
- static get firstOrigin(): Request;
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @param {MockServiceRequest} service - for bulk request
21
+ * @param {Request} origin - first real request
22
+ * @param {object} custom - custom values
23
+ * */
16
24
  constructor(service?: MockServiceRequest<B>, origin?: Request, custom?: Dict);
25
+ /** @inheritDoc*/
17
26
  accepted: MediaType[];
27
+ /** @inheritDoc*/
18
28
  readonly protocol: HttpProtocol;
29
+ /** @inheritDoc*/
19
30
  readonly secure: boolean;
31
+ /** @inheritDoc*/
20
32
  readonly ip: string;
33
+ /** @inheritDoc*/
21
34
  readonly ips: string[];
35
+ /** @inheritDoc*/
22
36
  readonly subdomains: string[];
37
+ /** @inheritDoc*/
23
38
  readonly path: string;
39
+ /** @inheritDoc*/
24
40
  readonly host: string;
41
+ /** @inheritDoc*/
25
42
  readonly hostname: string;
43
+ /** @inheritDoc*/
26
44
  readonly httpVersion: string;
45
+ /** @inheritDoc*/
27
46
  readonly httpVersionMajor: number;
47
+ /** @inheritDoc*/
28
48
  readonly httpVersionMinor: number;
49
+ /** @inheritDoc*/
29
50
  readonly fresh: boolean;
51
+ /** @inheritDoc*/
30
52
  readonly stale: boolean;
53
+ /** @inheritDoc*/
31
54
  readonly xhr: boolean;
55
+ /** @inheritDoc*/
32
56
  body: RequestBody;
57
+ /** @inheritDoc*/
33
58
  cookies: any;
59
+ /** @inheritDoc*/
34
60
  method: HttpMethod;
61
+ /** @inheritDoc*/
35
62
  params: HttpParams;
63
+ /** @inheritDoc*/
36
64
  query: HttpQuery;
65
+ /** @inheritDoc*/
37
66
  route: any;
67
+ /** @inheritDoc*/
38
68
  signedCookies: HttpCookies;
69
+ /** @inheritDoc*/
39
70
  originalUrl: string;
71
+ /** @inheritDoc*/
40
72
  url: string;
73
+ /** @inheritDoc*/
41
74
  baseUrl: string;
75
+ /** @inheritDoc*/
42
76
  app: Application;
77
+ /** @inheritDoc*/
43
78
  res?: Response<unknown, L>;
79
+ /** @inheritDoc*/
44
80
  next?: NextFunction;
81
+ /** @inheritDoc*/
45
82
  headers: IncomingHttpHeaders;
83
+ /** @inheritDoc*/
46
84
  is(t: OneOrMore<string>): string | false | null;
85
+ /** @inheritDoc*/
47
86
  get(n: "set-cookie"): string[] | undefined;
87
+ /** @inheritDoc*/
48
88
  get(n: string): string | undefined;
89
+ /** @inheritDoc*/
49
90
  header(n: "set-cookie"): string[] | undefined;
91
+ /** @inheritDoc*/
50
92
  header(n: string): string | undefined;
93
+ /** @inheritDoc*/
51
94
  accepts(): string[];
95
+ /** @inheritDoc*/
52
96
  accepts(t: string): string | false;
97
+ /** @inheritDoc*/
53
98
  accepts(t: string[]): string | false;
99
+ /** @inheritDoc*/
54
100
  accepts(...t: string[]): string | false;
101
+ /** @inheritDoc*/
55
102
  acceptsCharsets(): string[];
103
+ /** @inheritDoc*/
56
104
  acceptsCharsets(c: string): string | false;
105
+ /** @inheritDoc*/
57
106
  acceptsCharsets(c: string[]): string | false;
107
+ /** @inheritDoc*/
58
108
  acceptsCharsets(...c: string[]): string | false;
109
+ /** @inheritDoc*/
59
110
  acceptsEncodings(): string[];
111
+ /** @inheritDoc*/
60
112
  acceptsEncodings(e: string): string | false;
113
+ /** @inheritDoc*/
61
114
  acceptsEncodings(e: string[]): string | false;
115
+ /** @inheritDoc*/
62
116
  acceptsEncodings(...e: string[]): string | false;
117
+ /** @inheritDoc*/
63
118
  acceptsLanguages(): string[];
119
+ /** @inheritDoc*/
64
120
  acceptsLanguages(l: string): string | false;
121
+ /** @inheritDoc*/
65
122
  acceptsLanguages(l: string[]): string | false;
123
+ /** @inheritDoc*/
66
124
  acceptsLanguages(...l: string[]): string | false;
125
+ /** @inheritDoc*/
67
126
  range(s: number, o?: RangeParser.Options): RangeParser.Ranges | RangeParser.Result | undefined;
127
+ /** @inheritDoc*/
68
128
  aborted: boolean;
129
+ /** @inheritDoc*/
69
130
  complete: boolean;
131
+ /** @inheritDoc*/
70
132
  statusCode: HttpStatus | undefined;
133
+ /** @inheritDoc*/
71
134
  statusMessage: string | undefined;
135
+ /** @inheritDoc*/
72
136
  socket: Socket;
137
+ /** @inheritDoc*/
73
138
  headersDistinct: NodeJS.Dict<string[]>;
139
+ /** @inheritDoc*/
74
140
  rawHeaders: string[];
141
+ /** @inheritDoc*/
75
142
  trailers: Record<string, string>;
143
+ /** @inheritDoc*/
76
144
  rawTrailers: string[];
145
+ /** @inheritDoc*/
77
146
  trailersDistinct: NodeJS.Dict<string[]>;
147
+ /** @inheritDoc*/
78
148
  get connection(): Socket;
149
+ /** @inheritDoc*/
79
150
  destroy(_e?: Error): this;
151
+ /** @inheritDoc*/
80
152
  setTimeout(_m: number, _c?: Fnc): this;
153
+ /** @inheritDoc*/
81
154
  [Symbol.asyncIterator](): AsyncIterableIterator<any>;
155
+ /** @inheritDoc*/
82
156
  [Symbol.asyncDispose](): Promise<void>;
157
+ /** @inheritDoc*/
83
158
  readonly closed: boolean;
159
+ /** @inheritDoc*/
84
160
  readonly errored: Error;
161
+ /** @inheritDoc*/
85
162
  destroyed: boolean;
163
+ /** @inheritDoc*/
86
164
  readonly readableDidRead: boolean;
165
+ /** @inheritDoc*/
87
166
  readonly readableEncoding: BufferEncoding | null;
167
+ /** @inheritDoc*/
88
168
  readonly readableEnded: boolean;
169
+ /** @inheritDoc*/
89
170
  readonly readableAborted: boolean;
171
+ /** @inheritDoc*/
90
172
  readonly readableFlowing: boolean | null;
173
+ /** @inheritDoc*/
91
174
  readonly readableHighWaterMark: number;
175
+ /** @inheritDoc*/
92
176
  readonly readableLength: number;
177
+ /** @inheritDoc*/
93
178
  readonly readableObjectMode: boolean;
179
+ /** @inheritDoc*/
94
180
  readable: boolean;
181
+ /** @inheritDoc*/
95
182
  _construct(_c: RequestErrorCallback): void;
183
+ /** @inheritDoc*/
96
184
  _destroy(_e: Error | null, _c: RequestErrorCallback): void;
185
+ /** @inheritDoc*/
97
186
  _read(_s: number): void;
187
+ /** @inheritDoc*/
98
188
  read(_s: number | undefined): string | Buffer;
189
+ /** @inheritDoc*/
99
190
  push(_c: any, _e?: BufferEncoding): boolean;
191
+ /** @inheritDoc*/
100
192
  isPaused(): boolean;
193
+ /** @inheritDoc*/
101
194
  resume(): this;
195
+ /** @inheritDoc*/
102
196
  pause(): this;
197
+ /** @inheritDoc*/
103
198
  pipe<T extends NodeJS.WritableStream>(_d: T, _o?: PipeOption): T;
199
+ /** @inheritDoc*/
104
200
  setEncoding(_e: BufferEncoding): this;
201
+ /** @inheritDoc*/
105
202
  unpipe(_d?: NodeJS.WritableStream): this;
203
+ /** @inheritDoc*/
106
204
  unshift(_c: string | Uint8Array, _e?: BufferEncoding): void;
205
+ /** @inheritDoc*/
107
206
  wrap(_s: NodeJS.ReadableStream): this;
207
+ /** @inheritDoc*/
108
208
  asIndexedPairs(_o: _StreamAbort | undefined): Readable;
209
+ /** @inheritDoc*/
109
210
  compose<T extends NodeJS.ReadableStream>(_s: _StreamCompose | Iterable<T> | AsyncIterable<T> | T, _o: _StreamAbort | undefined): T;
211
+ /** @inheritDoc*/
110
212
  drop(_l: number, _o: _StreamAbort | undefined): Readable;
213
+ /** @inheritDoc*/
111
214
  every(_f: _StreamBool, _o: ArrayOptions | undefined): Promise<boolean>;
215
+ /** @inheritDoc*/
112
216
  filter(_f: _StreamBool, _o: ArrayOptions | undefined): Readable;
217
+ /** @inheritDoc*/
113
218
  find<T>(_f: _StreamGeneric<T>, _o: ArrayOptions | undefined): Promise<T | undefined>;
219
+ /** @inheritDoc*/
114
220
  flatMap(_f: _StreamGeneric<any>, _o: ArrayOptions | undefined): Readable;
221
+ /** @inheritDoc*/
115
222
  forEach(_f: _StreamVoid, _o: ArrayOptions | undefined): Promise<void>;
223
+ /** @inheritDoc*/
116
224
  iterator(_o: _StreamIterator | undefined): NodeJS.AsyncIterator<any>;
225
+ /** @inheritDoc*/
117
226
  map(_f: _StreamGeneric<any>, _o: ArrayOptions | undefined): Readable;
227
+ /** @inheritDoc*/
118
228
  reduce<T>(_f: _StreamReduce<T>, _i: undefined, _o: _StreamAbort | undefined): Promise<T>;
229
+ /** @inheritDoc*/
119
230
  some(_f: _StreamBool, _o: ArrayOptions | undefined): Promise<boolean>;
231
+ /** @inheritDoc*/
120
232
  take(_l: number, _o: _StreamAbort | undefined): Readable;
233
+ /** @inheritDoc*/
121
234
  toArray(_o: _StreamAbort | undefined): Promise<any[]>;
235
+ /** @inheritDoc*/
122
236
  param(name: string, defaultValue?: any): string;
237
+ /**
238
+ * Set first real request
239
+ *
240
+ * @param {Request} origin
241
+ * */
242
+ static setFirstOrigin(origin: Request): void;
243
+ /**
244
+ * Get first real request
245
+ *
246
+ * @return {Request}
247
+ * */
248
+ static get firstOrigin(): Request;
123
249
  }
@@ -1,35 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MockRequest = void 0;
4
- const shared_1 = require("../shared");
4
+ const event_1 = require("../event");
5
5
  const common_1 = require("@leyyo/common");
6
- const common_2 = require("@leyyo/common");
7
6
  let _firstOrigin;
8
7
  // noinspection JSUnusedGlobalSymbols
9
- class MockRequest extends shared_1.HttpEvent {
8
+ class MockRequest extends event_1.HttpEvent {
10
9
  // endregion property
11
- // region static
12
- static setFirstOrigin(origin) {
13
- if (!_firstOrigin && origin) {
14
- _firstOrigin = origin;
15
- delete _firstOrigin.headers;
16
- delete _firstOrigin.body;
17
- delete _firstOrigin.cookies;
18
- delete _firstOrigin.params;
19
- _removePath(_firstOrigin);
20
- try {
21
- delete _firstOrigin.path;
22
- }
23
- catch (e) {
24
- // nothing
25
- }
26
- }
27
- }
28
- static get firstOrigin() {
29
- return _firstOrigin;
30
- }
31
- // endregion static
32
10
  // region constructor
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @param {MockServiceRequest} service - for bulk request
15
+ * @param {Request} origin - first real request
16
+ * @param {object} custom - custom values
17
+ * */
33
18
  constructor(service, origin, custom) {
34
19
  super(origin);
35
20
  _attachOrigin(this, origin);
@@ -37,171 +22,243 @@ class MockRequest extends shared_1.HttpEvent {
37
22
  _attachCustom(this, custom);
38
23
  _checkRoute(this);
39
24
  }
25
+ /** @inheritDoc*/
40
26
  is(t) {
41
27
  var _a, _b;
42
28
  return (_b = (_a = this._origin) === null || _a === void 0 ? void 0 : _a.is(t)) !== null && _b !== void 0 ? _b : false;
43
29
  }
30
+ /** @inheritDoc*/
44
31
  get(n) {
45
32
  return this.header(n);
46
33
  }
34
+ /** @inheritDoc*/
47
35
  header(n) {
48
36
  return (typeof n === 'string') ? this.headers[n] : undefined;
49
37
  }
38
+ /** @inheritDoc*/
50
39
  accepts(...t) {
51
40
  var _a;
52
41
  return (_a = this._origin) === null || _a === void 0 ? void 0 : _a.accepts(...t);
53
42
  }
43
+ /** @inheritDoc*/
54
44
  acceptsCharsets(...c) {
55
45
  var _a;
56
46
  return (_a = this._origin) === null || _a === void 0 ? void 0 : _a.acceptsCharsets(...c);
57
47
  }
48
+ /** @inheritDoc*/
58
49
  acceptsEncodings(...e) {
59
50
  var _a;
60
51
  return (_a = this._origin) === null || _a === void 0 ? void 0 : _a.acceptsEncodings(...e);
61
52
  }
53
+ /** @inheritDoc*/
62
54
  acceptsLanguages(...l) {
63
55
  var _a;
64
56
  return (_a = this._origin) === null || _a === void 0 ? void 0 : _a.acceptsLanguages(...l);
65
57
  }
58
+ /** @inheritDoc*/
66
59
  range(s, o) {
67
60
  var _a, _b;
68
61
  return (_b = (_a = this._origin) === null || _a === void 0 ? void 0 : _a.range(s, o)) !== null && _b !== void 0 ? _b : -1;
69
62
  }
63
+ /** @inheritDoc*/
70
64
  get connection() {
71
65
  logger.warn('Should not be called', { fn: 'connection' });
72
66
  return this.socket;
73
67
  }
68
+ /** @inheritDoc*/
74
69
  destroy(_e) {
75
70
  logger.warn('Should not be called', { fn: 'destroy' });
76
71
  return this;
77
72
  }
73
+ /** @inheritDoc*/
78
74
  setTimeout(_m, _c) {
79
75
  logger.warn('Should not be called', { fn: 'setTimeout' });
80
76
  return this;
81
77
  }
82
78
  // endregion http
83
79
  // region stream
80
+ /** @inheritDoc*/
84
81
  [Symbol.asyncIterator]() {
85
82
  logger.warn('Should not be called', { fn: 'asyncIterator' });
86
83
  return this._origin ? this._origin[Symbol.asyncIterator]() : undefined;
87
84
  }
85
+ /** @inheritDoc*/
88
86
  [Symbol.asyncDispose]() {
89
87
  logger.warn('Should not be called', { fn: 'asyncDispose' });
90
- return this._origin ? this._origin[Symbol.asyncDispose]() : (0, common_2.delay)(100);
88
+ return this._origin ? this._origin[Symbol.asyncDispose]() : (0, common_1.delay)(100);
91
89
  }
90
+ /** @inheritDoc*/
92
91
  _construct(_c) {
93
92
  logger.warn('Should not be called', { fn: '_construct' });
94
93
  }
94
+ /** @inheritDoc*/
95
95
  _destroy(_e, _c) {
96
96
  logger.warn('Should not be called', { fn: '_destroy' });
97
97
  }
98
+ /** @inheritDoc*/
98
99
  _read(_s) {
99
100
  logger.warn('Should not be called', { fn: '_read' });
100
101
  }
102
+ /** @inheritDoc*/
101
103
  read(_s) {
102
104
  logger.warn('Should not be called', { fn: 'read' });
103
105
  return undefined;
104
106
  }
107
+ /** @inheritDoc*/
105
108
  push(_c, _e) {
106
109
  logger.warn('Should not be called', { fn: 'push' });
107
110
  return false;
108
111
  }
112
+ /** @inheritDoc*/
109
113
  isPaused() {
110
114
  logger.warn('Should not be called', { fn: 'isPaused' });
111
115
  return false;
112
116
  }
117
+ /** @inheritDoc*/
113
118
  resume() {
114
119
  logger.warn('Should not be called', { fn: 'resume' });
115
120
  return this;
116
121
  }
122
+ /** @inheritDoc*/
117
123
  pause() {
118
124
  logger.warn('Should not be called', { fn: 'pause' });
119
125
  return this;
120
126
  }
127
+ /** @inheritDoc*/
121
128
  pipe(_d, _o) {
122
129
  logger.warn('Should not be called', { fn: 'pipe' });
123
130
  return undefined;
124
131
  }
132
+ /** @inheritDoc*/
125
133
  setEncoding(_e) {
126
134
  logger.warn('Should not be called', { fn: 'setEncoding' });
127
135
  return this;
128
136
  }
137
+ /** @inheritDoc*/
129
138
  unpipe(_d) {
130
139
  logger.warn('Should not be called', { fn: 'unpipe' });
131
140
  return this;
132
141
  }
142
+ /** @inheritDoc*/
133
143
  unshift(_c, _e) {
134
144
  logger.warn('Should not be called', { fn: 'unshift' });
135
145
  }
146
+ /** @inheritDoc*/
136
147
  wrap(_s) {
137
148
  logger.warn('Should not be called', { fn: 'wrap' });
138
149
  return this;
139
150
  }
151
+ /** @inheritDoc*/
140
152
  asIndexedPairs(_o) {
141
153
  logger.warn('Should not be called', { fn: 'asIndexedPairs' });
142
154
  return undefined;
143
155
  }
156
+ /** @inheritDoc*/
144
157
  compose(_s, _o) {
145
158
  logger.warn('Should not be called', { fn: 'compose' });
146
159
  return undefined;
147
160
  }
161
+ /** @inheritDoc*/
148
162
  drop(_l, _o) {
149
163
  logger.warn('Should not be called', { fn: 'drop' });
150
164
  return undefined;
151
165
  }
166
+ /** @inheritDoc*/
152
167
  every(_f, _o) {
153
168
  logger.warn('Should not be called', { fn: 'every' });
154
- return (0, common_2.delay)(10, false);
169
+ return (0, common_1.delay)(10, false);
155
170
  }
171
+ /** @inheritDoc*/
156
172
  filter(_f, _o) {
157
173
  logger.warn('Should not be called', { fn: 'filter' });
158
174
  return undefined;
159
175
  }
176
+ /** @inheritDoc*/
160
177
  find(_f, _o) {
161
178
  logger.warn('Should not be called', { fn: 'find' });
162
- return (0, common_2.delay)(10);
179
+ return (0, common_1.delay)(10);
163
180
  }
181
+ /** @inheritDoc*/
164
182
  flatMap(_f, _o) {
165
183
  logger.warn('Should not be called', { fn: 'flatMap' });
166
184
  return undefined;
167
185
  }
186
+ /** @inheritDoc*/
168
187
  forEach(_f, _o) {
169
188
  logger.warn('Should not be called', { fn: 'forEach' });
170
- return (0, common_2.delay)(10);
189
+ return (0, common_1.delay)(10);
171
190
  }
191
+ /** @inheritDoc*/
172
192
  iterator(_o) {
173
193
  logger.warn('Should not be called', { fn: 'iterator' });
174
194
  return undefined;
175
195
  }
196
+ /** @inheritDoc*/
176
197
  map(_f, _o) {
177
198
  logger.warn('Should not be called', { fn: 'map' });
178
199
  return undefined;
179
200
  }
201
+ /** @inheritDoc*/
180
202
  reduce(_f, _i, _o) {
181
203
  logger.warn('Should not be called', { fn: 'reduce' });
182
- return (0, common_2.delay)(10);
204
+ return (0, common_1.delay)(10);
183
205
  }
206
+ /** @inheritDoc*/
184
207
  some(_f, _o) {
185
208
  logger.warn('Should not be called', { fn: 'some' });
186
- return (0, common_2.delay)(10, false);
209
+ return (0, common_1.delay)(10, false);
187
210
  }
211
+ /** @inheritDoc*/
188
212
  take(_l, _o) {
189
213
  logger.warn('Should not be called', { fn: 'take' });
190
214
  return undefined;
191
215
  }
216
+ /** @inheritDoc*/
192
217
  toArray(_o) {
193
218
  logger.warn('Should not be called', { fn: 'toArray' });
194
- return (0, common_2.delay)(10, []);
219
+ return (0, common_1.delay)(10, []);
195
220
  }
196
221
  // endregion stream
197
222
  // region method
223
+ /** @inheritDoc*/
198
224
  param(name, defaultValue) {
199
225
  var _a;
200
226
  return (_a = this.params[name]) !== null && _a !== void 0 ? _a : defaultValue;
201
227
  }
228
+ // endregion method
229
+ // region static
230
+ /**
231
+ * Set first real request
232
+ *
233
+ * @param {Request} origin
234
+ * */
235
+ static setFirstOrigin(origin) {
236
+ if (!_firstOrigin && origin) {
237
+ _firstOrigin = origin;
238
+ delete _firstOrigin.headers;
239
+ delete _firstOrigin.body;
240
+ delete _firstOrigin.cookies;
241
+ delete _firstOrigin.params;
242
+ _removePath(_firstOrigin);
243
+ try {
244
+ delete _firstOrigin.path;
245
+ }
246
+ catch (e) {
247
+ // nothing
248
+ }
249
+ }
250
+ }
251
+ /**
252
+ * Get first real request
253
+ *
254
+ * @return {Request}
255
+ * */
256
+ static get firstOrigin() {
257
+ return _firstOrigin;
258
+ }
202
259
  }
203
260
  exports.MockRequest = MockRequest;
204
- const logger = common_1.$log.create(MockRequest);
261
+ const logger = (0, common_1.newLogger)(MockRequest);
205
262
  // region functions
206
263
  function _removePath(req) {
207
264
  try {
@@ -211,6 +268,12 @@ function _removePath(req) {
211
268
  // nothing
212
269
  }
213
270
  }
271
+ /**
272
+ * Attach service to request
273
+ *
274
+ * @param {Request} req - request
275
+ * @param {MockServiceRequest} service - service request object
276
+ * */
214
277
  function _attachService(req, service) {
215
278
  var _a, _b, _g, _h, _j;
216
279
  if (!service) {
@@ -231,14 +294,27 @@ function _attachService(req, service) {
231
294
  req.cookies = (_h = service === null || service === void 0 ? void 0 : service.cookies) !== null && _h !== void 0 ? _h : {};
232
295
  req.signedCookies = (_j = service === null || service === void 0 ? void 0 : service.signedCookies) !== null && _j !== void 0 ? _j : {};
233
296
  }
234
- function _attachOrigin(req, origin) {
297
+ /**
298
+ * Attach first real request
299
+ *
300
+ * @param {Request} _req
301
+ * @param {Request} origin
302
+ * */
303
+ function _attachOrigin(_req, origin) {
235
304
  origin = origin !== null && origin !== void 0 ? origin : _firstOrigin;
236
305
  if (origin) {
306
+ // Clear specific values
237
307
  origin.body = undefined;
238
308
  origin.params = {};
239
309
  _removePath(origin);
240
310
  }
241
311
  }
312
+ /**
313
+ * Attach custom object to request
314
+ *
315
+ * @param {Request} req
316
+ * @param {object} custom
317
+ * */
242
318
  function _attachCustom(req, custom) {
243
319
  if (custom) {
244
320
  for (const [key, value] of Object.entries(custom)) {
@@ -248,6 +324,11 @@ function _attachCustom(req, custom) {
248
324
  }
249
325
  }
250
326
  }
327
+ /**
328
+ * Check route
329
+ *
330
+ * @param {Request} req
331
+ * */
251
332
  function _checkRoute(req) {
252
333
  if (!req.route) {
253
334
  req.route = {