@ms-cloudpack/api-server 0.42.1 → 0.44.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 (81) hide show
  1. package/lib/apis/addPackageOverride.js +1 -1
  2. package/lib/apis/addPackageOverride.js.map +1 -1
  3. package/lib/apis/index.d.ts +2 -0
  4. package/lib/apis/index.d.ts.map +1 -1
  5. package/lib/apis/index.js +2 -0
  6. package/lib/apis/index.js.map +1 -1
  7. package/lib/apis/openCodeEditor.d.ts +4 -4
  8. package/lib/apis/restartAllTasks.d.ts +19 -0
  9. package/lib/apis/restartAllTasks.d.ts.map +1 -0
  10. package/lib/apis/restartAllTasks.js +19 -0
  11. package/lib/apis/restartAllTasks.js.map +1 -0
  12. package/lib/apis/restartTask.d.ts +38 -0
  13. package/lib/apis/restartTask.d.ts.map +1 -0
  14. package/lib/apis/restartTask.js +19 -0
  15. package/lib/apis/restartTask.js.map +1 -0
  16. package/lib/common/createPartialApiContext.d.ts.map +1 -1
  17. package/lib/common/createPartialApiContext.js +5 -1
  18. package/lib/common/createPartialApiContext.js.map +1 -1
  19. package/lib/common/createSession.d.ts.map +1 -1
  20. package/lib/common/createSession.js +2 -6
  21. package/lib/common/createSession.js.map +1 -1
  22. package/lib/data/busSources.d.ts +42 -36
  23. package/lib/data/busSources.d.ts.map +1 -1
  24. package/lib/data/busSources.js +2 -4
  25. package/lib/data/busSources.js.map +1 -1
  26. package/lib/index.browser.d.ts +4 -1
  27. package/lib/index.browser.d.ts.map +1 -1
  28. package/lib/index.browser.js +2 -1
  29. package/lib/index.browser.js.map +1 -1
  30. package/lib/index.d.ts +1 -1
  31. package/lib/index.d.ts.map +1 -1
  32. package/lib/index.js +0 -1
  33. package/lib/index.js.map +1 -1
  34. package/lib/trpc/createAppRouter.d.ts +36 -2
  35. package/lib/trpc/createAppRouter.d.ts.map +1 -1
  36. package/lib/trpc/createCloudpackClient.d.ts.map +1 -1
  37. package/lib/trpc/createCloudpackClient.js +0 -7
  38. package/lib/trpc/createCloudpackClient.js.map +1 -1
  39. package/lib/trpc/createCloudpackServer.d.ts +8 -16
  40. package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
  41. package/lib/trpc/createCloudpackServer.js +12 -9
  42. package/lib/trpc/createCloudpackServer.js.map +1 -1
  43. package/lib/trpc/createContextFactory.d.ts +1 -14
  44. package/lib/trpc/createContextFactory.d.ts.map +1 -1
  45. package/lib/trpc/createContextFactory.js +2 -35
  46. package/lib/trpc/createContextFactory.js.map +1 -1
  47. package/lib/tsdoc-metadata.json +1 -1
  48. package/lib/types/Session.d.ts +11 -13
  49. package/lib/types/Session.d.ts.map +1 -1
  50. package/lib/types/Session.js.map +1 -1
  51. package/lib/types/TaskDescription.d.ts +23 -20
  52. package/lib/types/TaskDescription.d.ts.map +1 -1
  53. package/lib/types/TaskList.d.ts +392 -0
  54. package/lib/types/TaskList.d.ts.map +1 -0
  55. package/lib/types/TaskList.js +6 -0
  56. package/lib/types/TaskList.js.map +1 -0
  57. package/lib/types/TaskRunnerContext.d.ts +3 -0
  58. package/lib/types/TaskRunnerContext.d.ts.map +1 -0
  59. package/lib/types/TaskRunnerContext.js +2 -0
  60. package/lib/types/TaskRunnerContext.js.map +1 -0
  61. package/lib/utilities/TaskRunner.d.ts +19 -6
  62. package/lib/utilities/TaskRunner.d.ts.map +1 -1
  63. package/lib/utilities/TaskRunner.js +96 -24
  64. package/lib/utilities/TaskRunner.js.map +1 -1
  65. package/lib/utilities/createBundleTask.d.ts +1 -1
  66. package/lib/utilities/createBundleTask.d.ts.map +1 -1
  67. package/lib/utilities/createBundleTask.js +8 -2
  68. package/lib/utilities/createBundleTask.js.map +1 -1
  69. package/lib/utilities/getDefaultTaskStats.d.ts +3 -0
  70. package/lib/utilities/getDefaultTaskStats.d.ts.map +1 -0
  71. package/lib/utilities/getDefaultTaskStats.js +8 -0
  72. package/lib/utilities/getDefaultTaskStats.js.map +1 -0
  73. package/lib/utilities/notifyReload.d.ts +3 -1
  74. package/lib/utilities/notifyReload.d.ts.map +1 -1
  75. package/lib/utilities/notifyReload.js +3 -3
  76. package/lib/utilities/notifyReload.js.map +1 -1
  77. package/package.json +13 -13
  78. package/lib/startApiServer.d.ts +0 -28
  79. package/lib/startApiServer.d.ts.map +0 -1
  80. package/lib/startApiServer.js +0 -277
  81. package/lib/startApiServer.js.map +0 -1
