@fnet/cli 0.133.0 → 1.0.0

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
@@ -1,69 +1,31 @@
1
- import React from "react";
1
+ {% set waitForNext=true %}
2
+ {% set assign=true %}
3
+ {% set signal=true %}
2
4
 
3
- {% include "src/default/macros/block-header.js.njk" %}
5
+ {% import "src/default/types/block.js.njk" as block with context %}
4
6
 
5
- {% include "src/default/macros/block-next-header.js.njk" %}
7
+ {% call block.header() %}
6
8
 
7
- {% include "src/default/macros/block-library-header.js.njk" %}
9
+ {% include "src/default/macros/block-library-header.js.njk" %}
8
10
 
9
- {% include "src/default/macros/block-modules-header.js.njk" %}
11
+ import React from "react";
10
12
 
11
- export default function Block(context){
12
-
13
- {% include "src/default/macros/block-body-header.js.njk" %}
13
+ {% endcall %}
14
14
 
15
- this.run= function (){
16
-
17
- {% include "src/default/macros/block-entry-args.js.njk" %}
15
+ {% call block.definition() %}
18
16
 
19
- return new Promise(async (resolve,reject)=>{
17
+ {% if context.lib.type==='atom'%}
18
+ const formLib=LIBRARY;
19
+ {% elseif context.lib.type==='subworkflow' %}
20
+ const formLib={{context.lib.codeKey}};
21
+ {% else %}
22
+ const formLib=undefined;
23
+ throw new Error('Couldnt find form.');
24
+ {% endif %}
20
25
 
26
+ {% include "src/default/macros/block-run-form.js.njk" %}
21
27
 
22
- try{
23
- {% include "src/default/macros/block-run-header.js.njk" %}
24
-
25
- {% include "src/default/macros/page.js.njk" %}
28
+ {% endcall %}
26
29
 
27
- {% include "src/default/macros/block-modules.js.njk" %}
28
-
29
- flow.waitForNext({
30
- key:'{{indexKey}}',
31
- next: async () => {
32
- {% if context.transform.return %}
33
- resolve({type:'return',value: {{context.transform.return | safe}}});
34
- {% elseif context.next %}
35
- {% include "src/default/macros/block-next.js.njk" %}
36
- {% else %}
37
- resolve();
38
- {% endif %}
39
- }
40
- });
41
-
42
- {% if context.lib.type==='atom'%}
43
- const formLib=LIBRARY;
44
- {% elseif context.lib.type==='subworkflow' %}
45
- const formLib={{context.lib.codeKey}};
46
- {% else %}
47
- const formLib=undefined;
48
- throw new Error('Couldnt find form.');
49
- {% endif %}
50
-
51
- {% include "src/default/macros/block-run-form.js.njk" %}
52
-
53
- {% include "src/default/macros/block-assign.js.njk" %}
54
-
55
- {% include "src/default/macros/block-signal.js.njk" %}
56
-
57
- {% include "src/default/macros/block-run-footer.js.njk" %}
58
- }
59
- catch(error){
60
- reject(error);
61
- }
62
-
63
- });
64
- }
65
-
66
- Object.freeze(this);
67
- }
68
-
69
- {% include "src/default/macros/block-footer.js.njk" %}
30
+ {% call block.footer()%}
31
+ {% endcall %}
@@ -0,0 +1,135 @@
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
+ {% endcall %}
10
+
11
+ {% call block.definition() %}
12
+
13
+ // HTTP configuration
14
+ let url = {{ context.transform.http.url | safe }};
15
+ let method = "{{ context.transform.http.method |safe }}";
16
+ let headers = {{ context.transform.http.headers | safe }};
17
+ let timeout = {{ context.transform.http.timeout }};
18
+ {% if context.transform.http.body !== undefined %}
19
+ let body = {% if context.transform.http.body is string %}{{ context.transform.http.body |safe }}{% else %}{{ context.transform.http.body | safe }}{% endif %};
20
+ {% endif %}
21
+ {% if context.transform.http.params %}
22
+ let params = {{ context.transform.http.params | safe }};
23
+ {% endif %}
24
+
25
+ // Create HTTP context for modules
26
+ const httpContext = { url, method, headers, timeout, params: {% if context.transform.http.params %}params{% else %}undefined{% endif %}, body: {% if context.transform.http.body !== undefined %}body{% else %}undefined{% endif %} };
27
+
28
+ // If any property is a module function (m::), call it with HTTP context
29
+ if (typeof url === 'function') {
30
+ url = await url(httpContext);
31
+ }
32
+
33
+ if (typeof method === 'function') {
34
+ method = await method(httpContext);
35
+ }
36
+
37
+ if (typeof headers === 'function') {
38
+ headers = await headers(httpContext);
39
+ }
40
+
41
+ if (typeof timeout === 'function') {
42
+ timeout = await timeout(httpContext);
43
+ }
44
+
45
+ {% if context.transform.http.params %}
46
+ if (typeof params === 'function') {
47
+ params = await params(httpContext);
48
+ }
49
+ {% endif %}
50
+
51
+ {% if context.transform.http.body !== undefined %}
52
+ if (typeof body === 'function') {
53
+ body = await body(httpContext);
54
+ }
55
+ {% endif %}
56
+
57
+ // Build URL with query parameters if provided
58
+ let finalUrl = url;
59
+ {% if context.transform.http.params %}
60
+ if (params && Object.keys(params).length > 0) {
61
+ const queryString = new URLSearchParams(params).toString();
62
+ finalUrl = url + (url.includes('?') ? '&' : '?') + queryString;
63
+ }
64
+ {% endif %}
65
+
66
+ // Prepare fetch options
67
+ const fetchOptions = {
68
+ method: method,
69
+ headers: headers
70
+ };
71
+
72
+ // Add body if present (and not GET/HEAD)
73
+ {% if context.transform.http.body %}
74
+ if (body !== undefined && method !== 'GET' && method !== 'HEAD') {
75
+ // Auto JSON.stringify if body is object
76
+ if (typeof body === 'object' && body !== null) {
77
+ fetchOptions.body = JSON.stringify(body);
78
+ // Auto set Content-Type if not already set
79
+ if (!fetchOptions.headers['Content-Type'] && !fetchOptions.headers['content-type']) {
80
+ fetchOptions.headers['Content-Type'] = 'application/json';
81
+ }
82
+ } else {
83
+ fetchOptions.body = body;
84
+ }
85
+ }
86
+ {% endif %}
87
+
88
+ // Create abort controller for timeout
89
+ const controller = new AbortController();
90
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
91
+ fetchOptions.signal = controller.signal;
92
+
93
+ let result;
94
+
95
+ try {
96
+ // Execute HTTP request
97
+ const response = await fetch(finalUrl, fetchOptions);
98
+ clearTimeout(timeoutId);
99
+
100
+ // Check if response is successful (2xx)
101
+ if (!response.ok) {
102
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
103
+ }
104
+
105
+ // Parse response based on Content-Type
106
+ const contentType = response.headers.get('content-type');
107
+
108
+ if (contentType && contentType.includes('application/json')) {
109
+ result = await response.json();
110
+ } else if (contentType && contentType.includes('text/')) {
111
+ result = await response.text();
112
+ } else {
113
+ // Try JSON first, fallback to text
114
+ try {
115
+ result = await response.json();
116
+ } catch (e) {
117
+ result = await response.text();
118
+ }
119
+ }
120
+ } catch (error) {
121
+ clearTimeout(timeoutId);
122
+
123
+ // Handle timeout error
124
+ if (error.name === 'AbortError') {
125
+ const timeoutError = new Error(`HTTP request timeout after ${timeout}ms: ${finalUrl}`);
126
+ return reject(timeoutError);
127
+ }
128
+
129
+ // Handle other errors
130
+ return reject(error);
131
+ }
132
+ {% endcall %}
133
+
134
+ {% call block.footer()%}
135
+ {% endcall %}
@@ -1,57 +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
- try{
18
- {% include "src/default/macros/block-run-header.js.njk" %}
19
-
20
- {% include "src/default/macros/page.js.njk" %}
21
-
22
- {% if context.next and context.transform.wait==='next' %}
23
- flow.waitForNext({
24
- key:'{{indexKey}}',
25
- next: async () => {
26
- {% include "src/default/macros/block-next.js.njk" %}
27
- }
28
- });
29
- {% endif %}
30
-
31
- {% include "src/default/macros/block-modules.js.njk" %}
32
-
33
-
34
- {% include "src/default/macros/block-assign.js.njk" %}
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
- catch(error){
49
- reject(error);
50
- }
51
- });
52
- }
53
-
54
- Object.freeze(this);
55
- }
56
-
57
- {% include "src/default/macros/block-footer.js.njk" %}
14
+ {% call block.footer()%}
15
+ {% endcall %}
@@ -1,87 +1,42 @@
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" %}
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
+ {% endif %}
36
+
37
+ const result = instance;
12
38
 
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
- try{
20
- {% include "src/default/macros/block-run-header.js.njk" %}
21
-
22
- {% include "src/default/macros/page.js.njk" %}
23
-
24
- {% include "src/default/macros/block-modules.js.njk" %}
25
-
26
- {% if context.next and context.transform.wait==='next' %}
27
- flow.waitForNext({
28
- key:'{{indexKey}}',
29
- next: async () => {
30
- {% include "src/default/macros/block-next.js.njk" %}
31
- }
32
- });
33
- {% endif %}
34
-
35
- {# NEW: Check if 'new' keyword is present for constructor call #}
36
- {% if context.transform.new !== undefined %}
37
- {# Constructor instantiation with 'new' keyword #}
38
- {% if context.lib.type==='atom' and context.lib.atom.protocol!=='use:' %}
39
- const LibClass=LIBRARY;
40
- {% elseif context.lib.atom.protocol==='use:' %}
41
- {# For use:e:: protocol, call value is the class name (e.g., use:e::Map → Map) #}
42
- const LibClass={{context.transform.import}};
43
- if(!LibClass) throw new Error('[use] Couldnt find class.');
44
- {% else %}
45
- throw new Error('Cannot instantiate: unsupported lib type.');
46
- {% endif %}
47
-
48
- {# Create instance with constructor args #}
49
- {% if context.transform.new %}
50
- const constructorArgs = {{ context.transform.new | safe }};
51
- const instance = Array.isArray(constructorArgs) ? new LibClass(...constructorArgs) : new LibClass(constructorArgs);
52
- {% else %}
53
- const instance = new LibClass();
54
- {% endif %}
55
-
56
- {% endif %}
57
-
58
- const result = instance;
59
-
60
- {% for assign in context.transform.result %}
61
- flow.set({{assign.key | safe}},{{assign.value | safe}});
62
- {% endfor%}
63
-
64
- {% include "src/default/macros/block-assign.js.njk" %}
65
-
66
- {% include "src/default/macros/block-signal.js.njk" %}
67
-
68
- {% if context.transform.return %}
69
- resolve({type:'return',value: {{context.transform.return | safe}}});
70
- {% elseif context.next and context.transform.wait!=='next'%}
71
- {% include "src/default/macros/block-next.js.njk" %}
72
- {% elseif not context.next%}
73
- resolve();
74
- {% endif %}
75
-
76
- {% include "src/default/macros/block-run-footer.js.njk" %}
77
- }
78
- catch(error){
79
- onError? onError(error) : reject(error);
80
- }
81
- });
82
- }
83
-
84
- Object.freeze(this);
85
- }
39
+ {% endcall %}
86
40
 
