Skip to content

Commit

Permalink
improve: signatures.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzNotABug committed Oct 4, 2024
1 parent 286cc51 commit 88782bd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
3 changes: 1 addition & 2 deletions compression/zstd-compression/zstd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import zstd from '@mongodb-js/zstd';
/**
* Creates a compression utility object with `zstd` encoding.
*
* @param {Object} options - Configuration options for the compressor.
* @param {number} options.level=9 - Compression level, defaults to 9.
* @param {number} level=9 - Compression level, defaults to 9.
* Levels should be between `1` and `22`. If an invalid level is provided,
* default level of `9` is used.
* @returns {Object} A compression utility object containing supported encodings and a compression method.
Expand Down
15 changes: 8 additions & 7 deletions middlewares/api-cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ const configOptions = {
*
* **Note: The responses are cached in memory after the first request, up until the function container is removed.**
*
* @param {Object} options - Configuration options.
* @param {(string|RegExp)[]} [options.excludes=[]] - Paths to exclude.
* @param {(string|RegExp)[]} [excludes=[]] - Paths to exclude.
* Supports strings and regular expressions.
* Caching won't be applied if a path matches any one in excluded paths.
* @param {number} [options.timeout=300000] - Cache expiry in milliseconds. Default 5 minutes. Pass `0` for no expiry!
* @param {boolean} [options.cacheControl=true] - Should add a `cache-control` header. Default true. This header is not overridden if one already exists.
* @param {number} [timeout=300000] - Cache expiry in milliseconds. Default 5 minutes. Pass `0` for no expiry!
* @param {boolean} [cacheControl=true] - Should add a `cache-control` header. Default true. This header is not overridden if one already exists.
* @returns {{ hasCache: function, clearCache: function, clearAllCache: function }}
*/
export default function (options = {}) {
const { excludes = [], timeout = 300000, cacheControl = true } = options;

export default function ({
excludes = [],
timeout = 300000,
cacheControl = true,
} = {}) {
configOptions.excludedPaths = excludes;
configOptions.expirationTime = timeout;
configOptions.cacheControl = cacheControl;
Expand Down
27 changes: 12 additions & 15 deletions middlewares/cors/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@ const configOptions = {
/**
* Middleware that adds cors headers.
*
* @param {Object} options - Configuration options.
* @param {string} [options.origin='*'] - Specifies which origin(s) may access the resource.
* @param {string} [origin='*'] - Specifies which origin(s) may access the resource.
* Can be a single string (specific origin or '*') or an array of strings and `RegExp` for flexible matching.
* @param {(string|RegExp)[]} [options.excludes=[]] - Paths to exclude from applying CORS.
* @param {(string|RegExp)[]} [excludes=[]] - Paths to exclude from applying CORS.
* Supports strings and regular expressions. CORS headers won't be applied if a path
* matches any one in excluded paths.
* @param {boolean} [options.preFlightContinue=false] - When false, an empty response is sent back.
* @param {number} [options.optionsSuccessStatus=204] - The HTTP status code to use for successful
* @param {boolean} [preFlightContinue=false] - When false, an empty response is sent back.
* @param {number} [optionsSuccessStatus=204] - The HTTP status code to use for successful
* preflight requests, typically 204 (No Content).
* @param {string[]} [options.methods=['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']] - Specifies the
* @param {string[]} [methods=['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']] - Specifies the
* methods allowed when accessing the resource. This is reflected in the 'Access-Control-Allow-Methods' header.
*/
export default function (options = {}) {
const {
origin = '*',
excludes = [],
preFlightContinue = false,
optionsSuccessStatus = 204,
methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
} = options;

export default function ({
origin = '*',
excludes = [],
preFlightContinue = false,
optionsSuccessStatus = 204,
methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
} = {}) {
configOptions.origin = origin;
configOptions.excludedPaths = excludes;
configOptions.preflightContinue = preFlightContinue;
Expand Down
11 changes: 6 additions & 5 deletions middlewares/favicon/favicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
/**
* Middleware to serve the favicon.
*
* @param {Object} options - Configuration options.
* @param {string} [options.iconPath='public/favicon.ico'] - Path to the favicon file.
* @param {number} [options.maxCacheDays=365] - Number of days to cache the favicon.
* @param {string} [iconPath='public/favicon.ico'] - Path to the favicon file.
* @param {number} [maxCacheDays=365] - Number of days to cache the favicon.
*/
export default function (options = {}) {
const { iconPath = 'public/favicon.ico', maxCacheDays = 365 } = options;
export default function ({
iconPath = 'public/favicon.ico',
maxCacheDays = 365,
} = {}) {
configOptions.favIconPath = iconPath;
configOptions.favIconMaxCacheDays = maxCacheDays;

Expand Down
8 changes: 3 additions & 5 deletions middlewares/minifier/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ const configOptions = { excludedPaths: [], htmlMinifierOptions: {} };
/**
* Middleware that minifies content.
*
* @param {Object} options - Configuration options.
* @param {(string|RegExp)[]} [options.excludes=[]] - Paths to exclude.
* @param {(string|RegExp)[]} [excludes=[]] - Paths to exclude.
* Supports strings and regular expressions.
* Minification won't be applied if a path matches any one in excluded paths.
* @param {Object} [options.htmlOptions={}] - HTML minifier options.
* @param {Object} [htmlOptions={}] - HTML minifier options.
*/
export default function (options = {}) {
const { excludes = [], htmlOptions = {} } = options;
export default function ({ excludes = [], htmlOptions = {} } = {}) {
configOptions.excludedPaths = excludes;
configOptions.htmlMinifierOptions = htmlOptions;

Expand Down
7 changes: 2 additions & 5 deletions middlewares/no-cookies/nocookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ const configOptions = { excludedPaths: [] };
/**
* Middleware to remove cookies.
*
* @param {Object} options - Configuration options.
* @param {string} options.excludes=[] - Paths to exclude.
* @param {string} excludes=[] - Paths to exclude.
* Cookies won't be removed if a path matches any one in excluded paths.
*/
export default function (options = {}) {
const { excludes = [] } = options;

export default function ({ excludes = [] } = {}) {
configOptions.excludedPaths = excludes;

return {
Expand Down

0 comments on commit 88782bd

Please sign in to comment.