@n1k1t/mock-server 0.1.14 → 0.1.15

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.
package/README.md CHANGED
@@ -34,7 +34,6 @@ Mock, match, modify and manipulate a HTTP request/response payload using flexibl
34
34
  - [Configuration](#configuration)
35
35
  - [Logger](#logger)
36
36
  - [Meta](#meta)
37
- - [Plugins](#plugins)
38
37
 
39
38
  # Basics
40
39
 
@@ -167,8 +166,8 @@ await server.client.createExpectation({
167
166
  | | path | `path` | `string` | | Incoming request path |
168
167
  | | method | `method` | `string` | | Incoming request method in **uppercase** |
169
168
  | | headers | `incoming.headers` | `object` | | Incoming request headers with keys in **lowercase** |
170
- | | bodyRaw | `incoming.bodyRaw` | `string` | | Incoming request source body |
171
- | | body | `incoming.body` | `object` | * | Incoming request parsed body |
169
+ | | dataRaw | `incoming.dataRaw` | `string` | | Incoming request source data |
170
+ | | data | `incoming.data` | `object` | * | Incoming request parsed data |
172
171
  | | query | `incoming.query` | `object` | * | Incoming request query search parameters |
173
172
  | | delay | `delay` | `number` | * | Delay that can be applied with [operators](#operators) |
174
173
  | | error | `error` | `string` | * | Error that can be applied with [operators](#operators) |
@@ -302,7 +301,7 @@ await server.client.createExpectation({
302
301
  schema: {
303
302
  request: {
304
303
  $set: {
305
- $location: 'incoming.body',
304
+ $location: 'incoming.data',
306
305
  $path: 'foo',
307
306
  $exec: (payload, { _ }) => _.clamp(payload, 0, 10),
308
307
  },
@@ -319,7 +318,7 @@ curl -H "Content-type: application/json" -X POST --location "localhost:8080/_moc
319
318
  "schema": {
320
319
  "request": {
321
320
  "\$set": {
322
- "\$location": "incoming.body",
321
+ "\$location": "incoming.data",
323
322
  "\$path": "foo",
324
323
  "\$exec": "_.clamp(payload, 0, 10)"
325
324
  }
@@ -348,7 +347,7 @@ await server.client.createExpectation({
348
347
  schema: {
349
348
  request: {
350
349
  $merge: {
351
- $location: 'incoming.body',
350
+ $location: 'incoming.data',
352
351
  $value: { has_mocked: true },
353
352
  },
354
353
  },
@@ -364,7 +363,7 @@ curl -H "Content-type: application/json" -X POST --location "localhost:8080/_moc
364
363
  "schema": {
365
364
  "request": {
366
365
  "\$merge": {
367
- "\$location": "incoming.body",
366
+ "\$location": "incoming.data",
368
367
  "\$value": {"has_mocked": true}
369
368
  }
370
369
  }
@@ -723,7 +722,7 @@ Storage is a temporary storage that provides an access to read/write [containers
723
722
  | register | `(configuration: Container) => Container` | Registers a container in storage (overrides if existent) |
724
723
  | provide | `(configuration: Container) => Container` | Finds or registers a container in storage |
725
724
 
726
- As a temporary storage it has a job to garbage an expired containers. Use `containers.garbageInterval` to setup an interval of clearance in [configuration](#configuration)
725
+ As a temporary storage it has a job to garbage an expired containers. Use `containers.expiredCleaningInterval` to setup an interval of clearance in [configuration](#configuration)
727
726
 
728
727
  > **!NOTE** See example of usage in [containers](#containers) section below
729
728
 
@@ -779,7 +778,7 @@ To work with cache the mock server uses [ioredis](https://www.npmjs.com/package/
779
778
  2. Preparing [request schema](#schema) in expectation...
780
779
  3. Setting up cache configuration from [context](#context) or [forward.cache](#forwarding)...
781
780
  4. If `cache.isEnabled` is equals `true` the mock server checks a cache using provided configuration
782
- 5. If `key` was not provided a key for cache will calculated with `path`, `method`, `body` and `query` property values using [FNV1A-64](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) algorithm
781
+ 5. If `key` was not provided a key for cache will calculated with `path`, `method`, `data` and `query` property values using [FNV1A-64](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) algorithm
783
782
  6. If cache was found then step `7` is skipping
784
783
  7. Forwarding a request....
785
784
  8. Preparing [response schema](#schema) in expectation...
@@ -1158,7 +1157,7 @@ config.merge({
1158
1157
  },
1159
1158
 
1160
1159
  containers: {
1161
- garbageInterval: 60 * 60, // Containers clearance interval in seconds (default: 1h)
1160
+ expiredCleaningInterval: 60 * 60, // Expired containers cleaning interval in seconds (default: 1h)
1162
1161
  },
1163
1162
  });
1164
1163
  ```
@@ -1237,117 +1236,3 @@ await server.client.createExpectation({
1237
1236
  },
1238
1237
  });
1239
1238
  ```
1240
-
1241
- ## Plugins
1242
-
1243
- > **!NOTE** Configuration must be provided in the same script like mock server
1244
-
1245
- | Plugin | Description |
1246
- |--|--|
1247
- | [`incoming.body`](#incomingbody) | Describes how to handle incoming body |
1248
- | [`outgoing.response`](#outgoingresponse) | Describes how to reply |
1249
- | [`forward.request`](#forwardrequest) | Describes how provide an [axios](https://www.npmjs.com/package/axios) request config to forward a request |
1250
- | [`forward.response`](#forwardresponse) | Describes how to parse [axios](https://www.npmjs.com/package/axios) response of a forwarded request |
1251
-
1252
- ### incoming.body
1253
-
1254
- `INPUT`
1255
-
1256
- | Argument | Type | Description |
1257
- |--|--|--|
1258
- | request | `http.IncomingMessage` | Raw HTTP request |
1259
-
1260
- `OUTPUT`
1261
-
1262
- | Property | Type | Optional | Description |
1263
- |--|--|--|--|
1264
- | raw | `string` | | Serialized incoming request body |
1265
- | type | `xml ∣ json ∣ plain` | * | A type of `payload` |
1266
- | payload | `object` | * | A payload object |
1267
-
1268
- **Example**
1269
-
1270
- ```ts
1271
- server.context.plugins.register('incoming.body', async (request) => {
1272
- let raw = '';
1273
-
1274
- request.on('data', chunk => raw += chunk);
1275
- await new Promise(resolve => request.on('end', resolve));
1276
-
1277
- return { raw };
1278
- });
1279
- ```
1280
-
1281
- ### outgoing.response
1282
-
1283
- `INPUT`
1284
-
1285
- | Argument | Type | Description |
1286
- |--|--|--|
1287
- | response | `http.ServerResponse` | Raw HTTP response |
1288
- | context | `object` | A request [context](#context) |
1289
-
1290
- `OUTPUT`
1291
-
1292
- | Type | Description |
1293
- |--|--|
1294
- | `unknown` | Result is not handing |
1295
-
1296
- **Example**
1297
-
1298
- ```ts
1299
- server.context.plugins.register('outgoing.response', (response, context) => {
1300
- context.response.writeHead(context.outgoing.status ?? 200, context.outgoing.headers);
1301
- context.response.write(context.outgoing.dataRaw);
1302
- context.response.end();
1303
- });
1304
- ```
1305
-
1306
- ### forward.request
1307
-
1308
- `INPUT`
1309
-
1310
- | Argument | Type | Description |
1311
- |--|--|--|
1312
- | config | `AxiosRequestConfig` | An [axios](https://www.npmjs.com/package/axios) request config |
1313
- | context | `object` | A request [context](#context) |
1314
-
1315
- `OUTPUT`
1316
-
1317
- | Type | Description |
1318
- |--|--|
1319
- | `AxiosRequestConfig` | An [axios](https://www.npmjs.com/package/axios) request config |
1320
-
1321
- **Example**
1322
-
1323
- ```ts
1324
- server.context.plugins.register('forward.request', (config) => ({
1325
- ...config,
1326
- url: config.url.replace('/api_v1', '/api_v2'),
1327
- }));
1328
- ```
1329
-
1330
- ### forward.response
1331
-
1332
- `INPUT`
1333
-
1334
- | Argument | Type | Description |
1335
- |--|--|--|
1336
- | config | `AxiosResponse` | An [axios](https://www.npmjs.com/package/axios) response |
1337
- | context | `object` | A request [context](#context) |
1338
-
1339
- `OUTPUT`
1340
-
1341
- | Property | Type | Optional | Description |
1342
- |--|--|--|--|
1343
- | raw | `string` | | Serialized incoming request body |
1344
- | type | `xml ∣ json ∣ plain` | * | A type of `payload` |
1345
- | payload | `object` | * | A payload object |
1346
-
1347
- **Example**
1348
-
1349
- ```ts
1350
- server.context.plugins.register('forward.response', async (response: AxiosResponse<Buffer>) => ({
1351
- raw: response.data.toString(),
1352
- }));
1353
- ```