aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src
diff options
context:
space:
mode:
Diffstat (limited to 'teal-src')
-rw-r--r--teal-src/core/storagemanager.d.tl74
-rw-r--r--teal-src/module.d.tl12
-rw-r--r--teal-src/net/http.d.tl86
-rw-r--r--teal-src/net/http/codes.d.tl2
-rw-r--r--teal-src/net/http/errors.d.tl22
-rw-r--r--teal-src/net/http/files.d.tl14
-rw-r--r--teal-src/net/http/parser.d.tl58
-rw-r--r--teal-src/net/http/server.d.tl6
-rw-r--r--teal-src/net/server.d.tl65
-rw-r--r--teal-src/plugins/mod_cron.tl4
-rw-r--r--teal-src/util/array.d.tl9
-rw-r--r--teal-src/util/async.d.tl42
-rw-r--r--teal-src/util/bitcompat.d.tl8
-rw-r--r--teal-src/util/crypto.d.tl29
-rw-r--r--teal-src/util/dataforms.d.tl92
-rw-r--r--teal-src/util/datamapper.tl6
-rw-r--r--teal-src/util/datetime.d.tl12
-rw-r--r--teal-src/util/error.d.tl16
-rw-r--r--teal-src/util/hashes.d.tl8
-rw-r--r--teal-src/util/hex.d.tl2
-rw-r--r--teal-src/util/human/io.d.tl28
-rw-r--r--teal-src/util/human/units.d.tl5
-rw-r--r--teal-src/util/jsonschema.tl2
-rw-r--r--teal-src/util/logger.d.tl18
-rw-r--r--teal-src/util/mathcompat.tl15
-rw-r--r--teal-src/util/promise.d.tl22
-rw-r--r--teal-src/util/queue.d.tl21
-rw-r--r--teal-src/util/roles.d.tl32
-rw-r--r--teal-src/util/serialization.d.tl33
-rw-r--r--teal-src/util/set.d.tl21
-rw-r--r--teal-src/util/signal.d.tl8
-rw-r--r--teal-src/util/stanza.d.tl93
-rw-r--r--teal-src/util/struct.d.tl6
-rw-r--r--teal-src/util/table.d.tl1
-rw-r--r--teal-src/util/termcolours.d.tl7
-rw-r--r--teal-src/util/timer.d.tl8
-rw-r--r--teal-src/util/uuid.d.tl2
37 files changed, 811 insertions, 78 deletions
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
diff --git a/teal-src/module.d.tl b/teal-src/module.d.tl
index 67b2437c..24eb9558 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+"
@@ -121,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)
diff --git a/teal-src/net/http.d.tl b/teal-src/net/http.d.tl
new file mode 100644
index 00000000..9135ec12
--- /dev/null
+++ b/teal-src/net/http.d.tl
@@ -0,0 +1,86 @@
+local Promise = require "util.promise".Promise;
+
+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
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
diff --git a/teal-src/plugins/mod_cron.tl b/teal-src/plugins/mod_cron.tl
index f3b8f62f..7fa2a36b 100644
--- a/teal-src/plugins/mod_cron.tl
+++ b/teal-src/plugins/mod_cron.tl
@@ -88,8 +88,8 @@ local function run_task(task : task_spec)
task:save(started_at);
end
-local task_runner = async.runner(run_task);
-module:add_timer(1, function() : integer
+local task_runner : async.runner_t<task_spec> = async.runner(run_task);
+scheduled = module:add_timer(1, function() : integer
module:log("info", "Running periodic tasks");
local delay = 3600;
for host in pairs(active_hosts) do
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>
+ { T }
+end
+
+local record lib
+ metamethod __call : function () : array_t
+end
+
+return lib
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<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<T>, ... : any)
+ type watchers_t = { state_e : watcher_t }
+ data : any
+ id : string
+
+ run : function (runner_t<T>, T) : boolean, state_e, integer
+ enqueue : function (runner_t<T>, T) : runner_t<T>
+ log : function (runner_t<T>, string, string, ... : any)
+ onready : function (runner_t<T>, function) : runner_t<T>
+ onready : function (runner_t<T>, function) : runner_t<T>
+ onwaiting : function (runner_t<T>, function) : runner_t<T>
+ onerror : function (runner_t<T>, function) : runner_t<T>
+ end
+ runner : function <T>(function (T), runner_t.watchers_t, any) : runner_t<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
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
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
diff --git a/teal-src/util/dataforms.d.tl b/teal-src/util/dataforms.d.tl
index 9e4170fa..0eddf98e 100644
--- a/teal-src/util/dataforms.d.tl
+++ b/teal-src/util/dataforms.d.tl
@@ -1,51 +1,53 @@
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
+ data : function ( dataform, stanza_t ) : { string : any }
+ end
+
new : function ( dataform ) : dataform
end
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl
index 73b1dfc0..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";
@@ -133,10 +135,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
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
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
diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl
index cbb06f8e..5c249627 100644
--- a/teal-src/util/hashes.d.tl
+++ b/teal-src/util/hashes.d.tl
@@ -9,10 +9,18 @@ local record lib
sha384 : hash
sha512 : hash
md5 : hash
+ sha3_256 : hash
+ sha3_512 : hash
+ blake2s256 : hash
+ blake2b512 : hash
hmac_sha1 : hmac
hmac_sha256 : hmac
+ hmac_sha224 : hmac
+ 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
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
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<K,V>
+ 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> ({ K : V }) : string
+ table : function<K,V> ({ tablerow<K,V> }, width : integer) : getrow<K,V>
+end
+
+return lib
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
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/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
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
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<A, B>
+ type on_resolved = function (A) : any
+ type on_rejected = function (B) : any
+ next : function (Promise, on_resolved, on_rejected) : Promise<any, any>
+ 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
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<T>
+ size : integer
+ count : function (queue<T>) : integer
+ enum push_errors
+ "queue full"
+ end
+
+ push : function (queue<T>, T) : boolean, push_errors
+ pop : function (queue<T>) : T
+ peek : function (queue<T>) : T
+ replace : function (queue<T>, T) : boolean, push_errors
+ type iterator = function (T, integer) : integer, T
+ items : function (queue<T>) : iterator, T, integer
+ type consume_iter = function (queue<T>) : T
+ consume : function (queue<T>) : consume_iter
+ end
+
+ new : function<T> (size:integer, allow_wrapping:boolean) : queue<T>
+end
+return lib;
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
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
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<T>
+ add : function<T> (Set<T>, T)
+ contains : function<T> (Set<T>, T) : boolean
+ contains_set : function<T> (Set<T>, Set<T>) : boolean
+ items : function<T> (Set<T>) : function<T> (Set<T>, T) : T
+ add_list : function<T> (Set<T>, { T })
+ include : function<T> (Set<T>, Set<T>)
+ exclude : function<T> (Set<T>, Set<T>)
+ empty : function<T> (Set<T>) : boolean
+ end
+
+ new : function<T> ({ T }) : Set<T>
+ is_set : function (any) : boolean
+ union : function<T> (Set<T>, Set<T>) : Set <T>
+ difference : function<T> (Set<T>, Set<T>) : Set <T>
+ intersection : function<T> (Set<T>, Set<T>) : Set <T>
+ xor : function<T> (Set<T>, Set<T>) : Set <T>
+end
+
+return lib
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
diff --git a/teal-src/util/stanza.d.tl b/teal-src/util/stanza.d.tl
index a358248a..e1ab2105 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 }
@@ -16,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 )
@@ -24,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
@@ -35,7 +71,9 @@ 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
+ -- 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
@@ -45,16 +83,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, string, string, string, string )
- presence : function ( { string : string } ) : stanza_t
+ error_reply : function ( stanza_t, stanza_error_type, stanza_error_condition, string, string ) : stanza_t
+ presence : function ( presence_attr ) : stanza_t
xml_escape : function ( string ) : string
pretty_print : function ( string ) : string
end
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
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
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
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
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)