@ms-cloudpack/api-server 0.43.0 → 0.44.1
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/addPackageOverride.js +1 -1
- package/lib/apis/addPackageOverride.js.map +1 -1
- package/lib/apis/restartAllTasks.js +1 -1
- package/lib/apis/restartAllTasks.js.map +1 -1
- package/lib/apis/restartTask.js +1 -1
- package/lib/apis/restartTask.js.map +1 -1
- package/lib/index.browser.d.ts +4 -1
- package/lib/index.browser.d.ts.map +1 -1
- package/lib/index.browser.js +2 -1
- package/lib/index.browser.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/trpc/createCloudpackClient.d.ts.map +1 -1
- package/lib/trpc/createCloudpackClient.js +0 -7
- package/lib/trpc/createCloudpackClient.js.map +1 -1
- package/lib/trpc/createCloudpackServer.d.ts +2 -15
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
- package/lib/trpc/createCloudpackServer.js +12 -9
- package/lib/trpc/createCloudpackServer.js.map +1 -1
- package/lib/trpc/createContextFactory.d.ts +1 -14
- package/lib/trpc/createContextFactory.d.ts.map +1 -1
- package/lib/trpc/createContextFactory.js +2 -35
- package/lib/trpc/createContextFactory.js.map +1 -1
- package/lib/utilities/TaskRunner.d.ts.map +1 -1
- package/lib/utilities/TaskRunner.js +6 -10
- package/lib/utilities/TaskRunner.js.map +1 -1
- package/lib/utilities/notifyReload.d.ts +3 -1
- package/lib/utilities/notifyReload.d.ts.map +1 -1
- package/lib/utilities/notifyReload.js +3 -3
- package/lib/utilities/notifyReload.js.map +1 -1
- package/package.json +11 -11
- package/lib/startApiServer.d.ts +0 -28
- package/lib/startApiServer.d.ts.map +0 -1
- package/lib/startApiServer.js +0 -215
- package/lib/startApiServer.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addPackageOverride.js","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C;;OAEG;IACH,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IAEvB;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IAEtB;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE9B;;OAEG;IACH,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAGH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAyF;IAEzF,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAC9B,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC;IAEnD,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IACjF,IAAI,KAAK,EAAE,CAAC;QACV,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"addPackageOverride.js","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,E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\nimport { publicProcedure } from '../trpc/common.js';\nimport { addOverride } from '../utilities/addOverride.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { ApiParams } from '../types/ApiParams.js';\n\nconst ZodAddPackageOverrideInput = z.object({\n /**\n * The package name to override.\n */\n packageName: z.string(),\n\n /**\n * The import path to add for the package.\n */\n importPath: z.string(),\n\n /**\n * The version of the package to override.\n */\n version: z.string().optional(),\n\n /**\n * URL that issued the import.\n */\n issuerUrl: z.string().optional(),\n});\nexport type AddPackageOverrideInput = z.infer<typeof ZodAddPackageOverrideInput>;\n\n/**\n * Adds an override to the Cloudpack config.\n */\nexport async function addPackageOverride(\n params: ApiParams<AddPackageOverrideInput, 'session' | 'bus' | 'packages' | 'taskRunner'>,\n): Promise<boolean> {\n const { input, ctx } = params;\n const { session, bus, packages, taskRunner } = ctx;\n\n const { addedOverride, entry } = await addOverride(input, { session, packages });\n if (entry) {\n taskRunner.remove(entry.path);\n session.incrementTargetVersion(entry.path);\n notifyReload({ bus, session });\n }\n return addedOverride;\n}\n\naddPackageOverride.procedure = publicProcedure.input(ZodAddPackageOverrideInput).mutation(addPackageOverride);\n"]}
|
|
@@ -13,7 +13,7 @@ export async function restartAllTasks(params) {
|
|
|
13
13
|
taskRunner.clear();
|
|
14
14
|
// Update session version.
|
|
15
15
|
session.incrementSessionVersion();
|
|
16
|
-
notifyReload({ bus });
|
|
16
|
+
notifyReload({ bus, session });
|
|
17
17
|
}
|
|
18
18
|
restartAllTasks.procedure = publicProcedure.mutation(restartAllTasks);
|
|
19
19
|
//# sourceMappingURL=restartAllTasks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restartAllTasks.js","sourceRoot":"","sources":["../../src/apis/restartAllTasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM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IAElC,YAAY,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,eAAe,CAAC,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC","sourcesContent":["import { emptyDir } from 'fs-extra/esm';\nimport { publicProcedure } from '../trpc/common.js';\nimport { getCachePath } from '../utilities/getCachePath.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { ApiParams } from '../types/ApiParams.js';\n\nexport async function restartAllTasks(params: ApiParams<void, 'session' | 'bus' | 'taskRunner'>) {\n const { ctx } = params;\n const { session, bus, taskRunner } = ctx;\n\n console.debug('ApiServer: Restarting all tasks');\n\n // Clear entire local cache.\n await emptyDir(getCachePath());\n\n // All tasks can be removed as notifyReload()\n // will cause the client to add the tasks again.\n taskRunner.clear();\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload({ bus, session });\n}\n\nrestartAllTasks.procedure = publicProcedure.mutation(restartAllTasks);\n"]}
|
package/lib/apis/restartTask.js
CHANGED
|
@@ -12,7 +12,7 @@ export function restartTask(params) {
|
|
|
12
12
|
console.debug(`ApiServer: Restarting task ${id}`);
|
|
13
13
|
taskRunner.remove(id);
|
|
14
14
|
session.incrementTargetVersion(inputPath);
|
|
15
|
-
notifyReload({ bus });
|
|
15
|
+
notifyReload({ bus, session });
|
|
16
16
|
}
|
|
17
17
|
// Attach a trpc procedure to the function.
|
|
18
18
|
restartTask.procedure = publicProcedure.input(ZodRestartTaskInput).mutation(restartTask);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restartTask.js","sourceRoot":"","sources":["../../src/apis/restartTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,MAAM,mBAAmB,GAAG,CAAC,CAAC,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C;IAClD,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtB,OAAO,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC1C,YAAY,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,2CAA2C;AAC3C,WAAW,CAAC,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport { publicProcedure } from '../trpc/common.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { ApiParams } from '../types/ApiParams.js';\n\nconst ZodRestartTaskInput = z.object({\n id: z.string(),\n inputPath: z.string(),\n});\nexport type RestartTaskInput = z.infer<typeof ZodRestartTaskInput>;\n\nexport function restartTask(params: ApiParams<RestartTaskInput, 'session' | 'bus' | 'taskRunner'>) {\n const { input, ctx } = params;\n const { id, inputPath } = input;\n const { session, bus, taskRunner } = ctx;\n console.debug(`ApiServer: Restarting task ${id}`);\n taskRunner.remove(id);\n session.incrementTargetVersion(inputPath);\n notifyReload({ bus, session });\n}\n\n// Attach a trpc procedure to the function.\nrestartTask.procedure = publicProcedure.input(ZodRestartTaskInput).mutation(restartTask);\n"]}
|
package/lib/index.browser.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export type { TaskStats } from './types/TaskStats.js';
|
|
2
2
|
export type { TaskDescription } from './types/TaskDescription.js';
|
|
3
3
|
export type { TaskMessage } from './types/TaskMessage.js';
|
|
4
|
+
export type { TaskList } from './types/TaskList.js';
|
|
4
5
|
export type { AddPackageOverrideInput } from './apis/addPackageOverride.js';
|
|
5
6
|
export type { OpenCodeEditorInput } from './apis/openCodeEditor.js';
|
|
6
7
|
export type { OpenFilePathInput } from './apis/openFilePath.js';
|
|
7
8
|
export type { ReportMetricInput } from './apis/reportMetric.js';
|
|
8
9
|
export type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';
|
|
9
|
-
export {
|
|
10
|
+
export type { RestartTaskInput } from './apis/restartTask.js';
|
|
11
|
+
export { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';
|
|
12
|
+
export { taskListSource, taskStatsSource, reloadCountSource } from './data/busSources.js';
|
|
10
13
|
//# sourceMappingURL=index.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,YAAY,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACrH,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/lib/index.browser.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createCloudpackClient } from './trpc/createCloudpackClient.js';
|
|
2
|
+
export { taskListSource, taskStatsSource, reloadCountSource } from './data/busSources.js';
|
|
2
3
|
//# sourceMappingURL=index.browser.js.map
|
package/lib/index.browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type { TaskStats } from './types/TaskStats.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskList } from './types/TaskList.js';\n\nexport type { AddPackageOverrideInput } from './apis/addPackageOverride.js';\nexport type { OpenCodeEditorInput } from './apis/openCodeEditor.js';\nexport type { OpenFilePathInput } from './apis/openFilePath.js';\nexport type { ReportMetricInput } from './apis/reportMetric.js';\nexport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\nexport type { RestartTaskInput } from './apis/restartTask.js';\n\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\n\nexport { taskListSource, taskStatsSource, reloadCountSource } from './data/busSources.js';\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -22,7 +22,6 @@ export type { BundleTaskOptions } from './types/BundleTaskOptions.js';
|
|
|
22
22
|
export type { OverrideOptions } from './types/OverrideOptions.js';
|
|
23
23
|
export { TaskRunner } from './utilities/TaskRunner.js';
|
|
24
24
|
export { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';
|
|
25
|
-
export { startApiServer } from './startApiServer.js';
|
|
26
25
|
export { createCloudpackClient } from './trpc/createCloudpackClient.js';
|
|
27
26
|
export { createCloudpackServer } from './trpc/createCloudpackServer.js';
|
|
28
27
|
export { ZodTaskDescription } from './types/TaskDescription.js';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE,YAAY,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACrH,YAA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E,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { TaskRunner } from './utilities/TaskRunner.js';
|
|
2
2
|
export { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';
|
|
3
|
-
export { startApiServer } from './startApiServer.js';
|
|
4
3
|
export { createCloudpackClient } from './trpc/createCloudpackClient.js';
|
|
5
4
|
export { createCloudpackServer } from './trpc/createCloudpackServer.js';
|
|
6
5
|
export { ZodTaskDescription } from './types/TaskDescription.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,YAAY;AACZ,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,cAAc;AACd,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,uBAAuB,GACxB,MAAM,iBAAiB,CAAC","sourcesContent":["export type { ApiServer } from './types/ApiServer.js';\nexport type { Context, PartialContext } from './types/Context.js';\nexport type { BundleInfo } from './types/BundleInfo.js';\nexport type { Session } from './types/Session.js';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { CloudpackServer } from './trpc/createCloudpackServer.js';\n\n// API types\nexport type { AddPackageOverrideInput } from './apis/addPackageOverride.js';\nexport type { OpenCodeEditorInput } from './apis/openCodeEditor.js';\nexport type { OpenFilePathInput } from './apis/openFilePath.js';\nexport type { ReportMetricInput } from './apis/reportMetric.js';\nexport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\nexport type { RestartTaskInput } from './apis/restartTask.js';\n\n// TODO: delete these type exports once API reporting of \"forgotten\" exports is enabled\n// (they're not used and don't really need to be visible in the API)\nexport type {\n EnsurePackageBundledContext,\n EnsurePackageBundledInput,\n EnsurePackageBundledOutput,\n EnsurePackageBundledResult,\n} from './apis/ensurePackageBundled.js';\nexport type { BundleRequest } from './types/BundleRequest.js';\nexport type { BundleTaskOptions } from './types/BundleTaskOptions.js';\nexport type { OverrideOptions } from './types/OverrideOptions.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';\nexport { createCloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer } from './trpc/createCloudpackServer.js';\nexport { ZodTaskDescription } from './types/TaskDescription.js';\nexport { ZodTaskEndDescription } from './types/TaskEndDescription.js';\nexport { ZodTaskMessage } from './types/TaskMessage.js';\nexport { ZodTaskStartDescription } from './types/TaskStartDescription.js';\nexport { getCachePath, getLocalCachePath } from './utilities/getCachePath.js';\nexport { getSessionPath } from './utilities/getSessionPath.js';\nexport { getConsumedDependencies } from './utilities/getConsumedDependencies.js';\nexport { getConsumedPaths } from './utilities/getConsumedPaths.js';\n\n// Utilities\nexport { createPartialApiContext } from './common/createPartialApiContext.js';\n\n// API methods\nexport {\n addPackageOverride,\n ensurePackageBundled,\n getData,\n getSessionId,\n onDataChanged,\n openCodeEditor,\n openConfigEditor,\n openFilePath,\n reportMetric,\n syncDownload,\n syncUpload,\n validatePackageOverride,\n} from './apis/index.js';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAI1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC,SAAS,CAAC,GAAG;IAC/D,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiD3B"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { createDataBus } from '@ms-cloudpack/data-bus';
|
|
2
1
|
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
3
2
|
import { createTRPCProxyClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';
|
|
4
3
|
import { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';
|
|
5
4
|
import { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';
|
|
6
|
-
import { connectBusToClient } from './connectBusToClient.js';
|
|
7
5
|
export async function createCloudpackClient(options) {
|
|
8
6
|
// We polyfill websocket in node conditions.
|
|
9
7
|
await ensureWebsocketDefined();
|
|
@@ -30,15 +28,10 @@ export async function createCloudpackClient(options) {
|
|
|
30
28
|
}),
|
|
31
29
|
],
|
|
32
30
|
});
|
|
33
|
-
// Connect the bus to the client so that local requests are sent remotely.
|
|
34
|
-
const bus = createDataBus();
|
|
35
|
-
connectBusToClient({ bus, client });
|
|
36
31
|
// Ugh. This is a hack to get around the fact that the client is a proxy.
|
|
37
32
|
return new Proxy({
|
|
38
|
-
bus,
|
|
39
33
|
close: () => {
|
|
40
34
|
wsClient.close();
|
|
41
|
-
bus.dispose();
|
|
42
35
|
},
|
|
43
36
|
}, {
|
|
44
37
|
get(target, prop) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAQxF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAG3C;IACC,4CAA4C;IAC5C,MAAM,sBAAsB,EAAE,CAAC;IAE/B,0BAA0B,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE3D,qBAAqB;IACrB,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErC,oFAAoF;IACpF,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC;IAC1C,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,qBAAqB,CAAY;QAC9C,KAAK,EAAE;YACL,SAAS,CAAC;gBACR,SAAS,CAAC,EAAE;oBACV,OAAO,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC;gBACpC,CAAC;gBACD,IAAI,EAAE,MAAM,CAAC;oBACX,MAAM,EAAE,QAAQ;iBACjB,CAAC;gBACF,KAAK,EAAE,aAAa,CAAC;oBACnB,GAAG;iBACJ,CAAC;aACH,CAAC;SACH;KACF,CAA+B,CAAC;IAEjC,yEAAyE;IACzE,OAAO,IAAI,KAAK,CACd;QACE,KAAK,EAAE,GAAG,EAAE;YACV,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;KACF,EACD;QACE,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,iDAAiD;YACjD,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChC,OAAO,MAAM,CAAC,IAA2B,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO,MAAM,CAAC,IAA6B,CAAC,CAAC;QAC/C,CAAC;KACF,CACiB,CAAC;AACvB,CAAC","sourcesContent":["import type { DataBus } from '@ms-cloudpack/data-bus';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CreateTRPCProxyClient } from '@trpc/client';\nimport { createTRPCProxyClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';\nimport { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';\nimport { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';\nimport type { AppRouter } from './createAppRouter.js';\n\nexport type CloudpackClient = CreateTRPCProxyClient<AppRouter> & {\n bus: DataBus;\n close: () => Promise<void>;\n};\n\nexport async function createCloudpackClient(options: {\n url: string;\n reporter?: TaskReporter;\n}): Promise<CloudpackClient> {\n // We polyfill websocket in node conditions.\n await ensureWebsocketDefined();\n\n ignoreSelfSignedCertErrors({ reporter: options.reporter });\n\n // Create the client.\n const wsClient = createWSClient(options);\n const tempUrl = makeUrl(options.url);\n\n // Replace the protocol with http so that we can use the same url for http requests.\n const isSSL = tempUrl.protocol === 'wss:';\n tempUrl.protocol = isSSL ? 'https:' : 'http:';\n\n const url = tempUrl.toString().replace(/\\/$/, '');\n const client = createTRPCProxyClient<AppRouter>({\n links: [\n splitLink({\n condition(op) {\n return op.type === 'subscription';\n },\n true: wsLink({\n client: wsClient,\n }),\n false: httpBatchLink({\n url,\n }),\n }),\n ],\n }) as unknown as CloudpackClient;\n\n // Ugh. This is a hack to get around the fact that the client is a proxy.\n return new Proxy(\n {\n close: () => {\n wsClient.close();\n },\n },\n {\n get(target, prop) {\n // eslint-disable-next-line no-prototype-builtins\n if (target.hasOwnProperty(prop)) {\n return target[prop as keyof typeof target];\n }\n\n return client[prop as keyof CloudpackClient];\n },\n },\n ) as CloudpackClient;\n}\n"]}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { Session } from '../types/Session.js';
|
|
4
|
-
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
5
|
-
import type { PackageImportPaths } from '@ms-cloudpack/import-map';
|
|
6
|
-
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
7
|
-
export declare function createCloudpackServer(options: {
|
|
8
|
-
session: Session;
|
|
9
|
-
telemetryClient: TelemetryClient;
|
|
10
|
-
reporter: TaskReporter;
|
|
11
|
-
packages: PackageDefinitionsCache;
|
|
12
|
-
packageImportPaths: PackageImportPaths;
|
|
13
|
-
packageHashes: PackageHashes;
|
|
14
|
-
}): Promise<{
|
|
1
|
+
import type { Context } from '../types/Context.js';
|
|
2
|
+
export declare function createCloudpackServer(context: Context): Promise<{
|
|
15
3
|
url: string;
|
|
16
4
|
port: number;
|
|
17
|
-
ctx: import("../index.js").Context;
|
|
18
5
|
close: () => Promise<void>;
|
|
19
6
|
addPackageOverride: (options: {
|
|
20
7
|
packageName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyC3D;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -6,10 +6,10 @@ import { createContextFactory } from './createContextFactory.js';
|
|
|
6
6
|
import { createHTTPServer } from './httpAdapter.js';
|
|
7
7
|
import cors from 'cors';
|
|
8
8
|
import { getDomain } from '@ms-cloudpack/create-express-app';
|
|
9
|
-
export async function createCloudpackServer(
|
|
10
|
-
const createContext = await createContextFactory(
|
|
11
|
-
const hostname = getDomain(
|
|
12
|
-
const https =
|
|
9
|
+
export async function createCloudpackServer(context) {
|
|
10
|
+
const createContext = await createContextFactory(context);
|
|
11
|
+
const hostname = getDomain(context.session.config?.devServer?.domain);
|
|
12
|
+
const https = context.session.config?.devServer?.https;
|
|
13
13
|
const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
14
14
|
const { router, apis } = createAppRouter();
|
|
15
15
|
const { server, listen } = createHTTPServer({
|
|
@@ -28,15 +28,18 @@ export async function createCloudpackServer(options) {
|
|
|
28
28
|
listen(port, hostname);
|
|
29
29
|
const localCallContext = await createContext();
|
|
30
30
|
const apisWithContext = withContext(apis, localCallContext);
|
|
31
|
+
const url = `${webSocketProtocol}://${hostname}:${port}`;
|
|
32
|
+
context.session.urls.apiServer = url;
|
|
31
33
|
return {
|
|
32
34
|
...apisWithContext,
|
|
33
|
-
url
|
|
35
|
+
url,
|
|
34
36
|
port,
|
|
35
|
-
ctx: localCallContext,
|
|
36
37
|
close: async () => {
|
|
37
|
-
await
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
await new Promise((resolve, reject) => {
|
|
39
|
+
wss.clients.forEach((socket) => socket.terminate());
|
|
40
|
+
wss.close((err) => (err ? reject(err) : resolve()));
|
|
41
|
+
server.close();
|
|
42
|
+
});
|
|
40
43
|
},
|
|
41
44
|
};
|
|
42
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACrC,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;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAG7D,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAgB;IAC1D,MAAM,aAAa,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC;IACvD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,MAAM,EAAE,MAAM,EAAE,I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AC;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 { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\nimport { createAppRouter, type AppRouter } from './createAppRouter.js';\nimport { createContextFactory } from './createContextFactory.js';\nimport { createHTTPServer } from './httpAdapter.js';\nimport cors from 'cors';\nimport { getDomain } from '@ms-cloudpack/create-express-app';\nimport type { Context } from '../types/Context.js';\n\nexport async function createCloudpackServer(context: Context) {\n const createContext = await createContextFactory(context);\n const hostname = getDomain(context.session.config?.devServer?.domain);\n const https = context.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 const url = `${webSocketProtocol}://${hostname}:${port}`;\n context.session.urls.apiServer = url;\n\n return {\n ...apisWithContext,\n url,\n port,\n\n close: async () => {\n await new Promise<void>((resolve, reject) => {\n wss.clients.forEach((socket) => socket.terminate());\n wss.close((err) => (err ? reject(err) : resolve()));\n server.close();\n });\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"]}
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
-
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
3
|
-
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
4
1
|
import type { Context } from '../types/Context.js';
|
|
5
|
-
import type { Session } from '../types/Session.js';
|
|
6
|
-
import type { PackageImportPaths } from '@ms-cloudpack/import-map';
|
|
7
|
-
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
8
2
|
export type CreateContext = () => Promise<Context>;
|
|
9
3
|
/**
|
|
10
4
|
* Creates the server context and returns a connection context factory.
|
|
11
5
|
* The context object is accessible to apis and serves as a way to share stateful
|
|
12
6
|
* objects across them.
|
|
13
7
|
*/
|
|
14
|
-
export declare function createContextFactory(
|
|
15
|
-
session: Session;
|
|
16
|
-
reporter: TaskReporter;
|
|
17
|
-
telemetryClient: TelemetryClient;
|
|
18
|
-
packages: PackageDefinitionsCache;
|
|
19
|
-
packageImportPaths: PackageImportPaths;
|
|
20
|
-
packageHashes: PackageHashes;
|
|
21
|
-
}): Promise<CreateContext>;
|
|
8
|
+
export declare function createContextFactory(context: Context): Promise<CreateContext>;
|
|
22
9
|
//# 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,
|
|
1
|
+
{"version":3,"file":"createContextFactory.d.ts","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnD;;;;GAIG;AAEH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,0BAU1D"}
|
|
@@ -1,49 +1,16 @@
|
|
|
1
|
-
import { createDataBus } from '@ms-cloudpack/data-bus';
|
|
2
|
-
import { createWatcher } from '@ms-cloudpack/file-watcher';
|
|
3
|
-
import { TaskRunner } from '../utilities/TaskRunner.js';
|
|
4
1
|
/**
|
|
5
2
|
* Creates the server context and returns a connection context factory.
|
|
6
3
|
* The context object is accessible to apis and serves as a way to share stateful
|
|
7
4
|
* objects across them.
|
|
8
5
|
*/
|
|
9
6
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
10
|
-
export async function createContextFactory(
|
|
11
|
-
const { session, telemetryClient, reporter, packages, packageImportPaths, packageHashes } = options;
|
|
12
|
-
// const host = getDomain(config?.devServer?.domain);
|
|
13
|
-
// const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
14
|
-
// const bus = createDataBus();
|
|
15
|
-
const bus = createDataBus();
|
|
16
|
-
const watcher = createWatcher();
|
|
17
|
-
const taskRunner = new TaskRunner({ reporter, bus, session });
|
|
7
|
+
export async function createContextFactory(context) {
|
|
18
8
|
// Return the factory function which creates a context object per connection. This allows
|
|
19
9
|
// us to choose what we expose to each client from server context, but also allows us to
|
|
20
10
|
// add additional context to each connection.
|
|
21
11
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
22
12
|
const createContext = async () => {
|
|
23
|
-
return
|
|
24
|
-
// session manager
|
|
25
|
-
session,
|
|
26
|
-
// data bus
|
|
27
|
-
bus,
|
|
28
|
-
// telemetry
|
|
29
|
-
telemetryClient,
|
|
30
|
-
// logging
|
|
31
|
-
reporter,
|
|
32
|
-
// file watcher
|
|
33
|
-
watcher,
|
|
34
|
-
// packages
|
|
35
|
-
packages,
|
|
36
|
-
// tasks
|
|
37
|
-
taskRunner,
|
|
38
|
-
// package import paths
|
|
39
|
-
packageImportPaths,
|
|
40
|
-
// package hashes
|
|
41
|
-
packageHashes,
|
|
42
|
-
// dispose things that the context creates.
|
|
43
|
-
async dispose() {
|
|
44
|
-
await watcher.unwatchAll();
|
|
45
|
-
},
|
|
46
|
-
};
|
|
13
|
+
return context;
|
|
47
14
|
};
|
|
48
15
|
return createContext;
|
|
49
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createContextFactory.js","sourceRoot":"","sources":["../../src/trpc/createContextFactory.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAgB;IACzD,yFAAyF;IACzF,wFAAwF;IACxF,6CAA6C;IAC7C,4DAA4D;IAC5D,MAAM,aAAa,GAAkB,KAAK,IAAI,EAAE;QAC9C,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { Context } from '../types/Context.js';\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(context: Context) {\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 context;\n };\n\n return createContext;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;GAGG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;gBAE/B,OAAO,CAAC,EAAE,iBAAiB;IAevC;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;GAGG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;gBAE/B,OAAO,CAAC,EAAE,iBAAiB;IAevC;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAwE1E;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAaxB;;OAEG;IACH,KAAK,IAAI,IAAI;IAYb,2CAA2C;IAC3C,MAAM,IAAI,IAAI;IAId,sDAAsD;IACtD,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,CAAC,YAAY;IAmCpB;;OAEG;IACH,OAAO,CAAC,UAAU;CA6BnB"}
|
|
@@ -51,17 +51,13 @@ export class TaskRunner {
|
|
|
51
51
|
// Delete from rerun list (if present).
|
|
52
52
|
this._requiresRerun.delete(id);
|
|
53
53
|
taskResult = await this._queue.add(async () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
this._reportStart(id, startDescription);
|
|
54
|
+
if (task.getStartDescription) {
|
|
55
|
+
this._reportStart(id, task.getStartDescription());
|
|
56
|
+
}
|
|
59
57
|
const result = await execute();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
this._reportEnd(id, endDescription);
|
|
58
|
+
if (task.getEndDescription) {
|
|
59
|
+
this._reportEnd(id, task.getEndDescription(result));
|
|
60
|
+
}
|
|
65
61
|
return result;
|
|
66
62
|
},
|
|
67
63
|
// Removes void from return type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAOA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC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,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,MAAM,mBAAmB,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAEjC,IAAI,mBAAmB,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;YACjC,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,WAAW,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;YAEpE,KAAK,CAAC,KAAK,CAAC,GAAG;gBACb,GAAG,mBAAmB;gBACtB,GAAG,WAAW;gBACd,MAAM,EAAE,UAAU;gBAClB,oBAAoB,EAAE,GAAG,GAAG,mBAAmB,CAAC,SAAS;gBACzD,WAAW,EAAE,GAAG;aACjB,CAAC;YAEF,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC;YAClC,CAAC;YAED,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TaskStartDescription } from '../types/TaskStartDescription.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport type { TaskOptions } from '../types/TaskOptions.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskRunnerContext } from '../types/TaskRunnerContext.js';\nimport type { TaskStats } from '../types/TaskStats.js';\nimport type { TaskList } from '../types/TaskList.js';\nimport PQueue from 'p-queue';\nimport { getDefaultTaskStats } from './getDefaultTaskStats.js';\nimport { taskListSource, taskStatsSource, type TaskDescription } from '../index.browser.js';\n\n/**\n * TaskRunner class manages the state of Tasks.\n * This class is to be called by the api server.\n */\nexport class TaskRunner {\n // Context is used to publish task status to the bus,\n // so it is optional, as it is not needed during init or testing.\n private _context: TaskRunnerContext | undefined;\n private _queue: PQueue;\n private _taskStats: TaskStats;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _pendingTasks: Map<string, Promise<any>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _completedTasks: Map<string, any>;\n private _requiresRerun: Set<string>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _prevTasks: Map<string, Task<any>>;\n\n constructor(context?: TaskRunnerContext) {\n this._context = context;\n this._queue = new PQueue({ concurrency: 10 });\n this._taskStats = getDefaultTaskStats();\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n }\n }\n\n /**\n * The add method enqueues a Task and returns its Promise.\n * If a Task with the same id has already been processed,\n * it returns either the result or the promise.\n * Rerun flag forces the Task to be run again.\n */\n add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, watch, priority } = options || {};\n\n watch?.();\n\n if (!this._prevTasks.get(id)) {\n this._prevTasks.set(id, task);\n }\n\n // Check if we are already completed the task with that id.\n const action = this._completedTasks.get(id) as TReturn | undefined;\n if (action !== undefined && !rerun) {\n return Promise.resolve(action);\n }\n\n // Check if we are already running the task with that id.\n const pending = this._pendingTasks.get(id) as Promise<TReturn> | undefined;\n if (pending !== undefined) {\n if (rerun) {\n this._requiresRerun.add(id);\n }\n return pending;\n }\n\n const resultPromise = (async () => {\n let taskResult: TReturn | undefined;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n\n taskResult = await this._queue.add(\n async () => {\n const startDescription: TaskStartDescription = {\n ...task.getStartDescription?.(),\n id,\n };\n this._reportStart(id, startDescription);\n\n const result = await execute();\n\n const endDescription: TaskEndDescription = {\n ...task.getEndDescription?.(result),\n id,\n };\n this._reportEnd(id, endDescription);\n\n return result;\n },\n // Removes void from return type.\n // Read more on: https://github.com/sindresorhus/p-queue/issues/175\n { throwOnTimeout: true, priority },\n );\n } while (this._requiresRerun.has(id));\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n\n // Extra check to ensure that the task returned a value.\n // It should never throw, if it does we have a bug.\n if (taskResult === undefined) {\n throw new Error(`Task \"${name}:${id}\" returned undefined, without throwing an error, which was unexpected.`);\n }\n\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n\n return taskResult;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n\n return resultPromise;\n }\n\n /**\n * The remove method disposes a task if available\n * and then removes it from the TaskRunner.\n *\n * This is useful when the state of a task needs to be cleared.\n *\n * It is intended to be used by the api server\n * to clear the TaskRunner's state before reloading the page.\n */\n remove(id: string): void {\n this._prevTasks\n .get(id)\n ?.dispose?.()\n .catch(() => {\n console.debug(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.clear?.();\n this._prevTasks.delete(id);\n this._requiresRerun.delete(id);\n this._pendingTasks.delete(id);\n this._completedTasks.delete(id);\n }\n /**\n * The clear method disposes all tasks and clears the TaskRunner.\n */\n clear(): void {\n this._taskStats = getDefaultTaskStats();\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n bus.publish(taskListSource, { tasks: [] });\n }\n for (const id of this._prevTasks.keys()) {\n this.remove(id);\n }\n }\n\n /** Pauses the TaskRunner (for testing). */\n _pause(): void {\n this._queue.pause();\n }\n\n /** Starts or resumes the TaskRunner (for testing). */\n _start(): void {\n this._queue.start();\n }\n\n /**\n * Internal method to report the start of a task to the bus.\n */\n private _reportStart(id: string, description: TaskStartDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (!previousDescription) {\n this._taskStats.totalTasks++;\n }\n\n if (previousDescription?.status === 'complete') {\n this._taskStats.totalErrors -= previousDescription.errors?.length || 0;\n this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;\n }\n\n this._taskStats.remainingTasks++;\n this._taskStats.status = 'pending';\n\n const task: TaskDescription = {\n ...description,\n status: 'pending',\n startTime: now,\n };\n if (index === -1) {\n tasks.push(task);\n } else {\n tasks[index] = task;\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n\n /**\n * Internal method to report the end of a task to the bus.\n */\n private _reportEnd(id: string, description: TaskEndDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (previousDescription) {\n this._taskStats.remainingTasks--;\n this._taskStats.totalErrors += description?.errors?.length || 0;\n this._taskStats.totalWarnings += description?.warnings?.length || 0;\n\n tasks[index] = {\n ...previousDescription,\n ...description,\n status: 'complete',\n durationMilliseconds: now - previousDescription.startTime,\n lastUpdated: now,\n };\n\n if (this._taskStats.remainingTasks === 0) {\n this._taskStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAOA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAwB,MAAM,qBAAqB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zC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAEjC,IAAI,mBAAmB,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;YACjC,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,WAAW,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;YAEpE,KAAK,CAAC,KAAK,CAAC,GAAG;gBACb,GAAG,mBAAmB;gBACtB,GAAG,WAAW;gBACd,MAAM,EAAE,UAAU;gBAClB,oBAAoB,EAAE,GAAG,GAAG,mBAAmB,CAAC,SAAS;gBACzD,WAAW,EAAE,GAAG;aACjB,CAAC;YAEF,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC;YAClC,CAAC;YAED,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TaskStartDescription } from '../types/TaskStartDescription.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport type { TaskOptions } from '../types/TaskOptions.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskRunnerContext } from '../types/TaskRunnerContext.js';\nimport type { TaskStats } from '../types/TaskStats.js';\nimport type { TaskList } from '../types/TaskList.js';\nimport PQueue from 'p-queue';\nimport { getDefaultTaskStats } from './getDefaultTaskStats.js';\nimport { taskListSource, taskStatsSource, type TaskDescription } from '../index.browser.js';\n\n/**\n * TaskRunner class manages the state of Tasks.\n * This class is to be called by the api server.\n */\nexport class TaskRunner {\n // Context is used to publish task status to the bus,\n // so it is optional, as it is not needed during init or testing.\n private _context: TaskRunnerContext | undefined;\n private _queue: PQueue;\n private _taskStats: TaskStats;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _pendingTasks: Map<string, Promise<any>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _completedTasks: Map<string, any>;\n private _requiresRerun: Set<string>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _prevTasks: Map<string, Task<any>>;\n\n constructor(context?: TaskRunnerContext) {\n this._context = context;\n this._queue = new PQueue({ concurrency: 10 });\n this._taskStats = getDefaultTaskStats();\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n }\n }\n\n /**\n * The add method enqueues a Task and returns its Promise.\n * If a Task with the same id has already been processed,\n * it returns either the result or the promise.\n * Rerun flag forces the Task to be run again.\n */\n add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, watch, priority } = options || {};\n\n watch?.();\n\n if (!this._prevTasks.get(id)) {\n this._prevTasks.set(id, task);\n }\n\n // Check if we are already completed the task with that id.\n const action = this._completedTasks.get(id) as TReturn | undefined;\n if (action !== undefined && !rerun) {\n return Promise.resolve(action);\n }\n\n // Check if we are already running the task with that id.\n const pending = this._pendingTasks.get(id) as Promise<TReturn> | undefined;\n if (pending !== undefined) {\n if (rerun) {\n this._requiresRerun.add(id);\n }\n return pending;\n }\n\n const resultPromise = (async () => {\n let taskResult: TReturn | undefined;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n\n taskResult = await this._queue.add(\n async () => {\n if (task.getStartDescription) {\n this._reportStart(id, task.getStartDescription());\n }\n\n const result = await execute();\n\n if (task.getEndDescription) {\n this._reportEnd(id, task.getEndDescription(result));\n }\n return result;\n },\n // Removes void from return type.\n // Read more on: https://github.com/sindresorhus/p-queue/issues/175\n { throwOnTimeout: true, priority },\n );\n } while (this._requiresRerun.has(id));\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n\n // Extra check to ensure that the task returned a value.\n // It should never throw, if it does we have a bug.\n if (taskResult === undefined) {\n throw new Error(`Task \"${name}:${id}\" returned undefined, without throwing an error, which was unexpected.`);\n }\n\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n\n return taskResult;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n\n return resultPromise;\n }\n\n /**\n * The remove method disposes a task if available\n * and then removes it from the TaskRunner.\n *\n * This is useful when the state of a task needs to be cleared.\n *\n * It is intended to be used by the api server\n * to clear the TaskRunner's state before reloading the page.\n */\n remove(id: string): void {\n this._prevTasks\n .get(id)\n ?.dispose?.()\n .catch(() => {\n console.debug(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.clear?.();\n this._prevTasks.delete(id);\n this._requiresRerun.delete(id);\n this._pendingTasks.delete(id);\n this._completedTasks.delete(id);\n }\n /**\n * The clear method disposes all tasks and clears the TaskRunner.\n */\n clear(): void {\n this._taskStats = getDefaultTaskStats();\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n bus.publish(taskListSource, { tasks: [] });\n }\n for (const id of this._prevTasks.keys()) {\n this.remove(id);\n }\n }\n\n /** Pauses the TaskRunner (for testing). */\n _pause(): void {\n this._queue.pause();\n }\n\n /** Starts or resumes the TaskRunner (for testing). */\n _start(): void {\n this._queue.start();\n }\n\n /**\n * Internal method to report the start of a task to the bus.\n */\n private _reportStart(id: string, description: TaskStartDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (!previousDescription) {\n this._taskStats.totalTasks++;\n }\n\n if (previousDescription?.status === 'complete') {\n this._taskStats.totalErrors -= previousDescription.errors?.length || 0;\n this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;\n }\n\n this._taskStats.remainingTasks++;\n this._taskStats.status = 'pending';\n\n const task: TaskDescription = {\n ...description,\n status: 'pending',\n startTime: now,\n };\n if (index === -1) {\n tasks.push(task);\n } else {\n tasks[index] = task;\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n\n /**\n * Internal method to report the end of a task to the bus.\n */\n private _reportEnd(id: string, description: TaskEndDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (previousDescription) {\n this._taskStats.remainingTasks--;\n this._taskStats.totalErrors += description?.errors?.length || 0;\n this._taskStats.totalWarnings += description?.warnings?.length || 0;\n\n tasks[index] = {\n ...previousDescription,\n ...description,\n status: 'complete',\n durationMilliseconds: now - previousDescription.startTime,\n lastUpdated: now,\n };\n\n if (this._taskStats.remainingTasks === 0) {\n this._taskStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { DataBus } from '@ms-cloudpack/data-bus';
|
|
2
|
+
import type { Session } from '../types/Session.js';
|
|
2
3
|
/**
|
|
3
4
|
* Notifies clients that a reload is needed by incrementing the session version.
|
|
4
5
|
*/
|
|
5
|
-
export declare function notifyReload({ bus }: {
|
|
6
|
+
export declare function notifyReload({ bus, session }: {
|
|
6
7
|
bus: DataBus;
|
|
8
|
+
session: Session;
|
|
7
9
|
}): void;
|
|
8
10
|
//# sourceMappingURL=notifyReload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifyReload.d.ts","sourceRoot":"","sources":["../../src/utilities/notifyReload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"notifyReload.d.ts","sourceRoot":"","sources":["../../src/utilities/notifyReload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,QAGhF"}
|
|
@@ -2,8 +2,8 @@ import { reloadCountSource } from '../data/busSources.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Notifies clients that a reload is needed by incrementing the session version.
|
|
4
4
|
*/
|
|
5
|
-
export function notifyReload({ bus }) {
|
|
6
|
-
|
|
7
|
-
bus.publish(reloadCountSource,
|
|
5
|
+
export function notifyReload({ bus, session }) {
|
|
6
|
+
session.sequence++;
|
|
7
|
+
bus.publish(reloadCountSource, session.sequence);
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=notifyReload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifyReload.js","sourceRoot":"","sources":["../../src/utilities/notifyReload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"notifyReload.js","sourceRoot":"","sources":["../../src/utilities/notifyReload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,GAAG,EAAE,OAAO,EAAsC;IAC/E,OAAO,CAAC,QAAQ,EAAE,CAAC;IACnB,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { DataBus } from '@ms-cloudpack/data-bus';\nimport { reloadCountSource } from '../data/busSources.js';\nimport type { Session } from '../types/Session.js';\n\n/**\n * Notifies clients that a reload is needed by incrementing the session version.\n */\nexport function notifyReload({ bus, session }: { bus: DataBus; session: Session }) {\n session.sequence++;\n bus.publish(reloadCountSource, session.sequence);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/api-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.1",
|
|
4
4
|
"description": "An implementation of the API server that does interacts with a task scheduler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
"@lage-run/logger": "^1.3.0",
|
|
28
28
|
"@lage-run/scheduler": "^1.2.1",
|
|
29
29
|
"@lage-run/target-graph": "^0.8.9",
|
|
30
|
-
"@ms-cloudpack/bundler": "^0.20.
|
|
31
|
-
"@ms-cloudpack/common-types": "^0.5.
|
|
32
|
-
"@ms-cloudpack/config": "^0.20.
|
|
33
|
-
"@ms-cloudpack/create-express-app": "^1.6.
|
|
30
|
+
"@ms-cloudpack/bundler": "^0.20.8",
|
|
31
|
+
"@ms-cloudpack/common-types": "^0.5.2",
|
|
32
|
+
"@ms-cloudpack/config": "^0.20.5",
|
|
33
|
+
"@ms-cloudpack/create-express-app": "^1.6.12",
|
|
34
34
|
"@ms-cloudpack/data-bus": "^0.4.2",
|
|
35
35
|
"@ms-cloudpack/file-watcher": "^0.1.2",
|
|
36
|
-
"@ms-cloudpack/import-map": "^0.5.
|
|
36
|
+
"@ms-cloudpack/import-map": "^0.5.1",
|
|
37
37
|
"@ms-cloudpack/json-utilities": "^0.1.4",
|
|
38
|
-
"@ms-cloudpack/package-hashes": "^0.5.
|
|
39
|
-
"@ms-cloudpack/package-utilities": "^7.4.
|
|
38
|
+
"@ms-cloudpack/package-hashes": "^0.5.16",
|
|
39
|
+
"@ms-cloudpack/package-utilities": "^7.4.4",
|
|
40
40
|
"@ms-cloudpack/path-string-parsing": "^1.2.2",
|
|
41
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
42
|
-
"@ms-cloudpack/remote-cache": "^0.7.
|
|
41
|
+
"@ms-cloudpack/path-utilities": "^2.7.9",
|
|
42
|
+
"@ms-cloudpack/remote-cache": "^0.7.4",
|
|
43
43
|
"@ms-cloudpack/task-reporter": "^0.14.0",
|
|
44
|
-
"@ms-cloudpack/telemetry": "^0.5.
|
|
44
|
+
"@ms-cloudpack/telemetry": "^0.5.2",
|
|
45
45
|
"@trpc/client": "^10.45.0",
|
|
46
46
|
"@trpc/server": "^10.45.0",
|
|
47
47
|
"cors": "^2.8.5",
|
package/lib/startApiServer.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { DataBus } from '@ms-cloudpack/data-bus';
|
|
2
|
-
import type { TaskRunner } from './utilities/TaskRunner.js';
|
|
3
|
-
import type { ApiServer } from './types/ApiServer.js';
|
|
4
|
-
import type { Session } from './types/Session.js';
|
|
5
|
-
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
6
|
-
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
7
|
-
/**
|
|
8
|
-
* The api server handles the data pub/sub (for things like reporting build status)
|
|
9
|
-
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
10
|
-
* changing dependencies, connecting new projects to the running session, etc.)
|
|
11
|
-
*
|
|
12
|
-
* Each time `cloudpack start` is run, an api server will start up for that session. The
|
|
13
|
-
* hosted web page will have a "cloudpack-api-server" header which points
|
|
14
|
-
* to the websocket server.
|
|
15
|
-
*
|
|
16
|
-
* The bundle server will call the api server to publish build status updates.
|
|
17
|
-
*
|
|
18
|
-
* The app server will burn the api server url on the host html, so that client-side
|
|
19
|
-
* javascript can connect and subscribe to page changes.
|
|
20
|
-
*/
|
|
21
|
-
export declare function startApiServer(params: {
|
|
22
|
-
session: Session;
|
|
23
|
-
telemetryClient: TelemetryClient;
|
|
24
|
-
packages: PackageDefinitionsCache;
|
|
25
|
-
bus: DataBus;
|
|
26
|
-
taskRunner: TaskRunner;
|
|
27
|
-
}): Promise<ApiServer>;
|
|
28
|
-
//# sourceMappingURL=startApiServer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"startApiServer.d.ts","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAW1E;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,OAAO,CAAC,SAAS,CAAC,CAqOrB"}
|
package/lib/startApiServer.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import getPort from 'get-port';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import https from 'https';
|
|
4
|
-
import WebSocket, { WebSocketServer } from 'ws';
|
|
5
|
-
import { validateOverride } from './utilities/validateOverride.js';
|
|
6
|
-
import { parseHttpsConfig, getDomain } from '@ms-cloudpack/create-express-app';
|
|
7
|
-
import { reloadCountSource } from './data/busSources.js';
|
|
8
|
-
import { addPackageOverride } from './apis/addPackageOverride.js';
|
|
9
|
-
import { openCodeEditor } from './apis/openCodeEditor.js';
|
|
10
|
-
import { openFilePath } from './apis/openFilePath.js';
|
|
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
|
-
/**
|
|
16
|
-
* The api server handles the data pub/sub (for things like reporting build status)
|
|
17
|
-
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
18
|
-
* changing dependencies, connecting new projects to the running session, etc.)
|
|
19
|
-
*
|
|
20
|
-
* Each time `cloudpack start` is run, an api server will start up for that session. The
|
|
21
|
-
* hosted web page will have a "cloudpack-api-server" header which points
|
|
22
|
-
* to the websocket server.
|
|
23
|
-
*
|
|
24
|
-
* The bundle server will call the api server to publish build status updates.
|
|
25
|
-
*
|
|
26
|
-
* The app server will burn the api server url on the host html, so that client-side
|
|
27
|
-
* javascript can connect and subscribe to page changes.
|
|
28
|
-
*/
|
|
29
|
-
export async function startApiServer(params) {
|
|
30
|
-
const { session, telemetryClient, packages, bus, taskRunner } = params;
|
|
31
|
-
const host = getDomain(session.config?.devServer?.domain);
|
|
32
|
-
const port = await getPort({ port: [9890, 9891, 9892, 9893] });
|
|
33
|
-
// Create a node http(s) server.
|
|
34
|
-
let server;
|
|
35
|
-
const httpsConfig = session.config?.devServer?.https;
|
|
36
|
-
const protocol = httpsConfig ? 'wss' : 'ws';
|
|
37
|
-
if (httpsConfig) {
|
|
38
|
-
const { key, cert, passphrase } = parseHttpsConfig(httpsConfig);
|
|
39
|
-
if (!key || !cert) {
|
|
40
|
-
console.error('Invalid https config in cloudpack.config.json. Make sure key and cert are valid.');
|
|
41
|
-
throw new Error('Invalid https config.');
|
|
42
|
-
}
|
|
43
|
-
server = https
|
|
44
|
-
.createServer({
|
|
45
|
-
key,
|
|
46
|
-
cert,
|
|
47
|
-
passphrase,
|
|
48
|
-
}, () => {
|
|
49
|
-
/* no-op */
|
|
50
|
-
})
|
|
51
|
-
.listen(port, host);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
server = http.createServer().listen(port, host);
|
|
55
|
-
}
|
|
56
|
-
// Create a websocket server which listens for subscriptions and verb requests,
|
|
57
|
-
// and broadcasts the data to all connected clients.
|
|
58
|
-
const socketServer = new WebSocketServer({ server }, () => {
|
|
59
|
-
// console.log(`ApiServer: Started on port ${port}`);
|
|
60
|
-
}).on('connection', (socket) => {
|
|
61
|
-
const disposables = new Map();
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
-
function sendMessage(message) {
|
|
64
|
-
socket.send(JSON.stringify(message, null, 2));
|
|
65
|
-
}
|
|
66
|
-
socket.send(JSON.stringify({
|
|
67
|
-
type: 'sequence',
|
|
68
|
-
sequence: session.sequence,
|
|
69
|
-
}));
|
|
70
|
-
socket
|
|
71
|
-
.on('message', (rawData) => {
|
|
72
|
-
try {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
74
|
-
const request = JSON.parse(rawData.toString());
|
|
75
|
-
const requestId = request.requestId || '';
|
|
76
|
-
switch (request.type) {
|
|
77
|
-
/**
|
|
78
|
-
* Subscribe to a data subscription.
|
|
79
|
-
*/
|
|
80
|
-
case 'subscribe': {
|
|
81
|
-
const { path: subscriptionPath, id } = request.data;
|
|
82
|
-
disposables.set(id, bus.subscribe(subscriptionPath,
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
84
|
-
(data) => sendMessage({ type: 'notify', id, path: subscriptionPath, data })));
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Unsubscribe from a data subscription.
|
|
89
|
-
*/
|
|
90
|
-
case 'unsubscribe': {
|
|
91
|
-
const id = request.data.id;
|
|
92
|
-
if (id) {
|
|
93
|
-
const dispose = disposables.get(id);
|
|
94
|
-
if (dispose) {
|
|
95
|
-
dispose();
|
|
96
|
-
disposables.delete(id);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Open a file in VSCode.
|
|
103
|
-
*/
|
|
104
|
-
case 'openSource': {
|
|
105
|
-
openCodeEditor({ input: request.data, ctx: {} }).catch(() => {
|
|
106
|
-
// ignore
|
|
107
|
-
});
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Open a file or folder in the OS's default file manager.
|
|
112
|
-
*/
|
|
113
|
-
case 'open': {
|
|
114
|
-
openFilePath({ input: request.data, ctx: { session } }).catch(() => {
|
|
115
|
-
// ignore
|
|
116
|
-
});
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Opens the cloudpack config in VSCode for the user to manually edit. If the file doesn't exist,
|
|
121
|
-
* it will be created.
|
|
122
|
-
*/
|
|
123
|
-
case 'editConfig': {
|
|
124
|
-
openConfigEditor({ input: undefined, ctx: { session } }).catch(() => {
|
|
125
|
-
/* no-op */
|
|
126
|
-
});
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Adds an override to the cloudpack config.
|
|
131
|
-
*/
|
|
132
|
-
case 'addOverride': {
|
|
133
|
-
// TODO: Send filename from request data to findResolveMapEntry when chromium Issue 1371551 is fixed.
|
|
134
|
-
(async () => {
|
|
135
|
-
const { packageName, importPath } = request.data;
|
|
136
|
-
await addPackageOverride({
|
|
137
|
-
input: { packageName, importPath },
|
|
138
|
-
ctx: { session, bus, packages, taskRunner },
|
|
139
|
-
});
|
|
140
|
-
})().catch(() => {
|
|
141
|
-
// no-op
|
|
142
|
-
});
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
case 'validateOverride': {
|
|
146
|
-
// TODO: Get filename from request data when chromium Issue 1371551 is fixed.
|
|
147
|
-
(async () => {
|
|
148
|
-
const input = request.data;
|
|
149
|
-
const fixable = await validateOverride(input, { session, packages });
|
|
150
|
-
const result = { fixable };
|
|
151
|
-
sendMessage({ type: 'validateOverride', requestId, data: result });
|
|
152
|
-
})().catch(() => {
|
|
153
|
-
// no-op
|
|
154
|
-
});
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
case 'restartAllTasks': {
|
|
158
|
-
restartAllTasks({ input: undefined, ctx: { session, bus, taskRunner } }).catch(() => {
|
|
159
|
-
// no-op
|
|
160
|
-
});
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case 'restartTask': {
|
|
164
|
-
const { id, inputPath } = request.data;
|
|
165
|
-
restartTask({ input: { id, inputPath }, ctx: { bus, taskRunner, session } });
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case 'reportMetric': {
|
|
169
|
-
reportMetric({ input: request.data, ctx: { telemetryClient } });
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case 'getSessionId': {
|
|
173
|
-
sendMessage({ type: 'sessionId', requestId, data: { sessionId: session.id } });
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
console.error('ApiServer: error handling message');
|
|
180
|
-
console.error('Error:', err.stack || err);
|
|
181
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
182
|
-
console.error('Message:', rawData.toString());
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
.on('close', () => {
|
|
186
|
-
for (const d of disposables.values()) {
|
|
187
|
-
d();
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
const notifyReload = () => {
|
|
192
|
-
session.sequence++;
|
|
193
|
-
socketServer.clients.forEach((socket) => {
|
|
194
|
-
if (socket.readyState === WebSocket.OPEN) {
|
|
195
|
-
socket.send(JSON.stringify({
|
|
196
|
-
type: 'reload',
|
|
197
|
-
data: { sessionId: session.id },
|
|
198
|
-
}));
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
bus.subscribe(reloadCountSource, notifyReload);
|
|
203
|
-
const url = `${protocol}://${host}:${port}`;
|
|
204
|
-
session.urls.apiServer = url;
|
|
205
|
-
return {
|
|
206
|
-
url,
|
|
207
|
-
port,
|
|
208
|
-
close: () => new Promise((resolve, reject) => {
|
|
209
|
-
socketServer.clients.forEach((socket) => socket.terminate());
|
|
210
|
-
socketServer.close((err) => (err ? reject(err) : resolve()));
|
|
211
|
-
server.close();
|
|
212
|
-
}),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=startApiServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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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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;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"]}
|