Azure / azure-functions-durable-js

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

Improve TypeScript experience #443

Closed hossam-nasr closed 1 year ago

hossam-nasr commented 1 year ago

Implements most items of #416. Also took the chance to improve the types organization, and move the types from one types file into a types directory. Also converted some classes that were essentially serving as interfaces into interfaces. This looks like a big change, but it's pretty much all organization and renaming. There are no breaking changes in this PR (don't worry, those are coming soon 😉). The specific changes in this PR are:

  1. Exports type OrchestrationHandler<T = any> = (context: OrchestrationContext) => Generator<Task, T, any> (T being the return type of the generator), a more specific and type-safe version of the previous OrchestrationHandler.
  2. Exports an OrchestrationContext and an EntityContext<T> type, to replace the previous IOrchestrationFunctionContext and IEntityFunctionContext<T> types, and also exports them from the root of the package.
  3. Exports a DurableClient interface from the root of the package, which the class DurableOrchestrationClient now implements.
  4. Exports Task and TimerTask types from the root of the package.
  5. Transforms some classes that were essentially serving as interfaces into interfaces:
    • PurgeHistoryResult
    • EntityStateResponse
    • HttpManagementPayload
  6. Exports interfaces that classes implement:
    • Exports a DurableOrchestrationContext interface, which now the DurableOrchestrationContext class implements.
    • Exports a DurableEntityContext interface, which now the DurableEntityContext class implements.
    • Exports an EntityId interface, which now the EntityId class implements
    • Exports a DurableOrchestrationStatus interface, which the DurableOrchestrationStatus classs now implements.
    • Exports a RetryOptions interface, which the RetryOptions class implements
    • Exports a ManagedIdentityTokenSource interface, which the ManagedIdentityTokenSource class implements
  7. Renames GetStatusOptions to GetStatusInternalOptions (since it was actually passed to getStatusInternal(), not getStatus().
  8. Moves types from the src/types.ts into multiple src/types/*.ts files
hossam-nasr commented 1 year ago

Discussed this offline. Closing this PR to split into smaller PRs.