# core/validators/leak.validator.ts

> 28 lines of code and 6 definitions.

Tree: Build tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/build#file-build-core-validators-leak-validator-ts
Source text: https://banes-lab.com/assets/sources/source.5ccb1875e05d34633b942b79d513843d6881393b41b2f7e3b5fbfa90bdf8b2d7.generated.txt

## Definitions

- `validatePayload` (lexical_declaration, line 12, exported)
- `REASON_LEADS` (lexical_declaration, line 6)
- `tokens` (lexical_declaration, line 17, exported)
- `findings` (lexical_declaration, line 18, exported)
- `seen` (lexical_declaration, line 19, exported)
- `key` (lexical_declaration, line 22, exported)

## Uses

- [core/matchers/leak.matcher.ts](https://banes-lab.com/source/build/core/matchers/leak.matcher.ts.md)

## Used by

- [runtime/entrypoints/leak.entrypoint.ts](https://banes-lab.com/source/build/runtime/entrypoints/leak.entrypoint.ts.md)

## Source

```typescript
import { LEAK_IDENTIFIER, LEAK_INLINE, LEAK_PATH } from "#configuration/strings/coverage.strings";
import type { LeakReason, LeakSet, PagePayload } from "#types/leak.types";
import type { Finding } from "#types/derivation.types";
import { leaksIn } from "#core/matchers/leak.matcher";

const REASON_LEADS: Readonly<Record<LeakReason, string>> = {
    identifier: LEAK_IDENTIFIER,
    "inline-code": LEAK_INLINE,
    path: LEAK_PATH,
};

export const validatePayload = function validatePayload(
    payload: PagePayload,
    leaks: LeakSet,
    roots: ReadonlySet<string>,
): Finding[] {
    const tokens = new Set(leaks.tokens);
    const findings: Finding[] = [];
    const seen = new Set<string>();
    for (const text of payload.strings) {
        for (const match of leaksIn(text, tokens, roots)) {
            const key = match.reason + match.token;
            if (!seen.has(key)) {
                seen.add(key);
                findings.push({ file: payload.file, message: `${REASON_LEADS[match.reason]}${match.token}` });
            }
        }
    }
    return findings;
};
```
