Skip to content

Commit

Permalink
refactor(tools): remove reference of table from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Feb 2, 2024
1 parent 99a9aa2 commit f16b378
Show file tree
Hide file tree
Showing 48 changed files with 229 additions and 217 deletions.
3 changes: 2 additions & 1 deletion kong/api/api_helpers.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local cjson = require "cjson"
local pl_pretty = require "pl.pretty"
local tablex = require "pl.tablex"
Expand Down Expand Up @@ -94,7 +95,7 @@ function _M.normalize_nested_params(obj)
is_array = false
if type(v) == "table" then
-- normalize arrays since Lapis parses ?key[1]=foo as {["1"]="foo"} instead of {"foo"}
if utils.is_array(v, "lapis") then
if kong_table.is_array(v, "lapis") then
is_array = true
local arr = {}
for _, arr_v in pairs(v) do arr[#arr+1] = arr_v end
Expand Down
4 changes: 2 additions & 2 deletions kong/api/routes/plugins.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local cjson = require "cjson"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local reports = require "kong.reports"
local endpoints = require "kong.api.endpoints"
local arguments = require "kong.api.arguments"
Expand All @@ -20,7 +20,7 @@ local function reports_timer(premature, data)
return
end

local r_data = utils.cycle_aware_deep_copy(data)
local r_data = kong_table.cycle_aware_deep_copy(data)

r_data.config = nil
r_data.route = nil
Expand Down
6 changes: 3 additions & 3 deletions kong/clustering/compat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ local cjson = require("cjson.safe")
local constants = require("kong.constants")
local meta = require("kong.meta")
local version = require("kong.clustering.compat.version")
local utils = require("kong.tools.utils")
local kong_table = require("kong.tools.table")

local type = type
local ipairs = ipairs
local table_insert = table.insert
local table_sort = table.sort
local gsub = string.gsub
local split = utils.split
local split = require("kong.tools.utils").split
local deflate_gzip = require("kong.tools.gzip").deflate_gzip
local cjson_encode = cjson.encode

Expand Down Expand Up @@ -370,7 +370,7 @@ function _M.update_compatible_payload(payload, dp_version, log_suffix)
end

local has_update
payload = utils.cycle_aware_deep_copy(payload, true)
payload = kong_table.cycle_aware_deep_copy(payload, true)
local config_table = payload["config_table"]

for _, checker in ipairs(COMPATIBILITY_CHECKERS) do
Expand Down
4 changes: 2 additions & 2 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local pl_config = require "pl.config"
local pl_file = require "pl.file"
local pl_path = require "pl.path"
local tablex = require "pl.tablex"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local log = require "kong.cmd.utils.log"
local env = require "kong.cmd.utils.env"
local ffi = require "ffi"
Expand Down Expand Up @@ -871,7 +871,7 @@ return setmetatable({
end,

remove_sensitive = function(conf)
local purged_conf = utils.cycle_aware_deep_copy(conf)
local purged_conf = kong_table.cycle_aware_deep_copy(conf)

local refs = purged_conf["$refs"]
if type(refs) == "table" then
Expand Down
4 changes: 2 additions & 2 deletions kong/db/dao/certificates.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local cjson = require "cjson"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"


local setmetatable = setmetatable
Expand All @@ -16,7 +16,7 @@ local type = type
local function parse_name_list(input, errors)
local name_list
if type(input) == "table" then
name_list = utils.shallow_copy(input)
name_list = kong_table.shallow_copy(input)

elseif input == ngx.null then
name_list = {}
Expand Down
13 changes: 7 additions & 6 deletions kong/db/dao/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local cjson = require "cjson"
local iteration = require "kong.db.iteration"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local defaults = require "kong.db.strategies.connector".defaults
local hooks = require "kong.hooks"
local workspaces = require "kong.workspaces"
Expand All @@ -22,7 +23,7 @@ local log = ngx.log
local fmt = string.format
local match = string.match
local run_hook = hooks.run_hook
local table_merge = utils.table_merge
local table_merge = kong_table.table_merge


local ERR = ngx.ERR
Expand Down Expand Up @@ -154,7 +155,7 @@ local function get_pagination_options(self, options)
error("options must be a table when specified", 3)
end

options = utils.cycle_aware_deep_copy(options, true)
options = kong_table.cycle_aware_deep_copy(options, true)

if type(options.pagination) == "table" then
options.pagination = table_merge(self.pagination, options.pagination)
Expand Down Expand Up @@ -953,7 +954,7 @@ function _M.new(db, schema, strategy, errors)
schema = schema,
strategy = strategy,
errors = errors,
pagination = utils.shallow_copy(defaults.pagination),
pagination = kong_table.shallow_copy(defaults.pagination),
super = super,
}

Expand Down Expand Up @@ -1115,7 +1116,7 @@ function DAO:each_for_export(size, options)
if not options then
options = get_pagination_options(self, options)
else
options = utils.cycle_aware_deep_copy(options, true)
options = kong_table.cycle_aware_deep_copy(options, true)
end

options.export = true
Expand Down Expand Up @@ -1469,12 +1470,12 @@ function DAO:post_crud_event(operation, entity, old_entity, options)
if self.events then
local entity_without_nulls
if entity then
entity_without_nulls = remove_nulls(utils.cycle_aware_deep_copy(entity, true))
entity_without_nulls = remove_nulls(kong_table.cycle_aware_deep_copy(entity, true))
end

local old_entity_without_nulls
if old_entity then
old_entity_without_nulls = remove_nulls(utils.cycle_aware_deep_copy(old_entity, true))
old_entity_without_nulls = remove_nulls(kong_table.cycle_aware_deep_copy(old_entity, true))
end

local ok, err = self.events.post_local("dao:crud", operation, {
Expand Down
3 changes: 2 additions & 1 deletion kong/db/dao/targets.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local balancer = require "kong.runloop.balancer"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local cjson = require "cjson"
local workspaces = require "kong.workspaces"

Expand All @@ -10,7 +11,7 @@ local ipairs = ipairs
local table = table
local type = type
local min = math.min
local table_merge = utils.table_merge
local table_merge = kong_table.table_merge


local _TARGETS = {}
Expand Down
6 changes: 3 additions & 3 deletions kong/db/declarative/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local lmdb = require("resty.lmdb")
local txn = require("resty.lmdb.transaction")
local constants = require("kong.constants")
local workspaces = require("kong.workspaces")
local utils = require("kong.tools.utils")
local kong_table = require("kong.tools.table")
local declarative_config = require("kong.db.schema.others.declarative_config")


Expand Down Expand Up @@ -85,7 +85,7 @@ local function load_into_db(entities, meta)

local primary_key, ok, err, err_t
for _, entity in pairs(entities[schema_name]) do
entity = utils.cycle_aware_deep_copy(entity)
entity = kong_table.cycle_aware_deep_copy(entity)
entity._tags = nil
entity.ws_id = nil

Expand Down Expand Up @@ -312,7 +312,7 @@ local function load_into_cache(entities, meta, hash)

local cache_key = dao:cache_key(id, nil, nil, nil, nil, item.ws_id)
if transform and schema:has_transformations(item) then
local transformed_item = utils.cycle_aware_deep_copy(item)
local transformed_item = kong_table.cycle_aware_deep_copy(item)
remove_nulls(transformed_item)

local err
Expand Down
9 changes: 5 additions & 4 deletions kong/db/schema/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local tablex = require "pl.tablex"
local pretty = require "pl.pretty"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local cjson = require "cjson"
local new_tab = require "table.new"
local nkeys = require "table.nkeys"
Expand Down Expand Up @@ -1013,7 +1014,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 = kong_table.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 @@ -1651,7 +1652,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 = kong_table.cycle_aware_deep_copy(data)
end

local shorthand_fields = self.shorthand_fields
Expand Down Expand Up @@ -2049,7 +2050,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 = kong_table.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 @@ -2408,7 +2409,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 = kong_table.cycle_aware_deep_copy(definition)
setmetatable(self, Schema)

local cache_key = self.cache_key
Expand Down
15 changes: 8 additions & 7 deletions kong/db/schema/others/declarative_config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local uuid = require("resty.jit-uuid")
local utils = require("kong.tools.utils")
local kong_table = require("kong.tools.table")
local Errors = require("kong.db.errors")
local Entity = require("kong.db.schema.entity")
local Schema = require("kong.db.schema")
Expand Down Expand Up @@ -99,7 +100,7 @@ local function add_top_level_entities(fields, known_entities)
local records = {}

for _, entity in ipairs(known_entities) do
local definition = utils.cycle_aware_deep_copy(all_schemas[entity], true)
local definition = kong_table.cycle_aware_deep_copy(all_schemas[entity], true)

for k, _ in pairs(definition.fields) do
if type(k) ~= "number" then
Expand Down Expand Up @@ -132,7 +133,7 @@ end


local function copy_record(record, include_foreign, duplicates, name, cycle_aware_cache)
local copy = utils.cycle_aware_deep_copy(record, true, nil, cycle_aware_cache)
local copy = kong_table.cycle_aware_deep_copy(record, true, nil, cycle_aware_cache)
if include_foreign then
return copy
end
Expand Down Expand Up @@ -406,7 +407,7 @@ local function populate_references(input, known_entities, by_id, by_key, expecte
end

if parent_fk then
item[child_key] = utils.cycle_aware_deep_copy(parent_fk, true)
item[child_key] = kong_table.cycle_aware_deep_copy(parent_fk, true)
end
end

Expand Down Expand Up @@ -593,7 +594,7 @@ local function generate_ids(input, known_entities, parent_entity)
local pk_name, key = get_key_for_uuid_gen(entity, item, schema,
parent_fk, child_key)
if key then
item = utils.cycle_aware_deep_copy(item, true)
item = kong_table.cycle_aware_deep_copy(item, true)
item[pk_name] = generate_uuid(schema.name, key)
input[entity][i] = item
end
Expand Down Expand Up @@ -652,7 +653,7 @@ local function populate_ids_for_validation(input, known_entities, parent_entity,
end

if parent_fk and not item[child_key] then
item[child_key] = utils.cycle_aware_deep_copy(parent_fk, true)
item[child_key] = kong_table.cycle_aware_deep_copy(parent_fk, true)
end
end

Expand Down Expand Up @@ -756,11 +757,11 @@ local function flatten(self, input)
self.full_schema = DeclarativeConfig.load(self.plugin_set, self.vault_set, true)
end

local input_copy = utils.cycle_aware_deep_copy(input, true)
local input_copy = kong_table.cycle_aware_deep_copy(input, true)
populate_ids_for_validation(input_copy, self.known_entities)
local ok2, err2 = self.full_schema:validate(input_copy)
if not ok2 then
local err3 = utils.cycle_aware_deep_merge(err2, extract_null_errors(err))
local err3 = kong_table.cycle_aware_deep_merge(err2, extract_null_errors(err))
return nil, err3
end

Expand Down
4 changes: 2 additions & 2 deletions kong/db/strategies/postgres/connector.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local logger = require "kong.cmd.utils.log"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local pgmoon = require "pgmoon"
local arrays = require "pgmoon.arrays"
local stringx = require "pl.stringx"
Expand Down Expand Up @@ -31,7 +31,7 @@ local fmt = string.format
local sub = string.sub
local utils_toposort = db_utils.topological_sort
local insert = table.insert
local table_merge = utils.table_merge
local table_merge = kong_table.table_merge


local WARN = ngx.WARN
Expand Down
4 changes: 2 additions & 2 deletions kong/db/strategies/postgres/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local arrays = require "pgmoon.arrays"
local json = require "pgmoon.json"
local cjson_safe = require "cjson.safe"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local new_tab = require "table.new"
local clear_tab = require "table.clear"

Expand Down Expand Up @@ -1097,7 +1097,7 @@ function _M.new(connector, schema, errors)
do
local function add(name, opts, add_ws)
local orig_argn = opts.argn
opts = utils.cycle_aware_deep_copy(opts)
opts = kong_table.cycle_aware_deep_copy(opts)

-- ensure LIMIT table is the same
for i, n in ipairs(orig_argn) do
Expand Down
5 changes: 2 additions & 3 deletions kong/pdk/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ local ngx_re = require "ngx.re"
local inspect = require "inspect"
local ngx_ssl = require "ngx.ssl"
local phase_checker = require "kong.pdk.private.phases"
local utils = require "kong.tools.utils"
local cycle_aware_deep_copy = utils.cycle_aware_deep_copy
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
local constants = require "kong.constants"

local sub = string.sub
Expand All @@ -36,7 +35,7 @@ local setmetatable = setmetatable
local ngx = ngx
local kong = kong
local check_phase = phase_checker.check
local split = utils.split
local split = require("kong.tools.string").split
local byte = string.byte
local request_id_get = require "kong.tracing.request_id".get

Expand Down
2 changes: 1 addition & 1 deletion kong/pdk/table.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local table_merge = require("kong.tools.utils").table_merge
local table_merge = require("kong.tools.table").table_merge

--- Utilities for Lua tables.
--
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/oauth2/access.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local url = require "socket.url"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local constants = require "kong.constants"
local timestamp = require "kong.tools.timestamp"
local secret = require "kong.plugins.oauth2.secret"
Expand All @@ -21,7 +22,7 @@ local string_byte = string.byte
local check_https = utils.check_https
local encode_args = utils.encode_args
local random_string = utils.random_string
local table_contains = utils.table_contains
local table_contains = kong_table.table_contains


local ngx_decode_args = ngx.decode_args
Expand Down
Loading

0 comments on commit f16b378

Please sign in to comment.