Azure / azure-functions-durable-js

JavaScript library for using the Durable Functions bindings
https://www.npmjs.com/package/durable-functions
MIT License
128 stars 47 forks source link

Durable SDK breaking changes v2 -> v3 required for essential programming model functioning. #453

Closed hossam-nasr closed 1 year ago

hossam-nasr commented 1 year ago

All of the changes in this issue have already been merged (#389 and #399). This issue is purely for documentation and tracking purposes, to document the breaking changes going from v2.x to v3.x of the Durable SDK, that were essential to get a basic version of the SDK to work the new programming model package.

1. Take a dependency on @azure/functions v4.x

Due to the way the new programming model works, and the split between the Azure Functions worker and the node.js Framework (@azure/functions), the Durable SDK had to move @azure/functions from a devDependency to a dependency, as well as upgrade to v4.x of the package. This comes with all the breaking changes from v3.x to v4.x of @azure/functions, including, but not limited to:

2. Removed df.orchestrator() and df.entity()

The previous df.orchestrator() and df.entity() functions have been removed from the SDK, and have been replaced by new methods under the df.app namespace:

// takes your generator function as an argument directly
function orchestration(functionName: string, handler: OrchestrationHandler): void;

// takes an options object as an argument 
// currently, the only supported parameter is a handler parameter
// with the generator as value
function orchestration(functionName: string, options: OrchestrationOptions): void;

Both of which create your orchestration function and register it directly with the app.

// takes your entity function as an argument directly
function entity<T = unknown>(functionName: string, handler: EntityHandler<T>): void;

// takes an options object as an argument 
// currently, the only supported parameter is a handler parameter
// with the entity function as value
function entity<T = unknown>(functionName: string, options: EntityOptions<T>): void;

Both of which also create your entity function and register it directly with the app.

3. Remove dependency on context.done():

In the new programming model (v4.x), context.done() was removed from the InvocationContext object, and instead functions must return their result as the return value of the function. As a result, before, you could do something like this:

const myEntityFunc = df.entity(function (context) {
    // do stuff
});

export default (context) => {
    myEntityFunc(context); // note no `return` here
};

But after the change, such a wrapper around the entity function cannot be registered as an entity. This change should not be relevant in the vast majority of cases though, not only because this was a niche use-case, but also because the semantics of the df.entity() API have also changed (see below).

hossam-nasr commented 1 year ago

Closed by #389 and #399