[njs] Types: added TS description for items() introduced in f5428bc87159.

Dmitry Volyntsev xeioex at nginx.com
Tue Sep 12 18:56:47 UTC 2023


details:   https://hg.nginx.org/njs/rev/586767a28478
branches:  
changeset: 2199:586767a28478
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Sep 12 11:36:15 2023 -0700
description:
Types: added TS description for items() introduced in f5428bc87159.

diffstat:

 test/ts/test.ts  |  5 +++++
 ts/ngx_core.d.ts |  6 ++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r 6b3176692593 -r 586767a28478 test/ts/test.ts
--- a/test/ts/test.ts	Mon Sep 11 20:34:48 2023 -0700
+++ b/test/ts/test.ts	Tue Sep 12 11:36:15 2023 -0700
@@ -321,3 +321,8 @@ function ngx_object() {
     ngx.log(ngx.WARN, Buffer.from(ngx.error_log_path));
     ngx.log(ngx.ERR, ngx.version);
 }
+
+function ngx_shared(dict: NgxSharedDict<string>, numeric: NgxSharedDict<number>) {
+    var s:NgxKeyValuePair<string> = dict.items()[0];
+    var v:number = numeric.incr('foo', 1);
+}
diff -r 6b3176692593 -r 586767a28478 ts/ngx_core.d.ts
--- a/ts/ngx_core.d.ts	Mon Sep 11 20:34:48 2023 -0700
+++ b/ts/ngx_core.d.ts	Tue Sep 12 11:36:15 2023 -0700
@@ -250,6 +250,7 @@ interface NgxFetchOptions {
 declare class SharedMemoryError extends Error {}
 
 type NgxSharedDictValue = string | number;
+type NgxKeyValuePair<V> = { key: string, value: V };
 
 /**
  * Interface of a dictionary shared among the working processes.
@@ -315,6 +316,11 @@ interface NgxSharedDict<V extends string
       ? (key: string, delta: V, init?: number) => number
       : never;
     /**
+     * @param maxCount The maximum number of pairs to retrieve (default is 1024).
+     * @returns An array of the key-value pairs.
+     */
+    items(maxCount?: number): NgxKeyValuePair<V>[];
+    /**
      * @returns The free page size in bytes.
      *   Note that even if the free page is zero the dictionary may still accept
      *   new values if there is enough space in the occupied pages.


More information about the nginx-devel mailing list