( server: ReactotronServer, serverRedactionConfig: McpRedactionServerConfig, )
| 123 | const NO_CLIENT = "\0__no_client__" |
| 124 | |
| 125 | export function createRedactor( |
| 126 | server: ReactotronServer, |
| 127 | serverRedactionConfig: McpRedactionServerConfig, |
| 128 | ): Redactor { |
| 129 | const cache = new Map<string, ParsedRules | null>() |
| 130 | |
| 131 | function parsedFor(clientId?: string): ParsedRules | null { |
| 132 | const key = clientId ?? NO_CLIENT |
| 133 | if (cache.has(key)) return cache.get(key)! |
| 134 | const clientConfig = getClientRedactionConfig(server, clientId) |
| 135 | const rules = resolveEffectiveRules(serverRedactionConfig, clientConfig) |
| 136 | const parsed = rules ? parseRules(rules) : null |
| 137 | cache.set(key, parsed) |
| 138 | return parsed |
| 139 | } |
| 140 | |
| 141 | return { |
| 142 | redact(data, clientId) { |
| 143 | const parsed = parsedFor(clientId) |
| 144 | return parsed ? redactWithParsed(data, parsed) : data |
| 145 | }, |
| 146 | redactState(data, clientId, statePath) { |
| 147 | const parsed = parsedFor(clientId) |
| 148 | return parsed ? redactWithParsed(data, parsed, statePath) : data |
| 149 | }, |
| 150 | redactAsyncStorage(data, clientId) { |
| 151 | const parsed = parsedFor(clientId) |
| 152 | if (!parsed) return data |
| 153 | return redactWithParsed(redactAsyncStorageWithParsed(data, parsed), parsed) |
| 154 | }, |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | function deepCopyRules(rules: McpRedactionRules): McpRedactionRules { |
| 159 | return { |
no outgoing calls
no test coverage detected