mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
d72c82220f
* first pass * fix failing test * Update changeset to fix SWC compiler issue Fix bug where the SWC compiler bug prunes step-only imports in the client-mode transformation Signed-off-by: Nathan Rajlich <n@n8.io> * DCO Remediation Commit for nathancolosimo <nathancolosimo@gmail.com> I, nathancolosimo <nathancolosimo@gmail.com>, hereby add my Signed-off-by to this commit:150d175e7dI, nathancolosimo <nathancolosimo@gmail.com>, hereby add my Signed-off-by to this commit:429747fcc3Signed-off-by: nathancolosimo <nathancolosimo@gmail.com> --------- Signed-off-by: Nathan Rajlich <n@n8.io> Signed-off-by: nathancolosimo <nathancolosimo@gmail.com> Co-authored-by: Nathan Rajlich <n@n8.io>
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
/**
|
|
* Step functions that use the Vector class for cross-context serialization testing.
|
|
*
|
|
* These steps import Vector from serde-models.ts. The workflow code does NOT
|
|
* directly import Vector - it only receives/passes Vector instances through
|
|
* step calls. This tests cross-context class registration.
|
|
*/
|
|
|
|
import { Vector } from './serde-models';
|
|
|
|
/**
|
|
* Step that receives a Vector and scales it.
|
|
* Tests: workflow -> step deserialization, step -> workflow serialization
|
|
*/
|
|
export async function scaleVector(vector: Vector, factor: number) {
|
|
'use step';
|
|
// Verify the vector was properly deserialized and has its methods
|
|
console.log('Vector magnitude:', vector.magnitude());
|
|
// Scale and return (will be serialized on return)
|
|
return vector.scale(factor);
|
|
}
|
|
|
|
/**
|
|
* Step that receives two Vectors and adds them.
|
|
* Tests: workflow -> step deserialization of multiple instances
|
|
*/
|
|
export async function addVectors(v1: Vector, v2: Vector) {
|
|
'use step';
|
|
// Verify both vectors have their methods
|
|
console.log('v1 magnitude:', v1.magnitude());
|
|
console.log('v2 magnitude:', v2.magnitude());
|
|
return v1.add(v2);
|
|
}
|
|
|
|
/**
|
|
* Step that creates and returns a new Vector.
|
|
* Tests: step creating new instance -> workflow deserialization
|
|
*/
|
|
export async function createVector(x: number, y: number, z: number) {
|
|
'use step';
|
|
return new Vector(x, y, z);
|
|
}
|
|
|
|
/**
|
|
* Step that receives an array of Vectors.
|
|
* Tests: serialization of arrays containing custom class instances
|
|
*/
|
|
export async function sumVectors(vectors: Vector[]) {
|
|
'use step';
|
|
let totalX = 0;
|
|
let totalY = 0;
|
|
let totalZ = 0;
|
|
for (const v of vectors) {
|
|
// Verify each vector has its methods
|
|
console.log('Vector magnitude:', v.magnitude());
|
|
totalX += v.x;
|
|
totalY += v.y;
|
|
totalZ += v.z;
|
|
}
|
|
return new Vector(totalX, totalY, totalZ);
|
|
}
|