From 87367e4f44d1cc631a385598fe4c81d2d4f7b856 Mon Sep 17 00:00:00 2001 From: RiceWithMeat <47690223+RiceWithMeat@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:27:54 +0700 Subject: [PATCH] =?UTF-8?q?#102=20=F0=9F=90=98=20fix=20types=20in=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 206 +++++++++++++++++++++++++++--------------------------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index ab8aa8d6..f796e6e0 100644 --- a/README.md +++ b/README.md @@ -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} 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` 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} 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` 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 @@ -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} 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` 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 @@ -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} 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` 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 @@ -587,27 +587,27 @@ 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>` #### 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 | Function | Promise } available origins from which requests can be made -- `methods?` {Array} available methods (default: `GET,OPTIONS,PUT,PATCH,POST,DELETE`) -- `allowedHeaders?` {Array} allowed headers (default: `*`) -- `exposedHeaders?` {Array} 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 | Function | Promise` available origins from which requests can be made +- `methods?` `Array` available methods (default: `GET,OPTIONS,PUT,PATCH,POST,DELETE`) +- `allowedHeaders?` `Array` allowed headers (default: `*`) +- `exposedHeaders?` `Array` 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 @@ -615,48 +615,48 @@ Functions to change request or response parameters - `params` - `request` request object - - `setDelay` {(delay) => Promise} - - `delay` {number} milliseconds of delay time - - `getHeader` {(field) => string | number | string[] | undefined} - - `field` {string} name of response header - - `getHeaders` {() => Record} - - `getCookie` {(name) => string | undefined} - - `name` {string} name of cookie - - `log` {(logger) => Partial | null} logger function [read](#logger) - - `logger` {Logger | undefined} logger options + - `setDelay` `(delay) => Promise` + - `delay` `number` milliseconds of delay time + - `getHeader` `(field) => string | number | string[] | undefined` + - `field` `string` name of response header + - `getHeaders` `() => Record` + - `getCookie` `(name) => string | undefined` + - `name` `string` name of cookie + - `log` `(logger) => Partial | 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} - - `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} - - `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 | null} logger function [read](#logger) - - `logger` {Logger | undefined} logger options + - `setDelay` `(delay) => Promise` + - `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` + - `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 | null` logger function [read](#logger) + - `logger` `Logger | undefined` logger options #### Logger @@ -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 @@ -681,7 +681,7 @@ You can log requests and responses using `log` function in any [interceptor](#in - method - url - data -- `rewrite` {(tokenValues: Partial) => void} function to customize log default `console.dir(tokenValues, { depth: null })` appearance +- `rewrite` `(tokenValues: Partial) => 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` @@ -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} GraphQL variables. null if request is not GraphQL or variables is not passed -- `headers` {Record} headers object -- `cookies` {Record} cookies object -- `query` {Record} query object -- `params` {Record} 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` GraphQL variables. null if request is not GraphQL or variables is not passed +- `headers` `Record` headers object +- `cookies` `Record` cookies object +- `query` `Record` query object +- `params` `Record` 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` object instead of boolean. In that case log will use following logic: @@ -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 @@ -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