Skip to content

refactor!: validate arguments with zod instead of ow - #986

Open
vdusek wants to merge 8 commits into
v3from
feat/replace-ow-with-zod
Open

refactor!: validate arguments with zod instead of ow#986
vdusek wants to merge 8 commits into
v3from
feat/replace-ow-with-zod

Conversation

@vdusek

@vdusek vdusek commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Replaces ow with zod for 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.

ArgumentValidationError and the internal validate() helper are a hand-synced local copy of the @crawlee/core / SDK ones, because apify-client sits below both in the dependency graph. zod is 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 into invalid_union issues, so a failed union lists every arm the way ow.any() did instead of a bare Invalid 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.ts disables tree-shaking and minification; .strict(), .passthrough() and z.nativeEnum() are deprecated in zod 4 and could move to z.strictObject / z.looseObject / z.enum; chunkSize is missing from every .strict() list schema (pre-existing — ow's exactShape had the same gap).

BREAKING CHANGE: invalid arguments now throw ArgumentValidationError (exported from apify-client) instead of ow's ArgumentError, with different messages, the structured zod issues on issues and the original ZodError on cause. Two kinds of value that ow accepted are now rejected. Arrays and functions no longer pass where a plain object is expected — update() / create() fields, TaskClient.start() / call() input, the storage schema option, and DatasetClient.pushItems() items. And Infinity no longer passes on numeric options such as timeoutSecs, waitSecs, memory, limit or maxUnprocessedRequestsRetries, because zod's z.number() requires a finite number. Date, Map, Set and other class instances still pass as objects, exactly as they did under ow.

✍️ Drafted by Claude Code

vdusek added 2 commits July 30, 2026 16:19
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).
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Jul 30, 2026
@vdusek vdusek self-assigned this Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

⚠️ There are broken links in the documentation.

See more at https://github.com/apify/apify-client-js/actions/runs/30620418874#summary-91123398435

@vdusek vdusek changed the title refactor!: replace ow with zod for argument validation refactor!: validate arguments with zod instead of ow Jul 30, 2026
@vdusek
vdusek requested a review from B4nan July 31, 2026 09:40
@vdusek
vdusek marked this pull request as ready for review July 31, 2026 09:40
@vdusek
vdusek requested a review from szaganek as a code owner July 31, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants