Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Cap pagination page size with a sane maximum
Validate the pagination limit/take parameter with a reasonable maximum instead of allowing arbitrarily large page sizes. Bound the effective response after tie-group completion or other server-side expansion as well as the requested limit. If a complete group cannot fit, use a cursor that can safely continue within it or log and propagate a clear failure; never silently truncate a group or return an unbounded page.
Bad example
| 1 | const page = hits.slice(0, Math.min(requested, 100)); |
| 2 | page.push(...await readCompleteBoundaryGroup(page)); |
| 3 | return { articles: page }; |
Explanation (EN)
The input limit is bounded but completing a timestamp group can still assemble thousands of articles into one response.
Objašnjenje (HR)
Ulazni limit je ogranicen, ali dopunjavanje timestamp grupe jos uvijek moze stvoriti odgovor s tisucama clanaka.
Good example
| 1 | const page = hits.slice(0, Math.min(requested, 100)); |
| 2 | const remaining = pageCapacity - page.length; |
| 3 | const group = await readBoundaryGroup({ remaining, lookahead: 1 }); |
| 4 | if (group.length > remaining) { |
| 5 | logger.error('Boundary group exceeds page capacity'); |
| 6 | throw new Error('Page capacity exceeded'); |
| 7 | } |
| 8 | return { articles: [...page, ...group] }; |
Explanation (EN)
The expanded response has a separate capacity. Overflow is observable and fails without returning a silently incomplete group. The reader must bound its own buffering and release resources in finally.
Objašnjenje (HR)
Prosireni odgovor ima zasebnu granicu. Prekoracenje je vidljivo i ne vraca tihu nepotpunu grupu. Citac mora ograniciti memoriju i osloboditi resurse u finally.
Notes (EN)
Apply to interactive paginated endpoints, especially when timestamps or other non-unique sort keys expand a page beyond its requested limit. Inspect both cached and fallback paths, raw upstream counts, cursor semantics and cleanup. Choose a measured response/memory budget, test the exact bound and its overflow, and release scroll resources on failure. Keep ordinary and expansion query counts visible; do not claim a performance improvement without latency evidence. This complements input-limit validation rather than replacing it. A bounded batch size does not bound the total response assembled across batches.
Bilješke (HR)
Primijeni na interaktivne paginirane endpointove, osobito kad jednaki timestampovi prosiruju stranicu preko trazenog limita. Provjeri cache i fallback, broj izvornih rezultata, cursor i ciscenje resursa. Odredi granicu odgovora i memorije, testiraj samu granicu i prekoracenje te oslobodi scroll pri pogresci. Navedi broj redovnih i dodatnih upita; bez mjerenja latencije ne tvrdi da je rjesenje brze. Velicina pojedine serije ne ogranicava velicinu konacnog odgovora.
Exceptions / Tradeoffs (EN)
Internal/admin export endpoints may justify higher limits, but those should be explicit and ideally streamed rather than served as one large page. A stable compound cursor can keep pages bounded while continuing within a tie group; no group-size failure is needed then. Explicit partial-result contracts must signal incompleteness and provide a usable continuation.
Iznimke / Tradeoffi (HR)
Interni/admin export endpointi mogu opravdati vise limite, ali to treba biti eksplicitno i po mogucnosti streamano umjesto sluzeno kao jedna velika stranica. Stabilan slozeni cursor moze nastaviti unutar grupe pa odbijanje velike grupe nije potrebno. Izricit ugovor za djelomicne rezultate mora oznaciti nepotpunost i dati upotrebljiv nastavak.