[njs] Types: added description for "ngx" object.

Dmitry Volyntsev xeioex at nginx.com
Thu Nov 26 11:12:38 UTC 2020


details:   https://hg.nginx.org/njs/rev/42dfbf020c68
branches:  
changeset: 1573:42dfbf020c68
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Nov 26 11:11:01 2020 +0000
description:
Types: added description for "ngx" object.

diffstat:

 test/ts/test.ts              |   9 +++++++--
 ts/ngx_core.d.ts             |  14 ++++++++++++++
 ts/ngx_http_js_module.d.ts   |   1 +
 ts/ngx_stream_js_module.d.ts |   1 +
 4 files changed, 23 insertions(+), 2 deletions(-)

diffs (62 lines):

diff -r 5bd78c74777a -r 42dfbf020c68 test/ts/test.ts
--- a/test/ts/test.ts	Thu Nov 26 11:10:59 2020 +0000
+++ b/test/ts/test.ts	Thu Nov 26 11:11:01 2020 +0000
@@ -66,7 +66,6 @@ function http_module(r: NginxHTTPRequest
     // Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply => r.return(reply.status));
     r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
                                         JSON.stringify(JSON.parse(reply.responseBody ?? ''))));
-
 }
 
 function fs_module() {
@@ -107,7 +106,13 @@ function buffer(b: Buffer) {
     b.equals(b);
 }
 
-function builtins() {
+function njs_object() {
     njs.dump('asdf');
     njs.version != process.argv[1];
 }
+
+function ngx_object() {
+    ngx.log(ngx.INFO, 'asdf');
+    ngx.log(ngx.WARN, Buffer.from('asdf'));
+    ngx.log(ngx.ERR, 'asdf');
+}
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_core.d.ts
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ts/ngx_core.d.ts	Thu Nov 26 11:11:01 2020 +0000
@@ -0,0 +1,14 @@
+interface NgxObject {
+    readonly INFO: number;
+    readonly WARN: number;
+    readonly ERR: number;
+    /**
+     * Writes a string to the error log with the specified level
+     * of logging.
+     * @param level Log level (ngx.INFO, ngx.WARN, ngx.ERR).
+     * @param message Message to log.
+     */
+    log(level: number, message: NjsStringOrBuffer): void;
+}
+
+declare const ngx: NgxObject;
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.ts	Thu Nov 26 11:10:59 2020 +0000
+++ b/ts/ngx_http_js_module.d.ts	Thu Nov 26 11:11:01 2020 +0000
@@ -1,4 +1,5 @@
 /// <reference path="index.d.ts" />
+/// <reference path="ngx_core.d.ts" />
 
 interface NginxHTTPArgs {
     readonly [prop: string]: NjsByteString;
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_stream_js_module.d.ts
--- a/ts/ngx_stream_js_module.d.ts	Thu Nov 26 11:10:59 2020 +0000
+++ b/ts/ngx_stream_js_module.d.ts	Thu Nov 26 11:11:01 2020 +0000
@@ -1,4 +1,5 @@
 /// <reference path="index.d.ts" />
+/// <reference path="ngx_core.d.ts" />
 
 interface NginxStreamVariables {
     readonly 'binary_remote_addr'?: NjsByteString;


More information about the nginx-devel mailing list