How do @workflow/serde keys impact bundles?

HEAD
4ac75f4Add Fluid compute callout to Vercel World docs (#1242)
This post might have stale content, as HEAD is 936 commits ahead.

How does having a class with @workflow/serde keys impact the workflow and step bundles?

Avatar of julianbenegas
Julian Benegas
commented

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.

Avatar of julianbenegas
Julian Benegas
commented

How can the workflow team support this use case? Does it even make sense?

Avatar of julianbenegas
Julian Benegas
commented

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?

Avatar of julianbenegas
Julian Benegas
commented

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")

Avatar of julianbenegas
Julian Benegas
commented

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

How do @workflow/serde keys impact bundles? — vercel/workflow