Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lua-livr #57

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions types/lua-livr/LIVR.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--
-- https://luarocks.org/modules/fperrad/lua-livr
--

local record LIVR
type Data = {string:any}
type Error = string|table
type ValidatorFn = function(value: any, all: Data): any, Error
type Builder = function(builders: {string:Builder}, ...: any): ValidatorFn
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
9 changes: 9 additions & 0 deletions types/lua-livr/LIVR/helpers.d.tl
Original file line number Diff line number Diff line change
@@ -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