From c75a9ab3fb0ae60ee8acdf35f1fd1956c3e3b509 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 27 Jun 2024 20:13:50 +0200 Subject: [PATCH] add lua-livr - https://fperrad.frama.io/lua-LIVR - https://luarocks.org/modules/fperrad/lua-livr --- types/lua-livr/LIVR.d.tl | 38 ++++++++++++++++++++++++++++++++ types/lua-livr/LIVR/helpers.d.tl | 9 ++++++++ 2 files changed, 47 insertions(+) create mode 100644 types/lua-livr/LIVR.d.tl create mode 100644 types/lua-livr/LIVR/helpers.d.tl diff --git a/types/lua-livr/LIVR.d.tl b/types/lua-livr/LIVR.d.tl new file mode 100644 index 0000000..7104187 --- /dev/null +++ b/types/lua-livr/LIVR.d.tl @@ -0,0 +1,38 @@ +-- +-- https://luarocks.org/modules/fperrad/lua-livr +-- + +local record LIVR + type Data = {string:any} + type Error = string|table + type Validator = function(value: any, all: Data): any, Error + type Builder = function(builders: {string:Builder}, ...: any): Validator + type Rule = string|table + + record Alias + name: string + rules: Rule + error: string + end + + record VALIDATOR + prepare: function(self: VALIDATOR): VALIDATOR + validate: function(self: VALIDATOR, data: Data): Data, string|{string:Error} + register_rules: function(self: VALIDATOR, rules: {string:Builder}): VALIDATOR + register_aliased_rule: function(self: VALIDATOR, alias: Alias): VALIDATOR + get_rules: function(self: VALIDATOR): {string:Builder} + end + + new: function(rules: {string:Rule}, is_auto_trim: boolean): VALIDATOR + register_default_rules: function(rules: {string:Builder}) + register_aliased_default_rule: function(alias: Alias) + + default_rules: {string:Builder} + default_auto_trim: boolean + _NAME: string + _VERSION: string + _DESCRIPTION: string + _COPYRIGHT: string +end + +return LIVR diff --git a/types/lua-livr/LIVR/helpers.d.tl b/types/lua-livr/LIVR/helpers.d.tl new file mode 100644 index 0000000..65e615f --- /dev/null +++ b/types/lua-livr/LIVR/helpers.d.tl @@ -0,0 +1,9 @@ + +local record helpers + primitive_type: {string:boolean} + string_number_type: {string:boolean} + number_boolean_type: {string:boolean} + expected_type: function(rule: string, n: integer, tname: string, value: any) +end + +return helpers