Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsdoc: lib/api/util.js #3578

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ const {
} = require('../core/errors')

const { chunksDecode } = require('./readable')
/**
* @type {131072}
*/
const CHUNK_LIMIT = 128 * 1024

async function getResolveErrorBodyCallback ({ callback, body, contentType, statusCode, statusMessage, headers }) {
/**
*
* @param {object} options
* @param {(err?: Error) => void} options.callback
* @param {AsyncIterable<Buffer>} options.body
* @param {string} options.contentType
* @param {number} options.statusCode
* @param {string} options.statusMessage
* @param {object} options.headers
* @returns
*/
async function getResolveErrorBodyCallback ({
callback,
body,
contentType,
statusCode,
statusMessage,
headers
}) {
assert(body)

let chunks = []
Expand Down Expand Up @@ -55,6 +76,10 @@ async function getResolveErrorBodyCallback ({ callback, body, contentType, statu
queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers, payload)))
}

/**
* @param {string} contentType
* @returns {contentType is `application/json${string}`}`
*/
const isContentTypeApplicationJson = (contentType) => {
return (
contentType.length > 15 &&
Expand All @@ -77,6 +102,10 @@ const isContentTypeApplicationJson = (contentType) => {
)
}

/**
* @param {string} contentType
* @returns {contentType is `text/${string}`}`
*/
const isContentTypeText = (contentType) => {
return (
contentType.length > 4 &&
Expand Down
Loading