refactor!: validate arguments with zod instead of ow - #986
Open
vdusek wants to merge 8 commits into
Open
Conversation
BREAKING CHANGE: runtime argument validation switched from `ow` to `zod`, so every invalid-argument error message changed, and the thrown error is now an `ArgumentValidationError` (newly exported from `apify-client`) instead of `ow`'s `ArgumentError`. It exposes the structured zod issues on `issues` and keeps the original `ZodError` on `cause`, so you can branch on them instead of parsing the message. Values that `ow.object` accepted only incidentally are now rejected: arrays no longer pass as objects for `update()` / `create()` fields, for `TaskClient.start()` / `call()` input, for the storage `schema` option, or as `DatasetClient.pushItems()` array items (which must be objects or strings).
Contributor
|
See more at https://github.com/apify/apify-client-js/actions/runs/30620418874#summary-91123398435 |
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.
Replaces
owwithzodfor runtime argument validation, mirroring apify/apify-sdk-js#636 and apify/crawlee#3716 so all three packages share one error type and message format. Input validation only — response validation is a separate PR.ArgumentValidationErrorand the internalvalidate()helper are a hand-synced local copy of the@crawlee/core/ SDK ones, becauseapify-clientsits below both in the dependency graph.zodis required at^4.0.0, matching the merged SDK PR; crawlee's still-open PR allows^3 || ^4, which zod 4 satisfies, so the three still dedupe onto one copy. The one deliberate divergence is that the local formatter recurses intoinvalid_unionissues, so a failed union lists every arm the wayow.any()did instead of a bareInvalid input; the same patch should be upstreamed.Follow-ups: the browser bundle grows from 946 kB to 1446 kB raw (203 kB -> 272 kB gzip), because
rsbuild.config.tsdisables tree-shaking and minification;.strict(),.passthrough()andz.nativeEnum()are deprecated in zod 4 and could move toz.strictObject/z.looseObject/z.enum;chunkSizeis missing from every.strict()list schema (pre-existing —ow'sexactShapehad the same gap).BREAKING CHANGE: invalid arguments now throw
ArgumentValidationError(exported fromapify-client) instead ofow'sArgumentError, with different messages, the structured zod issues onissuesand the originalZodErroroncause. Two kinds of value thatowaccepted are now rejected. Arrays and functions no longer pass where a plain object is expected —update()/create()fields,TaskClient.start()/call()input, the storageschemaoption, andDatasetClient.pushItems()items. AndInfinityno longer passes on numeric options such astimeoutSecs,waitSecs,memory,limitormaxUnprocessedRequestsRetries, because zod'sz.number()requires a finite number.Date,Map,Setand other class instances still pass as objects, exactly as they did underow.✍️ Drafted by Claude Code