@synergenius/flow-weaver 0.30.4 → 0.30.6

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.
@@ -5987,7 +5987,7 @@ var VERSION;
5987
5987
  var init_generated_version = __esm({
5988
5988
  "src/generated-version.ts"() {
5989
5989
  "use strict";
5990
- VERSION = "0.30.4";
5990
+ VERSION = "0.30.6";
5991
5991
  }
5992
5992
  });
5993
5993
 
@@ -7760,7 +7760,18 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
7760
7760
  );
7761
7761
  }
7762
7762
  }
7763
- const allProps = defaults.length > 0 ? `${defaults.join(", ")}${returnProps.length > 0 ? ", " : ""}${returnProps.join(", ")}` : returnProps.join(", ");
7763
+ const allPropsUnsorted = [...defaults, ...returnProps];
7764
+ const onSuccessProp = allPropsUnsorted.find((p) => p.trimStart().startsWith("onSuccess"));
7765
+ const onFailureProp = allPropsUnsorted.find((p) => p.trimStart().startsWith("onFailure"));
7766
+ const dataProps = allPropsUnsorted.filter((p) => {
7767
+ const key = p.trimStart().split(":")[0].trim();
7768
+ return key !== "onSuccess" && key !== "onFailure";
7769
+ });
7770
+ const orderedProps = [];
7771
+ if (onSuccessProp) orderedProps.push(onSuccessProp);
7772
+ if (onFailureProp) orderedProps.push(onFailureProp);
7773
+ orderedProps.push(...dataProps);
7774
+ const allProps = orderedProps.join(", ");
7764
7775
  lines.push(` const finalResult = { ${allProps} };`);
7765
7776
  lines.push("");
7766
7777
  lines.push(` ${awaitPrefixTop}ctx.sendStatusChangedEvent({`);
@@ -88924,7 +88935,7 @@ function parseIntStrict(value) {
88924
88935
  // src/cli/index.ts
88925
88936
  init_logger();
88926
88937
  init_error_utils();
88927
- var version2 = true ? "0.30.4" : "0.0.0-dev";
88938
+ var version2 = true ? "0.30.6" : "0.0.0-dev";
88928
88939
  var program2 = new Command();
88929
88940
  program2.name("fw").description("Flow Weaver Annotations - Compile and validate workflow files").option("-v, --version", "Output the current version").option("--no-color", "Disable colors").option("--color", "Force colors").on("option:version", () => {
88930
88941
  logger.banner(version2);
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.30.4";
1
+ export declare const VERSION = "0.30.6";
2
2
  //# sourceMappingURL=generated-version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Auto-generated by scripts/generate-version.ts — do not edit manually
2
- export const VERSION = '0.30.4';
2
+ export const VERSION = '0.30.6';
3
3
  //# sourceMappingURL=generated-version.js.map
@@ -607,9 +607,22 @@ export function generateControlFlowWithExecutionContext(workflow, nodeTypes, isA
607
607
  lines.push(` ${setCallForDefaults}({ id: '${RESERVED_NODE_NAMES.EXIT}', portName: 'onFailure', executionIndex: exitIdx, nodeTypeName: '${RESERVED_NODE_NAMES.EXIT}' }, false);`);
608
608
  }
609
609
  }
610
- const allProps = defaults.length > 0
611
- ? `${defaults.join(', ')}${returnProps.length > 0 ? ', ' : ''}${returnProps.join(', ')}`
612
- : returnProps.join(', ');
610
+ // Assemble final result with onSuccess first, onFailure second, then data ports.
611
+ // This ensures JSON.stringify output is readable and predictable.
612
+ const allPropsUnsorted = [...defaults, ...returnProps];
613
+ const onSuccessProp = allPropsUnsorted.find(p => p.trimStart().startsWith('onSuccess'));
614
+ const onFailureProp = allPropsUnsorted.find(p => p.trimStart().startsWith('onFailure'));
615
+ const dataProps = allPropsUnsorted.filter(p => {
616
+ const key = p.trimStart().split(':')[0].trim();
617
+ return key !== 'onSuccess' && key !== 'onFailure';
618
+ });
619
+ const orderedProps = [];
620
+ if (onSuccessProp)
621
+ orderedProps.push(onSuccessProp);
622
+ if (onFailureProp)
623
+ orderedProps.push(onFailureProp);
624
+ orderedProps.push(...dataProps);
625
+ const allProps = orderedProps.join(', ');
613
626
  lines.push(` const finalResult = { ${allProps} };`);
614
627
  lines.push('');
615
628
  lines.push(` ${awaitPrefixTop}ctx.sendStatusChangedEvent({`);
@@ -46,12 +46,16 @@ export declare function getTypedPackages(workdir: string, nodeModulesOverride?:
46
46
  }>;
47
47
  };
48
48
  /**
49
- * Get function exports from a package's .d.ts file and return as TNodeType[].
49
+ * Get callable exports from a package's .d.ts file and return as TNodeType[].
50
+ *
51
+ * Uses ts-morph's symbol-based export enumeration to handle all export
52
+ * patterns: declare function, declare const with function types,
53
+ * re-exports from submodules, star exports, etc.
50
54
  *
51
55
  * @param packageName - The npm package name
52
56
  * @param workdir - Directory to start searching from
53
57
  * @param nodeModulesOverride - Optional explicit node_modules path (for testing)
54
- * @returns Array of node types for the package's exported functions
58
+ * @returns Array of node types for the package's callable exports
55
59
  */
56
60
  export declare function getPackageExports(packageName: string, workdir: string, nodeModulesOverride?: string): TNpmNodeType[];
57
61
  //# sourceMappingURL=npm-packages.d.ts.map
@@ -205,12 +205,16 @@ function inferNodeTypeFromDtsFunction(fn, packageName) {
205
205
  };
206
206
  }
