Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Filter non-finite numbers out before they reach a query clause
Validate raw IDs and their numeric range before building query clauses; finite checks alone do not establish valid identifiers.
Bad example
| 1 | const ids = new Set( |
| 2 | articles.flatMap((a) => a.tags.map((t) => Number(t.externalId))), |
| 3 | ); |
| 4 | await provider.byIds([...ids]); // terms: { ref: [NaN] } -> serialized as null -> 400 |
Explanation (EN)
NaN becomes null in JSON and can invalidate a combined query.
Objašnjenje (HR)
NaN postaje null u JSON-u i može učiniti kombinirani upit neispravnim.
Good example
| 1 | const ids = new Set<number>(); |
| 2 | for (const article of articles) { |
| 3 | for (const tag of article.tags) { |
| 4 | const id = parseOptionalExternalId(tag.externalId); |
| 5 | if (id !== undefined) ids.add(id); |
| 6 | } |
| 7 | } |
| 8 | await provider.byIds([...ids]); |
Explanation (EN)
The shared parser accepts only the source's documented ID forms and positive safe-integer range, with an explicit policy for invalid enrichment records.
Objašnjenje (HR)
Zajednički parser prihvaća samo dokumentirane oblike ID-ja izvora i pozitivan siguran cjelobrojni raspon, uz izričitu politiku za neispravne zapise obogaćivanja.
Notes (EN)
Validate raw identifier shape before conversion, then apply safe-integer/range rules before adding values to a shared query.
Bilješke (HR)
Prije pretvorbe validiraj izvorni oblik identifikatora, zatim provjeri sigurni cjelobrojni raspon prije dodavanja u zajednički upit.
Exceptions / Tradeoffs (EN)
Number(null), Number("") and Number([]) can become zero, and Number(true) becomes one. A finite check alone does not validate an ID. Whether a backend error fails the whole response depends on its actual caller recovery.