From 2b6429ead0c88dc60a1c99743e2c4d92b91fe7ca Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 23:10:57 -0300 Subject: import type definitions for dependencies from teal-types --- types/lfs.d.tl | 82 +++++++++++++++++++++++++ types/ltn12.d.tl | 45 ++++++++++++++ types/mimetypes.d.tl | 5 ++ types/socket.d.tl | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ types/socket/http.d.tl | 28 +++++++++ types/ssl.d.tl | 113 +++++++++++++++++++++++++++++++++++ types/ssl/https.d.tl | 50 ++++++++++++++++ types/zlib.d.tl | 10 ++++ 8 files changed, 491 insertions(+) create mode 100644 types/lfs.d.tl create mode 100644 types/ltn12.d.tl create mode 100644 types/mimetypes.d.tl create mode 100644 types/socket.d.tl create mode 100644 types/socket/http.d.tl create mode 100644 types/ssl.d.tl create mode 100644 types/ssl/https.d.tl create mode 100644 types/zlib.d.tl (limited to 'types') diff --git a/types/lfs.d.tl b/types/lfs.d.tl new file mode 100644 index 00000000..12535ca4 --- /dev/null +++ b/types/lfs.d.tl @@ -0,0 +1,82 @@ +local record lfs + + enum FileMode + "file" + "directory" + "link" + "socket" + "named pipe" + "char device" + "block device" + "other" + end + + record Attributes + dev: number + ino: number + mode: FileMode + nlink: number + uid: number + gid: number + rdev: number + access: number + modification: number + change: number + size: number + permissions: string + blocks: number + blksize: number + end + + enum OpenFileMode + "binary" + "text" + end + + enum LockMode + "r" + "w" + end + + record Lock + free: function() + end + + dir: function(string): function(): string + + chdir: function(string): boolean, string + + lock_dir: function(string, number): Lock, string + + -- returns number on success, really!? this should be fixed in the lfs library + link: function(string, string, boolean): number, string + + mkdir: function(string): boolean, string + + rmdir: function(string): boolean, string + + setmode: function(string, OpenFileMode): boolean, string + + currentdir: function(): string + + attributes: function(string): Attributes + attributes: function(string, string): string + attributes: function(string, string): number + attributes: function(string, string): FileMode + attributes: function(string, Attributes): Attributes + + symlinkattributes: function(string): Attributes + symlinkattributes: function(string, string): string + symlinkattributes: function(string, string): number + symlinkattributes: function(string, string): FileMode + symlinkattributes: function(string, Attributes): Attributes + + touch: function(string, number, number): boolean, string + + -- TODO: FILE needs to be renamed to io.FILE in tl itself + lock: function(FILE, LockMode, number, number): boolean, string + unlock: function(FILE, number, number): boolean, string + +end + +return lfs diff --git a/types/ltn12.d.tl b/types/ltn12.d.tl new file mode 100644 index 00000000..cd2375fc --- /dev/null +++ b/types/ltn12.d.tl @@ -0,0 +1,45 @@ + +local record ltn12 + type Filter = function(string): string, string + type Sink = function(string, string): boolean, string + type Source = function(): string, string + + type FancySink = function(string, string): boolean, string | FancySink + type FancySource = function(): string, string | FancySource + + -- Docs just say returns a truthy value on success + -- Since this value should really only be + -- used to check for truthiness, any seems fine here + type Pump = function(Source, Sink): any, string + + record filter + chain: function(Filter, Filter, ...: Filter): Filter + + cycle: function(string, string, any): Filter + end + record pump + all: Pump + step: Pump + end + record sink + chain: function(Filter, Sink): Sink + error: function(string): Sink + file: function(FILE, string): Sink + null: function(): Sink + simplify: function(FancySink): Sink + table: function({string}): Sink, {string} + end + record source + cat: function(Source, ...: Source): Source + chain: function(Source, Filter): Source + empty: function(): Source + error: function(string): Source + file: function(FILE): Source + file: function(FILE, string): Source + simplify: function(FancySource): Source + string: function(string): Source + table: function({string}): Source, {string} + end + end + + return ltn12 \ No newline at end of file diff --git a/types/mimetypes.d.tl b/types/mimetypes.d.tl new file mode 100644 index 00000000..a735225d --- /dev/null +++ b/types/mimetypes.d.tl @@ -0,0 +1,5 @@ +local record mimetypes + guess: function(string): string +end + +return mimetypes \ No newline at end of file diff --git a/types/socket.d.tl b/types/socket.d.tl new file mode 100644 index 00000000..e62e907b --- /dev/null +++ b/types/socket.d.tl @@ -0,0 +1,158 @@ +local ltn12 = require("ltn12") +local Sink = ltn12.Sink +local Source = ltn12.Source + +local record socket + record TCP + -- master methods + bind: function(TCP, string, integer) + connect: function(TCP, string, integer): integer, string + listen: function(TCP, integer): integer, string + + -- client methods + getpeername: function(TCP): string, integer + + enum TCPReceivePattern + "*l" + "*a" + end + enum TCPReceiveError + "closed" + "timeout" + end + receive: function(TCP, TCPReceivePattern|integer, string): string, TCPReceiveError + + send: function(TCP, string, integer, integer): integer, string, integer + + enum TCPShutdownMode + "both" + "send" + "receive" + end + shutdown: function(TCP, TCPShutdownMode): integer + + -- server methods + accept: function(TCP): TCP, string + + -- client and server methods + enum TCPOption + "keepalive" + "reuseaddr" + "tcp-nodelay" + end + enum TCPLinger + "linger" + end + record TCPLingerOption + on: boolean + timeout: integer + end + setoption: function(TCP, TCPOption): integer + setoption: function(TCP, TCPLinger, TCPLingerOption): integer + + -- master, client, and server methods + close: function(TCP) + + getsockname: function(TCP): string, integer + + getstats: function(TCP): integer, integer, integer + + setstats: function(TCP, integer, integer, integer): integer + + enum TCPTimeoutMode + "b" + "t" + end + settimeout: function(TCP, integer, TCPTimeoutMode) + end + record UDP + close: function(UDP) + + getpeername: function(UDP): string, integer + + getsockname: function(UDP): string, integer + + enum UDPTimeout + "timeout" + end + receive: function(UDP, integer): string, UDPTimeout + + receivefrom: function(UDP, integer): string, string, integer, UDPTimeout + + send: function(UDP, string): integer, string + + sendto: function(UDP, string, string, integer): integer, string + + setpeername: function(UDP, string, integer): integer, string + + setsockname: function(UDP, string, integer): integer, string + + enum UDPOptions + "dontroute" + "broadcast" + end + setoption: function(UDP, UDPOptions, boolean): integer, string + + settimeout: function(UDP, integer) + end + tcp: function(): TCP, string + + udp: function(): UDP, string + + record dns + record DNSResolved + name: string + alias: {string} + ip: {string} + end + toip: function(): string + tohostname: function(string): string, DNSResolved|string + gethostname: function(string): string, DNSResolved|string + end + + bind: function(string, integer, integer): TCP + + connect: function(string, integer, string, integer): TCP + + _DEBUG: boolean + + newtry: function(function): function + + protect: function(function): function + + -- tagged records/Table Union types would be nice here, + -- as this should be {TCP|UDP} + -- but I imagine this should be fine for most uses + select: function({UDP}, {UDP}, integer): {UDP}, {UDP}, string + select: function({TCP}, {TCP}, integer): {TCP}, {TCP}, string + + enum SinkMode + "http-chunked" + "close-when-done" + "keep-open" + end + + sink: function(SinkMode, UDP): Sink + sink: function(SinkMode, TCP): Sink + + skip: function(integer, ...: any): any... + + sleep: function(integer) + + enum SourceMode + "http-chunked" + "by-length" + "until-closed" + end + + source: function(SourceMode, TCP, integer): Source + source: function(SourceMode, UDP, integer): Source + + gettime: function(): integer + + try: function(...: any): any... + + _VERSION: string +end + +return socket \ No newline at end of file diff --git a/types/socket/http.d.tl b/types/socket/http.d.tl new file mode 100644 index 00000000..2a64872e --- /dev/null +++ b/types/socket/http.d.tl @@ -0,0 +1,28 @@ +local ltn12 = require("ltn12") +local type Pump = ltn12.Pump +local type Sink = ltn12.Sink +local type Source = ltn12.Source + +local record http + request: function(string): string, integer|string, string, string + request: function(string, string): string, integer|string, string, string + record HTTPRequest + url: string + sink: Sink + method: string + headers: {string:string} + source: Source + step: Pump + proxy: string + redirect: boolean + create: function + end + request: function(HTTPRequest): string, integer|string, string, string + + PORT: integer + PROXY: string + TIMEOUT: integer + USERAGENT: string +end + +return http \ No newline at end of file diff --git a/types/ssl.d.tl b/types/ssl.d.tl new file mode 100644 index 00000000..1bd40348 --- /dev/null +++ b/types/ssl.d.tl @@ -0,0 +1,113 @@ +local socket = require("socket") +local TCP = socket.TCP + +local record ssl + record SSLCertificate + certificate: string + key: string + password: string|function + end + record SSLContext + mode: string + protocol: string + key: string + password: string|function + certificate: string + certificates: {SSLCertificate} + cafile: string + capath: string + verify: string|{string} + options: string|{string} + ciphers: string + ciphersuites: string + depth: number + dhparam: function + curve: string + curves_list: string + verifyext: string|{string} + alpn: string|function|{string} + dane: boolean + end + record X509Certificate + enum Algorithm + "sha1" + "sha256" + "sha512" + end + digest: function(X509Certificate, Algorithm): string + extensions: function(X509Certificate): {string} + issued: function(X509Certificate, X509Certificate): string + issuer: function(X509Certificate): string + notbefore: function(X509Certificate): string + notafter: function(X509Certificate): string + pem: function(X509Certificate): string + pubkey: function(X509Certificate): string + serial: function(X509Certificate): string + enum Encoding + "ai5" + "utf8" + end + setencode: function(X509Certificate, Encoding): string + subject: function(X509Certificate): string + validat: function(X509Certificate, string): boolean + end + record SSLConnection + close: function(SSLConnection) + dohandshake: function(SSLConnection): boolean, string + getalpn: function(SSLConnection): string + getfinished: function(SSLConnection): string + getpeercertificate: function(SSLConnection): X509Certificate + getpeercertificate: function(SSLConnection, number): X509Certificate + getpeerchain: function(SSLConnection): X509Certificate + getpeerverification: function(SSLConnection): string + getpeerfinished: function(SSLConnection): string + getsniname: function(SSLConnection): string + getstats: function(SSLConnection): number, number, number + info: function(SSLConnection): table + info: function(SSLConnection, string): string + enum ReceivePattern + "*a" + "*l" + end + receive: function(SSLConnection, number|ReceivePattern): string, string + receive: function(SSLConnection, number|ReceivePattern, string): string, string + send: function(SSLConnection): number, number|string, number + send: function(SSLConnection, number): number, number|string, number + send: function(SSLConnection, number, number): number, number|string, number + setdane: function(SSLConnection, string) + setstats: function(SSLConnection, number, number, number): number + enum TimeoutMode + "b" + "t" + end + settimeout: function(SSLConnection, number) + settimeout: function(SSLConnection, number, TimeoutMode) + settlsa: function(SSLConnection, number, number, number, number) + sni: function(SSLConnection, string) + sni: function(SSLConnection, {string:SSLContext}) + sni: function(SSLConnection, {string:SSLContext}, boolean) + enum Reason + "read" + "write" + "nothing" + end + want: function(SSLConnection): Reason + end + + record config + protocols: {string:boolean} + curves: {string:boolean} + capabilities: {string:boolean} + options: {string:boolean} + algorithms: {string:boolean} + end + + newcontext: function(SSLContext): SSLContext + wrap: function(TCP, SSLContext): SSLConnection + loadcertificate: function(string): X509Certificate + + _COPYRIGHT: string + _VERSION: string +end + +return ssl \ No newline at end of file diff --git a/types/ssl/https.d.tl b/types/ssl/https.d.tl new file mode 100644 index 00000000..94c38df6 --- /dev/null +++ b/types/ssl/https.d.tl @@ -0,0 +1,50 @@ +local ssl = require("ssl") +local SSLCertificate = ssl.SSLCertificate +local SSLConnection = ssl.SSLConnection + +local ltn12 = require("ltn12") +local Pump = ltn12.Pump +local Sink = ltn12.Sink +local Source = ltn12.Source + +local record https + record HTTPSRequest + -- HTTP options + url: string|{string} + sink: Sink + method: string + headers: {string:string} + source: Source + step: Pump + -- proxy: string -- not supported + -- redirect: boolean -- not supported + -- create: function -- https implements its own + + -- SSL options + mode: string + protocol: string + key: string + password: string|function + certificate: string + certificates: {SSLCertificate} + cafile: string + capath: string + verify: string|{string} + options: string|{string} + ciphers: string + ciphersuites: string + depth: number + dhparam: function + curve: string + curves_list: string + verifyext: string|{string} + alpn: string|function|{string} + dane: boolean + end + request: function(string): string, number, {string:string}, string + request: function(string, string): string, number, {string:string}, string + request: function(HTTPSRequest): string, number, {string:string}, string + tcp: function(): function(): SSLConnection +end + +return https \ No newline at end of file diff --git a/types/zlib.d.tl b/types/zlib.d.tl new file mode 100644 index 00000000..cd08a721 --- /dev/null +++ b/types/zlib.d.tl @@ -0,0 +1,10 @@ +local record zlib + _VERSION: string + deflate: function(integer, integer): function(string, string): string + inflate: function(integer): function(string): string + crc32: function(): function(string): integer + compress: function(string, integer, integer, integer): string + decompress: function(string, integer): string + crc32: function((function(string): integer), string): integer +end +return zlib \ No newline at end of file -- cgit v1.2.3-55-g6feb