@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.
- package/lib/apis/index.d.ts +2 -0
- package/lib/apis/index.d.ts.map +1 -1
- package/lib/apis/index.js +2 -0
- package/lib/apis/index.js.map +1 -1
- package/lib/apis/openCodeEditor.d.ts +4 -4
- package/lib/apis/restartAllTasks.d.ts +19 -0
- package/lib/apis/restartAllTasks.d.ts.map +1 -0
- package/lib/apis/restartAllTasks.js +19 -0
- package/lib/apis/restartAllTasks.js.map +1 -0
- package/lib/apis/restartTask.d.ts +38 -0
- package/lib/apis/restartTask.d.ts.map +1 -0
- package/lib/apis/restartTask.js +19 -0
- package/lib/apis/restartTask.js.map +1 -0
- package/lib/common/createPartialApiContext.d.ts.map +1 -1
- package/lib/common/createPartialApiContext.js +5 -1
- package/lib/common/createPartialApiContext.js.map +1 -1
- package/lib/common/createSession.d.ts.map +1 -1
- package/lib/common/createSession.js +2 -6
- package/lib/common/createSession.js.map +1 -1
- package/lib/data/busSources.d.ts +42 -36
- package/lib/data/busSources.d.ts.map +1 -1
- package/lib/data/busSources.js +2 -4
- package/lib/data/busSources.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/startApiServer.d.ts.map +1 -1
- package/lib/startApiServer.js +11 -73
- package/lib/startApiServer.js.map +1 -1
- package/lib/trpc/createAppRouter.d.ts +36 -2
- package/lib/trpc/createAppRouter.d.ts.map +1 -1
- package/lib/trpc/createCloudpackServer.d.ts +6 -1
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
- package/lib/trpc/createContextFactory.js +1 -1
- package/lib/trpc/createContextFactory.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types/Session.d.ts +11 -13
- package/lib/types/Session.d.ts.map +1 -1
- package/lib/types/Session.js.map +1 -1
- package/lib/types/TaskDescription.d.ts +23 -20
- package/lib/types/TaskDescription.d.ts.map +1 -1
- package/lib/types/TaskList.d.ts +392 -0
- package/lib/types/TaskList.d.ts.map +1 -0
- package/lib/types/TaskList.js +6 -0
- package/lib/types/TaskList.js.map +1 -0
- package/lib/types/TaskRunnerContext.d.ts +3 -0
- package/lib/types/TaskRunnerContext.d.ts.map +1 -0
- package/lib/types/TaskRunnerContext.js +2 -0
- package/lib/types/TaskRunnerContext.js.map +1 -0
- package/lib/utilities/TaskRunner.d.ts +19 -6
- package/lib/utilities/TaskRunner.d.ts.map +1 -1
- package/lib/utilities/TaskRunner.js +94 -18
- package/lib/utilities/TaskRunner.js.map +1 -1
- package/lib/utilities/createBundleTask.d.ts +1 -1
- package/lib/utilities/createBundleTask.d.ts.map +1 -1
- package/lib/utilities/createBundleTask.js +8 -2
- package/lib/utilities/createBundleTask.js.map +1 -1
- package/lib/utilities/getDefaultTaskStats.d.ts +3 -0
- package/lib/utilities/getDefaultTaskStats.d.ts.map +1 -0
- package/lib/utilities/getDefaultTaskStats.js +8 -0
- package/lib/utilities/getDefaultTaskStats.js.map +1 -0
- package/package.json +11 -11
package/lib/startApiServer.js
CHANGED
|
@@ -2,16 +2,16 @@ import getPort from 'get-port';
|
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import https from 'https';
|
|
4
4
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
5
|
-
import { getCachePath } from './utilities/getCachePath.js';
|
|
6
|
-
import fsExtra from 'fs-extra';
|
|
7
5
|
import { validateOverride } from './utilities/validateOverride.js';
|
|
8
6
|
import { parseHttpsConfig, getDomain } from '@ms-cloudpack/create-express-app';
|
|
9
|
-
import {
|
|
10
|
-
import { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';
|
|
7
|
+
import { reloadCountSource } from './data/busSources.js';
|
|
11
8
|
import { addPackageOverride } from './apis/addPackageOverride.js';
|
|
12
9
|
import { openCodeEditor } from './apis/openCodeEditor.js';
|
|
13
10
|
import { openFilePath } from './apis/openFilePath.js';
|
|
14
11
|
import { reportMetric } from './apis/reportMetric.js';
|
|
12
|
+
import { restartAllTasks } from './apis/restartAllTasks.js';
|
|
13
|
+
import { restartTask } from './apis/restartTask.js';
|
|
14
|
+
import { openConfigEditor } from './apis/openConfigEditor.js';
|
|
15
15
|
/**
|
|
16
16
|
* The api server handles the data pub/sub (for things like reporting build status)
|
|
17
17
|
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
@@ -30,58 +30,6 @@ export async function startApiServer(params) {
|
|
|
30
30
|
const { session, telemetryClient, packages, bus, taskRunner } = params;
|
|
31
31
|
const host = getDomain(session.config?.devServer?.domain);
|
|
32
32
|
const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
33
|
-
const sessionStats = {
|
|
34
|
-
status: 'idle',
|
|
35
|
-
remainingTasks: 0,
|
|
36
|
-
totalTasks: 0,
|
|
37
|
-
totalErrors: 0,
|
|
38
|
-
totalWarnings: 0,
|
|
39
|
-
};
|
|
40
|
-
const allTasks = new Map();
|
|
41
|
-
function reportStart(taskStart) {
|
|
42
|
-
const previousResult = allTasks.get(taskStart.id);
|
|
43
|
-
const now = new Date().getTime();
|
|
44
|
-
if (!previousResult) {
|
|
45
|
-
sessionStats.totalTasks++;
|
|
46
|
-
}
|
|
47
|
-
if (previousResult?.status === 'complete') {
|
|
48
|
-
sessionStats.totalErrors -= previousResult.errors?.length || 0;
|
|
49
|
-
sessionStats.totalWarnings -= previousResult.warnings?.length || 0;
|
|
50
|
-
}
|
|
51
|
-
sessionStats.remainingTasks++;
|
|
52
|
-
sessionStats.status = 'pending';
|
|
53
|
-
allTasks.set(taskStart.id, {
|
|
54
|
-
...taskStart,
|
|
55
|
-
status: 'pending',
|
|
56
|
-
startTime: now,
|
|
57
|
-
});
|
|
58
|
-
bus.publish(taskStatsSource, sessionStats);
|
|
59
|
-
bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });
|
|
60
|
-
}
|
|
61
|
-
function reportEnd(taskEnd) {
|
|
62
|
-
const previousResult = allTasks.get(taskEnd.id);
|
|
63
|
-
const now = new Date().getTime();
|
|
64
|
-
if (previousResult) {
|
|
65
|
-
sessionStats.remainingTasks--;
|
|
66
|
-
sessionStats.totalErrors += taskEnd.errors?.length || 0;
|
|
67
|
-
sessionStats.totalWarnings += taskEnd.warnings?.length || 0;
|
|
68
|
-
allTasks.set(taskEnd.id, {
|
|
69
|
-
...previousResult,
|
|
70
|
-
...taskEnd,
|
|
71
|
-
status: 'complete',
|
|
72
|
-
durationMilliseconds: now - previousResult.startTime,
|
|
73
|
-
lastUpdated: now,
|
|
74
|
-
});
|
|
75
|
-
if (sessionStats.remainingTasks === 0) {
|
|
76
|
-
sessionStats.status = 'idle';
|
|
77
|
-
}
|
|
78
|
-
bus.publish(taskStatsSource, sessionStats);
|
|
79
|
-
bus.publish(taskListSource, { tasks: Array.from(allTasks.values()) });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
taskRunner.on('executeStarted', reportStart);
|
|
83
|
-
taskRunner.on('executeCompleted', reportEnd);
|
|
84
|
-
bus.publish([session.id, 'status'], sessionStats);
|
|
85
33
|
// Create a node http(s) server.
|
|
86
34
|
let server;
|
|
87
35
|
const httpsConfig = session.config?.devServer?.https;
|
|
@@ -173,7 +121,7 @@ export async function startApiServer(params) {
|
|
|
173
121
|
* it will be created.
|
|
174
122
|
*/
|
|
175
123
|
case 'editConfig': {
|
|
176
|
-
|
|
124
|
+
openConfigEditor({ input: undefined, ctx: { session } }).catch(() => {
|
|
177
125
|
/* no-op */
|
|
178
126
|
});
|
|
179
127
|
break;
|
|
@@ -207,26 +155,14 @@ export async function startApiServer(params) {
|
|
|
207
155
|
break;
|
|
208
156
|
}
|
|
209
157
|
case 'restartAllTasks': {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
// eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem
|
|
213
|
-
fsExtra.emptyDirSync(getCachePath());
|
|
214
|
-
// All tasks can be removed as notifyReload()
|
|
215
|
-
// will cause the client to add the tasks again.
|
|
216
|
-
allTasks.forEach((_, id) => {
|
|
217
|
-
taskRunner.remove(id);
|
|
158
|
+
restartAllTasks({ input: undefined, ctx: { session, bus, taskRunner } }).catch(() => {
|
|
159
|
+
// no-op
|
|
218
160
|
});
|
|
219
|
-
// Update session version.
|
|
220
|
-
session.incrementSessionVersion();
|
|
221
|
-
notifyReload();
|
|
222
161
|
break;
|
|
223
162
|
}
|
|
224
163
|
case 'restartTask': {
|
|
225
164
|
const { id, inputPath } = request.data;
|
|
226
|
-
|
|
227
|
-
taskRunner.remove(id);
|
|
228
|
-
session.incrementTargetVersion(inputPath);
|
|
229
|
-
notifyReload();
|
|
165
|
+
restartTask({ input: { id, inputPath }, ctx: { bus, taskRunner, session } });
|
|
230
166
|
break;
|
|
231
167
|
}
|
|
232
168
|
case 'reportMetric': {
|
|
@@ -264,8 +200,10 @@ export async function startApiServer(params) {
|
|
|
264
200
|
});
|
|
265
201
|
};
|
|
266
202
|
bus.subscribe(reloadCountSource, notifyReload);
|
|
203
|
+
const url = `${protocol}://${host}:${port}`;
|
|
204
|
+
session.urls.apiServer = url;
|
|
267
205
|
return {
|
|
268
|
-
url
|
|
206
|
+
url,
|
|
269
207
|
port,
|
|
270
208
|
close: () => new Promise((resolve, reject) => {
|
|
271
209
|
socketServer.clients.forEach((socket) => socket.terminate());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAGhD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAM/B,OAAO,EAAE,gBAAgB,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http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\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 { validateOverride } from './utilities/validateOverride.js';\nimport { parseHttpsConfig, getDomain } 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/common-types';\nimport { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';\nimport type { TaskStats } from './types/TaskStats.js';\nimport { addPackageOverride, type AddPackageOverrideInput } from './apis/addPackageOverride.js';\nimport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\nimport { openCodeEditor, type OpenCodeEditorInput } from './apis/openCodeEditor.js';\nimport { openFilePath, type OpenFilePathInput } from './apis/openFilePath.js';\nimport { reportMetric, type ReportMetricInput } from './apis/reportMetric.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 = getDomain(session.config?.devServer?.domain);\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 const requestId = request.requestId || '';\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 openCodeEditor({ input: request.data as OpenCodeEditorInput, ctx: {} }).catch(() => {\n // ignore\n });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n openFilePath({ input: request.data as OpenFilePathInput, ctx: { session } }).catch(() => {\n // ignore\n });\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(session.appPath).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 (async () => {\n const { packageName, importPath } = request.data as AddPackageOverrideInput;\n await addPackageOverride({\n input: { packageName, importPath },\n ctx: { session, bus, packages, taskRunner },\n });\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 (async () => {\n const input = request.data as ValidatePackageOverrideInput;\n const fixable = await validateOverride(input, { session, packages });\n const result: ValidatePackageOverrideOutput = { fixable };\n sendMessage({ type: 'validateOverride', requestId, data: result });\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 // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\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 reportMetric({ input: request.data as ReportMetricInput, ctx: { telemetryClient } });\n break;\n }\n\n case 'getSessionId': {\n sendMessage({ type: 'sessionId', requestId, data: { sessionId: session.id } });\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', (err as Error).stack || 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 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,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAKhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAG/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAgC,MAAM,8BAA8B,CAAC;AAEhG,OAAO,EAAE,cAAc,EAA4B,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,YAAY,EAA0B,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAA0B,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;;;;;;;;;GAaG;AACH,MAAM,CA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AAO,CAAC,EAAE,EAAE;iBAChC,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAE/C,MAAM,GAAG,GAAG,GAAG,QAAQ,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAE7B,OAAO;QACL,GAAG;QACH,IAAI;QACJ,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 getPort from 'get-port';\nimport http from 'http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { TaskRunner } from './utilities/TaskRunner.js';\nimport type { ApiServer } from './types/ApiServer.js';\nimport type { Session } from './types/Session.js';\nimport { validateOverride } from './utilities/validateOverride.js';\nimport { parseHttpsConfig, getDomain } from '@ms-cloudpack/create-express-app';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { reloadCountSource } from './data/busSources.js';\nimport { addPackageOverride, type AddPackageOverrideInput } from './apis/addPackageOverride.js';\nimport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\nimport { openCodeEditor, type OpenCodeEditorInput } from './apis/openCodeEditor.js';\nimport { openFilePath, type OpenFilePathInput } from './apis/openFilePath.js';\nimport { reportMetric, type ReportMetricInput } from './apis/reportMetric.js';\nimport { restartAllTasks } from './apis/restartAllTasks.js';\nimport { restartTask } from './apis/restartTask.js';\nimport { openConfigEditor } from './apis/openConfigEditor.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 = getDomain(session.config?.devServer?.domain);\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\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 const requestId = request.requestId || '';\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 openCodeEditor({ input: request.data as OpenCodeEditorInput, ctx: {} }).catch(() => {\n // ignore\n });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n openFilePath({ input: request.data as OpenFilePathInput, ctx: { session } }).catch(() => {\n // ignore\n });\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 openConfigEditor({ input: undefined, ctx: { session } }).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 (async () => {\n const { packageName, importPath } = request.data as AddPackageOverrideInput;\n await addPackageOverride({\n input: { packageName, importPath },\n ctx: { session, bus, packages, taskRunner },\n });\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 (async () => {\n const input = request.data as ValidatePackageOverrideInput;\n const fixable = await validateOverride(input, { session, packages });\n const result: ValidatePackageOverrideOutput = { fixable };\n sendMessage({ type: 'validateOverride', requestId, data: result });\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartAllTasks': {\n restartAllTasks({ input: undefined, ctx: { session, bus, taskRunner } }).catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartTask': {\n const { id, inputPath } = request.data as Record<string, string>;\n restartTask({ input: { id, inputPath }, ctx: { bus, taskRunner, session } });\n break;\n }\n\n case 'reportMetric': {\n reportMetric({ input: request.data as ReportMetricInput, ctx: { telemetryClient } });\n break;\n }\n\n case 'getSessionId': {\n sendMessage({ type: 'sessionId', requestId, data: { sessionId: session.id } });\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', (err as Error).stack || 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 const url = `${protocol}://${host}:${port}`;\n session.urls.apiServer = url;\n\n return {\n url,\n port,\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"]}
|
|
@@ -106,15 +106,15 @@ export declare function createAppRouter(): {
|
|
|
106
106
|
_ctx_out: import("../index.js").Context;
|
|
107
107
|
_input_in: {
|
|
108
108
|
rootPath: string;
|
|
109
|
-
relativePath?: string | undefined;
|
|
110
109
|
line?: number | undefined;
|
|
111
110
|
column?: number | undefined;
|
|
111
|
+
relativePath?: string | undefined;
|
|
112
112
|
};
|
|
113
113
|
_input_out: {
|
|
114
114
|
rootPath: string;
|
|
115
|
-
relativePath?: string | undefined;
|
|
116
115
|
line?: number | undefined;
|
|
117
116
|
column?: number | undefined;
|
|
117
|
+
relativePath?: string | undefined;
|
|
118
118
|
};
|
|
119
119
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
120
120
|
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
@@ -235,6 +235,40 @@ export declare function createAppRouter(): {
|
|
|
235
235
|
fixable: boolean;
|
|
236
236
|
};
|
|
237
237
|
}, unknown>;
|
|
238
|
+
restartAllTasks: import("@trpc/server").BuildProcedure<"mutation", {
|
|
239
|
+
_config: import("@trpc/server").RootConfig<{
|
|
240
|
+
ctx: import("../index.js").Context;
|
|
241
|
+
meta: object;
|
|
242
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
243
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
244
|
+
}>;
|
|
245
|
+
_ctx_out: import("../index.js").Context;
|
|
246
|
+
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
247
|
+
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
248
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
249
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
250
|
+
_meta: object;
|
|
251
|
+
}, void>;
|
|
252
|
+
restartTask: import("@trpc/server").BuildProcedure<"mutation", {
|
|
253
|
+
_config: import("@trpc/server").RootConfig<{
|
|
254
|
+
ctx: import("../index.js").Context;
|
|
255
|
+
meta: object;
|
|
256
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
257
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
258
|
+
}>;
|
|
259
|
+
_meta: object;
|
|
260
|
+
_ctx_out: import("../index.js").Context;
|
|
261
|
+
_input_in: {
|
|
262
|
+
id: string;
|
|
263
|
+
inputPath: string;
|
|
264
|
+
};
|
|
265
|
+
_input_out: {
|
|
266
|
+
id: string;
|
|
267
|
+
inputPath: string;
|
|
268
|
+
};
|
|
269
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
270
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
|
271
|
+
}, void>;
|
|
238
272
|
}>;
|
|
239
273
|
};
|
|
240
274
|
export type AppRouter = ReturnType<typeof createAppRouter>['router'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAppRouter.d.ts","sourceRoot":"","sources":["../../src/trpc/createAppRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAGzC,wBAAgB,eAAe
|
|
1
|
+
{"version":3,"file":"createAppRouter.d.ts","sourceRoot":"","sources":["../../src/trpc/createAppRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAGzC,wBAAgB,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK9B;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -32,9 +32,9 @@ export declare function createCloudpackServer(options: {
|
|
|
32
32
|
}) => any;
|
|
33
33
|
openCodeEditor: (options: {
|
|
34
34
|
rootPath: string;
|
|
35
|
-
relativePath?: string | undefined;
|
|
36
35
|
line?: number | undefined;
|
|
37
36
|
column?: number | undefined;
|
|
37
|
+
relativePath?: string | undefined;
|
|
38
38
|
}) => Promise<void>;
|
|
39
39
|
openConfigEditor: (options: void) => Promise<void>;
|
|
40
40
|
openFilePath: (options: {
|
|
@@ -58,6 +58,11 @@ export declare function createCloudpackServer(options: {
|
|
|
58
58
|
}) => Promise<{
|
|
59
59
|
fixable: boolean;
|
|
60
60
|
}>;
|
|
61
|
+
restartAllTasks: (options: void) => Promise<void>;
|
|
62
|
+
restartTask: (options: {
|
|
63
|
+
id: string;
|
|
64
|
+
inputPath: string;
|
|
65
|
+
}) => void;
|
|
61
66
|
}>;
|
|
62
67
|
export type CloudpackServer = ReturnType<typeof createCloudpackServer>;
|
|
63
68
|
//# sourceMappingURL=createCloudpackServer.d.ts.map
|
|
@@ -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;AAMnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,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
|
|
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;AAMnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,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"}
|
|
@@ -14,7 +14,7 @@ export async function createContextFactory(options) {
|
|
|
14
14
|
// const bus = createDataBus();
|
|
15
15
|
const bus = createDataBus();
|
|
16
16
|
const watcher = createWatcher();
|
|
17
|
-
const taskRunner = new TaskRunner();
|
|
17
|
+
const taskRunner = new TaskRunner({ reporter, bus, session });
|
|
18
18
|
// Return the factory function which creates a context object per connection. This allows
|
|
19
19
|
// us to choose what we expose to each client from server context, but also allows us to
|
|
20
20
|
// add additional context to each connection.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,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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/common-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/import-map';\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 = getDomain(config?.devServer?.domain);\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({ reporter, bus, session });\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/tsdoc-metadata.json
CHANGED
package/lib/types/Session.d.ts
CHANGED
|
@@ -16,16 +16,13 @@ export interface Session {
|
|
|
16
16
|
appPath: string;
|
|
17
17
|
/**
|
|
18
18
|
* The type of session controls how the code is served via start.
|
|
19
|
-
* Web apps require app server and asset hosting, while libraries
|
|
20
|
-
* only need a bundle service.
|
|
19
|
+
* Web apps require app server and asset hosting, while libraries only need a bundle service.
|
|
21
20
|
*/
|
|
22
21
|
type: 'web-app' | 'library';
|
|
23
22
|
/**
|
|
24
|
-
* The mode of the session controls how the code is bundled. Library
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* mode is fastest but packages must be complaint for loading in
|
|
28
|
-
* the browser.
|
|
23
|
+
* The mode of the session controls how the code is bundled. Library mode bundles each package
|
|
24
|
+
* in isolation, while development and production modes bundle the full app graph together.
|
|
25
|
+
* Library mode is fastest but packages must be compliant for loading in the browser.
|
|
29
26
|
*/
|
|
30
27
|
mode: 'library' | 'development' | 'production';
|
|
31
28
|
/**
|
|
@@ -33,17 +30,18 @@ export interface Session {
|
|
|
33
30
|
*/
|
|
34
31
|
resolveMap: ResolveMap;
|
|
35
32
|
/**
|
|
36
|
-
* Reload sequence to ensure that the client is always
|
|
37
|
-
* up to date with the latest changes.
|
|
33
|
+
* Reload sequence to ensure that the client is always up to date with the latest changes.
|
|
38
34
|
*/
|
|
39
35
|
sequence: number;
|
|
40
36
|
/**
|
|
41
|
-
*
|
|
37
|
+
* URLs of the active servers hosting this session.
|
|
38
|
+
* Each URL will only be set after the server is started.
|
|
42
39
|
*/
|
|
43
40
|
urls: {
|
|
44
|
-
appServer
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
appServer?: string;
|
|
42
|
+
/** If `useSingleWebServer` is enabled, this will be a URL for bundles under the app server. */
|
|
43
|
+
bundleServer?: string;
|
|
44
|
+
apiServer?: string;
|
|
47
45
|
};
|
|
48
46
|
/**
|
|
49
47
|
* Used to force a hard refresh on the client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;IAExB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB
|
|
1
|
+
{"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;IAExB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAE5B;;;;OAIG;IACH,IAAI,EAAE,SAAS,GAAG,aAAa,GAAG,YAAY,CAAC;IAE/C;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,IAAI,EAAE;QACJ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,+FAA+F;QAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,uBAAuB,EAAE,MAAM,IAAI,CAAC;IAEpC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,sBAAsB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpD;;OAEG;IACH,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;CAClC"}
|
package/lib/types/Session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/import-map';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { CloudpackConfig } from '@ms-cloudpack/common-types';\n\nexport interface Session {\n /**\n * The session id, used for identifying\n */\n id: string;\n\n /**\n * The config used by the session.\n */\n config: CloudpackConfig;\n\n /**\n * The primary application path to monitor.\n */\n appPath: string;\n\n /**\n * The type of session controls how the code is served via start.\n * Web apps require app server and asset hosting, while libraries
|
|
1
|
+
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/import-map';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { CloudpackConfig } from '@ms-cloudpack/common-types';\n\nexport interface Session {\n /**\n * The session id, used for identifying\n */\n id: string;\n\n /**\n * The config used by the session.\n */\n config: CloudpackConfig;\n\n /**\n * The primary application path to monitor.\n */\n appPath: string;\n\n /**\n * The type of session controls how the code is served via start.\n * Web apps require app server and asset hosting, while libraries only need a bundle service.\n */\n type: 'web-app' | 'library';\n\n /**\n * The mode of the session controls how the code is bundled. Library mode bundles each package\n * in isolation, while development and production modes bundle the full app graph together.\n * Library mode is fastest but packages must be compliant for loading in the browser.\n */\n mode: 'library' | 'development' | 'production';\n\n /**\n * Used to resolve packages in the dependency graph.\n */\n resolveMap: ResolveMap;\n\n /**\n * Reload sequence to ensure that the client is always up to date with the latest changes.\n */\n sequence: number;\n\n /**\n * URLs of the active servers hosting this session.\n * Each URL will only be set after the server is started.\n */\n urls: {\n appServer?: string;\n /** If `useSingleWebServer` is enabled, this will be a URL for bundles under the app server. */\n bundleServer?: string;\n apiServer?: string;\n };\n\n /**\n * Used to force a hard refresh on the client.\n */\n sessionVersion: number;\n\n /**\n * Used to increment the session version by 1.\n */\n incrementSessionVersion: () => void;\n\n /**\n * The name of the project folder.\n * Used to differentiate between multiple projects.\n */\n projectName: string;\n\n /**\n * The version of each target.\n * Used to force a client cache refresh on a single target.\n */\n targetVersions: Record<string, number>;\n\n /**\n * Increments the version for the given target.\n */\n incrementTargetVersion: (inputPath: string) => void;\n\n /**\n * The import map for the session.\n */\n importMap: ImportMap | undefined;\n}\n"]}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
export declare const ZodTaskDescription: z.ZodObject<{
|
|
2
|
+
export declare const ZodTaskDescription: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
3
3
|
status: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"pending">, z.ZodLiteral<"complete">]>>;
|
|
4
|
-
name: z.ZodOptional<z.ZodString>;
|
|
5
|
-
inputPath: z.ZodOptional<z.ZodString>;
|
|
6
|
-
outputPath: z.ZodOptional<z.ZodString>;
|
|
7
4
|
timings: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
8
5
|
name: z.ZodString;
|
|
9
6
|
start: z.ZodNumber;
|
|
@@ -23,6 +20,12 @@ export declare const ZodTaskDescription: z.ZodObject<{
|
|
|
23
20
|
startTime: z.ZodNumber;
|
|
24
21
|
durationMilliseconds: z.ZodOptional<z.ZodNumber>;
|
|
25
22
|
lastUpdated: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, {
|
|
24
|
+
id: z.ZodString;
|
|
25
|
+
name: z.ZodOptional<z.ZodString>;
|
|
26
|
+
inputPath: z.ZodOptional<z.ZodString>;
|
|
27
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}>, {
|
|
26
29
|
id: z.ZodString;
|
|
27
30
|
errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
31
|
text: z.ZodString;
|
|
@@ -182,21 +185,13 @@ export declare const ZodTaskDescription: z.ZodObject<{
|
|
|
182
185
|
} | undefined;
|
|
183
186
|
}[] | undefined;
|
|
184
187
|
}>, "many">>;
|
|
185
|
-
}
|
|
188
|
+
}>, "strip", z.ZodTypeAny, {
|
|
186
189
|
id: string;
|
|
187
190
|
startTime: number;
|
|
188
191
|
status?: "pending" | "complete" | undefined;
|
|
189
192
|
name?: string | undefined;
|
|
190
193
|
inputPath?: string | undefined;
|
|
191
194
|
outputPath?: string | undefined;
|
|
192
|
-
timings?: {
|
|
193
|
-
name: string;
|
|
194
|
-
start: number;
|
|
195
|
-
end?: number | undefined;
|
|
196
|
-
threwException?: boolean | undefined;
|
|
197
|
-
}[] | undefined;
|
|
198
|
-
durationMilliseconds?: number | undefined;
|
|
199
|
-
lastUpdated?: number | undefined;
|
|
200
195
|
errors?: {
|
|
201
196
|
text: string;
|
|
202
197
|
source: string;
|
|
@@ -231,13 +226,6 @@ export declare const ZodTaskDescription: z.ZodObject<{
|
|
|
231
226
|
} | undefined;
|
|
232
227
|
}[] | undefined;
|
|
233
228
|
}[] | undefined;
|
|
234
|
-
}, {
|
|
235
|
-
id: string;
|
|
236
|
-
startTime: number;
|
|
237
|
-
status?: "pending" | "complete" | undefined;
|
|
238
|
-
name?: string | undefined;
|
|
239
|
-
inputPath?: string | undefined;
|
|
240
|
-
outputPath?: string | undefined;
|
|
241
229
|
timings?: {
|
|
242
230
|
name: string;
|
|
243
231
|
start: number;
|
|
@@ -246,6 +234,13 @@ export declare const ZodTaskDescription: z.ZodObject<{
|
|
|
246
234
|
}[] | undefined;
|
|
247
235
|
durationMilliseconds?: number | undefined;
|
|
248
236
|
lastUpdated?: number | undefined;
|
|
237
|
+
}, {
|
|
238
|
+
id: string;
|
|
239
|
+
startTime: number;
|
|
240
|
+
status?: "pending" | "complete" | undefined;
|
|
241
|
+
name?: string | undefined;
|
|
242
|
+
inputPath?: string | undefined;
|
|
243
|
+
outputPath?: string | undefined;
|
|
249
244
|
errors?: {
|
|
250
245
|
text: string;
|
|
251
246
|
source: string;
|
|
@@ -280,6 +275,14 @@ export declare const ZodTaskDescription: z.ZodObject<{
|
|
|
280
275
|
} | undefined;
|
|
281
276
|
}[] | undefined;
|
|
282
277
|
}[] | undefined;
|
|
278
|
+
timings?: {
|
|
279
|
+
name: string;
|
|
280
|
+
start: number;
|
|
281
|
+
end?: number | undefined;
|
|
282
|
+
threwException?: boolean | undefined;
|
|
283
|
+
}[] | undefined;
|
|
284
|
+
durationMilliseconds?: number | undefined;
|
|
285
|
+
lastUpdated?: number | undefined;
|
|
283
286
|
}>;
|
|
284
287
|
export type TaskDescription = z.infer<typeof ZodTaskDescription>;
|
|
285
288
|
//# sourceMappingURL=TaskDescription.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskDescription.d.ts","sourceRoot":"","sources":["../../src/types/TaskDescription.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"TaskDescription.d.ts","sourceRoot":"","sources":["../../src/types/TaskDescription.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|