@fnet/cli 0.133.0 → 0.133.1

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.
Files changed (182) hide show
  1. package/dist/fbin/index.js +14 -1
  2. package/dist/fnet/index.0jcm9pn5.js +1 -0
  3. package/dist/fnet/index.2084z2ed.js +2 -0
  4. package/dist/fnet/index.33f1ggpr.js +1 -0
  5. package/dist/fnet/index.3exge2js.js +1 -0
  6. package/dist/fnet/index.3kfx538h.js +1 -0
  7. package/dist/fnet/index.490y87nc.js +1 -0
  8. package/dist/fnet/index.4g9yezkq.js +1 -0
  9. package/dist/fnet/index.4jkat7r4.js +1 -0
  10. package/dist/fnet/index.7crx8ky1.js +1 -0
  11. package/dist/fnet/index.7vw06nrn.js +1 -0
  12. package/dist/fnet/index.9567fa9x.js +1 -0
  13. package/dist/fnet/index.gh75wt1m.js +1 -0
  14. package/dist/fnet/index.hzsfswvp.js +1 -0
  15. package/dist/fnet/index.jgpc3grc.js +1 -0
  16. package/dist/fnet/index.js +19 -1
  17. package/dist/fnet/index.p0zb7e1b.js +1 -0
  18. package/dist/fnet/index.r19p3bpa.js +2 -0
  19. package/dist/fnet/index.r82rtnmz.js +1 -0
  20. package/dist/fnet/index.s662t98v.js +1 -0
  21. package/dist/fnet/index.w74dpnpn.js +1 -0
  22. package/dist/fnet/index.xeaw5xa9.js +1 -0
  23. package/dist/fnet/index.zm4kesg6.js +1 -0
  24. package/dist/fnode/index.05n3mvs9.js +2 -0
  25. package/dist/fnode/index.2hc9tbyx.js +1 -0
  26. package/dist/fnode/index.2pnjg6dc.js +1 -0
  27. package/dist/fnode/index.9qgtmxq3.js +2 -0
  28. package/dist/fnode/index.b1q7y05p.js +1 -0
  29. package/dist/fnode/index.bhapgrs7.js +1 -0
  30. package/dist/fnode/index.cvxrf34y.js +2 -0
  31. package/dist/fnode/index.dp9wyahp.js +1 -0
  32. package/dist/fnode/index.eqxmcpdc.js +1 -0
  33. package/dist/fnode/index.f2tb0x3t.js +1 -0
  34. package/dist/fnode/index.fbzv6wwf.js +1 -0
  35. package/dist/fnode/index.gazd9raq.js +1 -0
  36. package/dist/fnode/index.hv4s25f0.js +3 -0
  37. package/dist/fnode/index.j5z7dtsx.js +1 -0
  38. package/dist/fnode/index.js +9 -1
  39. package/dist/fnode/index.kb4e4bxf.js +1 -0
  40. package/dist/fnode/index.qn0schqp.js +1 -0
  41. package/dist/fnode/index.rht29phd.js +1 -0
  42. package/dist/fnode/index.rzsfmek6.js +3 -0
  43. package/dist/fnode/index.s0nk6cv8.js +4 -0
  44. package/dist/fnode/index.s66v6wt4.js +1 -0
  45. package/dist/fnode/index.sv7v0y60.js +1 -0
  46. package/dist/fnode/index.tgkhgnrp.js +1 -0
  47. package/dist/fnode/index.vq706f75.js +1 -0
  48. package/dist/fnode/index.y8pvdcny.js +1 -0
  49. package/dist/fnode/index.z4vz93ww.js +1 -0
  50. package/dist/frun/index.js +1 -1
  51. package/dist/fservice/index.js +18 -1
  52. package/dist/fservice/index.q01yvaz0.js +2 -0
  53. package/package.json +21 -18
  54. package/readme.md +62 -15
  55. package/template/fnet/core/object.js +10 -10
  56. package/template/fnet/node/package.json.njk +6 -3
  57. package/template/fnet/node/src/cli/index.js.njk +5 -315
  58. package/template/fnet/node/src/cli/index.js.v1.njk +318 -0
  59. package/template/fnet/node/src/cli/v2/core/args-parser.njk +10 -0
  60. package/template/fnet/node/src/cli/v2/core/imports.njk +31 -0
  61. package/template/fnet/node/src/cli/v2/core/run-wrapper.njk +25 -0
  62. package/template/fnet/node/src/cli/v2/index.js.njk +184 -0
  63. package/template/fnet/node/src/cli/v2/modes/default/extend.njk +11 -0
  64. package/template/fnet/node/src/cli/v2/modes/default/standard.njk +20 -0
  65. package/template/fnet/node/src/cli/v2/modes/http/builtin.njk +66 -0
  66. package/template/fnet/node/src/cli/v2/modes/http/imports.njk +9 -0
  67. package/template/fnet/node/src/cli/v2/modes/http/index.njk +12 -0
  68. package/template/fnet/node/src/cli/v2/modes/mcp/imports.njk +33 -0
  69. package/template/fnet/node/src/cli/v2/modes/mcp/index.njk +30 -0
  70. package/template/fnet/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
  71. package/template/fnet/node/src/cli/v2/modes/mcp/tool-handlers.njk +46 -0
  72. package/template/fnet/node/src/cli/v2/modes/mcp/transport-http.njk +222 -0
  73. package/template/fnet/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
  74. package/template/fnet/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
  75. package/template/fnet/node/src/cli/v2/modes/pipeline/index.njk +113 -0
  76. package/template/fnet/node/src/cli/v2/modes/webhook/imports.njk +9 -0
  77. package/template/fnet/node/src/cli/v2/modes/webhook/index.njk +127 -0
  78. package/template/fnet/node/src/cli/v2/modes/websocket/imports.njk +15 -0
  79. package/template/fnet/node/src/cli/v2/modes/websocket/index.njk +104 -0
  80. package/template/fnet/node/src/default/blocks/assign.js.njk +10 -48
  81. package/template/fnet/node/src/default/blocks/call.js.njk +110 -156
  82. package/template/fnet/node/src/default/blocks/for.js.njk +58 -74
  83. package/template/fnet/node/src/default/blocks/form.js.njk +21 -59
  84. package/template/fnet/node/src/default/blocks/http.js.njk +135 -0
  85. package/template/fnet/node/src/default/blocks/modules.js.njk +10 -52
  86. package/template/fnet/node/src/default/blocks/new.js.njk +40 -85
  87. package/template/fnet/node/src/default/blocks/next.js.njk +10 -32
  88. package/template/fnet/node/src/default/blocks/output.js.njk +10 -48
  89. package/template/fnet/node/src/default/blocks/parallel.js.njk +64 -0
  90. package/template/fnet/node/src/default/blocks/pipeline.js.njk +109 -0
  91. package/template/fnet/node/src/default/blocks/raise.js.njk +9 -25
  92. package/template/fnet/node/src/default/blocks/retry.js.njk +70 -0
  93. package/template/fnet/node/src/default/blocks/return.js.njk +13 -25
  94. package/template/fnet/node/src/default/blocks/schedule.js.njk +66 -0
  95. package/template/fnet/node/src/default/blocks/signal.js.njk +10 -32
  96. package/template/fnet/node/src/default/blocks/steps.js.njk +32 -48
  97. package/template/fnet/node/src/default/blocks/switch.js.njk +37 -67
  98. package/template/fnet/node/src/default/blocks/tryexcept.js.njk +58 -52
  99. package/template/fnet/node/src/default/blocks/wait.js.njk +10 -30
  100. package/template/fnet/node/src/default/input.args.js.njk +5 -2
  101. package/template/fnet/node/src/default/macros/block-body-header.js.njk +1 -1
  102. package/template/fnet/node/src/default/macros/block-header.js.njk +0 -3
  103. package/template/fnet/node/src/default/macros/block-next.js.njk +1 -1
  104. package/template/fnet/node/src/default/macros/block-run-footer.js.njk +1 -1
  105. package/template/fnet/node/src/default/macros/block-run-header.js.njk +14 -2
  106. package/template/fnet/node/src/default/macros/page.js.njk +1 -1
  107. package/template/fnet/node/src/default/types/block.js.njk +133 -0
  108. package/template/fnet/node/src/default/workflow.js.njk +8 -6
  109. package/template/fnode/node/package.json.njk +5 -4
  110. package/template/fnode/node/src/cli/index.js.njk +3 -397
  111. package/template/fnode/node/src/cli/index.js.v1.njk +464 -0
  112. package/template/fnode/node/src/cli/v2/core/args-parser.njk +10 -0
  113. package/template/fnode/node/src/cli/v2/core/imports.njk +29 -0
  114. package/template/fnode/node/src/cli/v2/core/run-wrapper.njk +25 -0
  115. package/template/fnode/node/src/cli/v2/index.js.njk +184 -0
  116. package/template/fnode/node/src/cli/v2/modes/default/extend.njk +11 -0
  117. package/template/fnode/node/src/cli/v2/modes/default/standard.njk +19 -0
  118. package/template/fnode/node/src/cli/v2/modes/http/builtin.njk +61 -0
  119. package/template/fnode/node/src/cli/v2/modes/http/imports.njk +9 -0
  120. package/template/fnode/node/src/cli/v2/modes/http/index.njk +12 -0
  121. package/template/fnode/node/src/cli/v2/modes/mcp/imports.njk +33 -0
  122. package/template/fnode/node/src/cli/v2/modes/mcp/index.njk +30 -0
  123. package/template/fnode/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
  124. package/template/fnode/node/src/cli/v2/modes/mcp/tool-handlers.njk +41 -0
  125. package/template/fnode/node/src/cli/v2/modes/mcp/transport-http.njk +212 -0
  126. package/template/fnode/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
  127. package/template/fnode/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
  128. package/template/fnode/node/src/cli/v2/modes/pipeline/index.njk +103 -0
  129. package/template/fnode/node/src/cli/v2/modes/webhook/imports.njk +9 -0
  130. package/template/fnode/node/src/cli/v2/modes/webhook/index.njk +122 -0
  131. package/template/fnode/node/src/cli/v2/modes/websocket/imports.njk +15 -0
  132. package/template/fnode/node/src/cli/v2/modes/websocket/index.njk +99 -0
  133. package/template/fnode/node/src/default/input.args.js.njk +6 -2
  134. package/dist/fnet/index.-SGbq2cI.js +0 -1
  135. package/dist/fnet/index.B5XE4ChJ.js +0 -1
  136. package/dist/fnet/index.Bft2w7m3.js +0 -1
  137. package/dist/fnet/index.BuYxdKtK.js +0 -1
  138. package/dist/fnet/index.C0YpfQ5j.js +0 -1
  139. package/dist/fnet/index.C2S9JYhS.js +0 -1
  140. package/dist/fnet/index.C7saWH6d.js +0 -1
  141. package/dist/fnet/index.CDct_kkF.js +0 -1
  142. package/dist/fnet/index.CMC8mlye.js +0 -1
  143. package/dist/fnet/index.CmMM-Ek9.js +0 -1
  144. package/dist/fnet/index.CuMyez3E.js +0 -1
  145. package/dist/fnet/index.CzAV0S36.js +0 -1
  146. package/dist/fnet/index.D2N9YZmA.js +0 -1
  147. package/dist/fnet/index.D3p7pncT.js +0 -1
  148. package/dist/fnet/index.DG8TqL-1.js +0 -1
  149. package/dist/fnet/index.DI3yyTtl.js +0 -1
  150. package/dist/fnet/index.DOYkqsYT.js +0 -1
  151. package/dist/fnet/index.DWpw12No.js +0 -1
  152. package/dist/fnet/index.DrwlOzAe.js +0 -1
  153. package/dist/fnet/index.Q-CYRcna.js +0 -1
  154. package/dist/fnet/index.W6RYgypK.js +0 -1
  155. package/dist/fnet/index.xd8c7XMr.js +0 -1
  156. package/dist/fnode/index.-SGbq2cI.js +0 -1
  157. package/dist/fnode/index.B5XE4ChJ.js +0 -1
  158. package/dist/fnode/index.B8gal9up.js +0 -1
  159. package/dist/fnode/index.BU1440aO.js +0 -1
  160. package/dist/fnode/index.BcGYSPne.js +0 -1
  161. package/dist/fnode/index.Bft2w7m3.js +0 -1
  162. package/dist/fnode/index.BuYxdKtK.js +0 -1
  163. package/dist/fnode/index.C2S9JYhS.js +0 -1
  164. package/dist/fnode/index.C7saWH6d.js +0 -1
  165. package/dist/fnode/index.CDct_kkF.js +0 -1
  166. package/dist/fnode/index.CMC8mlye.js +0 -1
  167. package/dist/fnode/index.CmMM-Ek9.js +0 -1
  168. package/dist/fnode/index.CuMyez3E.js +0 -1
  169. package/dist/fnode/index.CzAV0S36.js +0 -1
  170. package/dist/fnode/index.D2N9YZmA.js +0 -1
  171. package/dist/fnode/index.D3p7pncT.js +0 -1
  172. package/dist/fnode/index.DG8TqL-1.js +0 -1
  173. package/dist/fnode/index.DI3yyTtl.js +0 -1
  174. package/dist/fnode/index.DWpw12No.js +0 -1
  175. package/dist/fnode/index.DrwlOzAe.js +0 -1
  176. package/dist/fnode/index.N_a5FdgA.js +0 -1
  177. package/dist/fnode/index.Q-CYRcna.js +0 -1
  178. package/dist/fnode/index.UNoFg95r.js +0 -1
  179. package/dist/fnode/index.W6RYgypK.js +0 -1
  180. package/dist/fnode/index.xd8c7XMr.js +0 -1
  181. package/template/fnet/core/print.js +0 -1
  182. package/template/fnet/node/src/default/macros/workflow-header.js.njk +0 -7
