refactor!: validate arguments with zod instead of ow - #986
Conversation
|
See more at https://github.com/apify/apify-client-js/actions/runs/31005542533#summary-92304422147 |
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 |
aa2684d to
41d769b
Compare
|
@B4nan it's ready for a re-check |
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.How it works
ArgumentValidationErrorandvalidate()are a hand-synced copy of the@crawlee/core/ SDK ones —apify-clientsits below both in the dependency graph.zod ^4.0.0matches the merged SDK PR.z.strictObject/z.looseObject/z.enum, not the deprecated.strict()/.passthrough()/z.nativeEnum().chunkSizenow works wherever the options interface extendsPaginationOptions, via a sharedpaginationOptionsShapethe schemas spread. It used to type-check but throw;ow'sexactShapehad the same gap.Browser bundle
rsbuild.config.ts, off since the webpack-to-rsbuild migration in chore: update eslint, adopt prettier and rsbuild #671. Now 288 kB raw / 87 kB gzip, from 1439 kB / 273 kB — below the 946 kB / 203 kB before this PR. A 320 kB budget fails the build, so it cannot grow unnoticed again.Breaking changes
ArgumentValidationError(exported fromapify-client), notow'sArgumentError— different messages, the zod issues onissues, the originalZodErroroncause.update()/create()fields,TaskClient.start()/call()input, the storageschemaoption,DatasetClient.pushItems()items.Infinityno longer passes on numeric options such aswaitSecs,timeoutSecsormemory, and an invalidDateno longer passes onstartedBefore/startedAfter—z.number()requires a finite number andz.date()a valid date, whereowonly checked the type.chunkSizeondownloadItems()andcreateItemsPublicUrl(),signatureoncreateItemsPublicUrl()andcreateKeysPublicUrl()— a compile error now instead of a throw.Date,Map,Setand other class instances still pass as objects, as underow.✍️ Drafted by Claude Code