@decaf-ts/as-graph 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +167 -5
  2. package/dist/as-graph.cjs +1 -1
  3. package/dist/as-graph.cjs.map +1 -1
  4. package/dist/as-graph.js +1 -1
  5. package/dist/as-graph.js.map +1 -1
  6. package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs +102 -11
  7. package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs.map +1 -1
  8. package/lib/cjs/dagster/DagsterGraphQLClient.cjs +738 -0
  9. package/lib/cjs/dagster/DagsterGraphQLClient.cjs.map +1 -0
  10. package/lib/cjs/dagster/index.cjs +1 -0
  11. package/lib/cjs/dagster/index.cjs.map +1 -1
  12. package/lib/cjs/engine/execution/GraphExecutionEngine.cjs +7 -0
  13. package/lib/cjs/engine/execution/GraphExecutionEngine.cjs.map +1 -1
  14. package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs +39 -0
  15. package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs.map +1 -1
  16. package/lib/cjs/engine/index.cjs +1 -0
  17. package/lib/cjs/engine/index.cjs.map +1 -1
  18. package/lib/cjs/engine/services/GraphNodeModelService.cjs +129 -0
  19. package/lib/cjs/engine/services/GraphNodeModelService.cjs.map +1 -0
  20. package/lib/cjs/engine/services/GraphWorkflowService.cjs +33 -0
  21. package/lib/cjs/engine/services/GraphWorkflowService.cjs.map +1 -1
  22. package/lib/cjs/mastra/MastraDefaultStepHandlers.cjs +217 -0
  23. package/lib/cjs/mastra/MastraDefaultStepHandlers.cjs.map +1 -0
  24. package/lib/cjs/mastra/MastraEventBridge.cjs +10 -3
  25. package/lib/cjs/mastra/MastraEventBridge.cjs.map +1 -1
  26. package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs +111 -13
  27. package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs.map +1 -1
  28. package/lib/cjs/mastra/MastraWorkflowCompiler.cjs +3 -3
  29. package/lib/cjs/mastra/MastraWorkflowCompiler.cjs.map +1 -1
  30. package/lib/cjs/mastra/index.cjs +1 -0
  31. package/lib/cjs/mastra/index.cjs.map +1 -1
  32. package/lib/cjs/mastra/types.cjs +5 -1
  33. package/lib/cjs/mastra/types.cjs.map +1 -1
  34. package/lib/cjs/nest/graph/GraphBackendHost.cjs +232 -0
  35. package/lib/cjs/nest/graph/GraphBackendHost.cjs.map +1 -0
  36. package/lib/cjs/nest/graph/GraphExecutionModule.cjs +38 -1
  37. package/lib/cjs/nest/graph/GraphExecutionModule.cjs.map +1 -1
  38. package/lib/cjs/nest/graph/index.cjs +1 -0
  39. package/lib/cjs/nest/graph/index.cjs.map +1 -1
  40. package/lib/cjs/nest/graph/main.cjs +112 -12
  41. package/lib/cjs/nest/graph/main.cjs.map +1 -1
  42. package/lib/cjs/ram/GraphNodeRepository.cjs +40 -0
  43. package/lib/cjs/ram/GraphNodeRepository.cjs.map +1 -0
  44. package/lib/cjs/ram/index.cjs +1 -0
  45. package/lib/cjs/ram/index.cjs.map +1 -1
  46. package/lib/cjs/shared/graph/GraphNodeConverters.cjs +43 -0
  47. package/lib/cjs/shared/graph/GraphNodeConverters.cjs.map +1 -0
  48. package/lib/cjs/shared/graph/GraphNodeModel.cjs +74 -0
  49. package/lib/cjs/shared/graph/GraphNodeModel.cjs.map +1 -0
  50. package/lib/cjs/shared/graph/index.cjs +2 -0
  51. package/lib/cjs/shared/graph/index.cjs.map +1 -1
  52. package/lib/esm/dagster/DagsterGraphExecutionBackend.js +102 -11
  53. package/lib/esm/dagster/DagsterGraphExecutionBackend.js.map +1 -1
  54. package/lib/esm/dagster/DagsterGraphQLClient.js +733 -0
  55. package/lib/esm/dagster/DagsterGraphQLClient.js.map +1 -0
  56. package/lib/esm/dagster/index.js +1 -0
  57. package/lib/esm/dagster/index.js.map +1 -1
  58. package/lib/esm/engine/execution/GraphExecutionBackend.js.map +1 -1
  59. package/lib/esm/engine/execution/GraphExecutionEngine.js +7 -0
  60. package/lib/esm/engine/execution/GraphExecutionEngine.js.map +1 -1
  61. package/lib/esm/engine/execution/LocalGraphExecutionBackend.js +39 -0
  62. package/lib/esm/engine/execution/LocalGraphExecutionBackend.js.map +1 -1
  63. package/lib/esm/engine/index.js +1 -0
  64. package/lib/esm/engine/index.js.map +1 -1
  65. package/lib/esm/engine/services/GraphNodeModelService.js +120 -0
  66. package/lib/esm/engine/services/GraphNodeModelService.js.map +1 -0
  67. package/lib/esm/engine/services/GraphWorkflowService.js +34 -1
  68. package/lib/esm/engine/services/GraphWorkflowService.js.map +1 -1
  69. package/lib/esm/mastra/MastraCapabilities.js.map +1 -1
  70. package/lib/esm/mastra/MastraDefaultStepHandlers.js +212 -0
  71. package/lib/esm/mastra/MastraDefaultStepHandlers.js.map +1 -0
  72. package/lib/esm/mastra/MastraEventBridge.js +10 -3
  73. package/lib/esm/mastra/MastraEventBridge.js.map +1 -1
  74. package/lib/esm/mastra/MastraGraphExecutionBackend.js +112 -14
  75. package/lib/esm/mastra/MastraGraphExecutionBackend.js.map +1 -1
  76. package/lib/esm/mastra/MastraWorkflowCompiler.js +3 -3
  77. package/lib/esm/mastra/MastraWorkflowCompiler.js.map +1 -1
  78. package/lib/esm/mastra/index.js +1 -0
  79. package/lib/esm/mastra/index.js.map +1 -1
  80. package/lib/esm/mastra/types.js +4 -0
  81. package/lib/esm/mastra/types.js.map +1 -1
  82. package/lib/esm/nest/graph/GraphBackendHost.js +189 -0
  83. package/lib/esm/nest/graph/GraphBackendHost.js.map +1 -0
  84. package/lib/esm/nest/graph/GraphExecutionModule.js +39 -2
  85. package/lib/esm/nest/graph/GraphExecutionModule.js.map +1 -1
  86. package/lib/esm/nest/graph/index.js +1 -0
  87. package/lib/esm/nest/graph/index.js.map +1 -1
  88. package/lib/esm/nest/graph/main.js +79 -12
  89. package/lib/esm/nest/graph/main.js.map +1 -1
  90. package/lib/esm/ram/GraphNodeRepository.js +31 -0
  91. package/lib/esm/ram/GraphNodeRepository.js.map +1 -0
  92. package/lib/esm/ram/index.js +1 -0
  93. package/lib/esm/ram/index.js.map +1 -1
  94. package/lib/esm/shared/graph/GraphNodeConverters.js +38 -0
  95. package/lib/esm/shared/graph/GraphNodeConverters.js.map +1 -0
  96. package/lib/esm/shared/graph/GraphNodeModel.js +65 -0
  97. package/lib/esm/shared/graph/GraphNodeModel.js.map +1 -0
  98. package/lib/esm/shared/graph/index.js +2 -0
  99. package/lib/esm/shared/graph/index.js.map +1 -1
  100. package/lib/types/dagster/DagsterGraphExecutionBackend.d.cts +40 -4
  101. package/lib/types/dagster/DagsterGraphExecutionBackend.d.mts +40 -4
  102. package/lib/types/dagster/DagsterGraphQLClient.d.cts +231 -0
  103. package/lib/types/dagster/DagsterGraphQLClient.d.mts +231 -0
  104. package/lib/types/dagster/index.d.cts +1 -0
  105. package/lib/types/dagster/index.d.mts +1 -0
  106. package/lib/types/engine/execution/GraphExecutionBackend.d.cts +27 -0
  107. package/lib/types/engine/execution/GraphExecutionBackend.d.mts +27 -0
  108. package/lib/types/engine/execution/GraphExecutionEngine.d.cts +9 -0
  109. package/lib/types/engine/execution/GraphExecutionEngine.d.mts +9 -0
  110. package/lib/types/engine/execution/LocalGraphExecutionBackend.d.cts +14 -0
  111. package/lib/types/engine/execution/LocalGraphExecutionBackend.d.mts +14 -0
  112. package/lib/types/engine/index.d.cts +1 -0
  113. package/lib/types/engine/index.d.mts +1 -0
  114. package/lib/types/engine/services/GraphNodeModelService.d.cts +54 -0
  115. package/lib/types/engine/services/GraphNodeModelService.d.mts +54 -0
  116. package/lib/types/engine/services/GraphWorkflowService.d.cts +21 -0
  117. package/lib/types/engine/services/GraphWorkflowService.d.mts +21 -0
  118. package/lib/types/mastra/MastraCapabilities.d.cts +0 -5
  119. package/lib/types/mastra/MastraCapabilities.d.mts +0 -5
  120. package/lib/types/mastra/MastraDefaultStepHandlers.d.cts +74 -0
  121. package/lib/types/mastra/MastraDefaultStepHandlers.d.mts +74 -0
  122. package/lib/types/mastra/MastraGraphExecutionBackend.d.cts +29 -0
  123. package/lib/types/mastra/MastraGraphExecutionBackend.d.mts +29 -0
  124. package/lib/types/mastra/MastraWorkflowCompiler.d.cts +3 -3
  125. package/lib/types/mastra/MastraWorkflowCompiler.d.mts +3 -3
  126. package/lib/types/mastra/index.d.cts +1 -0
  127. package/lib/types/mastra/index.d.mts +1 -0
  128. package/lib/types/mastra/types.d.cts +12 -0
  129. package/lib/types/mastra/types.d.mts +12 -0
  130. package/lib/types/nest/graph/GraphBackendHost.d.cts +152 -0
  131. package/lib/types/nest/graph/GraphBackendHost.d.mts +152 -0
  132. package/lib/types/nest/graph/GraphExecutionModule.d.cts +23 -0
  133. package/lib/types/nest/graph/GraphExecutionModule.d.mts +23 -0
  134. package/lib/types/nest/graph/index.d.cts +1 -0
  135. package/lib/types/nest/graph/index.d.mts +1 -0
  136. package/lib/types/ram/GraphNodeRepository.d.cts +13 -0
  137. package/lib/types/ram/GraphNodeRepository.d.mts +13 -0
  138. package/lib/types/ram/index.d.cts +1 -0
  139. package/lib/types/ram/index.d.mts +1 -0
  140. package/lib/types/shared/graph/GraphNodeConverters.d.cts +15 -0
  141. package/lib/types/shared/graph/GraphNodeConverters.d.mts +15 -0
  142. package/lib/types/shared/graph/GraphNodeModel.d.cts +24 -0
  143. package/lib/types/shared/graph/GraphNodeModel.d.mts +24 -0
  144. package/lib/types/shared/graph/index.d.cts +2 -0
  145. package/lib/types/shared/graph/index.d.mts +2 -0
  146. package/package.json +15 -3
