]> git.kaiwu.me - njs.git/commitdiff
Types: added description for "ngx" object.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Nov 2020 11:11:01 +0000 (11:11 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Nov 2020 11:11:01 +0000 (11:11 +0000)
test/ts/test.ts
ts/ngx_core.d.ts [new file with mode: 0644]
ts/ngx_http_js_module.d.ts
ts/ngx_stream_js_module.d.ts

index 9a079a0cc7f775ae5668033f4d64737670c1c4dd..42a6ae8a49840a554f535fa6fa63aea11a8d0d29 100644 (file)
@@ -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 (file)
index 0000000..258a27f
--- /dev/null
@@ -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;
index 92833d8af30b3228effc54b0e229eb2ed48a90a3..239fa5289cd5ee978b34536d2365fc912a0f36f5 100644 (file)
@@ -1,4 +1,5 @@
 /// <reference path="index.d.ts" />
+/// <reference path="ngx_core.d.ts" />
 
 interface NginxHTTPArgs {
     readonly [prop: string]: NjsByteString;
index 3e01b91db0170241450284b01a03705eb9e5d05c..3fedc32f7a6658ba41a8c4773a7a862f935f4e41 100644 (file)
@@ -1,4 +1,5 @@
 /// <reference path="index.d.ts" />
+/// <reference path="ngx_core.d.ts" />
 
 interface NginxStreamVariables {
     readonly 'binary_remote_addr'?: NjsByteString;