Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/strapi/node_modules/koa/node_modules/koa-convert/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
/**
* Module dependencies.
*/
const co = require('co')
const compose = require('koa-compose')
/**
* Expose `convert()`.
*/
module.exports = convert
/**
* Convert Koa legacy generator-based middleware
* to modern promise-based middleware.
*
*
* @api public
* */
function convert (mw) {
if (typeof mw !== 'function') {
throw new TypeError('middleware must be a function')
}
// assume it's Promise-based middleware
if (
mw.constructor.name !== 'GeneratorFunction' &&
mw.constructor.name !== 'AsyncGeneratorFunction'
) {
return mw
}
const converted = function (ctx, next) {
return co.call(
ctx,
mw.call(
ctx,
(function * (next) { return yield next() })(next)
))
}
converted._name = mw._name || mw.name
return converted
}
/**
* Convert and compose multiple middleware
* (could mix legacy and modern ones)
* and return modern promise middleware.
*
*
* @api public
* */
// convert.compose(mw, mw, mw)
// convert.compose([mw, mw, mw])
convert.compose = function (arr) {
if (!Array.isArray(arr)) {
arr = Array.from(arguments)
}
return compose(arr.map(convert))
}
/**
* Convert Koa modern promise-based middleware
* to legacy generator-based middleware.
*
*
* @api public
* */
convert.back = function (mw) {
if (typeof mw !== 'function') {
throw new TypeError('middleware must be a function')
}
// assume it's generator middleware
if (mw.constructor.name === 'GeneratorFunction' || mw.constructor.name === 'AsyncGeneratorFunction') {
return mw
}
const converted = function * (next) {
const ctx = this
let called = false
yield mw(ctx, function () {
if (called) {
// guard against multiple next() calls
// https://github.com/koajs/compose/blob/4e3e96baf58b817d71bd44a8c0d78bb42623aa95/index.js#L36
throw new Error('next() called multiple times')
}
called = true
return co.call(ctx, next)
})
}
converted._name = mw._name || mw.name
return converted
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0048 ]-- |