From 117c340edbb7512b911038e40201e64135b966f8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 8 May 2022 15:21:35 +0200 Subject: util.async: Add Teal description file --- teal-src/plugins/mod_cron.tl | 2 +- teal-src/util/async.d.tl | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 teal-src/util/async.d.tl (limited to 'teal-src') diff --git a/teal-src/plugins/mod_cron.tl b/teal-src/plugins/mod_cron.tl index f3b8f62f..303ecbf0 100644 --- a/teal-src/plugins/mod_cron.tl +++ b/teal-src/plugins/mod_cron.tl @@ -88,7 +88,7 @@ local function run_task(task : task_spec) task:save(started_at); end -local task_runner = async.runner(run_task); +local task_runner : async.runner_t = async.runner(run_task); module:add_timer(1, function() : integer module:log("info", "Running periodic tasks"); local delay = 3600; diff --git a/teal-src/util/async.d.tl b/teal-src/util/async.d.tl new file mode 100644 index 00000000..a2e41cd6 --- /dev/null +++ b/teal-src/util/async.d.tl @@ -0,0 +1,42 @@ +local record lib + ready : function () : boolean + waiter : function (num : integer, allow_many : boolean) : function (), function () + guarder : function () : function (id : function ()) : function () | nil + record runner_t + func : function (T) + thread : thread + enum state_e + -- from Lua manual + "running" + "suspended" + "normal" + "dead" + + -- from util.async + "ready" + "error" + end + state : state_e + notified_state : state_e + queue : { T } + type watcher_t = function (runner_t, ... : any) + type watchers_t = { state_e : watcher_t } + data : any + id : string + + run : function (runner_t, T) : boolean, state_e, integer + enqueue : function (runner_t, T) : runner_t + log : function (runner_t, string, string, ... : any) + onready : function (runner_t, function) : runner_t + onready : function (runner_t, function) : runner_t + onwaiting : function (runner_t, function) : runner_t + onerror : function (runner_t, function) : runner_t + end + runner : function (function (T), runner_t.watchers_t, any) : runner_t + wait_for : function (any) : any, any + sleep : function (t:number) + + -- set_nexttick = function(new_next_tick) next_tick = new_next_tick; end; + -- set_schedule_function = function (new_schedule_function) schedule_task = new_schedule_function; end; +end +return lib -- cgit v1.2.3 From 04c6caba502115d0611b4313c3228865c48f4285 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 15 May 2022 15:27:35 +0200 Subject: teal/moduleapi: Describe timer wrapper Since it's used in mod_cron --- teal-src/module.d.tl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'teal-src') diff --git a/teal-src/module.d.tl b/teal-src/module.d.tl index 67b2437c..cb7771e2 100644 --- a/teal-src/module.d.tl +++ b/teal-src/module.d.tl @@ -62,7 +62,12 @@ global record moduleapi send_iq : function (moduleapi, st.stanza_t, util_session, number) broadcast : function (moduleapi, { string }, st.stanza_t, function) type timer_callback = function (number, ... : any) : number - add_timer : function (moduleapi, number, timer_callback, ... : any) + record timer_wrapper + stop : function (timer_wrapper) + disarm : function (timer_wrapper) + reschedule : function (timer_wrapper, number) + end + add_timer : function (moduleapi, number, timer_callback, ... : any) : timer_wrapper get_directory : function (moduleapi) : string enum file_mode "r" "w" "a" "r+" "w+" "a+" -- cgit v1.2.3 From 54d1ff8cfd2e51de040a11522f31870b9033dd67 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 15 May 2022 15:29:02 +0200 Subject: mod_cron: Remove difference between teal version This previously was considered an error because the module API Teal spec did not document a return value from module:add_timer() --- teal-src/plugins/mod_cron.tl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'teal-src') diff --git a/teal-src/plugins/mod_cron.tl b/teal-src/plugins/mod_cron.tl index 303ecbf0..7fa2a36b 100644 --- a/teal-src/plugins/mod_cron.tl +++ b/teal-src/plugins/mod_cron.tl @@ -89,7 +89,7 @@ local function run_task(task : task_spec) end local task_runner : async.runner_t = async.runner(run_task); -module:add_timer(1, function() : integer +scheduled = module:add_timer(1, function() : integer module:log("info", "Running periodic tasks"); local delay = 3600; for host in pairs(active_hosts) do -- cgit v1.2.3 From 977373c9887a1087bd64c76a9bb936078994f8b6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 17 May 2022 17:05:15 +0200 Subject: util.stanza: Document error conditions in Teal definition Gets you nice error messages if you make a typo in with error_reply() --- teal-src/util/stanza.d.tl | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/stanza.d.tl b/teal-src/util/stanza.d.tl index a358248a..a04deee0 100644 --- a/teal-src/util/stanza.d.tl +++ b/teal-src/util/stanza.d.tl @@ -4,6 +4,39 @@ local record lib type childtags_iter = function () : stanza_t type maptags_cb = function ( stanza_t ) : stanza_t + + enum stanza_error_type + "auth" + "cancel" + "continue" + "modify" + "wait" + end + enum stanza_error_condition + "bad-request" + "conflict" + "feature-not-implemented" + "forbidden" + "gone" + "internal-server-error" + "item-not-found" + "jid-malformed" + "not-acceptable" + "not-allowed" + "not-authorized" + "policy-violation" + "recipient-unavailable" + "redirect" + "registration-required" + "remote-server-not-found" + "remote-server-timeout" + "resource-constraint" + "service-unavailable" + "subscription-required" + "undefined-condition" + "unexpected-request" + end + record stanza_t name : string attr : { string : string } @@ -35,7 +68,7 @@ local record lib pretty_print : function ( stanza_t ) : string pretty_top_tag : function ( stanza_t ) : string - get_error : function ( stanza_t ) : string, string, string, stanza_t + get_error : function ( stanza_t ) : stanza_error_type, stanza_error_condition, string, stanza_t indent : function ( stanza_t, integer, string ) : stanza_t end @@ -53,7 +86,7 @@ local record lib message : function ( { string : string }, string ) : stanza_t iq : function ( { string : string } ) : stanza_t reply : function ( stanza_t ) : stanza_t - error_reply : function ( stanza_t, string, string, string, string ) + error_reply : function ( stanza_t, stanza_error_type, stanza_error_condition, string, string ) : stanza_t presence : function ( { string : string } ) : stanza_t xml_escape : function ( string ) : string pretty_print : function ( string ) : string -- cgit v1.2.3 From 413b9d70aa337f4ab07fb3cf8adefbe5b411f480 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 17 May 2022 17:06:36 +0200 Subject: util.stanza: Document top level attributes in Teal definition Tells you if you make a typo like "gropchat" or so --- teal-src/util/stanza.d.tl | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/stanza.d.tl b/teal-src/util/stanza.d.tl index a04deee0..1f565b88 100644 --- a/teal-src/util/stanza.d.tl +++ b/teal-src/util/stanza.d.tl @@ -78,16 +78,61 @@ local record lib { serialized_stanza_t | string } end + record message_attr + ["xml:lang"] : string + from : string + id : string + to : string + type : message_type + enum message_type + "chat" + "error" + "groupchat" + "headline" + "normal" + end + end + + record presence_attr + ["xml:lang"] : string + from : string + id : string + to : string + type : presence_type + enum presence_type + "error" + "probe" + "subscribe" + "subscribed" + "unsubscribe" + "unsubscribed" + end + end + + record iq_attr + ["xml:lang"] : string + from : string + id : string + to : string + type : iq_type + enum iq_type + "error" + "get" + "result" + "set" + end + end + stanza : function ( string, { string : string } ) : stanza_t is_stanza : function ( any ) : boolean preserialize : function ( stanza_t ) : serialized_stanza_t deserialize : function ( serialized_stanza_t ) : stanza_t clone : function ( stanza_t, boolean ) : stanza_t - message : function ( { string : string }, string ) : stanza_t - iq : function ( { string : string } ) : stanza_t + message : function ( message_attr, string ) : stanza_t + iq : function ( iq_attr ) : stanza_t reply : function ( stanza_t ) : stanza_t error_reply : function ( stanza_t, stanza_error_type, stanza_error_condition, string, string ) : stanza_t - presence : function ( { string : string } ) : stanza_t + presence : function ( presence_attr ) : stanza_t xml_escape : function ( string ) : string pretty_print : function ( string ) : string end -- cgit v1.2.3 From ae14dc12208406f54c3ac260dc1dfe701e77f3a3 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 29 Nov 2020 17:58:45 +0100 Subject: util.hashes: Expose sha224 and sha384 HMAC functions For completeness and consistency with set of plain hash functions --- teal-src/util/hashes.d.tl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'teal-src') diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl index cbb06f8e..2784a59b 100644 --- a/teal-src/util/hashes.d.tl +++ b/teal-src/util/hashes.d.tl @@ -11,6 +11,8 @@ local record lib md5 : hash hmac_sha1 : hmac hmac_sha256 : hmac + hmac_sha224 : hmac + hmac_sha384 :hmac hmac_sha512 : hmac hmac_md5 : hmac scram_Hi_sha1 : kdf -- cgit v1.2.3 From f3d61e394501472062f359e02ce5d3bb10bc4bc8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 10 Sep 2020 21:58:24 +0200 Subject: util.hashes: Bind BLAKE2 algoritms supported by OpenSSL --- teal-src/util/hashes.d.tl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'teal-src') diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl index 2784a59b..6932ab72 100644 --- a/teal-src/util/hashes.d.tl +++ b/teal-src/util/hashes.d.tl @@ -9,6 +9,8 @@ local record lib sha384 : hash sha512 : hash md5 : hash + blake2s256 : hash + blake2b512 : hash hmac_sha1 : hmac hmac_sha256 : hmac hmac_sha224 : hmac -- cgit v1.2.3 From a7567a9055c959c89d00424cc9c14f64365a8a35 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 10 Sep 2020 21:58:24 +0200 Subject: util.hashes: Add SHA3 bindings --- teal-src/util/hashes.d.tl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'teal-src') diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl index 6932ab72..5c249627 100644 --- a/teal-src/util/hashes.d.tl +++ b/teal-src/util/hashes.d.tl @@ -9,6 +9,8 @@ local record lib sha384 : hash sha512 : hash md5 : hash + sha3_256 : hash + sha3_512 : hash blake2s256 : hash blake2b512 : hash hmac_sha1 : hmac @@ -17,6 +19,8 @@ local record lib hmac_sha384 :hmac hmac_sha512 : hmac hmac_md5 : hmac + hmac_sha3_256 : hmac + hmac_sha3_512 : hmac scram_Hi_sha1 : kdf pbkdf2_hmac_sha1 : kdf pbkdf2_hmac_sha256 : kdf -- cgit v1.2.3 From 8e3e3f3bcd5dab436ac15f55c4244b20027ebabc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 10 Aug 2022 13:45:43 +0200 Subject: util.hex: Update Teal spec for function rename in a0ff5c438e9d --- teal-src/util/hex.d.tl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'teal-src') diff --git a/teal-src/util/hex.d.tl b/teal-src/util/hex.d.tl index 3b216a88..9d84540b 100644 --- a/teal-src/util/hex.d.tl +++ b/teal-src/util/hex.d.tl @@ -2,5 +2,7 @@ local type s2s = function (s : string) : string local record lib to : s2s from : s2s + encode : s2s + decode : s2s end return lib -- cgit v1.2.3 From a8332d2427bf918336f3b0353e28c13280ddd49d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 24 Mar 2021 20:23:38 +0100 Subject: core.storagemanager: Convert old Typed Lua description file into Teal Still only a type definition. Typed Lua is no longer maintained. Teal is currently an active project. --- teal-src/core/storagemanager.d.tl | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 teal-src/core/storagemanager.d.tl (limited to 'teal-src') diff --git a/teal-src/core/storagemanager.d.tl b/teal-src/core/storagemanager.d.tl new file mode 100644 index 00000000..3c8253b1 --- /dev/null +++ b/teal-src/core/storagemanager.d.tl @@ -0,0 +1,74 @@ +-- Storage local record API Description +-- +-- This is written as a TypedLua description + +-- Key-Value stores (the default) + +local stanza = require"util.stanza".stanza_t + +local record keyval_store + get : function ( keyval_store, string ) : any , string + set : function ( keyval_store, string, any ) : boolean, string +end + +-- Map stores (key-key-value stores) + +local record map_store + get : function ( map_store, string, any ) : any, string + set : function ( map_store, string, any, any ) : boolean, string + set_keys : function ( map_store, string, { any : any }) : boolean, string + remove : table +end + +-- Archive stores + +local record archive_query + start : number -- timestamp + ["end"]: number -- timestamp + with : string + after : string -- archive id + before : string -- archive id + total : boolean +end + +local record archive_store + -- Optional set of capabilities + caps : { + -- Optional total count of matching items returned as second return value from :find() + string : any + } + + -- Add to the archive + append : function ( archive_store, string, string, any, number, string ) : string, string + + -- Iterate over archive + type iterator = function () : string, any, number, string + find : function ( archive_store, string, archive_query ) : iterator, integer + + -- Removal of items. API like find. Optional + delete : function ( archive_store, string, archive_query ) : boolean | number, string + + -- Array of dates which do have messages (Optional) + dates : function ( archive_store, string ) : { string }, string + + -- Map of counts per "with" field + summary : function ( archive_store, string, archive_query ) : { string : integer }, string + + -- Map-store API + get : function ( archive_store, string, string ) : stanza, number, string + get : function ( archive_store, string, string ) : nil, string + set : function ( archive_store, string, string, stanza, number, string ) : boolean, string +end + +-- This represents moduleapi +local record coremodule + -- If the first string is omitted then the name of the module is used + -- The second string is one of "keyval" (default), "map" or "archive" + open_store : function (archive_store, string, string) : keyval_store, string + open_store : function (archive_store, string, string) : map_store, string + open_store : function (archive_store, string, string) : archive_store, string + + -- Other module methods omitted +end + +return coremodule -- cgit v1.2.3 From 185b679953985197b6c087487c01e269c749e5c4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Jul 2021 13:18:14 +0200 Subject: util.human.units: Specify enum argument to format() --- teal-src/util/human/units.d.tl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'teal-src') diff --git a/teal-src/util/human/units.d.tl b/teal-src/util/human/units.d.tl index f6568d90..3db17c3a 100644 --- a/teal-src/util/human/units.d.tl +++ b/teal-src/util/human/units.d.tl @@ -1,5 +1,8 @@ local lib = record + enum logbase + "b" -- 1024 + end adjust : function (number, string) : number, string - format : function (number, string, string) : string + format : function (number, string, logbase) : string end return lib -- cgit v1.2.3 From d459ec2f5dcf600840c44b75ff175c349b105bef Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:25:03 +0200 Subject: net.http: Add teal description files --- teal-src/net/http.d.tl | 88 +++++++++++++++++++++++++++++++++++++++++++ teal-src/net/http/codes.d.tl | 2 + teal-src/net/http/errors.d.tl | 22 +++++++++++ teal-src/net/http/files.d.tl | 14 +++++++ teal-src/net/http/parser.d.tl | 58 ++++++++++++++++++++++++++++ teal-src/net/http/server.d.tl | 6 +++ 6 files changed, 190 insertions(+) create mode 100644 teal-src/net/http.d.tl create mode 100644 teal-src/net/http/codes.d.tl create mode 100644 teal-src/net/http/errors.d.tl create mode 100644 teal-src/net/http/files.d.tl create mode 100644 teal-src/net/http/parser.d.tl create mode 100644 teal-src/net/http/server.d.tl (limited to 'teal-src') diff --git a/teal-src/net/http.d.tl b/teal-src/net/http.d.tl new file mode 100644 index 00000000..38da56b6 --- /dev/null +++ b/teal-src/net/http.d.tl @@ -0,0 +1,88 @@ +local record Promise + -- util.promise +end + +local record sslctx -- from LuaSec +end + +local record lib + + enum http_method + "GET" + "HEAD" + "POST" + "PUT" + "OPTIONS" + "DELETE" + -- etc? + end + + record http_client_options + sslctx : sslctx + end + + record http_options + id : string + onlystatus : boolean + body : string + method : http_method + headers : { string : string } + insecure : boolean + suppress_errors : boolean + streaming_handler : function + suppress_url : boolean + sslctx : sslctx + end + + record http_request + host : string + port : string + enum scheme + "http" + "https" + end + scheme : scheme + url : string + userinfo : string + path : string + + method : http_method + headers : { string : string } + + insecure : boolean + suppress_errors : boolean + streaming_handler : function + http : http_client + time : integer + id : string + callback : http_callback + end + + record http_response + end + + type http_callback = function (string, number, http_response, http_request) + + record http_client + options : http_client_options + request : function (http_client, string, http_options, http_callback) + end + + request : function (string, http_options, http_callback) : Promise, string + default : http_client + new : function (http_client_options) : http_client + events : table + -- COMPAT + urlencode : function (string) : string + urldecode : function (string) : string + formencode : function ({ string : string }) : string + formdecode : function (string) : { string : string } + destroy_request : function (http_request) + + enum available_features + "sni" + end + features : { available_features : boolean } +end + +return lib diff --git a/teal-src/net/http/codes.d.tl b/teal-src/net/http/codes.d.tl new file mode 100644 index 00000000..65d004fc --- /dev/null +++ b/teal-src/net/http/codes.d.tl @@ -0,0 +1,2 @@ +local type response_codes = { integer : string } +return response_codes diff --git a/teal-src/net/http/errors.d.tl b/teal-src/net/http/errors.d.tl new file mode 100644 index 00000000..a9b6ea6c --- /dev/null +++ b/teal-src/net/http/errors.d.tl @@ -0,0 +1,22 @@ +local record http_errors + enum known_conditions + "cancelled" + "connection-closed" + "certificate-chain-invalid" + "certificate-verify-failed" + "connection failed" + "invalid-url" + "unable to resolve service" + end + type registry_keys = known_conditions | integer + record error + type : string + condition : string + code : integer + text : string + end + registry : { registry_keys : error } + new : function (integer, known_conditions, table) + new : function (integer, string, table) +end +return http_errors diff --git a/teal-src/net/http/files.d.tl b/teal-src/net/http/files.d.tl new file mode 100644 index 00000000..d0ba5c1c --- /dev/null +++ b/teal-src/net/http/files.d.tl @@ -0,0 +1,14 @@ +local record serve_options + path : string + mime_map : { string : string } + cache_size : integer + cache_max_file_size : integer + index_files : { string } + directory_index : boolean +end + +local record http_files + serve : function(serve_options|string) : function +end + +return http_files diff --git a/teal-src/net/http/parser.d.tl b/teal-src/net/http/parser.d.tl new file mode 100644 index 00000000..1cd6ccf4 --- /dev/null +++ b/teal-src/net/http/parser.d.tl @@ -0,0 +1,58 @@ +local record httpstream + feed : function(httpstream, string) +end + +local type sink_cb = function () + +local record httppacket + enum http_method + "HEAD" + "GET" + "POST" + "PUT" + "DELETE" + "OPTIONS" + -- etc + end + method : http_method + record url_details + path : string + query : string + end + url : url_details + path : string + enum http_version + "1.0" + "1.1" + end + httpversion : http_version + headers : { string : string } + body : string | boolean + body_sink : sink_cb + chunked : boolean + partial : boolean +end + +local enum error_conditions + "cancelled" + "connection-closed" + "certificate-chain-invalid" + "certificate-verify-failed" + "connection failed" + "invalid-url" + "unable to resolve service" +end + +local type success_cb = function (httppacket) +local type error_cb = function (error_conditions) + +local enum stream_mode + "client" + "server" +end + +local record lib + new : function (success_cb, error_cb, stream_mode) : httpstream +end + +return lib diff --git a/teal-src/net/http/server.d.tl b/teal-src/net/http/server.d.tl new file mode 100644 index 00000000..5a83af7e --- /dev/null +++ b/teal-src/net/http/server.d.tl @@ -0,0 +1,6 @@ + +local record http_server + -- TODO +end + +return http_server -- cgit v1.2.3 From 0ed1e69a4e78612fe27426f716ce8faa6042a24a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:25:17 +0200 Subject: net.server: Add teal description file --- teal-src/net/server.d.tl | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 teal-src/net/server.d.tl (limited to 'teal-src') diff --git a/teal-src/net/server.d.tl b/teal-src/net/server.d.tl new file mode 100644 index 00000000..bb61f677 --- /dev/null +++ b/teal-src/net/server.d.tl @@ -0,0 +1,65 @@ +local record server + record LuaSocketTCP + end + record LuaSecCTX + end + + record extra_settings + end + + record interface + end + enum socket_type + "tcp" + "tcp6" + "tcp4" + end + + record listeners + onconnect : function (interface) + ondetach : function (interface) + onattach : function (interface, string) + onincoming : function (interface, string, string) + ondrain : function (interface) + onreadtimeout : function (interface) + onstarttls : function (interface) + onstatus : function (interface, string) + ondisconnect : function (interface, string) + end + + get_backend : function () : string + + type port = string | integer + enum read_mode + "*a" + "*l" + end + type read_size = read_mode | integer + addserver : function (string, port, listeners, read_size, LuaSecCTX) : interface + addclient : function (string, port, listeners, read_size, LuaSecCTX, socket_type, extra_settings) : interface + record listen_config + read_size : read_size + tls_ctx : LuaSecCTX + tls_direct : boolean + sni_hosts : { string : LuaSecCTX } + end + listen : function (string, port, listeners, listen_config) : interface + enum quitting + "quitting" + end + loop : function () : quitting + closeall : function () + setquitting : function (boolean | quitting) + + wrapclient : function (LuaSocketTCP, string, port, listeners, read_size, LuaSecCTX, extra_settings) : interface + wrapserver : function (LuaSocketTCP, string, port, listeners, listen_config) : interface + watchfd : function (integer | LuaSocketTCP, function (interface), function (interface)) : interface + link : function () + + record config + end + set_config : function (config) + +end + +return server -- cgit v1.2.3 From 53907b44cee9c5acfb6979d6f60b9f285a064bc7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:25:31 +0200 Subject: teal: add stub util.array teal defs --- teal-src/util/array.d.tl | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 teal-src/util/array.d.tl (limited to 'teal-src') diff --git a/teal-src/util/array.d.tl b/teal-src/util/array.d.tl new file mode 100644 index 00000000..70bf2624 --- /dev/null +++ b/teal-src/util/array.d.tl @@ -0,0 +1,9 @@ +local record array_t + { T } +end + +local record lib + metamethod __call : function () : array_t +end + +return lib -- cgit v1.2.3 From 523d844c789556f259244c2139009eff924e91ae Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:25:41 +0200 Subject: util.promise: Add Teal interface specification file --- teal-src/net/http.d.tl | 4 +--- teal-src/util/promise.d.tl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 teal-src/util/promise.d.tl (limited to 'teal-src') diff --git a/teal-src/net/http.d.tl b/teal-src/net/http.d.tl index 38da56b6..9135ec12 100644 --- a/teal-src/net/http.d.tl +++ b/teal-src/net/http.d.tl @@ -1,6 +1,4 @@ -local record Promise - -- util.promise -end +local Promise = require "util.promise".Promise; local record sslctx -- from LuaSec end diff --git a/teal-src/util/promise.d.tl b/teal-src/util/promise.d.tl new file mode 100644 index 00000000..d895a828 --- /dev/null +++ b/teal-src/util/promise.d.tl @@ -0,0 +1,22 @@ + +local record lib + type resolve_func = function (any) + type promise_body = function (resolve_func, resolve_func) + + record Promise + type on_resolved = function (A) : any + type on_rejected = function (B) : any + next : function (Promise, on_resolved, on_rejected) : Promise + end + + new : function (promise_body) : Promise + resolve : function (any) : Promise + reject : function (any) : Promise + all : function ({ Promise }) : Promise + all_settled : function ({ Promise }) : Promise + race : function ({ Promise }) : Promise + try : function + is_promise : function(any) : boolean +end + +return lib -- cgit v1.2.3 From 238c64e233938970224ad691831336cbfa08cdfd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 10 Nov 2021 15:12:03 +0100 Subject: util.human.io: Add Teal interface definition --- teal-src/util/human/io.d.tl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 teal-src/util/human/io.d.tl (limited to 'teal-src') diff --git a/teal-src/util/human/io.d.tl b/teal-src/util/human/io.d.tl new file mode 100644 index 00000000..e4f64cd1 --- /dev/null +++ b/teal-src/util/human/io.d.tl @@ -0,0 +1,28 @@ +local record lib + getchar : function (n : integer) : string + getline : function () : string + getpass : function () : string + show_yesno : function (prompt : string) : boolean + read_password : function () : string + show_prompt : function (prompt : string) : boolean + printf : function (fmt : string, ... : any) + padleft : function (s : string, width : integer) : string + padright : function (s : string, width : integer) : string + + -- {K:V} vs T ? + record tablerow + width : integer | string -- generate an 1..100 % enum? + title : string + mapper : function (V, {K:V}) : string + key : K + enum alignments + "left" + "right" + end + align : alignments + end + type getrow = function ({ K : V }) : string + table : function ({ tablerow }, width : integer) : getrow +end + +return lib -- cgit v1.2.3 From dff6720958a1cb46f4ce5c2721c67bc94cb80450 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 15 Nov 2021 17:07:23 +0100 Subject: util.dataforms: Restructure Teal definition file The PR has been merged and there's no reason not to have nested records and other definitions. --- teal-src/util/dataforms.d.tl | 91 ++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 45 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/dataforms.d.tl b/teal-src/util/dataforms.d.tl index 9e4170fa..eac55717 100644 --- a/teal-src/util/dataforms.d.tl +++ b/teal-src/util/dataforms.d.tl @@ -1,51 +1,52 @@ local stanza_t = require "util.stanza".stanza_t -local enum form_type - "form" - "submit" - "cancel" - "result" -end - -local enum field_type - "boolean" - "fixed" - "hidden" - "jid-multi" - "jid-single" - "list-multi" - "list-single" - "text-multi" - "text-private" - "text-single" -end - -local record form_field - - type : field_type - var : string -- protocol name - name : string -- internal name - - label : string - desc : string - - datatype : string - range_min : number - range_max : number - - value : any -- depends on field_type - options : table -end - -local record dataform - title : string - instructions : string - { form_field } -- XXX https://github.com/teal-language/tl/pull/415 - - form : function ( dataform, table, form_type ) : stanza_t -end - local record lib + record dataform + title : string + instructions : string + + record form_field + + enum field_type + "boolean" + "fixed" + "hidden" + "jid-multi" + "jid-single" + "list-multi" + "list-single" + "text-multi" + "text-private" + "text-single" + end + + type : field_type + var : string -- protocol name + name : string -- internal name + + label : string + desc : string + + datatype : string + range_min : number + range_max : number + + value : any -- depends on field_type + options : table + end + + { form_field } + + enum form_type + "form" + "submit" + "cancel" + "result" + end + + form : function ( dataform, { string : any }, form_type ) : stanza_t + end + new : function ( dataform ) : dataform end -- cgit v1.2.3 From 9dc7ac98fa5a71e1e2019dd1b6fefde9a6842b5a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 15 Nov 2021 17:15:22 +0100 Subject: util.dataforms: Add missing :data() to Teal definition --- teal-src/util/dataforms.d.tl | 1 + 1 file changed, 1 insertion(+) (limited to 'teal-src') diff --git a/teal-src/util/dataforms.d.tl b/teal-src/util/dataforms.d.tl index eac55717..0eddf98e 100644 --- a/teal-src/util/dataforms.d.tl +++ b/teal-src/util/dataforms.d.tl @@ -45,6 +45,7 @@ local record lib end form : function ( dataform, { string : any }, form_type ) : stanza_t + data : function ( dataform, stanza_t ) : { string : any } end new : function ( dataform ) : dataform -- cgit v1.2.3 From efb69fa99bc19dc1beab79829bf98987ab5a4a33 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 1 Dec 2021 15:05:06 +0100 Subject: util.serialization: Add Teal type specification --- teal-src/util/serialization.d.tl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 teal-src/util/serialization.d.tl (limited to 'teal-src') diff --git a/teal-src/util/serialization.d.tl b/teal-src/util/serialization.d.tl new file mode 100644 index 00000000..27f100c0 --- /dev/null +++ b/teal-src/util/serialization.d.tl @@ -0,0 +1,33 @@ +local record _M + enum preset + "debug" + "oneline" + "compact" + end + type fallback = function (any, string) : string + record config + preset : preset + fallback : fallback + fatal : boolean + keywords : { string : boolean } + indentwith : string + itemstart : string + itemsep : string + itemlast : string + tstart : string + tend : string + kstart : string + kend : string + equals : string + unquoted : boolean | string + hex : string + freeze : boolean + maxdepth : integer + multirefs : boolean + table_pairs : function + end + type serializer = function (any) : string + new : function (config|preset) : serializer + serialize : function (any, config|preset) : string +end +return _M -- cgit v1.2.3 From dfa35e5217b21c8ea8e10a1128c50d07e67c056b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 16 Feb 2022 16:42:22 +0100 Subject: util.set: Add teal type declaration file --- teal-src/util/set.d.tl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 teal-src/util/set.d.tl (limited to 'teal-src') diff --git a/teal-src/util/set.d.tl b/teal-src/util/set.d.tl new file mode 100644 index 00000000..1631eec4 --- /dev/null +++ b/teal-src/util/set.d.tl @@ -0,0 +1,21 @@ +local record lib + record Set + add : function (Set, T) + contains : function (Set, T) : boolean + contains_set : function (Set, Set) : boolean + items : function (Set) : function (Set, T) : T + add_list : function (Set, { T }) + include : function (Set, Set) + exclude : function (Set, Set) + empty : function (Set) : boolean + end + + new : function ({ T }) : Set + is_set : function (any) : boolean + union : function (Set, Set) : Set + difference : function (Set, Set) : Set + intersection : function (Set, Set) : Set + xor : function (Set, Set) : Set +end + +return lib -- cgit v1.2.3 From a9c96e12c2b2cbe40604571e2d81027fa4139aa6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 15 Jun 2022 15:40:03 +0200 Subject: util.table: Add move() to Teal interface description file --- teal-src/util/table.d.tl | 1 + 1 file changed, 1 insertion(+) (limited to 'teal-src') diff --git a/teal-src/util/table.d.tl b/teal-src/util/table.d.tl index 0ff5ed95..67e5d0f0 100644 --- a/teal-src/util/table.d.tl +++ b/teal-src/util/table.d.tl @@ -1,6 +1,7 @@ local record lib create : function (narr:integer, nrec:integer):table pack : function (...:any):{any} + move : function (table, integer, integer, integer, table) : table end return lib -- cgit v1.2.3 From 64641500885e86a28f79c69dbeb85ba2fa2566a3 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 15 Jun 2022 15:51:57 +0200 Subject: util.struct: Add Teal interface description file --- teal-src/util/struct.d.tl | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 teal-src/util/struct.d.tl (limited to 'teal-src') diff --git a/teal-src/util/struct.d.tl b/teal-src/util/struct.d.tl new file mode 100644 index 00000000..201aaa23 --- /dev/null +++ b/teal-src/util/struct.d.tl @@ -0,0 +1,6 @@ +local record lib + pack : function (string, ...:any) : string + unpack : function(string, string, integer) : any... + size : function(string) : integer +end +return lib -- cgit v1.2.3 From 6e1de3134c037a4308531c031f9eae401091ed76 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Jun 2022 15:39:03 +0200 Subject: util.bitcompat: Add Teal type specification --- teal-src/util/bitcompat.d.tl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 teal-src/util/bitcompat.d.tl (limited to 'teal-src') diff --git a/teal-src/util/bitcompat.d.tl b/teal-src/util/bitcompat.d.tl new file mode 100644 index 00000000..18adf725 --- /dev/null +++ b/teal-src/util/bitcompat.d.tl @@ -0,0 +1,8 @@ +local record lib + band : function (integer, integer, ... : integer) : integer + bor : function (integer, integer, ... : integer) : integer + bxor : function (integer, integer, ... : integer) : integer + lshift : function (integer, integer) : integer + rshift : function (integer, integer) : integer +end +return lib -- cgit v1.2.3 From 90dd7f694318b638ff1eef4d9a6e2e6f7f69820f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:39:07 +0200 Subject: util.logger: Add Teal interface description --- teal-src/util/logger.d.tl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 teal-src/util/logger.d.tl (limited to 'teal-src') diff --git a/teal-src/util/logger.d.tl b/teal-src/util/logger.d.tl new file mode 100644 index 00000000..db29adfd --- /dev/null +++ b/teal-src/util/logger.d.tl @@ -0,0 +1,18 @@ +local record util + enum loglevel + "debug" + "info" + "warn" + "error" + end + type logger = function ( loglevel, string, ...:any ) + type sink = function ( string, loglevel, string, ...:any ) + type simple_sink = function ( string, loglevel, string ) + init : function ( string ) : logger + make_logger : function ( string, loglevel ) : function ( string, ...:any ) + reset : function () + add_level_sink : function ( loglevel, sink ) + add_simple_sink : function ( simple_sink, { loglevel } ) +end + +return util -- cgit v1.2.3 From f307901a09bbb426ae3e0ccf3dec40b69ef68b8f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:39:32 +0200 Subject: util.queue: Add Teal interface description --- teal-src/util/queue.d.tl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 teal-src/util/queue.d.tl (limited to 'teal-src') diff --git a/teal-src/util/queue.d.tl b/teal-src/util/queue.d.tl new file mode 100644 index 00000000..cb8458e7 --- /dev/null +++ b/teal-src/util/queue.d.tl @@ -0,0 +1,21 @@ +local record lib + record queue + size : integer + count : function (queue) : integer + enum push_errors + "queue full" + end + + push : function (queue, T) : boolean, push_errors + pop : function (queue) : T + peek : function (queue) : T + replace : function (queue, T) : boolean, push_errors + type iterator = function (T, integer) : integer, T + items : function (queue) : iterator, T, integer + type consume_iter = function (queue) : T + consume : function (queue) : consume_iter + end + + new : function (size:integer, allow_wrapping:boolean) : queue +end +return lib; -- cgit v1.2.3 From 49497f25d3b9db07521f0a45fa2e949f72dbbf7d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:39:46 +0200 Subject: util.termcolours: Add Teal interface description --- teal-src/util/termcolours.d.tl | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 teal-src/util/termcolours.d.tl (limited to 'teal-src') diff --git a/teal-src/util/termcolours.d.tl b/teal-src/util/termcolours.d.tl new file mode 100644 index 00000000..226259aa --- /dev/null +++ b/teal-src/util/termcolours.d.tl @@ -0,0 +1,7 @@ +local record lib + getstring : function (string, string) : string + getstyle : function (...:string) : string + setstyle : function (string) : string + tohtml : function (string) : string +end +return lib -- cgit v1.2.3 From 93f6968077f48338ff7f925e45f365e7084dd524 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Jul 2022 21:39:51 +0200 Subject: util.timer: Add Teal interface description --- teal-src/util/timer.d.tl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 teal-src/util/timer.d.tl (limited to 'teal-src') diff --git a/teal-src/util/timer.d.tl b/teal-src/util/timer.d.tl new file mode 100644 index 00000000..a6394cf3 --- /dev/null +++ b/teal-src/util/timer.d.tl @@ -0,0 +1,8 @@ +local record util_timer + record task end + type timer_callback = function (number) : number + add_task : function ( number, timer_callback, any ) : task + stop : function ( task ) + reschedule : function ( task, number ) : task +end +return util_timer -- cgit v1.2.3 From 9daa82bfc1d3c65ba8c766b277b5846755917439 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 10 Aug 2022 15:10:14 +0200 Subject: util.uuid: Fix syntax of Teal interface declaration file --- teal-src/util/uuid.d.tl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'teal-src') diff --git a/teal-src/util/uuid.d.tl b/teal-src/util/uuid.d.tl index 45fd4312..284a4e4c 100644 --- a/teal-src/util/uuid.d.tl +++ b/teal-src/util/uuid.d.tl @@ -1,5 +1,5 @@ local record lib - get_nibbles : (number) : string + get_nibbles : function (number) : string generate : function () : string seed : function (string) -- cgit v1.2.3 From d7b7e4afb5df5006db1b127e5033050d5e62d079 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 10 Aug 2022 15:10:50 +0200 Subject: util.error: Use avoid name conflict in Teal interface declaration Naming things ... Thing or thing_t? --- teal-src/util/error.d.tl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/error.d.tl b/teal-src/util/error.d.tl index 05f52405..4c3a7196 100644 --- a/teal-src/util/error.d.tl +++ b/teal-src/util/error.d.tl @@ -38,7 +38,7 @@ local record protoerror code : integer end -local record error +local record Error type : error_type condition : error_condition text : string @@ -55,10 +55,10 @@ local type context = { string : any } local record error_registry_wrapper source : string registry : registry - new : function (string, context) : error - coerce : function (any, string) : any, error - wrap : function (error) : error - wrap : function (string, context) : error + new : function (string, context) : Error + coerce : function (any, string) : any, Error + wrap : function (Error) : Error + wrap : function (string, context) : Error is_error : function (any) : boolean end @@ -66,12 +66,12 @@ local record lib record configure_opt auto_inject_traceback : boolean end - new : function (protoerror, context, { string : protoerror }, string) : error + new : function (protoerror, context, { string : protoerror }, string) : Error init : function (string, string, registry | compact_registry) : error_registry_wrapper init : function (string, registry | compact_registry) : error_registry_wrapper is_error : function (any) : boolean - coerce : function (any, string) : any, error - from_stanza : function (table, context, string) : error + coerce : function (any, string) : any, Error + from_stanza : function (table, context, string) : Error configure : function end -- cgit v1.2.3 From 48ee5e3cbd3acaaeae817af0646a60dbdfa79639 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 10 Aug 2022 15:12:00 +0200 Subject: util.signal: Fix name conflict in Teal interface declaration --- teal-src/util/signal.d.tl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/signal.d.tl b/teal-src/util/signal.d.tl index 8610aa7f..290cf08f 100644 --- a/teal-src/util/signal.d.tl +++ b/teal-src/util/signal.d.tl @@ -1,5 +1,5 @@ local record lib - enum signal + enum Signal "SIGABRT" "SIGALRM" "SIGBUS" @@ -33,9 +33,9 @@ local record lib "SIGXCPU" "SIGXFSZ" end - signal : function (integer | signal, function, boolean) : boolean - raise : function (integer | signal) - kill : function (integer, integer | signal) + signal : function (integer | Signal, function, boolean) : boolean + raise : function (integer | Signal) + kill : function (integer, integer | Signal) -- enum : integer end return lib -- cgit v1.2.3 From cbff90a7ac5236a86accefdfd501147a1b5007fc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 17 Aug 2022 18:41:35 +0200 Subject: util.datetime: Update Teal interface description Integers were required before, now any number should work. --- teal-src/util/datetime.d.tl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/datetime.d.tl b/teal-src/util/datetime.d.tl index 971e8f9c..9f770a73 100644 --- a/teal-src/util/datetime.d.tl +++ b/teal-src/util/datetime.d.tl @@ -1,11 +1,9 @@ --- TODO s/number/integer/ once Teal gets support for that - local record lib - date : function (t : integer) : string - datetime : function (t : integer) : string - time : function (t : integer) : string - legacy : function (t : integer) : string - parse : function (t : string) : integer + date : function (t : number) : string + datetime : function (t : number) : string + time : function (t : number) : string + legacy : function (t : number) : string + parse : function (t : string) : number end return lib -- cgit v1.2.3 From 57ed2e28a09933dd6220dd6ddd84f0f442e9b71f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 15 Jun 2022 14:22:26 +0100 Subject: teal-src: update module.d.tl with new access control methods --- teal-src/module.d.tl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'teal-src') diff --git a/teal-src/module.d.tl b/teal-src/module.d.tl index cb7771e2..24eb9558 100644 --- a/teal-src/module.d.tl +++ b/teal-src/module.d.tl @@ -126,6 +126,11 @@ global record moduleapi path : string resource_path : string + -- access control + may : function (moduleapi, string, table|string) + default_permission : function (string, string) + default_permissions : function (string, { string }) + -- methods the module can add load : function () add_host : function (moduleapi) -- cgit v1.2.3 From 2b0676396dc84dad48735a9e3782bb4f13b36471 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 12 Aug 2022 22:09:09 +0200 Subject: util.roles: Add Teal interface declaration --- teal-src/util/roles.d.tl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 teal-src/util/roles.d.tl (limited to 'teal-src') diff --git a/teal-src/util/roles.d.tl b/teal-src/util/roles.d.tl new file mode 100644 index 00000000..fef4f88a --- /dev/null +++ b/teal-src/util/roles.d.tl @@ -0,0 +1,32 @@ +local record util_roles + + type context = any + + record Role + id : string + name : string + description : string + default : boolean + priority : number -- or integer? + permissions : { string : boolean } + + may : function (Role, string, context) + clone : function (Role, role_config) + set_permission : function (Role, string, boolean, boolean) + end + + is_role : function (any) : boolean + + record role_config + name : string + description : string + default : boolean + priority : number -- or integer? + inherits : { Role } + permissions : { string : boolean } + end + + new : function (role_config, Role) : Role +end + +return util_roles -- cgit v1.2.3 From d9ce2d5e4e6ebc7a09d71a590b1243ca5f4d5f85 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 Jun 2022 15:38:22 +0200 Subject: util.crypto: Add Teal type specification --- teal-src/util/crypto.d.tl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 teal-src/util/crypto.d.tl (limited to 'teal-src') diff --git a/teal-src/util/crypto.d.tl b/teal-src/util/crypto.d.tl new file mode 100644 index 00000000..cf0b0d1b --- /dev/null +++ b/teal-src/util/crypto.d.tl @@ -0,0 +1,29 @@ +local record lib + record key + private_pem : function (key) : string + public_pem : function (key) : string + get_type : function (key) : string + end + + generate_ed25519_keypair : function () : key + ed25519_sign : function (key, string) : string + ed25519_verify : function (key, string, string) : boolean + + ecdsa_sha256_sign : function (key, string) : string + ecdsa_sha256_verify : function (key, string, string) : boolean + parse_ecdsa_signature : function (string) : string, string + build_ecdsa_signature : function (string, string) : string + + import_private_pem : function (string) : key + import_public_pem : function (string) : key + + aes_128_gcm_encrypt : function (key, string, string) : string + aes_128_gcm_decrypt : function (key, string, string) : string + aes_256_gcm_encrypt : function (key, string, string) : string + aes_256_gcm_decrypt : function (key, string, string) : string + + + version : string + _LIBCRYPTO_VERSION : string +end +return lib -- cgit v1.2.3 From aa8f7d1533ae86e6832a5a1ec506d58dee213d36 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 17 Oct 2022 15:13:04 +0200 Subject: util.stanza: Add new methods to Teal interface specification at_top: 21217f7e82b9 get_child_with_attr: 39164ea2ab9e get_child_attr: e8934ce6ea0f add_error: 5f182bccf33f --- teal-src/util/stanza.d.tl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'teal-src') diff --git a/teal-src/util/stanza.d.tl b/teal-src/util/stanza.d.tl index 1f565b88..e1ab2105 100644 --- a/teal-src/util/stanza.d.tl +++ b/teal-src/util/stanza.d.tl @@ -49,6 +49,7 @@ local record lib tag : function ( stanza_t, string, { string : string } ) : stanza_t text : function ( stanza_t, string ) : stanza_t up : function ( stanza_t ) : stanza_t + at_top : function ( stanza_t ) : boolean reset : function ( stanza_t ) : stanza_t add_direct_child : function ( stanza_t, stanza_t ) add_child : function ( stanza_t, stanza_t ) @@ -57,6 +58,8 @@ local record lib get_child : function ( stanza_t, string, string ) : stanza_t get_text : function ( stanza_t ) : string get_child_text : function ( stanza_t, string, string ) : string + get_child_attr : function ( stanza_t, string, string ) : string + get_child_with_attr : function ( stanza_t, string, string, string, function (string) : boolean ) : string child_with_name : function ( stanza_t, string, string ) : stanza_t child_with_ns : function ( stanza_t, string, string ) : stanza_t children : function ( stanza_t ) : children_iter, stanza_t, integer @@ -68,7 +71,9 @@ local record lib pretty_print : function ( stanza_t ) : string pretty_top_tag : function ( stanza_t ) : string + -- FIXME Represent util.error support get_error : function ( stanza_t ) : stanza_error_type, stanza_error_condition, string, stanza_t + add_error : function ( stanza_t, stanza_error_type, stanza_error_condition, string, string ) indent : function ( stanza_t, integer, string ) : stanza_t end -- cgit v1.2.3 From 7be6630dfe1f828603b455279b69947edda40c4c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Oct 2022 14:07:48 +0200 Subject: util.datamapper: Remove leftover debug assert (Only Teal, not included in build) --- teal-src/util/datamapper.tl | 4 ---- 1 file changed, 4 deletions(-) (limited to 'teal-src') diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl index 73b1dfc0..23f5ecaa 100644 --- a/teal-src/util/datamapper.tl +++ b/teal-src/util/datamapper.tl @@ -133,10 +133,6 @@ local function unpack_propschema( propschema : schema_t, propname : string, curr end end - if current_ns == "urn:xmpp:reactions:0" and name == "reactions" then - assert(proptype=="array") - end - return proptype, value_where, name, namespace, prefix, single_attribute, enums end -- cgit v1.2.3 From e2cff346410c57686478d68fabd96cf4247df927 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 20 Oct 2022 16:50:12 +0200 Subject: util.mathcompat: Module to ease reuse of math.type() Mostly to ensure it is available during tests, as util.startup is not invoked there --- teal-src/util/datamapper.tl | 2 ++ teal-src/util/jsonschema.tl | 2 ++ teal-src/util/mathcompat.tl | 15 +++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 teal-src/util/mathcompat.tl (limited to 'teal-src') diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl index 23f5ecaa..4ff3a02c 100644 --- a/teal-src/util/datamapper.tl +++ b/teal-src/util/datamapper.tl @@ -19,6 +19,8 @@ -- TODO s/number/integer/ once we have appropriate math.type() compat -- +if not math.type then require "util.mathcompat" end + local st = require "util.stanza"; local json = require"util.json" local pointer = require"util.jsonpointer"; diff --git a/teal-src/util/jsonschema.tl b/teal-src/util/jsonschema.tl index 160c164c..14b04370 100644 --- a/teal-src/util/jsonschema.tl +++ b/teal-src/util/jsonschema.tl @@ -8,6 +8,8 @@ -- https://json-schema.org/draft/2020-12/json-schema-validation.html -- +if not math.type then require "util.mathcompat" end + local json = require"util.json" local null = json.null; diff --git a/teal-src/util/mathcompat.tl b/teal-src/util/mathcompat.tl new file mode 100644 index 00000000..1e3f9bab --- /dev/null +++ b/teal-src/util/mathcompat.tl @@ -0,0 +1,15 @@ +if not math.type then + local enum number_subtype + "float" "integer" + end + local function math_type(t:any) : number_subtype + if t is number then + if t % 1 == 0 and t ~= t+1 and t ~= t-1 then + return "integer" + else + return "float" + end + end + end + _G.math.type = math_type +end -- cgit v1.2.3