feat: add unpaginate util - #53
Merged
Merged
Conversation
The lossy counterpart to `toPaginated`: takes the result of a `find` that may or may not be paginated and yields the items. A plain array is returned as-is, a paginated result yields its `data`, and `undefined`/`null` yields an empty array - so a `find` can be consumed without knowing whether pagination is enabled for the service or disabled via `params.paginate: false`. `changeMany` now uses it instead of hand-rolling the same ternary. Also adds the docs frontmatter for `replaceData` and `replaceResult`, which was missed when they were added in #32 - both JSDoc blocks already pointed at `utils/replace-data.html` and `utils/replace-result.html`, pages that did not exist. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Deploying feathers-utils with
|
| Latest commit: |
5be4077
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5f7fa351.feathers-utils.pages.dev |
| Branch Preview URL: | https://feat-unpaginate.feathers-utils.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
unpaginateThe lossy counterpart to
toPaginated. Takes the result of afindthat may or may not be paginated and yields the items:dataundefined/nullyields[]This is the everyday case as soon as a service is consumed without knowing whether pagination is enabled for it or disabled via
params.paginate: false. The pattern was already hand-rolled three times inside this repo.total,limitandskipare dropped, sounpaginate(toPaginated(x))round-trips but the reverse does not — the JSDoc says so explicitly. The returned array must be treated as read-only, likecommon/toArray.changeManynow uses it in place ofArray.isArray(found) ? found : (found?.data ?? []).One thing to review
src/common/now imports fromsrc/utils/for the first time — so farcommonhas been a leaf layer. The import targets the file rather than the barrel, andunpaginateitself has only a type import, so a cycle is impossible. If the layering matters more than the single call site,changeManycan keep its ternary.Drive-by: missing docs pages
replaceDataandreplaceResulthad no.md, so they had no page on the docs site — missed when they were added in #32. Both JSDoc blocks already pointed atutils/replace-data.htmlandutils/replace-result.html, i.e. the@seelinks were dead. Frontmatter added for both; the three pagination utils (toPaginated,unpaginate,predicates/isPaginated) are now cross-linked.Also carries the
paginationtag additions togetResultIsArrayandmutateResult.Testing
pnpm testgreen: 134 files, 1449 passed / 2 skipped, no type errors, no lint errors.pnpm docs:buildandpnpm buildclean; the three new pages render.Known, not addressed here
replaceResultwrites only.dataon a paginated result and leavestotaluntouched, so a length-changing replacement leaves a staletotal(inherited bymutateResultvia delegation, and untested — both tests only cover length-preserving cases). Arguably correct, sincetotalis the number of matches in the database rather than the length of this page, but it is currently implicit. Left for a separate change.🤖 Generated with Claude Code