207
207
  /**
208
- * Get function exports from a package's .d.ts file and return as TNodeType[].
208
+ * Get callable exports from a package's .d.ts file and return as TNodeType[].
209
+ *
210
+ * Uses ts-morph's symbol-based export enumeration to handle all export
211
+ * patterns: declare function, declare const with function types,
212
+ * re-exports from submodules, star exports, etc.
209
213
  *
210
214
  * @param packageName - The npm package name
211
215
  * @param workdir - Directory to start searching from
212
216
  * @param nodeModulesOverride - Optional explicit node_modules path (for testing)
213
- * @returns Array of node types for the package's exported functions
217
+ * @returns Array of node types for the package's callable exports
214
218
  */
215
219
  export function getPackageExports(packageName, workdir, nodeModulesOverride) {
216
220
  const typesPath = resolvePackageTypesPath(packageName, workdir, nodeModulesOverride);
@@ -220,25 +224,212 @@ export function getPackageExports(packageName, workdir, nodeModulesOverride) {
220
224
  try {
221
225
  const project = getSharedProject();
222
226
  const dtsContent = fs.readFileSync(typesPath, 'utf-8');
223
- // Create source file with unique path to avoid conflicts
224
- const virtualPath = `__npm_exports__/${packageName}/${Date.now()}.d.ts`;
225
- const dtsFile = project.createSourceFile(virtualPath, dtsContent, { overwrite: true });
226
- const functions = extractFunctionLikes(dtsFile);
227
+ // Add the .d.ts file and nearby declaration files to the project so
228
+ // ts-morph can resolve re-exports (including `export * from './submodule'`).
229
+ const pkgDir = path.dirname(typesPath);
230
+ const addedFiles = [];
231
+ try {
232
+ const globPattern = path.join(pkgDir, '**/*.d.{ts,cts,mts}');
233
+ for (const file of project.addSourceFilesAtPaths(globPattern)) {
234
+ addedFiles.push(file.getFilePath());
235
+ }
236
+ }
237
+ catch {
238
+ // Glob may fail on some filesystems; fall back to single file
239
+ }
240
+ let dtsFile = project.getSourceFile(typesPath);
241
+ if (!dtsFile) {
242
+ dtsFile = project.addSourceFileAtPath(typesPath);
243
+ }
227
244
  const nodeTypes = [];
228
245
  const seenFunctionNames = new Set();
229
- for (const fn of functions) {
230
- const fnName = fn.getName();
231
- // Skip duplicates (can happen with re-exports or declaration merging)
232
- if (!fnName || seenFunctionNames.has(fnName))
246
+ // First pass: try symbol-based enumeration (handles re-exports, declare const, etc.)
247
+ const fileSymbol = dtsFile.getSymbol();
248
+ if (fileSymbol) {
249
+ for (const exportSymbol of fileSymbol.getExports()) {
250
+ const exportName = exportSymbol.getName();
251
+ if (seenFunctionNames.has(exportName))
252
+ continue;
253
+ // Check if this export is callable (has call signatures)
254
+ const exportType = exportSymbol.getTypeAtLocation(dtsFile);
255
+ const callSignatures = exportType.getCallSignatures();
256
+ if (callSignatures.length === 0)
257
+ continue;
258
+ seenFunctionNames.add(exportName);
259
+ // Use the first call signature to infer ports
260
+ const sig = callSignatures[0];
261
+ const ports = [];
262
+ // Execute input port
263
+ ports.push({
264
+ name: 'execute',
265
+ defaultLabel: 'Execute',
266
+ reference: 'execute',
267
+ type: 'STEP',
268
+ direction: 'INPUT',
269
+ });
270
+ // Input ports from parameters
271
+ for (const param of sig.getParameters()) {
272
+ const paramName = param.getName();
273
+ const paramType = param.getTypeAtLocation(dtsFile);
274
+ const dataType = inferDataTypeFromTS(paramType.getText());
275
+ ports.push({
276
+ name: paramName,
277
+ defaultLabel: capitalize(paramName),
278
+ reference: paramName,
279
+ type: dataType,
280
+ direction: 'INPUT',
281
+ });
282
+ }
283
+ // Output ports from return type
284
+ let returnType = sig.getReturnType();
285
+ const returnText = returnType.getText();
286
+ let isAsync = false;
287
+ if (returnText.startsWith('Promise<')) {
288
+ isAsync = true;
289
+ const typeArgs = returnType.getTypeArguments();
290
+ if (typeArgs.length > 0)
291
+ returnType = typeArgs[0];
292
+ }
293
+ const unwrapped = returnType.getText();
294
+ if (unwrapped !== 'void' && unwrapped !== 'undefined') {
295
+ const isPrimitive = PRIMITIVE_TYPES.has(unwrapped);
296
+ const isArray = unwrapped.endsWith('[]') || unwrapped.startsWith('Array<');
297
+ const properties = returnType.getProperties();
298
+ const isObjectLike = !isPrimitive && !isArray && returnType.isObject() && properties.length > 0;
299
+ if (isObjectLike) {
300
+ for (const prop of properties) {
301
+ const propName = prop.getName();
302
+ if (propName === 'onSuccess' || propName === 'onFailure')
303
+ continue;
304
+ const propType = prop.getTypeAtLocation(dtsFile);
305
+ ports.push({
306
+ name: propName,
307
+ defaultLabel: capitalize(propName),
308
+ reference: propName,
309
+ type: inferDataTypeFromTS(propType.getText()),
310
+ direction: 'OUTPUT',
311
+ });
312
+ }
313
+ }
314
+ else {
315
+ ports.push({
316
+ name: 'result',
317
+ defaultLabel: 'Result',
318
+ reference: 'result',
319
+ type: inferDataTypeFromTS(unwrapped),
320
+ direction: 'OUTPUT',
321
+ });
322
+ }
323
+ }
324
+ ports.push({
325
+ name: 'onSuccess',
326
+ defaultLabel: 'On Success',
327
+ reference: 'onSuccess',
328
+ type: 'STEP',
329
+ direction: 'OUTPUT',
330
+ });
331
+ ports.push({
332
+ name: 'onFailure',
333
+ defaultLabel: 'On Failure',
334
+ reference: 'onFailure',
335
+ type: 'STEP',
336
+ direction: 'OUTPUT',
337
+ });
338
+ nodeTypes.push({
339
+ name: `npm/${packageName}/${exportName}`,
340
+ variant: 'FUNCTION',
341
+ category: 'NPM Packages',
342
+ function: exportName,
343
+ label: exportName,
344
+ importSource: packageName,
345
+ ports,
346
+ synchronicity: isAsync ? 'ASYNC' : 'SYNC',
347
+ description: `${exportName} from ${packageName}`,
348
+ });
349
+ }
350
+ }
351
+ // Follow star re-exports (`export * from './submodule'`) which the symbol
352
+ // API surfaces as a single __export pseudo-symbol instead of individual names.
353
+ for (const exportDecl of dtsFile.getExportDeclarations()) {
354
+ if (!exportDecl.isNamespaceExport())
355
+ continue;
356
+ const targetFile = exportDecl.getModuleSpecifierSourceFile();
357
+ if (!targetFile)
233
358
  continue;
234
- seenFunctionNames.add(fnName);
235
- const nodeType = inferNodeTypeFromDtsFunction(fn, packageName);
236
- if (nodeType) {
237
- nodeTypes.push(nodeType);
359
+ const targetSymbol = targetFile.getSymbol();
360
+ if (!targetSymbol)
361
+ continue;
362
+ for (const exportSymbol of targetSymbol.getExports()) {
363
+ const exportName = exportSymbol.getName();
364
+ if (seenFunctionNames.has(exportName))
365
+ continue;
366
+ const exportType = exportSymbol.getTypeAtLocation(targetFile);
367
+ const callSignatures = exportType.getCallSignatures();
368
+ if (callSignatures.length === 0)
369
+ continue;
370
+ seenFunctionNames.add(exportName);
371
+ const sig = callSignatures[0];
372
+ const ports = [];
373
+ ports.push({ name: 'execute', defaultLabel: 'Execute', reference: 'execute', type: 'STEP', direction: 'INPUT' });
374
+ for (const param of sig.getParameters()) {
375
+ const paramName = param.getName();
376
+ const paramType = param.getTypeAtLocation(targetFile);
377
+ ports.push({
378
+ name: paramName,
379
+ defaultLabel: capitalize(paramName),
380
+ reference: paramName,
381
+ type: inferDataTypeFromTS(paramType.getText()),
382
+ direction: 'INPUT',
383
+ });
384
+ }
385
+ let returnType = sig.getReturnType();
386
+ const returnText = returnType.getText();
387
+ let isAsync = false;
388
+ if (returnText.startsWith('Promise<')) {
389
+ isAsync = true;
390
+ const typeArgs = returnType.getTypeArguments();
391
+ if (typeArgs.length > 0)
392
+ returnType = typeArgs[0];
393
+ }
394
+ const unwrapped = returnType.getText();
395
+ if (unwrapped !== 'void' && unwrapped !== 'undefined') {
396
+ ports.push({ name: 'result', defaultLabel: 'Result', reference: 'result', type: inferDataTypeFromTS(unwrapped), direction: 'OUTPUT' });
397
+ }
398
+ ports.push({ name: 'onSuccess', defaultLabel: 'On Success', reference: 'onSuccess', type: 'STEP', direction: 'OUTPUT' });
399
+ ports.push({ name: 'onFailure', defaultLabel: 'On Failure', reference: 'onFailure', type: 'STEP', direction: 'OUTPUT' });
400
+ nodeTypes.push({
401
+ name: `npm/${packageName}/${exportName}`,
402
+ variant: 'FUNCTION',
403
+ category: 'NPM Packages',
404
+ function: exportName,
405
+ label: exportName,
406
+ importSource: packageName,
407
+ ports,
408
+ synchronicity: isAsync ? 'ASYNC' : 'SYNC',
409
+ description: `${exportName} from ${packageName}`,
410
+ });
238
411
  }
239
412
  }
240
- // Clean up the temporary source file
241
- project.removeSourceFile(dtsFile);
413
+ // Fallback: if symbol-based enumeration found nothing, try extractFunctionLikes
414
+ // (handles edge cases where symbols aren't available)
415
+ if (nodeTypes.length === 0) {
416
+ const functions = extractFunctionLikes(dtsFile);
417
+ for (const fn of functions) {
418
+ const fnName = fn.getName();
419
+ if (!fnName || seenFunctionNames.has(fnName))
420
+ continue;
421
+ seenFunctionNames.add(fnName);
422
+ const nodeType = inferNodeTypeFromDtsFunction(fn, packageName);
423
+ if (nodeType)
424
+ nodeTypes.push(nodeType);
425
+ }
426
+ }
427
+ // Clean up added source files to avoid project bloat
428
+ for (const filePath of addedFiles) {
429
+ const sf = project.getSourceFile(filePath);
430
+ if (sf)
431
+ project.removeSourceFile(sf);
432
+ }
242
433
  return nodeTypes;
243
434
  }
244
435
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synergenius/flow-weaver",
3
- "version": "0.30.4",
3
+ "version": "0.30.6",
4
4
  "description": "Flow Weaver: deterministic TypeScript workflow compiler. Define workflows with JSDoc annotations, compile to standalone functions with zero runtime dependencies.",
5
5
  "private": false,
6
6
  "type": "module",