Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* replace
* upsert

### Changed

* `checks` is disabled for internal functions by default

## [0.1.0] - 2020-09-23

### Added
Expand Down
2 changes: 1 addition & 1 deletion crud-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source = {
dependencies = {
'tarantool',
'lua >= 5.1',
'checks == 3.0.1-1',
'checks == 3.1.0-1',
'errors == 2.1.3-1',
'vshard == 0.1.16-1',
}
Expand Down
6 changes: 3 additions & 3 deletions crud/common/call.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local checks = require('checks')
local fiber = require('fiber')
local vshard = require('vshard')
local errors = require('errors')

local dev_checks = require('crud.common.dev_checks')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')

Expand All @@ -23,7 +23,7 @@ local DEFAULT_VSHARD_CALL_TIMEOUT = 2
--
function call.init()
local function call(opts)
checks({
dev_checks({
func_name = 'string',
func_args = '?table',
})
Expand Down Expand Up @@ -63,7 +63,7 @@ local function call_on_replicaset(replicaset, channel, vshard_call, func_name, f
end

local function call_impl(vshard_call, func_name, func_args, opts)
checks('string', 'string', '?table', {
dev_checks('string', 'string', '?table', {
timeout = '?number',
replicasets = '?table',
})
Expand Down
46 changes: 0 additions & 46 deletions crud/common/checkers.lua

This file was deleted.

9 changes: 9 additions & 0 deletions crud/common/dev_checks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local checks = require('checks')

local dev_checks = function() end

if os.getenv('DEV') == 'ON' then
dev_checks = checks
end

return dev_checks
8 changes: 3 additions & 5 deletions crud/common/heap.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
local checks = require('checks')

require('crud.common.checkers')
local dev_checks = require('crud.common.dev_checks')

local Heap = {}
Heap.__index = Heap

function Heap.new(opts)
checks({
dev_checks({
comparator = 'function',
})

Expand Down Expand Up @@ -45,7 +43,7 @@ function Heap:_ok(child_idx, parent_idx)
end

function Heap:add(obj, meta)
checks('table', '?', '?')
dev_checks('table', '?', '?')

local node = {
obj = obj,
Expand Down
5 changes: 0 additions & 5 deletions crud/common/registry.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
local checks = require('checks')
local errors = require('errors')

require('crud.common.checkers')

local registry = {}

local registered_funcs = {}
Expand All @@ -17,8 +14,6 @@ local RegisterError = errors.new_class('Register')
-- Should be passed as a {string: function} map.
--
function registry.add(funcs)
checks('funcs_map')

for func_name in pairs(funcs) do
if registry.is_registered(func_name) then
return nil, RegisterError:new("Function %s is already registered", func_name)
Expand Down
7 changes: 4 additions & 3 deletions crud/common/utils.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local checks = require('checks')
local errors = require('errors')

local dev_checks = require('crud.common.dev_checks')

local FlattenError = errors.new_class("FlattenError", {capture_stack = false})
local UnflattenError = errors.new_class("UnflattenError", {capture_stack = false})
local ParseOperationsError = errors.new_class('ParseOperationsError', {capture_stack = false})

local utils = {}

function utils.table_count(table)
checks("table")
dev_checks("table")

local cnt = 0
for _, _ in pairs(table) do
Expand All @@ -19,7 +20,7 @@ function utils.table_count(table)
end

function utils.format_replicaset_error(replicaset_uuid, msg, ...)
checks("string", "string")
dev_checks("string", "string")

return string.format(
"Failed for %s: %s",
Expand Down
3 changes: 2 additions & 1 deletion crud/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local vshard = require('vshard')
local call = require('crud.common.call')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')
local dev_checks = require('crud.common.dev_checks')

local DeleteError = errors.new_class('Delete', {capture_stack = false})

Expand All @@ -13,7 +14,7 @@ local delete = {}
local DELETE_FUNC_NAME = '__delete'

local function call_delete_on_storage(space_name, key)
checks('string', '?')
dev_checks('string', '?')

local space = box.space[space_name]
if space == nil then
Expand Down
3 changes: 2 additions & 1 deletion crud/get.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local vshard = require('vshard')
local call = require('crud.common.call')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')
local dev_checks = require('crud.common.dev_checks')

local GetError = errors.new_class('Get', {capture_stack = false})

Expand All @@ -13,7 +14,7 @@ local get = {}
local GET_FUNC_NAME = '__get'

local function call_get_on_storage(space_name, key)
checks('string', '?')
dev_checks('string', '?')

local space = box.space[space_name]
if space == nil then
Expand Down
5 changes: 2 additions & 3 deletions crud/insert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ local vshard = require('vshard')
local call = require('crud.common.call')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')

require('crud.common.checkers')
local dev_checks = require('crud.common.dev_checks')

local InsertError = errors.new_class('Insert', {capture_stack = false})

Expand All @@ -15,7 +14,7 @@ local insert = {}
local INSERT_FUNC_NAME = '__insert'

local function call_insert_on_storage(space_name, tuple)
checks('string', 'table')
dev_checks('string', 'table')

local space = box.space[space_name]
if space == nil then
Expand Down
5 changes: 2 additions & 3 deletions crud/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ local vshard = require('vshard')
local call = require('crud.common.call')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')

require('crud.common.checkers')
local dev_checks = require('crud.common.dev_checks')

local ReplaceError = errors.new_class('Replace', { capture_stack = false })

Expand All @@ -15,7 +14,7 @@ local replace = {}
local REPLACE_FUNC_NAME = '__replace'

local function call_replace_on_storage(space_name, tuple)
checks('string', 'table')
dev_checks('string', 'table')

local space = box.space[space_name]
if space == nil then
Expand Down
15 changes: 7 additions & 8 deletions crud/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local vshard = require('vshard')
local call = require('crud.common.call')
local registry = require('crud.common.registry')
local utils = require('crud.common.utils')
local dev_checks = require('crud.common.dev_checks')

local select_conditions = require('crud.select.conditions')
local select_plan = require('crud.select.plan')
Expand All @@ -14,8 +15,6 @@ local select_filters = require('crud.select.filters')

local Iterator = require('crud.select.iterator')

require('crud.common.checkers')

local SelectError = errors.new_class('SelectError')
local GetReplicasetsError = errors.new_class('GetReplicasetsError')

Expand All @@ -26,7 +25,7 @@ local SELECT_FUNC_NAME = '__select'
local DEFAULT_BATCH_SIZE = 100

local function call_select_on_storage(space_name, index_id, conditions, opts)
checks('string', 'number', '?table', {
dev_checks('string', 'number', '?table', {
scan_value = 'table',
after_tuple = '?table',
iter = 'number',
Expand Down Expand Up @@ -73,7 +72,7 @@ function select_module.init()
end

local function select_iteration(space_name, plan, opts)
checks('string', '?table', {
dev_checks('string', '?table', {
after_tuple = '?table',
replicasets = 'table',
timeout = '?number',
Expand Down Expand Up @@ -118,8 +117,8 @@ local function get_replicasets_by_sharding_key(sharding_key)
end

local function build_select_iterator(space_name, user_conditions, opts)
checks('string', '?table', {
after = '?',
dev_checks('string', '?table', {
after = '?table',
limit = '?number',
timeout = '?number',
batch_size = '?number',
Expand Down Expand Up @@ -205,7 +204,7 @@ end

function select_module.pairs(space_name, user_conditions, opts)
checks('string', '?table', {
after = '?',
after = '?table',
limit = '?number',
timeout = '?number',
batch_size = '?number',
Expand Down Expand Up @@ -242,7 +241,7 @@ end

function select_module.call(space_name, user_conditions, opts)
checks('string', '?table', {
after = '?',
after = '?table',
limit = '?number',
timeout = '?number',
batch_size = '?number',
Expand Down
20 changes: 6 additions & 14 deletions crud/select/conditions.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local checks = require('checks')
local errors = require('errors')

local dev_checks = require('crud.common.dev_checks')

local ParseConditionError = errors.new_class('ParseConditionError')

local conditions = {}
Expand All @@ -22,19 +23,10 @@ local tarantool_iter_by_cond_operators = {
[conditions.operators.GE] = box.index.GE,
}

function _G.checkers.condition_operator(p)
for _, op in pairs(conditions.operators) do
if op == p then
return true
end
end
return false
end

local function new_condition(opts)
checks({
operator = 'condition_operator',
operand = 'string|strings_array',
dev_checks({
operator = 'string',
operand = 'string|table',
values = '?',
})

Expand Down Expand Up @@ -67,7 +59,7 @@ local cond_operators_by_func_names = {
for func_name, operator in pairs(cond_operators_by_func_names) do
assert(operator ~= nil)
conditions.funcs[func_name] = function(operand, values)
checks('string|strings_array', '?')
dev_checks('string|table', '?')
return new_condition({
operator = operator,
operand = operand,
Expand Down
6 changes: 3 additions & 3 deletions crud/select/executor.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local checks = require('checks')
local errors = require('errors')
local log = require('log')

local dev_checks = require('crud.common.dev_checks')
local select_comparators = require('crud.select.comparators')

local utils = require('crud.common.utils')
Expand Down Expand Up @@ -37,9 +37,9 @@ local function scroll_to_after_tuple(gen, space, scan_index, iter, after_tuple)
end

function executor.execute(space, index, filter_func, opts)
checks('table', 'table', 'function', {
dev_checks('table', 'table', 'function', {
scan_value = 'table',
after_tuple = '?cdata|table',
after_tuple = '?table',
iter = 'number',
limit = '?number',
})
Expand Down
Loading