@fnet/cli 0.5.1 → 0.5.2

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 (184) hide show
  1. package/dist/fbin/index.js +15 -0
  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 +20 -0
  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 +10 -0
  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 +2 -0
  51. package/dist/fservice/index.js +19 -0
  52. package/dist/fservice/index.q01yvaz0.js +2 -0
  53. package/package.json +74 -57
  54. package/readme.md +298 -0
  55. package/template/fnet/core/assert.js +6 -0
  56. package/template/fnet/core/message.js +3 -0
  57. package/template/fnet/core/object.js +47 -0
  58. package/template/fnet/core/sleep.js +5 -0
  59. package/template/fnet/node/.gitignore.njk +9 -0
  60. package/template/fnet/node/build.js.njk +153 -0
  61. package/template/fnet/node/package.json.njk +121 -0
  62. package/template/fnet/node/readme.md.njk +21 -0
  63. package/template/fnet/node/rollup.config.mjs.njk +498 -0
  64. package/template/fnet/node/src/app/index.html.njk +67 -0
  65. package/template/fnet/node/src/app/index.js.njk +36 -0
  66. package/template/fnet/node/src/cli/index.js.njk +9 -0
  67. package/template/fnet/node/src/cli/index.js.v1.njk +318 -0
  68. package/template/fnet/node/src/cli/v2/core/args-parser.njk +10 -0
  69. package/template/fnet/node/src/cli/v2/core/imports.njk +31 -0
  70. package/template/fnet/node/src/cli/v2/core/run-wrapper.njk +25 -0
  71. package/template/fnet/node/src/cli/v2/index.js.njk +184 -0
  72. package/template/fnet/node/src/cli/v2/modes/default/extend.njk +11 -0
  73. package/template/fnet/node/src/cli/v2/modes/default/standard.njk +20 -0
  74. package/template/fnet/node/src/cli/v2/modes/http/builtin.njk +66 -0
  75. package/template/fnet/node/src/cli/v2/modes/http/imports.njk +9 -0
  76. package/template/fnet/node/src/cli/v2/modes/http/index.njk +12 -0
  77. package/template/fnet/node/src/cli/v2/modes/mcp/imports.njk +33 -0
  78. package/template/fnet/node/src/cli/v2/modes/mcp/index.njk +30 -0
  79. package/template/fnet/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
  80. package/template/fnet/node/src/cli/v2/modes/mcp/tool-handlers.njk +46 -0
  81. package/template/fnet/node/src/cli/v2/modes/mcp/transport-http.njk +222 -0
  82. package/template/fnet/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
  83. package/template/fnet/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
  84. package/template/fnet/node/src/cli/v2/modes/pipeline/index.njk +113 -0
  85. package/template/fnet/node/src/cli/v2/modes/webhook/imports.njk +9 -0
  86. package/template/fnet/node/src/cli/v2/modes/webhook/index.njk +127 -0
  87. package/template/fnet/node/src/cli/v2/modes/websocket/imports.njk +15 -0
  88. package/template/fnet/node/src/cli/v2/modes/websocket/index.njk +104 -0
  89. package/template/fnet/node/src/default/blocks/assign.js.njk +15 -0
  90. package/template/fnet/node/src/default/blocks/call.js.njk +110 -0
  91. package/template/fnet/node/src/default/blocks/for.js.njk +71 -0
  92. package/template/fnet/node/src/default/blocks/form.js.njk +31 -0
  93. package/template/fnet/node/src/default/blocks/http.js.njk +135 -0
  94. package/template/fnet/node/src/default/blocks/modules.js.njk +15 -0
  95. package/template/fnet/node/src/default/blocks/new.js.njk +42 -0
  96. package/template/fnet/node/src/default/blocks/next.js.njk +15 -0
  97. package/template/fnet/node/src/default/blocks/output.js.njk +15 -0
  98. package/template/fnet/node/src/default/blocks/parallel.js.njk +64 -0
  99. package/template/fnet/node/src/default/blocks/pipeline.js.njk +109 -0
  100. package/template/fnet/node/src/default/blocks/raise.js.njk +15 -0
  101. package/template/fnet/node/src/default/blocks/retry.js.njk +70 -0
  102. package/template/fnet/node/src/default/blocks/return.js.njk +21 -0
  103. package/template/fnet/node/src/default/blocks/schedule.js.njk +66 -0
  104. package/template/fnet/node/src/default/blocks/signal.js.njk +15 -0
  105. package/template/fnet/node/src/default/blocks/steps.js.njk +47 -0
  106. package/template/fnet/node/src/default/blocks/switch.js.njk +49 -0
  107. package/template/fnet/node/src/default/blocks/tryexcept.js.njk +80 -0
  108. package/template/fnet/node/src/default/blocks/wait.js.njk +14 -0
  109. package/template/fnet/node/src/default/engine.js.njk +79 -0
  110. package/template/fnet/node/src/default/input.args.js.njk +125 -0
  111. package/template/fnet/node/src/default/macros/block-assign.js.njk +3 -0
  112. package/template/fnet/node/src/default/macros/block-body-header.js.njk +7 -0
  113. package/template/fnet/node/src/default/macros/block-entry-args.js.njk +2 -0
  114. package/template/fnet/node/src/default/macros/block-footer.js.njk +3 -0
  115. package/template/fnet/node/src/default/macros/block-header.js.njk +11 -0
  116. package/template/fnet/node/src/default/macros/block-library-header.js.njk +43 -0
  117. package/template/fnet/node/src/default/macros/block-modules-header.js.njk +8 -0
  118. package/template/fnet/node/src/default/macros/block-modules.js.njk +29 -0
  119. package/template/fnet/node/src/default/macros/block-next-header.js.njk +6 -0
  120. package/template/fnet/node/src/default/macros/block-next.js.njk +21 -0
  121. package/template/fnet/node/src/default/macros/block-run-footer.js.njk +7 -0
  122. package/template/fnet/node/src/default/macros/block-run-form.js.njk +32 -0
  123. package/template/fnet/node/src/default/macros/block-run-header.js.njk +43 -0
  124. package/template/fnet/node/src/default/macros/block-signal.js.njk +3 -0
  125. package/template/fnet/node/src/default/macros/page.js.njk +8 -0
  126. package/template/fnet/node/src/default/types/block.js.njk +133 -0
  127. package/template/fnet/node/src/default/workflow.js.njk +125 -0
  128. package/template/fnet/node/tsconfig.json.njk +16 -0
  129. package/template/fnet/project/.gitignore.njk +7 -0
  130. package/template/fnet/project/.vscode/launch.json.njk +41 -0
  131. package/template/fnet/project/.vscode/tasks.json.njk +46 -0
  132. package/template/fnet/project/fnet/flows.yaml.njk +4 -0
  133. package/template/fnet/project/fnet/targets.yaml.njk +7 -0
  134. package/template/fnet/project/fnet.yaml.njk +3 -0
  135. package/template/fnode/node/.gitignore.njk +9 -0
  136. package/template/fnode/node/build.js.njk +149 -0
  137. package/template/fnode/node/package.json.njk +121 -0
  138. package/template/fnode/node/readme.md.njk +21 -0
  139. package/template/fnode/node/rollup.config.mjs.njk +498 -0
  140. package/template/fnode/node/src/app/index-js-with-react-host.njk +50 -0
  141. package/template/fnode/node/src/app/index-js-without-react-host.njk +23 -0
  142. package/template/fnode/node/src/app/index.html.njk +67 -0
  143. package/template/fnode/node/src/app/index.js.njk +9 -0
  144. package/template/fnode/node/src/cli/index.js.njk +9 -0
  145. package/template/fnode/node/src/cli/index.js.v1.njk +464 -0
  146. package/template/fnode/node/src/cli/v2/core/args-parser.njk +10 -0
  147. package/template/fnode/node/src/cli/v2/core/imports.njk +29 -0
  148. package/template/fnode/node/src/cli/v2/core/run-wrapper.njk +25 -0
  149. package/template/fnode/node/src/cli/v2/index.js.njk +184 -0
  150. package/template/fnode/node/src/cli/v2/modes/default/extend.njk +11 -0
  151. package/template/fnode/node/src/cli/v2/modes/default/standard.njk +19 -0
  152. package/template/fnode/node/src/cli/v2/modes/http/builtin.njk +61 -0
  153. package/template/fnode/node/src/cli/v2/modes/http/imports.njk +9 -0
  154. package/template/fnode/node/src/cli/v2/modes/http/index.njk +12 -0
  155. package/template/fnode/node/src/cli/v2/modes/mcp/imports.njk +33 -0
  156. package/template/fnode/node/src/cli/v2/modes/mcp/index.njk +30 -0
  157. package/template/fnode/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
  158. package/template/fnode/node/src/cli/v2/modes/mcp/tool-handlers.njk +41 -0
  159. package/template/fnode/node/src/cli/v2/modes/mcp/transport-http.njk +212 -0
  160. package/template/fnode/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
  161. package/template/fnode/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
  162. package/template/fnode/node/src/cli/v2/modes/pipeline/index.njk +103 -0
  163. package/template/fnode/node/src/cli/v2/modes/webhook/imports.njk +9 -0
  164. package/template/fnode/node/src/cli/v2/modes/webhook/index.njk +122 -0
  165. package/template/fnode/node/src/cli/v2/modes/websocket/imports.njk +15 -0
  166. package/template/fnode/node/src/cli/v2/modes/websocket/index.njk +99 -0
  167. package/template/fnode/node/src/default/engine.js.njk +17 -0
  168. package/template/fnode/node/src/default/input.args.js.njk +126 -0
  169. package/template/fnode/node/tsconfig.json.njk +16 -0
  170. package/template/fnode/project/.gitignore.njk +11 -0
  171. package/template/fnode/project/.vscode/launch.json.njk +78 -0
  172. package/template/fnode/project/.vscode/tasks.json.njk +46 -0
  173. package/template/fnode/project/fnet/targets.yaml.njk +25 -0
  174. package/template/fnode/project/fnode.yaml.njk +12 -0
  175. package/template/fnode/python/.gitignore.njk +7 -0
  176. package/template/fnode/python/package.json.njk +4 -0
  177. package/template/fnode/python/pyproject.toml.njk +3 -0
  178. package/template/fnode/python/readme.md.njk +12 -0
  179. package/template/fnode/python/setup.py.njk +19 -0
  180. package/template/fnode/python/src/cli/index.py.njk +25 -0
  181. package/template/schemas/to-npm.yaml +14 -0
  182. package/dist/builder/lib-cli.js +0 -2
  183. package/dist/builder/wf-cli.js +0 -2
  184. package/dist/index.js +0 -2
