@powerlines/engine 0.47.3 → 0.49.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/api/build.cjs +66 -0
  2. package/dist/api/build.d.cts +14 -0
  3. package/dist/api/build.d.cts.map +1 -0
  4. package/dist/api/build.d.mts +14 -0
  5. package/dist/api/build.d.mts.map +1 -0
  6. package/dist/api/build.mjs +64 -0
  7. package/dist/api/build.mjs.map +1 -0
  8. package/dist/api/clean.cjs +28 -0
  9. package/dist/api/clean.d.cts +14 -0
  10. package/dist/api/clean.d.cts.map +1 -0
  11. package/dist/api/clean.d.mts +14 -0
  12. package/dist/api/clean.d.mts.map +1 -0
  13. package/dist/api/clean.mjs +28 -0
  14. package/dist/api/clean.mjs.map +1 -0
  15. package/dist/api/create.cjs +59 -0
  16. package/dist/api/create.d.cts +14 -0
  17. package/dist/api/create.d.cts.map +1 -0
  18. package/dist/api/create.d.mts +14 -0
  19. package/dist/api/create.d.mts.map +1 -0
  20. package/dist/api/create.mjs +57 -0
  21. package/dist/api/create.mjs.map +1 -0
  22. package/dist/api/deploy.cjs +24 -0
  23. package/dist/api/deploy.d.cts +17 -0
  24. package/dist/api/deploy.d.cts.map +1 -0
  25. package/dist/api/deploy.d.mts +17 -0
  26. package/dist/api/deploy.d.mts.map +1 -0
  27. package/dist/api/deploy.mjs +24 -0
  28. package/dist/api/deploy.mjs.map +1 -0
  29. package/dist/api/docs.cjs +24 -0
  30. package/dist/api/docs.d.cts +17 -0
  31. package/dist/api/docs.d.cts.map +1 -0
  32. package/dist/api/docs.d.mts +17 -0
  33. package/dist/api/docs.d.mts.map +1 -0
  34. package/dist/api/docs.mjs +24 -0
  35. package/dist/api/docs.mjs.map +1 -0
  36. package/dist/api/lint.cjs +27 -0
  37. package/dist/api/lint.d.cts +17 -0
  38. package/dist/api/lint.d.cts.map +1 -0
  39. package/dist/api/lint.d.mts +17 -0
  40. package/dist/api/lint.d.mts.map +1 -0
  41. package/dist/api/lint.mjs +27 -0
  42. package/dist/api/lint.mjs.map +1 -0
  43. package/dist/api/prepare.cjs +68 -0
  44. package/dist/api/prepare.d.cts +14 -0
  45. package/dist/api/prepare.d.cts.map +1 -0
  46. package/dist/api/prepare.d.mts +14 -0
  47. package/dist/api/prepare.d.mts.map +1 -0
  48. package/dist/api/prepare.mjs +68 -0
  49. package/dist/api/prepare.mjs.map +1 -0
  50. package/dist/api/test.cjs +27 -0
  51. package/dist/api/test.d.cts +17 -0
  52. package/dist/api/test.d.cts.map +1 -0
  53. package/dist/api/test.d.mts +17 -0
  54. package/dist/api/test.d.mts.map +1 -0
  55. package/dist/api/test.mjs +27 -0
  56. package/dist/api/test.mjs.map +1 -0
  57. package/dist/api/types.cjs +70 -0
  58. package/dist/api/types.d.cts +17 -0
  59. package/dist/api/types.d.cts.map +1 -0
  60. package/dist/api/types.d.mts +17 -0
  61. package/dist/api/types.d.mts.map +1 -0
  62. package/dist/api/types.mjs +70 -0
  63. package/dist/api/types.mjs.map +1 -0
  64. package/dist/api-BgyEi2hF.d.mts +138 -0
  65. package/dist/api-BgyEi2hF.d.mts.map +1 -0
  66. package/dist/api-DcHfCjQK.d.cts +138 -0
  67. package/dist/api-DcHfCjQK.d.cts.map +1 -0
  68. package/dist/api.cjs +39 -1268
  69. package/dist/api.d.cts +11 -300
  70. package/dist/api.d.cts.map +1 -1
  71. package/dist/api.d.mts +11 -300
  72. package/dist/api.d.mts.map +1 -1
  73. package/dist/api.mjs +31 -1264
  74. package/dist/api.mjs.map +1 -1
  75. package/dist/config-ByLyzMI0.d.mts +204 -0
  76. package/dist/config-ByLyzMI0.d.mts.map +1 -0
  77. package/dist/config-DKEmqMrh.d.cts +204 -0
  78. package/dist/config-DKEmqMrh.d.cts.map +1 -0
  79. package/dist/context/engine-context.cjs +177 -0
  80. package/dist/context/engine-context.d.cts +2 -0
  81. package/dist/context/engine-context.d.mts +2 -0
  82. package/dist/context/engine-context.mjs +175 -0
  83. package/dist/context/engine-context.mjs.map +1 -0
  84. package/dist/context/index.cjs +2 -9
  85. package/dist/context/index.d.cts +2 -150
  86. package/dist/context/index.d.mts +2 -150
  87. package/dist/context/index.mjs +2 -4
  88. package/dist/context-D0_a0kRO.d.cts +149 -0
  89. package/dist/context-D0_a0kRO.d.cts.map +1 -0
  90. package/dist/context-DcXV6_GL.d.mts +149 -0
  91. package/dist/context-DcXV6_GL.d.mts.map +1 -0
  92. package/dist/engine-Dz6BvkFY.cjs +590 -0
  93. package/dist/engine-context-B8K6Jtkk.d.cts +53 -0
  94. package/dist/engine-context-B8K6Jtkk.d.cts.map +1 -0
  95. package/dist/engine-context-DKlA5Pgu.d.mts +53 -0
  96. package/dist/engine-context-DKlA5Pgu.d.mts.map +1 -0
  97. package/dist/engine-q6YKXXcB.mjs +571 -0
  98. package/dist/engine-q6YKXXcB.mjs.map +1 -0
  99. package/dist/engine.cjs +6 -0
  100. package/dist/engine.d.cts +143 -0
  101. package/dist/engine.d.cts.map +1 -0
  102. package/dist/engine.d.mts +143 -0
  103. package/dist/engine.d.mts.map +1 -0
  104. package/dist/engine.mjs +3 -0
  105. package/dist/helpers/create-execution-host.cjs +57 -0
  106. package/dist/helpers/create-execution-host.d.cts +20 -0
  107. package/dist/helpers/create-execution-host.d.cts.map +1 -0
  108. package/dist/helpers/create-execution-host.d.mts +20 -0
  109. package/dist/helpers/create-execution-host.d.mts.map +1 -0
  110. package/dist/helpers/create-execution-host.mjs +57 -0
  111. package/dist/helpers/create-execution-host.mjs.map +1 -0
  112. package/dist/helpers/finalize.cjs +26 -0
  113. package/dist/helpers/finalize.d.cts +12 -0
  114. package/dist/helpers/finalize.d.cts.map +1 -0
  115. package/dist/helpers/finalize.d.mts +12 -0
  116. package/dist/helpers/finalize.d.mts.map +1 -0
  117. package/dist/helpers/finalize.mjs +26 -0
  118. package/dist/helpers/finalize.mjs.map +1 -0
  119. package/dist/helpers/index.cjs +12 -0
  120. package/dist/helpers/index.d.cts +5 -0
  121. package/dist/helpers/index.d.mts +5 -0
  122. package/dist/helpers/index.mjs +6 -0
  123. package/dist/helpers/rpc.cjs +139 -0
  124. package/dist/helpers/rpc.d.cts +7 -0
  125. package/dist/helpers/rpc.d.cts.map +1 -0
  126. package/dist/helpers/rpc.d.mts +7 -0
  127. package/dist/helpers/rpc.d.mts.map +1 -0
  128. package/dist/helpers/rpc.mjs +139 -0
  129. package/dist/helpers/rpc.mjs.map +1 -0
  130. package/dist/helpers/stream.cjs +119 -0
  131. package/dist/helpers/stream.d.cts +45 -0
  132. package/dist/helpers/stream.d.cts.map +1 -0
  133. package/dist/helpers/stream.d.mts +45 -0
  134. package/dist/helpers/stream.d.mts.map +1 -0
  135. package/dist/helpers/stream.mjs +117 -0
  136. package/dist/helpers/stream.mjs.map +1 -0
  137. package/dist/index-BVVgDSdq.d.cts +1 -0
  138. package/dist/index-BVVgDSdq.d.mts +1 -0
  139. package/dist/index.cjs +8 -748
  140. package/dist/index.d.cts +6 -140
  141. package/dist/index.d.mts +6 -140
  142. package/dist/index.mjs +4 -747
  143. package/package.json +102 -132
  144. package/dist/_internal/worker.cjs +0 -5192
  145. package/dist/_internal/worker.d.cts +0 -46
  146. package/dist/_internal/worker.d.cts.map +0 -1
  147. package/dist/_internal/worker.d.mts +0 -46
  148. package/dist/_internal/worker.d.mts.map +0 -1
  149. package/dist/_internal/worker.mjs +0 -5153
  150. package/dist/_internal/worker.mjs.map +0 -1
  151. package/dist/base-context-DLemGRbd.cjs +0 -322
  152. package/dist/base-context-DUha4Lz-.mjs +0 -315
  153. package/dist/base-context-DUha4Lz-.mjs.map +0 -1
  154. package/dist/context/index.d.cts.map +0 -1
  155. package/dist/context/index.d.mts.map +0 -1
  156. package/dist/engine-context-BfFiKN53.mjs +0 -86
  157. package/dist/engine-context-BfFiKN53.mjs.map +0 -1
  158. package/dist/engine-context-D0y88i_J.cjs +0 -91
  159. package/dist/execution-context-CE5H90Um.mjs +0 -2845
  160. package/dist/execution-context-CE5H90Um.mjs.map +0 -1
  161. package/dist/execution-context-CnyaM3Ul.cjs +0 -2889
  162. package/dist/execution-context-NyDjVZ6T.d.cts +0 -647
  163. package/dist/execution-context-NyDjVZ6T.d.cts.map +0 -1
  164. package/dist/execution-context-YrjFeD9k.d.mts +0 -647
  165. package/dist/execution-context-YrjFeD9k.d.mts.map +0 -1
  166. package/dist/fs-CeEdzPKE.cjs +0 -262
  167. package/dist/fs-Dcle8lUp.mjs +0 -226
  168. package/dist/fs-Dcle8lUp.mjs.map +0 -1
  169. package/dist/index.d.cts.map +0 -1
  170. package/dist/index.d.mts.map +0 -1
  171. package/dist/index.mjs.map +0 -1
  172. package/dist/rpc/client.cjs +0 -74
  173. package/dist/rpc/client.d.cts +0 -31
  174. package/dist/rpc/client.d.cts.map +0 -1
  175. package/dist/rpc/client.d.mts +0 -31
  176. package/dist/rpc/client.d.mts.map +0 -1
  177. package/dist/rpc/client.mjs +0 -71
  178. package/dist/rpc/client.mjs.map +0 -1
  179. package/dist/rpc/serialization.cjs +0 -82
  180. package/dist/rpc/serialization.d.cts +0 -46
  181. package/dist/rpc/serialization.d.cts.map +0 -1
  182. package/dist/rpc/serialization.d.mts +0 -46
  183. package/dist/rpc/serialization.d.mts.map +0 -1
  184. package/dist/rpc/serialization.mjs +0 -76
  185. package/dist/rpc/serialization.mjs.map +0 -1
  186. package/dist/rpc/server.cjs +0 -69
  187. package/dist/rpc/server.d.cts +0 -29
  188. package/dist/rpc/server.d.cts.map +0 -1
  189. package/dist/rpc/server.d.mts +0 -29
  190. package/dist/rpc/server.d.mts.map +0 -1
  191. package/dist/rpc/server.mjs +0 -66
  192. package/dist/rpc/server.mjs.map +0 -1
  193. package/dist/rpc/types.cjs +0 -0
  194. package/dist/rpc/types.d.cts +0 -70
  195. package/dist/rpc/types.d.cts.map +0 -1
  196. package/dist/rpc/types.d.mts +0 -70
  197. package/dist/rpc/types.d.mts.map +0 -1
  198. package/dist/rpc/types.mjs +0 -1
  199. package/dist/schemas.cjs +0 -9
  200. package/dist/schemas.d.cts +0 -127
  201. package/dist/schemas.d.cts.map +0 -1
  202. package/dist/schemas.d.mts +0 -127
  203. package/dist/schemas.d.mts.map +0 -1
  204. package/dist/schemas.mjs +0 -3
  205. package/dist/storage/base.cjs +0 -216
  206. package/dist/storage/base.d.cts +0 -199
  207. package/dist/storage/base.d.cts.map +0 -1
  208. package/dist/storage/base.d.mts +0 -199
  209. package/dist/storage/base.d.mts.map +0 -1
  210. package/dist/storage/base.mjs +0 -215
  211. package/dist/storage/base.mjs.map +0 -1
  212. package/dist/storage/file-system.cjs +0 -180
  213. package/dist/storage/file-system.d.cts +0 -127
  214. package/dist/storage/file-system.d.cts.map +0 -1
  215. package/dist/storage/file-system.d.mts +0 -127
  216. package/dist/storage/file-system.d.mts.map +0 -1
  217. package/dist/storage/file-system.mjs +0 -179
  218. package/dist/storage/file-system.mjs.map +0 -1
  219. package/dist/storage/helpers.cjs +0 -37
  220. package/dist/storage/helpers.d.cts +0 -25
  221. package/dist/storage/helpers.d.cts.map +0 -1
  222. package/dist/storage/helpers.d.mts +0 -25
  223. package/dist/storage/helpers.d.mts.map +0 -1
  224. package/dist/storage/helpers.mjs +0 -34
  225. package/dist/storage/helpers.mjs.map +0 -1
  226. package/dist/storage/index.cjs +0 -12
  227. package/dist/storage/index.d.cts +0 -5
  228. package/dist/storage/index.d.mts +0 -5
  229. package/dist/storage/index.mjs +0 -6
  230. package/dist/storage/virtual.cjs +0 -98
  231. package/dist/storage/virtual.d.cts +0 -80
  232. package/dist/storage/virtual.d.cts.map +0 -1
  233. package/dist/storage/virtual.d.mts +0 -80
  234. package/dist/storage/virtual.d.mts.map +0 -1
  235. package/dist/storage/virtual.mjs +0 -97
  236. package/dist/storage/virtual.mjs.map +0 -1
  237. package/dist/ts-morph-BbM83PT9.cjs +0 -114
  238. package/dist/ts-morph-C6YBNc46.mjs +0 -102
  239. package/dist/ts-morph-C6YBNc46.mjs.map +0 -1
  240. package/dist/tsconfig-DeKMGasE.cjs +0 -198
  241. package/dist/tsconfig-HzJsMUrr.mjs +0 -155
  242. package/dist/tsconfig-HzJsMUrr.mjs.map +0 -1
  243. package/dist/typescript/index.cjs +0 -13
  244. package/dist/typescript/index.d.cts +0 -106
  245. package/dist/typescript/index.d.cts.map +0 -1
  246. package/dist/typescript/index.d.mts +0 -106
  247. package/dist/typescript/index.d.mts.map +0 -1
  248. package/dist/typescript/index.mjs +0 -4
  249. /package/dist/{chunk-C0xms8kb.cjs → chunk-C_NdSu1c.cjs} +0 -0
