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

style(tools/table): clean the comments and improve usage #12800

Merged
merged 2 commits into from
Apr 1, 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
16 changes: 8 additions & 8 deletions kong/db/schema/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local tablex = require "pl.tablex"
local pretty = require "pl.pretty"
local utils = require "kong.tools.utils"
local table_tools = require "kong.tools.table"
local cjson = require "cjson"
local new_tab = require "table.new"
local nkeys = require "table.nkeys"
Expand Down Expand Up @@ -37,8 +37,8 @@ local sub = string.sub
local safe_decode = cjson_safe.decode


local random_string = utils.random_string
local uuid = utils.uuid
local random_string = require("kong.tools.rand").random_string
local uuid = require("kong.tools.uuid").uuid
local json_validate = json.validate


Expand Down Expand Up @@ -1025,7 +1025,7 @@ end
local function handle_missing_field(field, value, opts)
local no_defaults = opts and opts.no_defaults
if field.default ~= nil and not no_defaults then
local copy = utils.cycle_aware_deep_copy(field.default)
local copy = table_tools.cycle_aware_deep_copy(field.default)
if (field.type == "array" or field.type == "set")
and type(copy) == "table"
and not getmetatable(copy)
Expand Down Expand Up @@ -1663,7 +1663,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)

local is_select = context == "select"
if not is_select then
data = utils.cycle_aware_deep_copy(data)
data = table_tools.cycle_aware_deep_copy(data)
end

local shorthand_fields = self.shorthand_fields
Expand Down Expand Up @@ -1694,7 +1694,7 @@ function Schema:process_auto_fields(data, context, nulls, opts)
end

if is_select and sdata.translate_backwards and not(opts and opts.hide_shorthands) then
data[sname] = utils.table_path(data, sdata.translate_backwards)
data[sname] = table_tools.table_path(data, sdata.translate_backwards)
end
end
if has_errs then
Expand Down Expand Up @@ -2078,7 +2078,7 @@ function Schema:validate_immutable_fields(input, entity)
local errors = {}

for key, field in self:each_field(input) do
local compare = utils.is_array(input[key]) and tablex.compare_no_order or tablex.deepcompare
local compare = table_tools.is_array(input[key]) and tablex.compare_no_order or tablex.deepcompare

if field.immutable and entity[key] ~= nil and not compare(input[key], entity[key]) then
errors[key] = validation_errors.IMMUTABLE
Expand Down Expand Up @@ -2437,7 +2437,7 @@ function Schema.new(definition, is_subschema)
return nil, validation_errors.SCHEMA_NO_FIELDS
end

local self = utils.cycle_aware_deep_copy(definition)
local self = table_tools.cycle_aware_deep_copy(definition)
setmetatable(self, Schema)

local cache_key = self.cache_key
Expand Down
3 changes: 2 additions & 1 deletion kong/tools/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ function _M.add_error(errors, k, v)
return errors
end


--- Retrieves a value from table using path.
-- @param t The source table to retrieve the value from.
-- @param path Path table containing keys
-- @param v Value of the error
-- @return Returns `value` if something was found and `nil` otherwise
function _M.table_path(t, path)
local current_value = t
Expand All @@ -325,4 +325,5 @@ function _M.table_path(t, path)
return current_value
end


return _M
Loading