Welcome! Log In Create A New Profile

Advanced

[njs] Types: updates ts types.

Dmitry Volyntsev
August 03, 2022 11:52PM
details: https://hg.nginx.org/njs/rev/ffd0f3d3f6df
branches:
changeset: 1922:ffd0f3d3f6df
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Wed Aug 03 20:26:24 2022 -0700
description:
Types: updates ts types.

diffstat:

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 deletions(-)

diffs (136 lines):

diff -r 648a8092c05a -r ffd0f3d3f6df test/ts/test.ts
--- a/test/ts/test.ts Tue Aug 02 20:45:17 2022 -0700
+++ b/test/ts/test.ts Wed Aug 03 20:26:24 2022 -0700
@@ -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 -r 648a8092c05a -r ffd0f3d3f6df ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.ts Tue Aug 02 20:45:17 2022 -0700
+++ b/ts/ngx_http_js_module.d.ts Wed Aug 03 20:26:24 2022 -0700
@@ -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 -r 648a8092c05a -r ffd0f3d3f6df ts/njs_core.d.ts
--- a/ts/njs_core.d.ts Tue Aug 02 20:45:17 2022 -0700
+++ b/ts/njs_core.d.ts Wed Aug 03 20:26:24 2022 -0700
@@ -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 |
// 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 extend
* @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 -r 648a8092c05a -r ffd0f3d3f6df ts/tsconfig.json
--- a/ts/tsconfig.json Tue Aug 02 20:45:17 2022 -0700
+++ b/ts/tsconfig.json Wed Aug 03 20:26:24 2022 -0700
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
- "module": "ES2017",
+ "module": "ES2015",
"lib": [
"ES2015",
"ES2016.Array.Include",
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Types: updates ts types.

Dmitry Volyntsev 403 August 03, 2022 11:52PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 296
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready