@powerlines/engine 0.15.18 → 0.15.20

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 (110) hide show
  1. package/dist/api/build.cjs +1 -1
  2. package/dist/api/build.d.mts +2 -2
  3. package/dist/api/build.mjs +1 -1
  4. package/dist/api/clean.d.mts +2 -2
  5. package/dist/api/create.d.mts +2 -2
  6. package/dist/api/deploy.d.mts +2 -2
  7. package/dist/api/docs.d.mts +2 -2
  8. package/dist/api/lint.d.mts +2 -2
  9. package/dist/api/prepare.cjs +2 -2
  10. package/dist/api/prepare.d.mts +2 -2
  11. package/dist/api/prepare.mjs +2 -2
  12. package/dist/api/test.d.mts +2 -2
  13. package/dist/api/types.cjs +2 -2
  14. package/dist/api/types.d.mts +2 -2
  15. package/dist/api/types.mjs +2 -2
  16. package/dist/{api-Cdw4v0W4.d.mts → api-B2dWvRMM.d.mts} +10 -7
  17. package/dist/api-B2dWvRMM.d.mts.map +1 -0
  18. package/dist/{api-6w4hZL6n.d.cts → api-DgxYwNuZ.d.cts} +8 -5
  19. package/dist/api-DgxYwNuZ.d.cts.map +1 -0
  20. package/dist/{execution-host.cjs → api.cjs} +1 -1
  21. package/dist/{execution-host.d.mts → api.d.cts} +3 -3
  22. package/dist/api.d.cts.map +1 -0
  23. package/dist/{execution-host.d.cts → api.d.mts} +3 -3
  24. package/dist/api.d.mts.map +1 -0
  25. package/dist/{execution-host.mjs → api.mjs} +2 -2
  26. package/dist/api.mjs.map +1 -0
  27. package/dist/{config-BNe23XHx.d.mts → config-C9AD-erz.d.mts} +1 -1
  28. package/dist/{config-BNe23XHx.d.mts.map → config-C9AD-erz.d.mts.map} +1 -1
  29. package/dist/context/engine-context.cjs +4 -4
  30. package/dist/context/engine-context.d.cts +1 -1
  31. package/dist/context/engine-context.d.mts +1 -1
  32. package/dist/context/engine-context.mjs +4 -4
  33. package/dist/context/index.d.cts +1 -1
  34. package/dist/context/index.d.mts +1 -1
  35. package/dist/{context-DzgsMSWr.d.mts → context-S3XH2DWP.d.mts} +2 -2
  36. package/dist/{context-DzgsMSWr.d.mts.map → context-S3XH2DWP.d.mts.map} +1 -1
  37. package/dist/engine-DELjWFmN.mjs +564 -0
  38. package/dist/engine-DELjWFmN.mjs.map +1 -0
  39. package/dist/engine-DTKq6gFT.cjs +583 -0
  40. package/dist/{engine-context-Dw8odBCo.d.cts → engine-context-5-_EGiKp.d.cts} +1 -1
  41. package/dist/{engine-context-DEotmVzB.d.mts.map → engine-context-5-_EGiKp.d.cts.map} +1 -1
  42. package/dist/{engine-context-DEotmVzB.d.mts → engine-context-zsn1PoRl.d.mts} +5 -5
  43. package/dist/{engine-context-Dw8odBCo.d.cts.map → engine-context-zsn1PoRl.d.mts.map} +1 -1
  44. package/dist/engine.cjs +4 -266
  45. package/dist/engine.d.cts +3 -3
  46. package/dist/engine.d.cts.map +1 -1
  47. package/dist/engine.d.mts +6 -6
  48. package/dist/engine.d.mts.map +1 -1
  49. package/dist/engine.mjs +2 -263
  50. package/dist/helpers/create-execution-host.cjs +9 -2
  51. package/dist/helpers/create-execution-host.d.cts +20 -2
  52. package/dist/helpers/create-execution-host.d.cts.map +1 -0
  53. package/dist/helpers/create-execution-host.d.mts +20 -2
  54. package/dist/helpers/create-execution-host.d.mts.map +1 -0
  55. package/dist/helpers/create-execution-host.mjs +9 -2
  56. package/dist/helpers/create-execution-host.mjs.map +1 -1
  57. package/dist/helpers/finalize.d.cts +12 -2
  58. package/dist/helpers/finalize.d.cts.map +1 -0
  59. package/dist/helpers/finalize.d.mts +12 -2
  60. package/dist/helpers/finalize.d.mts.map +1 -0
  61. package/dist/helpers/index.cjs +4 -2
  62. package/dist/helpers/index.d.cts +5 -5
  63. package/dist/helpers/index.d.mts +5 -5
  64. package/dist/helpers/index.mjs +2 -2
  65. package/dist/helpers/rpc.cjs +2 -2
  66. package/dist/helpers/rpc.d.cts +7 -2
  67. package/dist/helpers/rpc.d.cts.map +1 -0
  68. package/dist/helpers/rpc.d.mts +7 -2
  69. package/dist/helpers/rpc.d.mts.map +1 -0
  70. package/dist/helpers/rpc.mjs +2 -2
  71. package/dist/helpers/stream.cjs +120 -0
  72. package/dist/helpers/stream.d.cts +45 -0
  73. package/dist/helpers/stream.d.cts.map +1 -0
  74. package/dist/helpers/stream.d.mts +45 -0
  75. package/dist/helpers/stream.d.mts.map +1 -0
  76. package/dist/helpers/stream.mjs +117 -0
  77. package/dist/helpers/stream.mjs.map +1 -0
  78. package/dist/index.cjs +2 -11
  79. package/dist/index.d.cts +3 -7
  80. package/dist/index.d.mts +5 -9
  81. package/dist/index.mjs +2 -7
  82. package/package.json +10 -12
  83. package/dist/api-6w4hZL6n.d.cts.map +0 -1
  84. package/dist/api-Cdw4v0W4.d.mts.map +0 -1
  85. package/dist/create-execution-host-CdpuL_YG.d.mts +0 -20
  86. package/dist/create-execution-host-CdpuL_YG.d.mts.map +0 -1
  87. package/dist/create-execution-host-DbOCE5bd.d.cts +0 -20
  88. package/dist/create-execution-host-DbOCE5bd.d.cts.map +0 -1
  89. package/dist/engine.mjs.map +0 -1
  90. package/dist/execution-host-worker-B8TS4clU.d.mts +0 -68
  91. package/dist/execution-host-worker-B8TS4clU.d.mts.map +0 -1
  92. package/dist/execution-host-worker-BjXO7l3Q.d.cts +0 -68
  93. package/dist/execution-host-worker-BjXO7l3Q.d.cts.map +0 -1
  94. package/dist/execution-host.d.cts.map +0 -1
  95. package/dist/execution-host.d.mts.map +0 -1
  96. package/dist/execution-host.mjs.map +0 -1
  97. package/dist/finalize-CW0cO75l.d.cts +0 -12
  98. package/dist/finalize-CW0cO75l.d.cts.map +0 -1
  99. package/dist/finalize-DeSY1r74.d.mts +0 -12
  100. package/dist/finalize-DeSY1r74.d.mts.map +0 -1
  101. package/dist/helpers/execution-host-worker.cjs +0 -315
  102. package/dist/helpers/execution-host-worker.d.cts +0 -2
  103. package/dist/helpers/execution-host-worker.d.mts +0 -2
  104. package/dist/helpers/execution-host-worker.mjs +0 -314
  105. package/dist/helpers/execution-host-worker.mjs.map +0 -1
  106. package/dist/rpc-BsFxzyAK.d.cts +0 -7
  107. package/dist/rpc-BsFxzyAK.d.cts.map +0 -1
  108. package/dist/rpc-xwbFMMNu.d.mts +0 -7
  109. package/dist/rpc-xwbFMMNu.d.mts.map +0 -1
  110. /package/dist/{index-D_TYgLX3.d.cts → index-DDRpa5CJ.d.cts} +0 -0
