]> git.kaiwu.me - njs.git/commitdiff
Types: updates ts types.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 4 Aug 2022 03:26:24 +0000 (20:26 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 4 Aug 2022 03:26:24 +0000 (20:26 -0700)
test/ts/test.ts
ts/ngx_http_js_module.d.ts
ts/njs_core.d.ts
ts/tsconfig.json

index 0ba55e95676f265f837086c92915181c35b8d5a3..16f511db77ed4980cd1d1d370448c0c33d44d2bf 100644 (file)
@@ -174,9 +174,15 @@ function timers() {
     // Warning: clearTimeout(123);
 }
 
+function global_functions() {
+    const encodedData = btoa("text to encode");
+    const decodedData = atob(encodedData);
+}
+
 function njs_object() {
     njs.dump('asdf');
     njs.version != process.argv[1];
+    typeof njs.version_number == 'number';
     njs.on('exit', ()=> {});
 }
 
index 9ed3b92a70feaa4c3c24f9e79e0f3e79ec9e9e26..7afd1308d28c57257bc2fa7a8d8ccc840af0e38f 100644 (file)
@@ -276,6 +276,15 @@ interface NginxHTTPSendBufferOptions {
 interface NginxHTTPRequest {
     /**
      * Request arguments object.
+     *
+     * Since 0.7.6, duplicate keys are returned as an array, keys are
+     * case-sensitive, both keys and values are percent-decoded.
+     * For example, the query string
+     *
+     * 'a=1&b=%32&A=3&b=4&B=two%20words'
+     * is converted to r.args as:
+     *
+     *   {a: "1", b: ["2", "4"], A: "3", B: "two words"}
      */
     readonly args: NginxHTTPArgs;
     /**
@@ -312,6 +321,7 @@ interface NginxHTTPRequest {
      * Performs an internal redirect to the specified uri.
      * If the uri starts with the “@” prefix, it is considered a named location.
      * The actual redirect happens after the handler execution is completed.
+     * Since 0.7.4, the method accepts escaped URIs.
      * @param uri Location to redirect to.
      */
     internalRedirect(uri: NjsStringOrBuffer): void;
index 7037845225bcd00bee0683c62aaa9c4cda673019..7ac37e1b949da413fe5ae1e47b87a9b22d13f765 100644 (file)
@@ -19,10 +19,14 @@ interface String {
     /**
      * Serializes a Unicode string with code points up to 255
      * into a byte string, otherwise, null is returned.
+     *
+     * @deprecated will be removed in the future.
      */
     toBytes(start?: number, end?: number): NjsByteString | null;
     /**
      * Serializes a Unicode string to a byte string using UTF8 encoding.
+     *
+     * @deprecated will be removed in the future.
      */
     toUTF8(start?: number, end?: number): NjsByteString;
 }
@@ -31,15 +35,21 @@ type NjsByteString = string & {
     /**
      * Returns a new Unicode string from a byte string where each byte is replaced
      * with a corresponding Unicode code point.
+     *
+     * @deprecated will be removed in the future.
      */
     fromBytes(start?: number, end?: number): string;
     /**
      * Converts a byte string containing a valid UTF8 string into a Unicode string,
      * otherwise null is returned.
+     *
+     * @deprecated will be removed in the future.
      */
     fromUTF8(start?: number, end?: number): string | null;
     /**
      * Encodes a byte string to hex, base64, or base64url.
+     *
+     * @deprecated will be removed in the future.
      */
     toString(encoding: Exclude<BufferEncoding, "utf8">): string;
 };
@@ -589,7 +599,17 @@ type NjsStringOrBuffer = NjsStringLike | Buffer | DataView | TypedArray | ArrayB
 // Global objects
 
 interface NjsGlobal {
+    /**
+     * Returns current njs version as a string.
+     * For example, '0.7.4'.
+     */
     readonly version: string;
+    /**
+     * Returns a number with the current version of njs.
+     * For example, “0.7.4” is returned as 0x000704.
+     * @since 0.7.4
+     */
+    readonly version_number: number;
     dump(value: any, indent?: number): string;
     /**
      * Registers a callback for the "exit" event. The callback is called before
@@ -654,3 +674,19 @@ declare function setTimeout<TArgs extends any[]>(callback: (...args: TArgs) => v
  * @param handle A value returned by `setTimeout()`.
  */
 declare function clearTimeout(handle?: TimerHandle): void;
+
+/**
+ * Decodes a string of data which has been encoded using Base64 encoding.
+ *
+ * @param encodedData is a binary string that contains Base64-encoded data.
+ * @returns A string that contains decoded data from encodedData.
+ */
+declare function atob(encodedData: string): string;
+
+/**
+ * Creates a Base64-encoded ASCII string from a binary string.
+ *
+ * @param stringToEncode is a binary string to encode.
+ * @returns A string containing the Base64 representation of stringToEncode.
+ */
+declare function btoa(stringToEncode: string): string;
index a3a5c670f7bcadbce6a69535dea546ff21decb4e..18a96c5738fa0ae77a709322a809fcf85a961430 100644 (file)
@@ -1,7 +1,7 @@
 {
     "compilerOptions": {
         "target": "es5",
-        "module": "ES2017",
+        "module": "ES2015",
         "lib": [
             "ES2015",
             "ES2016.Array.Include",