87
- {% include "src/default/macros/block-footer.js.njk" %}
41
+ {% call block.footer()%}
42
+ {% endcall %}
@@ -1,37 +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
- export default function Block(context){
6
-
7
- {% include "src/default/macros/block-body-header.js.njk" %}
7
+ {% call block.header() %}
8
+ {% endcall %}
8
9
 
9
- this.run= function (){
10
-
11
- {% include "src/default/macros/block-entry-args.js.njk" %}
10
+ {% call block.definition() %}
12
11
 
13
- return new Promise(async (resolve,reject)=>{
14
- {% include "src/default/macros/block-run-header.js.njk" %}
15
-
16
- {% include "src/default/macros/page.js.njk" %}
17
-
18
- {% include "src/default/macros/block-assign.js.njk" %}
12
+ {% endcall %}
19
13
 
20
- {% include "src/default/macros/block-signal.js.njk" %}
21
-
22
- {% if context.transform.return %}
23
- resolve({type:'return',value: {{context.transform.return | safe}}});
24
- {% elseif context.next %}
25
- {% include "src/default/macros/block-next.js.njk" %}
26
- {% else %}
27
- resolve();
28
- {% endif %}
29
-
30
- {% include "src/default/macros/block-run-footer.js.njk" %}
31
- });
32
- }
33
-
34
- Object.freeze(this);
35
- }
36
-
37
- {% include "src/default/macros/block-footer.js.njk" %}
14
+ {% call block.footer()%}
15
+ {% endcall %}
@@ -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 %}
@@ -0,0 +1,64 @@
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
+ {% for child in childs %}
10
+ {% if not child.definition.dynamic %}
11
+ // PARALLEL CHILD: {{child.indexKey}}
12
+ import {{child.codeKey}} from "./{{child.codeKey}}.js";
13
+ {% endif %}
14
+ {% endfor %}
15
+ {% endcall %}
16
+
17
+ {% call block.definition() %}
18
+ // PARALLEL EXECUTION
19
+ const promises = [];
20
+
21
+ {% for child in childs %}
22
+ {% if child.definition.dynamic %}
23
+ // PARALLEL CHILD: {{child.indexKey}}
24
+ const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}.js");
25
+ {% endif %}
26
+
27
+ promises.push((async () => {
28
+ const current = new {{child.codeKey}}({ parent: _this, engine, flow, caller: c, error });
29
+
30
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
31
+ console.log(new Date().toLocaleString(), ' * ', _this.constructor.IndexKey, ' -> ', current.constructor.IndexKey);
32
+ {% endif %}
33
+
34
+ const nextBlock = Array.isArray(args)
35
+ ? await current.run.apply(current, args)
36
+ : await current.run.call(current, args);
37
+
38
+ return nextBlock;
39
+ })());
40
+ {% endfor %}
41
+
42
+ // Execute based on strategy
43
+ {% set strategy = context.transform.strategy | default('all') %}
44
+ let result;
45
+
46
+ {% if strategy == 'race' %}
47
+ // Promise.race - first to complete wins
48
+ result = [await Promise.race(promises)];
49
+ {% elif strategy == 'any' %}
50
+ // Promise.any - first successful wins
51
+ result = [await Promise.any(promises)];
52
+ {% elif strategy == 'allsettled' %}
53
+ // Promise.allSettled - all complete, collect results
54
+ const settled = await Promise.allSettled(promises);
55
+ result = settled.map(r => r.status === 'fulfilled' ? r.value : null);
56
+ {% else %}
57
+ // Promise.all - all must succeed (default)
58
+ result = await Promise.all(promises);
59
+ {% endif %}
60
+
61
+ {% endcall %}
62
+
63
+ {% call block.footer()%}
64
+ {% endcall %}