@adminide-stack/form-builder-core 5.1.4-alpha.81 → 5.1.4-alpha.82
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 +4 -0
- package/lib/index.js +1 -1
- package/lib/inngest/generateFunctionCode.d.ts +1 -0
- package/lib/inngest/generateFunctionCode.d.ts.map +1 -1
- package/lib/inngest/generateFunctionCode.js +72 -3
- package/lib/inngest/generateFunctionCode.js.map +1 -1
- package/package.json +2 -2
- package/src/inngest/generateFunctionCode.ts +99 -2
- package/src/inngest/stepGenerator.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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.82](https://github.com/CDEBase/forms-stack/compare/v5.1.4-alpha.81...v5.1.4-alpha.82) (2025-10-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @adminide-stack/form-builder-core
|
|
9
|
+
|
|
6
10
|
## [5.1.4-alpha.81](https://github.com/CDEBase/forms-stack/compare/v5.1.4-alpha.80...v5.1.4-alpha.81) (2025-10-24)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @adminide-stack/form-builder-core
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{generateFunctionCode,generateHandlerBody,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction}from'./inngest/generateFunctionCode.js';export{cleanStepCode,extractFunctionBody,extractStepVarName,generateFromExtractedFunctions}from'./inngest/stepGenerator.js';export{getAvailableDefinitions,installLibraryForAutocomplete,setupMonacoAutocomplete,setupStepAutocomplete,updateAutocompleteConfig}from'./inngest/monacoAutocompleteIntegration.js';export{flatten,unflatten}from'./utils/json.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{generateFunctionCode,generateHandlerBody,generateHandlerBodyWithReturn,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction}from'./inngest/generateFunctionCode.js';export{cleanStepCode,extractFunctionBody,extractStepVarName,generateFromExtractedFunctions}from'./inngest/stepGenerator.js';export{getAvailableDefinitions,installLibraryForAutocomplete,setupMonacoAutocomplete,setupStepAutocomplete,updateAutocompleteConfig}from'./inngest/monacoAutocompleteIntegration.js';export{flatten,unflatten}from'./utils/json.js';//# sourceMappingURL=index.js.map
|
|
@@ -2,6 +2,7 @@ import type { InngestFunctionDef, ExtractedFunction, StepFunction, GeneratedFunc
|
|
|
2
2
|
export { cleanStepCode, extractStepVarName } from './stepGenerator';
|
|
3
3
|
export declare function generateFunctionCode(def: InngestFunctionDef): string;
|
|
4
4
|
export declare function generateHandlerBody(def: InngestFunctionDef): string;
|
|
5
|
+
export declare function generateHandlerBodyWithReturn(def: InngestFunctionDef): string;
|
|
5
6
|
export declare function generateStepFunctionsFromDB(functionId: string, events: string[], extractedFunctions: ExtractedFunction[]): GeneratedFunctionResult;
|
|
6
7
|
export declare function wrapStepsInInngestFunction(functionDef: InngestFunctionDef, stepFunctions: StepFunction[]): string;
|
|
7
8
|
export declare function generateStepFromFunction(stepFunction: StepFunction, index: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFunctionCode.d.ts","sourceRoot":"","sources":["../../src/inngest/generateFunctionCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,kBAAkB,EAElB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EAC1B,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"generateFunctionCode.d.ts","sourceRoot":"","sources":["../../src/inngest/generateFunctionCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,kBAAkB,EAElB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EAC1B,MAAM,oBAAoB,CAAC;AAS5B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAyEpE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAWpE;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAInE;AAiDD,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAkC7E;AAGD,wBAAgB,2BAA2B,CACvC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EAAE,EAChB,kBAAkB,EAAE,iBAAiB,EAAE,GACxC,uBAAuB,CAazB;AAGD,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,MAAM,CAWjH;AAGD,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAoB1F"}
|
|
@@ -23,6 +23,16 @@ function formatCode(code) {
|
|
|
23
23
|
// Basic formatting - in production, you'd use a proper formatter
|
|
24
24
|
return code.split('\n').map(line => line.trimEnd()).join('\n').replace(/\n{3,}/g, '\n\n'); // Remove excessive blank lines
|
|
25
25
|
}
|
|
26
|
+
function sanitizeDirectStepCode(code) {
|
|
27
|
+
if (!code) {
|
|
28
|
+
return code;
|
|
29
|
+
}
|
|
30
|
+
return code
|
|
31
|
+
// Remove inline object returns (e.g. return { success: true };)
|
|
32
|
+
.replace(/\n\s*return\s*\{[\s\S]*?\};?/g, '')
|
|
33
|
+
// Remove simple expression returns (e.g. return result;)
|
|
34
|
+
.replace(/\n\s*return\s+[^\n;]+;?/g, '');
|
|
35
|
+
}
|
|
26
36
|
function generateStepBlock(step, position) {
|
|
27
37
|
const stepVar = (step.code || '').match(/const\s+(\w+)\s*=/)?.[1] || `step_${position}`;
|
|
28
38
|
// If caller supplied code, embed it inside step.run wrapper by default for consistency
|
|
@@ -34,7 +44,7 @@ ${body}`;
|
|
|
34
44
|
}
|
|
35
45
|
const inner = extractFunctionBody(step.code || '') || 'return { success: true };';
|
|
36
46
|
return `// ${step.description || step.name || `Step ${position}`}
|
|
37
|
-
const ${stepVar}_result = await step.run('${stepVar}', async (
|
|
47
|
+
const ${stepVar}_result = await step.run('${stepVar}', async () => {
|
|
38
48
|
${indent(inner, 2)}
|
|
39
49
|
});`;
|
|
40
50
|
}
|
|
@@ -57,6 +67,65 @@ function generateHandlerBody(def) {
|
|
|
57
67
|
// Footer removed: callers should append their own consolidated return as needed
|
|
58
68
|
return `${stepBlocks}`;
|
|
59
69
|
}
|
|
70
|
+
function escapeSingleQuotes(value) {
|
|
71
|
+
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
72
|
+
}
|
|
73
|
+
function resolveStepVarName(step, index) {
|
|
74
|
+
const directMatch = (step.code || '').match(/const\s+(\w+)\s*=/);
|
|
75
|
+
if (directMatch) {
|
|
76
|
+
return directMatch[1];
|
|
77
|
+
}
|
|
78
|
+
if (typeof step.id === 'string' && step.id.trim()) {
|
|
79
|
+
return step.id;
|
|
80
|
+
}
|
|
81
|
+
return `step_${index + 1}`;
|
|
82
|
+
}
|
|
83
|
+
function resolveResultExpression(step, varName) {
|
|
84
|
+
switch (step.type) {
|
|
85
|
+
case 'sleep':
|
|
86
|
+
return 'sleepResult';
|
|
87
|
+
case 'sendEvent':
|
|
88
|
+
return 'eventResult';
|
|
89
|
+
case 'waitForEvent':
|
|
90
|
+
return 'waitResult';
|
|
91
|
+
default:
|
|
92
|
+
return `${varName}_result`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function sanitizeSteps(def) {
|
|
96
|
+
const sanitizedSteps = def.steps.map(step => {
|
|
97
|
+
if (step.type === 'sleep' || step.type === 'sendEvent' || step.type === 'waitForEvent') {
|
|
98
|
+
return {
|
|
99
|
+
...step,
|
|
100
|
+
code: sanitizeDirectStepCode(step.code || '')
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return step;
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
...def,
|
|
107
|
+
steps: sanitizedSteps
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function generateHandlerBodyWithReturn(def) {
|
|
111
|
+
const sanitizedDef = sanitizeSteps(def);
|
|
112
|
+
const body = generateHandlerBody(sanitizedDef).trimEnd();
|
|
113
|
+
const resultLines = sanitizedDef.steps.map((step, index) => {
|
|
114
|
+
const varName = resolveStepVarName(step, index);
|
|
115
|
+
const resultExpr = resolveResultExpression(step, varName);
|
|
116
|
+
if (!resultExpr) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return ` ${varName}: ${resultExpr},`;
|
|
120
|
+
}).filter(line => Boolean(line));
|
|
121
|
+
const escapedId = escapeSingleQuotes(def.id || 'new-function');
|
|
122
|
+
const returnLines = ['return {', ` functionId: '${escapedId}',`, ...resultLines, ' timestamp: new Date().toISOString()', '};'];
|
|
123
|
+
const returnBlock = returnLines.join('\n');
|
|
124
|
+
if (!body) {
|
|
125
|
+
return returnBlock;
|
|
126
|
+
}
|
|
127
|
+
return `${body}\n\n${returnBlock}`;
|
|
128
|
+
}
|
|
60
129
|
// Generate Inngest function from database-extracted functions
|
|
61
130
|
function generateStepFunctionsFromDB(functionId, events, extractedFunctions) {
|
|
62
131
|
if (!extractedFunctions || extractedFunctions.length === 0) {
|
|
@@ -93,5 +162,5 @@ function generateStepFromFunction(stepFunction, index) {
|
|
|
93
162
|
if (hasDirectOps) {
|
|
94
163
|
return `// ${stepFunction.name || `Step ${index}`}\n${cleanedBody}`;
|
|
95
164
|
}
|
|
96
|
-
return `// ${stepFunction.name || `Step ${index}`}\nconst ${stepVar}_result = await step.run('${stepVar}', async (
|
|
97
|
-
}export{cleanStepCode,extractStepVarName,generateFunctionCode,generateHandlerBody,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction};//# sourceMappingURL=generateFunctionCode.js.map
|
|
165
|
+
return `// ${stepFunction.name || `Step ${index}`}\nconst ${stepVar}_result = await step.run('${stepVar}', async () => {\n${indent(cleanedBody, 2)}\n});`;
|
|
166
|
+
}export{cleanStepCode,extractStepVarName,generateFunctionCode,generateHandlerBody,generateHandlerBodyWithReturn,generateStepFromFunction,generateStepFunctionsFromDB,wrapStepsInInngestFunction};//# sourceMappingURL=generateFunctionCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFunctionCode.js","sources":["../../src/inngest/generateFunctionCode.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateFunctionCode.js","sources":["../../src/inngest/generateFunctionCode.ts"],"sourcesContent":[null],"names":[],"mappings":"qHAuGA;AAqDA,SAAA;AAqCA,EAAA,OAAA,+CACI,CAAA,IAAA,CAAU,IAAE,CAAA;AAmBhB;AAcA,SAAA,oBAAgB,CAAA,IAAA,EAAA,EAAA,EAAA,KAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/form-builder-core",
|
|
3
|
-
"version": "5.1.4-alpha.
|
|
3
|
+
"version": "5.1.4-alpha.82",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "d2f703901231f55e85e7d721754f8746cd2753cc"
|
|
28
28
|
}
|
|
@@ -54,6 +54,20 @@ function formatCode(code: string): string {
|
|
|
54
54
|
.replace(/\n{3,}/g, '\n\n'); // Remove excessive blank lines
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
function sanitizeDirectStepCode(code: string): string {
|
|
58
|
+
if (!code) {
|
|
59
|
+
return code;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
code
|
|
64
|
+
// Remove inline object returns (e.g. return { success: true };)
|
|
65
|
+
.replace(/\n\s*return\s*\{[\s\S]*?\};?/g, '')
|
|
66
|
+
// Remove simple expression returns (e.g. return result;)
|
|
67
|
+
.replace(/\n\s*return\s+[^\n;]+;?/g, '')
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
57
71
|
function generateStepBlock(step: InngestStep, position: number): string {
|
|
58
72
|
const stepVar = (step.code || '').match(/const\s+(\w+)\s*=/)?.[1] || `step_${position}`;
|
|
59
73
|
|
|
@@ -67,7 +81,7 @@ ${body}`;
|
|
|
67
81
|
|
|
68
82
|
const inner = extractFunctionBody(step.code || '') || 'return { success: true };';
|
|
69
83
|
return `// ${step.description || step.name || `Step ${position}`}
|
|
70
|
-
const ${stepVar}_result = await step.run('${stepVar}', async (
|
|
84
|
+
const ${stepVar}_result = await step.run('${stepVar}', async () => {
|
|
71
85
|
${indent(inner, 2)}
|
|
72
86
|
});`;
|
|
73
87
|
}
|
|
@@ -93,6 +107,89 @@ export function generateHandlerBody(def: InngestFunctionDef): string {
|
|
|
93
107
|
return `${stepBlocks}`;
|
|
94
108
|
}
|
|
95
109
|
|
|
110
|
+
function escapeSingleQuotes(value: string): string {
|
|
111
|
+
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resolveStepVarName(step: InngestStep, index: number): string {
|
|
115
|
+
const directMatch = (step.code || '').match(/const\s+(\w+)\s*=/);
|
|
116
|
+
if (directMatch) {
|
|
117
|
+
return directMatch[1];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (typeof step.id === 'string' && step.id.trim()) {
|
|
121
|
+
return step.id;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return `step_${index + 1}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function resolveResultExpression(step: InngestStep, varName: string): string {
|
|
128
|
+
switch (step.type) {
|
|
129
|
+
case 'sleep':
|
|
130
|
+
return 'sleepResult';
|
|
131
|
+
case 'sendEvent':
|
|
132
|
+
return 'eventResult';
|
|
133
|
+
case 'waitForEvent':
|
|
134
|
+
return 'waitResult';
|
|
135
|
+
default:
|
|
136
|
+
return `${varName}_result`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function sanitizeSteps(def: InngestFunctionDef): InngestFunctionDef {
|
|
141
|
+
const sanitizedSteps = def.steps.map((step) => {
|
|
142
|
+
if (step.type === 'sleep' || step.type === 'sendEvent' || step.type === 'waitForEvent') {
|
|
143
|
+
return {
|
|
144
|
+
...step,
|
|
145
|
+
code: sanitizeDirectStepCode(step.code || ''),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return step;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
...def,
|
|
153
|
+
steps: sanitizedSteps,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function generateHandlerBodyWithReturn(def: InngestFunctionDef): string {
|
|
158
|
+
const sanitizedDef = sanitizeSteps(def);
|
|
159
|
+
const body = generateHandlerBody(sanitizedDef).trimEnd();
|
|
160
|
+
|
|
161
|
+
const resultLines = sanitizedDef.steps
|
|
162
|
+
.map((step, index) => {
|
|
163
|
+
const varName = resolveStepVarName(step, index);
|
|
164
|
+
const resultExpr = resolveResultExpression(step, varName);
|
|
165
|
+
|
|
166
|
+
if (!resultExpr) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return ` ${varName}: ${resultExpr},`;
|
|
171
|
+
})
|
|
172
|
+
.filter((line): line is string => Boolean(line));
|
|
173
|
+
|
|
174
|
+
const escapedId = escapeSingleQuotes(def.id || 'new-function');
|
|
175
|
+
|
|
176
|
+
const returnLines = [
|
|
177
|
+
'return {',
|
|
178
|
+
` functionId: '${escapedId}',`,
|
|
179
|
+
...resultLines,
|
|
180
|
+
' timestamp: new Date().toISOString()',
|
|
181
|
+
'};',
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const returnBlock = returnLines.join('\n');
|
|
185
|
+
|
|
186
|
+
if (!body) {
|
|
187
|
+
return returnBlock;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return `${body}\n\n${returnBlock}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
96
193
|
// Generate Inngest function from database-extracted functions
|
|
97
194
|
export function generateStepFunctionsFromDB(
|
|
98
195
|
functionId: string,
|
|
@@ -147,5 +244,5 @@ export function generateStepFromFunction(stepFunction: StepFunction, index: numb
|
|
|
147
244
|
|
|
148
245
|
return `// ${
|
|
149
246
|
stepFunction.name || `Step ${index}`
|
|
150
|
-
}\nconst ${stepVar}_result = await step.run('${stepVar}', async (
|
|
247
|
+
}\nconst ${stepVar}_result = await step.run('${stepVar}', async () => {\n${indent(cleanedBody, 2)}\n});`;
|
|
151
248
|
}
|
|
@@ -463,7 +463,7 @@ export function transformStepForExecution(
|
|
|
463
463
|
|
|
464
464
|
// For other step types, wrap in step.run()
|
|
465
465
|
return `// ${stepLabel}
|
|
466
|
-
const ${stepFunction.varName}_result = await step.run('${stepFunction.varName}', async (
|
|
466
|
+
const ${stepFunction.varName}_result = await step.run('${stepFunction.varName}', async () => {
|
|
467
467
|
${cleanedBody}
|
|
468
468
|
});`;
|
|
469
469
|
}
|