@@ -0,0 +1,104 @@
1
+ {# ============================================================================
2
+ WEBSOCKET MODE - MAIN
3
+ ============================================================================
4
+ WebSocket server for real-time bidirectional communication
5
+ Supports connection handling, message processing, and heartbeat
6
+ ============================================================================ #}
7
+
8
+ if (cliMode === 'websocket') {
9
+ // WebSocket mode code
10
+ const port = args['cli-port'] || args.cli_port || 3000;
11
+ const heartbeat = args['ws-heartbeat'] || args.ws_heartbeat || 30000; // 30 seconds default
12
+
13
+ const wss = new WebSocketServer({ port });
14
+
15
+ // Store active connections
16
+ const clients = new Set();
17
+
18
+ wss.on('connection', (ws) => {
19
+ console.log('WebSocket client connected');
20
+ clients.add(ws);
21
+
22
+ // Set up heartbeat
23
+ ws.isAlive = true;
24
+ ws.on('pong', () => {
25
+ ws.isAlive = true;
26
+ });
27
+
28
+ // Handle incoming messages
29
+ ws.on('message', async (data) => {
30
+ try {
31
+ // Parse message
32
+ const message = data.toString();
33
+ let input;
34
+
35
+ try {
36
+ input = JSON.parse(message);
37
+ } catch (e) {
38
+ // If not JSON, wrap in object
39
+ input = { data: message };
40
+ }
41
+
42
+ // Validate input
43
+ // TODO: Add schema validation if needed
44
+
45
+ // Process with Engine
46
+ {% if atom.doc.features.cli.extend===true %}
47
+ const result = await runExtended(input, { Engine });
48
+ {% else %}
49
+ const engine = new Engine();
50
+ const result = await engine.run(input);
51
+ {% endif %}
52
+
53
+ // Send response back to client
54
+ ws.send(JSON.stringify(result));
55
+
56
+ } catch (error) {
57
+ // Send error to client
58
+ ws.send(JSON.stringify({
59
+ error: error.message,
60
+ type: 'processing_error'
61
+ }));
62
+ }
63
+ });
64
+
65
+ // Handle client disconnect
66
+ ws.on('close', () => {
67
+ console.log('WebSocket client disconnected');
68
+ clients.delete(ws);
69
+ });
70
+
71
+ // Handle errors
72
+ ws.on('error', (error) => {
73
+ console.error('WebSocket error:', error.message);
74
+ clients.delete(ws);
75
+ });
76
+ });
77
+
78
+ // Heartbeat interval
79
+ if (heartbeat > 0) {
80
+ const interval = setInterval(() => {
81
+ wss.clients.forEach((ws) => {
82
+ if (ws.isAlive === false) {
83
+ console.log('Terminating inactive client');
84
+ return ws.terminate();
85
+ }
86
+
87
+ ws.isAlive = false;
88
+ ws.ping();
89
+ });
90
+ }, heartbeat);
91
+
92
+ wss.on('close', () => {
93
+ clearInterval(interval);
94
+ });
95
+ }
96
+
97
+ console.log(`WebSocket server started on port ${port}`);
98
+ if (heartbeat > 0) {
99
+ console.log(`Heartbeat interval: ${heartbeat}ms`);
100
+ }
101
+
102
+ return;
103
+ }
104
+
@@ -1,53 +1,15 @@
1
- {% include "src/default/macros/block-header.js.njk" %}
1
+ {% set assign=true %}
2
+ {% set signal=true %}
3
+ {% set resolve=true %}
2
4
 
3
- {% include "src/default/macros/block-next-header.js.njk" %}
5
+ {% import "src/default/types/block.js.njk" as block with context %}
4
6
 
5
- {% include "src/default/macros/block-modules-header.js.njk" %}
7
+ {% call block.header() %}
8
+ {% endcall %}
6
9
 
7
- export default function Block(context){
10
+ {% call block.definition() %}
8
11
 
9
- {% include "src/default/macros/block-body-header.js.njk" %}
12
+ {% endcall %}
10
13
 
11
- this.run= function (){
12
-
13
- {% include "src/default/macros/block-entry-args.js.njk" %}
14
-
15
- return new Promise(async (resolve,reject)=>{
16
-
17
- {% include "src/default/macros/block-run-header.js.njk" %}
18
-
19
- {% include "src/default/macros/page.js.njk" %}
20
-
21
- {% include "src/default/macros/block-modules.js.njk" %}
22
-
23
- {% if context.next and context.transform.wait==='next' %}
24
- flow.waitForNext({
25
- key:'{{indexKey}}',
26
- next: async () => {
27
- {% include "src/default/macros/block-next.js.njk" %}
28
- }
29
- });
30
- {% endif %}
31
-
32
- {% for assign in context.transform.assign %}
33
- flow.set({{assign.key | safe}},{{assign.value | safe}});
34
- {% endfor%}
35
-
36
- {% include "src/default/macros/block-signal.js.njk" %}
37
-
38
- {% if context.transform.return %}
39
- resolve({type:'return',value: {{context.transform.return | safe}}});
40
- {% elseif context.next and context.transform.wait!=='next'%}
41
- {% include "src/default/macros/block-next.js.njk" %}
42
- {% elseif not context.next%}
43
- resolve();
44
- {% endif %}
45
-
46
- {% include "src/default/macros/block-run-footer.js.njk" %}
47
- });
48
- }
49
-
50
- Object.freeze(this);
51
- }
52
-
53
- {% include "src/default/macros/block-footer.js.njk" %}
14
+ {% call block.footer()%}
15
+ {% endcall %}
@@ -1,156 +1,110 @@
1
- {% include "src/default/macros/block-header.js.njk" %}
2
-
3
- {% include "src/default/macros/block-next-header.js.njk" %}
4
-
5
- {% include "src/default/macros/block-library-header.js.njk" %}
6
-
7
- {% include "src/default/macros/block-modules-header.js.njk" %}
8
-
9
- export default function Block(context){
10
-
11
- {% include "src/default/macros/block-body-header.js.njk" %}
12
-
13
- this.run= function (){
14
-
15
- {% include "src/default/macros/block-entry-args.js.njk" %}
16
-
17
- return new Promise(async (resolve,reject)=>{
18
-
19
-
20
- try{
21
- {% include "src/default/macros/block-run-header.js.njk" %}
22
-
23
- {% include "src/default/macros/page.js.njk" %}
24
-
25
- {% include "src/default/macros/block-modules.js.njk" %}
26
-
27
- {% if context.next and context.transform.wait==='next' %}
28
- flow.waitForNext({
29
- key:'{{indexKey}}',
30
- next: async () => {
31
- {% include "src/default/macros/block-next.js.njk" %}
32
- }
33
- });
34
- {% endif %}
35
-
36
- {# NEW: Check if 'new' keyword is present for constructor call #}
37
- {% if context.transform.new !== undefined %}
38
- {# Constructor instantiation with 'new' keyword #}
39
- {% if context.lib.type==='atom' and context.lib.atom.protocol!=='use:' %}
40
- const LibClass=LIBRARY;
41
- {% elseif context.lib.atom.protocol==='use:' %}
42
- {# For use:e:: protocol, call value is the class name (e.g., use:e::Map → Map) #}
43
- const LibClass={{context.transform.import}};
44
- if(!LibClass) throw new Error('[use] Couldnt find class.');
45
- {% else %}
46
- throw new Error('Cannot instantiate: unsupported lib type.');
47
- {% endif %}
48
-
49
- {# Create instance with constructor args #}
50
- {% if context.transform.new %}
51
- const constructorArgs = {{ context.transform.new | safe }};
52
- const instance = Array.isArray(constructorArgs) ? new LibClass(...constructorArgs) : new LibClass(constructorArgs);
53
- {% else %}
54
- const instance = new LibClass();
55
- {% endif %}
56
-
57
- {# If 'call' is specified, get the method from instance #}
58
- {% if context.transform.call %}
59
- const callLib = instance.{{context.transform.call}};
60
- {% else %}
61
- {# No method call, just return the instance #}
62
- const callLib = () => instance;
63
- {% endif %}
64
-
65
- {% else %}
66
- {# EXISTING: Normal function/method call (no 'new') #}
67
- {% if context.lib.type==='atom'%}
68
- {% if context.transform.libExp %}
69
- const lib={{context.transform.libExp}};
70
- {% else %}
71
- const lib=LIBRARY;
72
- {% endif %}
73
- {% elseif context.lib.type==='subworkflow' %}
74
- const lib={{context.lib.codeKey}};
75
- {% elseif target.atom.protocol==='use:' %}
76
- const lib={{context.transform.call}};
77
- if(!lib) throw new Error('[use] Couldnt find lib.');
78
- {% else %}
79
- const lib=undefined;
80
- throw new Error('Couldn file lib.');
81
- {% endif %}
82
-
83
- {% if context.lib.atom.doc.subtype==='workflow'%}
84
- const Workflow=lib;
85
- const workflow=new Workflow({app:engine.app,caller:c});
86
- const callLib = workflow.run.bind(workflow);
87
- {% elseif context.lib.type==='subworkflow'%}
88
- const Workflow=lib;
89
- const workflow=new Workflow({engine,flow,caller:c});
90
- const callLib = workflow.run.bind(workflow);
91
- {% else %}
92
- const callLib = lib;
93
- {% endif %}
94
- {% endif %}
95
-
96
- {# Execute the call #}
97
- {% if context.transform.args %}
98
- {% if context.lib.type==='subworkflow' %}
99
- const callArgs ={ params: {{ context.transform.args | safe }} };
100
- {% else %}
101
- const callArgs ={{ context.transform.args | safe }} ;
102
- {% endif %}
103
-
104
- {% if context.transform.new !== undefined %}
105
- {# For constructor calls, use instance as context #}
106
- const result = Array.isArray(callArgs)? await callLib.apply(instance,callArgs): await callLib.call(instance,callArgs);
107
- {% else %}
108
- {# For regular calls, use _this as context #}
109
- {% if context.transform.context !== undefined %}
110
- const result = Array.isArray(callArgs)? await callLib.apply({{context.transform.context | safe}},callArgs): await callLib.call({{context.transform.context | safe}},callArgs);
111
- {% else %}
112
- const result = Array.isArray(callArgs)? await callLib.apply(_this,callArgs): await callLib.call(_this,callArgs);
113
- {% endif %}
114
-
115
- {% endif %}
116
-
117
- {% else %}
118
- {% if context.transform.new !== undefined %}
119
- const result = await callLib.call(instance);
120
- {% else %}
121
- {% if context.transform.context !== undefined %}
122
- const result = await callLib.call({{context.transform.context | safe}});
123
- {% else %}
124
- const result = await callLib.call(_this);
125
- {% endif %}
126
- {% endif %}
127
- {% endif %}
128
-
129
- {% for assign in context.transform.result %}
130
- flow.set({{assign.key | safe}},{{assign.value | safe}});
131
- {% endfor%}
132
-
133
- {% include "src/default/macros/block-assign.js.njk" %}
134
-
135
- {% include "src/default/macros/block-signal.js.njk" %}
136
-
137
- {% if context.transform.return %}
138
- resolve({type:'return',value: {{context.transform.return | safe}}});
139
- {% elseif context.next and context.transform.wait!=='next'%}
140
- {% include "src/default/macros/block-next.js.njk" %}
141
- {% elseif not context.next%}
142
- resolve();
143
- {% endif %}
144
-
145
- {% include "src/default/macros/block-run-footer.js.njk" %}
146
- }
147
- catch(error){
148
- onError? onError(error) : reject(error);
149
- }
150
- });
151
- }
152
-
153
- Object.freeze(this);
154
- }
155
-
156
- {% include "src/default/macros/block-footer.js.njk" %}
1
+ {% set assign=true %}
2
+ {% set signal=true %}
3
+ {% set resolve=true %}
4
+ {% set result=true %}
5
+
6
+ {% import "src/default/types/block.js.njk" as block with context %}
7
+
8
+ {% call block.header() %}
9
+ {% include "src/default/macros/block-library-header.js.njk" %}
10
+ {% endcall %}
11
+
12
+ {% call block.definition() %}
13
+
14
+ {# NEW: Check if 'new' keyword is present for constructor call #}
15
+ {% if context.transform.new !== undefined %}
16
+ {# Constructor instantiation with 'new' keyword #}
17
+ {% if context.lib.type==='atom' and context.lib.atom.protocol!=='use:' %}
18
+ const LibClass=LIBRARY;
19
+ {% elseif context.lib.atom.protocol==='use:' %}
20
+ {# For use:e:: protocol, call value is the class name (e.g., use:e::Map → Map) #}
21
+ const LibClass={{context.transform.import}};
22
+ if(!LibClass) throw new Error('[use] Couldnt find class.');
23
+ {% else %}
24
+ throw new Error('Cannot instantiate: unsupported lib type.');
25
+ {% endif %}
26
+
27
+ {# Create instance with constructor args #}
28
+ {% if context.transform.new %}
29
+ const constructorArgs = {{ context.transform.new | safe }};
30
+ const instance = Array.isArray(constructorArgs) ? new LibClass(...constructorArgs) : new LibClass(constructorArgs);
31
+ {% else %}
32
+ const instance = new LibClass();
33
+ {% endif %}
34
+
35
+ {# If 'call' is specified, get the method from instance #}
36
+ {% if context.transform.call %}
37
+ const callLib = instance.{{context.transform.call}};
38
+ {% else %}
39
+ {# No method call, just return the instance #}
40
+ const callLib = () => instance;
41
+ {% endif %}
42
+
43
+ {% else %}
44
+ {# EXISTING: Normal function/method call (no 'new') #}
45
+ {% if context.lib.type==='atom'%}
46
+ {% if context.transform.libExp %}
47
+ const lib={{context.transform.libExp}};
48
+ {% else %}
49
+ const lib=LIBRARY;
50
+ {% endif %}
51
+ {% elseif context.lib.type==='subworkflow' %}
52
+ const lib={{context.lib.codeKey}};
53
+ {% elseif target.atom.protocol==='use:' %}
54
+ const lib={{context.transform.call}};
55
+ if(!lib) throw new Error('[use] Couldnt find lib.');
56
+ {% else %}
57
+ const lib=undefined;
58
+ throw new Error('Couldn file lib.');
59
+ {% endif %}
60
+
61
+ {% if context.lib.atom.doc.subtype==='workflow'%}
62
+ const Workflow=lib;
63
+ const workflow=new Workflow({app:engine.app,caller:c});
64
+ const callLib = workflow.run.bind(workflow);
65
+ {% elseif context.lib.type==='subworkflow'%}
66
+ const Workflow=lib;
67
+ const workflow=new Workflow({engine,flow,caller:c});
68
+ const callLib = workflow.run.bind(workflow);
69
+ {% else %}
70
+ const callLib = lib;
71
+ {% endif %}
72
+ {% endif %}
73
+
74
+ {# Execute the call #}
75
+ {% if context.transform.args %}
76
+ {% if context.lib.type==='subworkflow' %}
77
+ const callArgs ={ params: {{ context.transform.args | safe }} };
78
+ {% else %}
79
+ const callArgs ={{ context.transform.args | safe }} ;
80
+ {% endif %}
81
+
82
+ {% if context.transform.new !== undefined %}
83
+ {# For constructor calls, use instance as context #}
84
+ const result = Array.isArray(callArgs)? await callLib.apply(instance,callArgs): await callLib.call(instance,callArgs);
85
+ {% else %}
86
+ {# For regular calls, use _this as context #}
87
+ {% if context.transform.context !== undefined %}
88
+ const result = Array.isArray(callArgs)? await callLib.apply({{context.transform.context | safe}},callArgs): await callLib.call({{context.transform.context | safe}},callArgs);
89
+ {% else %}
90
+ const result = Array.isArray(callArgs)? await callLib.apply(_this,callArgs): await callLib.call(_this,callArgs);
91
+ {% endif %}
92
+
93
+ {% endif %}
94
+
95
+ {% else %}
96
+ {% if context.transform.new !== undefined %}
97
+ const result = await callLib.call(instance);
98
+ {% else %}
99
+ {% if context.transform.context !== undefined %}
100
+ const result = await callLib.call({{context.transform.context | safe}});
101
+ {% else %}
102
+ const result = await callLib.call(_this);
103
+ {% endif %}
104
+ {% endif %}
105
+ {% endif %}
106
+
107
+ {% endcall %}
108
+
109
+ {% call block.footer()%}
110
+ {% endcall %}
@@ -1,87 +1,71 @@
1
+ {% set assign=true %}
2
+ {% set signal=true %}
3
+ {% set resolve=true %}
4
+
5
+ {% import "src/default/types/block.js.njk" as block with context %}
6
+
7
+ {% call block.header() %}
8
+ {% if childs.length %}
9
+ {% if not childs[0].definition.dynamic %}
10
+ // FIRST CHILD: {{childs[0].indexKey}}
11
+ import {{childs[0].codeKey}} from "./{{childs[0].codeKey}}.js";
12
+ {% endif %}
13
+ {% endif%}
14
+ {% endcall %}
15
+
16
+ {% call block.definition() %}
17
+
18
+ {% if childs.length %}
19
+ {% if childs[0].definition.dynamic %}
20
+ // FIRST CHILD: {{childs[0].indexKey}}
21
+ const { default: {{childs[0].codeKey}} } = await import("./{{childs[0].codeKey}}.js");
22
+ {% endif %}
23
+ {% endif%}
24
+
25
+ for await(const {{context.transform.for.as | safe}} of {{context.transform.for.in | safe}}){
26
+ // Create Proxy for closure-like variable resolution
27
+ // Local variable shadows parent, but parent scope accessible via Proxy fallback
28
+ const localForVar = { {{context.transform.for.as | safe}}: {{context.transform.for.as | safe}} };
29
+ const forProxy = new Proxy(localForVar, {
30
+ get(target, prop) {
31
+ // Check local scope first (shadowing)
32
+ if (prop in target) return target[prop];
33
+ // Fallback to parent scope
34
+ return c.for?.[prop];
35
+ }
36
+ });
1
37
 
2
- {% include "src/default/macros/block-header.js.njk" %}
3
-
4
- {% include "src/default/macros/block-next-header.js.njk" %}
5
-
6
- {% include "src/default/macros/block-modules-header.js.njk" %}
7
-
8
- {% if childs.length %}
9
- {% if not childs[0].definition.dynamic %}
10
- // FIRST CHILD: {{childs[0].indexKey}}
11
- import {{childs[0].codeKey}} from "./{{childs[0].codeKey}}.js";
12
- {% endif %}
13
- {% endif%}
14
-
15
- export default function Block(context) {
16
-
17
- {% include "src/default/macros/block-body-header.js.njk" %}
38
+ // Create new context with updated for
39
+ const loopContext = { ...c, for: forProxy };
18
40
 
19
- this.run= function (){
20
-
21
- {% include "src/default/macros/block-entry-args.js.njk" %}
41
+ {% if childs.length %}
42
+ let current= new {{childs[0].codeKey}}({ parent:_this, engine, flow, caller:loopContext });
43
+ let currentArgs=args;
22
44
 
23
- return new Promise(async (resolve,reject)=>{
24
-
25
- {% include "src/default/macros/block-run-header.js.njk" %}
26
-
27
- {% include "src/default/macros/page.js.njk" %}
28
-
29
- {% include "src/default/macros/block-modules.js.njk" %}
45
+ do {
30
46
 
31
- {% if childs.length %}
32
- {% if childs[0].definition.dynamic %}
33
- // FIRST CHILD: {{childs[0].indexKey}}
34
- const { default: {{childs[0].codeKey}} } = await import("./{{childs[0].codeKey}}.js");
47
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
48
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
35
49
  {% endif %}
36
- {% endif%}
37
-
38
- for await(const {{context.transform.for.value | safe}} of {{context.transform.for.in | safe}}){
39
- c.for={ {{context.transform.for.value | safe}} };
40
50
 
41
- {% if childs.length %}
42
- let current= new {{childs[0].codeKey}}({ parent:_this, engine, flow, caller:c });
43
- let currentArgs=args;
51
+ const nextBlock= typeof currentArgs==='undefined'? await current.run()
52
+ : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
44
53
 
45
- do {
46
-
47
- {% if workflow.parent.context.atom.doc.features.print_runners %}
48
- console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
49
- {% endif %}
54
+ if(nextBlock?.type==='return') return resolve(nextBlock);
55
+ else if(nextBlock?.type!=='block') break;
50
56
 
51
- const nextBlock= typeof currentArgs==='undefined'? await current.run()
52
- : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
57
+ if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
58
+ return resolve(nextBlock);
53
59
 
54
- if(nextBlock?.type==='return') return resolve(nextBlock);
55
- else if(nextBlock?.type!=='block') break;
60
+ current=new nextBlock.toType({ parent:_this, engine, flow, caller:loopContext, error });
61
+ currentArgs=nextBlock.input;
56
62
 
57
- if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
58
- return resolve(nextBlock);
63
+ } while(true);
59
64
 
60
- current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, onError, error });
61
- currentArgs=nextBlock.input;
62
-
63
- } while(true);
64
-
65
- {% endif %}
66
- }
67
-
68
- {% include "src/default/macros/block-assign.js.njk" %}
69
-
70
- {% include "src/default/macros/block-signal.js.njk" %}
71
-
72
- {% if context.transform.return %}
73
- resolve({type:'return',value: {{context.transform.return | safe}}});
74
- {% elseif context.next %}
75
- {% include "src/default/macros/block-next.js.njk" %}
76
- {% else %}
77
- resolve();
78
- {% endif %}
79
-
80
- {% include "src/default/macros/block-run-footer.js.njk" %}
81
- });
82
- }
65
+ {% endif %}
66
+ }
83
67
 
84
- Object.freeze(this);
85
- }
68
+ {% endcall %}
86
69
 
87
- {% include "src/default/macros/block-footer.js.njk" %}
70
+ {% call block.footer()%}
71
+ {% endcall %}