@@ -0,0 +1,583 @@
1
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
2
+ const require_helpers_stream = require('./helpers/stream.cjs');
3
+ const require_context_engine_context = require('./context/engine-context.cjs');
4
+ let _stryke_path_append = require("@stryke/path/append");
5
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
6
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
7
+ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
8
+ let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
9
+ let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
10
+ let node_events = require("node:events");
11
+ let node_stream = require("node:stream");
12
+ let devframe_node = require("devframe/node");
13
+ let get_port_please = require("get-port-please");
14
+ let h3 = require("h3");
15
+ let sirv = require("sirv");
16
+ sirv = require_chunk.__toESM(sirv, 1);
17
+ let _powerlines_core_lib_config = require("@powerlines/core/lib/config");
18
+ let _stryke_fs_resolve = require("@stryke/fs/resolve");
19
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
20
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
21
+ let date_fns_formatDuration = require("date-fns/formatDuration");
22
+ let jiti = require("jiti");
23
+ let node_util = require("node:util");
24
+ let node_worker_threads = require("node:worker_threads");
25
+ let piscina = require("piscina");
26
+ piscina = require_chunk.__toESM(piscina, 1);
27
+
28
+ //#region src/_internal/execution-host-worker.ts
29
+ const RESTARTED = Symbol("powerlines-worker:restarted");
30
+ /**
31
+ * Formats the debug address into a string.
32
+ */
33
+ const formatDebugAddress = ({ host, port }) => {
34
+ return host ? `${host}:${port}` : `${port}`;
35
+ };
36
+ /**
37
+ * Get's the debug address from the `NODE_OPTIONS` environment variable. If the
38
+ * address is not found, it returns the default host (`undefined`) and port
39
+ * (`9229`).
40
+ *
41
+ * @returns An object with the host and port of the debug address.
42
+ */
43
+ const getParsedDebugAddress = (address) => {
44
+ if (!address || !(0, _stryke_type_checks_is_string.isString)(address)) return {
45
+ host: void 0,
46
+ port: 9229
47
+ };
48
+ if (address.includes(":")) {
49
+ const [host, port] = address.split(":");
50
+ if (!host || !port) throw new Error(`Invalid debug address: ${address}`);
51
+ return {
52
+ host,
53
+ port: Number.parseInt(port, 10)
54
+ };
55
+ }
56
+ return {
57
+ host: void 0,
58
+ port: Number.parseInt(address, 10)
59
+ };
60
+ };
61
+ /**
62
+ * Get the debug type from the `NODE_OPTIONS` environment variable.
63
+ */
64
+ function getNodeDebugType(nodeOptions) {
65
+ if (nodeOptions.inspect) return "inspect";
66
+ if (nodeOptions["inspect-brk"] || nodeOptions.inspect_brk) return "inspect-brk";
67
+ }
68
+ var ExecutionHostWorker = class ExecutionHostWorker {
69
+ #worker;
70
+ /**
71
+ * Creates a new instance of the ExecutionHostWorker class, which manages a worker process for executing tasks related to the Powerlines Engine. The worker is initialized with the specified options and can be used to run tasks in an isolated environment, with support for automatic restarts and activity monitoring.
72
+ *
73
+ * @param apiPath - The path to the Execution Host file.
74
+ * @param options - The options for configuring the worker, including the execution context, exposed methods, timeout, and mode.
75
+ * @returns A promise that resolves to an instance of the ExecutionHostWorker class.
76
+ */
77
+ static async from(apiPath, options) {
78
+ const mode = await (0, _powerlines_core_lib_config.getDefaultMode)(options.context.cwd);
79
+ const resolvedPath = await (0, _stryke_fs_resolve.resolve)(apiPath, { paths: [options.context.cwd, options.root ? (0, _stryke_path_append.appendPath)(options.root, options.context.cwd) : void 0].filter(Boolean) });
80
+ if (!resolvedPath) throw new Error(`Could not resolve the provided Execution Host path: \`${apiPath}\`.`);
81
+ let exposedMethods = (0, _stryke_convert_to_array.toArray)(options.apiMethods ?? []);
82
+ if (exposedMethods.length === 0) {
83
+ const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href);
84
+ const mod = await jiti$1.import(jiti$1.esmResolve(resolvedPath));
85
+ if ((0, _stryke_type_checks_is_function.isFunction)(mod)) exposedMethods.push(...exposedMethods, "default");
86
+ else if ((0, _stryke_type_checks_is_set_object.isSetObject)(mod)) exposedMethods = Object.keys(mod).filter((name) => (0, _stryke_type_checks_is_function.isFunction)(mod[name]));
87
+ }
88
+ return new ExecutionHostWorker(resolvedPath, exposedMethods, {
89
+ mode,
90
+ ...options
91
+ });
92
+ }
93
+ /**
94
+ * Create a new worker instance.
95
+ *
96
+ * @param executionHostPath - The path to the worker file.
97
+ * @param exposedMethods - An array of method names that the worker exposes.
98
+ * @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.
99
+ */
100
+ constructor(executionHostPath, exposedMethods, options) {
101
+ this.executionHostPath = executionHostPath;
102
+ this.exposedMethods = exposedMethods;
103
+ this.options = options;
104
+ const { timeout = 9e5, isolatedMemory = false, mode = "production", context } = this.options;
105
+ const logger = context.extendLogger({ category: "communication" });
106
+ let restartPromise;
107
+ let resolveRestartPromise;
108
+ let activeTasks = 0;
109
+ this.#worker = void 0;
110
+ process.on("exit", () => {
111
+ this.finalize();
112
+ });
113
+ let nodeOptions = {};
114
+ const args = [...process.execArgv];
115
+ if (process.env.NODE_OPTIONS) {
116
+ let isInString = false;
117
+ let willStartNewArg = true;
118
+ const stringifiedNodeOptions = process.env.NODE_OPTIONS.split(" ").filter((part) => (part.startsWith("\"") && part.endsWith("\"") || part.startsWith("'") && part.endsWith("'")) && part.replace(/^['"]|['"]$/g, "").split(" ").filter(_stryke_type_checks_is_set_string.isSetString).length > 0 && part.replace(/^['"]|['"]$/g, "").split(" ").filter(_stryke_type_checks_is_set_string.isSetString).every((p) => p.startsWith("--")));
119
+ args.push(...stringifiedNodeOptions.map((part) => part.replace(/^['"]|['"]$/g, "")));
120
+ const inputNodeModules = stringifiedNodeOptions.reduce((acc, part) => {
121
+ return acc.replace(part, "").trim();
122
+ }, process.env.NODE_OPTIONS);
123
+ for (let i = 0; i < inputNodeModules.length; i++) {
124
+ let char = inputNodeModules[i];
125
+ if (char) {
126
+ if (char === "\\" && isInString) {
127
+ if (inputNodeModules.length === i + 1) throw new Error("Invalid escape character at the end.");
128
+ char = inputNodeModules[++i];
129
+ if (!char) continue;
130
+ } else if (char === " " && !isInString) {
131
+ willStartNewArg = true;
132
+ continue;
133
+ } else if (char === "\"") {
134
+ isInString = !isInString;
135
+ continue;
136
+ }
137
+ if (willStartNewArg) {
138
+ args.push(char);
139
+ willStartNewArg = false;
140
+ } else args[args.length - 1] += char;
141
+ }
142
+ }
143
+ if (isInString) throw new Error("Unterminated string");
144
+ }
145
+ if (args.length > 0) {
146
+ const { values, tokens } = (0, node_util.parseArgs)({
147
+ args,
148
+ strict: false,
149
+ tokens: true
150
+ });
151
+ nodeOptions = values;
152
+ let orphan = null;
153
+ for (let i = 0; i < tokens.length; i++) {
154
+ const token = tokens[i];
155
+ if (!token) continue;
156
+ if (token.kind === "option-terminator") break;
157
+ if (token.kind === "option") {
158
+ orphan = !(0, _stryke_type_checks_is_set.isSet)(token.value) ? token : null;
159
+ continue;
160
+ }
161
+ if (token.kind !== "positional") {
162
+ orphan = null;
163
+ continue;
164
+ }
165
+ if (!orphan) continue;
166
+ if (orphan.name in nodeOptions && (0, _stryke_type_checks_is_string.isString)(nodeOptions[orphan.name])) nodeOptions[orphan.name] += ` ${token.value}`;
167
+ else nodeOptions[orphan.name] = token.value;
168
+ }
169
+ }
170
+ const originalOptions = { ...nodeOptions };
171
+ delete nodeOptions.inspect;
172
+ delete nodeOptions["inspect-brk"];
173
+ delete nodeOptions.inspect_brk;
174
+ if (mode === "development") {
175
+ const nodeDebugType = getNodeDebugType(originalOptions);
176
+ if (nodeDebugType) {
177
+ const debuggerAddress = getParsedDebugAddress(originalOptions[nodeDebugType]);
178
+ const address = {
179
+ host: debuggerAddress.host,
180
+ port: debuggerAddress.port === 0 ? 0 : debuggerAddress.port + 1 + 1
181
+ };
182
+ nodeOptions[nodeDebugType] = formatDebugAddress(address);
183
+ }
184
+ nodeOptions["enable-source-maps"] = true;
185
+ }
186
+ if (isolatedMemory) {
187
+ delete nodeOptions["max-old-space-size"];
188
+ delete nodeOptions.max_old_space_size;
189
+ }
190
+ const execArgv = [];
191
+ const nodeOptionsParts = [];
192
+ for (const [key, value] of Object.entries(nodeOptions)) {
193
+ let formatted = null;
194
+ if (value === true) formatted = `--${key}`;
195
+ else if (value) formatted = `--${key}=${value.includes(" ") && !value.startsWith("\"") ? JSON.stringify(value) : value}`;
196
+ if (formatted === null) continue;
197
+ if ([
198
+ "experimental-network-inspection",
199
+ "experimental-storage-inspection",
200
+ "experimental-worker-inspection",
201
+ "experimental-inspector-network-resource"
202
+ ].includes(key)) execArgv.push(formatted);
203
+ else nodeOptionsParts.push(formatted);
204
+ }
205
+ const onHanging = () => {
206
+ if (!this.#worker) return;
207
+ const resolve = resolveRestartPromise;
208
+ createWorker();
209
+ logger.warn(`Sending SIGTERM signal to worker due to timeout${timeout ? ` of ${(0, date_fns_formatDuration.formatDuration)({ seconds: timeout / 1e3 })}` : ""}. Subsequent errors may be a result of the worker exiting.`);
210
+ this.finalize().then(() => {
211
+ resolve(RESTARTED);
212
+ });
213
+ };
214
+ let hangingTimer = false;
215
+ const onActivity = () => {
216
+ if (hangingTimer) clearTimeout(hangingTimer);
217
+ hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);
218
+ };
219
+ const createWorker = () => {
220
+ const env = {
221
+ ...process.env,
222
+ NODE_ENV: mode,
223
+ NODE_OPTIONS: nodeOptionsParts.join(" "),
224
+ POWERLINES_EXECUTION_HOST_WORKER: "true"
225
+ };
226
+ if (env.FORCE_COLOR === void 0) {
227
+ if (!env.NO_COLOR && !env.CI && env.TERM !== "dumb" && (process.stdout.isTTY || process.stderr?.isTTY)) env.FORCE_COLOR = "1";
228
+ }
229
+ this.#worker = new piscina.default({
230
+ filename: executionHostPath,
231
+ execArgv,
232
+ env
233
+ });
234
+ restartPromise = new Promise((resolve) => {
235
+ resolveRestartPromise = resolve;
236
+ });
237
+ this.#worker.on("exit", (code, signal) => {
238
+ logger.debug(`Worker process exited with code ${code} and signal ${signal}`);
239
+ if ((code || signal && signal !== "SIGINT") && this.#worker) {
240
+ const error = /* @__PURE__ */ new Error(`Execution Host Worker exited unexpectedly with code ${code} and signal ${signal}`);
241
+ logger.error(error);
242
+ this.finalize().then(() => {
243
+ throw error;
244
+ });
245
+ }
246
+ });
247
+ this.#worker.on("error", (error) => {
248
+ logger.error({
249
+ meta: { category: "communication" },
250
+ message: `Worker process emitted an error: ${error.message}`,
251
+ error
252
+ });
253
+ });
254
+ this.#worker.on("message", (data) => {
255
+ onActivity();
256
+ if (Array.isArray(data) && data.length > 1 && (0, _stryke_type_checks_is_number.isNumber)(data[0])) if (data[0] === 0) logger.trace(`Received message from worker: ${JSON.stringify(data.slice(1), null, 2)}`);
257
+ else logger.debug(`Received error message from worker: ${JSON.stringify(data.slice(1), null, 2)}`);
258
+ logger.trace(`Received message from worker: ${JSON.stringify(data, null, 2)}`);
259
+ });
260
+ };
261
+ createWorker();
262
+ for (const method of this.exposedMethods) {
263
+ if (method.startsWith("_")) continue;
264
+ const callWorker = async (options, inlineConfig) => {
265
+ if (!this.#worker) throw new Error("Execution Host Worker is not initialized");
266
+ const { port1, port2 } = new node_worker_threads.MessageChannel();
267
+ const promise = this.#worker.run({
268
+ options,
269
+ inlineConfig,
270
+ port: port2
271
+ }, {
272
+ name: method,
273
+ transferList: [port2]
274
+ });
275
+ let aborted = false;
276
+ const onActivityAbort = () => {
277
+ if (!aborted) aborted = true;
278
+ };
279
+ (0, node_stream.pipeline)(new require_helpers_stream.MessagePortDuplex(port1, { onActivityAbort }), process.stdout, (err) => {
280
+ if (err) {
281
+ logger.debug(`Received exception message from worker: ${JSON.stringify(err, null, 2)}`);
282
+ throw err;
283
+ }
284
+ });
285
+ await promise;
286
+ };
287
+ this[method] = timeout ? async (options, inlineConfig) => {
288
+ activeTasks++;
289
+ try {
290
+ let attempts = 0;
291
+ for (;;) {
292
+ onActivity();
293
+ const result = await Promise.race([callWorker(options, inlineConfig), restartPromise]);
294
+ if (result !== RESTARTED) return result;
295
+ logger.warn(`Execution Host Worker was restarted while calling method "${method}" (attempt ${attempts++}). Retrying the call...`);
296
+ }
297
+ } finally {
298
+ activeTasks--;
299
+ onActivity();
300
+ }
301
+ } : callWorker.bind(this);
302
+ }
303
+ }
304
+ /**
305
+ * Closes the worker process, terminating it if it's still running. This method should be called when the worker is no longer needed, to free up system resources and ensure a clean shutdown. If the worker has already been terminated, this method will have no effect.
306
+ */
307
+ async finalize() {
308
+ const worker = this.#worker;
309
+ if (!worker) return;
310
+ await worker.close({ force: true });
311
+ this.#worker = void 0;
312
+ }
313
+ };
314
+
315
+ //#endregion
316
+ //#region src/engine.ts
317
+ /**
318
+ * The Powerlines process' orchestration and coordination API.
319
+ *
320
+ * @public
321
+ */
322
+ var PowerlinesEngine = class {
323
+ /**
324
+ * The Powerlines context
325
+ */
326
+ #context;
327
+ /**
328
+ * The execution host, which provides methods to call the execution API functions from the engine context. This allows the engine to invoke commands and other API functions during the execution of Powerlines commands, enabling communication between the engine and the execution contexts.
329
+ */
330
+ #host;
331
+ /**
332
+ * The Powerlines context
333
+ */
334
+ get context() {
335
+ return this.#context;
336
+ }
337
+ /**
338
+ * The execution host, which provides methods to call the execution API functions from the engine context. This allows the engine to invoke commands and other API functions during the execution of Powerlines commands, enabling communication between the engine and the execution contexts.
339
+ */
340
+ get host() {
341
+ return this.#host;
342
+ }
343
+ /**
344
+ * Create a new Powerlines Engine instance
345
+ *
346
+ * @param context - The Powerlines context
347
+ * @param host - The API host for the execution workers
348
+ * @returns A new instance of the Powerlines Engine
349
+ */
350
+ constructor(context, host) {
351
+ this.#context = context;
352
+ this.#host = host;
353
+ }
354
+ /**
355
+ * Create a new Powerlines project
356
+ *
357
+ * @remarks
358
+ * This method will create a new Powerlines project in the current directory.
359
+ *
360
+ * @param inlineConfig - The inline configuration for the create command
361
+ * @returns A promise that resolves when the project has been created
362
+ */
363
+ async create(inlineConfig) {
364
+ const timer = this.context.timer("Create");
365
+ this.context.info("🆕 Creating a new project");
366
+ await this.execute("create", inlineConfig);
367
+ this.context.debug("✔ Create command completed successfully");
368
+ timer();
369
+ }
370
+ /**
371
+ * Generate the Powerlines typescript declaration file
372
+ *
373
+ * @remarks
374
+ * This method will only generate the typescript declaration file for the Powerlines project. It is generally recommended to run the full `prepare` command, which will run this method as part of its process.
375
+ *
376
+ * @param inlineConfig - The inline configuration for the types command
377
+ */
378
+ async types(inlineConfig) {
379
+ const timer = this.context.timer("Types");
380
+ this.context.info("🏗️ Generating typescript declarations for the project");
381
+ await this.execute("types", inlineConfig);
382
+ this.context.debug("✔ Types generation has completed successfully");
383
+ timer();
384
+ }
385
+ /**
386
+ * Prepare the Powerlines API
387
+ *
388
+ * @remarks
389
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
390
+ *
391
+ * @param inlineConfig - The inline configuration for the prepare command
392
+ */
393
+ async prepare(inlineConfig) {
394
+ const timer = this.context.timer("Prepare");
395
+ this.context.info("🏗️ Preparing the project");
396
+ await this.execute("prepare", inlineConfig);
397
+ this.context.debug("✔ Preparation has completed successfully");
398
+ timer();
399
+ }
400
+ /**
401
+ * Clean any previously prepared artifacts
402
+ *
403
+ * @remarks
404
+ * This method will remove the previous Powerlines artifacts from the project.
405
+ *
406
+ * @param inlineConfig - The inline configuration for the clean command
407
+ * @returns A promise that resolves when the clean command has completed
408
+ */
409
+ async clean(inlineConfig) {
410
+ const timer = this.context.timer("Clean");
411
+ this.context.info("🧹 Cleaning the previous artifacts");
412
+ await this.execute("clean", inlineConfig);
413
+ this.context.debug("✔ Cleaning completed successfully");
414
+ timer();
415
+ }
416
+ /**
417
+ * Lint the project
418
+ *
419
+ * @param inlineConfig - The inline configuration for the lint command
420
+ * @returns A promise that resolves when the lint command has completed
421
+ */
422
+ async lint(inlineConfig) {
423
+ const timer = this.context.timer("Lint");
424
+ this.context.info("📝 Linting the project");
425
+ await this.execute("lint", inlineConfig);
426
+ this.context.debug("✔ Linting completed successfully");
427
+ timer();
428
+ }
429
+ /**
430
+ * Test the project
431
+ *
432
+ * @remarks
433
+ * This method will run the tests for the Powerlines project.
434
+ *
435
+ * @param inlineConfig - The inline configuration for the test command
436
+ * @returns A promise that resolves when the test command has completed
437
+ */
438
+ async test(inlineConfig) {
439
+ const timer = this.context.timer("Test");
440
+ this.context.info("🧪 Running tests for the project");
441
+ await this.execute("test", inlineConfig);
442
+ this.context.debug("✔ Testing completed successfully");
443
+ timer();
444
+ }
445
+ /**
446
+ * Build the project
447
+ *
448
+ * @remarks
449
+ * This method will build the Powerlines project, generating the necessary artifacts.
450
+ *
451
+ * @param inlineConfig - The inline configuration for the build command
452
+ * @returns A promise that resolves when the build command has completed
453
+ */
454
+ async build(inlineConfig) {
455
+ const timer = this.context.timer("Build");
456
+ this.context.info("📦 Building the project");
457
+ await this.execute("build", inlineConfig);
458
+ this.context.debug("✔ Build completed successfully");
459
+ timer();
460
+ }
461
+ /**
462
+ * Prepare the documentation for the project
463
+ *
464
+ * @param inlineConfig - The inline configuration for the docs command
465
+ * @returns A promise that resolves when the documentation generation has completed
466
+ */
467
+ async docs(inlineConfig) {
468
+ const timer = this.context.timer("Docs");
469
+ this.context.info("📓 Generating documentation for the project");
470
+ await this.execute("docs", inlineConfig);
471
+ this.context.debug("✔ Documentation generation completed successfully");
472
+ timer();
473
+ }
474
+ /**
475
+ * Deploy the project source code
476
+ *
477
+ * @remarks
478
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
479
+ *
480
+ * @param inlineConfig - The inline configuration for the deploy command
481
+ * @returns A promise that resolves when the deploy command has completed
482
+ */
483
+ async deploy(inlineConfig) {
484
+ const timer = this.context.timer("Deploy");
485
+ this.context.info("🚀 Deploying the project");
486
+ await this.execute("deploy", inlineConfig);
487
+ this.context.debug("✔ Deployment completed successfully");
488
+ timer();
489
+ }
490
+ /**
491
+ * Finalization/cleanup processing for the Powerlines API
492
+ *
493
+ * @remarks
494
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
495
+ *
496
+ * @returns A promise that resolves when the finalization process has completed
497
+ */
498
+ async finalize() {
499
+ const timer = this.context.timer("Finalize");
500
+ this.context.info("🏁 Finalization processes started");
501
+ await this.host.finalize();
502
+ this.context.debug("✔ Finalization completed successfully");
503
+ timer();
504
+ }
505
+ /**
506
+ * Asynchronous disposal method for the Powerlines Engine, which will call the finalize method to perform any necessary cleanup when the engine is disposed of.
507
+ */
508
+ async [Symbol.asyncDispose]() {
509
+ return this.finalize();
510
+ }
511
+ /**
512
+ * Execute a Powerlines command based on the provided execution path and inline configuration, loading the necessary executions from the context and managing their lifecycle.
513
+ *
514
+ * @remarks
515
+ * This method will load the executions for the specified command and inline configuration, then execute each one while managing their lifecycle, including handling their completion and any errors that may occur during execution.
516
+ *
517
+ * @param method - The path to the execution configuration to load and run, which can be used to specify different execution configurations for different commands or scenarios.
518
+ * @param inlineConfig - Additional configuration options provided at runtime, which can override or supplement the options defined in the user configuration file.
519
+ * @returns A promise that resolves when all executions for the specified command have completed
520
+ */
521
+ async execute(method, inlineConfig) {
522
+ await Promise.all((await this.context.loadExecutions(method, inlineConfig)).map(async (execution) => {
523
+ try {
524
+ await this.host[method](execution.options, inlineConfig);
525
+ } catch (error) {
526
+ this.context.error(`Execution of method "${method}" failed for execution with invocation ID "${execution.invocationId}" and execution ID "${execution.options.executionId}": \n\n${error instanceof Error ? error.stack || error.message : String(error)}`);
527
+ throw error;
528
+ } finally {
529
+ this.context.completeExecution(execution.invocationId, execution.options.executionId);
530
+ }
531
+ }));
532
+ }
533
+ };
534
+ async function createContext(options) {
535
+ const port = options.port ?? await (0, get_port_please.getPort)({
536
+ host: options.host || "localhost",
537
+ random: true
538
+ });
539
+ const app = (0, h3.createApp)();
540
+ const host = (0, devframe_node.createH3DevToolsHost)({
541
+ appName: options.framework?.name || "powerlines",
542
+ origin: `http://${options.host || "localhost"}:${port}`,
543
+ mount: (base, dir) => {
544
+ app.use(base, (0, h3.fromNodeMiddleware)((0, sirv.default)(dir, {
545
+ dev: true,
546
+ single: true
547
+ })));
548
+ }
549
+ });
550
+ return require_context_engine_context.PowerlinesEngineContext.from(options, host, {
551
+ backend: "websocket",
552
+ websocket: port
553
+ });
554
+ }
555
+ async function createEngine(options, apiPath = "@powerlines/engine/api", apiMethods) {
556
+ node_events.EventEmitter.setMaxListeners(Infinity);
557
+ const context = await createContext(options);
558
+ return new PowerlinesEngine(context, await ExecutionHostWorker.from(apiPath, {
559
+ root: options.root,
560
+ context,
561
+ apiMethods
562
+ }));
563
+ }
564
+
565
+ //#endregion
566
+ Object.defineProperty(exports, 'PowerlinesEngine', {
567
+ enumerable: true,
568
+ get: function () {
569
+ return PowerlinesEngine;
570
+ }
571
+ });
572
+ Object.defineProperty(exports, 'createContext', {
573
+ enumerable: true,
574
+ get: function () {
575
+ return createContext;
576
+ }
577
+ });
578
+ Object.defineProperty(exports, 'createEngine', {
579
+ enumerable: true,
580
+ get: function () {
581
+ return createEngine;
582
+ }
583
+ });
@@ -51,4 +51,4 @@ declare class PowerlinesEngineContext<TSystemContext = unknown> extends Powerlin
51
51
  }
