@ms-cloudpack/api-server 0.21.10 → 0.23.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.
- package/lib/apis/ensurePackageBundled.d.ts +16 -16
- package/lib/apis/ensurePackageBundled.d.ts.map +1 -1
- package/lib/apis/ensurePackageBundled.js +1 -2
- package/lib/apis/ensurePackageBundled.js.map +1 -1
- package/lib/apis/syncDownload.d.ts.map +1 -1
- package/lib/apis/syncDownload.js +8 -12
- package/lib/apis/syncDownload.js.map +1 -1
- package/lib/apis/syncUpload.d.ts.map +1 -1
- package/lib/apis/syncUpload.js +9 -14
- package/lib/apis/syncUpload.js.map +1 -1
- package/lib/common/createPartialApiContext.d.ts.map +1 -1
- package/lib/common/createPartialApiContext.js +16 -2
- package/lib/common/createPartialApiContext.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/startApiServer.d.ts +4 -2
- package/lib/startApiServer.d.ts.map +1 -1
- package/lib/startApiServer.js +6 -61
- package/lib/startApiServer.js.map +1 -1
- package/lib/trpc/createAppRouter.d.ts +8 -8
- package/lib/trpc/createCloudpackServer.d.ts +6 -4
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
- package/lib/trpc/createCloudpackServer.js.map +1 -1
- package/lib/trpc/createContextFactory.d.ts +2 -0
- package/lib/trpc/createContextFactory.d.ts.map +1 -1
- package/lib/trpc/createContextFactory.js +3 -1
- package/lib/trpc/createContextFactory.js.map +1 -1
- package/lib/types/ApiServer.d.ts +0 -7
- package/lib/types/ApiServer.d.ts.map +1 -1
- package/lib/types/ApiServer.js.map +1 -1
- package/lib/types/BundleRequest.d.ts +2 -3
- package/lib/types/BundleRequest.d.ts.map +1 -1
- package/lib/types/BundleRequest.js.map +1 -1
- package/lib/types/Context.d.ts +2 -0
- package/lib/types/Context.d.ts.map +1 -1
- package/lib/types/Context.js.map +1 -1
- package/lib/utilities/TaskRunner.d.ts +3 -1
- package/lib/utilities/TaskRunner.d.ts.map +1 -1
- package/lib/utilities/TaskRunner.js +23 -2
- package/lib/utilities/TaskRunner.js.map +1 -1
- package/lib/utilities/bundleTask.d.ts.map +1 -1
- package/lib/utilities/bundleTask.js +31 -13
- package/lib/utilities/bundleTask.js.map +1 -1
- package/lib/utilities/createBundleRequestForPackage.d.ts +1 -1
- package/lib/utilities/createBundleRequestForPackage.d.ts.map +1 -1
- package/lib/utilities/createBundleRequestForPackage.js +5 -7
- package/lib/utilities/createBundleRequestForPackage.js.map +1 -1
- package/lib/utilities/createBundleTask.d.ts.map +1 -1
- package/lib/utilities/createBundleTask.js +8 -5
- package/lib/utilities/createBundleTask.js.map +1 -1
- package/lib/utilities/createRemoteCacheClient.d.ts +7 -0
- package/lib/utilities/createRemoteCacheClient.d.ts.map +1 -0
- package/lib/utilities/createRemoteCacheClient.js +20 -0
- package/lib/utilities/createRemoteCacheClient.js.map +1 -0
- package/lib/utilities/getBundleLocation.d.ts +10 -0
- package/lib/utilities/getBundleLocation.d.ts.map +1 -0
- package/lib/utilities/{getBundleDetails.js → getBundleLocation.js} +8 -13
- package/lib/utilities/getBundleLocation.js.map +1 -0
- package/lib/utilities/getPackagesToSync.d.ts.map +1 -1
- package/lib/utilities/getPackagesToSync.js +6 -5
- package/lib/utilities/getPackagesToSync.js.map +1 -1
- package/lib/utilities/isCachedResultValid.d.ts.map +1 -1
- package/lib/utilities/isCachedResultValid.js +5 -1
- package/lib/utilities/isCachedResultValid.js.map +1 -1
- package/package.json +5 -5
- package/lib/utilities/getBundleDetails.d.ts +0 -16
- package/lib/utilities/getBundleDetails.d.ts.map +0 -1
- package/lib/utilities/getBundleDetails.js.map +0 -1
- package/lib/utilities/startWatcher.d.ts +0 -9
- package/lib/utilities/startWatcher.d.ts.map +0 -1
- package/lib/utilities/startWatcher.js +0 -51
- package/lib/utilities/startWatcher.js.map +0 -1
package/lib/startApiServer.js
CHANGED
|
@@ -4,17 +4,14 @@ import path from 'path';
|
|
|
4
4
|
import http from 'http';
|
|
5
5
|
import https from 'https';
|
|
6
6
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
7
|
-
import { createDataBus } from '@ms-cloudpack/data-bus';
|
|
8
7
|
import { execSync } from 'child_process';
|
|
9
|
-
import { TaskRunner } from './utilities/TaskRunner.js';
|
|
10
8
|
import { getCachePath } from './utilities/getCachePath.js';
|
|
11
9
|
import fsExtra from 'fs-extra';
|
|
12
|
-
import { startWatcher } from './utilities/startWatcher.js';
|
|
13
10
|
import { addOverride } from './utilities/addOverride.js';
|
|
14
11
|
import { validateOverride } from './utilities/validateOverride.js';
|
|
15
12
|
import { parseHttpsConfig } from '@ms-cloudpack/create-express-app';
|
|
16
13
|
import { editCloudpackConfig } from './utilities/editCloudpackConfig.js';
|
|
17
|
-
import { taskListSource, taskStatsSource } from './data/busSources.js';
|
|
14
|
+
import { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';
|
|
18
15
|
/**
|
|
19
16
|
* The api server handles the data pub/sub (for things like reporting build status)
|
|
20
17
|
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
@@ -30,10 +27,9 @@ import { taskListSource, taskStatsSource } from './data/busSources.js';
|
|
|
30
27
|
* javascript can connect and subscribe to page changes.
|
|
31
28
|
*/
|
|
32
29
|
export async function startApiServer(params) {
|
|
33
|
-
const { session, telemetryClient,
|
|
30
|
+
const { session, telemetryClient, packages, bus, taskRunner } = params;
|
|
34
31
|
const host = session.config?.devServer?.domain || 'localhost';
|
|
35
32
|
const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
36
|
-
const bus = createDataBus();
|
|
37
33
|
const sessionStats = {
|
|
38
34
|
status: 'idle',
|
|
39
35
|
remainingTasks: 0,
|
|
@@ -42,7 +38,6 @@ export async function startApiServer(params) {
|
|
|
42
38
|
totalWarnings: 0,
|
|
43
39
|
};
|
|
44
40
|
const allTasks = new Map();
|
|
45
|
-
const taskRunner = new TaskRunner();
|
|
46
41
|
function reportStart(taskStart) {
|
|
47
42
|
const previousResult = allTasks.get(taskStart.id);
|
|
48
43
|
const now = new Date().getTime();
|
|
@@ -84,37 +79,9 @@ export async function startApiServer(params) {
|
|
|
84
79
|
bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });
|
|
85
80
|
}
|
|
86
81
|
}
|
|
82
|
+
taskRunner.on('executeStarted', reportStart);
|
|
83
|
+
taskRunner.on('executeCompleted', reportEnd);
|
|
87
84
|
bus.publish([session.id, 'status'], sessionStats);
|
|
88
|
-
const addTask = (task, options) => {
|
|
89
|
-
if (task.watch) {
|
|
90
|
-
options = options || {};
|
|
91
|
-
options.watch = () => {
|
|
92
|
-
watcher.watch(task, { onSuccess: notifyReload });
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return taskRunner.add({
|
|
96
|
-
...task,
|
|
97
|
-
execute: async () => {
|
|
98
|
-
reportStart({
|
|
99
|
-
...task.getStartDescription?.(),
|
|
100
|
-
id: task.id,
|
|
101
|
-
});
|
|
102
|
-
let taskResult;
|
|
103
|
-
try {
|
|
104
|
-
taskResult = await task.execute();
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
// no-op
|
|
108
|
-
}
|
|
109
|
-
reportEnd({
|
|
110
|
-
...task.getEndDescription?.(taskResult),
|
|
111
|
-
id: task.id,
|
|
112
|
-
});
|
|
113
|
-
return taskResult;
|
|
114
|
-
},
|
|
115
|
-
}, options);
|
|
116
|
-
};
|
|
117
|
-
const watcher = startWatcher(addTask);
|
|
118
85
|
// Create a node http(s) server.
|
|
119
86
|
let server;
|
|
120
87
|
const httpsConfig = session.config?.devServer?.https;
|
|
@@ -187,7 +154,7 @@ export async function startApiServer(params) {
|
|
|
187
154
|
*/
|
|
188
155
|
case 'openSource': {
|
|
189
156
|
const { rootPath, relativePath = '', line, column } = request.data;
|
|
190
|
-
const fullPath = path.
|
|
157
|
+
const fullPath = path.resolve(rootPath, relativePath);
|
|
191
158
|
console.log(`Opening VSCode with path: ${fullPath}`);
|
|
192
159
|
execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });
|
|
193
160
|
break;
|
|
@@ -294,33 +261,11 @@ export async function startApiServer(params) {
|
|
|
294
261
|
}
|
|
295
262
|
});
|
|
296
263
|
};
|
|
297
|
-
|
|
298
|
-
if (session.config.features?.enableLage) {
|
|
299
|
-
const { TaskScheduler } = await import('./task-scheduler/TaskScheduler.js');
|
|
300
|
-
scheduler = new TaskScheduler({ reporter, root: session.appPath });
|
|
301
|
-
}
|
|
264
|
+
bus.subscribe(reloadCountSource, notifyReload);
|
|
302
265
|
return {
|
|
303
266
|
url: `${protocol}://${host}:${port}`,
|
|
304
267
|
port,
|
|
305
268
|
notifyReload,
|
|
306
|
-
addTask: (task, options) => {
|
|
307
|
-
return addTask(task, options);
|
|
308
|
-
},
|
|
309
|
-
scheduleTask: async (bundleRequest, scripts, options) => {
|
|
310
|
-
if (!scheduler) {
|
|
311
|
-
throw new Error('Cannot schedule task when not using lage');
|
|
312
|
-
}
|
|
313
|
-
reportStart({
|
|
314
|
-
id: bundleRequest.id,
|
|
315
|
-
inputPath: bundleRequest.packagePath,
|
|
316
|
-
outputPath: bundleRequest.outputPath,
|
|
317
|
-
name: bundleRequest.packageName,
|
|
318
|
-
});
|
|
319
|
-
await scheduler.scheduleTask(bundleRequest, scripts, options);
|
|
320
|
-
reportEnd({
|
|
321
|
-
id: bundleRequest.id,
|
|
322
|
-
});
|
|
323
|
-
},
|
|
324
269
|
close: () => new Promise((resolve, reject) => {
|
|
325
270
|
socketServer.clients.forEach((socket) => socket.terminate());
|
|
326
271
|
socketServer.close((err) => (err ? reject(err) : resolve()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC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M,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;aAC7D;YAED,WAAW,CAAC;gBACV,EAAE,EAAE,aAAa,CAAC,EAAE;gBACpB,SAAS,EAAE,aAAa,CAAC,WAAW;gBACpC,UAAU,EAAE,aAAa,CAAC,UAAU;gBACpC,IAAI,EAAE,aAAa,CAAC,WAAW;aAChC,CAAC,CAAC;YAEH,MAAM,SAAS,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAE9D,SAAS,CAAC;gBACR,EAAE,EAAE,aAAa,CAAC,EAAE;aACrB,CAAC,CAAC;QACL,CAAC;QAED,KAAK,EAAE,GAAG,EAAE,CACV,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;YACxE,YAAY,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import os from 'os';\nimport getPort from 'get-port';\nimport path from 'path';\nimport http from 'http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport { execSync } from 'child_process';\nimport { TaskRunner } from './utilities/TaskRunner.js';\nimport { getCachePath } from './utilities/getCachePath.js';\nimport fsExtra from 'fs-extra';\nimport { startWatcher } from './utilities/startWatcher.js';\nimport type { TaskDescription } from './types/TaskDescription.js';\nimport type { TaskEndDescription } from './types/TaskEndDescription.js';\nimport type { TaskStartDescription } from './types/TaskStartDescription.js';\nimport type { ApiServer } from './types/ApiServer.js';\nimport type { Session } from './types/Session.js';\nimport { addOverride } from './utilities/addOverride.js';\nimport { validateOverride } from './utilities/validateOverride.js';\nimport { parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { editCloudpackConfig } from './utilities/editCloudpackConfig.js';\nimport type { TaskScheduler } from './task-scheduler/TaskScheduler.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { taskListSource, taskStatsSource } from './data/busSources.js';\nimport type { TaskStats } from './types/TaskStats.js';\n\n/**\n * The api server handles the data pub/sub (for things like reporting build status)\n * and hosting the dashboard verb backend (for executing actions like loading vscode,\n * changing dependencies, connecting new projects to the running session, etc.)\n *\n * Each time `cloudpack start` is run, an api server will start up for that session. The\n * hosted web page will have a \"cloudpack-api-server\" header which points\n * to the websocket server.\n *\n * The bundle server will call the api server to publish build status updates.\n *\n * The app server will burn the api server url on the host html, so that client-side\n * javascript can connect and subscribe to page changes.\n */\nexport async function startApiServer(params: {\n session: Session;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}): Promise<ApiServer> {\n const { session, telemetryClient, reporter, packages } = params;\n const host = session.config?.devServer?.domain || 'localhost';\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const bus = createDataBus();\n const sessionStats: TaskStats = {\n status: 'idle',\n\n remainingTasks: 0,\n totalTasks: 0,\n\n totalErrors: 0,\n totalWarnings: 0,\n };\n\n const allTasks = new Map<string, TaskDescription>();\n const taskRunner = new TaskRunner();\n\n function reportStart(taskStart: TaskStartDescription): void {\n const previousResult = allTasks.get(taskStart.id);\n const now = new Date().getTime();\n\n if (!previousResult) {\n sessionStats.totalTasks++;\n }\n\n if (previousResult?.status === 'complete') {\n sessionStats.totalErrors -= previousResult.errors?.length || 0;\n sessionStats.totalWarnings -= previousResult.warnings?.length || 0;\n }\n\n sessionStats.remainingTasks++;\n sessionStats.status = 'pending';\n\n allTasks.set(taskStart.id, {\n ...taskStart,\n status: 'pending',\n startTime: now,\n });\n\n bus.publish(taskStatsSource, sessionStats);\n bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });\n }\n\n function reportEnd(taskEnd: TaskEndDescription): void {\n const previousResult = allTasks.get(taskEnd.id);\n const now = new Date().getTime();\n\n if (previousResult) {\n sessionStats.remainingTasks--;\n sessionStats.totalErrors += taskEnd.errors?.length || 0;\n sessionStats.totalWarnings += taskEnd.warnings?.length || 0;\n\n allTasks.set(taskEnd.id, {\n ...previousResult,\n ...taskEnd,\n status: 'complete',\n durationMilliseconds: now - previousResult.startTime,\n lastUpdated: now,\n });\n\n if (sessionStats.remainingTasks === 0) {\n sessionStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, sessionStats);\n bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });\n }\n }\n\n bus.publish([session.id, 'status'], sessionStats);\n\n const addTask: ApiServer['addTask'] = (task, options) => {\n if (task.watch) {\n options = options || {};\n options.watch = () => {\n watcher.watch(task, { onSuccess: notifyReload });\n };\n }\n\n return taskRunner.add(\n {\n ...task,\n execute: async () => {\n reportStart({\n ...task.getStartDescription?.(),\n id: task.id,\n });\n\n let taskResult;\n\n try {\n taskResult = await task.execute();\n } catch (err) {\n // no-op\n }\n\n reportEnd({\n ...task.getEndDescription?.(taskResult),\n id: task.id,\n } as TaskEndDescription);\n\n return taskResult;\n },\n },\n options,\n );\n };\n\n const watcher = startWatcher(addTask);\n\n // Create a node http(s) server.\n let server: http.Server | https.Server;\n const httpsConfig = session.config?.devServer?.https;\n const protocol = httpsConfig ? 'wss' : 'ws';\n\n if (httpsConfig) {\n const { key, cert, passphrase } = parseHttpsConfig(httpsConfig);\n\n if (!key || !cert) {\n console.error('Invalid https config in cloudpack.config.json. Make sure key and cert are valid.');\n\n throw new Error('Invalid https config.');\n }\n\n server = https\n .createServer(\n {\n key,\n cert,\n passphrase,\n },\n () => {\n /* no-op */\n },\n )\n .listen(port, host);\n } else {\n server = http.createServer().listen(port, host);\n }\n\n // Create a websocket server which listens for subscriptions and verb requests,\n // and broadcasts the data to all connected clients.\n const socketServer = new WebSocketServer({ server }, () => {\n // console.log(`ApiServer: Started on port ${port}`);\n }).on('connection', (socket: WebSocket) => {\n const disposables = new Map<number, () => void>();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function sendMessage(message: any) {\n socket.send(JSON.stringify(message, null, 2));\n }\n\n socket.send(\n JSON.stringify({\n type: 'sequence',\n sequence: session.sequence,\n }),\n );\n\n socket\n .on('message', (rawData) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n const request = JSON.parse(rawData.toString()) as {\n type: string;\n requestId?: string;\n data: Record<string, unknown>;\n };\n\n switch (request.type) {\n /**\n * Subscribe to a data subscription.\n */\n case 'subscribe': {\n const { path: subscriptionPath, id } = request.data;\n\n disposables.set(\n id as number,\n bus.subscribe(\n subscriptionPath as string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment\n (data: any) => sendMessage({ type: 'notify', id, path: subscriptionPath, data }),\n ),\n );\n\n break;\n }\n\n /**\n * Unsubscribe from a data subscription.\n */\n case 'unsubscribe': {\n const id = request.data.id as number | undefined;\n if (id) {\n const dispose = disposables.get(id);\n\n if (dispose) {\n dispose();\n disposables.delete(id);\n }\n }\n\n break;\n }\n\n /**\n * Open a file in VSCode.\n */\n case 'openSource': {\n const { rootPath, relativePath = '', line, column } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening VSCode with path: ${fullPath}`);\n execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n const { rootPath, relativePath = '' } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening path: ${fullPath}`);\n const openCommand = os.platform() == 'win32' ? 'start' : 'open';\n\n execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Opens the cloudpack config in VSCode for the user to manually edit. If the file doesn't exist,\n * it will be created.\n */\n case 'editConfig': {\n editCloudpackConfig().catch(() => {\n /* no-op */\n });\n break;\n }\n\n /**\n * Adds an override to the cloudpack config.\n */\n case 'addOverride': {\n // TODO: Send filename from request data to findResolveMapEntry when chromium Issue 1371551 is fixed.\n const { packageName, importPath } = request.data as Record<string, string>;\n (async () => {\n await addOverride({ packageName, importPath }, { session, packages });\n session.incrementSessionVersion();\n notifyReload();\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'validateOverride': {\n // TODO: Get filename from request data when chromium Issue 1371551 is fixed.\n const { requestId, data } = request as { requestId: string; data: Record<string, string> };\n const { packageName, importPath } = data;\n (async () => {\n const fixable = await validateOverride({ packageName, importPath }, { session, packages });\n sendMessage({ type: 'validateOverride', requestId, data: { fixable } });\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartAllTasks': {\n console.log('ApiServer: Restarting all tasks');\n\n // Clear entire local cache.\n fsExtra.emptyDirSync(getCachePath());\n\n // All tasks can be removed as notifyReload()\n // will cause the client to add the tasks again.\n allTasks.forEach((_, id) => {\n taskRunner.remove(id);\n });\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload();\n break;\n }\n\n case 'restartTask': {\n const { id, inputPath } = request.data as Record<string, string>;\n console.log(`ApiServer: Restarting task ${id}`);\n taskRunner.remove(id);\n session.incrementTargetVersion(inputPath);\n notifyReload();\n break;\n }\n\n case 'reportMetric': {\n const { metric, value } = request.data as { metric: string; value: number };\n console.debug(`ApiServer: Received metric: ${metric}, value: ${value}`);\n telemetryClient.rootSpan.addEvent(metric, value);\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', err);\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n console.error('Message:', rawData.toString());\n }\n })\n .on('close', () => {\n for (const d of disposables.values()) {\n d();\n }\n });\n });\n\n const notifyReload = () => {\n session.sequence++;\n socketServer.clients.forEach((socket: WebSocket) => {\n if (socket.readyState === WebSocket.OPEN) {\n socket.send(\n JSON.stringify({\n type: 'reload',\n data: { sessionId: session.id },\n }),\n );\n }\n });\n };\n\n let scheduler: TaskScheduler | undefined;\n\n if (session.config.features?.enableLage) {\n const { TaskScheduler } = await import('./task-scheduler/TaskScheduler.js');\n\n scheduler = new TaskScheduler({ reporter, root: session.appPath });\n }\n\n return {\n url: `${protocol}://${host}:${port}`,\n port,\n\n notifyReload,\n\n addTask: (task, options) => {\n return addTask(task, options);\n },\n\n scheduleTask: async (bundleRequest, scripts, options) => {\n if (!scheduler) {\n throw new Error('Cannot schedule task when not using lage');\n }\n\n reportStart({\n id: bundleRequest.id,\n inputPath: bundleRequest.packagePath,\n outputPath: bundleRequest.outputPath,\n name: bundleRequest.packageName,\n });\n\n await scheduler.scheduleTask(bundleRequest, scripts, options);\n\n reportEnd({\n id: bundleRequest.id,\n });\n },\n\n close: () =>\n new Promise<void>((resolve, reject) => {\n socketServer.clients.forEach((socket: WebSocket) => socket.terminate());\n socketServer.close((err) => (err ? reject(err) : resolve()));\n server.close();\n }),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAM/B,OAAO,EAA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KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,EAAE;gBACpC,CAAC,EAAE,CAAC;aACL;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,GAAG,EAAE;QACxB,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnB,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAiB,EAAE,EAAE;YACjD,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE;gBACxC,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;oBACb,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE;iBAChC,CAAC,CACH,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAE/C,OAAO;QACL,GAAG,EAAE,GAAG,QAAQ,MAAM,IAAI,IAAI,IAAI,EAAE;QACpC,IAAI;QAEJ,YAAY;QAEZ,KAAK,EAAE,GAAG,EAAE,CACV,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;YACxE,YAAY,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import os from 'os';\nimport getPort from 'get-port';\nimport path from 'path';\nimport http from 'http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport { execSync } from 'child_process';\nimport type { TaskRunner } from './utilities/TaskRunner.js';\nimport { getCachePath } from './utilities/getCachePath.js';\nimport fsExtra from 'fs-extra';\nimport type { TaskDescription } from './types/TaskDescription.js';\nimport type { TaskEndDescription } from './types/TaskEndDescription.js';\nimport type { TaskStartDescription } from './types/TaskStartDescription.js';\nimport type { ApiServer } from './types/ApiServer.js';\nimport type { Session } from './types/Session.js';\nimport { addOverride } from './utilities/addOverride.js';\nimport { validateOverride } from './utilities/validateOverride.js';\nimport { parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { editCloudpackConfig } from './utilities/editCloudpackConfig.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';\nimport type { TaskStats } from './types/TaskStats.js';\n\n/**\n * The api server handles the data pub/sub (for things like reporting build status)\n * and hosting the dashboard verb backend (for executing actions like loading vscode,\n * changing dependencies, connecting new projects to the running session, etc.)\n *\n * Each time `cloudpack start` is run, an api server will start up for that session. The\n * hosted web page will have a \"cloudpack-api-server\" header which points\n * to the websocket server.\n *\n * The bundle server will call the api server to publish build status updates.\n *\n * The app server will burn the api server url on the host html, so that client-side\n * javascript can connect and subscribe to page changes.\n */\nexport async function startApiServer(params: {\n session: Session;\n telemetryClient: TelemetryClient;\n packages: PackageDefinitionsCache;\n bus: DataBus;\n taskRunner: TaskRunner;\n}): Promise<ApiServer> {\n const { session, telemetryClient, packages, bus, taskRunner } = params;\n const host = session.config?.devServer?.domain || 'localhost';\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const sessionStats: TaskStats = {\n status: 'idle',\n\n remainingTasks: 0,\n totalTasks: 0,\n\n totalErrors: 0,\n totalWarnings: 0,\n };\n\n const allTasks = new Map<string, TaskDescription>();\n\n function reportStart(taskStart: TaskStartDescription): void {\n const previousResult = allTasks.get(taskStart.id);\n const now = new Date().getTime();\n\n if (!previousResult) {\n sessionStats.totalTasks++;\n }\n\n if (previousResult?.status === 'complete') {\n sessionStats.totalErrors -= previousResult.errors?.length || 0;\n sessionStats.totalWarnings -= previousResult.warnings?.length || 0;\n }\n\n sessionStats.remainingTasks++;\n sessionStats.status = 'pending';\n\n allTasks.set(taskStart.id, {\n ...taskStart,\n status: 'pending',\n startTime: now,\n });\n\n bus.publish(taskStatsSource, sessionStats);\n bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });\n }\n\n function reportEnd(taskEnd: TaskEndDescription): void {\n const previousResult = allTasks.get(taskEnd.id);\n const now = new Date().getTime();\n\n if (previousResult) {\n sessionStats.remainingTasks--;\n sessionStats.totalErrors += taskEnd.errors?.length || 0;\n sessionStats.totalWarnings += taskEnd.warnings?.length || 0;\n\n allTasks.set(taskEnd.id, {\n ...previousResult,\n ...taskEnd,\n status: 'complete',\n durationMilliseconds: now - previousResult.startTime,\n lastUpdated: now,\n });\n\n if (sessionStats.remainingTasks === 0) {\n sessionStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, sessionStats);\n bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });\n }\n }\n\n taskRunner.on('executeStarted', reportStart);\n taskRunner.on('executeCompleted', reportEnd);\n\n bus.publish([session.id, 'status'], sessionStats);\n\n // Create a node http(s) server.\n let server: http.Server | https.Server;\n const httpsConfig = session.config?.devServer?.https;\n const protocol = httpsConfig ? 'wss' : 'ws';\n\n if (httpsConfig) {\n const { key, cert, passphrase } = parseHttpsConfig(httpsConfig);\n\n if (!key || !cert) {\n console.error('Invalid https config in cloudpack.config.json. Make sure key and cert are valid.');\n\n throw new Error('Invalid https config.');\n }\n\n server = https\n .createServer(\n {\n key,\n cert,\n passphrase,\n },\n () => {\n /* no-op */\n },\n )\n .listen(port, host);\n } else {\n server = http.createServer().listen(port, host);\n }\n\n // Create a websocket server which listens for subscriptions and verb requests,\n // and broadcasts the data to all connected clients.\n const socketServer = new WebSocketServer({ server }, () => {\n // console.log(`ApiServer: Started on port ${port}`);\n }).on('connection', (socket: WebSocket) => {\n const disposables = new Map<number, () => void>();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function sendMessage(message: any) {\n socket.send(JSON.stringify(message, null, 2));\n }\n\n socket.send(\n JSON.stringify({\n type: 'sequence',\n sequence: session.sequence,\n }),\n );\n\n socket\n .on('message', (rawData) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n const request = JSON.parse(rawData.toString()) as {\n type: string;\n requestId?: string;\n data: Record<string, unknown>;\n };\n\n switch (request.type) {\n /**\n * Subscribe to a data subscription.\n */\n case 'subscribe': {\n const { path: subscriptionPath, id } = request.data;\n\n disposables.set(\n id as number,\n bus.subscribe(\n subscriptionPath as string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment\n (data: any) => sendMessage({ type: 'notify', id, path: subscriptionPath, data }),\n ),\n );\n\n break;\n }\n\n /**\n * Unsubscribe from a data subscription.\n */\n case 'unsubscribe': {\n const id = request.data.id as number | undefined;\n if (id) {\n const dispose = disposables.get(id);\n\n if (dispose) {\n dispose();\n disposables.delete(id);\n }\n }\n\n break;\n }\n\n /**\n * Open a file in VSCode.\n */\n case 'openSource': {\n const { rootPath, relativePath = '', line, column } = request.data;\n const fullPath = path.resolve(rootPath as string, relativePath as string);\n\n console.log(`Opening VSCode with path: ${fullPath}`);\n execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n const { rootPath, relativePath = '' } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening path: ${fullPath}`);\n const openCommand = os.platform() == 'win32' ? 'start' : 'open';\n\n execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Opens the cloudpack config in VSCode for the user to manually edit. If the file doesn't exist,\n * it will be created.\n */\n case 'editConfig': {\n editCloudpackConfig().catch(() => {\n /* no-op */\n });\n break;\n }\n\n /**\n * Adds an override to the cloudpack config.\n */\n case 'addOverride': {\n // TODO: Send filename from request data to findResolveMapEntry when chromium Issue 1371551 is fixed.\n const { packageName, importPath } = request.data as Record<string, string>;\n (async () => {\n await addOverride({ packageName, importPath }, { session, packages });\n session.incrementSessionVersion();\n notifyReload();\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'validateOverride': {\n // TODO: Get filename from request data when chromium Issue 1371551 is fixed.\n const { requestId, data } = request as { requestId: string; data: Record<string, string> };\n const { packageName, importPath } = data;\n (async () => {\n const fixable = await validateOverride({ packageName, importPath }, { session, packages });\n sendMessage({ type: 'validateOverride', requestId, data: { fixable } });\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartAllTasks': {\n console.log('ApiServer: Restarting all tasks');\n\n // Clear entire local cache.\n fsExtra.emptyDirSync(getCachePath());\n\n // All tasks can be removed as notifyReload()\n // will cause the client to add the tasks again.\n allTasks.forEach((_, id) => {\n taskRunner.remove(id);\n });\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload();\n break;\n }\n\n case 'restartTask': {\n const { id, inputPath } = request.data as Record<string, string>;\n console.log(`ApiServer: Restarting task ${id}`);\n taskRunner.remove(id);\n session.incrementTargetVersion(inputPath);\n notifyReload();\n break;\n }\n\n case 'reportMetric': {\n const { metric, value } = request.data as { metric: string; value: number };\n console.debug(`ApiServer: Received metric: ${metric}, value: ${value}`);\n telemetryClient.rootSpan.addEvent(metric, value);\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', err);\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n console.error('Message:', rawData.toString());\n }\n })\n .on('close', () => {\n for (const d of disposables.values()) {\n d();\n }\n });\n });\n\n const notifyReload = () => {\n session.sequence++;\n socketServer.clients.forEach((socket: WebSocket) => {\n if (socket.readyState === WebSocket.OPEN) {\n socket.send(\n JSON.stringify({\n type: 'reload',\n data: { sessionId: session.id },\n }),\n );\n }\n });\n };\n\n bus.subscribe(reloadCountSource, notifyReload);\n\n return {\n url: `${protocol}://${host}:${port}`,\n port,\n\n notifyReload,\n\n close: () =>\n new Promise<void>((resolve, reject) => {\n socketServer.clients.forEach((socket: WebSocket) => socket.terminate());\n socketServer.close((err) => (err ? reject(err) : resolve()));\n server.close();\n }),\n };\n}\n"]}
|
|
@@ -63,7 +63,7 @@ export declare function createAppRouter(): {
|
|
|
63
63
|
shouldForce?: boolean | undefined;
|
|
64
64
|
};
|
|
65
65
|
_output_in: {
|
|
66
|
-
|
|
66
|
+
dependencies: Promise<{
|
|
67
67
|
name: string;
|
|
68
68
|
outputPath: string;
|
|
69
69
|
version: string;
|
|
@@ -129,8 +129,8 @@ export declare function createAppRouter(): {
|
|
|
129
129
|
rawInput?: Record<string, unknown> | undefined;
|
|
130
130
|
rawOutput?: Record<string, unknown> | undefined;
|
|
131
131
|
imports?: Record<string, string[]> | undefined;
|
|
132
|
-
}
|
|
133
|
-
|
|
132
|
+
}[]>;
|
|
133
|
+
result: {
|
|
134
134
|
name: string;
|
|
135
135
|
outputPath: string;
|
|
136
136
|
version: string;
|
|
@@ -196,10 +196,10 @@ export declare function createAppRouter(): {
|
|
|
196
196
|
rawInput?: Record<string, unknown> | undefined;
|
|
197
197
|
rawOutput?: Record<string, unknown> | undefined;
|
|
198
198
|
imports?: Record<string, string[]> | undefined;
|
|
199
|
-
}
|
|
199
|
+
};
|
|
200
200
|
};
|
|
201
201
|
_output_out: {
|
|
202
|
-
|
|
202
|
+
dependencies: Promise<{
|
|
203
203
|
name: string;
|
|
204
204
|
outputPath: string;
|
|
205
205
|
version: string;
|
|
@@ -265,8 +265,8 @@ export declare function createAppRouter(): {
|
|
|
265
265
|
rawInput?: Record<string, unknown> | undefined;
|
|
266
266
|
rawOutput?: Record<string, unknown> | undefined;
|
|
267
267
|
imports?: Record<string, string[]> | undefined;
|
|
268
|
-
}
|
|
269
|
-
|
|
268
|
+
}[]>;
|
|
269
|
+
result: {
|
|
270
270
|
name: string;
|
|
271
271
|
outputPath: string;
|
|
272
272
|
version: string;
|
|
@@ -332,7 +332,7 @@ export declare function createAppRouter(): {
|
|
|
332
332
|
rawInput?: Record<string, unknown> | undefined;
|
|
333
333
|
rawOutput?: Record<string, unknown> | undefined;
|
|
334
334
|
imports?: Record<string, string[]> | undefined;
|
|
335
|
-
}
|
|
335
|
+
};
|
|
336
336
|
};
|
|
337
337
|
}, unknown>;
|
|
338
338
|
getData: import("@trpc/server").BuildProcedure<"query", {
|
|
@@ -3,12 +3,14 @@ import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
|
3
3
|
import type { Session } from '../types/Session.js';
|
|
4
4
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
5
5
|
import type { PackageImportPaths } from '@ms-cloudpack/package-utilities';
|
|
6
|
+
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
6
7
|
export declare function createCloudpackServer(options: {
|
|
7
8
|
session: Session;
|
|
8
9
|
telemetryClient: TelemetryClient;
|
|
9
10
|
reporter: TaskReporter;
|
|
10
11
|
packages: PackageDefinitionsCache;
|
|
11
12
|
packageImportPaths: PackageImportPaths;
|
|
13
|
+
packageHashes: PackageHashes;
|
|
12
14
|
}): Promise<{
|
|
13
15
|
url: string;
|
|
14
16
|
port: number;
|
|
@@ -31,7 +33,7 @@ export declare function createCloudpackServer(options: {
|
|
|
31
33
|
shouldWatch?: boolean | undefined;
|
|
32
34
|
shouldForce?: boolean | undefined;
|
|
33
35
|
}) => Promise<{
|
|
34
|
-
|
|
36
|
+
dependencies: Promise<{
|
|
35
37
|
name: string;
|
|
36
38
|
outputPath: string;
|
|
37
39
|
version: string;
|
|
@@ -97,8 +99,8 @@ export declare function createCloudpackServer(options: {
|
|
|
97
99
|
rawInput?: Record<string, unknown> | undefined;
|
|
98
100
|
rawOutput?: Record<string, unknown> | undefined;
|
|
99
101
|
imports?: Record<string, string[]> | undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
+
}[]>;
|
|
103
|
+
result: {
|
|
102
104
|
name: string;
|
|
103
105
|
outputPath: string;
|
|
104
106
|
version: string;
|
|
@@ -164,7 +166,7 @@ export declare function createCloudpackServer(options: {
|
|
|
164
166
|
rawInput?: Record<string, unknown> | undefined;
|
|
165
167
|
rawOutput?: Record<string, unknown> | undefined;
|
|
166
168
|
imports?: Record<string, string[]> | undefined;
|
|
167
|
-
}
|
|
169
|
+
};
|
|
168
170
|
}>;
|
|
169
171
|
getData: (options: {
|
|
170
172
|
path: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;CAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCA;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,eAAe,EAAkB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,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AAC,CAAC;IAE5D,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,EAAE,GAAG,iBAAiB,MAAM,QAAQ,IAAI,IAAI,EAAE;QACjD,IAAI;QACJ,GAAG,EAAE,gBAAgB;QAErB,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAID,8FAA8F;AAC9F,8DAA8D;AAC9D,SAAS,WAAW,CAClB,IAAW,EACX,GAAa;IAEb,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAChC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;QAC1B,GAAG,CAAC,GAAkB,CAAC,GAAG,CAAC,KAAgD,EAAE,EAAE;QAC7E,+DAA+D;QAC/D,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAuG,CACxG,CAAC;AACJ,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\nimport type { Session } from '../types/Session.js';\nimport { createAppRouter, type AppRouter } from './createAppRouter.js';\nimport { createContextFactory } from './createContextFactory.js';\nimport { createHTTPServer } from './httpAdapter.js';\nimport cors from 'cors';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { PackageImportPaths } from '@ms-cloudpack/package-utilities';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\nexport async function createCloudpackServer(options: {\n session: Session;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashes;\n}) {\n const createContext = await createContextFactory(options);\n const hostname = options.session.config?.devServer?.domain || 'localhost';\n const https = options.session.config?.devServer?.https;\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const { router, apis } = createAppRouter();\n const { server, listen } = createHTTPServer({\n middleware: cors(),\n router,\n createContext,\n https,\n });\n const webSocketProtocol = https ? 'wss' : 'ws';\n const wss = new WebSocketServer({ server });\n\n applyWSSHandler<AppRouter>({\n wss,\n router,\n createContext,\n });\n\n listen(port, hostname);\n\n const localCallContext = await createContext();\n const apisWithContext = withContext(apis, localCallContext);\n\n return {\n ...apisWithContext,\n url: `${webSocketProtocol}://${hostname}:${port}`,\n port,\n ctx: localCallContext,\n\n close: async () => {\n await localCallContext.dispose();\n server.close();\n wss.close();\n },\n };\n}\n\nexport type CloudpackServer = ReturnType<typeof createCloudpackServer>;\n\n/** Helper to tie the local call context with the apis so callers don't have to cache them. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withContext<TApis extends { [key: string]: (options: { input: any; ctx: TContext }) => any }, TContext>(\n apis: TApis,\n ctx: TContext,\n) {\n return Object.entries(apis).reduce(\n (acc, [key, apiFunction]) => {\n acc[key as keyof TApis] = (input: Parameters<TApis[typeof key]>[0]['input']) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n apiFunction({ input, ctx });\n return acc;\n },\n {} as { [key in keyof TApis]: (options: Parameters<TApis[key]>[0]['input']) => ReturnType<TApis[key]> },\n );\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
|
4
4
|
import type { Context } from '../types/Context.js';
|
|
5
5
|
import type { Session } from '../types/Session.js';
|
|
6
6
|
import type { PackageImportPaths } from '@ms-cloudpack/package-utilities';
|
|
7
|
+
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
7
8
|
export type CreateContext = () => Promise<Context>;
|
|
8
9
|
/**
|
|
9
10
|
* Creates the server context and returns a connection context factory.
|
|
@@ -16,5 +17,6 @@ export declare function createContextFactory(options: {
|
|
|
16
17
|
telemetryClient: TelemetryClient;
|
|
17
18
|
packages: PackageDefinitionsCache;
|
|
18
19
|
packageImportPaths: PackageImportPaths;
|
|
20
|
+
packageHashes: PackageHashes;
|
|
19
21
|
}): Promise<CreateContext>;
|
|
20
22
|
//# sourceMappingURL=createContextFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFactory.d.ts","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"createContextFactory.d.ts","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnD;;;;GAIG;AAEH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;CAC9B,0BAmDA"}
|
|
@@ -8,7 +8,7 @@ import { TaskRunner } from '../utilities/TaskRunner.js';
|
|
|
8
8
|
*/
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
10
10
|
export async function createContextFactory(options) {
|
|
11
|
-
const { session, telemetryClient, reporter, packages, packageImportPaths } = options;
|
|
11
|
+
const { session, telemetryClient, reporter, packages, packageImportPaths, packageHashes } = options;
|
|
12
12
|
// const host = config?.devServer?.domain || 'localhost';
|
|
13
13
|
// const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
14
14
|
// const bus = createDataBus();
|
|
@@ -37,6 +37,8 @@ export async function createContextFactory(options) {
|
|
|
37
37
|
taskRunner,
|
|
38
38
|
// package import paths
|
|
39
39
|
packageImportPaths,
|
|
40
|
+
// package hashes
|
|
41
|
+
packageHashes,
|
|
40
42
|
// dispose things that the context creates.
|
|
41
43
|
async dispose() {
|
|
42
44
|
await watcher.unwatchAll();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAQxD;;;;GAIG;AACH,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAO1C;IACC,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACpG,yDAAyD;IACzD,kEAAkE;IAClE,+BAA+B;IAE/B,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAEpC,yFAAyF;IACzF,wFAAwF;IACxF,6CAA6C;IAC7C,4DAA4D;IAC5D,MAAM,aAAa,GAAkB,KAAK,IAAI,EAAE;QAC9C,OAAO;YACL,kBAAkB;YAClB,OAAO;YAEP,WAAW;YACX,GAAG;YAEH,YAAY;YACZ,eAAe;YAEf,UAAU;YACV,QAAQ;YAER,eAAe;YACf,OAAO;YAEP,WAAW;YACX,QAAQ;YAER,QAAQ;YACR,UAAU;YAEV,uBAAuB;YACvB,kBAAkB;YAElB,iBAAiB;YACjB,aAAa;YAEb,2CAA2C;YAC3C,KAAK,CAAC,OAAO;gBACX,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;YAC7B,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport { createWatcher } from '@ms-cloudpack/file-watcher';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { TaskRunner } from '../utilities/TaskRunner.js';\nimport type { Context } from '../types/Context.js';\nimport type { Session } from '../types/Session.js';\nimport type { PackageImportPaths } from '@ms-cloudpack/package-utilities';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\nexport type CreateContext = () => Promise<Context>;\n\n/**\n * Creates the server context and returns a connection context factory.\n * The context object is accessible to apis and serves as a way to share stateful\n * objects across them.\n */\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function createContextFactory(options: {\n session: Session;\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashes;\n}) {\n const { session, telemetryClient, reporter, packages, packageImportPaths, packageHashes } = options;\n // const host = config?.devServer?.domain || 'localhost';\n // const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n // const bus = createDataBus();\n\n const bus = createDataBus();\n const watcher = createWatcher();\n const taskRunner = new TaskRunner();\n\n // Return the factory function which creates a context object per connection. This allows\n // us to choose what we expose to each client from server context, but also allows us to\n // add additional context to each connection.\n // eslint-disable-next-line @typescript-eslint/require-await\n const createContext: CreateContext = async () => {\n return {\n // session manager\n session,\n\n // data bus\n bus,\n\n // telemetry\n telemetryClient,\n\n // logging\n reporter,\n\n // file watcher\n watcher,\n\n // packages\n packages,\n\n // tasks\n taskRunner,\n\n // package import paths\n packageImportPaths,\n\n // package hashes\n packageHashes,\n\n // dispose things that the context creates.\n async dispose() {\n await watcher.unwatchAll();\n },\n };\n };\n\n return createContext;\n}\n"]}
|
package/lib/types/ApiServer.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import type { BundleRequest } from './BundleRequest.js';
|
|
2
|
-
import type { TaskOptions } from './TaskOptions.js';
|
|
3
|
-
import type { Task } from './Task.js';
|
|
4
1
|
export interface ApiServer {
|
|
5
2
|
url: string;
|
|
6
3
|
port: number;
|
|
7
4
|
notifyReload: () => void;
|
|
8
|
-
addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => Promise<TReturn>;
|
|
9
|
-
scheduleTask: <T extends BundleRequest>(bundleRequest: T, scripts: Record<string, string>, options: {
|
|
10
|
-
rerun?: boolean;
|
|
11
|
-
}) => Promise<void>;
|
|
12
5
|
close: () => Promise<void>;
|
|
13
6
|
}
|
|
14
7
|
//# sourceMappingURL=ApiServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiServer.d.ts","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ApiServer.d.ts","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,IAAI,CAAC;IAEzB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiServer.js","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ApiServer.js","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"","sourcesContent":["export interface ApiServer {\n url: string;\n port: number;\n\n notifyReload: () => void;\n\n close: () => Promise<void>;\n}\n"]}
|
|
@@ -8,16 +8,15 @@ export interface BundleRequest {
|
|
|
8
8
|
packageName: string;
|
|
9
9
|
version: string;
|
|
10
10
|
packagePath: string;
|
|
11
|
-
outputPath
|
|
11
|
+
outputPath?: string;
|
|
12
12
|
isExternal: boolean;
|
|
13
|
-
hash?: string;
|
|
14
13
|
bundlerType?: string;
|
|
15
14
|
result?: BundleResult & {
|
|
16
15
|
imports?: Record<string, string[]>;
|
|
17
16
|
hash?: string;
|
|
17
|
+
outputPath: string;
|
|
18
18
|
};
|
|
19
19
|
resultFromCache?: boolean;
|
|
20
|
-
isRebuildRequired?: boolean;
|
|
21
20
|
disableSourceMaps?: boolean;
|
|
22
21
|
enableFindImports?: boolean;
|
|
23
22
|
enableCacheInternalPackages?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAClG,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,MAAM,EAAE,eAAe,CAAC;CACzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleResult, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\n/**\n * Tracks a given bundle request and its result.\n */\n\nexport interface BundleRequest {\n id: string;\n packageName: string;\n version: string;\n packagePath: string;\n outputPath
|
|
1
|
+
{"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleResult, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\n/**\n * Tracks a given bundle request and its result.\n */\n\nexport interface BundleRequest {\n id: string;\n packageName: string;\n version: string;\n packagePath: string;\n outputPath?: string;\n isExternal: boolean;\n bundlerType?: string;\n result?: BundleResult & { imports?: Record<string, string[]>; hash?: string; outputPath: string };\n resultFromCache?: boolean;\n disableSourceMaps?: boolean;\n enableFindImports?: boolean;\n enableCacheInternalPackages?: boolean;\n hashPackages?: boolean;\n packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n}\n"]}
|
package/lib/types/Context.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
|
6
6
|
import type { Session } from '../types/Session.js';
|
|
7
7
|
import type { TaskRunner } from '../utilities/TaskRunner.js';
|
|
8
8
|
import type { PackageImportPaths } from '@ms-cloudpack/package-utilities';
|
|
9
|
+
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
9
10
|
/** Context for Cloudpack API server procedures. */
|
|
10
11
|
export interface Context {
|
|
11
12
|
session: Session;
|
|
@@ -16,6 +17,7 @@ export interface Context {
|
|
|
16
17
|
packages: PackageDefinitionsCache;
|
|
17
18
|
taskRunner: TaskRunner;
|
|
18
19
|
packageImportPaths: PackageImportPaths;
|
|
20
|
+
packageHashes: PackageHashes;
|
|
19
21
|
dispose(): Promise<void>;
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,mDAAmD;AACnD,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/lib/types/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { Watcher } from '@ms-cloudpack/file-watcher';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Session } from '../types/Session.js';\nimport type { TaskRunner } from '../utilities/TaskRunner.js';\nimport type { PackageImportPaths } from '@ms-cloudpack/package-utilities';\n\n/** Context for Cloudpack API server procedures. */\nexport interface Context {\n session: Session;\n bus: DataBus;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n watcher: Watcher;\n packages: PackageDefinitionsCache;\n taskRunner: TaskRunner;\n packageImportPaths: PackageImportPaths;\n dispose(): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { Watcher } from '@ms-cloudpack/file-watcher';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { Session } from '../types/Session.js';\nimport type { TaskRunner } from '../utilities/TaskRunner.js';\nimport type { PackageImportPaths } from '@ms-cloudpack/package-utilities';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\n/** Context for Cloudpack API server procedures. */\nexport interface Context {\n session: Session;\n bus: DataBus;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n watcher: Watcher;\n packages: PackageDefinitionsCache;\n taskRunner: TaskRunner;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashes;\n dispose(): Promise<void>;\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { TaskOptions } from '../types/TaskOptions.js';
|
|
2
3
|
import type { Task } from '../types/Task.js';
|
|
4
|
+
import EventEmitter from 'events';
|
|
3
5
|
/**
|
|
4
6
|
* TaskRunner class manages the state of Tasks.
|
|
5
7
|
* This class is to be called by the api server.
|
|
6
8
|
*/
|
|
7
|
-
export declare class TaskRunner {
|
|
9
|
+
export declare class TaskRunner extends EventEmitter {
|
|
8
10
|
private _queue;
|
|
9
11
|
private _pendingTasks;
|
|
10
12
|
private _completedTasks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,YAAY,MAAM,QAAQ,CAAC;AAQlC;;;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;IA0F1E;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAYzB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import PQueue from 'p-queue';
|
|
2
|
+
import EventEmitter from 'events';
|
|
2
3
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
4
|
const log = (...messages) => {
|
|
4
5
|
// console.log(`TaskRunner:`, ...messages);
|
|
@@ -7,8 +8,9 @@ const log = (...messages) => {
|
|
|
7
8
|
* TaskRunner class manages the state of Tasks.
|
|
8
9
|
* This class is to be called by the api server.
|
|
9
10
|
*/
|
|
10
|
-
export class TaskRunner {
|
|
11
|
+
export class TaskRunner extends EventEmitter {
|
|
11
12
|
constructor() {
|
|
13
|
+
super();
|
|
12
14
|
this._queue = new PQueue({ concurrency: 10 });
|
|
13
15
|
this._pendingTasks = new Map();
|
|
14
16
|
this._completedTasks = new Map();
|
|
@@ -53,7 +55,26 @@ export class TaskRunner {
|
|
|
53
55
|
try {
|
|
54
56
|
// TODO: possibly remove cast once this issue is resolved
|
|
55
57
|
// https://github.com/sindresorhus/p-queue/issues/175
|
|
56
|
-
taskResult = (await this._queue.add(
|
|
58
|
+
taskResult = (await this._queue.add(async () => {
|
|
59
|
+
const startDescription = {
|
|
60
|
+
...task.getStartDescription?.(),
|
|
61
|
+
id: task.id,
|
|
62
|
+
};
|
|
63
|
+
this.emit('executeStarted', startDescription);
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = await execute();
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
// no-op
|
|
70
|
+
}
|
|
71
|
+
const endDescription = {
|
|
72
|
+
...task.getEndDescription?.(result),
|
|
73
|
+
id: task.id,
|
|
74
|
+
};
|
|
75
|
+
this.emit('executeCompleted', endDescription);
|
|
76
|
+
return result;
|
|
77
|
+
}));
|
|
57
78
|
completed = true;
|
|
58
79
|
}
|
|
59
80
|
catch (err) {
|