From 4a1b9ccfccd1c6d0dbc044b941848b747d6e73b0 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 26 Nov 2020 11:11:01 +0000 Subject: [PATCH] Types: added description for "ngx" object. --- 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(-) create mode 100644 ts/ngx_core.d.ts diff --git a/test/ts/test.ts b/test/ts/test.ts index 9a079a0c..42a6ae8a 100644 --- a/test/ts/test.ts +++ b/test/ts/test.ts @@ -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 --git a/ts/ngx_core.d.ts b/ts/ngx_core.d.ts new file mode 100644 index 00000000..258a27fc --- /dev/null +++ b/ts/ngx_core.d.ts @@ -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 --git a/ts/ngx_http_js_module.d.ts b/ts/ngx_http_js_module.d.ts index 92833d8a..239fa528 100644 --- a/ts/ngx_http_js_module.d.ts +++ b/ts/ngx_http_js_module.d.ts @@ -1,4 +1,5 @@ /// +/// interface NginxHTTPArgs { readonly [prop: string]: NjsByteString; diff --git a/ts/ngx_stream_js_module.d.ts b/ts/ngx_stream_js_module.d.ts index 3e01b91d..3fedc32f 100644 --- a/ts/ngx_stream_js_module.d.ts +++ b/ts/ngx_stream_js_module.d.ts @@ -1,4 +1,5 @@ /// +/// interface NginxStreamVariables { readonly 'binary_remote_addr'?: NjsByteString; -- 2.47.3