Skip to content

Commit

Permalink
refactor(tools): update reference of table from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed May 16, 2024
1 parent 204dd8d commit 8861343
Show file tree
Hide file tree
Showing 51 changed files with 275 additions and 266 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,9 +1,9 @@
local cjson = require "cjson"
local utils = require "kong.tools.utils"
local reports = require "kong.reports"
local endpoints = require "kong.api.endpoints"
local arguments = require "kong.api.arguments"
local api_helpers = require "kong.api.api_helpers"
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy


local ngx = ngx
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 = 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 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.string").split
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
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 = 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 @@ -15,7 +15,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 cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
local log = require "kong.cmd.utils.log"
local env = require "kong.cmd.utils.env"
local ffi = require "ffi"
Expand Down Expand Up @@ -958,7 +958,7 @@ return setmetatable({
end,

remove_sensitive = function(conf)
local purged_conf = utils.cycle_aware_deep_copy(conf)
local purged_conf = 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 shallow_copy = require("kong.tools.table").shallow_copy


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 = 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 @@ -956,7 +957,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 @@ -1118,7 +1119,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 @@ -1472,12 +1473,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 cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
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 = 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 = cycle_aware_deep_copy(item)
remove_nulls(transformed_item)

local err
Expand Down
19 changes: 10 additions & 9 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_uuid = require("kong.tools.uuid").uuid
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 @@ -421,7 +422,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 @@ -608,7 +609,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 @@ -648,7 +649,7 @@ local function populate_ids_for_validation(input, known_entities, parent_entity,
if key then
item[pk_name] = generate_uuid(schema.name, key)
else
item[pk_name] = utils.uuid()
item[pk_name] = kong_uuid()
end
end

Expand All @@ -667,7 +668,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 @@ -771,11 +772,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,6 @@
local arrays = require "pgmoon.arrays"
local json = require "pgmoon.json"
local cjson_safe = require "cjson.safe"
local utils = require "kong.tools.utils"
local new_tab = require "table.new"
local clear_tab = require "table.clear"

Expand Down Expand Up @@ -33,6 +32,7 @@ local fmt = string.format
local rep = string.rep
local sub = string.sub
local log = ngx.log
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy


local NOTICE = ngx.NOTICE
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 = cycle_aware_deep_copy(opts)

-- ensure LIMIT table is the same
for i, n in ipairs(orig_argn) do
Expand Down
6 changes: 3 additions & 3 deletions kong/llm/drivers/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ local http = require("resty.http")
local fmt = string.format
local os = os
local parse_url = require("socket.url").parse
local utils = require("kong.tools.utils")
--

-- static
local str_find = string.find
local str_sub = string.sub
local string_match = string.match
local split = utils.split
local split = require("kong.tools.string").split
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy

local function str_ltrim(s) -- remove leading whitespace from string.
return (s:gsub("^%s*", ""))
Expand Down Expand Up @@ -356,7 +356,7 @@ end

function _M.resolve_plugin_conf(kong_request, conf)
local err
local conf_m = utils.cycle_aware_deep_copy(conf)
local conf_m = cycle_aware_deep_copy(conf)

-- handle model name
local model_m = string_match(conf_m.model.name or "", '%$%((.-)%)')
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 workspace = require "kong.workspaces"

Expand All @@ -37,7 +36,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
2 changes: 1 addition & 1 deletion kong/plugins/ai-proxy/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local typedefs = require("kong.db.schema.typedefs")
local llm = require("kong.llm")
local deep_copy = require("kong.tools.utils").deep_copy
local deep_copy = require("kong.tools.table").deep_copy

local this_schema = deep_copy(llm.config_schema)

Expand Down
7 changes: 4 additions & 3 deletions kong/plugins/opentelemetry/otlp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ local pb = require "pb"
local new_tab = require "table.new"
local nkeys = require "table.nkeys"
local tablepool = require "tablepool"
local utils = require "kong.tools.utils"
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy
local kong_table = require "kong.tools.table"

local kong = kong
local insert = table.insert
local tablepool_fetch = tablepool.fetch
local tablepool_release = tablepool.release
local table_merge = utils.table_merge
local table_merge = kong_table.table_merge
local setmetatable = setmetatable

local TRACE_ID_LEN = 16
Expand Down Expand Up @@ -169,7 +170,7 @@ do
encode_traces = function(spans, resource_attributes)
local tab = tablepool_fetch(POOL_OTLP, 0, 2)
if not tab.resource_spans then
tab.resource_spans = utils.cycle_aware_deep_copy(pb_memo.resource_spans)
tab.resource_spans = cycle_aware_deep_copy(pb_memo.resource_spans)
end

local resource = tab.resource_spans[1].resource
Expand Down
Loading

0 comments on commit 8861343

Please sign in to comment.