feat(fetch-client): implement fetch-based CRUD API client#2651
feat(fetch-client): implement fetch-based CRUD API client#2651
Conversation
A simple fetch-based, non-reactive client library that consumes the
RPC-style auto CRUD API.
- Per-model CRUD operations (`findUnique`, `findMany`, `create`, etc.)
derived from the ORM's `AllModelOperations`, with slicing applied via
a key-filter mapped type that preserves per-call generic narrowing.
- `findUniqueOrThrow` / `findFirstOrThrow` raise a typed `CrudError`
with `code: CrudErrorCode.NotFound` and the offending model name.
- Sequential transactions via `client.\$transaction([...])` accepting an
array of typed `{ model, op, args }` operations; result tuple is
typed per-position via `TransactionResults`.
- Custom procedures exposed under `client.\$procs` with `query` /
`mutate` based on the procedure shape.
- Endpoint is required and validated as a fully qualified URL.
- Threads `ExtQueryArgs` and `ExtResult` through model ops and
transactions so plugin-extended query args / result fields are
reflected in user-facing types.
Refactors:
- Move `TransactionOperation` / `TransactionResults` types and the
`CUSTOM_PROC_ROUTE_NAME` / `TRANSACTION_ROUTE_PREFIX` constants into
`@zenstackhq/client-helpers` so both clients can share them.
- Move the `DEFAULT_QUERY_ENDPOINT` constant to tanstack-query (where
it belongs).
Tests: 47 runtime tests + 13 type-level tests covering CRUD ops, HTTP
methods, SuperJSON serialization, error handling, transactions, slicing,
ExtQueryArgs, and ExtResult propagation. Test schemas use real ZModel
files generated via the existing `scripts/test-generate.ts`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job PR Review: feat(fetch-client): add @zenstackhq/fetch-client packageI've completed my review of the new Review Tasks
🟢 Overall Assessment: Strong ImplementationThis is a well-designed and implemented addition to the ZenStack ecosystem. The code quality is high, follows established patterns, and provides excellent type safety. Code Quality & Best Practices✅ Excellent Type Safety
✅ Clean Architecture
✅ Error Handling
Test Coverage Analysis✅ Comprehensive Coverage (60 tests)
✅ Test Quality
Security Considerations✅ Good Security Practices
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughA new fetch-based client package is introduced alongside a refactoring that extracts shared transaction types and route constants into a centralized client-helpers module. Existing consumer packages (tanstack-query) are updated to import from the new shared locations. ChangesCentralized Client Infrastructure & Fetch Client
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job PR Review: feat(fetch-client): implement fetch-based CRUD API clientI've completed my review of the new Review Tasks
🟢 Overall Assessment: Strong ImplementationThis is a well-designed and implemented addition to the ZenStack ecosystem. The code quality is high, follows established patterns, and provides excellent type safety. Code Quality & Best Practices✅ Excellent Type Safety
✅ Clean Architecture
✅ Error Handling
Test Coverage Analysis✅ Comprehensive Coverage (60 tests)
✅ Test Quality
Security Considerations✅ Good Security Practices
|
|
Claude finished @ymc9's task —— View job PR Review: feat(fetch-client): implement fetch-based CRUD API clientI've completed my comprehensive review of this new fetch-client package. Here's my detailed feedback: Review Tasks
🟢 Overall Assessment: Strong ImplementationThis is a well-designed and implemented addition to the ZenStack ecosystem. The code quality is high, follows established patterns, and provides excellent type safety. Code Quality & Best Practices✅ Excellent Type Safety
✅ Clean Architecture
✅ Error Handling
Test Coverage Analysis✅ Comprehensive Coverage (60 tests)
✅ Test Quality
Security Considerations✅ Good Security Practices
|
|
Claude finished @ymc9's task —— View job PR Review: feat(fetch-client): implement fetch-based CRUD API clientI've completed my comprehensive review of this new fetch-client package. Here's my detailed feedback: Review Tasks
🟢 Overall Assessment: Strong ImplementationThis is a well-designed and implemented addition to the ZenStack ecosystem. The code quality is high, follows established patterns, and provides excellent type safety. Code Quality & Best Practices✅ Excellent Type Safety
✅ Clean Architecture
✅ Error Handling
Test Coverage Analysis✅ Comprehensive Coverage (60 tests)
✅ Test Quality
Security Considerations✅ Good Security Practices
|
Summary
A new
@zenstackhq/fetch-clientpackage — a simple, fetch-based, non-reactive client that consumes the RPC-style auto CRUD API. Sits alongside@zenstackhq/tanstack-queryfor consumers who want plain async/await without a reactive layer.What's in it
AllModelOperations, then trimmed by slicing options via a key-filter mapped type that preserves per-call generic narrowing (soselect/includestill narrow result types).findUniqueOrThrow/findFirstOrThrow— implemented client-side; raise a typedCrudErrorwithcode: CrudErrorCode.NotFoundand the offending model name.client.\$transaction([...])— sequential transactions accepting a typed array of{ model, op, args }operations. Result tuple is typed per-position viaTransactionResults.client.\$procs— custom procedures exposed withquery/mutatebased on the procedure shape.ExtQueryArgs/ExtResultare threaded through model ops and transactions, so plugin-extended query args / result fields are reflected in user-facing types.Cross-package refactors
TransactionOperation/TransactionResultstypes and theCUSTOM_PROC_ROUTE_NAME/TRANSACTION_ROUTE_PREFIXconstants fromtanstack-queryinto@zenstackhq/client-helpersso both clients share them.tanstack-queryre-exports unchanged at its existing import paths — no churn at call sites.DEFAULT_QUERY_ENDPOINTtotanstack-query(where it actually belongs).Test plan
pnpm --filter @zenstackhq/fetch-client build— clean (tsc, tsdown, test:generate, test:typecheck)pnpm --filter @zenstackhq/fetch-client test— 60 tests pass (47 runtime + 13 type-level)pnpm --filter @zenstackhq/client-helpers build— cleanpnpm --filter @zenstackhq/tanstack-query exec tsc --noEmit -p tsconfig.general.json— cleanTest schemas use real
.zmodelfiles generated via the existingscripts/test-generate.ts(mirroring tanstack-query's setup).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Chores