-- Compiled with roblox-ts v2.3.0-dev-30dae68 local TS = _G[script] --[[ * * @license * Copyright 2024 Daymon Littrell-Reyes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ]] local reverseArray = TS.import(script, TS.getModule(script, "@rbxts", "reverse-array").out).reverseArray local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService local LogLevel = TS.import(script, script.Parent, "common").LogLevel local isStudio = RunService:IsStudio() --[[ * * Configuration settings for serialization. * * @see {@link RLogConfig} * * @public ]] --[[ * * Default configuration for serialization. * * @internal ]] local defaultSerializationConfig = { encodeRobloxTypes = true, encodeFunctions = false, encodeMethod = "__tostring", deepEncodeTables = true, } --[[ * * Configuration settings for {@link RLog}. * * @public ]] --[[ * * Default configuration for {@link RLog}. * * @internal ]] local defaultRLogConfig = { minLogLevel = if isStudio then LogLevel.VERBOSE else LogLevel.WARNING, serialization = defaultSerializationConfig, contextBypass = false, suspendContext = false, } --[[ * * Version of {@link RLogConfig} that allows all data to be absent. * * @public ]] --[[ * * Merges a variable amount of config files. * * @remarks * * Configs that come later take precedence over those before. * * Uses the {@link defaultRLogConfig | default} config as a baseline. * * @param configs - A variable list of config files to merge together. * * @returns The merged config files. * * @internal ]] -- TODO(): see if there's any use case where we _wouldn't_ want the default config involved -- TODO(): reduce the amount of places where we need to call this. maybe make primary constructors take in full rLog configs or something idk local function mergeConfigs(...) local configs = { ... } -- ▼ ReadonlyArray.filterUndefined ▼ local _length = 0 for _i in configs do if _i > _length then _length = _i end end local _result = {} local _resultLength = 0 for _i = 1, _length do local _v = configs[_i] if _v ~= nil then _resultLength += 1 _result[_resultLength] = _v end end -- ▲ ReadonlyArray.filterUndefined ▲ local validConfigs = _result -- ▼ ReadonlyArray.reduce ▼ local _result_1 = defaultSerializationConfig local _callback = function(acc, it) local _object = table.clone(acc) setmetatable(_object, nil) for _k, _v in (it.serialization or {}) do _object[_k] = _v end return _object end for _i = 1, #validConfigs do _result_1 = _callback(_result_1, validConfigs[_i], _i - 1, validConfigs) end -- ▲ ReadonlyArray.reduce ▲ local serialization = _result_1 -- ▼ ReadonlyArray.reduce ▼ local _result_2 = defaultRLogConfig local _callback_1 = function(acc, it) local _object = table.clone(acc) setmetatable(_object, nil) for _k, _v in (it or {}) do _object[_k] = _v end _object.tag = it.tag return _object end for _i = 1, #validConfigs do _result_2 = _callback_1(_result_2, validConfigs[_i], _i - 1, validConfigs) end -- ▲ ReadonlyArray.reduce ▲ local mergedConfigs = _result_2 -- TODO(): cleanup. there needs to be a better way to do this -- note: could also check if the last config is actually even a partial. cause if it's not, we can just return it deep copied local addedSinks = {} local addedEnrichers = {} local enrichers = {} local sinks = {} local flipped = reverseArray(validConfigs) for _, config in flipped do local _result_3 = config.sinks if _result_3 ~= nil then -- ▼ ReadonlyArray.forEach ▼ local _callback_2 = function(it) local _it = it if not (addedSinks[_it] ~= nil) then local _it_1 = it addedSinks[_it_1] = true local _it_2 = it table.insert(sinks, _it_2) end end for _k, _v in _result_3 do _callback_2(_v, _k - 1, _result_3) end -- ▲ ReadonlyArray.forEach ▲ end local _result_4 = config.enrichers if _result_4 ~= nil then -- ▼ ReadonlyArray.forEach ▼ local _callback_2 = function(it) local _it = it if not (addedEnrichers[_it] ~= nil) then local _it_1 = it addedEnrichers[_it_1] = true local _it_2 = it table.insert(enrichers, _it_2) end end for _k, _v in _result_4 do _callback_2(_v, _k - 1, _result_4) end -- ▲ ReadonlyArray.forEach ▲ end end local _object = table.clone(mergedConfigs) setmetatable(_object, nil) local _left = "sinks" local _array = {} local _length_1 = #_array table.move(sinks, 1, #sinks, _length_1 + 1, _array) _object[_left] = _array local _left_1 = "enrichers" local _array_1 = {} local _length_2 = #_array_1 table.move(enrichers, 1, #enrichers, _length_2 + 1, _array_1) _object[_left_1] = _array_1 _object.serialization = serialization return _object end return { mergeConfigs = mergeConfigs, defaultSerializationConfig = defaultSerializationConfig, defaultRLogConfig = defaultRLogConfig, }