motia 0.7.3-beta.136 → 0.8.1-beta.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/create/templates/generate.js +2 -2
- package/dist/cjs/create/templates/generate.ts +2 -2
- package/dist/cjs/create/templates/nodejs/motia-workbench.json +5 -5
- package/dist/cjs/create/templates/nodejs/src/services/pet-store/create-order.ts.txt +15 -0
- package/dist/cjs/create/templates/nodejs/src/services/pet-store/create-pet.ts.txt +14 -0
- package/dist/cjs/create/templates/nodejs/src/services/pet-store/index.ts.txt +9 -0
- package/dist/{esm/create/templates/nodejs/steps → cjs/create/templates/nodejs/steps/petstore}/api.step.ts-features.json.txt +9 -9
- package/dist/{esm/create/templates/nodejs/steps → cjs/create/templates/nodejs/steps/petstore}/api.step.ts.txt +1 -2
- package/dist/{esm/create/templates/nodejs/steps → cjs/create/templates/nodejs/steps/petstore}/process-food-order.step.ts.txt +1 -1
- package/dist/cjs/create/templates/nodejs/tutorial.tsx.txt +40 -8
- package/dist/cjs/create/templates/python/motia-workbench.json +4 -4
- package/dist/cjs/create/templates/python/steps/{api_step.py.txt → petstore/api_step.py.txt} +2 -2
- package/dist/cjs/create/templates/python/steps/{process_food_order_step.py.txt → petstore/process_food_order_step.py.txt} +1 -1
- package/dist/cjs/create/templates/python/tutorial.tsx.txt +41 -9
- package/dist/cjs/cursor-rules/dot-files/.cursor/architecture/architecture.mdc +96 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/architecture/error-handling.mdc +122 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/index.mdc +34 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/api-steps.mdc +425 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/cron-steps.mdc +171 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/event-steps.mdc +218 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/middlewares.mdc +217 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/realtime-streaming.mdc +380 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/state-management.mdc +136 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/ui-steps.mdc +76 -0
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/motia/virtual-steps.mdc +251 -0
- package/dist/cjs/dev.js +0 -2
- package/dist/cjs/generate-locked-data.js +1 -1
- package/dist/cjs/generate-types.js +2 -2
- package/dist/cjs/start.js +0 -2
- package/dist/cjs/watcher.js +4 -4
- package/dist/esm/create/templates/generate.js +2 -2
- package/dist/esm/create/templates/generate.ts +2 -2
- package/dist/esm/create/templates/nodejs/motia-workbench.json +5 -5
- package/dist/esm/create/templates/nodejs/src/services/pet-store/create-order.ts.txt +15 -0
- package/dist/esm/create/templates/nodejs/src/services/pet-store/create-pet.ts.txt +14 -0
- package/dist/esm/create/templates/nodejs/src/services/pet-store/index.ts.txt +9 -0
- package/dist/{cjs/create/templates/nodejs/steps → esm/create/templates/nodejs/steps/petstore}/api.step.ts-features.json.txt +9 -9
- package/dist/{cjs/create/templates/nodejs/steps → esm/create/templates/nodejs/steps/petstore}/api.step.ts.txt +1 -2
- package/dist/{cjs/create/templates/nodejs/steps → esm/create/templates/nodejs/steps/petstore}/process-food-order.step.ts.txt +1 -1
- package/dist/esm/create/templates/nodejs/tutorial.tsx.txt +40 -8
- package/dist/esm/create/templates/python/motia-workbench.json +4 -4
- package/dist/esm/create/templates/python/src/__init__.py.txt +0 -0
- package/dist/esm/create/templates/python/src/services/__init__.py.txt +0 -0
- package/dist/esm/create/templates/python/steps/{api_step.py.txt → petstore/api_step.py.txt} +2 -2
- package/dist/esm/create/templates/python/steps/{process_food_order_step.py.txt → petstore/process_food_order_step.py.txt} +1 -1
- package/dist/esm/create/templates/python/tutorial.tsx.txt +41 -9
- package/dist/esm/cursor-rules/dot-files/.cursor/architecture/architecture.mdc +96 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/architecture/error-handling.mdc +122 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/index.mdc +34 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/api-steps.mdc +425 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/cron-steps.mdc +171 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/event-steps.mdc +218 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/middlewares.mdc +217 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/realtime-streaming.mdc +380 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/state-management.mdc +136 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/ui-steps.mdc +76 -0
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/motia/virtual-steps.mdc +251 -0
- package/dist/esm/dev.js +0 -2
- package/dist/esm/generate-locked-data.js +1 -1
- package/dist/esm/generate-types.js +2 -2
- package/dist/esm/start.js +0 -2
- package/dist/esm/watcher.js +4 -4
- package/package.json +4 -4
- package/dist/cjs/create/templates/nodejs/services/pet-store.ts.txt +0 -29
- package/dist/cjs/cursor-rules/dot-files/.claude/CLAUDE.md +0 -467
- package/dist/cjs/cursor-rules/dot-files/.claude/README.md +0 -97
- package/dist/cjs/cursor-rules/dot-files/.claude/agents/code-reviewer.md +0 -153
- package/dist/cjs/cursor-rules/dot-files/.claude/agents/debugger.md +0 -259
- package/dist/cjs/cursor-rules/dot-files/.claude/agents/test-runner.md +0 -268
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/add-authentication.md +0 -491
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/ai-ml-patterns.md +0 -748
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/authentication.md +0 -515
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/backend-types.md +0 -719
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/build-api.md +0 -407
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/claude-workflows.md +0 -1032
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/complete-backend.md +0 -345
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/create-api.md +0 -96
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/data-processing.md +0 -977
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/integrate-ai.md +0 -852
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/javascript-patterns.md +0 -678
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/multi-language-workflow.md +0 -756
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/multi-language.md +0 -141
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/process-background-jobs.md +0 -587
- package/dist/cjs/cursor-rules/dot-files/.claude/commands/process-events.md +0 -89
- package/dist/cjs/cursor-rules/dot-files/.claude/hooks/pre-commit.sh +0 -84
- package/dist/cjs/cursor-rules/dot-files/.claude/settings.json +0 -37
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/ai-agent-patterns.mdc +0 -725
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/api-design-patterns.mdc +0 -740
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/api-steps.mdc +0 -230
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/architecture.mdc +0 -189
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/authentication-patterns.mdc +0 -620
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/background-job-patterns.mdc +0 -628
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/complete-application-patterns.mdc +0 -433
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/complete-backend-generator.mdc +0 -415
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/cron-steps.mdc +0 -257
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/event-steps.mdc +0 -504
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/instructions.mdc +0 -15
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/multi-language-workflows.mdc +0 -1059
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/noop-steps.mdc +0 -57
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/production-deployment.mdc +0 -668
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/realtime-streaming.mdc +0 -656
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/state-management.mdc +0 -371
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/steps.mdc +0 -373
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/testing.mdc +0 -329
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/typescript.mdc +0 -409
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/ui-steps.mdc +0 -429
- package/dist/cjs/cursor-rules/dot-files/.cursor/rules/workflow-patterns.mdc +0 -938
- package/dist/cjs/cursor-rules/dot-files/AGENTS.md +0 -397
- package/dist/cjs/cursor-rules/dot-files/README.md +0 -58
- package/dist/cjs/dev/state-endpoints.d.ts +0 -2
- package/dist/cjs/dev/state-endpoints.js +0 -30
- package/dist/esm/create/templates/nodejs/services/pet-store.ts.txt +0 -29
- package/dist/esm/cursor-rules/dot-files/.claude/CLAUDE.md +0 -467
- package/dist/esm/cursor-rules/dot-files/.claude/README.md +0 -97
- package/dist/esm/cursor-rules/dot-files/.claude/agents/code-reviewer.md +0 -153
- package/dist/esm/cursor-rules/dot-files/.claude/agents/debugger.md +0 -259
- package/dist/esm/cursor-rules/dot-files/.claude/agents/test-runner.md +0 -268
- package/dist/esm/cursor-rules/dot-files/.claude/commands/add-authentication.md +0 -491
- package/dist/esm/cursor-rules/dot-files/.claude/commands/ai-ml-patterns.md +0 -748
- package/dist/esm/cursor-rules/dot-files/.claude/commands/authentication.md +0 -515
- package/dist/esm/cursor-rules/dot-files/.claude/commands/backend-types.md +0 -719
- package/dist/esm/cursor-rules/dot-files/.claude/commands/build-api.md +0 -407
- package/dist/esm/cursor-rules/dot-files/.claude/commands/claude-workflows.md +0 -1032
- package/dist/esm/cursor-rules/dot-files/.claude/commands/complete-backend.md +0 -345
- package/dist/esm/cursor-rules/dot-files/.claude/commands/create-api.md +0 -96
- package/dist/esm/cursor-rules/dot-files/.claude/commands/data-processing.md +0 -977
- package/dist/esm/cursor-rules/dot-files/.claude/commands/integrate-ai.md +0 -852
- package/dist/esm/cursor-rules/dot-files/.claude/commands/javascript-patterns.md +0 -678
- package/dist/esm/cursor-rules/dot-files/.claude/commands/multi-language-workflow.md +0 -756
- package/dist/esm/cursor-rules/dot-files/.claude/commands/multi-language.md +0 -141
- package/dist/esm/cursor-rules/dot-files/.claude/commands/process-background-jobs.md +0 -587
- package/dist/esm/cursor-rules/dot-files/.claude/commands/process-events.md +0 -89
- package/dist/esm/cursor-rules/dot-files/.claude/hooks/pre-commit.sh +0 -84
- package/dist/esm/cursor-rules/dot-files/.claude/settings.json +0 -37
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/ai-agent-patterns.mdc +0 -725
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/api-design-patterns.mdc +0 -740
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/api-steps.mdc +0 -230
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/architecture.mdc +0 -189
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/authentication-patterns.mdc +0 -620
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/background-job-patterns.mdc +0 -628
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/complete-application-patterns.mdc +0 -433
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/complete-backend-generator.mdc +0 -415
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/cron-steps.mdc +0 -257
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/event-steps.mdc +0 -504
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/instructions.mdc +0 -15
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/multi-language-workflows.mdc +0 -1059
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/noop-steps.mdc +0 -57
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/production-deployment.mdc +0 -668
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/realtime-streaming.mdc +0 -656
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/state-management.mdc +0 -371
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/steps.mdc +0 -373
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/testing.mdc +0 -329
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/typescript.mdc +0 -409
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/ui-steps.mdc +0 -429
- package/dist/esm/cursor-rules/dot-files/.cursor/rules/workflow-patterns.mdc +0 -938
- package/dist/esm/cursor-rules/dot-files/AGENTS.md +0 -397
- package/dist/esm/cursor-rules/dot-files/README.md +0 -58
- package/dist/esm/dev/state-endpoints.d.ts +0 -2
- package/dist/esm/dev/state-endpoints.js +0 -26
- package/dist/types/dev/state-endpoints.d.ts +0 -2
- /package/dist/cjs/create/templates/nodejs/{services → src/services/pet-store}/types.ts.txt +0 -0
- /package/dist/cjs/create/templates/nodejs/steps/{notification.step.ts.txt → petstore/notification.step.ts.txt} +0 -0
- /package/dist/cjs/create/templates/nodejs/steps/{process-food-order.step.ts-features.json.txt → petstore/process-food-order.step.ts-features.json.txt} +0 -0
- /package/dist/cjs/create/templates/nodejs/steps/{state-audit-cron.step.ts-features.json.txt → petstore/state-audit-cron.step.ts-features.json.txt} +0 -0
- /package/dist/cjs/create/templates/nodejs/steps/{state-audit-cron.step.ts.txt → petstore/state-audit-cron.step.ts.txt} +0 -0
- /package/dist/cjs/create/templates/python/{steps/services → src}/__init__.py.txt +0 -0
- /package/dist/{esm/create/templates/python/steps → cjs/create/templates/python/src}/services/__init__.py.txt +0 -0
- /package/dist/cjs/create/templates/python/{steps → src}/services/pet_store.py.txt +0 -0
- /package/dist/cjs/create/templates/python/{steps → src}/services/types.py.txt +0 -0
- /package/dist/cjs/create/templates/python/steps/{api_step.py-features.json.txt → petstore/api_step.py-features.json.txt} +0 -0
- /package/dist/cjs/create/templates/python/steps/{notification_step.py.txt → petstore/notification_step.py.txt} +0 -0
- /package/dist/cjs/create/templates/python/steps/{process_food_order_step.py-features.json.txt → petstore/process_food_order_step.py-features.json.txt} +0 -0
- /package/dist/cjs/create/templates/python/steps/{state_audit_cron_step.py-features.json.txt → petstore/state_audit_cron_step.py-features.json.txt} +0 -0
- /package/dist/cjs/create/templates/python/steps/{state_audit_cron_step.py.txt → petstore/state_audit_cron_step.py.txt} +0 -0
- /package/dist/esm/create/templates/nodejs/{services → src/services/pet-store}/types.ts.txt +0 -0
- /package/dist/esm/create/templates/nodejs/steps/{notification.step.ts.txt → petstore/notification.step.ts.txt} +0 -0
- /package/dist/esm/create/templates/nodejs/steps/{process-food-order.step.ts-features.json.txt → petstore/process-food-order.step.ts-features.json.txt} +0 -0
- /package/dist/esm/create/templates/nodejs/steps/{state-audit-cron.step.ts-features.json.txt → petstore/state-audit-cron.step.ts-features.json.txt} +0 -0
- /package/dist/esm/create/templates/nodejs/steps/{state-audit-cron.step.ts.txt → petstore/state-audit-cron.step.ts.txt} +0 -0
- /package/dist/esm/create/templates/python/{steps → src}/services/pet_store.py.txt +0 -0
- /package/dist/esm/create/templates/python/{steps → src}/services/types.py.txt +0 -0
- /package/dist/esm/create/templates/python/steps/{api_step.py-features.json.txt → petstore/api_step.py-features.json.txt} +0 -0
- /package/dist/esm/create/templates/python/steps/{notification_step.py.txt → petstore/notification_step.py.txt} +0 -0
- /package/dist/esm/create/templates/python/steps/{process_food_order_step.py-features.json.txt → petstore/process_food_order_step.py-features.json.txt} +0 -0
- /package/dist/esm/create/templates/python/steps/{state_audit_cron_step.py-features.json.txt → petstore/state_audit_cron_step.py-features.json.txt} +0 -0
- /package/dist/esm/create/templates/python/steps/{state_audit_cron_step.py.txt → petstore/state_audit_cron_step.py.txt} +0 -0
|
@@ -40,7 +40,7 @@ const glob_1 = require("glob");
|
|
|
40
40
|
const generateTemplateSteps = (templateFolder) => {
|
|
41
41
|
return async (rootDir, context) => {
|
|
42
42
|
const templatePath = path.join(__dirname, templateFolder);
|
|
43
|
-
const files = (0, glob_1.globSync)('**/*', { absolute: false, cwd: templatePath });
|
|
43
|
+
const files = (0, glob_1.globSync)('**/*', { absolute: false, cwd: templatePath, dot: true });
|
|
44
44
|
try {
|
|
45
45
|
for (const fileName of files) {
|
|
46
46
|
const filePath = path.join(templatePath, fileName);
|
|
@@ -54,7 +54,7 @@ const generateTemplateSteps = (templateFolder) => {
|
|
|
54
54
|
(0, fs_1.mkdirSync)(targetDir, { recursive: true });
|
|
55
55
|
}
|
|
56
56
|
if ((0, fs_1.statSync)(filePath).isDirectory()) {
|
|
57
|
-
const folderPath =
|
|
57
|
+
const folderPath = filePath.replace(templatePath, '');
|
|
58
58
|
(0, fs_1.mkdirSync)(path.join(rootDir, folderPath), { recursive: true });
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
@@ -8,7 +8,7 @@ export type Generator = (rootDir: string, context: CliContext) => Promise<void>
|
|
|
8
8
|
export const generateTemplateSteps = (templateFolder: string): Generator => {
|
|
9
9
|
return async (rootDir: string, context: CliContext): Promise<void> => {
|
|
10
10
|
const templatePath = path.join(__dirname, templateFolder)
|
|
11
|
-
const files = globSync('**/*', { absolute: false, cwd: templatePath })
|
|
11
|
+
const files = globSync('**/*', { absolute: false, cwd: templatePath, dot: true })
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
14
|
for (const fileName of files) {
|
|
@@ -24,7 +24,7 @@ export const generateTemplateSteps = (templateFolder: string): Generator => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (statSync(filePath).isDirectory()) {
|
|
27
|
-
const folderPath =
|
|
27
|
+
const folderPath = filePath.replace(templatePath, '')
|
|
28
28
|
mkdirSync(path.join(rootDir, folderPath), { recursive: true })
|
|
29
29
|
continue
|
|
30
30
|
}
|
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
{
|
|
3
3
|
"id": "basic-tutorial",
|
|
4
4
|
"config": {
|
|
5
|
-
"steps/state-audit-cron.step.ts": {
|
|
5
|
+
"steps/petstore/state-audit-cron.step.ts": {
|
|
6
6
|
"x": -165,
|
|
7
7
|
"y": 217,
|
|
8
8
|
"sourceHandlePosition": "right"
|
|
9
9
|
},
|
|
10
|
-
"steps/process-food-order.step.ts": {
|
|
10
|
+
"steps/petstore/process-food-order.step.ts": {
|
|
11
11
|
"x": 211,
|
|
12
12
|
"y": 17,
|
|
13
13
|
"sourceHandlePosition": "bottom",
|
|
14
14
|
"targetHandlePosition": "left"
|
|
15
15
|
},
|
|
16
|
-
"steps/api.step.ts": {
|
|
16
|
+
"steps/petstore/api.step.ts": {
|
|
17
17
|
"x": -100,
|
|
18
18
|
"y": 3,
|
|
19
19
|
"sourceHandlePosition": "right",
|
|
20
20
|
"targetHandlePosition": "left"
|
|
21
21
|
},
|
|
22
|
-
"steps/notification.step.ts": {
|
|
22
|
+
"steps/petstore/notification.step.ts": {
|
|
23
23
|
"x": 300,
|
|
24
24
|
"y": 264
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
]
|
|
28
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Order } from './types'
|
|
2
|
+
|
|
3
|
+
export const createOrder = async (order: Omit<Order, 'id'>): Promise<Order> => {
|
|
4
|
+
const response = await fetch('https://petstore.swagger.io/v2/store/order', {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
body: JSON.stringify({
|
|
7
|
+
quantity: order?.quantity ?? 1,
|
|
8
|
+
petId: 1,
|
|
9
|
+
shipDate: order?.shipDate ?? new Date().toISOString(),
|
|
10
|
+
status: order?.status ?? 'placed',
|
|
11
|
+
}),
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
})
|
|
14
|
+
return response.json()
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Pet } from './types'
|
|
2
|
+
|
|
3
|
+
export const createPet = async (pet: Omit<Pet, 'id'>): Promise<Pet> => {
|
|
4
|
+
const response = await fetch('https://petstore.swagger.io/v2/pet', {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
body: JSON.stringify({
|
|
7
|
+
name: pet?.name ?? '',
|
|
8
|
+
photoUrls: [pet?.photoUrl ?? ''],
|
|
9
|
+
status: 'available',
|
|
10
|
+
}),
|
|
11
|
+
headers: { 'Content-Type': 'application/json' },
|
|
12
|
+
})
|
|
13
|
+
return response.json()
|
|
14
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"title": "Step Configuration",
|
|
5
5
|
"description": "All steps should have a defined configuration, this is how you define the step's behavior and how it will be triggered.",
|
|
6
6
|
"lines": [
|
|
7
|
-
"
|
|
7
|
+
"5-29"
|
|
8
8
|
]
|
|
9
9
|
},
|
|
10
10
|
{
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"title": "API Step",
|
|
13
13
|
"description": "Definition of an API endpoint",
|
|
14
14
|
"lines": [
|
|
15
|
-
"12
|
|
15
|
+
"11-12"
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
{
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"title": "Request body",
|
|
21
21
|
"description": "Definition of the expected request body. Motia will automatically generate types based on this schema.",
|
|
22
22
|
"lines": [
|
|
23
|
-
"
|
|
23
|
+
"13-24"
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
{
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"title": "Response Payload",
|
|
29
29
|
"description": "Definition of the expected response payload, Motia will generate the types automatically based on this schema. This is also important to create the Open API spec later.",
|
|
30
30
|
"lines": [
|
|
31
|
-
"
|
|
31
|
+
"25-27"
|
|
32
32
|
]
|
|
33
33
|
},
|
|
34
34
|
{
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"title": "Emits",
|
|
37
37
|
"description": "We can define the events that this step will emit, this is how we can trigger other Motia Steps.",
|
|
38
38
|
"lines": [
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"28",
|
|
40
|
+
"38-45"
|
|
41
41
|
]
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"title": "Handler",
|
|
46
46
|
"description": "The handler is the function that will be executed when the step is triggered. This one receives the request body and emits events.",
|
|
47
47
|
"lines": [
|
|
48
|
-
"
|
|
48
|
+
"31-49"
|
|
49
49
|
]
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"title": "Logger",
|
|
54
54
|
"description": "The logger is a utility that allows you to log messages to the console. It is available in the handler function. We encourage you to use it instead of console.log. It will automatically be tied to the trace id of the request.",
|
|
55
55
|
"lines": [
|
|
56
|
-
"
|
|
56
|
+
"32"
|
|
57
57
|
]
|
|
58
58
|
},
|
|
59
59
|
{
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"title": "HTTP Response",
|
|
62
62
|
"description": "The handler can return a response to the client. This is how we can return a response to the client. It must comply with the responseSchema defined in the step configuration.",
|
|
63
63
|
"lines": [
|
|
64
|
-
"
|
|
64
|
+
"48"
|
|
65
65
|
]
|
|
66
66
|
}
|
|
67
67
|
]
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ApiRouteConfig, Handlers } from 'motia'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
-
import { petStoreService } from '
|
|
4
|
-
import { petSchema } from '../services/types'
|
|
3
|
+
import { petStoreService, petSchema } from '../../src/services/pet-store'
|
|
5
4
|
|
|
6
5
|
export const config: ApiRouteConfig = {
|
|
7
6
|
type: 'api',
|
|
@@ -371,25 +371,35 @@ export const steps: TutorialStep[] = [
|
|
|
371
371
|
before: [{ type: 'click', selector: workbenchXPath.closePanelButton }],
|
|
372
372
|
},
|
|
373
373
|
{
|
|
374
|
-
elementXpath: workbenchXPath.endpoints.
|
|
374
|
+
elementXpath: workbenchXPath.endpoints.endpointsList,
|
|
375
375
|
title: 'Endpoints Tool',
|
|
376
376
|
description: () => (
|
|
377
377
|
<p>
|
|
378
378
|
This section will display all of the endpoints declared in your API Steps. It will list the HTTP method, the URL
|
|
379
379
|
path, and the description declared in the Step configuration.
|
|
380
|
-
<br />
|
|
381
|
-
<br />
|
|
382
|
-
💡 Clicking on an endpoint from the list will open the endpoint overview which provides documentation on how to
|
|
383
|
-
use the endpoint and a tool to test the endpoint.
|
|
384
380
|
</p>
|
|
385
381
|
),
|
|
386
382
|
before: [{ type: 'click', selector: workbenchXPath.links.endpoints }],
|
|
387
383
|
},
|
|
388
384
|
{
|
|
389
|
-
elementXpath: workbenchXPath.
|
|
390
|
-
title: '
|
|
385
|
+
elementXpath: workbenchXPath.endpoints.endpoint('POST', '/basic-tutorial'),
|
|
386
|
+
title: 'Endpoints Tool',
|
|
391
387
|
description: () => (
|
|
392
388
|
<p>
|
|
389
|
+
Clicking on an endpoint from the list will open the endpoint overview which provides documentation on how to use
|
|
390
|
+
the endpoint and a tool to test the endpoint.
|
|
391
|
+
</p>
|
|
392
|
+
),
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
elementXpath: workbenchXPath.endpoints.callPanel,
|
|
396
|
+
title: 'API Endpoint Playground',
|
|
397
|
+
description: () => (
|
|
398
|
+
<p>
|
|
399
|
+
Once you click on an endpoint from the list, you will be able to test it by providing a request payload and
|
|
400
|
+
clicking on the <b>Play</b> button.
|
|
401
|
+
<br />
|
|
402
|
+
<br />
|
|
393
403
|
This section will provide an overview of your API endpoint.
|
|
394
404
|
<br />
|
|
395
405
|
<br />
|
|
@@ -399,6 +409,25 @@ export const steps: TutorialStep[] = [
|
|
|
399
409
|
),
|
|
400
410
|
before: [{ type: 'click', selector: workbenchXPath.endpoints.endpoint('POST', '/basic-tutorial') }],
|
|
401
411
|
},
|
|
412
|
+
{
|
|
413
|
+
elementXpath: workbenchXPath.endpoints.specButton,
|
|
414
|
+
title: 'API Endpoint Specification',
|
|
415
|
+
description: () => (
|
|
416
|
+
<p>
|
|
417
|
+
Clicking on this button will open the specification of your API endpoint. Like response and request schemas.
|
|
418
|
+
</p>
|
|
419
|
+
),
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
423
|
+
title: 'API Endpoint Specification',
|
|
424
|
+
description: () => (
|
|
425
|
+
<p>
|
|
426
|
+
This is what you see when clicking on the <b>Details</b> button.
|
|
427
|
+
</p>
|
|
428
|
+
),
|
|
429
|
+
before: [{ type: 'click', selector: workbenchXPath.endpoints.specButton }],
|
|
430
|
+
},
|
|
402
431
|
{
|
|
403
432
|
elementXpath: workbenchXPath.endpoints.callPanel,
|
|
404
433
|
title: 'API Endpoint Test',
|
|
@@ -428,7 +457,10 @@ export const steps: TutorialStep[] = [
|
|
|
428
457
|
</pre>
|
|
429
458
|
</p>
|
|
430
459
|
),
|
|
431
|
-
before: [
|
|
460
|
+
before: [
|
|
461
|
+
{ type: 'click', selector: workbenchXPath.closePanelButton },
|
|
462
|
+
{ type: 'click', selector: workbenchXPath.endpoints.bodyTab },
|
|
463
|
+
],
|
|
432
464
|
},
|
|
433
465
|
{
|
|
434
466
|
elementXpath: workbenchXPath.endpoints.playButton,
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
{
|
|
3
3
|
"id": "basic-tutorial",
|
|
4
4
|
"config": {
|
|
5
|
-
"steps/state_audit_cron_step.py": {
|
|
5
|
+
"steps/petstore/state_audit_cron_step.py": {
|
|
6
6
|
"x": -38,
|
|
7
7
|
"y": 683,
|
|
8
8
|
"sourceHandlePosition": "right"
|
|
9
9
|
},
|
|
10
|
-
"steps/process_food_order_step.py": {
|
|
10
|
+
"steps/petstore/process_food_order_step.py": {
|
|
11
11
|
"x": 384,
|
|
12
12
|
"y": 476,
|
|
13
13
|
"targetHandlePosition": "left"
|
|
14
14
|
},
|
|
15
|
-
"steps/notification_step.py": {
|
|
15
|
+
"steps/petstore/notification_step.py": {
|
|
16
16
|
"x": 601,
|
|
17
17
|
"y": 724,
|
|
18
18
|
"targetHandlePosition": "left"
|
|
19
19
|
},
|
|
20
|
-
"steps/api_step.py": {
|
|
20
|
+
"steps/petstore/api_step.py": {
|
|
21
21
|
"x": 15,
|
|
22
22
|
"y": 461,
|
|
23
23
|
"sourceHandlePosition": "right"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from pydantic import BaseModel
|
|
2
2
|
from typing import Optional
|
|
3
|
-
from .services.pet_store import pet_store_service
|
|
4
|
-
from .services.types import Pet
|
|
3
|
+
from src.services.pet_store import pet_store_service
|
|
4
|
+
from src.services.types import Pet
|
|
5
5
|
|
|
6
6
|
class PetRequest(BaseModel):
|
|
7
7
|
name: str
|
|
@@ -360,7 +360,7 @@ export const steps: TutorialStep[] = [
|
|
|
360
360
|
title: 'Endpoints',
|
|
361
361
|
description: () => (
|
|
362
362
|
<p>
|
|
363
|
-
Now that we've looked at Motia
|
|
363
|
+
Now that we've looked at Motia primitives, let's trigger the API Step from the <b>endpoints</b> section in
|
|
364
364
|
Workbench.
|
|
365
365
|
<br />
|
|
366
366
|
<br />
|
|
@@ -371,25 +371,35 @@ export const steps: TutorialStep[] = [
|
|
|
371
371
|
before: [{ type: 'click', selector: workbenchXPath.closePanelButton }],
|
|
372
372
|
},
|
|
373
373
|
{
|
|
374
|
-
elementXpath: workbenchXPath.endpoints.
|
|
374
|
+
elementXpath: workbenchXPath.endpoints.endpointsList,
|
|
375
375
|
title: 'Endpoints Tool',
|
|
376
376
|
description: () => (
|
|
377
377
|
<p>
|
|
378
378
|
This section will display all of the endpoints declared in your API Steps. It will list the HTTP method, the URL
|
|
379
379
|
path, and the description declared in the Step configuration.
|
|
380
|
-
<br />
|
|
381
|
-
<br />
|
|
382
|
-
💡 Clicking on an endpoint from the list will open the endpoint overview which provides documentation on how to
|
|
383
|
-
use the endpoint and a tool to test the endpoint.
|
|
384
380
|
</p>
|
|
385
381
|
),
|
|
386
382
|
before: [{ type: 'click', selector: workbenchXPath.links.endpoints }],
|
|
387
383
|
},
|
|
388
384
|
{
|
|
389
|
-
elementXpath: workbenchXPath.
|
|
390
|
-
title: '
|
|
385
|
+
elementXpath: workbenchXPath.endpoints.endpoint('POST', '/basic-tutorial'),
|
|
386
|
+
title: 'Endpoints Tool',
|
|
391
387
|
description: () => (
|
|
392
388
|
<p>
|
|
389
|
+
Clicking on an endpoint from the list will open the endpoint overview which provides documentation on how to use
|
|
390
|
+
the endpoint and a tool to test the endpoint.
|
|
391
|
+
</p>
|
|
392
|
+
),
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
elementXpath: workbenchXPath.endpoints.callPanel,
|
|
396
|
+
title: 'API Endpoint Playground',
|
|
397
|
+
description: () => (
|
|
398
|
+
<p>
|
|
399
|
+
Once you click on an endpoint from the list, you will be able to test it by providing a request payload and
|
|
400
|
+
clicking on the <b>Play</b> button.
|
|
401
|
+
<br />
|
|
402
|
+
<br />
|
|
393
403
|
This section will provide an overview of your API endpoint.
|
|
394
404
|
<br />
|
|
395
405
|
<br />
|
|
@@ -399,6 +409,25 @@ export const steps: TutorialStep[] = [
|
|
|
399
409
|
),
|
|
400
410
|
before: [{ type: 'click', selector: workbenchXPath.endpoints.endpoint('POST', '/basic-tutorial') }],
|
|
401
411
|
},
|
|
412
|
+
{
|
|
413
|
+
elementXpath: workbenchXPath.endpoints.specButton,
|
|
414
|
+
title: 'API Endpoint Specification',
|
|
415
|
+
description: () => (
|
|
416
|
+
<p>
|
|
417
|
+
Clicking on this button will open the specification of your API endpoint. Like response and request schemas.
|
|
418
|
+
</p>
|
|
419
|
+
),
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
elementXpath: workbenchXPath.sidebarContainer,
|
|
423
|
+
title: 'API Endpoint Specification',
|
|
424
|
+
description: () => (
|
|
425
|
+
<p>
|
|
426
|
+
This is what you see when clicking on the <b>Details</b> button.
|
|
427
|
+
</p>
|
|
428
|
+
),
|
|
429
|
+
before: [{ type: 'click', selector: workbenchXPath.endpoints.specButton }],
|
|
430
|
+
},
|
|
402
431
|
{
|
|
403
432
|
elementXpath: workbenchXPath.endpoints.callPanel,
|
|
404
433
|
title: 'API Endpoint Test',
|
|
@@ -428,7 +457,10 @@ export const steps: TutorialStep[] = [
|
|
|
428
457
|
</pre>
|
|
429
458
|
</p>
|
|
430
459
|
),
|
|
431
|
-
before: [
|
|
460
|
+
before: [
|
|
461
|
+
{ type: 'click', selector: workbenchXPath.closePanelButton },
|
|
462
|
+
{ type: 'click', selector: workbenchXPath.endpoints.bodyTab },
|
|
463
|
+
],
|
|
432
464
|
},
|
|
433
465
|
{
|
|
434
466
|
elementXpath: workbenchXPath.endpoints.playButton,
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: How to structure your Motia project
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Architecture Guide
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This guide covers the architecture of a Motia project.
|
|
12
|
+
|
|
13
|
+
## File Structure
|
|
14
|
+
|
|
15
|
+
All step files should be underneath the `steps/` folder.
|
|
16
|
+
|
|
17
|
+
Underneath the `steps/` folder, create subfolders for Flows. Flows are used to group steps together.
|
|
18
|
+
|
|
19
|
+
## Step Naming Conventions
|
|
20
|
+
|
|
21
|
+
### Typescript
|
|
22
|
+
|
|
23
|
+
- Use kebab-case for filenames: `resource-processing.step.ts`
|
|
24
|
+
- Include `.step` before language extension
|
|
25
|
+
|
|
26
|
+
### Python
|
|
27
|
+
|
|
28
|
+
- Use snake_case for filenames: `data_processor_step.py`
|
|
29
|
+
- Include `_step` before language extension
|
|
30
|
+
|
|
31
|
+
### Global
|
|
32
|
+
|
|
33
|
+
- Match handler names to config names
|
|
34
|
+
- Use descriptive, action-oriented names
|
|
35
|
+
|
|
36
|
+
## Code Style Guidelines
|
|
37
|
+
|
|
38
|
+
- **JavaScript**: Use modern ES6+ features, async/await, proper error handling
|
|
39
|
+
- **TypeScript**: Make sure you use the correct Handlers type that is auto generated on the `types.d.ts` file.
|
|
40
|
+
|
|
41
|
+
## Defining Middlewares
|
|
42
|
+
|
|
43
|
+
Middleware is a powerful feature in Motia to help adding common validation, error
|
|
44
|
+
handling and other common logic to your steps.
|
|
45
|
+
|
|
46
|
+
- Make sure to add all the middlewares in a single folder, called `middlewares/`.
|
|
47
|
+
- Create a comprehensive file name for the middleware, like `auth.middleware.ts`.
|
|
48
|
+
- Follow SOLID principles with separation of concerns in middlewares, create a middleware for each responsibility.
|
|
49
|
+
- Use core middleware to handle ZodError gracefully (see [Error Handling Guide](./error-handling.mdc))
|
|
50
|
+
- Rate limiting and CORS are not needed to be handled in middleware since they're an infrastructure concern.
|
|
51
|
+
|
|
52
|
+
## Domain Driven Design
|
|
53
|
+
|
|
54
|
+
Make sure you follow Domain Driven Design principles in your project.
|
|
55
|
+
|
|
56
|
+
- Create `/src/services` folder to store your services, this is where it holds business logic.
|
|
57
|
+
- Create `/src/repositories` folder to store your repositories, this is where it holds data access logic.
|
|
58
|
+
- Create `/src/utils` folder to store your utility functions.
|
|
59
|
+
- Models and DTOs are not quite necessary, we can rely on zod to create the models and DTOs from the steps.
|
|
60
|
+
- Controller layer is the Steps, it should have mostly logic around validation and calling services.
|
|
61
|
+
- Avoid having Service methods with just a call to the Repository, it should have some logic around it, if it doesn't have, then Steps can have access to repositories directly.
|
|
62
|
+
|
|
63
|
+
### Services
|
|
64
|
+
|
|
65
|
+
Defining services can be done in the following way:
|
|
66
|
+
|
|
67
|
+
- Create a folder underneath `/src/services/` folder, like `/src/services/auth/`.
|
|
68
|
+
- Create a file inside the folder called `index.ts`.
|
|
69
|
+
- Inside `index.ts`, export a constant with the name of the service, with the methods as properties.
|
|
70
|
+
- Methods should be defined as separate files, use export named functions.
|
|
71
|
+
- Use the service in the Steps.
|
|
72
|
+
|
|
73
|
+
#### Example
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
/**
|
|
77
|
+
* Business logic for authentication defined in a separate file in the same folder.
|
|
78
|
+
*/
|
|
79
|
+
import { login } from './login'
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Constant with the name of the service, with the methods as properties.
|
|
83
|
+
*/
|
|
84
|
+
export const authService = {
|
|
85
|
+
login
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Logging and observability
|
|
90
|
+
|
|
91
|
+
- Make sure to use the Logger from Motia (from context object) to log messages.
|
|
92
|
+
- Make sure to have visibility of what is going on in a request
|
|
93
|
+
- Before throwing errors, make sure to log the issue, identify if issue is a validation blocker, then log with `logger.warn`, if it's something that is not supposed to happen, then log with `logger.error`.
|
|
94
|
+
- Make sure to add context to the logs to help identify any potential issues.
|
|
95
|
+
|
|
96
|
+
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: How to handle errors in a Motia project
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Error Handling Guide
|
|
8
|
+
|
|
9
|
+
Errors happen, but we need to handle them gracefully. Make sure you create a custom error class for your project, underneath `/src/errors/` folder.
|
|
10
|
+
|
|
11
|
+
## Good practices
|
|
12
|
+
|
|
13
|
+
- Use Custom error to return errors to the client.
|
|
14
|
+
- Anything that is not the error class, should be logged with `logger.error`. And root cause should be omitted to the client.
|
|
15
|
+
|
|
16
|
+
## Create a custom Error class
|
|
17
|
+
|
|
18
|
+
Name: `/src/errors/base.error.ts`
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
export class BaseError extends Error {
|
|
22
|
+
public readonly status: number
|
|
23
|
+
public readonly code: string
|
|
24
|
+
public readonly metadata: Record<string, any>
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
message: string,
|
|
28
|
+
status: number = 500,
|
|
29
|
+
code: string = 'INTERNAL_SERVER_ERROR',
|
|
30
|
+
metadata: Record<string, any> = {}
|
|
31
|
+
) {
|
|
32
|
+
super(message)
|
|
33
|
+
this.name = this.constructor.name
|
|
34
|
+
this.status = status
|
|
35
|
+
this.code = code
|
|
36
|
+
this.metadata = metadata
|
|
37
|
+
|
|
38
|
+
// Maintains proper stack trace for where our error was thrown
|
|
39
|
+
Error.captureStackTrace(this, this.constructor)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
toJSON() {
|
|
43
|
+
return {
|
|
44
|
+
error: {
|
|
45
|
+
name: this.name,
|
|
46
|
+
message: this.message,
|
|
47
|
+
code: this.code,
|
|
48
|
+
status: this.status,
|
|
49
|
+
...(Object.keys(this.metadata).length > 0 && { metadata: this.metadata }),
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then create sub class for specific errors that are commonly thrown in your project.
|
|
57
|
+
|
|
58
|
+
Name: `/src/errors/not-found.error.ts`
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { BaseError } from './base.error'
|
|
62
|
+
|
|
63
|
+
export class NotFoundError extends BaseError {
|
|
64
|
+
constructor(message: string = 'Not Found', metadata: Record<string, any> = {}) {
|
|
65
|
+
super(message, 404, 'NOT_FOUND', metadata)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Core Middleware
|
|
71
|
+
|
|
72
|
+
Make sure you create a core middleware that will be added to ALL API Steps.
|
|
73
|
+
|
|
74
|
+
File: `/src/middlewares/core.middleware.ts`
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { ApiMiddleware } from 'motia'
|
|
78
|
+
import { ZodError } from 'zod'
|
|
79
|
+
import { BaseError } from '../errors/base.error'
|
|
80
|
+
|
|
81
|
+
export const coreMiddleware: ApiMiddleware = async (req, ctx, next) => {
|
|
82
|
+
const logger = ctx.logger
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
return await next()
|
|
86
|
+
} catch (error: any) {
|
|
87
|
+
if (error instanceof ZodError) {
|
|
88
|
+
logger.error('Validation error', {
|
|
89
|
+
error,
|
|
90
|
+
stack: error.stack,
|
|
91
|
+
errors: error.errors,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
status: 400,
|
|
96
|
+
body: {
|
|
97
|
+
error: 'Invalid request body',
|
|
98
|
+
data: error.errors,
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
} else if (error instanceof BaseError) {
|
|
102
|
+
logger.error('BaseError', {
|
|
103
|
+
status: error.status,
|
|
104
|
+
code: error.code,
|
|
105
|
+
metadata: error.metadata,
|
|
106
|
+
name: error.name,
|
|
107
|
+
message: error.message,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return { status: error.status, body: error.toJSON() }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
logger.error('Error while performing request', {
|
|
114
|
+
error,
|
|
115
|
+
body: req.body,
|
|
116
|
+
stack: error.stack,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return { status: 500, body: { error: 'Internal Server Error' } }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Rules for the project
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Real time events
|
|
8
|
+
|
|
9
|
+
Make sure to use [real time events guide](./rules/motia/realtime-streaming.mdc) to create a new real time event.
|
|
10
|
+
|
|
11
|
+
## State/Cache management
|
|
12
|
+
|
|
13
|
+
Make sure to use [state management guide](./rules/motia/state-management.mdc) to create a new state management.
|
|
14
|
+
|
|
15
|
+
## Creating HTTP Endpoints
|
|
16
|
+
|
|
17
|
+
Make sure to use [API steps guide](./rules/motia/api-steps.mdc) to create new HTTP endpoints.
|
|
18
|
+
|
|
19
|
+
## Background Tasks
|
|
20
|
+
|
|
21
|
+
Make sure to use [event steps guide](./rules/motia/event-steps.mdc) to create new background tasks.
|
|
22
|
+
|
|
23
|
+
## Scheduled Tasks
|
|
24
|
+
|
|
25
|
+
Make sure to use [cron steps guide](./rules/motia/cron-steps.mdc) to create new scheduled tasks.
|
|
26
|
+
|
|
27
|
+
## Virtual Steps & Flow Visualization
|
|
28
|
+
|
|
29
|
+
Make sure to use [virtual steps guide](./rules/motia/virtual-steps.mdc) when connecting nodes virtually and creating smooth flows in Workbench.
|
|
30
|
+
|
|
31
|
+
## Authentication
|
|
32
|
+
|
|
33
|
+
If ever need to add authentication, make sure to use middleware to authenticate the request.
|
|
34
|
+
Make sure to use [middlewares](./rules/motia/middlewares.mdc) to validate the requests.
|