@ms-cloudpack/api-server 0.42.1 → 0.43.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 (62) hide show
  1. package/lib/apis/index.d.ts +2 -0
  2. package/lib/apis/index.d.ts.map +1 -1
  3. package/lib/apis/index.js +2 -0
  4. package/lib/apis/index.js.map +1 -1
  5. package/lib/apis/openCodeEditor.d.ts +4 -4
  6. package/lib/apis/restartAllTasks.d.ts +19 -0
  7. package/lib/apis/restartAllTasks.d.ts.map +1 -0
  8. package/lib/apis/restartAllTasks.js +19 -0
  9. package/lib/apis/restartAllTasks.js.map +1 -0
  10. package/lib/apis/restartTask.d.ts +38 -0
  11. package/lib/apis/restartTask.d.ts.map +1 -0
  12. package/lib/apis/restartTask.js +19 -0
  13. package/lib/apis/restartTask.js.map +1 -0
  14. package/lib/common/createPartialApiContext.d.ts.map +1 -1
  15. package/lib/common/createPartialApiContext.js +5 -1
  16. package/lib/common/createPartialApiContext.js.map +1 -1
  17. package/lib/common/createSession.d.ts.map +1 -1
  18. package/lib/common/createSession.js +2 -6
  19. package/lib/common/createSession.js.map +1 -1
  20. package/lib/data/busSources.d.ts +42 -36
  21. package/lib/data/busSources.d.ts.map +1 -1
  22. package/lib/data/busSources.js +2 -4
  23. package/lib/data/busSources.js.map +1 -1
  24. package/lib/index.d.ts +1 -0
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js.map +1 -1
  27. package/lib/startApiServer.d.ts.map +1 -1
  28. package/lib/startApiServer.js +11 -73
  29. package/lib/startApiServer.js.map +1 -1
  30. package/lib/trpc/createAppRouter.d.ts +36 -2
  31. package/lib/trpc/createAppRouter.d.ts.map +1 -1
  32. package/lib/trpc/createCloudpackServer.d.ts +6 -1
  33. package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
  34. package/lib/trpc/createContextFactory.js +1 -1
  35. package/lib/trpc/createContextFactory.js.map +1 -1
  36. package/lib/tsdoc-metadata.json +1 -1
  37. package/lib/types/Session.d.ts +11 -13
  38. package/lib/types/Session.d.ts.map +1 -1
  39. package/lib/types/Session.js.map +1 -1
  40. package/lib/types/TaskDescription.d.ts +23 -20
  41. package/lib/types/TaskDescription.d.ts.map +1 -1
  42. package/lib/types/TaskList.d.ts +392 -0
  43. package/lib/types/TaskList.d.ts.map +1 -0
  44. package/lib/types/TaskList.js +6 -0
  45. package/lib/types/TaskList.js.map +1 -0
  46. package/lib/types/TaskRunnerContext.d.ts +3 -0
  47. package/lib/types/TaskRunnerContext.d.ts.map +1 -0
  48. package/lib/types/TaskRunnerContext.js +2 -0
  49. package/lib/types/TaskRunnerContext.js.map +1 -0
  50. package/lib/utilities/TaskRunner.d.ts +19 -6
  51. package/lib/utilities/TaskRunner.d.ts.map +1 -1
  52. package/lib/utilities/TaskRunner.js +94 -18
  53. package/lib/utilities/TaskRunner.js.map +1 -1
  54. package/lib/utilities/createBundleTask.d.ts +1 -1
  55. package/lib/utilities/createBundleTask.d.ts.map +1 -1
  56. package/lib/utilities/createBundleTask.js +8 -2
  57. package/lib/utilities/createBundleTask.js.map +1 -1
  58. package/lib/utilities/getDefaultTaskStats.d.ts +3 -0
  59. package/lib/utilities/getDefaultTaskStats.d.ts.map +1 -0
  60. package/lib/utilities/getDefaultTaskStats.js +8 -0
  61. package/lib/utilities/getDefaultTaskStats.js.map +1 -0
  62. package/package.json +11 -11
