moleculer-zod-validator
Advanced tools
Changelog
3.3.1 (2023/6/22)
ReturnType
with classes, as you'd run into TS2052. Whoops.Changelog
3.3.0 (2023/6/22)
Added the .return
property to ZodParams
. This is a utility to store return types that can be used for typing action calls elsewhere.
Return values are provided by providing a type on a new third optional constructor parameter. It does not matter what is passed in, so long as it is given the desired return types using the as
keyword. Once stored, these can be referred to in the same way that you would access .call
and .context
.
const sampleParam = new ZodParams({ property: z.string() }, undefined, {} as Promise<string>);
...
const returnedValue = broker.call<typeof sampleParam.return, typeof sampleParam.call>({ property: "whatever" });
// type of returnedValue is Promise<string>
Updated dev dependencies
Changelog
3.2.0 (2023/5/2)
.refine
and .superRefine
methods. These add additional flexibility for validation. This closes Issue #7.Changelog
3.1.0 (2023/4/21)
Type inference now works (mostly) as expected! While the runtime behavior of the package worked as expected during work on 3.0.0 and was what I had been testing, I somehow was completely unaware that type inference was completely broken. It's a bit embarrassing for me, to be honest. It took more energy than I had anticipated to make it work, but type inferences now behave when using typeof .call
and typeof .context
almost exactly as they do in Zod with z.input<typeof validator>
and z.infer<typeof validator>
/z.output<typeof validator>
. This closes Issue #5.
I do say almost, as there is an important note that is worth mentioning. There's a known upstream bug in Zod where using .catchall()
results in bugged TypeScript type inference. While I could have left that behavior in ZodParams for parity with Zod, the sudden introduction of that behavior could break builds (it already broke one of our tests, through no fault of my own), so for the time being I've disabled catchall type inference in ZodParams. When the bug is fixed upstream, I'll reenable that behavior here.
Beyond all of this, there should be no other changes and everything should Just Work™ as expected.
Updated dev dependencies
Changelog
3.0.1 (2023/4/13)
Changelog
3.0.0 (2023/4/13)
structuredClone
function in the fastest-validator fallback (described below), which in Node.js is only available in v17.0.0 and above. I tried using Lodash's cloneDeep
method like Moleculer itself uses, but for a reason unknown to me it kept causing crashes during unit testing that I couldn't figure out. structuredClone
does work, however, which should solve the same problem.$node
internal services built into Moleculer assume that fastest-validator is the current validator, which poses a problem given as moleculer-zod-validator had no idea what to do with those schemas. By checking for the existence of property in the Zod schema that is not used in fastest-validator, this can now automatically switch into a failsafe that uses fastest-validator instead.Changelog
2.0.0 (2022/1/24)
compiledValidatorOnly
nested options object. The two settings, strip
and passthrough
, are now present in the top level options object.strip
as opposed to passthrough
.Changelog
1.0.2 (2022/1/17)
Changelog
1.0.1 (2022/1/17)