Chore: cleanup workflows SDK (#9244)

Fixes: FRMW-2712
This commit is contained in:
Harminder Virk
2024-09-23 11:04:38 +00:00
committed by GitHub
parent 97e003ef4f
commit 9f72fb5902
9 changed files with 147 additions and 70 deletions
+20 -1
View File
@@ -1,5 +1,24 @@
module.exports = {
transform: { "^.+\\.[jt]s?$": "@swc/jest" },
transform: {
"^.+\\.[jt]s$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
decorators: true,
},
transform: {
useDefineForClassFields: false,
legacyDecorator: true,
decoratorMetadata: true,
},
target: "ES2021",
},
},
],
},
testPathIgnorePatterns: [`dist/`, `node_modules/`],
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
+12 -4
View File
@@ -3,29 +3,37 @@
"version": "0.1.6",
"description": "Set of workflows tooling for Medusa",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./composer": "./dist/utils/composer/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/workflows"
},
"engines": {
"node": ">=16"
"node": ">=20.0.0"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
"dist",
"!dist/**/__tests__",
"!dist/**/__mocks__",
"!dist/**/__fixtures__"
],
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/types": "^1.11.16",
"@swc/jest": "^0.2.36",
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"typescript": "^5.1.6"
"ts-jest": "^29.2.5",
"typescript": "^5.6.2"
},
"dependencies": {
"@medusajs/modules-sdk": "^1.12.11",
@@ -24,6 +24,7 @@ const workflow = createWorkflow(
"sub-workflow",
function (input: WorkflowData<{ outsideWorkflowData: string }>) {
step1()
step2({ filters: { id: [] } })
const somethingHook = createHook("something", { id: "1" })
step3()
return new WorkflowResponse({ id: 1 }, { hooks: [somethingHook] })
@@ -4,6 +4,7 @@ import {
WorkflowManager,
WorkflowScheduler,
} from "@medusajs/orchestration"
import { IEventBusModuleService } from "@medusajs/types"
import {
Modules,
composeMessage,
@@ -138,14 +139,14 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
@@ -223,14 +224,14 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
@@ -331,14 +332,14 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
@@ -441,14 +442,14 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
@@ -557,14 +558,14 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation(function (...inputs) {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation(function (...inputs) {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
@@ -651,21 +652,21 @@ describe("Workflow composer", function () {
return { inputs: [input], obj: "return from 1" }
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 2",
}
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 3",
}
})
const mockStep4Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 4",
@@ -1001,14 +1002,14 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
@@ -1093,6 +1094,7 @@ describe("Workflow composer", function () {
if (!input) {
return StepResponse.skip()
}
return new StepResponse({ obj: "return from 2" })
})
const mockStep3Fn = jest.fn().mockImplementation((inputs) => {
return new StepResponse({
@@ -1140,7 +1142,7 @@ describe("Workflow composer", function () {
obj: "return from 1",
},
two: {
__type: "Symbol(WorkflowWorkflowData)",
obj: "return from 2",
},
input: "none",
})
@@ -1151,7 +1153,7 @@ describe("Workflow composer", function () {
obj: "return from 1",
},
two: {
__type: "Symbol(WorkflowWorkflowData)",
obj: "return from 2",
},
input: "none",
},
@@ -1164,14 +1166,14 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
@@ -1272,14 +1274,14 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
@@ -1382,14 +1384,14 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
@@ -1498,14 +1500,14 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation(function (...inputs) {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation(function (...inputs) {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
@@ -1592,21 +1594,21 @@ describe("Workflow composer", function () {
return new StepResponse({ inputs: [input], obj: "return from 1" })
})
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 2",
})
})
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return new StepResponse({
inputs,
obj: "return from 3",
})
})
const mockStep4Fn = jest.fn().mockImplementation((...inputs) => {
const context = inputs.pop()
inputs.pop()
return {
inputs,
obj: "return from 4",
@@ -2147,7 +2149,12 @@ describe("Workflow composer", function () {
expect(mockStep1Fn).toHaveBeenCalledTimes(1)
expect(mockStep1Fn.mock.calls[0]).toHaveLength(2)
const eventBusMock = container.resolve(Modules.EVENT_BUS)
const eventBusMock = container.resolve<
IEventBusModuleService & {
emit: jest.Mock<any, any, any>
releaseGroupedEvents: jest.Mock<any, any, any>
}
>(Modules.EVENT_BUS)
expect(eventBusMock.emit).toHaveBeenCalledTimes(1)
expect(eventBusMock.emit.mock.calls[0][0]).toEqual("event1")
@@ -1,6 +1,7 @@
import { createStep } from "../create-step"
import { createWorkflow } from "../create-workflow"
import { StepResponse } from "../helpers"
import { WorkflowResponse } from "../helpers/workflow-response"
import { transform } from "../transform"
import { WorkflowData } from "../type"
import { when } from "../when"
@@ -25,7 +26,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
step1()
return step2(input)
return new WorkflowResponse(step2(input))
}
)
@@ -33,7 +34,7 @@ describe("Workflow composer", () => {
const subWorkflowRes = subWorkflow.runAsStep({
input: "hi from outside",
})
return step3(subWorkflowRes.result)
return new WorkflowResponse(step3(subWorkflowRes.result))
})
const { result } = await workflow.run({ input: {} })
@@ -59,7 +60,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
step1()
return step2(input)
return new WorkflowResponse(step2(input))
}
)
@@ -74,7 +75,7 @@ describe("Workflow composer", () => {
})
})
return step3(subWorkflowRes.result)
return new WorkflowResponse(step3(subWorkflowRes!.result))
}
)
@@ -101,7 +102,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
step1()
return step2(input)
return new WorkflowResponse(step2(input))
}
)
@@ -116,7 +117,7 @@ describe("Workflow composer", () => {
})
})
return step3(subWorkflowRes.result)
return new WorkflowResponse(step3(subWorkflowRes!.result))
}
)
@@ -169,7 +170,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
step1()
return step2(input)
return new WorkflowResponse(step2(input))
}
)
@@ -179,7 +180,7 @@ describe("Workflow composer", () => {
input: "hi from outside",
})
step4WithError()
return subWorkflowRes
return new WorkflowResponse(subWorkflowRes)
})
const { errors } = await workflow.run({ throwOnError: false })
@@ -219,7 +220,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
childWorkflowStep1()
return childWorkflowStep2(input)
return new WorkflowResponse(childWorkflowStep2(input))
}
)
@@ -227,7 +228,7 @@ describe("Workflow composer", () => {
const subWorkflowRes = subWorkflow.runAsStep({
input: "hi from outside",
})
return step1(subWorkflowRes.result)
return new WorkflowResponse(step1(subWorkflowRes.result))
})
const { result } = await workflow.run({
@@ -271,7 +272,7 @@ describe("Workflow composer", () => {
getNewWorkflowId(),
function (input: WorkflowData<string>) {
childWorkflowStep1()
return childWorkflowStep2(input)
return new WorkflowResponse(childWorkflowStep2(input))
}
)
@@ -279,7 +280,7 @@ describe("Workflow composer", () => {
const subWorkflowRes = subWorkflow.runAsStep({
input: "hi from outside",
})
return step1(subWorkflowRes.result)
return new WorkflowResponse(step1(subWorkflowRes.result))
})
const { result } = await workflow.run({
@@ -307,16 +308,19 @@ describe("Workflow composer", () => {
})
const work = createWorkflow("id" as any, () => {
const resStep1 = step1()
step1()
const resStep2 = step2()
const transformedData = transform({ data: resStep2 }, (data) => {
// @ts-expect-error "Since we are reading result from undefined"
return { result: data.data.result }
})
return transform({ data: transformedData, resStep2 }, (data) => {
return { result: data.data }
})
return new WorkflowResponse(
transform({ data: transformedData, resStep2 }, (data) => {
return { result: data.data }
})
)
})
const { errors } = await work.run({ input: {}, throwOnError: false })
+5 -10
View File
@@ -4,27 +4,22 @@
"target": "es2021",
"outDir": "./dist",
"esModuleInterop": true,
"declarationMap": true,
"declaration": true,
"noUnusedLocals": true,
"declarationMap": true,
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true,
"downlevelIteration": true
"skipLibCheck": true
},
"include": ["src"],
"exclude": [
"dist",
"./src/**/__tests__",
"./src/**/__mocks__",
"./src/**/__fixtures__",
"node_modules"
]
"exclude": ["dist", "node_modules"]
}
@@ -1,5 +0,0 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules", "dist"]
}