fix: add Zod schemas for PocketBase API responses to resolve type-aware linting errors #67
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.
Problem
After enabling type-aware linting with oxlint, 41
no-unsafe-*
linting errors were identified across the codebase. These errors occurred because PocketBase API responses were being parsed asany
types without proper validation, leading to unsafe type assertions and member access throughout the codebase.Solution
This PR implements comprehensive Zod schemas for all PocketBase API responses, ensuring type-safe parsing and validation of all data received from the PocketBase API.
Key Changes
1. New Type Definitions (
src/types/pocketbase-api-responses.type.ts
)Created Zod schemas for all PocketBase API response types:
pocketbaseErrorResponseSchema
- Validates error responses withcode
,message
, and optionaldata
fieldspocketbaseAuthResponseSchema
- Validates authentication responses containingtoken
fieldpocketbaseListResponseSchema
- Validates paginated collection responses with proper item validationpocketbaseMinimalListResponseSchema
- Handles responses when specific fields are requested (e.g., onlyid
field)2. Enhanced Entry and Schema Types
pocketBaseEntrySchema
to validate core PocketBase entry fields (id
,collectionId
,collectionName
)pocketBaseCollection
andpocketBaseSchemaEntry
to use.passthrough()
, allowing additional fields from PocketBase while still validating required fields3. Type-Safe API Response Handling
Updated all files that interact with PocketBase API:
Files updated:
src/utils/get-superuser-token.ts
src/schema/get-remote-schema.ts
src/loader/fetch-collection.ts
src/loader/fetch-entry.ts
src/loader/cleanup-entries.ts
4. Improved Error Handling
All error response parsing now includes try-catch fallbacks to handle cases where PocketBase returns non-JSON responses (e.g., HTML error pages):
5. Fixed Unsafe Type Assertions
error as Error
to proper type checking witherror instanceof Error
.safeParse()
before processing file fieldsResults
no-unsafe-*
errors (41 → 0)The codebase now has strong type safety while maintaining compatibility with PocketBase's dynamic response structures.
Documentation
All changes follow the existing code patterns and are documented with JSDoc comments. The Zod schemas are based on the official PocketBase API documentation.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.