mockaton 8.0.0 → 8.0.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.
package/README.md CHANGED
@@ -102,7 +102,7 @@ api/user(default).GET.200.json
102
102
 
103
103
  ## You can write JSON mocks in JavaScript or TypeScript
104
104
 
105
- An Object, Array, or String is sent as JSON.
105
+ **Option A:** An Object, Array, or String is sent as JSON.
106
106
 
107
107
  `api/foo.GET.200.js`
108
108
  ```js
@@ -111,29 +111,32 @@ export default [
111
111
  ]
112
112
  ```
113
113
 
114
- Or, export default a function. In it, you can override the
115
- response status and the default JSON content type. But don’t call
116
- `response.end()`, just return a `string`, `Buffer`, or `Uint8Array`.
114
+ **Option B:** Function
117
115
 
118
116
  Think of this as an HTTP handler. You can read or write to a
119
- database, or pull data from a backend. The `request` is of type
120
- [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage), and the
121
- `response` a [ServerResponse](https://nodejs.org/api/http.html#class-httpserverresponse).
117
+ database, or pull data from a backend.
118
+
119
+ Don’t call `response.end()`, just return a `string | Buffer | Uint8Array`.
120
+
122
121
  ```js
123
122
  export default function optionalName(request, response) {
124
123
  globalThis.myDatabase ??= { count: 0 }
125
124
  globalThis.myDatabase.count++
126
125
 
126
+ // Optinally, you can override these two:
127
+ repsonse.statusCode = 200
128
+ response.setHeader('Content-Type', 'application/json')
129
+
127
130
  return JSON.stringify({ a: 1 })
128
131
  }
129
132
  ```
130
133
 
131
- If you need to serve a static `.js` file, put it in your `Config.staticDir`.
134
+ If you need to serve a static `.js` file, put it in your
135
+ `Config.staticDir` without the mock filename convention.
132
136
 
133
137
  ---
134
138
 
135
- ## File Name Convention
136
- This convention is only for files within your `Config.mocksDir`.
139
+ ## Mock File Name Convention
137
140
 
138
141
  ### Extension
139
142
 
@@ -274,7 +277,7 @@ Config.extraMimes = {
274
277
  }
275
278
  ```
276
279
 
277
- ### `plugins?: [filenameTester: RegExp, plugin: Plugin][]
280
+ ### `plugins?: [filenameTester: RegExp, plugin: Plugin][]`
278
281
  ```ts
279
282
  type Plugin = (
280
283
  filePath: string,
package/index.d.ts CHANGED
@@ -40,6 +40,7 @@ interface Config {
40
40
 
41
41
  export function Mockaton(options: Config): Server
42
42
 
43
+ export const jsToJsonPlugin: Plugin
43
44
 
44
45
  export function jwtCookie(cookieName: string, payload: any): string
45
46
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "8.0.0",
5
+ "version": "8.0.2",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",