@@ -0,0 +1,392 @@
1
+ import { z } from 'zod';
2
+ export declare const ZodTaskList: z.ZodObject<{
3
+ tasks: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
4
+ status: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"pending">, z.ZodLiteral<"complete">]>>;
5
+ timings: z.ZodOptional<z.ZodArray<z.ZodObject<{
6
+ name: z.ZodString;
7
+ start: z.ZodNumber;
8
+ end: z.ZodOptional<z.ZodNumber>;
9
+ threwException: z.ZodOptional<z.ZodBoolean>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ name: string;
12
+ start: number;
13
+ end?: number | undefined;
14
+ threwException?: boolean | undefined;
15
+ }, {
16
+ name: string;
17
+ start: number;
18
+ end?: number | undefined;
19
+ threwException?: boolean | undefined;
20
+ }>, "many">>;
21
+ startTime: z.ZodNumber;
22
+ durationMilliseconds: z.ZodOptional<z.ZodNumber>;
23
+ lastUpdated: z.ZodOptional<z.ZodNumber>;
24
+ }, {
25
+ id: z.ZodString;
26
+ name: z.ZodOptional<z.ZodString>;
27
+ inputPath: z.ZodOptional<z.ZodString>;
28
+ outputPath: z.ZodOptional<z.ZodString>;
29
+ }>, {
30
+ id: z.ZodString;
31
+ errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ text: z.ZodString;
33
+ source: z.ZodString;
34
+ location: z.ZodOptional<z.ZodObject<{
35
+ file: z.ZodString;
36
+ line: z.ZodOptional<z.ZodNumber>;
37
+ column: z.ZodOptional<z.ZodNumber>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ file: string;
40
+ line?: number | undefined;
41
+ column?: number | undefined;
42
+ }, {
43
+ file: string;
44
+ line?: number | undefined;
45
+ column?: number | undefined;
46
+ }>>;
47
+ notes: z.ZodOptional<z.ZodArray<z.ZodObject<{
48
+ text: z.ZodString;
49
+ location: z.ZodOptional<z.ZodObject<{
50
+ file: z.ZodString;
51
+ line: z.ZodOptional<z.ZodNumber>;
52
+ column: z.ZodOptional<z.ZodNumber>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ file: string;
55
+ line?: number | undefined;
56
+ column?: number | undefined;
57
+ }, {
58
+ file: string;
59
+ line?: number | undefined;
60
+ column?: number | undefined;
61
+ }>>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ text: string;
64
+ location?: {
65
+ file: string;
66
+ line?: number | undefined;
67
+ column?: number | undefined;
68
+ } | undefined;
69
+ }, {
70
+ text: string;
71
+ location?: {
72
+ file: string;
73
+ line?: number | undefined;
74
+ column?: number | undefined;
75
+ } | undefined;
76
+ }>, "many">>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ text: string;
79
+ source: string;
80
+ location?: {
81
+ file: string;
82
+ line?: number | undefined;
83
+ column?: number | undefined;
84
+ } | undefined;
85
+ notes?: {
86
+ text: string;
87
+ location?: {
88
+ file: string;
89
+ line?: number | undefined;
90
+ column?: number | undefined;
91
+ } | undefined;
92
+ }[] | undefined;
93
+ }, {
94
+ text: string;
95
+ source: string;
96
+ location?: {
97
+ file: string;
98
+ line?: number | undefined;
99
+ column?: number | undefined;
100
+ } | undefined;
101
+ notes?: {
102
+ text: string;
103
+ location?: {
104
+ file: string;
105
+ line?: number | undefined;
106
+ column?: number | undefined;
107
+ } | undefined;
108
+ }[] | undefined;
109
+ }>, "many">>;
110
+ warnings: z.ZodOptional<z.ZodArray<z.ZodObject<{
111
+ text: z.ZodString;
112
+ source: z.ZodString;
113
+ location: z.ZodOptional<z.ZodObject<{
114
+ file: z.ZodString;
115
+ line: z.ZodOptional<z.ZodNumber>;
116
+ column: z.ZodOptional<z.ZodNumber>;
117
+ }, "strip", z.ZodTypeAny, {
118
+ file: string;
119
+ line?: number | undefined;
120
+ column?: number | undefined;
121
+ }, {
122
+ file: string;
123
+ line?: number | undefined;
124
+ column?: number | undefined;
125
+ }>>;
126
+ notes: z.ZodOptional<z.ZodArray<z.ZodObject<{
127
+ text: z.ZodString;
128
+ location: z.ZodOptional<z.ZodObject<{
129
+ file: z.ZodString;
130
+ line: z.ZodOptional<z.ZodNumber>;
131
+ column: z.ZodOptional<z.ZodNumber>;
132
+ }, "strip", z.ZodTypeAny, {
133
+ file: string;
134
+ line?: number | undefined;
135
+ column?: number | undefined;
136
+ }, {
137
+ file: string;
138
+ line?: number | undefined;
139
+ column?: number | undefined;
140
+ }>>;
141
+ }, "strip", z.ZodTypeAny, {
142
+ text: string;
143
+ location?: {
144
+ file: string;
145
+ line?: number | undefined;
146
+ column?: number | undefined;
147
+ } | undefined;
148
+ }, {
149
+ text: string;
150
+ location?: {
151
+ file: string;
152
+ line?: number | undefined;
153
+ column?: number | undefined;
154
+ } | undefined;
155
+ }>, "many">>;
156
+ }, "strip", z.ZodTypeAny, {
157
+ text: string;
158
+ source: string;
159
+ location?: {
160
+ file: string;
161
+ line?: number | undefined;
162
+ column?: number | undefined;
163
+ } | undefined;
164
+ notes?: {
165
+ text: string;
166
+ location?: {
167
+ file: string;
168
+ line?: number | undefined;
169
+ column?: number | undefined;
170
+ } | undefined;
171
+ }[] | undefined;
172
+ }, {
173
+ text: string;
174
+ source: string;
175
+ location?: {
176
+ file: string;
177
+ line?: number | undefined;
178
+ column?: number | undefined;
179
+ } | undefined;
180
+ notes?: {
181
+ text: string;
182
+ location?: {
183
+ file: string;
184
+ line?: number | undefined;
185
+ column?: number | undefined;
186
+ } | undefined;
187
+ }[] | undefined;
188
+ }>, "many">>;
189
+ }>, "strip", z.ZodTypeAny, {
190
+ id: string;
191
+ startTime: number;
192
+ status?: "pending" | "complete" | undefined;
193
+ name?: string | undefined;
194
+ inputPath?: string | undefined;
195
+ outputPath?: string | undefined;
196
+ errors?: {
197
+ text: string;
198
+ source: string;
199
+ location?: {
200
+ file: string;
201
+ line?: number | undefined;
202
+ column?: number | undefined;
203
+ } | undefined;
204
+ notes?: {
205
+ text: string;
206
+ location?: {
207
+ file: string;
208
+ line?: number | undefined;
209
+ column?: number | undefined;
210
+ } | undefined;
211
+ }[] | undefined;
212
+ }[] | undefined;
213
+ warnings?: {
214
+ text: string;
215
+ source: string;
216
+ location?: {
217
+ file: string;
218
+ line?: number | undefined;
219
+ column?: number | undefined;
220
+ } | undefined;
221
+ notes?: {
222
+ text: string;
223
+ location?: {
224
+ file: string;
225
+ line?: number | undefined;
226
+ column?: number | undefined;
227
+ } | undefined;
228
+ }[] | undefined;
229
+ }[] | undefined;
230
+ timings?: {
231
+ name: string;
232
+ start: number;
233
+ end?: number | undefined;
234
+ threwException?: boolean | undefined;
235
+ }[] | undefined;
236
+ durationMilliseconds?: number | undefined;
237
+ lastUpdated?: number | undefined;
238
+ }, {
239
+ id: string;
240
+ startTime: number;
241
+ status?: "pending" | "complete" | undefined;
242
+ name?: string | undefined;
243
+ inputPath?: string | undefined;
244
+ outputPath?: string | undefined;
245
+ errors?: {
246
+ text: string;
247
+ source: string;
248
+ location?: {
249
+ file: string;
250
+ line?: number | undefined;
251
+ column?: number | undefined;
252
+ } | undefined;
253
+ notes?: {
254
+ text: string;
255
+ location?: {
256
+ file: string;
257
+ line?: number | undefined;
258
+ column?: number | undefined;
259
+ } | undefined;
260
+ }[] | undefined;
261
+ }[] | undefined;
262
+ warnings?: {
263
+ text: string;
264
+ source: string;
265
+ location?: {
266
+ file: string;
267
+ line?: number | undefined;
268
+ column?: number | undefined;
269
+ } | undefined;
270
+ notes?: {
271
+ text: string;
272
+ location?: {
273
+ file: string;
274
+ line?: number | undefined;
275
+ column?: number | undefined;
276
+ } | undefined;
277
+ }[] | undefined;
278
+ }[] | undefined;
279
+ timings?: {
280
+ name: string;
281
+ start: number;
282
+ end?: number | undefined;
283
+ threwException?: boolean | undefined;
284
+ }[] | undefined;
285
+ durationMilliseconds?: number | undefined;
286
+ lastUpdated?: number | undefined;
287
+ }>, "many">;
288
+ }, "strip", z.ZodTypeAny, {
289
+ tasks: {
290
+ id: string;
291
+ startTime: number;
292
+ status?: "pending" | "complete" | undefined;
293
+ name?: string | undefined;
294
+ inputPath?: string | undefined;
295
+ outputPath?: string | undefined;
296
+ errors?: {
297
+ text: string;
298
+ source: string;
299
+ location?: {
300
+ file: string;
301
+ line?: number | undefined;
302
+ column?: number | undefined;
303
+ } | undefined;
304
+ notes?: {
305
+ text: string;
306
+ location?: {
307
+ file: string;
308
+ line?: number | undefined;
309
+ column?: number | undefined;
310
+ } | undefined;
311
+ }[] | undefined;
312
+ }[] | undefined;
313
+ warnings?: {
314
+ text: string;
315
+ source: string;
316
+ location?: {
317
+ file: string;
318
+ line?: number | undefined;
319
+ column?: number | undefined;
320
+ } | undefined;
321
+ notes?: {
322
+ text: string;
323
+ location?: {
324
+ file: string;
325
+ line?: number | undefined;
326
+ column?: number | undefined;
327
+ } | undefined;
328
+ }[] | undefined;
329
+ }[] | undefined;
330
+ timings?: {
331
+ name: string;
332
+ start: number;
333
+ end?: number | undefined;
334
+ threwException?: boolean | undefined;
335
+ }[] | undefined;
336
+ durationMilliseconds?: number | undefined;
337
+ lastUpdated?: number | undefined;
338
+ }[];
339
+ }, {
340
+ tasks: {
341
+ id: string;
342
+ startTime: number;
343
+ status?: "pending" | "complete" | undefined;
344
+ name?: string | undefined;
345
+ inputPath?: string | undefined;
346
+ outputPath?: string | undefined;
347
+ errors?: {
348
+ text: string;
349
+ source: string;
350
+ location?: {
351
+ file: string;
352
+ line?: number | undefined;
353
+ column?: number | undefined;
354
+ } | undefined;
355
+ notes?: {
356
+ text: string;
357
+ location?: {
358
+ file: string;
359
+ line?: number | undefined;
360
+ column?: number | undefined;
361
+ } | undefined;
362
+ }[] | undefined;
363
+ }[] | undefined;
364
+ warnings?: {
365
+ text: string;
366
+ source: string;
367
+ location?: {
368
+ file: string;
369
+ line?: number | undefined;
370
+ column?: number | undefined;
371
+ } | undefined;
372
+ notes?: {
373
+ text: string;
374
+ location?: {
375
+ file: string;
376
+ line?: number | undefined;
377
+ column?: number | undefined;
378
+ } | undefined;
379
+ }[] | undefined;
380
+ }[] | undefined;
381
+ timings?: {
382
+ name: string;
383
+ start: number;
384
+ end?: number | undefined;
385
+ threwException?: boolean | undefined;
386
+ }[] | undefined;
387
+ durationMilliseconds?: number | undefined;
388
+ lastUpdated?: number | undefined;
389
+ }[];
390
+ }>;
391
+ export type TaskList = z.infer<typeof ZodTaskList>;
392
+ //# sourceMappingURL=TaskList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskList.d.ts","sourceRoot":"","sources":["../../src/types/TaskList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEtB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ import { ZodTaskDescription } from './TaskDescription.js';
3
+ export const ZodTaskList = z.object({
4
+ tasks: z.array(ZodTaskDescription),
5
+ });
6
+ //# sourceMappingURL=TaskList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskList.js","sourceRoot":"","sources":["../../src/types/TaskList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC;CACnC,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport { ZodTaskDescription } from './TaskDescription.js';\n\nexport const ZodTaskList = z.object({\n tasks: z.array(ZodTaskDescription),\n});\n\nexport type TaskList = z.infer<typeof ZodTaskList>;\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Context } from './Context.js';
2
+ export type TaskRunnerContext = Pick<Context, 'reporter' | 'bus' | 'session'>;
3
+ //# sourceMappingURL=TaskRunnerContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskRunnerContext.d.ts","sourceRoot":"","sources":["../../src/types/TaskRunnerContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TaskRunnerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskRunnerContext.js","sourceRoot":"","sources":["../../src/types/TaskRunnerContext.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context } from './Context.js';\n\nexport type TaskRunnerContext = Pick<Context, 'reporter' | 'bus' | 'session'>;\n"]}
@@ -1,18 +1,19 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { TaskOptions } from '../types/TaskOptions.js';
3
2
  import type { Task } from '../types/Task.js';