@@ -0,0 +1,109 @@
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
+ // PIPELINE EXECUTION
13
+ const { spawn } = await import('child_process');
14
+
15
+ const pipelineBinary = '{{ context.transform.binaryName }}';
16
+ {% if context.transform.args %}
17
+ const pipelineArgs = {{ context.transform.args | safe }};
18
+ {% else %}
19
+ const pipelineArgs = [];
20
+ {% endif %}
21
+
22
+ {% if context.transform.input %}
23
+ const pipelineInput = {{ context.transform.input | safe }};
24
+ {% else %}
25
+ const pipelineInput = null;
26
+ {% endif %}
27
+
28
+ const pipelineFormat = '{{ context.transform.format }}';
29
+
30
+ {% if context.transform.env %}
31
+ const pipelineEnv = {{ context.transform.env | safe }};
32
+ {% else %}
33
+ const pipelineEnv = {};
34
+ {% endif %}
35
+
36
+ {% if context.transform.cwd %}
37
+ const pipelineCwd = {{ context.transform.cwd | safe }};
38
+ {% else %}
39
+ const pipelineCwd = undefined;
40
+ {% endif %}
41
+
42
+ const result = await new Promise((pipelineResolve, pipelineReject) => {
43
+ const spawnOptions = {
44
+ env: { ...process.env, ...pipelineEnv },
45
+ stdio: ['pipe', 'pipe', 'pipe'] // stdin, stdout, stderr as pipes (don't inherit parent)
46
+ };
47
+
48
+ if (pipelineCwd) {
49
+ spawnOptions.cwd = pipelineCwd;
50
+ }
51
+
52
+ const proc = spawn(pipelineBinary, pipelineArgs, spawnOptions);
53
+
54
+ let stdout = '';
55
+ let stderr = '';
56
+
57
+ proc.stdout.on('data', (data) => {
58
+ stdout += data.toString();
59
+ });
60
+
61
+ proc.stderr.on('data', (data) => {
62
+ stderr += data.toString();
63
+ });
64
+
65
+ proc.on('error', (error) => {
66
+ pipelineReject(new Error(`Failed to execute pipeline '${pipelineBinary}': ${error.message}`));
67
+ });
68
+
69
+ proc.on('close', (code) => {
70
+ if (code !== 0) {
71
+ pipelineReject(new Error(`Pipeline '${pipelineBinary}' exited with code ${code}: ${stderr}`));
72
+ return;
73
+ }
74
+
75
+ // Parse output based on format
76
+ if (pipelineFormat === 'text') {
77
+ // Text format: return as-is
78
+ pipelineResolve(stdout.trim());
79
+ } else {
80
+ // JSON format (default): parse
81
+ try {
82
+ const result = JSON.parse(stdout.trim());
83
+ pipelineResolve(result);
84
+ } catch (error) {
85
+ pipelineReject(new Error(`Failed to parse pipeline output as JSON: ${error.message}`));
86
+ }
87
+ }
88
+ });
89
+
90
+ // Write input based on type (auto-detect)
91
+ if (pipelineInput !== null && pipelineInput !== undefined) {
92
+ if (typeof pipelineInput === 'object') {
93
+ // Object/Array → JSON
94
+ proc.stdin.write(JSON.stringify(pipelineInput) + '\n');
95
+ } else if (typeof pipelineInput === 'string') {
96
+ // String → as-is (text)
97
+ proc.stdin.write(pipelineInput + '\n');
98
+ } else {
99
+ // Other types → JSON
100
+ proc.stdin.write(JSON.stringify(pipelineInput) + '\n');
101
+ }
102
+ }
103
+ proc.stdin.end();
104
+ });
105
+
106
+ {% endcall %}
107
+
108
+ {% call block.footer()%}
109
+ {% endcall %}
@@ -0,0 +1,15 @@
1
+ {% import "src/default/types/block.js.njk" as block with context %}
2
+
3
+ {% call block.header() %}
4
+ {% endcall %}
5
+
6
+ {% call block.definition() %}
7
+
8
+ const raise = {{context.transform.raise | safe}};
9
+
10
+ reject(new Error(raise?.message||raise||"Unknown error"));
11
+
12
+ {% endcall %}
13
+
14
+ {% call block.footer()%}
15
+ {% endcall %}
@@ -0,0 +1,70 @@
1
+ {% set resolve=true %}
2
+
3
+ {% import "src/default/types/block.js.njk" as block with context %}
4
+
5
+ {% call block.header() %}
6
+ {% for child in childs %}
7
+ {% if not child.definition.dynamic %}
8
+ // RETRYABLE CHILD: {{child.indexKey}}
9
+ import {{child.codeKey}} from "./{{child.codeKey}}.js";
10
+ {% endif %}
11
+ {% endfor %}
12
+ {% endcall %}
13
+
14
+ {% call block.definition() %}
15
+ // Retry configuration (always an object)
16
+ const attempts = {{ context.transform.retry.attempts }};
17
+ const initialDelay = {{ context.transform.retry.delay }};
18
+ const backoff = "{{ context.transform.retry.backoff }}";
19
+ const maxDelay = {% if context.transform.retry.maxDelay %}{{ context.transform.retry.maxDelay }}{% else %}null{% endif %};
20
+
21
+ {% if childs[0] %}
22
+ // Create child block instance
23
+ const retryableBlock = new {{childs[0].codeKey}}({
24
+ parent: _this,
25
+ engine: engine,
26
+ flow: flow
27
+ });
28
+
29
+ // Retry logic with backoff
30
+ let lastError;
31
+ let currentDelay = initialDelay;
32
+
33
+ for (let attempt = 1; attempt <= attempts; attempt++) {
34
+ try {
35
+ // Execute child block
36
+ await retryableBlock.run();
37
+
38
+ // Success! Break out of retry loop
39
+ break;
40
+ } catch (error) {
41
+ lastError = error;
42
+
43
+ // Last attempt failed - throw error
44
+ if (attempt === attempts) {
45
+ throw new Error(`Retry failed after ${attempts} attempts: ${error.message}`);
46
+ }
47
+
48
+ // Wait before retry
49
+ await new Promise(resolve => setTimeout(resolve, currentDelay));
50
+
51
+ // Calculate next delay based on backoff strategy
52
+ if (backoff === 'exponential') {
53
+ currentDelay = currentDelay * 2;
54
+ } else if (backoff === 'linear') {
55
+ currentDelay = currentDelay + initialDelay;
56
+ }
57
+ // 'fixed' keeps currentDelay unchanged
58
+
59
+ // Apply maxDelay cap if specified
60
+ if (maxDelay && currentDelay > maxDelay) {
61
+ currentDelay = maxDelay;
62
+ }
63
+ }
64
+ }
65
+ {% endif %}
66
+
67
+ {% endcall %}
68
+
69
+ {% call block.footer()%}
70
+ {% endcall %}
@@ -0,0 +1,21 @@
1
+ {% import "src/default/types/block.js.njk" as block with context %}
2
+
3
+ {% call block.header() %}
4
+ {% endcall %}
5
+
6
+ {% call block.definition() %}
7
+
8
+ {% include "src/default/macros/block-assign.js.njk" %}
9
+
10
+ {% include "src/default/macros/block-signal.js.njk" %}
11
+
12
+ const value = {{context.transform.return | safe}};
13
+
14
+ flow.result={value: value};
15
+
16
+ resolve({type:'return',value: value});
17
+
18
+ {% endcall %}
19
+
20
+ {% call block.footer()%}
21
+ {% endcall %}
@@ -0,0 +1,66 @@
1
+ {% set resolve=true %}
2
+
3
+ {% import "src/default/types/block.js.njk" as block with context %}
4
+
5
+ {% call block.header() %}
6
+ {% for child in childs %}
7
+ {% if not child.definition.dynamic %}
8
+ // SCHEDULED CHILD: {{child.indexKey}}
9
+ import {{child.codeKey}} from "./{{child.codeKey}}.js";
10
+ {% endif %}
11
+ {% endfor %}
12
+ {% endcall %}
13
+
14
+ {% call block.definition() %}
15
+ // Import node-cron for scheduling
16
+ const cron = await import('node-cron');
17
+
18
+ // Schedule configuration
19
+ const cronExpression = {{ context.transform.schedule.cron | safe }};
20
+ const timezone = {{ context.transform.schedule.timezone | dump | safe }};
21
+ const enabled = {{ context.transform.schedule.enabled | dump | safe }};
22
+
23
+ // Check if schedule is enabled
24
+ if (!enabled) {
25
+ // Schedule is disabled, skip to next block
26
+ {% include "src/default/macros/block-next.js.njk" %}
27
+ return;
28
+ }
29
+
30
+ // Validate cron expression
31
+ if (!cron.validate(cronExpression)) {
32
+ reject(new Error(`Invalid cron expression: ${cronExpression}`));
33
+ return;
34
+ }
35
+
36
+ // Get child block (the scheduled task)
37
+ {% if childs[0] %}
38
+ const scheduledTask = new {{childs[0].codeKey}}({
39
+ parent: _this,
40
+ engine: engine,
41
+ flow: flow
42
+ });
43
+ {% endif %}
44
+
45
+ // Schedule the task with optional timezone
46
+ const scheduleOptions = timezone ? { timezone } : {};
47
+ const task = cron.schedule(cronExpression, async () => {
48
+ try {
49
+ {% if childs[0] %}
50
+ await scheduledTask.run();
51
+ {% endif %}
52
+ } catch (error) {
53
+ console.error(`Scheduled task '{{indexKey}}' failed:`, error);
54
+ }
55
+ }, scheduleOptions);
56
+
57
+ // Start the scheduled task
58
+ task.start();
59
+
60
+ // Store task reference for potential cleanup
61
+ flow.set('{{indexKey}}_task', task);
62
+
63
+ {% endcall %}
64
+
65
+ {% call block.footer()%}
66
+ {% endcall %}
@@ -0,0 +1,15 @@
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
+ {% endcall %}
9
+
10
+ {% call block.definition() %}
11
+
12
+ {% endcall %}
13
+
14
+ {% call block.footer()%}
15
+ {% endcall %}
@@ -0,0 +1,47 @@
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
+ {% endcall %}
9
+
10
+ {% call block.definition() %}
11
+
12
+ {% if context.next %}
13
+
14
+ // NEXT : {{context.next.indexKey}}
15
+ {% if context.next.definition.dynamic %}
16
+ const { default: {{context.next.codeKey}} } = await import("./{{context.next.codeKey}}.js");
17
+ {% endif %}
18
+
19
+ let current=new {{context.next.codeKey}}({ parent:_this, engine, flow, caller:c , error });
20
+ let currentArgs=args;
21
+
22
+ do {
23
+
24
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
25
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
26
+ {% endif %}
27
+
28
+ const nextBlock= typeof currentArgs==='undefined'? await current.run()
29
+ : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
30
+
31
+ if(nextBlock?.type==='return') return resolve(nextBlock);
32
+ else if(nextBlock?.type!=='block') break;
33
+
34
+ if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
35
+ return resolve(nextBlock);
36
+
37
+ current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, error });
38
+ currentArgs=nextBlock.input;
39
+
40
+ } while(true);
41
+
42
+ {% endif %}
43
+
44
+ {% endcall %}
45
+
46
+ {% call block.footer()%}
47
+ {% endcall %}
@@ -0,0 +1,49 @@
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
+
9
+ {% for child in childs %}
10
+ {% if not child.definition.dynamic %}
11
+ // CHILD: {{child.indexKey}}
12
+ import {{child.codeKey}} from "./{{child.codeKey}}.js";
13
+ {% endif %}
14
+ {% endfor%}
15
+
16
+ {% endcall %}
17
+
18
+ {% call block.definition() %}
19
+
20
+ {% for child in childs %}
21
+ {% if loop.first %}
22
+ if ({{child.context.transform.condition | safe}})
23
+ {% else %}
24
+ {%if child.context.transform.condition %}
25
+ else if ({{child.context.transform.condition | safe}})
26
+ {% else %}
27
+ else
28
+ {% endif %}
29
+ {% endif %}
30
+ {
31
+ {% if child.definition.dynamic %}
32
+ // CHILD: {{child.indexKey}}
33
+ const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}.js");
34
+ {% endif %}
35
+
36
+ const current=new {{child.codeKey}}({ parent:_this, engine, flow, caller:c, error });
37
+
38
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
39
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
40
+ {% endif %}
41
+
42
+ return resolve(Array.isArray(args)? await current.run.apply(current,args) : await current.run.call(current,args));
43
+ }
44
+ {% endfor%}
45
+
46
+ {% endcall %}
47
+
48
+ {% call block.footer()%}
49
+ {% endcall %}
@@ -0,0 +1,80 @@
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
+ {% for child in childs %}
9
+ {% if not child.definition.dynamic %}
10
+ // CHILD: {{child.indexKey}}
11
+ import {{child.codeKey}} from "./{{child.codeKey}}.js";
12
+ {% endif %}
13
+ {% endfor%}
14
+ {% endcall %}
15
+
16
+ {% call block.definition() %}
17
+
18
+ try{
19
+
20
+ {% if context.try.definition.dynamic %}
21
+ const { default: {{context.try.codeKey}} } = await import("./{{context.try.codeKey}}.js");
22
+ {% endif %}
23
+
24
+ let current=new {{context.try.codeKey}}({ parent:_this, engine, flow, caller:c, error });
25
+ let currentArgs=args;
26
+
27
+ do {
28
+
29
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
30
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
31
+ {% endif %}
32
+
33
+ const nextBlock= typeof currentArgs==='undefined'? await current.run()
34
+ : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
35
+
36
+ if(nextBlock?.type==='return') return resolve(nextBlock);
37
+ else if(nextBlock?.type!=='block') break;
38
+
39
+ if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
40
+ return resolve(nextBlock);
41
+
42
+ current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, error });
43
+ currentArgs=nextBlock.input;
44
+
45
+ } while(true);
46
+ }
47
+ catch(error){
48
+
49
+ {% if context.except.definition.dynamic %}
50
+ const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}.js");
51
+ {% endif %}
52
+
53
+ let current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c , error });
54
+ let currentArgs=args;
55
+
56
+ do {
57
+
58
+ {% if workflow.parent.context.atom.doc.features.print_runners %}
59
+ console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
60
+ {% endif %}
61
+
62
+ const nextBlock= typeof currentArgs==='undefined'? await current.run()
63
+ : Array.isArray(currentArgs)? await current.run.apply(current,currentArgs) : await current.run.call(current, currentArgs) ;
64
+
65
+ if(nextBlock?.type==='return') return resolve(nextBlock);
66
+ else if(nextBlock?.type!=='block') break;
67
+
68
+ if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
69
+ return resolve(nextBlock);
70
+
71
+ current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, error });
72
+ currentArgs=nextBlock.input;
73
+
74
+ } while(true);
75
+ }
76
+
77
+ {% endcall %}
78
+
79
+ {% call block.footer()%}
80
+ {% endcall %}
@@ -0,0 +1,14 @@
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
+ {% endcall %}
9
+
10
+ {% call block.definition() %}
11
+ {% endcall %}
12
+
13
+ {% call block.footer()%}
14
+ {% endcall %}
@@ -0,0 +1,79 @@
1
+ import Object from "../core/object.js";
2
+
3
+ import { default as Workflow } from "./{{flow.codeKey}}.js";
4
+
5
+ {% set form_enabled = false if flow.name === 'cli' else flow.parent.context.atom.doc.features.form_enabled %}
6
+
7
+ {% set form_enabled = false if flow.definition.features.server === true else form_enabled %}
8
+
9
+ {% if form_enabled %}
10
+ import { App } from "{{ui.package}}";
11
+ {% endif %}
12
+
13
+ export default class Engine extends Object {
14
+
15
+ #main;
16
+ {% if form_enabled %}
17
+ #app;
18
+ #appOwner;
19
+ {% endif %}
20
+
21
+ constructor(context) {
22
+ super(context);
23
+
24
+ this.#main = new Workflow({ engine: this });
25
+
26
+ {% if form_enabled %}
27
+ this.#app =context?.app || new App();
28
+ this.#appOwner = !!context?.app;
29
+ {% endif %}
30
+ }
31
+
32
+ async #init(context) {
33
+ {% if form_enabled %}
34
+ await this.#initApp(context);
35
+ {% endif %}
36
+ }
37
+
38
+ {% if form_enabled %}
39
+
40
+ async #initApp(context) {
41
+ const container = context.params?.container;
42
+ await this.#app.init({ container });
43
+ }
44
+
45
+ async setActiveForm(context) {
46
+ const form = context.form;
47
+ const props = context.props;
48
+
49
+ await this.#app.setActiveForm({form,props});
50
+ }
51
+
52
+ get app(){
53
+ return this.#app;
54
+ }
55
+
56
+ {% endif %}
57
+
58
+ // Main entry function to run workflow
59
+ async run(params) {
60
+
61
+ {% if flow.parent.context.atom.doc.features.print_steps %}
62
+ console.log(new Date().toLocaleString(),'{{ flow.parent.context.atom.doc.title or flow.parent.context.atom.doc.name }}');
63
+ {% endif %}
64
+
65
+ await this.#init({ params });
66
+
67
+ const response = await this.#main.run({ params });
68
+
69
+ return response?.value;
70
+ }
71
+
72
+ async destroy() {
73
+ {% if form_enabled %}
74
+ if (this.#appOwner) {
75
+ await this.#app.destroy();
76
+ }
77
+ {% endif %}
78
+ }
79
+ }
@@ -0,0 +1,125 @@
1
+ {% if atom.doc.features.project.format === 'esm' %}
2
+ import fnetArgs,{argsParser} from '@fnet/args';
3
+ import validate,{schema as inputSchema} from "./validate_input.js";
4
+
5
+ {% elif atom.doc.features.project.format === 'cjs' %}
6
+ const {default:fnetArgs,argsParser} = require('@fnet/args');
7
+ const validate,{schema as inputSchema} = require("./validate_input.js");
8
+ {% endif %}
9
+
10
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
11
+
12
+ const get_fargs = (argv) => {
13
+ const fargsIndex = argv.indexOf('--fargs');
14
+ if (fargsIndex !== -1 && argv[fargsIndex + 1]) return argv[fargsIndex + 1];
15
+ {% if atom.doc.features.cli.fargs.default %}
16
+ else return "{{atom.doc.features.cli.fargs.default}}";
17
+ {% endif %}
18
+ };
19
+
20
+ const get_ftags = (argv) => {
21
+ const ftags = [];
22
+ for (let i = 0; i < argv.length; i++) {
23
+ if (argv[i] === '--ftag' && argv[i + 1]) {
24
+ ftags.push(argv[i + 1]);
25
+ i++;
26
+ }
27
+ }
28
+
29
+ {% if atom.doc.features.cli.fargs.tags %}
30
+ return ftags.length > 0 ? ftags : {{atom.doc.features.cli.fargs.tags | dump | safe}};
31
+ {% else %}
32
+ return ftags.length > 0 ? ftags : undefined;
33
+ {% endif %}
34
+ };
35
+
36
+ {% endif %}
37
+
38
+ {% if atom.doc.features.project.format === 'esm' %}
39
+
40
+ export default async () => {
41
+
42
+ let schema = inputSchema;
43
+ let initial;
44
+
45
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
46
+ const fargs = get_fargs(process.argv.slice(2));
47
+ const ftags = get_ftags(process.argv.slice(2));
48
+
49
+ if (fargs) {
50
+ const { default: fnetConfig } = await import("@fnet/config");
51
+ const config = await fnetConfig({ name: fargs, tags: ftags });
52
+ if (config?.data) {
53
+ initial=config.data;
54
+ }
55
+ }
56
+ {% endif %}
57
+
58
+ const packageCallback = async () => {
59
+ const { default: url } = await import("node:url");
60
+ const { default: path } = await import("node:path");
61
+ const { default: fs } = await import("node:fs");
62
+ let currentDir = path.dirname(url.fileURLToPath(import.meta.url));
63
+ let firstPackageJson = path.join(currentDir, "package.json");
64
+ while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
65
+ currentDir = path.dirname(currentDir);
66
+ firstPackageJson = path.join(currentDir, "package.json");
67
+ }
68
+ if (!fs.existsSync(firstPackageJson)) return {
69
+ name: "Unknown",
70
+ version: "Unknown"
71
+ }
72
+ else return await JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
73
+ };
74
+
75
+ return await fnetArgs({schema,initial,validate,packageCallback});
76
+ };
77
+
78
+ export { argsParser };
79
+ {% elif atom.doc.features.project.format === 'cjs' %}
80
+
81
+ module.exports = async () => {
82
+
83
+ let schema = inputSchema;
84
+ let initial;
85
+
86
+ {% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
87
+ const fargs = get_fargs(process.argv.slice(2));
88
+ const ftags = get_ftags(process.argv.slice(2));
89
+
90
+ if (fargs) {
91
+ const { default: fnetConfig } = await import("@fnet/config");
92
+ const config = await fnetConfig({ name: fargs, tags: ftags });
93
+ if (config?.data) {
94
+ initial=config.data;
95
+ }
96
+ }
97
+ {% endif %}
98
+
99
+ const packageCallback = async () => {
100
+ const path = require("node:path");
101
+ const fs = require("node:fs");
102
+
103
+ let currentDir = __dirname;
104
+ let firstPackageJson = path.join(currentDir, "package.json");
105
+
106
+ while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
107
+ currentDir = path.dirname(currentDir);
108
+ firstPackageJson = path.join(currentDir, "package.json");
109
+ }
110
+
111
+ if (!fs.existsSync(firstPackageJson)) {
112
+ return {
113
+ name: "Unknown",
114
+ version: "Unknown"
115
+ };
116
+ } else {
117
+ return JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
118
+ }
119
+ };
120
+
121
+ return await fnetArgs({schema,initial,validate,packageCallback});
122
+ };
123
+
124
+ module.exports.argsParser = argsParser;
125
+ {% endif %}