@adobe/openwhisk-action-utils 中文文档教程
Openwhisk Action Utilities
用于 OpenWhisk 操作的实用程序。
Status
API Reference
Modules
- expressify
将 OpenWhisk 网络操作转换为可通过正常方式处理的快速请求的帮助程序 快递员。
Expressify 将查询和大部分操作参数映射到
req.query
。 原始操作参数在req.owActionParams
下可用。用法:
const { expressify, errorHandler } = require('@adobe/openwhisk-action-utils'); async function main(params) { const app = express(); app.use(cookieParser()); app.use(express.static('static')); app.get('/', homepageHandler); app.get('/ping', pingHandler); app.use(errorHandler(log)); return expressify(app)(params); }
- middleware
表达动作的辅助函数。
用法:
const { expressify, logRequest, errorHandler, asyncHandler, cacheControl, createBunyanLogger, } = require('@adobe/openwhisk-action-utils'); async function startHandler(params, req, res) { res.send('Hello, world.'); } async function main(params) { const log = createBunyanLogger(); const app = express(); app.use(logRequest(log)); app.use(cacheControl()); app.get('/', asyncHandler(startHandler)); app.get('/ping', asyncHandler(pingHandler)); app.use(errorHandler(log)); return expressify(app)(params); }
- wrap
帮助函数轻松链接 OpenWhisk 操作。
用法:
const { wrap } = require('@adobe/openwhisk-action-utils'); async main(params) { // …my action code… } module.exports.main = wrap(main) .with(epsagon) .with(status) .with(logger);
Classes
- VersionLock
帮助程序类使用
x-ow-version-lock
标头中的信息来锁定版本 一个 openwhisk 动作。
Functions
- createBunyanLogger([logger]) ⇒
BunyanLogger
设置适合与 openwhisk 操作一起使用的 bunyan 记录器。 bunyan 记录器将 流到给定的螺旋记录器。
expressify
帮助程序将 OpenWhisk 网络操作转换为可以用正常方式处理的快速请求 快递员。
Expressify 将查询和大部分操作参数映射到 req.query
。 原始操作参数在 req.owActionParams
下可用。
用法:
const { expressify, errorHandler } = require('@adobe/openwhisk-action-utils');
async function main(params) {
const app = express();
app.use(cookieParser());
app.use(express.static('static'));
app.get('/', homepageHandler);
app.get('/ping', pingHandler);
app.use(errorHandler(log));
return expressify(app)(params);
}
expressify~expressify(app) ⇒ ActionFunction
创建一个使用 express 框架处理调用的 OpenWhisk 操作函数。
Kind:expressify
的内部方法 返回:ActionFunction
- 动作函数。
参见:https:
Param | Type | Description |
---|---|---|
app | ExpressApp | The express application |
//expressjs.com/en/4x/api.html#app
middleware
表达操作的辅助函数。
用法:
const {
expressify, logRequest, errorHandler, asyncHandler, cacheControl, createBunyanLogger,
} = require('@adobe/openwhisk-action-utils');
async function startHandler(params, req, res) {
res.send('Hello, world.');
}
async function main(params) {
const log = createBunyanLogger();
const app = express();
app.use(logRequest(log));
app.use(cacheControl());
app.get('/', asyncHandler(startHandler));
app.get('/ping', asyncHandler(pingHandler));
app.use(errorHandler(log));
return expressify(app)(params);
}
- middleware
- ~errorHandler(log) ⇒
ExpressMiddleware
- ~cacheControl([value]) ⇒
ExpressMiddleware
- ~hideHeaders(headerNames) ⇒
ExpressMiddleware
- ~logRequest(logger, [level]) ⇒
ExpressMiddleware
- ~asyncHandler(fn) ⇒
ExpressMiddleware
- ~ActionMiddlewareFunction :
function
- ~errorHandler(log) ⇒
middleware~errorHandler(log) ⇒ ExpressMiddleware
错误处理程序。 报告请求处理期间发生的错误并做出响应 如果尚未设置,则带有 500
。
种类:中间件
的内部方法 返回:ExpressMiddleware
- 一个快速中间件函数。
Param | Type | Description |
---|---|---|
log | BunyanLogger | The logger to use for reporting errors. |
示例
// install last
app.use(errorHandler(log));
middleware~cacheControl([value]) ⇒ ExpressMiddleware
确保缓存控制。 设置缓存控制标头。
种类:中间件
的内部方法 返回:ExpressMiddleware
- 一个快速中间件函数。
Param | Type | Default | Description |
---|---|---|---|
[value] | string | "no-store, private, must-revalidate" | Cache control header value. |
示例
app.use(cacheControl());
middleware~hideHeaders(headerNames) ⇒ ExpressMiddleware
从枚举中隐藏标题。
种类:中间件
的内部方法 返回:ExpressMiddleware
- 一个快速中间件函数。
Param | Type | Description |
---|---|---|
headerNames | Array.<string> | Names of headers to make un-enumerable |
示例
// install first
app.use(hideHeaders(['x-token', 'authentication'));
app.use(logRequest(log));
middleware~logRequest(logger, [level]) ⇒ ExpressMiddleware
为请求创建一个 bunyan 子记录器并将其添加到请求中。 这确保了 重要的标头值,如 x-request-id
包含在每个日志条目中。 它也是 记录请求和响应行。
种类:中间件
的内部方法 返回:ExpressMiddleware
- 一个快速中间件函数。
Param | Type | Default | Description |
---|---|---|---|
logger | BunyanLogger | the bunyan logger | |
[level] | string | "debug" | the log level to use for logging the request information. |
示例
// install first
app.use(logRequest(log));
middleware~asyncHandler(fn) ⇒ ExpressMiddleware
包装路由中间件,以便它可以捕获潜在的承诺拒绝 在异步调用期间。
种类:中间件
的内部方法 返回:ExpressMiddleware
- 一个快速中间件函数。
Param | Type | Description |
---|---|---|
fn | ExpressMiddleware | an extended express middleware function |
middleware~ActionMiddlewareFunction : function
与 asyncHandler 一起使用的扩展中间件函数。
种类:中间件
的内部类型定义 参见:https:
Param | Type | Description |
---|---|---|
params | \* | The action params |
req | ExpressRequest | The express request |
res | ExpressResponse | The express response |
next | ExpressMiddleware | The next handler in chain. |
//expressjs.com/en/4x/api.html#middleware-callback-function-examples
wrap
轻松链接 OpenWhisk 的辅助函数动作。
用法:
const { wrap } = require('@adobe/openwhisk-action-utils');
async main(params) {
// …my action code…
}
module.exports.main = wrap(main)
.with(epsagon)
.with(status)
.with(logger);
- wrap
- ~wrap(main) ⇒
WrappableActionFunction
- ~ActionFunction ⇒
object
- ~WrappableActionFunction ⇒
object
- ~WrapFunction ⇒
ActionFunction
- ~wrap(main) ⇒
wrap~wrap(main) ⇒ WrappableActionFunction
使您的操作函数(即 main
)可包装的函数, 以便使用 with
可以应用许多包装器。 这允许 您将结果导出为新函数。
Kind:wrap
的内部方法 返回:WrappableActionFunction
- 相同的主函数,现在包含一个with
方法
Param | Type | Description |
---|---|---|
main | ActionFunction | the main function to prepare for wrapping |
Example
async main(params) {
//…my action code…
}
module.exports.main = wrap(main)
.with(epsagon)
.with(status)
.with(logger);
wrap~ActionFunction ⇒ object
OpenWhisk 操作的 main
函数。
种类:wrap
的内部类型定义 返回:object
- 结果
Param | Type | Description |
---|---|---|
params | object | the parameters of the action function |
wrap~WrappableActionFunction ⇒ object
一个 ActionFunction
已被扩充为可使用 with
方法进行包装。
种类:wrap
的内部类型定义 返回:object
- 结果
Param | Type | Description |
---|---|---|
params | object | the parameters of the action function |
wrap~WrapFunction ⇒ ActionFunction
包装(并调用您的主函数)的函数。 可以用 装饰输入或输出,或提供额外的功能 例如日志记录、跟踪、调试等。
种类:wrap
的内部类型定义 返回:ActionFunction
- 一个与原始主函数具有相同签名的新函数
Param | Type | Description |
---|---|---|
main | ActionFunction | your main function |
…opts | \* | configuration options for the wrapping function |
示例
function tracer(fn, level) {
return (params) => {
log[level]('enter');
const ret = fn(params);
log[level]('exit');
return ret;
}
}
VersionLock
使用 x-ow-version-lock
标头中的信息来锁定版本的帮助程序类 一个 openwhisk 动作。
Kind: global class
- VersionLock
- new VersionLock(params, defaults)
- instance
- .transformActionURL(url)
- .wrapOpenwhisk(ow) ⇒
OpenWhisk
- static
- .XOWVERSION_LOCK ⇒
string
- .XOWVERSION_LOCK ⇒
new VersionLock(params, defaults)
创建一个版本锁类。
Param | Type | Description |
---|---|---|
params | object | the openwhisk action params |
defaults | object | the action name defaults. |
versionLock.transformActionURL(url)
根据锁信息转换一个action url。
Kind:VersionLock
的实例方法
Param | Type | Description |
---|---|---|
url | string | the action url. |
versionLock.wrapOpenwhisk(ow) ⇒ OpenWhisk
增强 openwhisk客户端通过包装自动操作名称的 invoke
方法 替代品。
Kind:VersionLock
的实例方法 返回:OpenWhisk
- 包装的客户端
Param | Type | Description |
---|---|---|
ow | OpenWhisk | openwhisk client |
VersionLock.X_OW_VERSION_LOCK ⇒ string
版本锁标头的名称。
种类:VersionLock
的静态属性 返回:string
- 'x-ow-version-lock'
createBunyanLogger([logger]) ⇒ BunyanLogger
设置适合与 openwhisk 操作一起使用的 bunyan 记录器。 bunyan 记录器将 流到给定的螺旋记录器。
种类:全局函数
返回:BunyanLogger
- 一个 bunyan 记录器
Param | Type | Default | Description |
---|---|---|---|
[logger] | Logger | rootLogger | a helix multi logger. defaults to the helix rootLogger . |
Openwhisk Action Utilities
Utilities for OpenWhisk actions.
Status
API Reference
Modules
- expressify
Helper to turn a OpenWhisk web action into a express request which can be handled with normal express handlers.
Expressify maps the query and most of action params to
req.query
. The original action params are available underreq.owActionParams
.Usage:
const { expressify, errorHandler } = require('@adobe/openwhisk-action-utils'); async function main(params) { const app = express(); app.use(cookieParser()); app.use(express.static('static')); app.get('/', homepageHandler); app.get('/ping', pingHandler); app.use(errorHandler(log)); return expressify(app)(params); }
- middleware
Helper functions for expressified actions.
Usage:
const { expressify, logRequest, errorHandler, asyncHandler, cacheControl, createBunyanLogger, } = require('@adobe/openwhisk-action-utils'); async function startHandler(params, req, res) { res.send('Hello, world.'); } async function main(params) { const log = createBunyanLogger(); const app = express(); app.use(logRequest(log)); app.use(cacheControl()); app.get('/', asyncHandler(startHandler)); app.get('/ping', asyncHandler(pingHandler)); app.use(errorHandler(log)); return expressify(app)(params); }
- wrap
Helper function to easily chain OpenWhisk actions.
Usage:
const { wrap } = require('@adobe/openwhisk-action-utils'); async main(params) { // …my action code… } module.exports.main = wrap(main) .with(epsagon) .with(status) .with(logger);
Classes
- VersionLock
Helper class that uses the information in the
x-ow-version-lock
header to lock the version of an openwhisk action.
Functions
- createBunyanLogger([logger]) ⇒
BunyanLogger
Sets up a bunyan logger suitable to use with an openwhisk action. The bunyan logger will stream to the given helix logger.
expressify
Helper to turn a OpenWhisk web action into a express request which can be handled with normal express handlers.
Expressify maps the query and most of action params to req.query
. The original action params are available under req.owActionParams
.
Usage:
const { expressify, errorHandler } = require('@adobe/openwhisk-action-utils');
async function main(params) {
const app = express();
app.use(cookieParser());
app.use(express.static('static'));
app.get('/', homepageHandler);
app.get('/ping', pingHandler);
app.use(errorHandler(log));
return expressify(app)(params);
}
expressify~expressify(app) ⇒ ActionFunction
Creates an OpenWhisk action function that uses the express framework to handle the invocation.
Kind: inner method of expressify
Returns: ActionFunction
- An action function.
See: https://expressjs.com/en/4x/api.html#app
Param | Type | Description |
---|---|---|
app | ExpressApp | The express application |
middleware
Helper functions for expressified actions.
Usage:
const {
expressify, logRequest, errorHandler, asyncHandler, cacheControl, createBunyanLogger,
} = require('@adobe/openwhisk-action-utils');
async function startHandler(params, req, res) {
res.send('Hello, world.');
}
async function main(params) {
const log = createBunyanLogger();
const app = express();
app.use(logRequest(log));
app.use(cacheControl());
app.get('/', asyncHandler(startHandler));
app.get('/ping', asyncHandler(pingHandler));
app.use(errorHandler(log));
return expressify(app)(params);
}
- middleware
- ~errorHandler(log) ⇒
ExpressMiddleware
- ~cacheControl([value]) ⇒
ExpressMiddleware
- ~hideHeaders(headerNames) ⇒
ExpressMiddleware
- ~logRequest(logger, [level]) ⇒
ExpressMiddleware
- ~asyncHandler(fn) ⇒
ExpressMiddleware
- ~ActionMiddlewareFunction :
function
- ~errorHandler(log) ⇒
middleware~errorHandler(log) ⇒ ExpressMiddleware
Error handler. Reports errors that happen during the request processing and responds with a 500
if not already set.
Kind: inner method of middleware
Returns: ExpressMiddleware
- an express middleware function.
Param | Type | Description |
---|---|---|
log | BunyanLogger | The logger to use for reporting errors. |
Example
// install last
app.use(errorHandler(log));
middleware~cacheControl([value]) ⇒ ExpressMiddleware
Ensures cache control. Sets cache control headers.
Kind: inner method of middleware
Returns: ExpressMiddleware
- an express middleware function.
Param | Type | Default | Description |
---|---|---|---|
[value] | string | "no-store, private, must-revalidate" | Cache control header value. |
Example
app.use(cacheControl());
middleware~hideHeaders(headerNames) ⇒ ExpressMiddleware
Hides headers from enumeration.
Kind: inner method of middleware
Returns: ExpressMiddleware
- an express middleware function.
Param | Type | Description |
---|---|---|
headerNames | Array.<string> | Names of headers to make un-enumerable |
Example
// install first
app.use(hideHeaders(['x-token', 'authentication'));
app.use(logRequest(log));
middleware~logRequest(logger, [level]) ⇒ ExpressMiddleware
Creates a bunyan child logger for the request and adds it to the request. This ensures that important header values, like x-request-id
are included in every log entry. It also logs the request and response lines.
Kind: inner method of middleware
Returns: ExpressMiddleware
- an express middleware function.
Param | Type | Default | Description |
---|---|---|---|
logger | BunyanLogger | the bunyan logger | |
[level] | string | "debug" | the log level to use for logging the request information. |
Example
// install first
app.use(logRequest(log));
middleware~asyncHandler(fn) ⇒ ExpressMiddleware
Wraps the route middleware so it can catch potential promise rejections during the async invocation.
Kind: inner method of middleware
Returns: ExpressMiddleware
- an express middleware function.
Param | Type | Description |
---|---|---|
fn | ExpressMiddleware | an extended express middleware function |
middleware~ActionMiddlewareFunction : function
Extended middleware function to be use with the asyncHandler.
Kind: inner typedef of middleware
See: https://expressjs.com/en/4x/api.html#middleware-callback-function-examples
Param | Type | Description |
---|---|---|
params | \* | The action params |
req | ExpressRequest | The express request |
res | ExpressResponse | The express response |
next | ExpressMiddleware | The next handler in chain. |
wrap
Helper function to easily chain OpenWhisk actions.
Usage:
const { wrap } = require('@adobe/openwhisk-action-utils');
async main(params) {
// …my action code…
}
module.exports.main = wrap(main)
.with(epsagon)
.with(status)
.with(logger);
- wrap
- ~wrap(main) ⇒
WrappableActionFunction
- ~ActionFunction ⇒
object
- ~WrappableActionFunction ⇒
object
- ~WrapFunction ⇒
ActionFunction
- ~wrap(main) ⇒
wrap~wrap(main) ⇒ WrappableActionFunction
A function that makes your action function (i.e. main
) wrappable, so that using with
a number of wrappers can be applied. This allows you to export the result as a new function.
Kind: inner method of wrap
Returns: WrappableActionFunction
- the same main function, now including a with
method
Param | Type | Description |
---|---|---|
main | ActionFunction | the main function to prepare for wrapping |
Example
async main(params) {
//…my action code…
}
module.exports.main = wrap(main)
.with(epsagon)
.with(status)
.with(logger);
Note: the execution order is that the last wrapper added will be executed first.
wrap~ActionFunction ⇒ object
The main
function of an OpenWhisk action.
Kind: inner typedef of wrap
Returns: object
- a result
Param | Type | Description |
---|---|---|
params | object | the parameters of the action function |
wrap~WrappableActionFunction ⇒ object
An ActionFunction
that has been augmented to become wrappable using the with
method.
Kind: inner typedef of wrap
Returns: object
- a result
Param | Type | Description |
---|---|---|
params | object | the parameters of the action function |
wrap~WrapFunction ⇒ ActionFunction
A function that wraps (and invokes your main function). It can be used to decorate inputs or outputs, or to provide additional functionality like logging, tracing, debugging, etc.
Kind: inner typedef of wrap
Returns: ActionFunction
- a new function with the same signature as your original main function
Param | Type | Description |
---|---|---|
main | ActionFunction | your main function |
…opts | \* | configuration options for the wrapping function |
Example
function tracer(fn, level) {
return (params) => {
log[level]('enter');
const ret = fn(params);
log[level]('exit');
return ret;
}
}
VersionLock
Helper class that uses the information in the x-ow-version-lock
header to lock the version of an openwhisk action.
Kind: global class
- VersionLock
- new VersionLock(params, defaults)
- instance
- .transformActionURL(url)
- .wrapOpenwhisk(ow) ⇒
OpenWhisk
- static
- .XOWVERSION_LOCK ⇒
string
- .XOWVERSION_LOCK ⇒
new VersionLock(params, defaults)
Creates a version lock class.
Param | Type | Description |
---|---|---|
params | object | the openwhisk action params |
defaults | object | the action name defaults. |
versionLock.transformActionURL(url)
Transforms an action url according to the lock information.
Kind: instance method of VersionLock
Param | Type | Description |
---|---|---|
url | string | the action url. |
versionLock.wrapOpenwhisk(ow) ⇒ OpenWhisk
Enhances an openwhisk client by wrapping the invoke
method for automatic action name replacement.
Kind: instance method of VersionLock
Returns: OpenWhisk
- the wrapped client
Param | Type | Description |
---|---|---|
ow | OpenWhisk | openwhisk client |
VersionLock.X_OW_VERSION_LOCK ⇒ string
The name of the version lock header.
Kind: static property of VersionLock
Returns: string
- 'x-ow-version-lock'
createBunyanLogger([logger]) ⇒ BunyanLogger
Sets up a bunyan logger suitable to use with an openwhisk action. The bunyan logger will stream to the given helix logger.
Kind: global function
Returns: BunyanLogger
- A bunyan logger
Param | Type | Default | Description |
---|---|---|---|
[logger] | Logger | rootLogger | a helix multi logger. defaults to the helix rootLogger . |
你可能也喜欢
- @0x0/restify-errors 中文文档教程
- @10play/cells 中文文档教程
- @3dwayfinder/scrollarea 中文文档教程
- @4geit/rct-common-store 中文文档教程
- @8pattern/jhistory 中文文档教程
- @abhaykumar01234/vendor-portal 中文文档教程
- @aboutbits/react-material-icons 中文文档教程
- @absolunet/stylelint-config-nwayo 中文文档教程
- @acegoal07/timestamp-progress 中文文档教程
- @adactive/arc-clock 中文文档教程