@@ -0,0 +1,204 @@
1
+ import { CustomLogger, ExecutionOptions, FrameworkOptions, LogMeta, Options, ResolvedConfig, UserConfig } from "@powerlines/core";
2
+ import { MaybePromise, PartialKeys, RequiredKeys } from "@stryke/types/base";
3
+ import { BirpcOptions, BirpcReturn, ProxifiedRemoteFunctions } from "birpc";
4
+ import { RpcCacheManager, RpcCacheOptions, RpcFunctionsCollector } from "devframe/rpc";
5
+ import { WsRpcChannelOptions } from "devframe/rpc/transports/ws-client";
6
+ import { ConnectionMeta, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevframeDefinition, EventEmitter, RpcSharedStateHost } from "devframe/types";
7
+ import { Asyncify } from "@stryke/types/async";
8
+ import { RpcStreamingClientHost } from "devframe/client";
9
+
10
+ //#region src/types/rpc.d.ts
11
+ interface RpcPayloadMetadata {
12
+ /**
13
+ * A unique identifier for correlating related Rpc messages, which can be used to group messages that belong to the same logical operation or workflow across different parts of the system. This is a required field and should be generated by the sender of the message.
14
+ */
15
+ messageId: string;
16
+ /**
17
+ * The type of the Rpc message, which indicates the purpose of the message and how it should be handled by the receiving end. This is a required field and must be one of the predefined values in the IpcMessageType enum.
18
+ */
19
+ type: string;
20
+ /**
21
+ * The timestamp when the Rpc message was created, represented as the number of milliseconds since the Unix epoch.
22
+ */
23
+ timestamp: number;
24
+ /**
25
+ * A unique identifier for the current execution instance, which can be used for logging and other purposes to distinguish between different executions in the same process.
26
+ */
27
+ executionId?: string;
28
+ /**
29
+ * The zero-based index of the current execution within the sequence of executions in the same process.
30
+ */
31
+ configIndex?: number;
32
+ /**
33
+ * Optional environment identifier to specify the context or environment in which the message is being processed.
34
+ */
35
+ environment?: string;
36
+ }
37
+ interface RpcPayloadEnvelop<TPayload> extends RpcPayloadMetadata {
38
+ /**
39
+ * The payload data associated with the Rpc message, typed according to the message type.
40
+ */
41
+ payload: TPayload;
42
+ }
43
+ type RpcFunction = (payload: any) => MaybePromise<any>;
44
+ type RpcFunctions = Record<string, RpcFunction>;
45
+ type InputRpcFunction = (envelop: RpcPayloadEnvelop<any>) => any;
46
+ type InputRpcFunctions = Record<string, InputRpcFunction>;
47
+ type WrappedRpcFunction = (envelop: RpcPayloadEnvelop<any>) => Promise<any>;
48
+ type WrappedRpcFunctions = Record<string, WrappedRpcFunction>;
49
+ type ExtractRpcFunction<TFunction extends WrappedRpcFunction> = (payload: Parameters<TFunction>[0]["payload"]) => ReturnType<Asyncify<TFunction>>;
50
+ type ExtractRpcFunctions<TFunctions extends WrappedRpcFunctions> = { [TKey in keyof TFunctions]: ExtractRpcFunction<TFunctions[TKey]> };
51
+ type WrapRpcFunction<TFunction extends RpcFunction> = (envelop: RpcPayloadEnvelop<Parameters<TFunction>[0]>) => ReturnType<TFunction> extends Promise<infer A> ? A : ReturnType<TFunction>;
52
+ type WrapRpcFunctions<TFunctions extends RpcFunctions> = { [TKey in keyof TFunctions]: WrapRpcFunction<TFunctions[TKey]> };
53
+ type RpcClientRemoteFunctions<TFunctions extends WrappedRpcFunctions> = ProxifiedRemoteFunctions<ExtractRpcFunctions<TFunctions>>;
54
+ /**
55
+ * Payload for write log Rpc messages.
56
+ */
57
+ interface LogPayload {
58
+ /**
59
+ * Metadata associated with the log message, excluding fields that are automatically added by the engine such as executionId, configIndex, environment, and timestamp. This can include custom fields relevant to the log entry, such as category, name, command, hook, plugin, and source.
60
+ */
61
+ meta: LogMeta;
62
+ /**
63
+ * The log message content, which can be a string or an array of strings representing the log entry. This field is required and should contain the actual message to be logged.
64
+ */
65
+ message: string;
66
+ }
67
+ interface RpcServerFunctions extends DevToolsRpcServerFunctions {
68
+ "powerlines:log": (payload: LogPayload) => void;
69
+ }
70
+ interface RpcClientFunctions extends DevToolsRpcClientFunctions {}
71
+ interface RpcContext {
72
+ /**
73
+ * The Rpc client to interact with the server
74
+ */
75
+ readonly rpc: RpcClient;
76
+ }
77
+ type RpcClientHost = RpcFunctionsCollector<RpcClientFunctions, RpcContext>;
78
+ type RpcClientCall = BirpcReturn<RpcServerFunctions, RpcClientFunctions>["$call"];
79
+ type RpcClientCallEvent = BirpcReturn<RpcServerFunctions, RpcClientFunctions>["$callEvent"];
80
+ type RpcClientCallOptional = BirpcReturn<RpcServerFunctions, RpcClientFunctions>["$callOptional"];
81
+ interface RpcClientEvents {
82
+ "rpc:is-trusted:updated": (isTrusted: boolean) => void;
83
+ }
84
+ interface RpcClient {
85
+ /**
86
+ * The events of the client
87
+ */
88
+ events: EventEmitter<RpcClientEvents>;
89
+ /**
90
+ * Whether the client is trusted
91
+ */
92
+ readonly isTrusted: boolean | null;
93
+ /**
94
+ * The connection meta
95
+ */
96
+ readonly connectionMeta: ConnectionMeta;
97
+ /**
98
+ * Return a promise that resolves when the client is trusted
99
+ *
100
+ * Rejects with an error if the timeout is reached
101
+ *
102
+ * @param timeout - The timeout in milliseconds, default to 60 seconds
103
+ */
104
+ ensureTrusted: (timeout?: number) => Promise<boolean>;
105
+ /**
106
+ * Request trust from the server
107
+ */
108
+ requestTrust: () => Promise<boolean>;
109
+ /**
110
+ * Request trust from the server using a specific auth token.
111
+ * Updates the stored token and re-requests trust without reloading the page.
112
+ */
113
+ requestTrustWithToken: (token: string) => Promise<boolean>;
114
+ /**
115
+ * Call a Rpc function on the server
116
+ */
117
+ call: RpcClientCall;
118
+ /**
119
+ * Call a Rpc event on the server, and does not expect a response
120
+ */
121
+ callEvent: RpcClientCallEvent;
122
+ /**
123
+ * Call a Rpc optional function on the server
124
+ */
125
+ callOptional: RpcClientCallOptional;
126
+ /**
127
+ * The client Rpc host
128
+ */
129
+ client: RpcClientHost;
130
+ /**
131
+ * The shared state host
132
+ */
133
+ sharedState: RpcSharedStateHost;
134
+ /**
135
+ * The streaming channel host. Subscribe to a server-side stream by
136
+ * channel + id; the returned reader is both `AsyncIterable<T>` and
137
+ * exposes `.readable: ReadableStream<T>` for `pipeTo` consumption.
138
+ */
139
+ streaming: RpcStreamingClientHost;
140
+ /**
141
+ * The Rpc cache manager
142
+ */
143
+ cacheManager: RpcCacheManager;
144
+ }
145
+ //#endregion
146
+ //#region src/types/config.d.ts
147
+ /**
148
+ * The options required to start the Powerlines engine.
149
+ */
150
+ type EngineOptions = Omit<PartialKeys<DevframeDefinition, "name" | "setup">, "id" | "basePath"> & Options & {
151
+ /**
152
+ * The host URL for the engine's WebSocket server, which is used for communication between the engine and the various hosts (e.g., dev server, CLI, etc.) that interact with it. This value is required for the engine to function properly, as it allows the engine to establish a WebSocket connection and facilitate communication with other components of the system.
153
+ */
154
+ host?: string;
155
+ /**
156
+ * The port number to use for the websocket connection between the engine and the various hosts.
157
+ */
158
+ port?: number;
159
+ /**
160
+ * An optional root directory for the engine to use when resolving paths and loading configuration files. This value can be used to specify a custom root directory for the engine, which can be useful in cases where the default behavior of using the current working directory is not desirable. If this option is not provided, the engine will use the current working directory as the root directory by default.
161
+ */
162
+ root?: string;
163
+ /**
164
+ * A custom logger instance that implements the {@link CustomLogger} interface, which can be used for logging messages during the build process instead of the default Powerlines logger.
165
+ *
166
+ * @remarks
167
+ * Providing a custom logger allows you to integrate Powerlines logging with your own logging system or to customize the logging behavior, such as formatting log messages differently or sending logs to an external service. If a custom logger is not provided, Powerlines will use its default logger implementation.
168
+ */
169
+ customLogger?: CustomLogger;
170
+ /**
171
+ * The framework for which the engine is being used, which can be used by plugins to customize their behavior based on the specific framework being targeted. This value is optional and can be set to `undefined` if not applicable, but providing it allows plugins to make informed decisions about how to handle certain tasks or configurations based on the framework being used.
172
+ */
173
+ framework?: FrameworkOptions;
174
+ };
175
+ interface EngineExecutionOptions extends ExecutionOptions {
176
+ /**
177
+ * The base URL for the dev server, which can be used by plugins to construct URLs for assets or API endpoints during development. This value is only relevant in "dev" mode and will be `undefined` in "build" mode.
178
+ */
179
+ baseURL: string;
180
+ /**
181
+ * Metadata for the connection used by the dev server, including the backend type and websocket configuration.
182
+ */
183
+ connection: ConnectionMeta;
184
+ /**
185
+ * Options for configuring the WebSocket RPC channel used for communication between the dev server and the client, which can be used by plugins to customize the behavior of the WebSocket connection, such as setting custom timeouts, retry strategies, or other options.
186
+ */
187
+ wsOptions?: Partial<WsRpcChannelOptions>;
188
+ /**
189
+ * Options for configuring the RPC client used for communication between the dev server and the client, which can be used by plugins to customize the behavior of the RPC client, such as setting custom timeouts, retry strategies, or other options.
190
+ */
191
+ rpcOptions?: Partial<BirpcOptions<RpcServerFunctions, RpcClientFunctions, boolean>>;
192
+ /**
193
+ * Options for configuring the RPC cache used for caching RPC responses between the dev server and the client, which can be used by plugins to customize the behavior of the RPC cache, such as setting custom cache keys, expiration times, or other options.
194
+ *
195
+ * @remarks
196
+ * This option can be set to `true` to enable caching with default options, or it can be set to a configuration object that allows for fine-grained control over the caching behavior.
197
+ */
198
+ cacheOptions?: boolean | Partial<RpcCacheOptions>;
199
+ }
200
+ type RpcClientOptions = RequiredKeys<EngineExecutionOptions, "baseURL" | "connection">;
201
+ type EngineResolvedConfig<TUserConfig extends UserConfig = UserConfig> = ResolvedConfig<TUserConfig, EngineExecutionOptions>;
202
+ //#endregion
203
+ export { RpcServerFunctions as C, WrappedRpcFunctions as D, WrappedRpcFunction as E, RpcPayloadMetadata as S, WrapRpcFunctions as T, RpcClientRemoteFunctions as _, ExtractRpcFunction as a, RpcFunctions as b, InputRpcFunctions as c, RpcClientCall as d, RpcClientCallEvent as f, RpcClientHost as g, RpcClientFunctions as h, RpcClientOptions as i, LogPayload as l, RpcClientEvents as m, EngineOptions as n, ExtractRpcFunctions as o, RpcClientCallOptional as p, EngineResolvedConfig as r, InputRpcFunction as s, EngineExecutionOptions as t, RpcClient as u, RpcContext as v, WrapRpcFunction as w, RpcPayloadEnvelop as x, RpcFunction as y };
204
+ //# sourceMappingURL=config-DKEmqMrh.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-DKEmqMrh.d.cts","names":[],"sources":["../src/types/rpc.ts","../src/types/config.ts"],"mappings":"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"}
@@ -0,0 +1,177 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('../chunk-C_NdSu1c.cjs');
3
+ let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
4
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
5
+ let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
6
+ let devframe_node = require("devframe/node");
7
+ let _powerlines_core_lib_config = require("@powerlines/core/lib/config");
8
+ let _powerlines_core_context_base_context = require("@powerlines/core/context/base-context");
9
+ let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
10
+ let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
11
+ let valibot = require("valibot");
12
+ valibot = require_chunk.__toESM(valibot, 1);
13
+
14
+ //#region src/context/engine-context.ts
15
+ var PowerlinesEngineContext = class PowerlinesEngineContext extends _powerlines_core_context_base_context.PowerlinesBaseContext {
16
+ options;
17
+ connection;
18
+ #executions = [];
19
+ #devtools;
20
+ #logLevel;
21
+ /**
22
+ * Creates a new instance of the PowerlinesEngineContext class.
23
+ *
24
+ * @param options - The options to initialize the context with.
25
+ * @returns A promise that resolves to an instance of the PowerlinesEngineContext class.
26
+ */
27
+ static async from(options, host, connection) {
28
+ const context = new PowerlinesEngineContext(options, connection);
29
+ context.#devtools = await (0, devframe_node.createHostContext)({
30
+ cwd: context.cwd,
31
+ mode: "dev",
32
+ host
33
+ });
34
+ await options.setup?.(context.#devtools);
35
+ context.#devtools.rpc.register({
36
+ name: "powerlines:log",
37
+ type: "event",
38
+ args: [valibot.object({
39
+ meta: valibot.object({
40
+ category: valibot.string(),
41
+ name: valibot.string(),
42
+ command: valibot.string(),
43
+ hook: valibot.string(),
44
+ plugin: valibot.string(),
45
+ source: valibot.string()
46
+ }),
47
+ message: valibot.string()
48
+ })],
49
+ setup: (_) => ({ handler: (payload) => {
50
+ switch (payload.meta.type) {
51
+ case "error":
52
+ context.error(payload);
53
+ break;
54
+ case "warn":
55
+ context.warn(payload);
56
+ break;
57
+ case "info":
58
+ context.info(payload);
59
+ break;
60
+ case "debug":
61
+ context.debug(payload);
62
+ break;
63
+ case "trace":
64
+ context.trace(payload);
65
+ break;
66
+ default:
67
+ context.info(payload);
68
+ break;
69
+ }
70
+ } })
71
+ });
72
+ context.#logLevel = options.logLevel ? (0, _powerlines_core_plugin_utils.resolveLogLevel)(options.logLevel) : await (0, _powerlines_core_lib_config.getDefaultLogLevel)(context.cwd);
73
+ return context;
74
+ }
75
+ createLogger(options = {}, logFn) {
76
+ let logger = (0, _powerlines_core_plugin_utils.createLogger)("engine", {
77
+ logLevel: this.#logLevel,
78
+ ...options
79
+ }, logFn);
80
+ if (this.options.customLogger) logger = (0, _powerlines_core_plugin_utils.withCustomLogger)(logger, this.options.customLogger);
81
+ return logger;
82
+ }
83
+ get executions() {
84
+ return this.#executions;
85
+ }
86
+ get devtools() {
87
+ return this.#devtools;
88
+ }
89
+ get envPaths() {
90
+ return (0, _stryke_env_get_env_paths.getEnvPaths)({
91
+ orgId: (0, _stryke_string_format_kebab_case.kebabCase)(this.orgId),
92
+ appId: (0, _stryke_string_format_kebab_case.kebabCase)(this.framework.name),
93
+ workspaceRoot: this.cwd
94
+ });
95
+ }
96
+ get framework() {
97
+ return {
98
+ name: "powerlines",
99
+ orgId: "storm-software",
100
+ ...this.options.framework
101
+ };
102
+ }
103
+ get orgId() {
104
+ return this.framework.orgId;
105
+ }
106
+ /**
107
+ * Creates a new Context instance.
108
+ *
109
+ * @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
110
+ * @param connection - The connection metadata for the dev server.
111
+ */
112
+ constructor(options, connection) {
113
+ super(options);
114
+ this.options = options;
115
+ this.connection = connection;
116
+ }
117
+ /**
118
+ * Initialize the context with the provided configuration options
119
+ *
120
+ * @remarks
121
+ * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
122
+ *
123
+ * @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.
124
+ * @param inlineConfig - Additional configuration options provided at runtime, which can override or supplement the options defined in the user configuration file.
125
+ */
126
+ async loadExecutions(method, inlineConfig) {
127
+ const root = (0, _powerlines_core_lib_config.resolveRoot)(this.cwd, inlineConfig.root, inlineConfig.configFile);
128
+ const config = await (0, _powerlines_core_lib_config.loadParsedConfig)(this.cwd, root, this.framework?.name, this.orgId, inlineConfig);
129
+ if (!config) throw new Error("Failed to load configuration");
130
+ const invocationId = (0, _stryke_unique_id_uuid.uuid)();
131
+ const executions = await Promise.all((0, _stryke_convert_to_array.toArray)(config.config).map(async (_, configIndex) => {
132
+ const executionId = (0, _stryke_unique_id_uuid.uuid)();
133
+ const options = {
134
+ cwd: this.cwd,
135
+ root,
136
+ framework: this.framework,
137
+ orgId: this.orgId,
138
+ ...this.options,
139
+ command: method,
140
+ baseURL: this.#devtools.host.resolveOrigin(),
141
+ connection: this.connection,
142
+ configFile: config.configFile,
143
+ executionId,
144
+ configIndex
145
+ };
146
+ this.logger.debug({
147
+ meta: { category: "config" },
148
+ message: `Invoking ${method} with the following execution parameters: \n --- Options --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(options)}\n --- Inline Config --- \n${(0, _powerlines_core_plugin_utils.formatConfig)(inlineConfig)}`
149
+ });
150
+ return {
151
+ invocationId,
152
+ method,
153
+ configFile: config,
154
+ options,
155
+ state: {
156
+ command: null,
157
+ hook: null,
158
+ plugin: null
159
+ }
160
+ };
161
+ }));
162
+ this.#executions = this.#executions.concat(executions);
163
+ return executions;
164
+ }
165
+ /**
166
+ * Complete an execution by removing it from the list of active executions based on the provided invocation ID and execution ID. This method is typically called when an execution has finished or has been terminated, allowing the context to clean up any resources associated with that execution and update its internal state accordingly.
167
+ *
168
+ * @param invocationId - The unique identifier for the invocation of the execution to be completed.
169
+ * @param executionId - The unique identifier for the specific execution to be completed.
170
+ */
171
+ completeExecution(invocationId, executionId) {
172
+ this.#executions = this.#executions.filter((execution) => execution.options.executionId !== executionId || execution.invocationId !== invocationId);
173
+ }
174
+ };
175
+
176
+ //#endregion
177
+ exports.PowerlinesEngineContext = PowerlinesEngineContext;
@@ -0,0 +1,2 @@
1
+ import { t as PowerlinesEngineContext } from "../engine-context-B8K6Jtkk.cjs";
2
+ export { PowerlinesEngineContext };
@@ -0,0 +1,2 @@
1
+ import { t as PowerlinesEngineContext } from "../engine-context-DKlA5Pgu.mjs";
2
+ export { PowerlinesEngineContext };
@@ -0,0 +1,175 @@
1
+ import { createLogger, formatConfig, resolveLogLevel, withCustomLogger } from "@powerlines/core/plugin-utils";
2
+ import { toArray } from "@stryke/convert/to-array";
3
+ import { uuid } from "@stryke/unique-id/uuid";
4
+ import { createHostContext } from "devframe/node";
5
+ import { getDefaultLogLevel, loadParsedConfig, resolveRoot } from "@powerlines/core/lib/config";
6
+ import { PowerlinesBaseContext } from "@powerlines/core/context/base-context";
7
+ import { getEnvPaths } from "@stryke/env/get-env-paths";
8
+ import { kebabCase } from "@stryke/string-format/kebab-case";
9
+ import * as v from "valibot";
10
+
11
+ //#region src/context/engine-context.ts
12
+ var PowerlinesEngineContext = class PowerlinesEngineContext extends PowerlinesBaseContext {
13
+ options;
14
+ connection;
15
+ #executions = [];
16
+ #devtools;
17
+ #logLevel;
18
+ /**
19
+ * Creates a new instance of the PowerlinesEngineContext class.
20
+ *
21
+ * @param options - The options to initialize the context with.
22
+ * @returns A promise that resolves to an instance of the PowerlinesEngineContext class.
23
+ */
24
+ static async from(options, host, connection) {
25
+ const context = new PowerlinesEngineContext(options, connection);
26
+ context.#devtools = await createHostContext({
27
+ cwd: context.cwd,
28
+ mode: "dev",
29
+ host
30
+ });
31
+ await options.setup?.(context.#devtools);
32
+ context.#devtools.rpc.register({
33
+ name: "powerlines:log",
34
+ type: "event",
35
+ args: [v.object({
36
+ meta: v.object({
37
+ category: v.string(),
38
+ name: v.string(),
39
+ command: v.string(),
40
+ hook: v.string(),
41
+ plugin: v.string(),
42
+ source: v.string()
43
+ }),
44
+ message: v.string()
45
+ })],
46
+ setup: (_) => ({ handler: (payload) => {
47
+ switch (payload.meta.type) {
48
+ case "error":
49
+ context.error(payload);
50
+ break;
51
+ case "warn":
52
+ context.warn(payload);
53
+ break;
54
+ case "info":
55
+ context.info(payload);
56
+ break;
57
+ case "debug":
58
+ context.debug(payload);
59
+ break;
60
+ case "trace":
61
+ context.trace(payload);
62
+ break;
63
+ default:
64
+ context.info(payload);
65
+ break;
66
+ }
67
+ } })
68
+ });
69
+ context.#logLevel = options.logLevel ? resolveLogLevel(options.logLevel) : await getDefaultLogLevel(context.cwd);
70
+ return context;
71
+ }
72
+ createLogger(options = {}, logFn) {
73
+ let logger = createLogger("engine", {
74
+ logLevel: this.#logLevel,
75
+ ...options
76
+ }, logFn);
77
+ if (this.options.customLogger) logger = withCustomLogger(logger, this.options.customLogger);
78
+ return logger;
79
+ }
80
+ get executions() {
81
+ return this.#executions;
82
+ }
83
+ get devtools() {
84
+ return this.#devtools;
85
+ }
86
+ get envPaths() {
87
+ return getEnvPaths({
88
+ orgId: kebabCase(this.orgId),
89
+ appId: kebabCase(this.framework.name),
90
+ workspaceRoot: this.cwd
91
+ });
92
+ }
93
+ get framework() {
94
+ return {
95
+ name: "powerlines",
96
+ orgId: "storm-software",
97
+ ...this.options.framework
98
+ };
99
+ }
100
+ get orgId() {
101
+ return this.framework.orgId;
102
+ }
103
+ /**
104
+ * Creates a new Context instance.
105
+ *
106
+ * @param options - The options to use for creating the context, including the resolved configuration and workspace settings.
107
+ * @param connection - The connection metadata for the dev server.
108
+ */
109
+ constructor(options, connection) {
110
+ super(options);
111
+ this.options = options;
112
+ this.connection = connection;
113
+ }
114
+ /**
115
+ * Initialize the context with the provided configuration options
116
+ *
117
+ * @remarks
118
+ * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.
119
+ *
120
+ * @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.
121
+ * @param inlineConfig - Additional configuration options provided at runtime, which can override or supplement the options defined in the user configuration file.
122
+ */
123
+ async loadExecutions(method, inlineConfig) {
124
+ const root = resolveRoot(this.cwd, inlineConfig.root, inlineConfig.configFile);
125
+ const config = await loadParsedConfig(this.cwd, root, this.framework?.name, this.orgId, inlineConfig);
126
+ if (!config) throw new Error("Failed to load configuration");
127
+ const invocationId = uuid();
128
+ const executions = await Promise.all(toArray(config.config).map(async (_, configIndex) => {
129
+ const executionId = uuid();
130
+ const options = {
131
+ cwd: this.cwd,
132
+ root,
133
+ framework: this.framework,
134
+ orgId: this.orgId,
135
+ ...this.options,
136
+ command: method,
137
+ baseURL: this.#devtools.host.resolveOrigin(),
138
+ connection: this.connection,
139
+ configFile: config.configFile,
140
+ executionId,
141
+ configIndex
142
+ };
143
+ this.logger.debug({
144
+ meta: { category: "config" },
145
+ message: `Invoking ${method} with the following execution parameters: \n --- Options --- \n${formatConfig(options)}\n --- Inline Config --- \n${formatConfig(inlineConfig)}`
146
+ });
147
+ return {
148
+ invocationId,
149
+ method,
150
+ configFile: config,
151
+ options,
152
+ state: {
153
+ command: null,
154
+ hook: null,
155
+ plugin: null
156
+ }
157
+ };
158
+ }));
159
+ this.#executions = this.#executions.concat(executions);
160
+ return executions;
161
+ }
162
+ /**
163
+ * Complete an execution by removing it from the list of active executions based on the provided invocation ID and execution ID. This method is typically called when an execution has finished or has been terminated, allowing the context to clean up any resources associated with that execution and update its internal state accordingly.
164
+ *
165
+ * @param invocationId - The unique identifier for the invocation of the execution to be completed.
166
+ * @param executionId - The unique identifier for the specific execution to be completed.
167
+ */
168
+ completeExecution(invocationId, executionId) {
169
+ this.#executions = this.#executions.filter((execution) => execution.options.executionId !== executionId || execution.invocationId !== invocationId);
170
+ }
171
+ };
172
+
173
+ //#endregion
174
+ export { PowerlinesEngineContext };
175
+ //# sourceMappingURL=engine-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-context.mjs","names":["#devtools","#logLevel","#executions"],"sources":["../../src/context/engine-context.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n FrameworkOptions,\n InlineConfig,\n LogFn,\n LoggerOptions,\n LogLevelResolvedConfig\n} from \"@powerlines/core\";\nimport { PowerlinesBaseContext } from \"@powerlines/core/context/base-context\";\nimport {\n getDefaultLogLevel,\n loadParsedConfig,\n resolveRoot\n} from \"@powerlines/core/lib/config\";\nimport {\n createLogger,\n formatConfig,\n resolveLogLevel,\n withCustomLogger\n} from \"@powerlines/core/plugin-utils\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { EnvPaths, getEnvPaths } from \"@stryke/env/get-env-paths\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { uuid } from \"@stryke/unique-id/uuid\";\nimport { createHostContext } from \"devframe/node\";\nimport {\n ConnectionMeta,\n DevToolsHost,\n DevToolsNodeContext\n} from \"devframe/types\";\nimport * as v from \"valibot\";\nimport { EngineOptions } from \"../types/config\";\nimport { EngineContext, EngineExecutionItem } from \"../types/context\";\n\nexport class PowerlinesEngineContext<TSystemContext = unknown>\n extends PowerlinesBaseContext<TSystemContext>\n implements EngineContext<TSystemContext>\n{\n #executions: EngineExecutionItem[] = [];\n\n #devtools!: DevToolsNodeContext;\n\n #logLevel!: LogLevelResolvedConfig;\n\n /**\n * Creates a new instance of the PowerlinesEngineContext class.\n *\n * @param options - The options to initialize the context with.\n * @returns A promise that resolves to an instance of the PowerlinesEngineContext class.\n */\n public static async from<TSystemContext = unknown>(\n options: EngineOptions,\n host: DevToolsHost,\n connection: ConnectionMeta\n ): Promise<PowerlinesEngineContext<TSystemContext>> {\n const context = new PowerlinesEngineContext<TSystemContext>(\n options,\n connection\n );\n\n context.#devtools = await createHostContext({\n cwd: context.cwd,\n mode: \"dev\",\n host\n });\n await options.setup?.(context.#devtools);\n\n context.#devtools.rpc.register({\n name: \"powerlines:log\",\n type: \"event\",\n args: [\n v.object({\n meta: v.object({\n category: v.string(),\n name: v.string(),\n command: v.string(),\n hook: v.string(),\n plugin: v.string(),\n source: v.string()\n }),\n message: v.string()\n })\n ],\n setup: _ => ({\n handler: payload => {\n switch (payload.meta.type) {\n case \"error\":\n context.error(payload);\n break;\n case \"warn\":\n context.warn(payload);\n break;\n case \"info\":\n context.info(payload);\n break;\n case \"debug\":\n context.debug(payload);\n break;\n case \"trace\":\n context.trace(payload);\n break;\n default:\n context.info(payload);\n break;\n }\n }\n })\n });\n\n context.#logLevel = options.logLevel\n ? resolveLogLevel(options.logLevel)\n : await getDefaultLogLevel(context.cwd);\n\n return context;\n }\n\n public override createLogger(options: LoggerOptions = {}, logFn?: LogFn) {\n let logger = createLogger(\n \"engine\",\n {\n logLevel: this.#logLevel,\n ...options\n },\n logFn\n );\n if (this.options.customLogger) {\n logger = withCustomLogger(logger, this.options.customLogger);\n }\n return logger;\n }\n\n public get executions(): EngineExecutionItem[] {\n return this.#executions;\n }\n\n public get devtools(): DevToolsNodeContext {\n return this.#devtools;\n }\n\n public get envPaths(): EnvPaths {\n return getEnvPaths({\n orgId: kebabCase(this.orgId),\n appId: kebabCase(this.framework.name),\n workspaceRoot: this.cwd\n });\n }\n\n public get framework(): FrameworkOptions {\n return {\n name: \"powerlines\",\n orgId: \"storm-software\",\n ...this.options.framework\n };\n }\n\n public get orgId(): string {\n return this.framework.orgId;\n }\n\n /**\n * Creates a new Context instance.\n *\n * @param options - The options to use for creating the context, including the resolved configuration and workspace settings.\n * @param connection - The connection metadata for the dev server.\n */\n protected constructor(\n public override options: EngineOptions,\n public connection: ConnectionMeta\n ) {\n super(options);\n }\n\n /**\n * Initialize the context with the provided configuration options\n *\n * @remarks\n * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.\n *\n * @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.\n * @param inlineConfig - Additional configuration options provided at runtime, which can override or supplement the options defined in the user configuration file.\n */\n public async loadExecutions(\n method: string,\n inlineConfig: InlineConfig\n ): Promise<EngineExecutionItem[]> {\n const root = resolveRoot(\n this.cwd,\n inlineConfig.root,\n inlineConfig.configFile\n );\n\n const config = await loadParsedConfig(\n this.cwd,\n root,\n this.framework?.name,\n this.orgId,\n inlineConfig\n );\n if (!config) {\n throw new Error(\"Failed to load configuration\");\n }\n\n const invocationId = uuid();\n const executions = await Promise.all(\n toArray(config.config).map(async (_, configIndex) => {\n const executionId = uuid();\n const options = {\n cwd: this.cwd,\n root,\n framework: this.framework,\n orgId: this.orgId,\n ...this.options,\n command: method,\n baseURL: this.#devtools.host.resolveOrigin(),\n connection: this.connection,\n configFile: config.configFile!,\n executionId,\n configIndex\n };\n\n this.logger.debug({\n meta: { category: \"config\" },\n message: `Invoking ${method} with the following execution parameters: \\n --- Options --- \\n${formatConfig(\n options\n )}\\n --- Inline Config --- \\n${formatConfig(inlineConfig)}`\n });\n\n return {\n invocationId,\n method,\n configFile: config,\n options,\n state: {\n command: null,\n hook: null,\n plugin: null\n }\n };\n })\n );\n\n this.#executions = this.#executions.concat(executions);\n\n return executions;\n }\n\n /**\n * Complete an execution by removing it from the list of active executions based on the provided invocation ID and execution ID. This method is typically called when an execution has finished or has been terminated, allowing the context to clean up any resources associated with that execution and update its internal state accordingly.\n *\n * @param invocationId - The unique identifier for the invocation of the execution to be completed.\n * @param executionId - The unique identifier for the specific execution to be completed.\n */\n public completeExecution(invocationId: string, executionId: string) {\n this.#executions = this.#executions.filter(\n execution =>\n execution.options.executionId !== executionId ||\n execution.invocationId !== invocationId\n );\n }\n}\n"],"mappings":"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"}
@@ -1,11 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_execution_context = require('../execution-context-CnyaM3Ul.cjs');
3
- const require_base_context = require('../base-context-DLemGRbd.cjs');
4
- const require_engine_context = require('../engine-context-D0y88i_J.cjs');
2
+ const require_context_engine_context = require('./engine-context.cjs');
5
3
 
6
- exports.PowerlinesBaseContext = require_base_context.PowerlinesBaseContext;
7
- exports.PowerlinesContext = require_execution_context.PowerlinesContext;
8
- exports.PowerlinesEngineContext = require_engine_context.PowerlinesEngineContext;
9
- exports.PowerlinesEnvironmentContext = require_execution_context.PowerlinesEnvironmentContext;
10
- exports.PowerlinesExecutionContext = require_execution_context.PowerlinesExecutionContext;
11
- exports.createPluginContext = require_execution_context.createPluginContext;
4
+ exports.PowerlinesEngineContext = require_context_engine_context.PowerlinesEngineContext;