@adminide-stack/form-builder-core 5.1.4-alpha.47 → 5.1.4-alpha.49
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/CHANGELOG.md +8 -0
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -0
- package/lib/inngest/generateFunctionCode.js +67 -77
- package/lib/inngest/generateFunctionCode.js.map +1 -0
- package/lib/inngest/stepGenerator.js +148 -160
- package/lib/inngest/stepGenerator.js.map +1 -0
- package/package.json +12 -4
- package/rollup.config.mjs +33 -0
- package/lib/inngest/interfaces/index.js +0 -1
- package/lib/inngest/interfaces/types.js +0 -1
- package/lib/inngest/types.d.ts +0 -47
- package/lib/inngest/types.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.1.4-alpha.49](https://github.com/CDEBase/forms-stack/compare/v5.1.4-alpha.48...v5.1.4-alpha.49) (2025-09-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @adminide-stack/form-builder-core
|
|
9
|
+
|
|
10
|
+
## [5.1.4-alpha.48](https://github.com/CDEBase/forms-stack/compare/v5.1.4-alpha.47...v5.1.4-alpha.48) (2025-09-23)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @adminide-stack/form-builder-core
|
|
13
|
+
|
|
6
14
|
## [5.1.4-alpha.47](https://github.com/CDEBase/forms-stack/compare/v5.1.4-alpha.46...v5.1.4-alpha.47) (2025-09-23)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @adminide-stack/form-builder-core
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './inngest/generateFunctionCode';
|
|
3
|
-
export { generateFromExtractedFunctions } from './inngest/stepGenerator';
|
|
1
|
+
export{generateFunctionCode,generateHandlerBody,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction}from'./inngest/generateFunctionCode.js';export{cleanStepCode,extractStepVarName,generateFromExtractedFunctions}from'./inngest/stepGenerator.js';//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// Re-export utilities for backward compatibility
|
|
3
|
-
export { cleanStepCode, extractStepVarName } from './stepGenerator';
|
|
4
|
-
// Check if code contains direct step operations (sleep, sendEvent, etc)
|
|
1
|
+
import {generateFromExtractedFunctions,extractStepVarName,extractFunctionBody,cleanStepCode}from'./stepGenerator.js';// Check if code contains direct step operations (sleep, sendEvent, etc)
|
|
5
2
|
function hasDirectStepOperations(code) {
|
|
6
|
-
|
|
3
|
+
return /step\.(sleep|sendEvent|waitForEvent|run)\s*\(/.test(code);
|
|
7
4
|
}
|
|
8
5
|
function getDefaultDirectBody(type, id, label) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'sleep':
|
|
8
|
+
return `const ${id}_result = await step.sleep('${id}', '5s');`;
|
|
9
|
+
case 'sendEvent':
|
|
10
|
+
return `const ${id}_result = await step.sendEvent('${id}', { name: 'my.custom.event', data: { source: '${label || id}', ts: new Date().toISOString() } });`;
|
|
11
|
+
case 'waitForEvent':
|
|
12
|
+
return `const ${id}_result = await step.waitForEvent('${id}', { event: 'my.waited.event', timeout: '60s' });`;
|
|
13
|
+
default:
|
|
14
|
+
return `// not supported`;
|
|
15
|
+
}
|
|
19
16
|
}
|
|
20
17
|
function indent(s, spaces) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.split('\n')
|
|
24
|
-
.map((l) => (l ? pad + l : l))
|
|
25
|
-
.join('\n');
|
|
18
|
+
const pad = ' '.repeat(spaces);
|
|
19
|
+
return s.split('\n').map(l => l ? pad + l : l).join('\n');
|
|
26
20
|
}
|
|
27
21
|
// Simple code formatter
|
|
28
22
|
function formatCode(code) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.split('\n')
|
|
32
|
-
.map((line) => line.trimEnd())
|
|
33
|
-
.join('\n')
|
|
34
|
-
.replace(/\n{3,}/g, '\n\n'); // Remove excessive blank lines
|
|
23
|
+
// Basic formatting - in production, you'd use a proper formatter
|
|
24
|
+
return code.split('\n').map(line => line.trimEnd()).join('\n').replace(/\n{3,}/g, '\n\n'); // Remove excessive blank lines
|
|
35
25
|
}
|
|
36
26
|
function generateStepBlock(step, position) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return `// ${step.description || step.name || `Step ${position}`}
|
|
43
|
-
${body}`;
|
|
44
|
-
}
|
|
45
|
-
const inner = extractFunctionBody(step.code || '') || 'return { success: true };';
|
|
27
|
+
const stepVar = (step.code || '').match(/const\s+(\w+)\s*=/)?.[1] || `step_${position}`;
|
|
28
|
+
// If caller supplied code, embed it inside step.run wrapper by default for consistency
|
|
29
|
+
if (step.type === 'sleep' || step.type === 'sendEvent' || step.type === 'waitForEvent') {
|
|
30
|
+
// Execute directly (these typically call step.* helpers)
|
|
31
|
+
const body = extractFunctionBody(step.code || '') || getDefaultDirectBody(step.type, stepVar, step.name);
|
|
46
32
|
return `// ${step.description || step.name || `Step ${position}`}
|
|
33
|
+
${body}`;
|
|
34
|
+
}
|
|
35
|
+
const inner = extractFunctionBody(step.code || '') || 'return { success: true };';
|
|
36
|
+
return `// ${step.description || step.name || `Step ${position}`}
|
|
47
37
|
const ${stepVar}_result = await step.run('${stepVar}', async (event, step) => {
|
|
48
38
|
${indent(inner, 2)}
|
|
49
39
|
});`;
|
|
50
40
|
}
|
|
51
41
|
// Minimal shared generator. Replace internals by moving editor logic here incrementally.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
function generateFunctionCode(def) {
|
|
43
|
+
const eventsString = def.events.length > 0 ? def.events.map(e => `'${e}'`).join(', ') : `'app.event'`;
|
|
44
|
+
const safeId = def.id.replace(/[^a-zA-Z0-9]/g, '') || 'function';
|
|
45
|
+
const body = generateHandlerBody(def);
|
|
46
|
+
return `const ${safeId}Function = inngest.createFunction(
|
|
57
47
|
{ id: '${def.id}' },
|
|
58
48
|
{ event: [${eventsString}] },
|
|
59
49
|
async ({ event, step }) => {
|
|
@@ -62,46 +52,46 @@ ${indent(body, 4)}
|
|
|
62
52
|
);`;
|
|
63
53
|
}
|
|
64
54
|
// New: return only the handler body that backend executes and editor displays
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
function generateHandlerBody(def) {
|
|
56
|
+
const stepBlocks = def.steps.map((step, index) => generateStepBlock(step, index + 1)).join('\n');
|
|
57
|
+
const footer = `return {\n functionId: '${def.id}',\n steps: ${def.steps.length},\n timestamp: new Date().toISOString()\n};`;
|
|
58
|
+
return `${stepBlocks}\n${footer}`;
|
|
69
59
|
}
|
|
70
60
|
// Generate Inngest function from database-extracted functions
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
function generateStepFunctionsFromDB(functionId, events, extractedFunctions) {
|
|
62
|
+
if (!extractedFunctions || extractedFunctions.length === 0) {
|
|
63
|
+
throw new Error('No functions provided to generate');
|
|
64
|
+
}
|
|
65
|
+
// Use the new unified generator
|
|
66
|
+
const code = generateFromExtractedFunctions(extractedFunctions);
|
|
67
|
+
return {
|
|
68
|
+
code: formatCode(code),
|
|
69
|
+
functionId,
|
|
70
|
+
stepCount: extractedFunctions.length
|
|
71
|
+
};
|
|
82
72
|
}
|
|
83
73
|
// Wrap multiple step functions in a single Inngest function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
74
|
+
function wrapStepsInInngestFunction(functionDef, stepFunctions) {
|
|
75
|
+
const extractedFunctions = stepFunctions.map(sf => ({
|
|
76
|
+
id: sf.id,
|
|
77
|
+
name: sf.name,
|
|
78
|
+
code: sf.code,
|
|
79
|
+
description: sf.description
|
|
80
|
+
}));
|
|
81
|
+
const result = generateStepFunctionsFromDB(functionDef.id, functionDef.events, extractedFunctions);
|
|
82
|
+
return result.code;
|
|
93
83
|
}
|
|
94
84
|
// Generate a single step from an extracted function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
85
|
+
function generateStepFromFunction(stepFunction, index) {
|
|
86
|
+
const stepVar = extractStepVarName(stepFunction.code) || `step_${index}`;
|
|
87
|
+
const functionBody = extractFunctionBody(stepFunction.code);
|
|
88
|
+
if (!functionBody) {
|
|
89
|
+
return `// ${stepFunction.name || `Step ${index}`}\nconst ${stepVar}_result = { success: false, error: 'Invalid function format' };`;
|
|
90
|
+
}
|
|
91
|
+
const hasDirectOps = hasDirectStepOperations(stepFunction.code);
|
|
92
|
+
const cleanedBody = cleanStepCode(functionBody);
|
|
93
|
+
if (hasDirectOps) {
|
|
94
|
+
return `// ${stepFunction.name || `Step ${index}`}\n${cleanedBody}`;
|
|
95
|
+
}
|
|
96
|
+
return `// ${stepFunction.name || `Step ${index}`}\nconst ${stepVar}_result = await step.run('${stepVar}', async (event, step) => {\n${indent(cleanedBody, 2)}\n});`;
|
|
97
|
+
}export{cleanStepCode,extractStepVarName,generateFunctionCode,generateHandlerBody,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction};//# sourceMappingURL=generateFunctionCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateFunctionCode.js","sources":["../../src/inngest/generateFunctionCode.ts"],"sourcesContent":[null],"names":[],"mappings":"qHAyFA;AAOA,SAAA;AAoBA,EAAA,OAAA,+CAA2C,CAAA,IAAA,CAAW,IAAE,CAAA;AAcxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
* Used by both browser editor and server execution
|
|
4
4
|
*/
|
|
5
5
|
// Pass through code without any cleaning/validation
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function cleanStepCode(code) {
|
|
7
|
+
return code;
|
|
8
8
|
}
|
|
9
9
|
// Extract step variable name from code
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function extractStepVarName(code) {
|
|
11
|
+
const match = code.match(/const\s+(\w+)\s*=/);
|
|
12
|
+
return match ? match[1] : null;
|
|
13
13
|
}
|
|
14
14
|
// Generate default step function for different step types
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function generateDefaultStepFunction(stepVar, stepType) {
|
|
16
|
+
switch (stepType) {
|
|
17
|
+
case 'sleep':
|
|
18
|
+
return `const ${stepVar} = async (event, step) => {
|
|
19
19
|
// Sleep for specified duration
|
|
20
20
|
const sleepResult = await step.sleep('${stepVar}', '5s');
|
|
21
21
|
|
|
@@ -23,8 +23,8 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
23
23
|
|
|
24
24
|
return { success: true, duration: '5s', result: sleepResult };
|
|
25
25
|
};`;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
case 'sendEvent':
|
|
27
|
+
return `const ${stepVar} = async (event, step) => {
|
|
28
28
|
// Send an event to trigger other functions
|
|
29
29
|
const eventResult = await step.sendEvent('${stepVar}', {
|
|
30
30
|
name: 'my.custom.event',
|
|
@@ -39,8 +39,8 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
39
39
|
|
|
40
40
|
return { success: true, eventSent: true, result: eventResult };
|
|
41
41
|
};`;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
case 'waitForEvent':
|
|
43
|
+
return `const ${stepVar} = async (event, step) => {
|
|
44
44
|
// Wait for a specific event before continuing
|
|
45
45
|
const waitResult = await step.waitForEvent('${stepVar}', {
|
|
46
46
|
event: 'my.waited.event',
|
|
@@ -51,8 +51,8 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
51
51
|
|
|
52
52
|
return { success: true, eventReceived: true, result: waitResult };
|
|
53
53
|
};`;
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
case 'retrieveData':
|
|
55
|
+
return `const ${stepVar} = async (event, step) => {
|
|
56
56
|
// Data retrieval implementation
|
|
57
57
|
const formData = event.data.formData || {};
|
|
58
58
|
|
|
@@ -64,8 +64,8 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
64
64
|
|
|
65
65
|
return { success: true, data: retrievedData };
|
|
66
66
|
};`;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
case 'validateForm':
|
|
68
|
+
return `const ${stepVar} = async (event, step) => {
|
|
69
69
|
// Validate form data
|
|
70
70
|
const formData = event.data.formData || {};
|
|
71
71
|
const errors = [];
|
|
@@ -81,8 +81,8 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
81
81
|
validated: errors.length === 0
|
|
82
82
|
};
|
|
83
83
|
};`;
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
case 'parallel':
|
|
85
|
+
return `const ${stepVar} = async (event, step) => {
|
|
86
86
|
// Execute parallel operations
|
|
87
87
|
const results = await Promise.all([
|
|
88
88
|
// Add parallel operations here
|
|
@@ -92,145 +92,135 @@ export function generateDefaultStepFunction(stepVar, stepType) {
|
|
|
92
92
|
|
|
93
93
|
return { success: true, results };
|
|
94
94
|
};`;
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
default:
|
|
96
|
+
return `const ${stepVar} = async (event, step) => {
|
|
97
97
|
// Default step implementation
|
|
98
98
|
return { success: true };
|
|
99
99
|
};`;
|
|
100
|
-
|
|
100
|
+
}
|
|
101
101
|
}
|
|
102
102
|
// Generate a step function in editor format (const step_xxx = async (event, step) => {...})
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
function generateStepFunction(step, index) {
|
|
104
|
+
// Extract or generate step variable name
|
|
105
|
+
const varName = extractStepVarName(step.code || '') || step.originalStepName || step.id || `step_${index}`;
|
|
106
|
+
// If step has code, use it; otherwise generate default
|
|
107
|
+
const code = step.code || generateDefaultStepFunction(varName, step.type || 'run');
|
|
108
|
+
return {
|
|
109
|
+
code: cleanStepCode(code),
|
|
110
|
+
varName
|
|
111
|
+
};
|
|
112
112
|
}
|
|
113
113
|
// Extract function body from step function code
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
114
|
+
function extractFunctionBody(code) {
|
|
115
|
+
// Find the opening brace after the arrow or function keyword
|
|
116
|
+
const arrowIndex = code.indexOf('=>');
|
|
117
|
+
const functionIndex = code.indexOf('function');
|
|
118
|
+
let startIndex = -1;
|
|
119
|
+
if (arrowIndex !== -1) {
|
|
120
|
+
// Find opening brace after =>
|
|
121
|
+
const openBraceIndex = code.indexOf('{', arrowIndex);
|
|
122
|
+
if (openBraceIndex !== -1) {
|
|
123
|
+
startIndex = openBraceIndex + 1;
|
|
125
124
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
125
|
+
} else if (functionIndex !== -1) {
|
|
126
|
+
// Find opening brace after function declaration
|
|
127
|
+
const openBraceIndex = code.indexOf('{', functionIndex);
|
|
128
|
+
if (openBraceIndex !== -1) {
|
|
129
|
+
startIndex = openBraceIndex + 1;
|
|
132
130
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
braceCount--;
|
|
144
|
-
}
|
|
145
|
-
if (braceCount > 0) {
|
|
146
|
-
endIndex++;
|
|
147
|
-
}
|
|
131
|
+
}
|
|
132
|
+
if (startIndex === -1) return null;
|
|
133
|
+
// Find the matching closing brace by counting braces
|
|
134
|
+
let braceCount = 1;
|
|
135
|
+
let endIndex = startIndex;
|
|
136
|
+
while (endIndex < code.length && braceCount > 0) {
|
|
137
|
+
if (code[endIndex] === '{') {
|
|
138
|
+
braceCount++;
|
|
139
|
+
} else if (code[endIndex] === '}') {
|
|
140
|
+
braceCount--;
|
|
148
141
|
}
|
|
149
|
-
if (braceCount
|
|
150
|
-
|
|
142
|
+
if (braceCount > 0) {
|
|
143
|
+
endIndex++;
|
|
151
144
|
}
|
|
152
|
-
|
|
145
|
+
}
|
|
146
|
+
if (braceCount === 0) {
|
|
147
|
+
return code.substring(startIndex, endIndex).trim();
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
153
150
|
}
|
|
154
151
|
// Transform a step function for execution inside Inngest wrapper
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
152
|
+
function transformStepForExecution(stepFunction, stepType, stepLabel) {
|
|
153
|
+
const functionBody = extractFunctionBody(stepFunction.code);
|
|
154
|
+
if (!functionBody) {
|
|
155
|
+
return `// ${stepLabel}\nconst ${stepFunction.varName}_result = { success: false, error: 'Invalid function format' };`;
|
|
156
|
+
}
|
|
157
|
+
const cleanedBody = cleanStepCode(functionBody);
|
|
158
|
+
// For these step types, execute the body directly (they contain step.* calls)
|
|
159
|
+
if (stepType === 'sleep' || stepType === 'sendEvent' || stepType === 'waitForEvent') {
|
|
160
|
+
// Transform the body to ensure result is captured
|
|
161
|
+
let transformedBody = cleanedBody;
|
|
162
|
+
// Replace step method calls to ensure result variable is created
|
|
163
|
+
transformedBody = transformedBody.replace(/(const\s+\w+\s*=\s*)?await\s+step\.(sleep|sendEvent|waitForEvent)/g, (match, constPart, method) => {
|
|
164
|
+
if (constPart) {
|
|
165
|
+
// Already has assignment, replace variable name
|
|
166
|
+
return `const ${stepFunction.varName}_result = await step.${method}`;
|
|
167
|
+
}
|
|
168
|
+
// No assignment, add one
|
|
169
|
+
return `const ${stepFunction.varName}_result = await step.${method}`;
|
|
170
|
+
});
|
|
171
|
+
// Find the original variable name from the step assignment
|
|
172
|
+
const originalVarMatch = transformedBody.match(/const\s+(\w+)\s*=\s*await\s+step\./);
|
|
173
|
+
let originalVarName = null;
|
|
174
|
+
// Also try to find variable from the original code before transformation
|
|
175
|
+
if (!originalVarMatch) {
|
|
176
|
+
const [, codeVarName] = cleanedBody.match(/const\s+(\w+)\s*=\s*await\s+step\./) || [];
|
|
177
|
+
if (codeVarName) {
|
|
178
|
+
originalVarName = codeVarName;
|
|
179
|
+
}
|
|
159
180
|
}
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
transformedBody = transformedBody.replace(/(const\s+\w+\s*=\s*)?await\s+step\.(sleep|sendEvent|waitForEvent)/g, (match, constPart, method) => {
|
|
167
|
-
if (constPart) {
|
|
168
|
-
// Already has assignment, replace variable name
|
|
169
|
-
return `const ${stepFunction.varName}_result = await step.${method}`;
|
|
170
|
-
}
|
|
171
|
-
// No assignment, add one
|
|
172
|
-
return `const ${stepFunction.varName}_result = await step.${method}`;
|
|
173
|
-
});
|
|
174
|
-
// Find the original variable name from the step assignment
|
|
175
|
-
const originalVarMatch = transformedBody.match(/const\s+(\w+)\s*=\s*await\s+step\./);
|
|
176
|
-
let originalVarName = null;
|
|
177
|
-
// Also try to find variable from the original code before transformation
|
|
178
|
-
if (!originalVarMatch) {
|
|
179
|
-
const [, codeVarName] = cleanedBody.match(/const\s+(\w+)\s*=\s*await\s+step\./) || [];
|
|
180
|
-
if (codeVarName) {
|
|
181
|
-
originalVarName = codeVarName;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Replace variable references (like eventResult, sleepResult, waitResult)
|
|
185
|
-
// Common patterns: eventResult, sleepResult, waitResult, or any variable used in console.log/return
|
|
186
|
-
if (originalVarName) {
|
|
187
|
-
// Replace all references to the original variable with the new result variable
|
|
188
|
-
const varPattern = new RegExp(`\\b${originalVarName}\\b`, 'g');
|
|
189
|
-
transformedBody = transformedBody.replace(varPattern, `${stepFunction.varName}_result`);
|
|
190
|
-
}
|
|
191
|
-
// Also replace common result variable names that might not have been caught
|
|
192
|
-
transformedBody = transformedBody
|
|
193
|
-
.replace(/\beventResult\b/g, `${stepFunction.varName}_result`)
|
|
194
|
-
.replace(/\bsleepResult\b/g, `${stepFunction.varName}_result`)
|
|
195
|
-
.replace(/\bwaitResult\b/g, `${stepFunction.varName}_result`);
|
|
196
|
-
// Remove return statements (since we'll add our own unified return)
|
|
197
|
-
transformedBody = transformedBody
|
|
198
|
-
.split('\n')
|
|
199
|
-
.filter((line) => {
|
|
200
|
-
const trimmed = line.trim();
|
|
201
|
-
// Remove lines that start with 'return'
|
|
202
|
-
return !trimmed.match(/^return\s/);
|
|
203
|
-
})
|
|
204
|
-
.join('\n');
|
|
205
|
-
return `// ${stepLabel}\n ${transformedBody}`;
|
|
181
|
+
// Replace variable references (like eventResult, sleepResult, waitResult)
|
|
182
|
+
// Common patterns: eventResult, sleepResult, waitResult, or any variable used in console.log/return
|
|
183
|
+
if (originalVarName) {
|
|
184
|
+
// Replace all references to the original variable with the new result variable
|
|
185
|
+
const varPattern = new RegExp(`\\b${originalVarName}\\b`, 'g');
|
|
186
|
+
transformedBody = transformedBody.replace(varPattern, `${stepFunction.varName}_result`);
|
|
206
187
|
}
|
|
207
|
-
//
|
|
208
|
-
|
|
188
|
+
// Also replace common result variable names that might not have been caught
|
|
189
|
+
transformedBody = transformedBody.replace(/\beventResult\b/g, `${stepFunction.varName}_result`).replace(/\bsleepResult\b/g, `${stepFunction.varName}_result`).replace(/\bwaitResult\b/g, `${stepFunction.varName}_result`);
|
|
190
|
+
// Remove return statements (since we'll add our own unified return)
|
|
191
|
+
transformedBody = transformedBody.split('\n').filter(line => {
|
|
192
|
+
const trimmed = line.trim();
|
|
193
|
+
// Remove lines that start with 'return'
|
|
194
|
+
return !trimmed.match(/^return\s/);
|
|
195
|
+
}).join('\n');
|
|
196
|
+
return `// ${stepLabel}\n ${transformedBody}`;
|
|
197
|
+
}
|
|
198
|
+
// For other step types, wrap in step.run()
|
|
199
|
+
return `// ${stepLabel}
|
|
209
200
|
const ${stepFunction.varName}_result = await step.run('${stepFunction.varName}', async (event, step) => {
|
|
210
201
|
${cleanedBody}
|
|
211
202
|
});`;
|
|
212
203
|
}
|
|
213
204
|
// Generate complete Inngest function from step functions
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const code = `${stepBlocks.join('\n\n')}
|
|
205
|
+
function generateInngestFunctionFromSteps(stepFunctions) {
|
|
206
|
+
// Transform each step for execution
|
|
207
|
+
const stepBlocks = [];
|
|
208
|
+
const resultVars = [];
|
|
209
|
+
stepFunctions.forEach((stepFunc, index) => {
|
|
210
|
+
const stepType = stepFunc.type || 'run';
|
|
211
|
+
const stepLabel = stepFunc.label || `Step ${index + 1}`;
|
|
212
|
+
const executionCode = transformStepForExecution(stepFunc, stepType, stepLabel);
|
|
213
|
+
stepBlocks.push(executionCode);
|
|
214
|
+
// Determine result variable name
|
|
215
|
+
if (executionCode.includes(`${stepFunc.varName}_result`)) {
|
|
216
|
+
resultVars.push(`${stepFunc.varName}_result`);
|
|
217
|
+
} else {
|
|
218
|
+
// For direct execution without result assignment
|
|
219
|
+
resultVars.push(stepFunc.varName);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
// Generate function body without async wrapper
|
|
223
|
+
const code = `${stepBlocks.join('\n\n')}
|
|
234
224
|
|
|
235
225
|
return {
|
|
236
226
|
steps: ${stepFunctions.length},
|
|
@@ -238,27 +228,25 @@ export function generateInngestFunctionFromSteps(stepFunctions) {
|
|
|
238
228
|
${resultVars.map((v, i) => ` ${stepFunctions[i].varName}: ${v}`).join(',\n')}
|
|
239
229
|
}
|
|
240
230
|
};`;
|
|
241
|
-
|
|
231
|
+
return code;
|
|
242
232
|
}
|
|
243
233
|
// Convert ExtractedFunction array to step functions and generate Inngest function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return generateInngestFunctionFromSteps(stepFunctions);
|
|
264
|
-
}
|
|
234
|
+
function generateFromExtractedFunctions(extractedFunctions) {
|
|
235
|
+
// Convert extracted functions to step function format
|
|
236
|
+
const stepFunctions = extractedFunctions.map((func, index) => {
|
|
237
|
+
const {
|
|
238
|
+
code,
|
|
239
|
+
varName
|
|
240
|
+
} = generateStepFunction(func, index + 1);
|
|
241
|
+
// Detect step type from the code
|
|
242
|
+
let type = 'run';
|
|
243
|
+
if (code.includes('step.sleep(')) type = 'sleep';else if (code.includes('step.sendEvent(')) type = 'sendEvent';else if (code.includes('step.waitForEvent(')) type = 'waitForEvent';
|
|
244
|
+
return {
|
|
245
|
+
code,
|
|
246
|
+
varName,
|
|
247
|
+
type,
|
|
248
|
+
label: func.name || `Step ${index + 1}`
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
return generateInngestFunctionFromSteps(stepFunctions);
|
|
252
|
+
}export{cleanStepCode,extractFunctionBody,extractStepVarName,generateDefaultStepFunction,generateFromExtractedFunctions,generateInngestFunctionFromSteps,generateStepFunction,transformStepForExecution};//# sourceMappingURL=stepGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepGenerator.js","sources":["../../src/inngest/stepGenerator.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AAGA;AAEA;;;AAGG,SAAA,aAAA,CAAA,IAAA,EAAA;AAGH,EAAA,OAAA,IAAA;AAKA;AAMA;AA+FA,SAAA,kBAAgB,CAAA,IAAA,EAAA;QAGP,QAAQ,IAAC,CAAA,KAAA,CAAA,mBAAA,CAAA;SAAC,aAAe,CAAA,CAAA,CAAA,GAAA,IAAA;;AAelC;AA6CA,SAAA,2BAAgB,CAAA,OACZ,EAAA,QAAA,EAAY;UAAU,QAAO;IAAC,KAAA;MAC9B,OAAU,CAAA,MAAM,UACP;AA0Eb;wCACwC,EAAA,OAAA,CAAA;;;;;AAoCxC,EAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/form-builder-core",
|
|
3
|
-
"version": "5.1.4-alpha.
|
|
3
|
+
"version": "5.1.4-alpha.49",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"clean": "rimraf lib"
|
|
10
|
+
"build": "npm run build:clean && npm run build:lib",
|
|
11
|
+
"build:clean": "rimraf lib",
|
|
12
|
+
"build:lib": "rollup -c rollup.config.mjs",
|
|
13
|
+
"build:lib:watch": "npm run build:lib -- --watch",
|
|
14
|
+
"jest": "./node_modules/.bin/jest",
|
|
15
|
+
"prepublish": "npm run build",
|
|
16
|
+
"test": "cross-env ENV_FILE=../../../config/test/test.env jest",
|
|
17
|
+
"test:debug": "npm test -- --runInBand",
|
|
18
|
+
"test:watch": "npm test -- --watch",
|
|
19
|
+
"watch": "npm run build:lib:watch"
|
|
12
20
|
},
|
|
13
21
|
"devDependencies": {
|
|
14
22
|
"typescript": "^5.4.0"
|
|
@@ -16,5 +24,5 @@
|
|
|
16
24
|
"publishConfig": {
|
|
17
25
|
"access": "public"
|
|
18
26
|
},
|
|
19
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "4fc9dbe45e8754f40077dc927b64be811d2e1562"
|
|
20
28
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRollupConfig } from '../../../rollup.config.base.mjs';
|
|
2
|
+
|
|
3
|
+
// Define any additional plugins specific to this bundle
|
|
4
|
+
const additionalPlugins = [];
|
|
5
|
+
|
|
6
|
+
// Use the createRollupConfig function to merge the base and specific configurations
|
|
7
|
+
export default (commandLineArgs) => {
|
|
8
|
+
const isWatchMode = commandLineArgs.watch;
|
|
9
|
+
return [
|
|
10
|
+
createRollupConfig(
|
|
11
|
+
{
|
|
12
|
+
input: ['src/index.ts'],
|
|
13
|
+
plugins: [
|
|
14
|
+
// Spread in additional plugins specific to this config
|
|
15
|
+
...additionalPlugins,
|
|
16
|
+
],
|
|
17
|
+
output: [
|
|
18
|
+
{
|
|
19
|
+
dir: 'lib',
|
|
20
|
+
format: 'es',
|
|
21
|
+
name: 'form-stack-server',
|
|
22
|
+
compact: true,
|
|
23
|
+
exports: 'named',
|
|
24
|
+
sourcemap: true,
|
|
25
|
+
preserveModules: true,
|
|
26
|
+
chunkFileNames: '[name]-[hash].[format].js',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
isWatchMode,
|
|
31
|
+
),
|
|
32
|
+
];
|
|
33
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/inngest/types.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export type InngestStepType = 'run' | 'sleep' | 'sendEvent' | 'waitForEvent' | 'retrieveData' | 'parallel' | 'validateForm';
|
|
2
|
-
export interface InngestStep {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
type: InngestStepType;
|
|
6
|
-
code?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
}
|
|
10
|
-
export interface InngestFunctionDef {
|
|
11
|
-
id: string;
|
|
12
|
-
name: string;
|
|
13
|
-
description?: string;
|
|
14
|
-
events: string[];
|
|
15
|
-
steps: InngestStep[];
|
|
16
|
-
concurrency?: number;
|
|
17
|
-
retries?: number;
|
|
18
|
-
timeout?: string | number;
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
}
|
|
21
|
-
export interface ExtractedFunction {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
code?: string;
|
|
25
|
-
extensionId?: string;
|
|
26
|
-
extensionName?: string;
|
|
27
|
-
generatedCode?: string;
|
|
28
|
-
steps?: StepDefinition[];
|
|
29
|
-
originalStepName?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface StepFunction {
|
|
32
|
-
id: string;
|
|
33
|
-
name: string;
|
|
34
|
-
code: string;
|
|
35
|
-
type?: InngestStepType;
|
|
36
|
-
description?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface StepDefinition {
|
|
39
|
-
id: string;
|
|
40
|
-
name: string;
|
|
41
|
-
code: string;
|
|
42
|
-
}
|
|
43
|
-
export interface GeneratedFunctionResult {
|
|
44
|
-
code: string;
|
|
45
|
-
functionId: string;
|
|
46
|
-
stepCount: number;
|
|
47
|
-
}
|
package/lib/inngest/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|