[njs] Types: updated TS definitions.
Dmitry Volyntsev
xeioex at nginx.com
Tue Mar 9 13:28:37 UTC 2021
details: https://hg.nginx.org/njs/rev/715e1eeb9a4d
branches:
changeset: 1618:715e1eeb9a4d
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Mar 09 13:24:06 2021 +0000
description:
Types: updated TS definitions.
diffstat:
test/ts/test.ts | 6 +++++
ts/ngx_http_js_module.d.ts | 35 +++++++++++++++++++++++++++++++-
ts/ngx_stream_js_module.d.ts | 48 ++++++++++++++++++++++++++++++++++++++-----
ts/njs_core.d.ts | 5 ++++
4 files changed, 87 insertions(+), 7 deletions(-)
diffs (194 lines):
diff -r 84af87035c4e -r 715e1eeb9a4d test/ts/test.ts
--- a/test/ts/test.ts Sat Mar 06 12:42:30 2021 +0000
+++ b/test/ts/test.ts Tue Mar 09 13:24:06 2021 +0000
@@ -93,6 +93,11 @@ function http_module(r: NginxHTTPRequest
})
.then(body => r.return(200, body))
.catch(e => r.return(501, e.message))
+
+ // js_body_filter
+ r.sendBuffer(Buffer.from("xxx"), {last:true});
+ r.sendBuffer("xxx", {flush: true});
+ r.done();
}
function fs_module() {
@@ -150,6 +155,7 @@ function timers() {
function njs_object() {
njs.dump('asdf');
njs.version != process.argv[1];
+ njs.on('exit', ()=> {});
}
function ngx_object() {
diff -r 84af87035c4e -r 715e1eeb9a4d ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.ts Sat Mar 06 12:42:30 2021 +0000
+++ b/ts/ngx_http_js_module.d.ts Tue Mar 09 13:24:06 2021 +0000
@@ -262,12 +262,32 @@ interface NginxSubrequestOptions {
detached?: boolean
}
+interface NginxHTTPSendBufferOptions {
+ /**
+ * True if data is a last buffer.
+ */
+ last?: boolean
+ /**
+ * True if the buffer should have the flush flag.
+ */
+ flush?: boolean
+}
+
interface NginxHTTPRequest {
/**
* Request arguments object.
*/
readonly args: NginxHTTPArgs;
/**
+ * After calling this function, next data chunks will be passed to
+ * the client without calling js_body_filter.
+ *
+ * **Warning:** May be called only from the js_body_filter function.
+ *
+ * @since 0.5.2
+ */
+ done(): void;
+ /**
* Writes a string to the error log on the error level of logging.
* @param message Message to log.
*/
@@ -374,10 +394,23 @@ interface NginxHTTPRequest {
*/
return(status: number, body?: NjsStringOrBuffer): void;
/**
- * Sends the HTTP headers to the client.
+ * Sends a part of the response body to the client.
*/
send(part: NjsStringOrBuffer): void;
/**
+ * Adds data to the chain of data chunks to be forwarded to the next body filter.
+ * The actual forwarding happens later, when the all the data chunks of the current
+ * chain are processed.
+ *
+ * **Warning:** May be called only from the js_body_filter function.
+ *
+ * @since 0.5.2
+ * @param data Data to send.
+ * @param options Object used to override nginx buffer flags derived from
+ * an incoming data chunk buffer.
+ */
+ sendBuffer(data: NjsStringOrBuffer, options?: NginxHTTPSendBufferOptions): void;
+ /**
* Sends the HTTP headers to the client.
*/
sendHeader(): void;
diff -r 84af87035c4e -r 715e1eeb9a4d ts/ngx_stream_js_module.d.ts
--- a/ts/ngx_stream_js_module.d.ts Sat Mar 06 12:42:30 2021 +0000
+++ b/ts/ngx_stream_js_module.d.ts Tue Mar 09 13:24:06 2021 +0000
@@ -97,21 +97,44 @@ interface NginxStreamSendOptions {
interface NginxStreamRequest {
/**
- * Successfully finalizes the phase handler.
+ * Successfully finalizes the phase handler. An alias to s.done(0).
+ *
+ * @since 0.2.4
+ * @see done()
*/
allow(): void;
/**
- * Finalizes the phase handler and passes control to the next handler.
+ * Passing control to the next handler of the current phase (if any).
+ * An alias to s.done(-5).
+ *
+ * @since 0.2.4
+ * @see done()
*/
decline(): void;
/**
* Finalizes the phase handler with the access error code.
+ * An alias to s.done(403).
+ *
+ * @since 0.2.4
+ * @see done()
*/
deny(): void;
/**
- * Successfully finalizes the current phase handler
- * or finalizes it with the specified numeric code.
- * @param code Finalization code.
+ * Sets an exit code for the current phase handler to a code value.
+ * The actual finalization happens when the js handler is completed and
+ * all pending events, for example from ngx.fetch() or setTimeout(),
+ * are processed.
+ *
+ * @param code Finalization code, by default is 0.
+ * Possible code values:
+ * 0 - successful finalization, passing control to the next phase
+ * -5 - undecided, passing control to the next handler of the current
+ * phase (if any)
+ * 403 - access is forbidden
+ * @since 0.2.4
+ * @see allow()
+ * @see decline()
+ * @see deny()
*/
done(code?: number): void;
/**
@@ -127,6 +150,7 @@ interface NginxStreamRequest {
/**
* Unregisters the callback set by on() method.
* @param event Event type to unregister.
+ * @see on()
*/
off(event: "upload" | "download" | "upstream" | "downstream"): void;
/**
@@ -138,6 +162,7 @@ interface NginxStreamRequest {
*
* **Warning:** For string data type bytes invalid in UTF-8 encoding may be
* converted into the replacement character.
+ * @see off()
*/
on(event: "upload" | "download",
callback: (data: NjsByteString, flags: NginxStreamCallbackFlags) => void): void;
@@ -148,13 +173,24 @@ interface NginxStreamRequest {
*/
readonly remoteAddress: NjsByteString;
/**
- * Sends the data to the client.
+ * Adds data to the chain of data chunks that will be forwarded in
+ * the forward direction: in download callback to a client; in upload
+ * to an upstream server. The actual forwarding happens later, when the all
+ * the data chunks of the current chain are processed.
+ *
+ * @since 0.2.4
* @param data Data to send.
* @param options Object used to override nginx buffer flags derived from
* an incoming data chunk buffer.
+ * @see on()
*/
send(data: NjsStringOrBuffer, options?: NginxStreamSendOptions): void;
/**
+ * The stream session exit status. It is an alias to the $status variable.
+ * @since 0.5.2
+ */
+ readonly status: number;
+ /**
* nginx variables as Buffers.
*
* @since 0.5.0
diff -r 84af87035c4e -r 715e1eeb9a4d ts/njs_core.d.ts
--- a/ts/njs_core.d.ts Sat Mar 06 12:42:30 2021 +0000
+++ b/ts/njs_core.d.ts Tue Mar 09 13:24:06 2021 +0000
@@ -591,6 +591,11 @@ type NjsStringOrBuffer = NjsStringLike |
interface NjsGlobal {
readonly version: string;
dump(value: any, indent?: number): string;
+ /**
+ * Registers a callback for the "exit" event. The callback is called before
+ * the VM is destroyed.
+ */
+ on(event: "exit", callback: () => void): void;
}
declare const njs: NjsGlobal;
More information about the nginx-devel
mailing list