@synergenius/flow-weaver 0.10.2 → 0.10.4

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.
@@ -459,6 +459,8 @@ export type TConnectionAST = {
459
459
  metadata?: TConnectionMetadata;
460
460
  /** Pre-computed type compatibility (set during parsing when ts-morph Types are available) */
461
461
  typeCompatibility?: TTypeCompatibility;
462
+ /** Explicit type coercion for this connection (e.g., 'number' wraps value with Number()) */
463
+ coerce?: TCoerceTargetType;
462
464
  };
463
465
  /**
464
466
  * Port Reference - Identifies a specific port on a node.
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Parser for @connect declarations using Chevrotain.
5
5
  */
6
+ import type { TCoerceTargetType } from '../ast/types.js';
6
7
  export interface PortReference {
7
8
  nodeId: string;
8
9
  portName: string;
@@ -11,6 +12,10 @@ export interface PortReference {
11
12
  export interface ConnectParseResult {
12
13
  source: PortReference;
13
14
  target: PortReference;
15
+ /** Explicit type coercion (from `as <type>` suffix) */
16
+ coerce?: TCoerceTargetType;
17
+ /** Set when `as <type>` uses an unrecognized type (cleared after warning is emitted) */
18
+ invalidCoerceType?: string;
14
19
  }
15
20
  /**
16
21
  * Parse a @connect line and return structured result.
@@ -4,7 +4,7 @@
4
4
  * Parser for @connect declarations using Chevrotain.
5
5
  */
6
6
  import { CstParser } from 'chevrotain';
7
- import { JSDocLexer, ConnectTag, Identifier, Arrow, Dot, Colon, allTokens } from './tokens.js';
7
+ import { JSDocLexer, ConnectTag, Identifier, Arrow, Dot, Colon, AsKeyword, allTokens } from './tokens.js';
8
8
  // =============================================================================
9
9
  // Parser Definition
10
10
  // =============================================================================
@@ -13,12 +13,16 @@ class ConnectParser extends CstParser {
13
13
  super(allTokens);
14
14
  this.performSelfAnalysis();
15
15
  }
16
- // Entry rule for connect line
16
+ // Entry rule for connect line: @connect A.port -> B.port [as type]
17
17
  connectLine = this.RULE('connectLine', () => {
18
18
  this.CONSUME(ConnectTag);
19
19
  this.SUBRULE(this.portRef, { LABEL: 'sourceRef' });
20
20
  this.CONSUME(Arrow);
21
21
  this.SUBRULE2(this.portRef, { LABEL: 'targetRef' });
22
+ this.OPTION(() => {
23
+ this.CONSUME(AsKeyword);
24
+ this.CONSUME(Identifier, { LABEL: 'coerceType' });
25
+ });
22
26
  });
23
27
  // node.port or node.port:scope
24
28
  portRef = this.RULE('portRef', () => {
@@ -47,7 +51,18 @@ class ConnectVisitor extends BaseVisitor {
47
51
  connectLine(ctx) {
48
52
  const source = this.visit(ctx.sourceRef);
49
53
  const target = this.visit(ctx.targetRef);
50
- return { source, target };
54
+ const result = { source, target };
55
+ if (ctx.coerceType?.[0]) {
56
+ const validTypes = new Set(['string', 'number', 'boolean', 'json', 'object']);
57
+ const raw = ctx.coerceType[0].image;
58
+ if (validTypes.has(raw)) {
59
+ result.coerce = raw;
60
+ }
61
+ else {
62
+ result.invalidCoerceType = raw;
63
+ }
64
+ }
65
+ return result;
51
66
  }
52
67
  portRef(ctx) {
53
68
  const nodeId = ctx.nodeId[0].image;
@@ -87,7 +102,12 @@ export function parseConnectLine(input, warnings) {
87
102
  ` Expected format: @connect sourceNode.port -> targetNode.port`);
88
103
  return null;
89
104
  }
90
- return visitorInstance.visit(cst);
105
+ const result = visitorInstance.visit(cst);
106
+ if (result.invalidCoerceType) {
107
+ warnings.push(`Invalid coerce type "${result.invalidCoerceType}" in @connect. Valid types: string, number, boolean, json, object`);
108
+ delete result.invalidCoerceType;
109
+ }
110
+ return result;
91
111
  }
92
112
  /**
93
113
  * Get serialized grammar for documentation/diagram generation.