Skip to content

feat(line-protocol): add splitPoints for oversized write batches - #53

Merged
AayushMainali-Github merged 1 commit into
mainfrom
feat/37-split-points
Jul 25, 2026
Merged

feat(line-protocol): add splitPoints for oversized write batches#53
AayushMainali-Github merged 1 commit into
mainfrom
feat/37-split-points

Conversation

@AayushMainali-Github

Copy link
Copy Markdown
Owner

Closes #37.

What

Adds splitPoints(points, { maxBytes, precision }), a generator that cuts a batch of points into Line Protocol payloads none larger than maxBytes. writePoints() still sends one request however many points it is given; this is the explicit escape hatch for batches large enough to hit a server limit.

Why it is shaped this way

Sizing is by encoded UTF-8 bytes rather than point count. Points vary enormously in encoded length, and the limit a server enforces is measured in bytes, so a point-count cap would be a guess dressed up as a guarantee. The newlines between lines are counted too, so a payload that fits here fits on the wire.

There is no default maxBytes and nothing splits unless a caller asks. A default would be this library guessing at a server limit it cannot see, and it would silently change what existing writes do.

It is a generator, so points are serialized as they are consumed. A caller writing chunk by chunk never holds the whole batch in memory as one string.

Sending the chunks is left to the caller. If the seventh chunk fails, the first six are already written, and only the caller can decide what that means for their data. Hiding the loop inside a write would turn one call into many requests and make partial success invisible.

A single point larger than maxBytes throws a RangeError naming its index and encoded size, because no split can satisfy the request and emitting an oversized payload anyway would break the guarantee the caller asked for. A non-positive or non-integer maxBytes throws a TypeError.

Tests

Unit tests cover exact-fit boundaries, the newline accounting, multi-byte characters, empty input, precision pass-through, lazy evaluation, and both throw paths. An integration test writes a 60-point batch through a 400-byte limit against a live server and asserts all 60 rows land, so the chunking is proven to produce payloads the server actually accepts rather than only ones that satisfy the unit test's arithmetic.

@github-actions github-actions Bot added area: client Area: client area: testing Area: testing area: documentation Area: documentation area: release Area: release labels Jul 25, 2026
@AayushMainali-Github
AayushMainali-Github merged commit 2ef8eea into main Jul 25, 2026
14 checks passed
@AayushMainali-Github
AayushMainali-Github deleted the feat/37-split-points branch July 25, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: client Area: client area: documentation Area: documentation area: release Area: release area: testing Area: testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Explicit helper for splitting oversized write batches

1 participant