@@ -0,0 +1,738 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DagsterGraphQLClient = void 0;
4
+ const index_js_1 = require("./../engine/errors/index.cjs");
5
+ const constants_js_1 = require("./constants.cjs");
6
+ /**
7
+ * The documented Dagster event types the read-only driver consumes. Raw Dagster
8
+ * telemetry outside this set is filtered by the transport (see module docs).
9
+ */
10
+ const DAGSTER_MAPPED_EVENT_TYPES = new Set([
11
+ "STEP_START",
12
+ "STEP_SUCCESS",
13
+ "STEP_FAILURE",
14
+ "STEP_SKIPPED",
15
+ "STEP_OUTPUT",
16
+ "RUN_START",
17
+ "RUN_SUCCESS",
18
+ "RUN_FAILURE",
19
+ "RUN_CANCELED",
20
+ ]);
21
+ /** Default hard cap on the transport's pagination depth. */
22
+ const DEFAULT_MAX_PAGES = 100;
23
+ /** Default hard cap on the transport's replayed event count. */
24
+ const DEFAULT_MAX_EVENTS = 10000;
25
+ const LIST_JOBS_QUERY = /* GraphQL */ `
26
+ query AsGraphListJobs {
27
+ repositoriesOrError {
28
+ __typename
29
+ ... on RepositoryConnection {
30
+ nodes {
31
+ name
32
+ location {
33
+ name
34
+ }
35
+ jobs {
36
+ name
37
+ description
38
+ }
39
+ }
40
+ }
41
+ ... on PythonError {
42
+ message
43
+ }
44
+ }
45
+ }
46
+ `;
47
+ const REPOSITORY_QUERY = /* GraphQL */ `
48
+ query AsGraphRepository($repositoryName: String!, $repositoryLocationName: String!) {
49
+ repositoryOrError(
50
+ repositorySelector: {
51
+ repositoryName: $repositoryName
52
+ repositoryLocationName: $repositoryLocationName
53
+ }
54
+ ) {
55
+ __typename
56
+ ... on Repository {
57
+ name
58
+ jobs {
59
+ name
60
+ description
61
+ solids {
62
+ name
63
+ inputs {
64
+ definition {
65
+ name
66
+ }
67
+ dependsOn {
68
+ solid {
69
+ name
70
+ }
71
+ definition {
72
+ name
73
+ }
74
+ }
75
+ }
76
+ outputs {
77
+ definition {
78
+ name
79
+ }
80
+ }
81
+ }
82
+ }
83
+ schedules {
84
+ name
85
+ cronSchedule
86
+ executionTimezone
87
+ pipelineName
88
+ }
89
+ sensors {
90
+ name
91
+ sensorType
92
+ targets {
93
+ pipelineName
94
+ }
95
+ }
96
+ assetNodes {
97
+ assetKey {
98
+ path
99
+ }
100
+ jobNames
101
+ }
102
+ }
103
+ ... on RepositoryNotFoundError {
104
+ message
105
+ }
106
+ ... on PythonError {
107
+ message
108
+ }
109
+ }
110
+ }
111
+ `;
112
+ const RUN_QUERY = /* GraphQL */ `
113
+ query AsGraphRun($runId: ID!) {
114
+ runOrError(runId: $runId) {
115
+ __typename
116
+ ... on Run {
117
+ runId
118
+ jobName
119
+ status
120
+ startTime
121
+ endTime
122
+ }
123
+ ... on RunNotFoundError {
124
+ message
125
+ }
126
+ ... on PythonError {
127
+ message
128
+ }
129
+ }
130
+ }
131
+ `;
132
+ const RUN_EVENTS_QUERY = /* GraphQL */ `
133
+ query AsGraphRunEvents($runId: ID!, $after: String) {
134
+ runOrError(runId: $runId) {
135
+ __typename
136
+ ... on Run {
137
+ runId
138
+ status
139
+ eventConnection(afterCursor: $after, limit: 1000) {
140
+ cursor
141
+ hasMore
142
+ events {
143
+ __typename
144
+ ... on MessageEvent {
145
+ eventType
146
+ timestamp
147
+ message
148
+ stepKey
149
+ }
150
+ ... on ExecutionStepOutputEvent {
151
+ outputName
152
+ }
153
+ }
154
+ }
155
+ }
156
+ ... on RunNotFoundError {
157
+ message
158
+ }
159
+ ... on PythonError {
160
+ message
161
+ }
162
+ }
163
+ }
164
+ `;
165
+ const RUNS_QUERY = /* GraphQL */ `
166
+ query AsGraphRuns($pipelineName: String) {
167
+ runsOrError(filter: { pipelineName: $pipelineName }, limit: 100) {
168
+ __typename
169
+ ... on Runs {
170
+ results {
171
+ runId
172
+ jobName
173
+ status
174
+ }
175
+ }
176
+ ... on PythonError {
177
+ message
178
+ }
179
+ }
180
+ }
181
+ `;
182
+ const TERMINATE_RUN_MUTATION = /* GraphQL */ `
183
+ mutation AsGraphTerminateRun($runId: String!) {
184
+ terminateRun(runId: $runId) {
185
+ __typename
186
+ ... on TerminateRunSuccess {
187
+ run {
188
+ runId
189
+ }
190
+ }
191
+ ... on TerminateRunFailure {
192
+ message
193
+ }
194
+ ... on RunNotFoundError {
195
+ message
196
+ }
197
+ ... on PythonError {
198
+ message
199
+ }
200
+ }
201
+ }
202
+ `;
203
+ /**
204
+ * Launches a run of an already-deployed job. This is not authoring: the job must
205
+ * already exist in the deployment; the mutation only selects it and launches a
206
+ * run. The driver never emits Python.
207
+ */
208
+ const LAUNCH_RUN_MUTATION = /* GraphQL */ `
209
+ mutation AsGraphLaunchRun($executionParams: ExecutionParams!) {
210
+ launchRun(executionParams: $executionParams) {
211
+ __typename
212
+ ... on LaunchRunSuccess {
213
+ run {
214
+ runId
215
+ status
216
+ }
217
+ }
218
+ ... on RunConfigValidationInvalid {
219
+ errors {
220
+ message
221
+ }
222
+ }
223
+ ... on PipelineNotFoundError {
224
+ message
225
+ }
226
+ ... on RunConflict {
227
+ message
228
+ }
229
+ ... on UnauthorizedError {
230
+ message
231
+ }
232
+ ... on PythonError {
233
+ message
234
+ }
235
+ }
236
+ }
237
+ `;
238
+ /**
239
+ * Re-executes an existing run from its run id through Dagster's dedicated
240
+ * re-execution mutation (`launchRunReexecution`). Dagster requires exactly one of
241
+ * `executionParams` or `reexecutionParams`; selecting a parent run uses the
242
+ * latter. The parent run must already exist; the driver never authors a job or
243
+ * emits Python.
244
+ */
245
+ const REEXECUTE_RUN_MUTATION = /* GraphQL */ `
246
+ mutation AsGraphReexecuteRun($reexecutionParams: ReexecutionParams!) {
247
+ launchRunReexecution(reexecutionParams: $reexecutionParams) {
248
+ __typename
249
+ ... on LaunchRunSuccess {
250
+ run {
251
+ runId
252
+ status
253
+ }
254
+ }
255
+ ... on RunConfigValidationInvalid {
256
+ errors {
257
+ message
258
+ }
259
+ }
260
+ ... on PipelineNotFoundError {
261
+ message
262
+ }
263
+ ... on RunConflict {
264
+ message
265
+ }
266
+ ... on UnauthorizedError {
267
+ message
268
+ }
269
+ ... on PythonError {
270
+ message
271
+ }
272
+ }
273
+ }
274
+ `;
275
+ /**
276
+ * Real, read-only Dagster GraphQL client implementing the production
277
+ * `DagsterClient` port. It never authors a workflow or launches a run.
278
+ */
279
+ class DagsterGraphQLClient {
280
+ /**
281
+ * @param options - Endpoint URL, fetch implementation, timeout, and repository
282
+ * selector.
283
+ */
284
+ constructor(options) {
285
+ this.url = options.url;
286
+ this.fetchImpl = options.fetchImpl ?? fetch;
287
+ this.requestTimeoutMs = options.requestTimeoutMs ?? 15000;
288
+ this.repositoryName = options.repositoryName ?? "__repository__";
289
+ this.repositoryLocationName =
290
+ options.repositoryLocationName ?? "definitions.py";
291
+ }
292
+ /**
293
+ * Sends a GraphQL operation and unwraps the `data` envelope, failing loudly
294
+ * on transport, HTTP, or GraphQL errors.
295
+ *
296
+ * @typeParam T - The expected `data` shape.
297
+ * @param query - The GraphQL document.
298
+ * @param variables - Optional operation variables.
299
+ * @param signal - Optional caller signal composed with the request timeout.
300
+ * @returns The response `data`.
301
+ */
302
+ async request(query, variables, signal) {
303
+ const timeoutSignal = AbortSignal.timeout(this.requestTimeoutMs);
304
+ const effectiveSignal = signal
305
+ ? AbortSignal.any([signal, timeoutSignal])
306
+ : timeoutSignal;
307
+ const response = await this.fetchImpl(this.url, {
308
+ method: "POST",
309
+ headers: { "content-type": "application/json" },
310
+ body: JSON.stringify({ query, variables }),
311
+ signal: effectiveSignal,
312
+ });
313
+ if (!response.ok) {
314
+ throw new Error(`Dagster GraphQL request failed with HTTP ${response.status}`);
315
+ }
316
+ const body = (await response.json());
317
+ if (body.errors?.length) {
318
+ throw new Error(`Dagster GraphQL errors: ${body.errors
319
+ .map((error) => error.message)
320
+ .join("; ")}`);
321
+ }
322
+ if (!body.data) {
323
+ throw new Error("Dagster GraphQL response carried no data");
324
+ }
325
+ return body.data;
326
+ }
327
+ /**
328
+ * Lists every already-deployed Dagster job across the served repositories.
329
+ *
330
+ * @returns The deployed job summaries.
331
+ */
332
+ async listJobs() {
333
+ const data = await this.request(LIST_JOBS_QUERY);
334
+ const connection = data.repositoriesOrError;
335
+ if (connection.__typename !== "RepositoryConnection") {
336
+ throw new Error(`Dagster repository listing failed: ${connection.message ?? connection.__typename}`);
337
+ }
338
+ const summaries = [];
339
+ for (const repository of connection.nodes ?? []) {
340
+ for (const job of repository.jobs) {
341
+ summaries.push({
342
+ name: job.name,
343
+ ...(job.description ? { description: job.description } : {}),
344
+ });
345
+ }
346
+ }
347
+ return summaries;
348
+ }
349
+ /**
350
+ * Reads a single already-deployed Dagster job, including its real graph
351
+ * structure (ops, dependencies, asset keys, schedules, sensors).
352
+ *
353
+ * @param jobName - The Dagster job name.
354
+ * @returns The inspected job record.
355
+ */
356
+ async getJob(jobName) {
357
+ const data = await this.request(REPOSITORY_QUERY, {
358
+ repositoryName: this.repositoryName,
359
+ repositoryLocationName: this.repositoryLocationName,
360
+ });
361
+ const repository = data.repositoryOrError;
362
+ if (repository.__typename !== "Repository") {
363
+ throw new Error(`Dagster repository lookup failed: ${repository.message ?? repository.__typename}`);
364
+ }
365
+ const job = (repository.jobs ?? []).find((candidate) => candidate.name === jobName);
366
+ if (!job) {
367
+ throw new Error(`Dagster job '${jobName}' was not found in the deployment`);
368
+ }
369
+ return this.toJobRecord(job, repository);
370
+ }
371
+ /**
372
+ * Replays the recorded event stream of an EXISTING Dagster run and invokes the
373
+ * handler for every documented graph-transition event. The client never launches
374
+ * a run; it only reads a run that already exists.
375
+ *
376
+ * @param runId - The Dagster run id.
377
+ * @param handler - The per-event callback.
378
+ * @param options - Optional signal/event/page bounds.
379
+ * @returns A subscription handle.
380
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_OBSERVE_ABORTED` when the signal
381
+ * is already aborted before or during the event replay,
382
+ * `GRAPH_DAGSTER_PAGE_LIMIT_EXCEEDED` when the page cap is hit, or
383
+ * `GRAPH_DAGSTER_EVENT_LIMIT_EXCEEDED` when the event cap is hit.
384
+ */
385
+ async subscribeRun(runId, handler, options = {}) {
386
+ let closed = false;
387
+ const raw = await this.fetchRunEvents(runId, options);
388
+ for (const event of raw) {
389
+ if (closed || options.signal?.aborted)
390
+ break;
391
+ const record = this.toEventRecord(event);
392
+ if (record)
393
+ handler(record);
394
+ }
395
+ return {
396
+ unsubscribe: () => {
397
+ closed = true;
398
+ },
399
+ };
400
+ }
401
+ /**
402
+ * Terminates an EXISTING Dagster run through the GraphQL mutation.
403
+ *
404
+ * @param runId - The Dagster run id.
405
+ * @param reason - Optional termination reason (unused by Dagster).
406
+ */
407
+ async terminateRun(runId, reason) {
408
+ void reason;
409
+ const data = await this.request(TERMINATE_RUN_MUTATION, { runId });
410
+ const result = data.terminateRun;
411
+ if (result.__typename !== "TerminateRunSuccess") {
412
+ throw new Error(`Dagster run termination failed: ${result.message ?? result.__typename}`);
413
+ }
414
+ }
415
+ /**
416
+ * Launches a run of an ALREADY-DEPLOYED Dagster job through the real GraphQL
417
+ * `launchRun` mutation. The job must already exist in the deployment; no job or
418
+ * op is authored and no Python is emitted.
419
+ *
420
+ * @param request - The job name, optional raw run config, and optional tags.
421
+ * @returns The launched run's id and initial status.
422
+ */
423
+ async launchRun(request) {
424
+ const data = await this.request(LAUNCH_RUN_MUTATION, {
425
+ executionParams: this.executionParams(request.jobName, request.runConfig, request.tags),
426
+ });
427
+ return this.toLaunchedRun(data.launchRun, request.jobName);
428
+ }
429
+ /**
430
+ * Re-executes an EXISTING Dagster run from its run id through the real GraphQL
431
+ * `launchRunReexecution` mutation (Dagster's re-execution surface). The parent
432
+ * run must already exist; no job or op is authored and no Python is emitted.
433
+ *
434
+ * @param request - The parent run id, its job name, and optional tags.
435
+ * @returns The re-executed run's id and initial status.
436
+ */
437
+ async replayRun(request) {
438
+ const reexecutionParams = {
439
+ parentRunId: request.dagsterRunId,
440
+ strategy: "ALL_STEPS",
441
+ };
442
+ if (request.tags && Object.keys(request.tags).length > 0) {
443
+ reexecutionParams["extraTags"] = Object.entries(request.tags).map(([key, value]) => ({ key, value }));
444
+ }
445
+ const data = await this.request(REEXECUTE_RUN_MUTATION, { reexecutionParams });
446
+ return this.toLaunchedRun(data.launchRunReexecution, request.jobName ?? request.dagsterRunId);
447
+ }
448
+ /**
449
+ * Builds the GraphQL `ExecutionParams` for a launch/re-execution: the job
450
+ * selector, optional raw run config, and optional run tags.
451
+ *
452
+ * @param jobName - The already-deployed job name.
453
+ * @param runConfig - Optional raw Dagster run config (forwarded verbatim).
454
+ * @param tags - Optional run tags.
455
+ * @returns The `ExecutionParams` input object.
456
+ */
457
+ executionParams(jobName, runConfig, tags) {
458
+ const executionMetadata = {};
459
+ if (tags && Object.keys(tags).length > 0) {
460
+ executionMetadata["tags"] = Object.entries(tags).map(([key, value]) => ({
461
+ key,
462
+ value,
463
+ }));
464
+ }
465
+ return {
466
+ selector: {
467
+ pipelineName: jobName,
468
+ repositoryName: this.repositoryName,
469
+ repositoryLocationName: this.repositoryLocationName,
470
+ },
471
+ ...(runConfig ? { runConfigData: runConfig } : {}),
472
+ ...(Object.keys(executionMetadata).length > 0
473
+ ? { executionMetadata }
474
+ : {}),
475
+ };
476
+ }
477
+ /**
478
+ * Unwraps a launch/re-execution result union into a run handle, failing loudly
479
+ * on a launch error.
480
+ *
481
+ * @param result - The raw launch result union.
482
+ * @param jobName - The job name, for error context.
483
+ * @returns The launched run's id and initial status.
484
+ */
485
+ toLaunchedRun(result, jobName) {
486
+ if (result.__typename !== "LaunchRunSuccess" || !result.run) {
487
+ const detail = result.errors?.map((error) => error.message).join("; ") ??
488
+ result.message ??
489
+ result.__typename;
490
+ throw new Error(`Dagster launch of job '${jobName}' failed: ${detail}`);
491
+ }
492
+ return {
493
+ runId: result.run.runId,
494
+ status: this.toRunStatus(result.run.status),
495
+ };
496
+ }
497
+ /**
498
+ * Reads an EXISTING Dagster run's terminal record.
499
+ *
500
+ * @param runId - The Dagster run id.
501
+ * @returns The terminal run record.
502
+ */
503
+ async getRun(runId) {
504
+ const data = await this.request(RUN_QUERY, {
505
+ runId,
506
+ });
507
+ return this.toRunRecord(data.runOrError);
508
+ }
509
+ /**
510
+ * Harness-only helper: lists the runs for a job (or every run when no job name
511
+ * is given) with their raw Dagster status. Not part of the `DagsterClient` port;
512
+ * it exists so the suite can discover a pre-existing terminal run (e.g. the
513
+ * `etl_pipeline` run materialized at startup) without launching one, and can
514
+ * count runs before/after an operation to prove no run was created.
515
+ *
516
+ * @param jobName - Optional Dagster job name filter.
517
+ * @returns The runs, with raw Dagster run status.
518
+ */
519
+ async listRuns(jobName) {
520
+ const data = await this.request(RUNS_QUERY, jobName ? { pipelineName: jobName } : {});
521
+ const runs = data.runsOrError;
522
+ if (runs.__typename !== "Runs") {
523
+ throw new Error(`Dagster run listing failed: ${runs.message ?? runs.__typename}`);
524
+ }
525
+ return (runs.results ?? []).map((run) => ({
526
+ runId: run.runId,
527
+ jobName: run.jobName,
528
+ status: run.status,
529
+ }));
530
+ }
531
+ /**
532
+ * Harness-only helper: lists the ids of runs for a job (or every run when no
533
+ * job name is given). Not part of the `DagsterClient` port; it exists so the
534
+ * suite can discover a pre-existing run without launching one.
535
+ *
536
+ * @param jobName - Optional Dagster job name filter.
537
+ * @returns The run ids.
538
+ */
539
+ async listRunIds(jobName) {
540
+ const runs = await this.listRuns(jobName);
541
+ return runs.map((run) => run.runId);
542
+ }
543
+ /** Disposes the client; the fetch transport holds no resources. */
544
+ dispose() {
545
+ return;
546
+ }
547
+ /**
548
+ * Paginates the run's recorded event stream, bounded by `maxPages` and
549
+ * `maxEvents` so a gateway whose `eventConnection` never reports
550
+ * `hasMore: false` cannot page or buffer without limit.
551
+ *
552
+ * @param runId - The Dagster run id.
553
+ * @param options - Optional signal/event/page bounds.
554
+ * @returns The raw events, in order.
555
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_PAGE_LIMIT_EXCEEDED` when the
556
+ * page cap is hit, or `GRAPH_DAGSTER_EVENT_LIMIT_EXCEEDED` when the event cap
557
+ * is hit.
558
+ */
559
+ async fetchRunEvents(runId, options = {}) {
560
+ const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
561
+ const maxEvents = options.maxEvents ?? DEFAULT_MAX_EVENTS;
562
+ const events = [];
563
+ let after;
564
+ let pages = 0;
565
+ for (;;) {
566
+ if (options.signal?.aborted) {
567
+ throw new index_js_1.GraphExecutionError(`Dagster run '${runId}' event replay was aborted by the caller`, constants_js_1.DAGSTER_ERROR.OBSERVE_ABORTED, { runId });
568
+ }
569
+ if (pages >= maxPages) {
570
+ throw new index_js_1.GraphExecutionError(`Dagster run '${runId}' event replay exceeded the ${maxPages}-page cap`, constants_js_1.DAGSTER_ERROR.PAGE_LIMIT_EXCEEDED, { runId, maxPages });
571
+ }
572
+ const data = await this.request(RUN_EVENTS_QUERY, after ? { runId, after } : { runId }, options.signal);
573
+ pages += 1;
574
+ const run = data.runOrError;
575
+ if (run.__typename !== "Run") {
576
+ throw new Error(`Dagster run event lookup failed: ${run.message ?? run.__typename}`);
577
+ }
578
+ const connection = run.eventConnection;
579
+ if (!connection)
580
+ break;
581
+ events.push(...connection.events);
582
+ if (events.length > maxEvents) {
583
+ throw new index_js_1.GraphExecutionError(`Dagster run '${runId}' event replay exceeded the ${maxEvents}-event cap`, constants_js_1.DAGSTER_ERROR.EVENT_LIMIT_EXCEEDED, { runId, maxEvents });
584
+ }
585
+ if (!connection.hasMore)
586
+ break;
587
+ after = connection.cursor;
588
+ }
589
+ return events;
590
+ }
591
+ /**
592
+ * Maps a raw Dagster event onto the driver's documented `DagsterEventRecord`
593
+ * contract, filtering out non-graph-transition telemetry.
594
+ *
595
+ * @param event - The raw event.
596
+ * @returns The driver event record, or `undefined` when the event is engine
597
+ * telemetry the read-only driver does not consume.
598
+ */
599
+ toEventRecord(event) {
600
+ const type = event.eventType;
601
+ if (!type || !DAGSTER_MAPPED_EVENT_TYPES.has(type))
602
+ return undefined;
603
+ const record = { type };
604
+ if (event.stepKey)
605
+ record.stepKey = event.stepKey;
606
+ if (event.timestamp) {
607
+ record.timestamp = new Date(Number(event.timestamp)).toISOString();
608
+ }
609
+ if (event.message)
610
+ record.message = event.message;
611
+ if (type === "STEP_OUTPUT" && event.outputName) {
612
+ record.payload = { outputs: { [event.outputName]: event.outputName } };
613
+ }
614
+ return record;
615
+ }
616
+ /**
617
+ * Maps a raw `Run` onto the driver's `DagsterRunRecord` contract.
618
+ *
619
+ * @param run - The raw run.
620
+ * @returns The driver run record.
621
+ */
622
+ toRunRecord(run) {
623
+ if (run.__typename !== "Run") {
624
+ throw new Error(`Dagster run lookup failed: ${run.message ?? run.__typename}`);
625
+ }
626
+ const record = {
627
+ runId: run.runId ?? "",
628
+ status: this.toRunStatus(run.status),
629
+ outputs: {},
630
+ ...(run.jobName ? { jobName: run.jobName } : {}),
631
+ };
632
+ if (run.startTime) {
633
+ record.startedAt = new Date(run.startTime * 1000).toISOString();
634
+ }
635
+ if (run.endTime) {
636
+ record.finishedAt = new Date(run.endTime * 1000).toISOString();
637
+ }
638
+ return record;
639
+ }
640
+ /**
641
+ * Maps a Dagster `RunStatus` onto the driver's terminal run status.
642
+ *
643
+ * @param status - The raw Dagster run status.
644
+ * @returns The driver run status.
645
+ */
646
+ toRunStatus(status) {
647
+ switch (status) {
648
+ case "SUCCESS":
649
+ return "success";
650
+ case "FAILURE":
651
+ return "failure";
652
+ case "CANCELED":
653
+ return "canceled";
654
+ case "QUEUED":
655
+ return "QUEUED";
656
+ case "STARTING":
657
+ return "STARTING";
658
+ default:
659
+ return "started";
660
+ }
661
+ }
662
+ /**
663
+ * Maps a raw job plus its repository context onto the driver's
664
+ * `DagsterJobRecord` contract.
665
+ *
666
+ * @param job - The raw job.
667
+ * @param repository - The raw repository the job belongs to.
668
+ * @returns The inspected job record.
669
+ */
670
+ toJobRecord(job, repository) {
671
+ const assetKeys = this.assetKeysFor(job.name, repository.assetNodes ?? []);
672
+ const ops = job.solids.map((solid) => {
673
+ const op = {
674
+ name: solid.name,
675
+ inputs: solid.inputs.map((input) => input.definition.name),
676
+ outputs: solid.outputs.map((output) => output.definition.name),
677
+ };
678
+ const keys = assetKeys.filter((key) => key.split(".").pop() === solid.name);
679
+ if (keys.length)
680
+ op.assetKeys = keys;
681
+ return op;
682
+ });
683
+ const dependencies = [];
684
+ for (const solid of job.solids) {
685
+ for (const input of solid.inputs) {
686
+ for (const upstream of input.dependsOn) {
687
+ dependencies.push({
688
+ from: upstream.solid.name,
689
+ to: solid.name,
690
+ });
691
+ }
692
+ }
693
+ }
694
+ const schedules = (repository.schedules ?? [])
695
+ .filter((schedule) => schedule.pipelineName === job.name)
696
+ .map((schedule) => ({
697
+ name: schedule.name,
698
+ ...(schedule.cronSchedule ? { cron: schedule.cronSchedule } : {}),
699
+ ...(schedule.executionTimezone
700
+ ? { timezone: schedule.executionTimezone }
701
+ : {}),
702
+ }));
703
+ const sensors = (repository.sensors ?? [])
704
+ .filter((sensor) => sensor.targets.some((target) => target.pipelineName === job.name))
705
+ .map((sensor) => ({
706
+ name: sensor.name,
707
+ ...(sensor.sensorType ? { kind: sensor.sensorType } : {}),
708
+ }));
709
+ return {
710
+ name: job.name,
711
+ ...(job.description ? { description: job.description } : {}),
712
+ ops,
713
+ dependencies,
714
+ ...(assetKeys.length ? { assetKeys } : {}),
715
+ ...(schedules.length ? { schedules } : {}),
716
+ ...(sensors.length ? { sensors } : {}),
717
+ };
718
+ }
719
+ /**
720
+ * Resolves the asset keys a job produces from the repository's asset nodes.
721
+ *
722
+ * @param jobName - The Dagster job name.
723
+ * @param assetNodes - The repository asset nodes.
724
+ * @returns The dotted asset keys.
725
+ */
726
+ assetKeysFor(jobName, assetNodes) {
727
+ const keys = [];
728
+ for (const node of assetNodes) {
729
+ if (!node.jobNames.includes(jobName))
730
+ continue;
731
+ keys.push(node.assetKey.path.join("."));
732
+ }
733
+ return keys;
734
+ }
735
+ }
736
+ exports.DagsterGraphQLClient = DagsterGraphQLClient;
737
+ //# sourceMappingURL=DagsterGraphQLClient.js.map
738
+ //# sourceMappingURL=DagsterGraphQLClient.cjs.map