Skip to content

Commit

Permalink
#102 🐘 fix types in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RiceWithMeat committed Dec 20, 2024
1 parent 219b847 commit 87367e4
Showing 1 changed file with 103 additions and 103 deletions.
206 changes: 103 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ $ npx mock-config-server
## 🎭 Parameters for mock-server.config.(js|ts)

- `rest?` Rest configs for mock requests
- `baseUrl?` {string} part of the url that will be substituted at the beginning of rest request url (default: `'/'`)
- `configs` {Array<RestRequestConfig>} configs for mock requests, [read](#configs)
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `baseUrl?` `string` part of the url that will be substituted at the beginning of rest request url (default: `'/'`)
- `configs` `Array<RestRequestConfig>` configs for mock requests, [read](#configs)
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)
- `graphql?` GraphQL configs for mock requests
- `baseUrl?` {string} part of the url that will be substituted at the beginning of graphql request url (default: `'/'`)
- `configs` {Array<GraphQLRequestConfig>} configs for mock requests, [read](#configs)
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `baseUrl?` `string` part of the url that will be substituted at the beginning of graphql request url (default: `'/'`)
- `configs` `Array<GraphQLRequestConfig>` configs for mock requests, [read](#configs)
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)
- `database?` Database config for mock requests [read](#database)
- `data` {Object | string} initial data for database
- `routes?` {Object | string} map of custom routes for database
- `staticPath?` {StaticPath} entity for working with static files, [read](#static-path)
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `cors?` {Cors} CORS settings object (default: `CORS is turn off`), [read](#cors)
- `port?` {number} server port (default: `31299`)
- `baseUrl?` {string} part of the url that will be substituted at the beginning of the request url (default: `'/'`)
- `data` `Object | string` initial data for database
- `routes?` `Object | string` map of custom routes for database
- `staticPath?` `StaticPath` entity for working with static files, [read](#static-path)
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)
- `cors?` `Cors` CORS settings object (default: `CORS is turn off`), [read](#cors)
- `port?` `number` server port (default: `31299`)
- `baseUrl?` `string` part of the url that will be substituted at the beginning of the request url (default: `'/'`)

### Configs

Expand All @@ -90,16 +90,16 @@ Configs are the fundamental part of the mock server. These configs are easy to f

Every route must be configured to handle response content in one of three ways: data or [queue](#polling) or [file](#file-responses).

- `path` {string | RegExp} request path
- `method` {get | post | delete | put | patch | options} rest api method
- `routes` {RestRouteConfig[]} request routes
- `data?` {any} mock data of request
- `queue?` {Array<{ time?: number; data: any}>} queue for polling with opportunity to set time for each response
- `file?` {string} path to file for return in response
- `settings?` {Settings} settings for route (polling on/off, etc.)
- `entities?` {Object<headers | cookies | query | params | body>} object that helps in data retrieval
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `path` `string | RegExp` request path
- `method` `'get' | 'post' | 'delete' | 'put' | 'patch' | 'options'` rest api method
- `routes` `RestRouteConfig[]` request routes
- `data?` `any` mock data of request
- `queue?` `Array<{ time?: number; data: any}>` queue for polling with opportunity to set time for each response
- `file?` `string` path to file for return in response
- `settings?` `Settings` settings for route (polling on/off, etc.)
- `entities?` `Object<headers | cookies | query | params | body>` object that helps in data retrieval
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)

##### Rest example

Expand Down Expand Up @@ -151,16 +151,16 @@ fetch('http://localhost:31299/api/user', {

Every route must be configured to handle response content in one of two ways: data or [queue](#polling).

- `operationType` {query | mutation} graphql operation type
- `operationName?` {string | RegExp} graphql operation name
- `query?`: {string} graphql query as string
- `routes` {GraphQLRouteConfig[]} request routes
- `data?` {any} mock data of request
- `queue?` {Array<{ time?: number; data: any}>} queue for polling with opportunity to set time for each response
- `settings?` {Settings} settings for route (polling on/off, etc.)
- `entities?` {Object<headers | cookies | query | variables>} object that helps in data retrieval
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `interceptors?` {Interceptors} functions to change request or response parameters, [read](#interceptors)
- `operationType` `query | mutation` graphql operation type
- `operationName?` `string | RegExp` graphql operation name
- `query?`: `string` graphql query as string
- `routes` `GraphQLRouteConfig[]` request routes
- `data?` `any` mock data of request
- `queue?` `Array<{ time?: number; data: any}>` queue for polling with opportunity to set time for each response
- `settings?` `Settings` settings for route (polling on/off, etc.)
- `entities?` `Object<headers | cookies | query | variables>` object that helps in data retrieval
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)
- `interceptors?` `Interceptors` functions to change request or response parameters, [read](#interceptors)

> Every graphql config should contain `operationName` or `query` or both of them
Expand Down Expand Up @@ -587,76 +587,76 @@ Entity for connecting statics to the server, like HTML, JSON, PNG, etc.

- `string` path to your static files
- `Object<{prefix, path}`
- `prefix` {string} path prefix for request
- `path` {string} path to your static files
- `prefix` `string` path prefix for request
- `path` `string` path to your static files
- `Array<string | Object<{prefix, path}>>`

#### Cors

Object with settings for [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). You can flexibly configure the required origin, methods, headers, credentials, maxAge for the entire server. If you do not specify `CORS` settings, then it will be disabled.

- `origin` {string | RegExp | Array<string | RegExp> | Function | Promise } available origins from which requests can be made
- `methods?` {Array<GET | POST | DELETE | PUT | PATCH>} available methods (default: `GET,OPTIONS,PUT,PATCH,POST,DELETE`)
- `allowedHeaders?` {Array<string>} allowed headers (default: `*`)
- `exposedHeaders?` {Array<string>} exposed headers (default: `*`)
- `credentials?` {boolean} param tells browsers whether to expose the response to the frontend JavaScript code (default: `true`)
- `maxAge?` {number} how long the results can be cached (default: `3600`)
- `origin` `string | RegExp | Array<string | RegExp> | Function | Promise` available origins from which requests can be made
- `methods?` `Array<GET | POST | DELETE | PUT | PATCH>` available methods (default: `GET,OPTIONS,PUT,PATCH,POST,DELETE`)
- `allowedHeaders?` `Array<string>` allowed headers (default: `*`)
- `exposedHeaders?` `Array<string>` exposed headers (default: `*`)
- `credentials?` `boolean` param tells browsers whether to expose the response to the frontend JavaScript code (default: `true`)
- `maxAge?` `number` how long the results can be cached (default: `3600`)

#### Interceptors

Functions to change request or response parameters

- `request?` {(params) => void}
- `response?` {(data, params) => any}
- `request?` `(params) => void`
- `response?` `(data, params) => any`

> request interceptors (except interceptor for route) are called regardless of whether the server found a route match or not. So changes in request interceptors can affect whether the server finds the route or not
##### Request

- `params`
- `request` request object
- `setDelay` {(delay) => Promise<void>}
- `delay` {number} milliseconds of delay time
- `getHeader` {(field) => string | number | string[] | undefined}
- `field` {string} name of response header
- `getHeaders` {() => Record<string | number | string[] | undefined>}
- `getCookie` {(name) => string | undefined}
- `name` {string} name of cookie
- `log` {(logger) => Partial<LoggerTokenValues> | null} logger function [read](#logger)
- `logger` {Logger | undefined} logger options
- `setDelay` `(delay) => Promise<void>`
- `delay` `number` milliseconds of delay time
- `getHeader` `(field) => string | number | string[] | undefined`
- `field` `string` name of response header
- `getHeaders` `() => Record<string | number | string[] | undefined>`
- `getCookie` `(name) => string | undefined`
- `name` `string` name of cookie
- `log` `(logger) => Partial<LoggerTokenValues> | null` logger function [read](#logger)
- `logger` `Logger | undefined` logger options

##### Response

- `data` {any} mock data of request
- `data` `any` mock data of request
- `params`
- `request` request object
- `response` response object
- `setDelay` {(delay) => Promise<void>}
- `delay` {number} milliseconds of delay time
- `setStatusCode` {(statusCode) => void}
- `statusCode` {number} status code for response
- `setHeader` {(field, value) => void}
- `field` {string} name of response header
- `value` {string | string[] | undefined} value of response header
- `appendHeader` {(field, value) => void}
- `field` {string} name of response header
- `value` {string | string[] | undefined} value of response header
- `getHeader` {(field) => string | number | string[] | undefined}
- `field` {string} name of response header
- `getHeaders` {() => Record<string | number | string[] | undefined>}
- `setCookie` {(name, value, options) => void}
- `name` {string} name of cookie
- `value` {string} value of cookie
- `options` {[CookieOptions](https://expressjs.com/en/resources/middleware/cookie-session.html) | undefined} cookie options (like path, expires, etc.)
- `getCookie` {(name) => string | undefined}
- `name` {string} name of cookie
- `clearCookie` {(name, options) => void}
- `name` {string} name of cookie
- `options` {[CookieOptions](https://expressjs.com/en/resources/middleware/cookie-session.html) | undefined} cookie options (like path, expires, etc.)
- `attachment` {(filename) => void}
- `filename` {string} name of file in 'Content-Disposition' header
- `log` {(logger) => Partial<LoggerTokenValues> | null} logger function [read](#logger)
- `logger` {Logger | undefined} logger options
- `setDelay` `(delay) => Promise<void>`
- `delay` `number` milliseconds of delay time
- `setStatusCode` `(statusCode) => void`
- `statusCode` `number` status code for response
- `setHeader` `(field, value) => void`
- `field` `string` name of response header
- `value` `string | string[] | undefined` value of response header
- `appendHeader` `(field, value) => void`
- `field` `string` name of response header
- `value` `string | string[] | undefined` value of response header
- `getHeader` `(field) => string | number | string[] | undefined`
- `field` `string` name of response header
- `getHeaders` `() => Record<string | number | string[] | undefined>`
- `setCookie` `(name, value, options) => void`
- `name` `string` name of cookie
- `value` `string` value of cookie
- `options` `[CookieOptions](https://expressjs.com/en/resources/middleware/cookie-session.html) | undefined` cookie options (like path, expires, etc.)
- `getCookie` `(name) => string | undefined`
- `name` `string` name of cookie
- `clearCookie` `(name, options) => void`
- `name` `string` name of cookie
- `options` `[CookieOptions](https://expressjs.com/en/resources/middleware/cookie-session.html) | undefined` cookie options (like path, expires, etc.)
- `attachment` `(filename) => void`
- `filename` `string` name of file in 'Content-Disposition' header
- `log` `(logger) => Partial<LoggerTokenValues> | null` logger function [read](#logger)
- `logger` `Logger | undefined` logger options

#### Logger

Expand All @@ -666,8 +666,8 @@ You can log requests and responses using `log` function in any [interceptor](#in

`logger` parameter has the following optional properties

- `enabled` {boolean} draw log or not, `true` by default
- `tokenOptions` {LoggerTokenOptions} object map containing tokens to log. Keys is token names, values is boolean. `true` will add token into log, `false` will remove. If tokenOptions is not passed, following tokens will be logged
- `enabled` `boolean` draw log or not, `true` by default
- `tokenOptions` `LoggerTokenOptions` object map containing tokens to log. Keys is token names, values is boolean. `true` will add token into log, `false` will remove. If tokenOptions is not passed, following tokens will be logged
- Request
- type
- id
Expand All @@ -681,7 +681,7 @@ You can log requests and responses using `log` function in any [interceptor](#in
- method
- url
- data
- `rewrite` {(tokenValues: Partial<LoggerTokenValues>) => void} function to customize log default `console.dir(tokenValues, { depth: null })` appearance
- `rewrite` `(tokenValues: Partial<LoggerTokenValues>) => void` function to customize log default `console.dir(tokenValues, { depth: null })` appearance

returns object with logged token values or `null` if log was not `enabled`

Expand Down Expand Up @@ -742,23 +742,23 @@ export default mockServerConfig;
##### Logger tokens

- `type` {'request' | 'response'} type of log
- `id` {number} unique id of request to reference request log with response log
- `timestamp` {number} UNIX-timestamp in milliseconds
- `method` {'get' | 'post' | 'delete' | 'put' | 'patch' | 'options'} HTTP method
- `url` {string} requested URL
- `graphQLOperationType` {'query' | 'mutation' | null} GraphQL operation type. null if request is not GraphQL
- `graphQLOperationName` {string} GraphQL operation name. null if request is not GraphQL
- `variables`: {Record<string, any>} GraphQL variables. null if request is not GraphQL or variables is not passed
- `headers` {Record<string, any>} headers object
- `cookies` {Record<string, any>} cookies object
- `query` {Record<string, any>} query object
- `params` {Record<string, any>} params object
- `body` {any} body
- `type` `'request' | 'response'` type of log
- `id` `number` unique id of request to reference request log with response log
- `timestamp` `number` UNIX-timestamp in milliseconds
- `method` `'get' | 'post' | 'delete' | 'put' | 'patch' | 'options'` HTTP method
- `url` `string` requested URL
- `graphQLOperationType` `'query' | 'mutation' | null` GraphQL operation type. null if request is not GraphQL
- `graphQLOperationName` `string` GraphQL operation name. null if request is not GraphQL
- `variables`: `Record<string, any>` GraphQL variables. null if request is not GraphQL or variables is not passed
- `headers` `Record<string, any>` headers object
- `cookies` `Record<string, any>` cookies object
- `query` `Record<string, any>` query object
- `params` `Record<string, any>` params object
- `body` `any` body

Response logger has additional tokens
- `statusCode` {number} response status code
- `data` {any} data returned to client
- `statusCode` `number` response status code
- `data` `any` data returned to client

If you need to log specific mapped entities (headers, cookies, query, params), use `Record<string, boolean>` object instead of boolean.
In that case log will use following logic:
Expand Down Expand Up @@ -821,8 +821,8 @@ export default mockServerConfig;

With `mock-config-server` you can create your own mock database with all CRUD operations

- `data` {Object | string} initial data for database
- `routes?` {Object | string} map of custom routes for database
- `data` `Object | string` initial data for database
- `routes?` `Object | string` map of custom routes for database

### Basic example

Expand Down Expand Up @@ -936,10 +936,10 @@ In the **Link** header you'll get **count**, **pages**, **next** and **prev** li

#### Link

- `count` {number} total count of elements
- `pages` {number} count of pages
- `next` {string | null} query string for next link
- `prev` {string | null} query string for prev link
- `count` `number` total count of elements
- `pages` `number` count of pages
- `next` `string | null` query string for next link
- `prev` `string | null` query string for prev link

### Sort

Expand Down

0 comments on commit 87367e4

Please sign in to comment.