How do @workflow/serde keys impact bundles?
How does having a class with @workflow/serde keys impact the workflow and step bundles?
Thanks. Now, what if the class, in order to deserialize, depends on some module-level code? Or on things that cannot be reconstructed. Typical case i think is some helper function that does new Point and gives it some specific methods.
Could we use a globalThis registry of these built instances? Though the file that instantiated new Point won’t be included, i assume, so this wouldn’t work. And serialization/deserialization happen in different nodejs processes, i assume.
How can the workflow team support this use case? Does it even make sense?
Maybe including files which instantiate a serde class? Imagine this: new Point(x, y, (diff) => {}) where the third param is a callback. That’s simply impossible to serde right now.
And I don’t just mean if that new Point is inside a factory, or route handler, but even if it’s in module scope.
In case it doesn’t make sense for workflow to support this pattern: what would you suggest i, as the author of this Point class, do to support my users?
i know it can't be serialized, but i meant, if i used a registry in globalThis, that got populated at module-scope. then we'd only need to include that file.
// my-point-def.ts
export const myPoint = new Point(x, y, (diff) => {})
registerPoint(myPoint)
the issue of course being that this file is not included in the workflow bundle.
then i wonder if there's a way for the user to define their own workflow and nest this instance. like:
function execute() {
"use workflow"
const myPoint = new Point(x, y, (diff) => {})
registerPoint(myPoint)
await someStepThatComputesTheDiff(myPoint)
}
albeit in this case our library wouldn't be integrating workflow, which was a core tenant of it ("it features durability")
in your last example.
// user's code — must be in a file that gets included in all bundles // (e.g., the same file as their workflow/step, or a file with serde markers) import { defineBehavior, Point } from 'cool-point-lib';
defineBehavior('my-custom', (diff) => sendToAnalytics(diff));
// Now this survives serialization: const p = new Point(10, 20, 'my-custom');
would this work? defineBehavior runs in the user's file
END OF POST