]> git.kaiwu.me - njs.git/commitdiff
Types: added TS description for items() introduced in f5428bc87159.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 12 Sep 2023 18:36:15 +0000 (11:36 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 12 Sep 2023 18:36:15 +0000 (11:36 -0700)
test/ts/test.ts
ts/ngx_core.d.ts

index c43ba093a612cc89a631b0ecf37896e51f54ba32..a30e02fe8158aac5d289ccd82f12f4a4bbdc87e2 100644 (file)
@@ -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);
+}
index fd06e3027ff931026ec52f84878e192a7a6e935f..af8fc4f3d8c8e0f5c86f555832fd86eed865e7c6 100644 (file)
@@ -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.
@@ -314,6 +315,11 @@ interface NgxSharedDict<V extends string | number = string | number> {
     incr: V extends number
       ? (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