iwf icon indicating copy to clipboard operation
iwf copied to clipboard

NodeJS/TypeScript SDK

Open longquanzheng opened this issue 2 years ago • 4 comments

As discussed in the slack channel

https://iwfglobal.slack.com/archives/C048NCNLZB9/p1675787722020629

longquanzheng avatar Feb 12 '23 23:02 longquanzheng

@longquanzheng - We are evaluating options for workflow engines/solutions (I am the CTO @ agileonboarding.com), we are a heavy nodejs/ts shop, your comments on HN and other outlets lead me to believe that a TS SDK would not be difficult and iWF seems like a very good option for us so far in looking at it.

If there is a bit more specificity in what such an SDK would require to implement, we would consider doing so.

24601 avatar Mar 17 '23 06:03 24601

@24601 great to hear that. I also think that iWF will be a great tool for nodejs/ts developer. I would suggest to "translate" the implementation of either Java or Go SDK. Use either of them based on your preference/familiarity of the language. Or at least understand how it works -- it should be simple enough. Here I assume you use Java(based on your Github profile)

When you are ready to start, I would suggest to implement it from simple as the below steps:

Step 1: Basic workflow execution with IO/parallel

The minimum of the SDK just be able to start and execute a basic IO workflow without any additional features like more deciderTriggerType/signalComand/timerComand/dataObject/searchAttributes/workflowOptions/workflowStateOptions/complicated error handling etc.

The acceptance criteria is to be able to implement and execute a workflow like this: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/test/java/io/iworkflow/integ/basic/BasicWorkflow.java

And execute it (ignore the error handling assertion for now): https://github.com/indeedeng/iwf-java-sdk/blob/main/src/test/java/io/iworkflow/integ/BasicTest.java#L31

To implement this, you need the below components:

  • The generated API models from Swagger:
    • Add the iwf-idl repo as the submodule: https://github.com/indeedeng/iwf-golang-sdk/blob/main/.gitmodules
    • in Java we uses gradle task: https://github.com/indeedeng/iwf-java-sdk/blob/main/build.gradle#L93 so that we don't check in the generated code into the repo, but in GoSDK we use a command to generate and check in to the code: https://github.com/indeedeng/iwf-golang-sdk/blob/main/Makefile#L128 https://github.com/indeedeng/iwf-golang-sdk/tree/main/gen/iwfidl
  • Workflow interface (again, ignore the features like dataObject persistence for now, same for others) https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/Workflow.java
  • WorkflowState interface: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/WorkflowState.java
  • Registry to store the registered workflow/states in memory: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/Registry.java
  • An ObjectEncoder to encode/decode the object with JSON: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/ObjectEncoder.java
  • A client with just a start API to start the workflow: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/Client.java#L50 or https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/UnregisteredClient.java#L87
  • A worker service to invoke the two state APIs(start/decide): https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/WorkerService.java
  • Some default data models for StateDecision/StateMovement: https://github.com/indeedeng/iwf-java-sdk/blob/main/src/main/java/io/iworkflow/core/StateDecision.java

The first step may take longer time than the rest as per step, as it set up all the foundation of the work.

===================== You can start with the step 1 and let me know how it works. I will add more details to the below steps later when you are finishing the first step.

Step 2: Add Timer command

Step 3: Add Signal command

Step 4: Add interStateChannel command

Step 5: Add more decider trigger type

Step 6: Add DataObject persistence

Step 7: Add Search attribute persistence

Step 8: Add the other client API and error handling, and workflow Options and stateOptions

longquanzheng avatar Mar 17 '23 15:03 longquanzheng

@longquanzheng - thank you so very much, this is very helpful. I will evaluate this and get started as soon as I can based on our product plan/roadmap.

24601 avatar Mar 17 '23 16:03 24601

https://github.com/indeedeng/iwf-ts-sdk is being implemented

longquanzheng avatar Jul 13 '23 16:07 longquanzheng