4
- import EventEmitter from 'events';
3
+ import type { TaskRunnerContext } from '../types/TaskRunnerContext.js';
5
4
  /**
6
5
  * TaskRunner class manages the state of Tasks.
7
6
  * This class is to be called by the api server.
8
7
  */
9
- export declare class TaskRunner extends EventEmitter {
8
+ export declare class TaskRunner {
9
+ private _context;
10
10
  private _queue;
11
+ private _taskStats;
11
12
  private _pendingTasks;
12
13
  private _completedTasks;
13
14
  private _requiresRerun;
14
15
  private _prevTasks;
15
- constructor();
16
+ constructor(context?: TaskRunnerContext);
16
17
  /**
17
18
  * The add method enqueues a Task and returns its Promise.
18
19
  * If a Task with the same id has already been processed,
@@ -30,9 +31,21 @@ export declare class TaskRunner extends EventEmitter {
30
31
  * to clear the TaskRunner's state before reloading the page.
31
32
  */
32
33
  remove(id: string): void;
34
+ /**
35
+ * The clear method disposes all tasks and clears the TaskRunner.
36
+ */
37
+ clear(): void;
33
38
  /** Pauses the TaskRunner (for testing). */
34
- pause(): void;
39
+ _pause(): void;
35
40
  /** Starts or resumes the TaskRunner (for testing). */
36
- start(): void;
41
+ _start(): void;
42
+ /**
43
+ * Internal method to report the start of a task to the bus.
44
+ */
45
+ private _reportStart;
46
+ /**
47
+ * Internal method to report the end of a task to the bus.
48
+ */
49
+ private _reportEnd;
37
50
  }
38
51
  //# sourceMappingURL=TaskRunner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,YAAY,MAAM,QAAQ,CAAC;AAOlC;;;GAGG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;;IAY3C;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAiF1E;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAcxB,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAIb,sDAAsD;IACtD,KAAK,IAAI,IAAI;CAGd"}
1
+ {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;GAGG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;gBAE/B,OAAO,CAAC,EAAE,iBAAiB;IAevC;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IA6E1E;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAaxB;;OAEG;IACH,KAAK,IAAI,IAAI;IAYb,2CAA2C;IAC3C,MAAM,IAAI,IAAI;IAId,sDAAsD;IACtD,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,CAAC,YAAY;IAmCpB;;OAEG;IACH,OAAO,CAAC,UAAU;CA6BnB"}
@@ -1,21 +1,23 @@
1
1
  import PQueue from 'p-queue';
2
- import EventEmitter from 'events';
3
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
- const log = (...messages) => {
5
- // console.log(`TaskRunner:`, ...messages);
6
- };
2
+ import { getDefaultTaskStats } from './getDefaultTaskStats.js';
3
+ import { taskListSource, taskStatsSource } from '../index.browser.js';
7
4
  /**
8
5
  * TaskRunner class manages the state of Tasks.
9
6
  * This class is to be called by the api server.
10
7
  */
11
- export class TaskRunner extends EventEmitter {
12
- constructor() {
13
- super();
8
+ export class TaskRunner {
9
+ constructor(context) {
10
+ this._context = context;
14
11
  this._queue = new PQueue({ concurrency: 10 });
12
+ this._taskStats = getDefaultTaskStats();
15
13
  this._pendingTasks = new Map();
16
14
  this._completedTasks = new Map();
17
15
  this._requiresRerun = new Set();
18
16
  this._prevTasks = new Map();
17
+ if (this._context) {
18
+ const { bus, session } = this._context;
19
+ bus.publish([session.id, 'status'], this._taskStats);
20
+ }
19
21
  }
20
22
  /**
21
23
  * The add method enqueues a Task and returns its Promise.
@@ -33,7 +35,6 @@ export class TaskRunner extends EventEmitter {
33
35
  // Check if we are already completed the task with that id.
34
36
  const action = this._completedTasks.get(id);
35
37
  if (action !== undefined && !rerun) {
36
- log(`Previous action found, returning: "${name}:${id}"`);
37
38
  return Promise.resolve(action);
38
39
  }
39
40
  // Check if we are already running the task with that id.
@@ -42,7 +43,6 @@ export class TaskRunner extends EventEmitter {
42
43
  if (rerun) {
43
44
  this._requiresRerun.add(id);
44
45
  }
45
- log(`Previous action found, waiting: "${name}:${id}"`);
46
46
  return pending;
47
47
  }
48
48
  const resultPromise = (async () => {
@@ -53,22 +53,21 @@ export class TaskRunner extends EventEmitter {
53
53
  taskResult = await this._queue.add(async () => {
54
54
  const startDescription = {
55
55
  ...task.getStartDescription?.(),
56
- id: task.id,
56
+ id,
57
57
  };
58
- this.emit('executeStarted', startDescription);
58
+ this._reportStart(id, startDescription);
59
59
  const result = await execute();
60
60
  const endDescription = {
61
61
  ...task.getEndDescription?.(result),
62
- id: task.id,
62
+ id,
63
63
  };
64
- this.emit('executeCompleted', endDescription);
64
+ this._reportEnd(id, endDescription);
65
65
  return result;
66
66
  },
67
67
  // Removes void from return type.
68
68
  // Read more on: https://github.com/sindresorhus/p-queue/issues/175
69
69
  { throwOnTimeout: true, priority });
70
70
  } while (this._requiresRerun.has(id));
71
- log(`Task finished: "${name}:${id}"`);
72
71
  // Delete from pending list.
73
72
  this._pendingTasks.delete(id);
74
73
  // Extra check to ensure that the task returned a value.
@@ -98,7 +97,7 @@ export class TaskRunner extends EventEmitter {
98
97
  .get(id)
99
98
  ?.dispose?.()
100
99
  .catch(() => {
101
- log(`Error disposing task: ${id}`);
100
+ console.debug(`Error disposing task: ${id}`);
102
101
  });
103
102
  this._prevTasks.get(id)?.clear?.();
104
103
  this._prevTasks.delete(id);
@@ -106,13 +105,90 @@ export class TaskRunner extends EventEmitter {
106
105
  this._pendingTasks.delete(id);
107
106
  this._completedTasks.delete(id);
108
107
  }
108
+ /**
109
+ * The clear method disposes all tasks and clears the TaskRunner.
110
+ */
111
+ clear() {
112
+ this._taskStats = getDefaultTaskStats();
113
+ if (this._context) {
114
+ const { bus, session } = this._context;
115
+ bus.publish([session.id, 'status'], this._taskStats);
116
+ bus.publish(taskListSource, { tasks: [] });
117
+ }
118
+ for (const id of this._prevTasks.keys()) {
119
+ this.remove(id);
120
+ }
121
+ }
109
122
  /** Pauses the TaskRunner (for testing). */
110
- pause() {
123
+ _pause() {
111
124
  this._queue.pause();
112
125
  }
113
126
  /** Starts or resumes the TaskRunner (for testing). */
114
- start() {
127
+ _start() {
115
128
  this._queue.start();
116
129
  }
130
+ /**
131
+ * Internal method to report the start of a task to the bus.
132
+ */
133
+ _reportStart(id, description) {
134
+ if (!this._context)
135
+ return;
136
+ const { bus } = this._context;
137
+ const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
138
+ const index = tasks.findIndex((t) => t.id === id);
139
+ const previousDescription = tasks[index];
140
+ const now = new Date().getTime();
141
+ if (!previousDescription) {
142
+ this._taskStats.totalTasks++;
143
+ }
144
+ if (previousDescription?.status === 'complete') {
145
+ this._taskStats.totalErrors -= previousDescription.errors?.length || 0;
146
+ this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;
147
+ }
148
+ this._taskStats.remainingTasks++;
149
+ this._taskStats.status = 'pending';
150
+ const task = {
151
+ ...description,
152
+ status: 'pending',
153
+ startTime: now,
154
+ };
155
+ if (index === -1) {
156
+ tasks.push(task);
157
+ }
158
+ else {
159
+ tasks[index] = task;
160
+ }
161
+ bus.publish(taskStatsSource, this._taskStats);
162
+ bus.publish(taskListSource, { tasks });
163
+ }
164
+ /**
165
+ * Internal method to report the end of a task to the bus.
166
+ */
167
+ _reportEnd(id, description) {
168
+ if (!this._context)
169
+ return;
170
+ const { bus } = this._context;
171
+ const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
172
+ const index = tasks.findIndex((t) => t.id === id);
173
+ const previousDescription = tasks[index];
174
+ const now = new Date().getTime();
175
+ if (previousDescription) {
176
+ this._taskStats.remainingTasks--;
177
+ this._taskStats.totalErrors += description?.errors?.length || 0;
178
+ this._taskStats.totalWarnings += description?.warnings?.length || 0;
179
+ tasks[index] = {
180
+ ...previousDescription,
181
+ ...description,
182
+ status: 'complete',
183
+ durationMilliseconds: now - previousDescription.startTime,
184
+ lastUpdated: now,
185
+ };
186
+ if (this._taskStats.remainingTasks === 0) {
187
+ this._taskStats.status = 'idle';
188
+ }
189
+ bus.publish(taskStatsSource, this._taskStats);
190
+ bus.publish(taskListSource, { tasks });
191
+ }
192
+ }
117
193
  }
118
194
  //# sourceMappingURL=TaskRunner.js.map