@@ -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;IAwE1E;;;;;;;;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 () => {
@@ -51,24 +51,19 @@ export class TaskRunner extends EventEmitter {
51
51
  // Delete from rerun list (if present).
52
52
  this._requiresRerun.delete(id);
53
53
  taskResult = await this._queue.add(async () => {
54
- const startDescription = {
55
- ...task.getStartDescription?.(),
56
- id: task.id,
57
- };
58
- this.emit('executeStarted', startDescription);
54
+ if (task.getStartDescription) {
55
+ this._reportStart(id, task.getStartDescription());
56
+ }
59
57
  const result = await execute();
60
- const endDescription = {
61
- ...task.getEndDescription?.(result),
62
- id: task.id,
63
- };
64
- this.emit('executeCompleted', endDescription);
58
+ if (task.getEndDescription) {
59
+ this._reportEnd(id, task.getEndDescription(result));
60
+ }
65
61
  return result;
66
62
  },
67
63
  // Removes void from return type.
68
64
  // Read more on: https://github.com/sindresorhus/p-queue/issues/175
69
65
  { throwOnTimeout: true, priority });
70
66
  } while (this._requiresRerun.has(id));
71
- log(`Task finished: "${name}:${id}"`);
72
67
  // Delete from pending list.
73
68
  this._pendingTasks.delete(id);
74
69
  // Extra check to ensure that the task returned a value.
@@ -98,7 +93,7 @@ export class TaskRunner extends EventEmitter {
98
93
  .get(id)
99
94
  ?.dispose?.()
100
95
  .catch(() => {
101
- log(`Error disposing task: ${id}`);
96
+ console.debug(`Error disposing task: ${id}`);
102
97
  });
103
98
  this._prevTasks.get(id)?.clear?.();
104
99
  this._prevTasks.delete(id);
@@ -106,13 +101,90 @@ export class TaskRunner extends EventEmitter {
106
101
  this._pendingTasks.delete(id);
107
102
  this._completedTasks.delete(id);
108
103
  }
104
+ /**
105
+ * The clear method disposes all tasks and clears the TaskRunner.
106
+ */
107
+ clear() {
108
+ this._taskStats = getDefaultTaskStats();
109
+ if (this._context) {
110
+ const { bus, session } = this._context;
111
+ bus.publish([session.id, 'status'], this._taskStats);
112
+ bus.publish(taskListSource, { tasks: [] });
113
+ }
114
+ for (const id of this._prevTasks.keys()) {
115
+ this.remove(id);
116
+ }
117
+ }
109
118
  /** Pauses the TaskRunner (for testing). */
110
- pause() {
119
+ _pause() {
111
120
  this._queue.pause();
112
121
  }
113
122
  /** Starts or resumes the TaskRunner (for testing). */
114
- start() {
123
+ _start() {
115
124
  this._queue.start();
116
125
  }
126
+ /**
127
+ * Internal method to report the start of a task to the bus.
128
+ */
129
+ _reportStart(id, description) {
130
+ if (!this._context)
131
+ return;
132
+ const { bus } = this._context;
133
+ const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
134
+ const index = tasks.findIndex((t) => t.id === id);
135
+ const previousDescription = tasks[index];
136
+ const now = new Date().getTime();
137
+ if (!previousDescription) {
138
+ this._taskStats.totalTasks++;
139
+ }
140
+ if (previousDescription?.status === 'complete') {
141
+ this._taskStats.totalErrors -= previousDescription.errors?.length || 0;
142
+ this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;
143
+ }
144
+ this._taskStats.remainingTasks++;
145
+ this._taskStats.status = 'pending';
146
+ const task = {
147
+ ...description,
148
+ status: 'pending',
149
+ startTime: now,
150
+ };
151
+ if (index === -1) {
152
+ tasks.push(task);
153
+ }
154
+ else {
155
+ tasks[index] = task;
156
+ }
157
+ bus.publish(taskStatsSource, this._taskStats);
158
+ bus.publish(taskListSource, { tasks });
159
+ }
160
+ /**
161
+ * Internal method to report the end of a task to the bus.
162
+ */
163
+ _reportEnd(id, description) {
164
+ if (!this._context)
165
+ return;
166
+ const { bus } = this._context;
167
+ const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
168
+ const index = tasks.findIndex((t) => t.id === id);
169
+ const previousDescription = tasks[index];
170
+ const now = new Date().getTime();
171
+ if (previousDescription) {
172
+ this._taskStats.remainingTasks--;
173
+ this._taskStats.totalErrors += description?.errors?.length || 0;
174
+ this._taskStats.totalWarnings += description?.warnings?.length || 0;
175
+ tasks[index] = {
176
+ ...previousDescription,
177
+ ...description,
178
+ status: 'complete',
179
+ durationMilliseconds: now - previousDescription.startTime,
180
+ lastUpdated: now,
181
+ };
182
+ if (this._taskStats.remainingTasks === 0) {
183
+ this._taskStats.status = 'idle';
184
+ }
185
+ bus.publish(taskStatsSource, this._taskStats);
186
+ bus.publish(taskListSource, { tasks });
187
+ }
188
+ }
117
189
  }
118
190
  //# sourceMappingURL=TaskRunner.js.map