52
52
  //#endregion
53
53
  export { PowerlinesEngineContext as t };
54
- //# sourceMappingURL=engine-context-Dw8odBCo.d.cts.map
54
+ //# sourceMappingURL=engine-context-5-_EGiKp.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine-context-DEotmVzB.d.mts","names":[],"sources":["../src/context/engine-context.ts"],"mappings":";;;;;;;;;cAmDa,uBAAA,mCACH,qBAAA,CAAsB,cAAA,aACnB,aAAA,CAAc,cAAA;EAAA;EAkIP,OAAA,EAAS,aAAA;EAClB,UAAA,EAAY,cAAA;EArIa;;;;;;EAAA,OAgBd,I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;EAvCuD;;;;;;EAAA,UAiDzD,WAAA,CACS,OAAA,EAAS,aAAA,EAClB,UAAA,EAAY,cAAA;EAAA;;;;;;;;;EAcR,cAAA,CACX,MAAA,UACA,YAAA,EAAc,YAAA,GACb,OAAA,CAAQ,mBAAA;EArJmB;;;;;;EAyNvB,iBAAA,CAAkB,YAAA,UAAsB,WAAA;AAAA"}
@@ -1,9 +1,9 @@
1
- import { n as EngineOptions } from "./config-BNe23XHx.mjs";
2
- import { n as EngineExecutionItem, t as EngineContext } from "./context-DzgsMSWr.mjs";
3
- import { PowerlinesBaseContext } from "@powerlines/core/context/base-context";
4
- import { EnvPaths } from "@stryke/env/get-env-paths";
1
+ import { n as EngineOptions } from "./config-C9AD-erz.mjs";
2
+ import { n as EngineExecutionItem, t as EngineContext } from "./context-S3XH2DWP.mjs";
5
3
  import * as _$_powerlines_core0 from "@powerlines/core";
