refactor!: validate arguments with zod instead of ow - #986
Conversation
|
See more at https://github.com/apify/apify-client-js/actions/runs/30827446923#summary-91732605864 |
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).
4e8b5c1 to
b74a66e
Compare
The ow-based validation rejected symbol and bigint values loudly, but the zod replacement only checked for undefined. A symbol value would then pass validation, serialize to undefined, and silently PUT an empty record body.
Also fixes a pre-existing "validatioon" typo carried through two comments.
`describeReceived('')` used to produce bare backticks with nothing
between them, e.g. for `client.actor('')`.
I would rather fix it here before it gets merged. We don't want to use any deprecated methods, and this PR introduces the bundle size issue. |
OK, I'll check it out |
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