@motiadev/core 0.1.0-beta.2 → 0.1.0-beta.5
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.
|
@@ -8,13 +8,16 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const flowsConfigEndpoint = (app, baseDir) => {
|
|
10
10
|
const configPath = path_1.default.join(baseDir, 'motia-workbench.json');
|
|
11
|
+
const getConfig = () => {
|
|
12
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
13
|
+
return JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
return {};
|
|
16
|
+
};
|
|
11
17
|
app.post('/flows/:id/config', (req, res) => {
|
|
12
18
|
const newFlowConfig = req.body;
|
|
13
19
|
try {
|
|
14
|
-
|
|
15
|
-
fs_1.default.writeFileSync(configPath, JSON.stringify({}, null, 2));
|
|
16
|
-
}
|
|
17
|
-
const existingConfig = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
20
|
+
const existingConfig = getConfig();
|
|
18
21
|
const updatedConfig = {
|
|
19
22
|
...existingConfig,
|
|
20
23
|
};
|
|
@@ -28,21 +31,20 @@ const flowsConfigEndpoint = (app, baseDir) => {
|
|
|
28
31
|
res.status(200).send({ message: 'Flow config saved successfully' });
|
|
29
32
|
}
|
|
30
33
|
catch (error) {
|
|
31
|
-
console.error('Error saving flow config:', error);
|
|
34
|
+
console.error('Error saving flow config:', error.message);
|
|
32
35
|
res.status(500).json({ error: 'Failed to save flow config' });
|
|
33
36
|
}
|
|
34
37
|
});
|
|
35
38
|
app.get('/flows/:id/config', (req, res) => {
|
|
36
39
|
const { id } = req.params;
|
|
37
40
|
try {
|
|
38
|
-
const
|
|
39
|
-
const allFlowsConfig = JSON.parse(file);
|
|
41
|
+
const allFlowsConfig = getConfig();
|
|
40
42
|
const flowConfig = allFlowsConfig[id] || {};
|
|
41
43
|
res.status(200).send(flowConfig);
|
|
42
44
|
}
|
|
43
45
|
catch (error) {
|
|
44
|
-
console.error('Error reading flow config:', error);
|
|
45
|
-
res.status(400).send({});
|
|
46
|
+
console.error('Error reading flow config:', error.message);
|
|
47
|
+
res.status(400).send({ error: 'Failed to read flow config' });
|
|
46
48
|
}
|
|
47
49
|
});
|
|
48
50
|
};
|
|
@@ -65,6 +65,7 @@ const eventSchema = zod_1.z
|
|
|
65
65
|
virtualEmits: emits.optional(),
|
|
66
66
|
input: zod_1.z.union([jsonSchema, zod_1.z.null()]).optional(),
|
|
67
67
|
flows: zod_1.z.array(zod_1.z.string()).optional(),
|
|
68
|
+
includeFiles: zod_1.z.array(zod_1.z.string()).optional(),
|
|
68
69
|
})
|
|
69
70
|
.strict();
|
|
70
71
|
const apiSchema = zod_1.z
|
|
@@ -79,6 +80,7 @@ const apiSchema = zod_1.z
|
|
|
79
80
|
virtualSubscribes: zod_1.z.array(zod_1.z.string()).optional(),
|
|
80
81
|
flows: zod_1.z.array(zod_1.z.string()).optional(),
|
|
81
82
|
bodySchema: zod_1.z.union([jsonSchema, zod_1.z.null()]).optional(),
|
|
83
|
+
includeFiles: zod_1.z.array(zod_1.z.string()).optional(),
|
|
82
84
|
})
|
|
83
85
|
.strict();
|
|
84
86
|
const cronSchema = zod_1.z
|
|
@@ -90,6 +92,7 @@ const cronSchema = zod_1.z
|
|
|
90
92
|
virtualEmits: emits.optional(),
|
|
91
93
|
emits: emits,
|
|
92
94
|
flows: zod_1.z.array(zod_1.z.string()).optional(),
|
|
95
|
+
includeFiles: zod_1.z.array(zod_1.z.string()).optional(),
|
|
93
96
|
})
|
|
94
97
|
.strict();
|
|
95
98
|
const validateStep = (step) => {
|
package/dist/src/types.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export type EventConfig<TInput extends ZodObject<any> = any> = {
|
|
|
32
32
|
virtualEmits?: Emit[];
|
|
33
33
|
input: TInput;
|
|
34
34
|
flows?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Files to include in the step bundle.
|
|
37
|
+
* Needs to be relative to the step file.
|
|
38
|
+
*/
|
|
39
|
+
includeFiles?: string[];
|
|
35
40
|
};
|
|
36
41
|
export type NoopConfig = {
|
|
37
42
|
type: 'noop';
|
|
@@ -53,6 +58,11 @@ export type ApiRouteConfig = {
|
|
|
53
58
|
virtualSubscribes?: string[];
|
|
54
59
|
flows?: string[];
|
|
55
60
|
bodySchema?: ZodObject<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Files to include in the step bundle.
|
|
63
|
+
* Needs to be relative to the step file.
|
|
64
|
+
*/
|
|
65
|
+
includeFiles?: string[];
|
|
56
66
|
};
|
|
57
67
|
export type ApiRequest = {
|
|
58
68
|
pathParams: Record<string, string>;
|
|
@@ -74,6 +84,11 @@ export type CronConfig = {
|
|
|
74
84
|
virtualEmits?: Emit[];
|
|
75
85
|
emits: Emit[];
|
|
76
86
|
flows?: string[];
|
|
87
|
+
/**
|
|
88
|
+
* Files to include in the step bundle.
|
|
89
|
+
* Needs to be relative to the step file.
|
|
90
|
+
*/
|
|
91
|
+
includeFiles?: string[];
|
|
77
92
|
};
|
|
78
93
|
export type CronHandler = (ctx: FlowContext) => Promise<void>;
|
|
79
94
|
export type StepHandler<T> = T extends EventConfig<any> ? EventHandler<T['input']> : T extends ApiRouteConfig ? ApiRouteHandler : T extends CronConfig ? CronHandler : never;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@motiadev/core",
|
|
3
3
|
"description": "Core functionality for the Motia framework, providing the foundation for building event-driven workflows.",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
-
"version": "0.1.0-beta.
|
|
5
|
+
"version": "0.1.0-beta.5",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"body-parser": "^1.20.3",
|
|
8
8
|
"colors": "^1.4.0",
|