6
4
  import { FrameworkOptions, InlineConfig, LogFn, LoggerOptions } from "@powerlines/core";
5
+ import { PowerlinesBaseContext } from "@powerlines/core/context/base-context";
6
+ import { EnvPaths } from "@stryke/env/get-env-paths";
7
7
  import { ConnectionMeta, DevToolsHost, DevToolsNodeContext } from "devframe/types";
8
8
 
9
9
  //#region src/context/engine-context.d.ts
@@ -51,4 +51,4 @@ declare class PowerlinesEngineContext<TSystemContext = unknown> extends Powerlin
51
51
  }
52
52
  //#endregion
53
53
  export { PowerlinesEngineContext as t };
54
- //# sourceMappingURL=engine-context-DEotmVzB.d.mts.map
54
+ //# sourceMappingURL=engine-context-zsn1PoRl.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine-context-Dw8odBCo.d.cts","names":[],"sources":["../src/context/engine-context.ts"],"mappings":";;;;;;;;;cAmDa,uBAAA,mCACH,qBAAA,CAAsB,cAAA,aACnB,aAAA,CAAc,cAAA;EAAA;EAkIP,OAAA,EAAS,aAAA;EAClB,UAAA,EAAY,cAAA;EArIa;;;;;;EAAA,OAgBd,IAAA,0BAAA,CAClB,OAAA,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