From 7e69faeb303f2774dc669694f31470f4044d7e23 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 3 Aug 2022 20:26:24 -0700 Subject: [PATCH] Types: updates ts types. --- test/ts/test.ts | 6 ++++++ ts/ngx_http_js_module.d.ts | 10 ++++++++++ ts/njs_core.d.ts | 36 ++++++++++++++++++++++++++++++++++++ ts/tsconfig.json | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/test/ts/test.ts b/test/ts/test.ts index 0ba55e95..16f511db 100644 --- a/test/ts/test.ts +++ b/test/ts/test.ts @@ -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', ()=> {}); } diff --git a/ts/ngx_http_js_module.d.ts b/ts/ngx_http_js_module.d.ts index 9ed3b92a..7afd1308 100644 --- a/ts/ngx_http_js_module.d.ts +++ b/ts/ngx_http_js_module.d.ts @@ -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; diff --git a/ts/njs_core.d.ts b/ts/njs_core.d.ts index 70378452..7ac37e1b 100644 --- a/ts/njs_core.d.ts +++ b/ts/njs_core.d.ts @@ -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): 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(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; diff --git a/ts/tsconfig.json b/ts/tsconfig.json index a3a5c670..18a96c57 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "module": "ES2017", + "module": "ES2015", "lib": [ "ES2015", "ES2016.Array.Include", -- 2.47.3